|
|
|
@ -7,20 +7,107 @@
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
|
|
position_f_2d dbga_axis;
|
|
|
|
|
position_f_2d dbga_pos;
|
|
|
|
|
double dbga_angle = NAN;
|
|
|
|
|
double dbga_len = NAN;
|
|
|
|
|
|
|
|
|
|
#define DBGA_W 400
|
|
|
|
|
#define DBGA_H 400
|
|
|
|
|
|
|
|
|
|
void debug_angles_calculate() {
|
|
|
|
|
position_f_2d center;
|
|
|
|
|
|
|
|
|
|
center.x = DBGA_W >> 1;
|
|
|
|
|
center.y = DBGA_H >> 1;
|
|
|
|
|
|
|
|
|
|
dbga_len = dbga_axis.perpendicular(dbga_pos, center);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void debug_angles_draw(cairo_t *cr) {
|
|
|
|
|
int centerX = DBGA_W >> 1;
|
|
|
|
|
int centerY = DBGA_H >> 1;
|
|
|
|
|
position_f_2d v;
|
|
|
|
|
double d;
|
|
|
|
|
|
|
|
|
|
debug_angles_calculate();
|
|
|
|
|
|
|
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
|
|
|
|
cairo_set_line_width(cr, 1.0);
|
|
|
|
|
cairo_move_to(cr, 0, 0);
|
|
|
|
|
cairo_line_to(cr, DBGA_W, 0);
|
|
|
|
|
cairo_line_to(cr, DBGA_W, DBGA_H);
|
|
|
|
|
cairo_line_to(cr, 0, DBGA_H);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
|
|
|
|
|
cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
|
|
|
|
|
cairo_set_font_size (cr, 12);
|
|
|
|
|
draw_text(cr, 10, 10, 0.5, "Debug Angles");
|
|
|
|
|
|
|
|
|
|
if (isnan(dbga_axis.x)) return;
|
|
|
|
|
|
|
|
|
|
// len
|
|
|
|
|
cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
|
|
|
|
|
draw_printf(cr, 250, 10, 0.0, (char*)"Len: %5.2f", dbga_len);
|
|
|
|
|
|
|
|
|
|
// draw pos
|
|
|
|
|
cairo_set_source_rgb(cr, 0.3, 0.3, 1.0);
|
|
|
|
|
draw_printf(cr, 50, 10, 0.0, (char*)"Pos: %5.1f,%5.1f", dbga_pos.x, dbga_pos.y);
|
|
|
|
|
cairo_set_line_width(cr, 3.0);
|
|
|
|
|
cairo_move_to(cr, centerX, centerY);
|
|
|
|
|
cairo_line_to(cr, dbga_pos.x, dbga_pos.y);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
|
|
|
|
cairo_set_line_width(cr, 1.0);
|
|
|
|
|
if (dbga_len >= 0.0) cairo_set_source_rgb(cr, 1.0, 0.5, 0.5);
|
|
|
|
|
else cairo_set_source_rgb(cr, 0.5, 1.0, 0.5);
|
|
|
|
|
d = hypot(dbga_axis.x, dbga_axis.y);
|
|
|
|
|
v.x = dbga_len * dbga_axis.y / d;
|
|
|
|
|
v.y = dbga_len * (-dbga_axis.x) / d;
|
|
|
|
|
cairo_move_to(cr, dbga_pos.x, dbga_pos.y);
|
|
|
|
|
cairo_line_to(cr, dbga_pos.x + v.x, dbga_pos.y + v.y);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
|
|
|
|
// draw axis
|
|
|
|
|
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
|
|
|
|
|
draw_printf(cr, 50, 25, 0.0, (char*)"Axis: %5.1f,%5.1f", dbga_axis.x, dbga_axis.y);
|
|
|
|
|
cairo_set_line_width(cr, 3.0);
|
|
|
|
|
cairo_move_to(cr, centerX, centerY);
|
|
|
|
|
cairo_line_to(cr, centerX + dbga_axis.x, centerY + dbga_axis.y);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
|
|
|
|
cairo_set_line_width(cr, 1.0);
|
|
|
|
|
d = hypot(dbga_axis.x, dbga_axis.y);
|
|
|
|
|
v.x = centerX * dbga_axis.x / d;
|
|
|
|
|
v.y = centerY * dbga_axis.y / d;
|
|
|
|
|
cairo_move_to(cr, centerX - v.x, centerY - v.y);
|
|
|
|
|
cairo_line_to(cr, centerX + v.x, centerY + v.y);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void debug_angles_motionevent(GdkEvent *event) {
|
|
|
|
|
if (event->motion.x < 0 || event->motion.x >= DBGA_W
|
|
|
|
|
|| event->motion.y < 0 || event->motion.y >= DBGA_H) return;
|
|
|
|
|
|
|
|
|
|
dbga_pos.x = event->motion.x;
|
|
|
|
|
dbga_pos.y = event->motion.y;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void debug_angles_btnpress(GdkEvent *event) {
|
|
|
|
|
if (event->motion.x < 0 || event->motion.x >= DBGA_W
|
|
|
|
|
|| event->motion.y < 0 || event->motion.y >= DBGA_H) return;
|
|
|
|
|
|
|
|
|
|
dbga_axis.x = event->motion.x - (DBGA_W >> 1);
|
|
|
|
|
dbga_axis.y = event->motion.y - (DBGA_H >> 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|