ALBA
albaGUIRangeSlider.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaGUIRangeSlider
5 Authors: Silvano Imboden
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16#ifndef __albaGUIRangeSlider_H__
17#define __albaGUIRangeSlider_H__
18//----------------------------------------------------------------------------
19// Include:
20//----------------------------------------------------------------------------
21#include "albaObserver.h"
22
27class albaGUIRangeSlider : public wxControl
28{
29public:
31 albaGUIRangeSlider(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPanelNameStr);
32
34 void SetListener(albaObserver *listener) {m_Listener = listener;}
35
37 double GetValue(int i) const { return this->m_Value[i]; }
38
40 void SetValue(int i, double value);
41
43 const double *GetRange() const { return this->m_Range; }
44
46 void SetRange(double *range);
47
49 void SetRange(double minR, double maxR) { double range[2] = {minR, maxR}; this->SetRange(range); }
50
52 void SetNumberOfWidgets(int num) { if (num == this->m_NumberOfWidgets || num < 1 || num > 3) return; this->m_NumberOfWidgets = num; this->Refresh(); }
53
55 void EnableCenterWidget(bool enable) { this->m_NumberOfWidgets = (enable) ? 3 : 2; this->Refresh(); }
56
58 void EnableBoundaryHandles(bool enable) {this->m_BorderWidgetRadius = (enable) ? 3 : 0; this->Refresh();}
59
61 bool IsDragging() const { return this->m_SelectedTriangleWidget != -1 || this->m_SelectedRangeWidget != -1; }
62
63protected:
65 void Initialize();
66
68 void OnPaint(wxPaintEvent &event);
69
71 void OnMouse(wxMouseEvent &event);
72
74 void OnRangeModified(wxCommandEvent &event);
75
77 void RedrawWidgets(wxDC &dc, bool eraseWidgets = false);
78
80 void DrawLabel(int x, int y, double val);
81
82 double m_Range[2];
83 double m_Value[3];
84
87
88private:
89 // ui coordinates
90 int m_LineStartX;
91 int m_LineStartY;
92 int m_LineWidth;
93 int m_BorderWidgetRadius;
94 wxPoint m_TrianglePosition[3];
95
96 static wxPoint m_TriangleWidgetPoints[3];
97 static wxPoint m_TriangleWidgetCenter;
98 static int m_TriangleWidgetRadius;
99
100 wxPoint m_PrevMousePosition;
101 int m_SelectedTriangleWidget;
102 int m_SelectedRangeWidget;
103 wxString m_ValueString;
104 wxStaticText *m_RangeValueLabel;
106 DECLARE_EVENT_TABLE()
107};
108#endif // _albaGUIRangeSlider_H_
class name: albaGUIRangeSlider Class that handles a slider for visualising or changing range.
void Initialize()
Initialize the values for the slider.
bool IsDragging() const
Return true if one of the cursors are moving.
albaGUIRangeSlider(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxPanelNameStr)
constructor
void SetValue(int i, double value)
Set the 'min', 'max' or 'mid' value according to 'i'.
void SetRange(double *range)
Set the range for the slider.
void DrawLabel(int x, int y, double val)
Draw a label according to the mouse position.
void EnableBoundaryHandles(bool enable)
Hide / show the circles on the boundary of the slider.
void OnRangeModified(wxCommandEvent &event)
Intercept slider events and forward to the listener.
void RedrawWidgets(wxDC &dc, bool eraseWidgets=false)
Redraw the widgets in the new position.
void SetListener(albaObserver *listener)
function for setting the listener of events coming from another object
albaObserver * m_Listener
void EnableCenterWidget(bool enable)
Enable/Disable the center cursor for the slider.
const double * GetRange() const
Get the range of the slider.
void SetRange(double minR, double maxR)
Set the range for the slider.
void OnMouse(wxMouseEvent &event)
Move the cursors on mouse event.
void OnPaint(wxPaintEvent &event)
Refresh the slider shape.
void SetNumberOfWidgets(int num)
Set the number of widgets for the slider.
double GetValue(int i) const
Get the 'min', 'max' or 'mid' value according to 'i'.
Interface implementing the Observer of the Subject/Observer design pattern.
Definition: albaObserver.h:36