5 * Created by Toshi Nagata on 08/11/15.
6 * Copyright 2008 Toshi Nagata. All rights reserved.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation version 2 of the License.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
21 BEGIN_EVENT_TABLE(MySlider, wxToggleButton)
22 EVT_MOUSE_EVENTS(MySlider::OnMouseEvent)
23 // EVT_PAINT(MySlider::OnPaint)
24 EVT_MOUSE_CAPTURE_LOST(MySlider::OnCaptureLost)
27 const wxEventType MySliderEvent = wxNewEventType();
29 MySlider::MySlider(wxWindow* parent, wxWindowID id, int direction, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name):
30 wxToggleButton(parent, id, wxEmptyString, pos, size, style | wxTOGGLEBUTTON_STYLE, validator, name)
32 m_direction = direction;
33 SetCursor(wxCursor(wxCURSOR_HAND));
38 //MySlider::OnPaint(wxPaintEvent &event)
40 // wxToggleButton::OnPaint(event);
44 MySlider::OnCaptureLost(wxMouseCaptureLostEvent &event)
50 MySlider::OnMouseEvent(wxMouseEvent &event)
52 wxPoint pt(event.GetPosition());
53 bool sendAction = false;
55 if (mouseStatus == 0) {
56 if (event.LeftDown()) {
64 if (event.Dragging()) {
68 } else if (event.LeftUp() /* || (event.Entering() && !event.LeftIsDown()) */) {
72 // } else if (event.Leaving()) {
73 // wxGetApp().NotifyMouseUpEvent(this);
77 /* Send a custom event */
78 wxCommandEvent event(MySliderEvent, GetId());
79 event.SetEventObject(this);
80 GetEventHandler()->ProcessEvent(event);
85 MySlider::GetFloatValue()
89 GetSize(&width, &height);
90 if (m_direction == wxHORIZONTAL) {
91 f = (mouseDragPoint.x - mouseDownPoint.x) / (float)width;
94 /* Note the flipped coordinate! (up is positive internally) */
95 f = -(mouseDragPoint.y - mouseDownPoint.y) / (float)height;