// when the mouse is moved virtual void onMouseMove(MouseEvent &ev) { // dragging a point if (hasCapture()) { mPoints[mHotPoint] = viewToModel(ev.getPoint()); invalidate(true); } // change hot-tracking point else { int oldHotTracking = mHotPoint; mHotPoint = -1; // number of points int n = mPoints.size(); // check points for (int i=0; i<n; ++i) { Size sz(16, 16); Rect pointBounds = Rect(modelToView(mPoints[i]), sz).offset(-Point(sz/2)); if (pointBounds.contains(ev.getPoint())) { mHotPoint = i; break; } } if (oldHotTracking != mHotPoint) invalidate(true); } }
// when a mouse's button is pressed virtual void onMouseDown(MouseEvent &ev) { if (mHotPoint >= 0) { // drag the point with left button if (ev.getButton() == MouseButton::Left) captureMouse(); // ...or remove the point with the right one else { // remove point remove_from_container(mPoints, mPoints[mHotPoint]); // update hot-tracking point mHotPoint = -1; // redraw invalidate(true); } } else { // add a new point mPoints.push_back(viewToModel(ev.getPoint())); // update hot-tracking point onMouseMove(ev); // redraw invalidate(true); } }
void SplitBar::onMouseDown(MouseEvent& ev) { Widget::MouseDown(ev); // capture the mouse only if the user clicks in the bar if (getBarRect().contains(ev.getPoint())) { m_oldPoint = ev.getPoint(); m_oldBarPos = m_barPos; captureMouse(); if (!isFullDrag()) { ScreenGraphics g; drawTracker(g); } } }
void SplitBar::onMouseMove(MouseEvent& ev) { Widget::MouseMove(ev); if (hasCapture()) { Rect rcClient(getClientBounds()); ScreenGraphics g; if (!isFullDrag()) cleanTracker(g); bool byPixels = (getStyle() & Styles::ByPixels) == Styles::ByPixels; // Bar-position by pixels if (byPixels) { if (m_orientation == Orientation::Vertical) { m_barPos = m_oldBarPos + (ev.getPoint().x - m_oldPoint.x); m_barPos = clamp_value(m_barPos, 0.0, (double)rcClient.w-m_barSize); } else { m_barPos = m_oldBarPos + (ev.getPoint().y - m_oldPoint.y); m_barPos = clamp_value(m_barPos, 0.0, (double)rcClient.h-m_barSize); } } // Bar-position by percentage else { if (m_orientation == Orientation::Vertical) { m_barPos = m_oldBarPos + 100.0 * (ev.getPoint().x - m_oldPoint.x) / getBounds().w; } else { m_barPos = m_oldBarPos + 100.0 * (ev.getPoint().y - m_oldPoint.y) / getBounds().h; } m_barPos = clamp_value(m_barPos, 0.0, 100.0); } if (!isFullDrag()) drawTracker(g); else { layout(); invalidate(true); } } }