From: <pst...@us...> - 2008-04-06 05:09:40
|
Revision: 416 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=416&view=rev Author: pstieber Date: 2008-04-05 22:09:36 -0700 (Sat, 05 Apr 2008) Log Message: ----------- Added events for the knob control. 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-06 02:37:34 UTC (rev 415) +++ trunk/jazz/src/Knob.cpp 2008-04-06 05:09:36 UTC (rev 416) @@ -29,6 +29,47 @@ //***************************************************************************** // Description: +// This is the knob control event class definition. +//***************************************************************************** +//----------------------------------------------------------------------------- +// Define the knob control event types. +// I think the following insures the event IDs are unique. +//----------------------------------------------------------------------------- +DEFINE_EVENT_TYPE(wxEVT_KNOB_CHANGED) + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +IMPLEMENT_DYNAMIC_CLASS(JZKnobEvent, wxCommandEvent) + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZKnobEvent::JZKnobEvent() + : wxCommandEvent(), + mValue(0) +{ +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZKnobEvent::JZKnobEvent( + JZKnob* pKnobCtrl, + wxEventType Type) + : wxCommandEvent(Type, pKnobCtrl->GetId()), + mValue(0) +{ + mValue = pKnobCtrl->GetValue(); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZKnobEvent::JZKnobEvent(JZKnob* pKnobCtrl, int Value, wxEventType Type) + : wxCommandEvent(Type, pKnobCtrl->GetId()), + mValue(Value) +{ +} + +//***************************************************************************** +// Description: // This is the knob class definition. //***************************************************************************** //----------------------------------------------------------------------------- @@ -109,8 +150,8 @@ SetInitialSize(Size); - mMin = MinValue; - mMax = MaxValue; + mMinValue = MinValue; + mMaxValue = MaxValue; Range %= 360; MinAngle %= 360; mMaxAngle = (MinAngle + 360 - Range) % 360; @@ -125,9 +166,9 @@ { if (MinValue < MaxValue) { - mMin = MinValue; - mMax = MaxValue; - SetValue(mSetting); + mMinValue = MinValue; + mMaxValue = MaxValue; + SetValueWithEvent(mSetting); } } @@ -135,13 +176,13 @@ //----------------------------------------------------------------------------- int JZKnob::SetValue(int Value) { - if (Value < mMin) + if (Value < mMinValue) { - Value = mMin; + Value = mMinValue; } - if (Value > mMax) + if (Value > mMaxValue) { - Value = mMax; + Value = mMaxValue; } if (Value != mSetting) @@ -155,6 +196,19 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +int JZKnob::SetValueWithEvent(int Value) +{ + int ActualValue = SetValue(Value); + + JZKnobEvent Event(this, ActualValue, wxEVT_KNOB_CHANGED); + Event.SetEventObject(this); + GetEventHandler()->ProcessEvent(Event); + + return ActualValue; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZKnob::OnSize(wxSizeEvent& Event) { int Width, Height; @@ -181,7 +235,8 @@ wxSize Size = GetSize(); double Theta = gDegreesToRadians * - (mMaxAngle + (((double)mMax - mSetting) / (mMax - mMin)) * mRange); + (mMaxAngle + + (((double)mMaxValue - mSetting) / (mMaxValue - mMinValue)) * mRange); double DeltaX = cos(Theta); @@ -241,14 +296,14 @@ if (Event.GetWheelRotation() < 0) { - SetValue(GetValue() - 1); + SetValueWithEvent(GetValue() - 1); Event.Skip(); return; } if (Event.GetWheelRotation() > 0) { - SetValue(GetValue() + 1); + SetValueWithEvent(GetValue() + 1); Event.Skip(); return; } @@ -278,9 +333,10 @@ { return; } - int NewValue = int(mMax - (DeltaTheta / mRange) * (mMax - mMin)); + int NewValue = int( + mMaxValue - (DeltaTheta / mRange) * (mMaxValue - mMinValue)); - SetValue(NewValue); + SetValueWithEvent(NewValue); if (Event.Dragging() || Event.ButtonUp()) { if (Event.ButtonUp()) Modified: trunk/jazz/src/Knob.h =================================================================== --- trunk/jazz/src/Knob.h 2008-04-06 02:37:34 UTC (rev 415) +++ trunk/jazz/src/Knob.h 2008-04-06 05:09:36 UTC (rev 416) @@ -21,8 +21,62 @@ #ifndef JZ_KNOB_H #define JZ_KNOB_H +class JZKnobEvent; +class JZKnob; + //***************************************************************************** // Description: +// Declare knob control event types and macros for handling them. +//***************************************************************************** +//----------------------------------------------------------------------------- +// Description: +// The second argument to DECLARE_EVENT_TYPE is unused. wxWidgets assigns a +// unique evant ID at run time. +//----------------------------------------------------------------------------- +BEGIN_DECLARE_EVENT_TYPES() + DECLARE_EVENT_TYPE(wxEVT_KNOB_CHANGED, 1) +END_DECLARE_EVENT_TYPES() + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +typedef void (wxEvtHandler::*wxKnobEventFunction)(JZKnobEvent&); + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#define EVT_KNOB_CHANGED(Id, Function) \ + DECLARE_EVENT_TABLE_ENTRY( \ + wxEVT_KNOB_CHANGED, \ + Id, \ + -1, \ + (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \ + (wxKnobEventFunction)& Function, \ + (wxObject *) NULL), + +//***************************************************************************** +// Description: +// This is the knob control event class declaration. +//***************************************************************************** +class JZKnobEvent : public wxCommandEvent +{ + public: + + JZKnobEvent(); + + JZKnobEvent(JZKnob* pKnobCtrl, wxEventType Type); + + JZKnobEvent(JZKnob* pKnobCtrl, int Value, wxEventType Type); + + int GetValue() const; + + private: + + int mValue; + + DECLARE_DYNAMIC_CLASS(JZKnobEvent) +}; + +//***************************************************************************** +// Description: // This is the knob class declaration. This is a custom control that looks // like a mixer knob. //***************************************************************************** @@ -79,6 +133,8 @@ int SetValue(int Value); + int SetValueWithEvent(int Value); + private: void GetCenter(int& x, int& y) const; @@ -93,9 +149,9 @@ private: - int mMin; + int mMinValue; - int mMax; + int mMaxValue; int mSetting; @@ -110,6 +166,18 @@ //***************************************************************************** // Description: +// These are the knob control event inline member functions. +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZKnobEvent::GetValue() const +{ + return mValue; +} + +//***************************************************************************** +// Description: // These are the knob inline member functions. //***************************************************************************** //----------------------------------------------------------------------------- @@ -117,7 +185,7 @@ inline int JZKnob::GetMin() const { - return mMin; + return mMinValue; } //----------------------------------------------------------------------------- @@ -125,7 +193,7 @@ inline int JZKnob::GetMax() const { - return mMax; + return mMaxValue; } //----------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |