static void MouseMotion(AG_Event *event) { AG_HSVPal *pal = AG_SELF(); int x = AG_INT(1); int y = AG_INT(2); switch (pal->state) { case AG_HSVPAL_SEL_NONE: break; case AG_HSVPAL_SEL_H: UpdateHue(pal, x - pal->circle.x, y - pal->circle.y); break; case AG_HSVPAL_SEL_SV: UpdateSV(pal, x, y); break; case AG_HSVPAL_SEL_A: UpdateAlpha(pal, x); break; default: break; } }
void RingColorPicker::mousePressEvent(QMouseEvent *e) { this->grabMouse(); Vector2 pt((float)e->x(), (float)e->y()); Vector2 center(mRingSize / 2.0f, mRingSize / 2.0f); float dist = center.DistanceTo(pt); if (dist >= (mRingSize / 2.0f - mRingWidth) && dist <= mRingSize / 2.0f) { mDragRing = true; } else if (mRect.contains(e->pos())) { mDragRect = true; } if (mDragRing) { UpdateHue(e->pos()); } else if (mDragRect) { UpdateSatValue(e->pos()); } }
void RingColorPicker::mouseMoveEvent(QMouseEvent *e) { if (mDragRing) { UpdateHue(e->pos()); } else if (mDragRect) { UpdateSatValue(e->pos()); } }
static void MouseButtonDown(AG_Event *event) { AG_HSVPal *pal = AG_SELF(); int btn = AG_INT(1); int x = AG_INT(2); int y = AG_INT(3); float r; if (!AG_WidgetIsFocused(pal)) AG_WidgetFocus(pal); switch (btn) { case AG_MOUSE_LEFT: if (y > pal->rAlpha.y) { UpdateAlpha(pal, x); pal->state = AG_HSVPAL_SEL_A; } else { x -= pal->circle.x; y -= pal->circle.y; r = Hypot((float)x, (float)y); if (r > (float)pal->circle.rin) { UpdateHue(pal, x, y); pal->state = AG_HSVPAL_SEL_H; } else { UpdateSV(pal, AG_INT(2), AG_INT(3)); pal->state = AG_HSVPAL_SEL_SV; } } AG_Redraw(pal); break; case AG_MOUSE_MIDDLE: case AG_MOUSE_RIGHT: OpenMenu(pal, x,y); break; } }