From: <pst...@us...> - 2008-04-28 01:27:15
|
Revision: 477 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=477&view=rev Author: pstieber Date: 2008-04-27 18:27:11 -0700 (Sun, 27 Apr 2008) Log Message: ----------- Changed the way the knob control works. The control is no longer angle based, but captures the mouse. Left-dragging up or down changes the value, left/right double-click increases/decreases the value, and the mouse wheel also increases/decreases the value. Modified Paths: -------------- trunk/jazz/src/Knob.cpp trunk/jazz/src/Knob.h Modified: trunk/jazz/src/Knob.cpp =================================================================== --- trunk/jazz/src/Knob.cpp 2008-04-27 22:23:47 UTC (rev 476) +++ trunk/jazz/src/Knob.cpp 2008-04-28 01:27:11 UTC (rev 477) @@ -78,16 +78,31 @@ EVT_SIZE(JZKnob::OnSize) EVT_ERASE_BACKGROUND(JZKnob::OnEraseBackground) EVT_PAINT(JZKnob::OnPaint) - EVT_LEFT_DOWN(JZKnob::OnMouse) - EVT_LEFT_UP(JZKnob::OnMouse) - EVT_MOTION(JZKnob::OnMouse) - EVT_MOUSEWHEEL(JZKnob::OnMouse) + EVT_LEFT_DOWN(JZKnob::OnLeftButtonDown) + EVT_RIGHT_DOWN(JZKnob::OnRightButtonDown) + EVT_MOTION(JZKnob::OnMouseMove) + EVT_LEFT_UP(JZKnob::OnLeftButtonUp) + EVT_LEFT_DCLICK(JZKnob::OnLeftButtonDoubleClick) + EVT_RIGHT_DCLICK(JZKnob::OnRightButtonDoubleClick) + EVT_MOUSEWHEEL(JZKnob::OnMouseWheel) END_EVENT_TABLE() //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +int JZKnob::mSensitivity = 4; + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZKnob::JZKnob() - : wxControl() + : wxControl(), + mMinValue(0), + mMaxValue(100), + mSetting(50), + mRange(300), + mMaxAngle(300), + mBuffer(), + mDragging(false), + mLastPoint() { } @@ -106,7 +121,15 @@ long WindowStyle, const wxValidator& Validator, const wxString& Name) - : wxControl() + : wxControl(), + mMinValue(0), + mMaxValue(100), + mSetting(50), + mRange(300), + mMaxAngle(300), + mBuffer(), + mDragging(false), + mLastPoint() { Create( pParent, @@ -209,6 +232,15 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +void JZKnob::GetCenter(int& x, int& y) const +{ + wxSize Size = GetSize(); + x = Size.x / 2; + y = Size.y / 2; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZKnob::OnSize(wxSizeEvent& Event) { int Width, Height; @@ -247,7 +279,8 @@ wxBufferedDC Dc(&PaintDc, mBuffer); - Dc.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE))); + Dc.SetBackground( + wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE))); Dc.Clear(); @@ -284,87 +317,96 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void JZKnob::OnMouse(wxMouseEvent& Event) +void JZKnob::OnLeftButtonDown(wxMouseEvent& Event) { - wxEventType ScrollEvent = wxEVT_NULL; + SetFocus(); - if (Event.Moving()) - { - Event.Skip(); - return; - } + mLastPoint = Event.GetPosition(); - if (Event.GetWheelRotation() < 0) - { - SetValueWithEvent(GetValue() - 1); - Event.Skip(); - return; - } + SetCursor(wxCursor(wxCURSOR_SIZENS)); - if (Event.GetWheelRotation() > 0) - { - SetValueWithEvent(GetValue() + 1); - Event.Skip(); - return; - } + CaptureMouse(); - int XCenter, YCenter; - GetCenter(XCenter, YCenter); + mDragging = true; +} - double DeltaX = Event.m_x - XCenter; - double DeltaY = YCenter - Event.m_y; - if (DeltaX == 0.0 && DeltaY == 0.0) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZKnob::OnRightButtonDown(wxMouseEvent& Event) +{ + SetFocus(); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZKnob::OnMouseMove(wxMouseEvent& Event) +{ + if (mDragging) { - return; - } + wxPoint Point = Event.GetPosition(); - double Theta = atan2(DeltaY, DeltaX) * gRadiansToDegrees; - if (Theta < 0.0) - { - Theta += 360.0; + int Delta = (mLastPoint.y - Point.y) / mSensitivity; + + if (Delta) + { + int PriorValue = GetValue(); + SetValueWithEvent(PriorValue + Delta); + if (PriorValue != GetValue()) + { + mLastPoint = Point; + } + } } +} - double DeltaTheta = Theta - mMaxAngle; - if (DeltaTheta < 0.0) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZKnob::OnLeftButtonUp(wxMouseEvent& Event) +{ + if (HasCapture()) { - DeltaTheta += 360; + ReleaseMouse(); } - if (DeltaTheta > mRange) - { - return; - } - int NewValue = int( - mMaxValue - (DeltaTheta / mRange) * (mMaxValue - mMinValue)); - SetValueWithEvent(NewValue); - if (Event.Dragging() || Event.ButtonUp()) - { - if (Event.ButtonUp()) - { - ScrollEvent = wxEVT_SCROLL_THUMBRELEASE; - } - else - { - ScrollEvent = wxEVT_SCROLL_THUMBTRACK; - } + SetCursor(wxCursor(wxCURSOR_ARROW)); - wxScrollEvent ScrollEvent(wxEVT_SCROLL_CHANGED, m_windowId); - ScrollEvent.SetPosition(NewValue); - ScrollEvent.SetEventObject(this); - GetEventHandler()->ProcessEvent(ScrollEvent); + mDragging = false; - wxCommandEvent CommandEvent(wxEVT_COMMAND_SLIDER_UPDATED, m_windowId); - CommandEvent.SetInt(NewValue); - CommandEvent.SetEventObject(this); - GetEventHandler()->ProcessEvent(CommandEvent); + wxPoint Point = Event.GetPosition(); + + int Delta = (mLastPoint.y - Point.y) / mSensitivity; + if (Delta) + { + SetValueWithEvent(GetValue() + Delta); } } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void JZKnob::GetCenter(int& x, int& y) const +void JZKnob::OnLeftButtonDoubleClick(wxMouseEvent& Event) { - wxSize Size = GetSize(); - x = Size.x / 2; - y = Size.y / 2; + SetValueWithEvent(GetValue() + 1); } + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZKnob::OnRightButtonDoubleClick(wxMouseEvent& Event) +{ + SetValueWithEvent(GetValue() - 1); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZKnob::OnMouseWheel(wxMouseEvent& Event) +{ + int WheelRotation = Event.GetWheelRotation(); + + if (WheelRotation < 0) + { + SetValueWithEvent(GetValue() - 1); + } + else if (WheelRotation > 0) + { + SetValueWithEvent(GetValue() + 1); + } +} Modified: trunk/jazz/src/Knob.h =================================================================== --- trunk/jazz/src/Knob.h 2008-04-27 22:23:47 UTC (rev 476) +++ trunk/jazz/src/Knob.h 2008-04-28 01:27:11 UTC (rev 477) @@ -145,22 +145,40 @@ void OnPaint(wxPaintEvent& Event); - void OnMouse(wxMouseEvent& Event); + void OnLeftButtonDown(wxMouseEvent& Event); + void OnRightButtonDown(wxMouseEvent& Event); + + void OnMouseMove(wxMouseEvent& Event); + + void OnLeftButtonUp(wxMouseEvent& Event); + + void OnLeftButtonDoubleClick(wxMouseEvent& Event); + + void OnRightButtonDoubleClick(wxMouseEvent& Event); + + void OnMouseWheel(wxMouseEvent& Event); + private: + static int mSensitivity; + int mMinValue; int mMaxValue; int mSetting; + unsigned int mRange; + unsigned int mMaxAngle; - unsigned int mRange; - wxBitmap mBuffer; + bool mDragging; + + wxPoint mLastPoint; + DECLARE_EVENT_TABLE() }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |