Commit 3acba18d authored by Christoffer Ackelman's avatar Christoffer Ackelman

Slight cleanup of Glow.

parent 85f94d7b
...@@ -114,35 +114,19 @@ void GrowArc::move(double delta_x, double delta_y, int grid) ...@@ -114,35 +114,19 @@ void GrowArc::move(double delta_x, double delta_y, int grid)
} }
} }
int GrowArc::local_event_handler(glow_eEvent event, double x, double y)
{
double ll_x, ur_x, ll_y, ur_y;
ll_x = MIN(ll.x, ur.x);
ur_x = MAX(ll.x, ur.x);
ll_y = MIN(ll.y, ur.y);
ur_y = MAX(ll.y, ur.y);
if (ll_x <= x && x <= ur_x && ll_y <= y && y <= ur_y)
return 1;
else
return 0;
}
int GrowArc::event_handler(glow_eEvent event, double fx, double fy) int GrowArc::event_handler(glow_eEvent event, double fx, double fy)
{ {
// Convert from global to local coordinates
glow_sPoint p = trf.reverse(fx, fy); glow_sPoint p = trf.reverse(fx, fy);
return local_event_handler(event, p.x, p.y); return (MIN(ll.x, ur.x) <= p.x && p.x <= MAX(ll.x, ur.x)
&& MIN(ll.y, ur.y) <= p.y && p.y <= MAX(ll.y, ur.y));
} }
int GrowArc::event_handler(glow_eEvent event, int x, int y, double fx, double fy) int GrowArc::event_handler(glow_eEvent event, int x, int y, double fx, double fy)
{ {
// Convert koordinates to local koordinates
glow_sPoint r = trf.reverse(fx, fy);
int sts = 0; int sts = 0;
if (event == ctx->event_move_node) { if (event == ctx->event_move_node) {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) { if (sts) {
/* Register node for potential movement */ /* Register node for potential movement */
ctx->move_insert(this); ctx->move_insert(this);
...@@ -156,7 +140,7 @@ int GrowArc::event_handler(glow_eEvent event, int x, int y, double fx, double fy ...@@ -156,7 +140,7 @@ int GrowArc::event_handler(glow_eEvent event, int x, int y, double fx, double fy
else if (ctx->hot_found) else if (ctx->hot_found)
sts = 0; sts = 0;
else { else {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) if (sts)
ctx->hot_found = 1; ctx->hot_found = 1;
} }
...@@ -173,7 +157,7 @@ int GrowArc::event_handler(glow_eEvent event, int x, int y, double fx, double fy ...@@ -173,7 +157,7 @@ int GrowArc::event_handler(glow_eEvent event, int x, int y, double fx, double fy
break; break;
} }
default: default:
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
} }
if (sts) if (sts)
ctx->register_callback_object(glow_eObjectType_Node, this); ctx->register_callback_object(glow_eObjectType_Node, this);
......
...@@ -118,20 +118,6 @@ public: ...@@ -118,20 +118,6 @@ public:
*/ */
int event_handler(glow_eEvent event, double fx, double fy); int event_handler(glow_eEvent event, double fx, double fy);
//! Detects if the object is hit by an event in local coordinates
/*!
\param event Current event.
\param x x of event coordinate in the objects local coordinate
system.
\param y y of event coordinate in the objects local coordinate
system.
\return Returns 1 if the object is hit, else 0.
Compares the coordinates of the event with the borders of the object.
If the event is inside the borders, 1 is returned, otherwise 0 is returned.
*/
int local_event_handler(glow_eEvent event, double x, double y);
//! Calculate the border for a set of objects or for a parent node. //! Calculate the border for a set of objects or for a parent node.
/*! /*!
\param t Transform. \param t Transform.
......
...@@ -271,35 +271,19 @@ void GrowImage::move(double delta_x, double delta_y, int grid) ...@@ -271,35 +271,19 @@ void GrowImage::move(double delta_x, double delta_y, int grid)
} }
} }
int GrowImage::local_event_handler(glow_eEvent event, double x, double y)
{
double ll_x, ur_x, ll_y, ur_y;
ll_x = MIN(ll.x, ur.x);
ur_x = MAX(ll.x, ur.x);
ll_y = MIN(ll.y, ur.y);
ur_y = MAX(ll.y, ur.y);
if (ll_x <= x && x <= ur_x && ll_y <= y && y <= ur_y) {
return 1;
} else
return 0;
}
int GrowImage::event_handler(glow_eEvent event, double fx, double fy) int GrowImage::event_handler(glow_eEvent event, double fx, double fy)
{ {
// Convert from global to local coordinates
glow_sPoint p = trf.reverse(fx, fy); glow_sPoint p = trf.reverse(fx, fy);
return local_event_handler(event, p.x, p.y); return (MIN(ll.x, ur.x) <= p.x && p.x <= MAX(ll.x, ur.x)
&& MIN(ll.y, ur.y) <= p.y && p.y <= MAX(ll.y, ur.y));
} }
int GrowImage::event_handler(glow_eEvent event, int x, int y, double fx, double fy) int GrowImage::event_handler(glow_eEvent event, int x, int y, double fx, double fy)
{ {
// Convert koordinates to local koordinates
glow_sPoint r = trf.reverse(fx, fy);
int sts = 0; int sts = 0;
if (event == ctx->event_move_node) { if (event == ctx->event_move_node) {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) { if (sts) {
/* Register node for potential movement */ /* Register node for potential movement */
ctx->move_insert(this); ctx->move_insert(this);
...@@ -313,7 +297,7 @@ int GrowImage::event_handler(glow_eEvent event, int x, int y, double fx, double ...@@ -313,7 +297,7 @@ int GrowImage::event_handler(glow_eEvent event, int x, int y, double fx, double
else if (ctx->hot_found) else if (ctx->hot_found)
sts = 0; sts = 0;
else { else {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) if (sts)
ctx->hot_found = 1; ctx->hot_found = 1;
} }
...@@ -330,7 +314,7 @@ int GrowImage::event_handler(glow_eEvent event, int x, int y, double fx, double ...@@ -330,7 +314,7 @@ int GrowImage::event_handler(glow_eEvent event, int x, int y, double fx, double
break; break;
} }
default: default:
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
} }
if (sts) if (sts)
ctx->register_callback_object(glow_eObjectType_Node, this); ctx->register_callback_object(glow_eObjectType_Node, this);
......
...@@ -108,20 +108,6 @@ public: ...@@ -108,20 +108,6 @@ public:
*/ */
int event_handler(glow_eEvent event, double fx, double fy); int event_handler(glow_eEvent event, double fx, double fy);
//! Detects if the object is hit by an event in local coordinates
/*!
\param event Current event.
\param x x of event coordinate in the objects local coordinate
system.
\param y y of event coordinate in the objects local coordinate
system.
\return Returns 1 if the object is hit, else 0.
Compares the coordinates of the event with the borders of the object.
If the event is inside the borders, 1 is returned, otherwise 0 is returned.
*/
int local_event_handler(glow_eEvent event, double x, double y);
//! Calculate the border for a set of objects or for a parent node. //! Calculate the border for a set of objects or for a parent node.
/*! /*!
\param t Transform. \param t Transform.
......
...@@ -104,48 +104,42 @@ void GrowLine::move(double delta_x, double delta_y, int grid) ...@@ -104,48 +104,42 @@ void GrowLine::move(double delta_x, double delta_y, int grid)
} }
} }
int GrowLine::local_event_handler(glow_eEvent event, double x, double y) { int GrowLine::event_handler(glow_eEvent event, double fx, double fy)
{
// Convert from global to local coordinates
glow_sPoint p = trf.reverse(fx, fy);
glow_sPoint tmp2 = trf.reverse(0.05 * line_width, 0.05 * line_width); glow_sPoint tmp2 = trf.reverse(0.05 * line_width, 0.05 * line_width);
glow_sPoint tmp1 = trf.reverse(0, 0); glow_sPoint tmp1 = trf.reverse(0, 0);
double dx = fabs(tmp2.x - tmp1.x); double dx = fabs(tmp2.x - tmp1.x);
double dy = fabs(tmp2.y - tmp1.y); double dy = fabs(tmp2.y - tmp1.y);
if ((feq(p1.x, p2.x) && p1.y < p2.y && // Vertical if ((feq(p1.x, p2.x) && p1.y < p2.y && // Vertical
fabs(p1.x - x) < dx && p1.y < y && y < p2.y) fabs(p1.x - p.x) < dx && p1.y < p.y && p.y < p2.y)
|| (feq(p1.x, p2.x) && p1.y > p2.y && // Vertical || (feq(p1.x, p2.x) && p1.y > p2.y && // Vertical
fabs(p1.x - x) < dx && p2.y < y && y < p1.y) fabs(p1.x - p.x) < dx && p2.y < p.y && p.y < p1.y)
|| (feq(p1.y, p2.y) && p1.x < p2.x && // Horizontal || (feq(p1.y, p2.y) && p1.x < p2.x && // Horizontal
fabs(p1.y - y) < dy && p1.x < x && x < p2.x) fabs(p1.y - p.y) < dy && p1.x < p.x && p.x < p2.x)
|| (feq(p1.y, p2.y) && p1.x > p2.x && // Horizontal || (feq(p1.y, p2.y) && p1.x > p2.x && // Horizontal
fabs(p1.y - y) < dy && p2.x < x && x < p1.x)) { fabs(p1.y - p.y) < dy && p2.x < p.x && p.x < p1.x)) {
return 1; return 1;
} else if ( } else if (
(!(feq(p1.x, p2.x) || feq(p1.y, p2.y)) && p1.x < p2.x && p1.x <= x && (!(feq(p1.x, p2.x) || feq(p1.y, p2.y)) && p1.x < p2.x && p1.x <= p.x &&
x <= p2.x && fabs(y - (p2.y - p1.y) / (p2.x - p1.x) * x - p1.y + p.x <= p2.x && fabs(p.y - (p2.y - p1.y) / (p2.x - p1.x) * p.x - p1.y +
(p2.y - p1.y) / (p2.x - p1.x) * p1.x) < dx) || (p2.y - p1.y) / (p2.x - p1.x) * p1.x) < dx) ||
(!(feq(p1.x, p2.x) || feq(p1.y, p2.y)) && p1.x > p2.x && p2.x <= x && (!(feq(p1.x, p2.x) || feq(p1.y, p2.y)) && p1.x > p2.x && p2.x <= p.x &&
x <= p1.x && fabs(y - (p2.y - p1.y) / (p2.x - p1.x) * x - p1.y + p.x <= p1.x && fabs(p.y - (p2.y - p1.y) / (p2.x - p1.x) * p.x - p1.y +
(p2.y - p1.y) / (p2.x - p1.x) * p1.x) < dx)) { (p2.y - p1.y) / (p2.x - p1.x) * p1.x) < dx)) {
return 1; return 1;
} }
return 0; return 0;
} }
int GrowLine::event_handler(glow_eEvent event, double fx, double fy)
{
glow_sPoint p = trf.reverse(fx, fy);
return local_event_handler(event, p.x, p.y);
}
int GrowLine::event_handler(glow_eEvent event, int x, int y, double fx, int GrowLine::event_handler(glow_eEvent event, int x, int y, double fx,
double fy) double fy)
{ {
// Convert koordinates to local koordinates
glow_sPoint r = trf.reverse(fx, fy);
int sts = 0; int sts = 0;
if (event == ctx->event_move_node) { if (event == ctx->event_move_node) {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) { if (sts) {
/* Register node for potential movement */ /* Register node for potential movement */
ctx->move_insert(this); ctx->move_insert(this);
...@@ -159,7 +153,7 @@ int GrowLine::event_handler(glow_eEvent event, int x, int y, double fx, ...@@ -159,7 +153,7 @@ int GrowLine::event_handler(glow_eEvent event, int x, int y, double fx,
else if (ctx->hot_found) else if (ctx->hot_found)
sts = 0; sts = 0;
else { else {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) if (sts)
ctx->hot_found = 1; ctx->hot_found = 1;
} }
...@@ -176,7 +170,7 @@ int GrowLine::event_handler(glow_eEvent event, int x, int y, double fx, ...@@ -176,7 +170,7 @@ int GrowLine::event_handler(glow_eEvent event, int x, int y, double fx,
break; break;
} }
default: default:
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
} }
if (sts) if (sts)
ctx->register_callback_object(glow_eObjectType_Node, this); ctx->register_callback_object(glow_eObjectType_Node, this);
......
...@@ -107,20 +107,6 @@ public: ...@@ -107,20 +107,6 @@ public:
*/ */
int event_handler(glow_eEvent event, double fx, double fy); int event_handler(glow_eEvent event, double fx, double fy);
//! Detects if the object is hit by an event in local coordinates
/*!
\param event Current event.
\param x x of event coordinate in the objects local coordinate
system.
\param y y of event coordinate in the objects local coordinate
system.
\return Returns 1 if the object is hit, else 0.
Compares the coordinates of the event with the borders of the object.
If the event is inside the borders, 1 is returned, otherwise 0 is returned.
*/
int local_event_handler(glow_eEvent event, double x, double y);
//! Calculate the border for a set of objects or for a parent node. //! Calculate the border for a set of objects or for a parent node.
/*! /*!
\param t Transform. \param t Transform.
......
...@@ -301,21 +301,14 @@ void GrowMenu::erase(GlowWind* w, GlowTransform* t, int hot, void* node) ...@@ -301,21 +301,14 @@ void GrowMenu::erase(GlowWind* w, GlowTransform* t, int hot, void* node)
ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, glow_eDrawType_LineErase, 1, 0); ll_x, ll_y, ur_x - ll_x, ur_y - ll_y, glow_eDrawType_LineErase, 1, 0);
} }
int GrowMenu::local_event_handler(glow_eEvent event, double x, double y) int GrowMenu::event_handler(glow_eEvent event, double fx, double fy)
{ {
double ll_x, ur_x, ll_y, ur_y; if (MIN(ll.x, ur.x) <= fx && fx <= MAX(ll.x, ur.x) &&
MIN(ll.y, ur.y) <= fy && fy <= MAX(ll.y, ur.y)) {
ll_x = MIN(ll.x, ur.x);
ur_x = MAX(ll.x, ur.x);
ll_y = MIN(ll.y, ur.y);
ur_y = MAX(ll.y, ur.y);
if (ll_x <= x && x <= ur_x && ll_y <= y && y <= ur_y) {
int item; int item;
double vscale = 1; // trf.vertical_scale(); double vscale = 1; // trf.vertical_scale();
// std::cout << "Event handler: Hit in menu " << this << '\n';
item = int((y - ll.y) / (item_height / vscale / ctx->mw.zoom_factor_y)); item = int((fy - ll.y) / (item_height / vscale / ctx->mw.zoom_factor_y));
if (item > item_cnt - 1) if (item > item_cnt - 1)
item = item_cnt - 1; item = item_cnt - 1;
if (item < 0) if (item < 0)
...@@ -344,17 +337,8 @@ int GrowMenu::local_event_handler(glow_eEvent event, double x, double y) ...@@ -344,17 +337,8 @@ int GrowMenu::local_event_handler(glow_eEvent event, double x, double y)
} }
} }
int GrowMenu::event_handler(glow_eEvent event, double fx, double fy)
{
return local_event_handler(event, fx, fy);
}
int GrowMenu::event_handler(glow_eEvent event, int x, int y, double fx, double fy) int GrowMenu::event_handler(glow_eEvent event, int x, int y, double fx, double fy)
{ {
// Convert koordinates to local koordinates
double rx = fx;
double ry = fy;
int sts = 0; int sts = 0;
if (event == ctx->event_move_node) { if (event == ctx->event_move_node) {
return 0; return 0;
...@@ -364,7 +348,7 @@ int GrowMenu::event_handler(glow_eEvent event, int x, int y, double fx, double f ...@@ -364,7 +348,7 @@ int GrowMenu::event_handler(glow_eEvent event, int x, int y, double fx, double f
if (ctx->hot_mode != glow_eHotMode_TraceAction && ctx->hot_found) if (ctx->hot_mode != glow_eHotMode_TraceAction && ctx->hot_found)
sts = 0; sts = 0;
else { else {
sts = local_event_handler(event, rx, ry); sts = event_handler(event, fx, fy);
if (sts) { if (sts) {
ctx->hot_found = 1; ctx->hot_found = 1;
} }
...@@ -393,14 +377,14 @@ int GrowMenu::event_handler(glow_eEvent event, int x, int y, double fx, double f ...@@ -393,14 +377,14 @@ int GrowMenu::event_handler(glow_eEvent event, int x, int y, double fx, double f
break; break;
} }
case glow_eEvent_MB1Down: case glow_eEvent_MB1Down:
sts = local_event_handler(event, rx, ry); sts = event_handler(event, fx, fy);
if (sts) if (sts)
// Remove any previous hit // Remove any previous hit
ctx->register_callback_object(glow_eObjectType_NoObject, 0); ctx->register_callback_object(glow_eObjectType_NoObject, 0);
ctx->gdraw->set_click_sensitivity(glow_mSensitivity_MB1Click); ctx->gdraw->set_click_sensitivity(glow_mSensitivity_MB1Click);
break; break;
case glow_eEvent_MB1Click: { case glow_eEvent_MB1Click: {
sts = local_event_handler(event, rx, ry); sts = event_handler(event, fx, fy);
if (sts && current_item != -1) { if (sts && current_item != -1) {
if (info.item[current_item].type == glow_eMenuItem_Button) { if (info.item[current_item].type == glow_eMenuItem_Button) {
int csts = ctx->send_menu_callback( int csts = ctx->send_menu_callback(
...@@ -418,7 +402,7 @@ int GrowMenu::event_handler(glow_eEvent event, int x, int y, double fx, double f ...@@ -418,7 +402,7 @@ int GrowMenu::event_handler(glow_eEvent event, int x, int y, double fx, double f
} }
} }
default: default:
sts = local_event_handler(event, rx, ry); sts = event_handler(event, fx, fy);
} }
if (sts) if (sts)
ctx->register_callback_object(glow_eObjectType_Node, this); ctx->register_callback_object(glow_eObjectType_Node, this);
......
...@@ -180,7 +180,6 @@ public: ...@@ -180,7 +180,6 @@ public:
int event_handler(glow_eEvent event, int x, int y, double fx, double fy); int event_handler(glow_eEvent event, int x, int y, double fx, double fy);
int event_handler(glow_eEvent event, double fx, double fy); int event_handler(glow_eEvent event, double fx, double fy);
int local_event_handler(glow_eEvent event, double x, double y);
//! Check this menu object is a child to the specified menu object, and delete //! Check this menu object is a child to the specified menu object, and delete
//! it if it is. //! it if it is.
......
...@@ -579,13 +579,15 @@ GrowPolyLine::~GrowPolyLine() ...@@ -579,13 +579,15 @@ GrowPolyLine::~GrowPolyLine()
ctx->gdraw->set_cursor(ctx->mw.window, glow_eDrawCursor_Normal); ctx->gdraw->set_cursor(ctx->mw.window, glow_eDrawCursor_Normal);
} }
int GrowPolyLine::local_event_handler(glow_eEvent event, double x, double y) int GrowPolyLine::event_handler(glow_eEvent event, double fx, double fy)
{ {
// Convert from global to local coordinates
glow_sPoint p = trf.reverse(fx, fy);
if (ctx->edit_mode == grow_eMode_EditPolyLine && ctx->a_sel[0] == this) { if (ctx->edit_mode == grow_eMode_EditPolyLine && ctx->a_sel[0] == this) {
int dx = 4; int dx = 4;
int dy = 4; int dy = 4;
glow_sPoint c = trf * glow_sPoint({x, y}); glow_sPoint c = trf * p;
c.x = c.x * ctx->mw.zoom_factor_x + ctx->mw.offset_x; c.x = c.x * ctx->mw.zoom_factor_x + ctx->mw.offset_x;
c.y = c.y * ctx->mw.zoom_factor_y + ctx->mw.offset_y; c.y = c.y * ctx->mw.zoom_factor_y + ctx->mw.offset_y;
...@@ -611,20 +613,20 @@ int GrowPolyLine::local_event_handler(glow_eEvent event, double x, double y) ...@@ -611,20 +613,20 @@ int GrowPolyLine::local_event_handler(glow_eEvent event, double x, double y)
p2 = *((GlowPoint *) a_points[i + 1]); p2 = *((GlowPoint *) a_points[i + 1]);
if ((feq(p1.x, p2.x) && p1.y < p2.y && // Vertical if ((feq(p1.x, p2.x) && p1.y < p2.y && // Vertical
fabs(p1.x - x) < dx && p1.y < y && y < p2.y) fabs(p1.x - p.x) < dx && p1.y < p.y && p.y < p2.y)
|| (feq(p1.x, p2.x) && p1.y > p2.y && // Vertical || (feq(p1.x, p2.x) && p1.y > p2.y && // Vertical
fabs(p1.x - x) < dx && p2.y < y && y < p1.y) fabs(p1.x - p.x) < dx && p2.y < p.y && p.y < p1.y)
|| (feq(p1.y, p2.y) && p1.x < p2.x && // Horizontal || (feq(p1.y, p2.y) && p1.x < p2.x && // Horizontal
fabs(p1.y - y) < dy && p1.x < x && x < p2.x) fabs(p1.y - p.y) < dy && p1.x < p.x && p.x < p2.x)
|| (feq(p1.y, p2.y) && p1.x > p2.x && // Horizontal || (feq(p1.y, p2.y) && p1.x > p2.x && // Horizontal
fabs(p1.y - y) < dy && p2.x < x && x < p1.x)) { fabs(p1.y - p.y) < dy && p2.x < p.x && p.x < p1.x)) {
return 1; return 1;
} else if ( } else if (
(!(feq(p1.x, p2.x) || feq(p1.y, p2.y)) && p1.x < p2.x && p1.x <= x && (!(feq(p1.x, p2.x) || feq(p1.y, p2.y)) && p1.x < p2.x && p1.x <= p.x &&
x <= p2.x && fabs(y - (p2.y - p1.y) / (p2.x - p1.x) * x - p1.y + p.x <= p2.x && fabs(p.y - (p2.y - p1.y) / (p2.x - p1.x) * p.x - p1.y +
(p2.y - p1.y) / (p2.x - p1.x) * p1.x) < dx) || (p2.y - p1.y) / (p2.x - p1.x) * p1.x) < dx) ||
(!(feq(p1.x, p2.x) || feq(p1.y, p2.y)) && p1.x > p2.x && p2.x <= x && (!(feq(p1.x, p2.x) || feq(p1.y, p2.y)) && p1.x > p2.x && p2.x <= p.x &&
x <= p1.x && fabs(y - (p2.y - p1.y) / (p2.x - p1.x) * x - p1.y + p.x <= p1.x && fabs(p.y - (p2.y - p1.y) / (p2.x - p1.x) * p.x - p1.y +
(p2.y - p1.y) / (p2.x - p1.x) * p1.x) < dx)) { (p2.y - p1.y) / (p2.x - p1.x) * p1.x) < dx)) {
return 1; return 1;
} }
...@@ -633,20 +635,11 @@ int GrowPolyLine::local_event_handler(glow_eEvent event, double x, double y) ...@@ -633,20 +635,11 @@ int GrowPolyLine::local_event_handler(glow_eEvent event, double x, double y)
return 0; return 0;
} }
int GrowPolyLine::event_handler(glow_eEvent event, double fx, double fy)
{
glow_sPoint p = trf.reverse(fx, fy);
return local_event_handler(event, p.x, p.y);
}
int GrowPolyLine::event_handler(glow_eEvent event, int x, int y, double fx, double fy) int GrowPolyLine::event_handler(glow_eEvent event, int x, int y, double fx, double fy)
{ {
// Convert koordinates to local koordinates
glow_sPoint r = trf.reverse(fx, fy);
int sts = 0; int sts = 0;
if (event == ctx->event_move_node) { if (event == ctx->event_move_node) {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) { if (sts) {
/* Register node for potential movement */ /* Register node for potential movement */
ctx->move_insert(this); ctx->move_insert(this);
...@@ -660,7 +653,7 @@ int GrowPolyLine::event_handler(glow_eEvent event, int x, int y, double fx, doub ...@@ -660,7 +653,7 @@ int GrowPolyLine::event_handler(glow_eEvent event, int x, int y, double fx, doub
else if (ctx->hot_found) else if (ctx->hot_found)
sts = 0; sts = 0;
else { else {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) if (sts)
ctx->hot_found = 1; ctx->hot_found = 1;
} }
...@@ -677,7 +670,7 @@ int GrowPolyLine::event_handler(glow_eEvent event, int x, int y, double fx, doub ...@@ -677,7 +670,7 @@ int GrowPolyLine::event_handler(glow_eEvent event, int x, int y, double fx, doub
break; break;
} }
default: default:
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
} }
if (sts) if (sts)
ctx->register_callback_object(glow_eObjectType_Node, this); ctx->register_callback_object(glow_eObjectType_Node, this);
......
...@@ -110,20 +110,6 @@ public: ...@@ -110,20 +110,6 @@ public:
*/ */
int event_handler(glow_eEvent event, double fx, double fy); int event_handler(glow_eEvent event, double fx, double fy);
//! Detects if the object is hit by an event in local coordinates
/*!
\param event Current event.
\param x x of event coordinate in the objects local coordinate
system.
\param y y of event coordinate in the objects local coordinate
system.
\return Returns 1 if the object is hit, else 0.
Compares the coordinates of the event with the borders of the object.
If the event is inside the borders, 1 is returned, otherwise 0 is returned.
*/
int local_event_handler(glow_eEvent event, double x, double y);
//! Calculate the border for a set of objects or for a parent node. //! Calculate the border for a set of objects or for a parent node.
/*! /*!
\param t Transform. \param t Transform.
......
...@@ -115,36 +115,19 @@ void GrowRect::move(double delta_x, double delta_y, int grid) ...@@ -115,36 +115,19 @@ void GrowRect::move(double delta_x, double delta_y, int grid)
} }
} }
int GrowRect::local_event_handler(glow_eEvent event, double x, double y)
{
double ll_x, ur_x, ll_y, ur_y;
ll_x = MIN(ll.x, ur.x);
ur_x = MAX(ll.x, ur.x);
ll_y = MIN(ll.y, ur.y);
ur_y = MAX(ll.y, ur.y);
if (ll_x <= x && x <= ur_x && ll_y <= y && y <= ur_y) {
// std::cout << "Event handler: Hit in rect\n";
return 1;
} else
return 0;
}
int GrowRect::event_handler(glow_eEvent event, double fx, double fy) int GrowRect::event_handler(glow_eEvent event, double fx, double fy)
{ {
// Convert from global to local coordinates
glow_sPoint p = trf.reverse(fx, fy); glow_sPoint p = trf.reverse(fx, fy);
return local_event_handler(event, p.x, p.y); return (MIN(ll.x, ur.x) <= p.x && p.x <= MAX(ll.x, ur.x)
&& MIN(ll.y, ur.y) <= p.y && p.y <= MAX(ll.y, ur.y));
} }
int GrowRect::event_handler(glow_eEvent event, int x, int y, double fx, double fy) int GrowRect::event_handler(glow_eEvent event, int x, int y, double fx, double fy)
{ {
// Convert koordinates to local koordinates
glow_sPoint r = trf.reverse(fx, fy);
int sts = 0; int sts = 0;
if (event == ctx->event_move_node) { if (event == ctx->event_move_node) {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) { if (sts) {
/* Register node for potential movement */ /* Register node for potential movement */
ctx->move_insert(this); ctx->move_insert(this);
...@@ -158,7 +141,7 @@ int GrowRect::event_handler(glow_eEvent event, int x, int y, double fx, double f ...@@ -158,7 +141,7 @@ int GrowRect::event_handler(glow_eEvent event, int x, int y, double fx, double f
else if (ctx->hot_found) else if (ctx->hot_found)
sts = 0; sts = 0;
else { else {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) if (sts)
ctx->hot_found = 1; ctx->hot_found = 1;
} }
...@@ -176,7 +159,7 @@ int GrowRect::event_handler(glow_eEvent event, int x, int y, double fx, double f ...@@ -176,7 +159,7 @@ int GrowRect::event_handler(glow_eEvent event, int x, int y, double fx, double f
break; break;
} }
default: default:
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
} }
if (sts) if (sts)
ctx->register_callback_object(glow_eObjectType_Node, this); ctx->register_callback_object(glow_eObjectType_Node, this);
......
...@@ -111,20 +111,6 @@ public: ...@@ -111,20 +111,6 @@ public:
*/ */
int event_handler(glow_eEvent event, double fx, double fy); int event_handler(glow_eEvent event, double fx, double fy);
//! Detects if the object is hit by an event in local coordinates
/*!
\param event Current event.
\param x x of event coordinate in the objects local coordinate
system.
\param y y of event coordinate in the objects local coordinate
system.
\return Returns 1 if the object is hit, else 0.
Compares the coordinates of the event with the borders of the object.
If the event is inside the borders, 1 is returned, otherwise 0 is returned.
*/
virtual int local_event_handler(glow_eEvent event, double x, double y);
//! Calculate the border for a set of objects or for a parent node. //! Calculate the border for a set of objects or for a parent node.
/*! /*!
\param t Transform. \param t Transform.
......
...@@ -112,36 +112,19 @@ void GrowRectRounded::move(double delta_x, double delta_y, int grid) ...@@ -112,36 +112,19 @@ void GrowRectRounded::move(double delta_x, double delta_y, int grid)
} }
} }
int GrowRectRounded::local_event_handler(glow_eEvent event, double x, double y)
{
double ll_x, ur_x, ll_y, ur_y;
ll_x = MIN(ll.x, ur.x);
ur_x = MAX(ll.x, ur.x);
ll_y = MIN(ll.y, ur.y);
ur_y = MAX(ll.y, ur.y);
if (ll_x <= x && x <= ur_x && ll_y <= y && y <= ur_y) {
// std::cout << "Event handler: Hit in rect\n";
return 1;
} else
return 0;
}
int GrowRectRounded::event_handler(glow_eEvent event, double fx, double fy) int GrowRectRounded::event_handler(glow_eEvent event, double fx, double fy)
{ {
// Convert from global to local coordinates
glow_sPoint p = trf.reverse(fx, fy); glow_sPoint p = trf.reverse(fx, fy);
return local_event_handler(event, p.x, p.y); return (MIN(ll.x, ur.x) <= p.x && p.x <= MAX(ll.x, ur.x)
&& MIN(ll.y, ur.y) <= p.y && p.y <= MAX(ll.y, ur.y));
} }
int GrowRectRounded::event_handler(glow_eEvent event, int x, int y, double fx, double fy) int GrowRectRounded::event_handler(glow_eEvent event, int x, int y, double fx, double fy)
{ {
// Convert koordinates to local koordinates
glow_sPoint r = trf.reverse(fx, fy);
int sts = 0; int sts = 0;
if (event == ctx->event_move_node) { if (event == ctx->event_move_node) {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) { if (sts) {
/* Register node for potential movement */ /* Register node for potential movement */
ctx->move_insert(this); ctx->move_insert(this);
...@@ -155,7 +138,7 @@ int GrowRectRounded::event_handler(glow_eEvent event, int x, int y, double fx, d ...@@ -155,7 +138,7 @@ int GrowRectRounded::event_handler(glow_eEvent event, int x, int y, double fx, d
else if (ctx->hot_found) else if (ctx->hot_found)
sts = 0; sts = 0;
else { else {
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
if (sts) if (sts)
ctx->hot_found = 1; ctx->hot_found = 1;
} }
...@@ -172,7 +155,7 @@ int GrowRectRounded::event_handler(glow_eEvent event, int x, int y, double fx, d ...@@ -172,7 +155,7 @@ int GrowRectRounded::event_handler(glow_eEvent event, int x, int y, double fx, d
break; break;
} }
default: default:
sts = local_event_handler(event, r.x, r.y); sts = event_handler(event, fx, fy);
} }
if (sts) if (sts)
ctx->register_callback_object(glow_eObjectType_Node, this); ctx->register_callback_object(glow_eObjectType_Node, this);
......
...@@ -109,20 +109,6 @@ public: ...@@ -109,20 +109,6 @@ public:
*/ */
int event_handler(glow_eEvent event, double fx, double fy); int event_handler(glow_eEvent event, double fx, double fy);
//! Detects if the object is hit by an event in local coordinates
/*!
\param event Current event.
\param x x of event coordinate in the objects local coordinate
system.
\param y y of event coordinate in the objects local coordinate
system.
\return Returns 1 if the object is hit, else 0.
Compares the coordinates of the event with the borders of the object.
If the event is inside the borders, 1 is returned, otherwise 0 is returned.
*/
int local_event_handler(glow_eEvent event, double x, double y);
//! Calculate the border for a set of objects or for a parent node. //! Calculate the border for a set of objects or for a parent node.
/*! /*!
\param t Transform. \param t Transform.
......
...@@ -1106,9 +1106,7 @@ int GrowTable::event_handler(glow_eEvent event, int x, int y, double fx, double ...@@ -1106,9 +1106,7 @@ int GrowTable::event_handler(glow_eEvent event, int x, int y, double fx, double
if (!ctx->trace_started) if (!ctx->trace_started)
return 0; return 0;
if (v_scrollbar) { if (v_scrollbar) {
// Convert koordinates to local koordinates sts = GrowRect::event_handler(event, fx, fy);
glow_sPoint r = trf.reverse(fx, fy);
sts = local_event_handler(event, r.x, r.y);
if (sts) { if (sts) {
v_value -= (table_y1 - table_y0) * window_scale / 50; v_value -= (table_y1 - table_y0) * window_scale / 50;
if (v_value < table_y0 * window_scale) if (v_value < table_y0 * window_scale)
...@@ -1124,9 +1122,7 @@ int GrowTable::event_handler(glow_eEvent event, int x, int y, double fx, double ...@@ -1124,9 +1122,7 @@ int GrowTable::event_handler(glow_eEvent event, int x, int y, double fx, double
if (!ctx->trace_started) if (!ctx->trace_started)
return 0; return 0;
if (v_scrollbar) { if (v_scrollbar) {
// Convert koordinates to local koordinates sts = GrowRect::event_handler(event, fx, fy);
glow_sPoint r = trf.reverse(fx, fy);
sts = local_event_handler(event, r.x, r.y);
if (sts) { if (sts) {
v_value += (table_y1 - table_y0) * window_scale / 50; v_value += (table_y1 - table_y0) * window_scale / 50;
if (v_value > (table_y1 - (y_high - y_low if (v_value > (table_y1 - (y_high - y_low
......
...@@ -111,21 +111,16 @@ void GrowText::move(double delta_x, double delta_y, int grid) ...@@ -111,21 +111,16 @@ void GrowText::move(double delta_x, double delta_y, int grid)
} }
} }
int GrowText::local_event_handler(glow_eEvent event, double x, double y)
{
return (x_left <= x && x <= x_right && y_low <= y && y <= y_high);
}
int GrowText::event_handler(glow_eEvent event, double fx, double fy) int GrowText::event_handler(glow_eEvent event, double fx, double fy)
{ {
return local_event_handler(event, fx, fy); return (x_left <= fx && fx <= x_right && y_low <= fy && fy <= y_high);
} }
int GrowText::event_handler(glow_eEvent event, int x, int y, double fx, double fy) int GrowText::event_handler(glow_eEvent event, int x, int y, double fx, double fy)
{ {
int sts = 0; int sts = 0;
if (event == ctx->event_move_node) { if (event == ctx->event_move_node) {
sts = local_event_handler(event, fx, fy); sts = event_handler(event, fx, fy);
if (sts) { if (sts) {
/* Register node for potential movement */ /* Register node for potential movement */
ctx->move_insert(this); ctx->move_insert(this);
...@@ -139,7 +134,7 @@ int GrowText::event_handler(glow_eEvent event, int x, int y, double fx, double f ...@@ -139,7 +134,7 @@ int GrowText::event_handler(glow_eEvent event, int x, int y, double fx, double f
else if (ctx->hot_found) else if (ctx->hot_found)
sts = 0; sts = 0;
else { else {
sts = local_event_handler(event, fx, fy); sts = event_handler(event, fx, fy);
if (sts) if (sts)
ctx->hot_found = 1; ctx->hot_found = 1;
} }
...@@ -156,7 +151,7 @@ int GrowText::event_handler(glow_eEvent event, int x, int y, double fx, double f ...@@ -156,7 +151,7 @@ int GrowText::event_handler(glow_eEvent event, int x, int y, double fx, double f
break; break;
} }
default: default:
sts = local_event_handler(event, fx, fy); sts = event_handler(event, fx, fy);
} }
if (sts) if (sts)
ctx->register_callback_object(glow_eObjectType_Node, this); ctx->register_callback_object(glow_eObjectType_Node, this);
......
...@@ -112,20 +112,6 @@ public: ...@@ -112,20 +112,6 @@ public:
*/ */
int event_handler(glow_eEvent event, double fx, double fy); int event_handler(glow_eEvent event, double fx, double fy);
//! Detects if the object is hit by an event in local coordinates
/*!
\param event Current event.
\param x x of event coordinate in the objects local coordinate
system.
\param y y of event coordinate in the objects local coordinate
system.
\return Returns 1 if the object is hit, else 0.
Compares the coordinates of the event with the borders of the object.
If the event is inside the borders, 1 is returned, otherwise 0 is returned.
*/
int local_event_handler(glow_eEvent event, double x, double y);
//! Calculate the border for a set of objects or for a parent node. //! Calculate the border for a set of objects or for a parent node.
/*! /*!
\param t Transform. \param t Transform.
......
...@@ -571,9 +571,7 @@ int GrowWindow::event_handler(glow_eEvent event, int x, int y, double fx, double ...@@ -571,9 +571,7 @@ int GrowWindow::event_handler(glow_eEvent event, int x, int y, double fx, double
if (!ctx->trace_started) if (!ctx->trace_started)
return 0; return 0;
if (v_scrollbar) { if (v_scrollbar) {
// Convert koordinates to local koordinates sts = GrowRect::event_handler(event, fx, fy);
glow_sPoint r = trf.reverse(fx, fy);
sts = local_event_handler(event, r.x, r.y);
if (sts) { if (sts) {
v_value -= (wctx_y1 - wctx_y0) * window_scale / 50; v_value -= (wctx_y1 - wctx_y0) * window_scale / 50;
if (v_value < wctx_y0 * window_scale) if (v_value < wctx_y0 * window_scale)
...@@ -589,9 +587,7 @@ int GrowWindow::event_handler(glow_eEvent event, int x, int y, double fx, double ...@@ -589,9 +587,7 @@ int GrowWindow::event_handler(glow_eEvent event, int x, int y, double fx, double
if (!ctx->trace_started) if (!ctx->trace_started)
return 0; return 0;
if (v_scrollbar) { if (v_scrollbar) {
// Convert koordinates to local koordinates sts = GrowRect::event_handler(event, fx, fy);
glow_sPoint r = trf.reverse(fx, fy);
sts = local_event_handler(event, r.x, r.y);
if (sts) { if (sts) {
v_value += (wctx_y1 - wctx_y0) * window_scale / 50; v_value += (wctx_y1 - wctx_y0) * window_scale / 50;
if (v_value > wctx_y1 * window_scale if (v_value > wctx_y1 * window_scale
...@@ -633,9 +629,7 @@ int GrowWindow::event_handler(glow_eEvent event, int x, int y, double fx, double ...@@ -633,9 +629,7 @@ int GrowWindow::event_handler(glow_eEvent event, int x, int y, double fx, double
} }
if (ctx->hot_mode == glow_eHotMode_TraceAction) { if (ctx->hot_mode == glow_eHotMode_TraceAction) {
// Convert koordinates to local koordinates sts = GrowRect::event_handler(event, fx, fy);
glow_sPoint r = trf.reverse(fx, fy);
sts = local_event_handler(event, r.x, r.y);
} }
if (window_ctx && sts) { if (window_ctx && sts) {
...@@ -680,10 +674,6 @@ int GrowWindow::event_handler(glow_eEvent event, int x, int y, double fx, double ...@@ -680,10 +674,6 @@ int GrowWindow::event_handler(glow_eEvent event, int x, int y, double fx, double
ctx->register_inputfocus(this, 0); ctx->register_inputfocus(this, 0);
input_focus = 0; input_focus = 0;
} }
// if ( window_ctx->callback_object)
// ctx->register_callback_object( window_ctx->callback_object_type,
// window_ctx->callback_object);
} }
return sts; return sts;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment