2 * MyProgressIndicator.cpp
5 * Created by Toshi Nagata on 13/06/26.
6 * Copyright 2013 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.
18 #include "MyProgressIndicator.h"
21 #include "wx/dcclient.h"
22 #include "wx/bitmap.h"
23 #include "wx/image.h" // If omitted, then new wxBitmap(char *, int) will fail
25 BEGIN_EVENT_TABLE(MyProgressIndicator, wxWindow)
26 EVT_MOUSE_EVENTS(MyProgressIndicator::OnMouseEvent)
27 EVT_PAINT(MyProgressIndicator::OnPaint)
28 EVT_MOUSE_CAPTURE_LOST(MyProgressIndicator::OnCaptureLost)
31 static wxBitmap *sStopMiniIcons[3];
32 static wxBitmap *sProgressIndicatorIcons[12];
34 MyProgressIndicator::MyProgressIndicator(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxWindow(parent, id, pos, size, style)
40 // Initialize icons for progress indicator
41 if (sStopMiniIcons[0] == NULL) {
42 #include "../bitmaps/stop_mini_grey.xpm"
43 #include "../bitmaps/stop_mini.xpm"
44 #include "../bitmaps/stop_mini_dark.xpm"
45 #include "../bitmaps/pi00.xpm"
46 #include "../bitmaps/pi01.xpm"
47 #include "../bitmaps/pi02.xpm"
48 #include "../bitmaps/pi03.xpm"
49 #include "../bitmaps/pi04.xpm"
50 #include "../bitmaps/pi05.xpm"
51 #include "../bitmaps/pi06.xpm"
52 #include "../bitmaps/pi07.xpm"
53 #include "../bitmaps/pi08.xpm"
54 #include "../bitmaps/pi09.xpm"
55 #include "../bitmaps/pi10.xpm"
56 #include "../bitmaps/pi11.xpm"
57 sStopMiniIcons[0] = new wxBitmap(stop_mini_grey, wxBITMAP_TYPE_XPM);
58 sStopMiniIcons[1] = new wxBitmap(stop_mini, wxBITMAP_TYPE_XPM);
59 sStopMiniIcons[2] = new wxBitmap(stop_mini_dark, wxBITMAP_TYPE_XPM);
60 sProgressIndicatorIcons[0] = new wxBitmap(pi00, wxBITMAP_TYPE_XPM);
61 sProgressIndicatorIcons[1] = new wxBitmap(pi01, wxBITMAP_TYPE_XPM);
62 sProgressIndicatorIcons[2] = new wxBitmap(pi02, wxBITMAP_TYPE_XPM);
63 sProgressIndicatorIcons[3] = new wxBitmap(pi03, wxBITMAP_TYPE_XPM);
64 sProgressIndicatorIcons[4] = new wxBitmap(pi04, wxBITMAP_TYPE_XPM);
65 sProgressIndicatorIcons[5] = new wxBitmap(pi05, wxBITMAP_TYPE_XPM);
66 sProgressIndicatorIcons[6] = new wxBitmap(pi06, wxBITMAP_TYPE_XPM);
67 sProgressIndicatorIcons[7] = new wxBitmap(pi07, wxBITMAP_TYPE_XPM);
68 sProgressIndicatorIcons[8] = new wxBitmap(pi08, wxBITMAP_TYPE_XPM);
69 sProgressIndicatorIcons[9] = new wxBitmap(pi09, wxBITMAP_TYPE_XPM);
70 sProgressIndicatorIcons[10] = new wxBitmap(pi10, wxBITMAP_TYPE_XPM);
71 sProgressIndicatorIcons[11] = new wxBitmap(pi11, wxBITMAP_TYPE_XPM);
76 MyProgressIndicator::OnPaint(wxPaintEvent &event)
83 stopState = (pressed ? 2 : 1);
85 dc.DrawBitmap(*sStopMiniIcons[stopState], 0, 0, 1);
87 dc.DrawBitmap(*sProgressIndicatorIcons[indicatorState % 12], 0, 15, 1);
91 MyProgressIndicator::OnMouseEvent(wxMouseEvent &event)
95 event.GetPosition(&x, &y);
96 if (event.LeftDown()) {
97 if (x >= 0 && x <= 12 && y >= 0 && y <= 12) {
101 } else if (event.Dragging()) {
102 if (x >= 0 && x <= 12 && y >= 0 && y <= 12) {
105 } else if (event.LeftUp()) {
107 /* Send button action */
108 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
109 event.SetEventObject(this);
110 GetEventHandler()->ProcessEvent(event);
116 if (event.LeftDown())
121 MyProgressIndicator::OnCaptureLost(wxMouseCaptureLostEvent &event)
126 MyProgressIndicator::SetEnabled(bool flag)
128 if (flag != enabled) {
135 MyProgressIndicator::SetPressed(bool flag)
137 if (flag != pressed) {
144 MyProgressIndicator::SetIndicatorState(int state)
146 if (state != indicatorState) {
147 indicatorState = state;
153 MyProgressIndicator::ProceedIndicatorState()
155 indicatorState = (indicatorState + 1) % 12;