|
From: <pst...@us...> - 2013-04-08 04:30:37
|
Revision: 1022
http://sourceforge.net/p/jazzplusplus/code/1022
Author: pstieber
Date: 2013-04-08 04:30:34 +0000 (Mon, 08 Apr 2013)
Log Message:
-----------
Added mouse events.
Modified Paths:
--------------
trunk/jazz/src/ArrayControl.cpp
trunk/jazz/src/ArrayControl.h
Modified: trunk/jazz/src/ArrayControl.cpp
===================================================================
--- trunk/jazz/src/ArrayControl.cpp 2013-04-08 04:00:54 UTC (rev 1021)
+++ trunk/jazz/src/ArrayControl.cpp 2013-04-08 04:30:34 UTC (rev 1022)
@@ -49,6 +49,8 @@
BEGIN_EVENT_TABLE(JZArrayControl, wxControl)
EVT_SIZE(JZArrayControl::OnSize)
EVT_PAINT(JZArrayControl::OnPaint)
+ EVT_MOUSE_EVENTS(JZArrayControl::OnMouseEvent)
+ EVT_MOUSE_CAPTURE_LOST(JZArrayControl::OnMouseCaptureLost)
END_EVENT_TABLE()
//-----------------------------------------------------------------------------
@@ -70,6 +72,8 @@
mYNull(0),
mWidth(0),
mHeight(0),
+ mDragging(false),
+ mIndex(-1),
mXMin(0),
mXMax(RandomArray.Size())
{
@@ -178,6 +182,155 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
+void JZArrayControl::OnMouseEvent(wxMouseEvent& MouseEvent)
+{
+ if (!mEnabled)
+ {
+ return;
+ }
+ if (MouseEvent.ButtonDown())
+ {
+ ButtonDown(MouseEvent);
+ }
+ else if (MouseEvent.Dragging())
+ {
+ Dragging(MouseEvent);
+ }
+ else if (MouseEvent.ButtonUp())
+ {
+ ButtonUp(MouseEvent);
+ }
+}
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void JZArrayControl::OnMouseCaptureLost(wxMouseCaptureLostEvent&)
+{
+ if (HasCapture())
+ {
+ ReleaseMouse();
+ }
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void JZArrayControl::ButtonDown(wxMouseEvent& MouseEvent)
+{
+ CaptureMouse();
+ mDragging = true;
+ mIndex = GetIndex(MouseEvent);
+ Dragging(MouseEvent);
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void JZArrayControl::Dragging(wxMouseEvent& MouseEvent)
+{
+ if (!mDragging)
+ {
+ return;
+ }
+
+ if (mIndex < 0)
+ {
+ mIndex = GetIndex(MouseEvent);
+ }
+
+ wxClientDC Dc(this); // PORTING this is evil and shoud go
+
+ int Value = mpRandomArray->GetNull();
+ if (MouseEvent.LeftIsDown())
+ {
+ int EventX, EventY;
+ MouseEvent.GetPosition(&EventX, &EventY);
+
+ Value = (int)((double)(mY + mHeight - EventY) *
+ (mpRandomArray->GetMax() - mpRandomArray->GetMin()) / mHeight +
+ mpRandomArray->GetMin() + 0.5);
+
+ if (Value < mpRandomArray->GetMin())
+ {
+ Value = mpRandomArray->GetMin();
+ }
+ if (Value > mpRandomArray->GetMax())
+ {
+ Value = mpRandomArray->GetMax();
+ }
+ }
+
+ if (MouseEvent.ShiftDown())
+ {
+ for (int k = 0; k < mpRandomArray->Size(); ++k)
+ {
+ DrawBar(Dc, k, 0);
+ (*mpRandomArray)[k] = Value;
+ DrawBar(Dc, k, 1);
+ }
+ }
+ else if (MouseEvent.ControlDown())
+ {
+ DrawBar(Dc, mIndex, 0);
+ (*mpRandomArray)[mIndex] = Value;
+ DrawBar(Dc, mIndex, 1);
+ }
+ else
+ {
+ int i = GetIndex(MouseEvent);
+ int k = i;
+ if (i < mIndex)
+ {
+ for (; i <= mIndex; ++i)
+ {
+ DrawBar(Dc, i, 0);
+ (*mpRandomArray)[i] = Value;
+ DrawBar(Dc, i, 1);
+ }
+ }
+ else
+ {
+ for (; i >= mIndex; --i)
+ {
+ DrawBar(Dc, i, 0);
+ (*mpRandomArray)[i] = Value;
+ DrawBar(Dc, i, 1);
+ }
+ }
+ mIndex = k;
+ }
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void JZArrayControl::ButtonUp(wxMouseEvent& MouseEvent)
+{
+ if (HasCapture())
+ {
+ ReleaseMouse();
+ }
+ mDragging = false;
+ mIndex = -1;
+ Refresh();
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+int JZArrayControl::GetIndex(wxMouseEvent& MouseEvent)
+{
+ int EventX, EventY;
+ MouseEvent.GetPosition(&EventX, &EventY);
+ int Index = (int)((EventX - mX) * mpRandomArray->Size() / mWidth);
+ if (Index < 0)
+ {
+ Index = 0;
+ }
+ if (Index >= mpRandomArray->Size())
+ {
+ Index = mpRandomArray->Size() - 1;
+ }
+ return Index;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
void JZArrayControl::DrawBar(wxDC& Dc, int i, bool black)
{
if (mStyleBits & ARED_LINES)
Modified: trunk/jazz/src/ArrayControl.h
===================================================================
--- trunk/jazz/src/ArrayControl.h 2013-04-08 04:00:54 UTC (rev 1021)
+++ trunk/jazz/src/ArrayControl.h 2013-04-08 04:30:34 UTC (rev 1022)
@@ -52,6 +52,18 @@
void OnPaint(wxPaintEvent& Event);
+ void OnMouseEvent(wxMouseEvent& MouseEvent);
+
+ void OnMouseCaptureLost(wxMouseCaptureLostEvent& Event);
+
+ void ButtonDown(wxMouseEvent& MouseEvent);
+
+ void Dragging(wxMouseEvent& MouseEvent);
+
+ void ButtonUp(wxMouseEvent& MouseEvent);
+
+ int GetIndex(wxMouseEvent& MouseEvent);
+
void DrawBar(wxDC& Dc, int i, bool black);
void DrawLabel(wxDC& Dc);
@@ -79,6 +91,12 @@
int mX, mY, mYNull;
int mWidth, mHeight;
+ // Dragging flag.
+ bool mDragging;
+
+ // If ctrl is pushed: drag this one.
+ int mIndex;
+
// Array size is mapped to this range for x-tick marks.
int mXMin, mXMax;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|