-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxKickBitmapButton.cpp
112 lines (94 loc) · 3.2 KB
/
wxKickBitmapButton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/***************************************************************
* Name: wxKickBitmapButton.h
* Purpose: wxWidgets Kick button
* Author: Benoit BOUCHEZ (BEB)
* Created: 2020-04-11
* Copyright: (c) Benoit BOUCHEZ
* License: wxWindows licence
**************************************************************/
/* This wxWidget is an equivalent of the KickButton from VSTGUI framework.
Button sends an event when clicked. One bitmap is displayed during the click
A second bitmap is displayed when button is released
The two bitmaps must have the same size */
#include "wxKickBitmapButton.h"
IMPLEMENT_DYNAMIC_CLASS(wxKickBitmapButton, wxControl)
BEGIN_EVENT_TABLE(wxKickBitmapButton, wxControl)
EVT_MOUSE_EVENTS(wxKickBitmapButton::OnMouse)
EVT_PAINT(wxKickBitmapButton::OnPaint)
END_EVENT_TABLE()
wxKickBitmapButton::wxKickBitmapButton (wxWindow *parent,
wxWindowID id,
wxBitmap& offBitmap,
wxBitmap& onBitmap,
const wxPoint& pos,
const wxSize& size,
long style,
const wxValidator& WXUNUSED(validator),
const wxString& WXUNUSED(name)) : wxControl(parent, id, pos, size, style)
{
this->Init();
this->mId=id;
this->mOffBitmap=&offBitmap;
this->mOnBitmap=&onBitmap;
if (parent)
SetBackgroundColour(parent->GetBackgroundColour());
else
SetBackgroundColour(*wxLIGHT_GREY);
} // wxKickBitmapButton::wxKickBitmapButton
// ----------------------------------------------------------------------------
void wxKickBitmapButton::Init (void)
{
this->mOffBitmap=0;
this->mOnBitmap=0;
this->mId=0;
this->MouseInControl=false;
this->mState=false;
} // wxKickBitmapButton::Init
// ----------------------------------------------------------------------------
void wxKickBitmapButton::OnMouse(wxMouseEvent& event)
{
wxClientDC dc(this);
if (event.Entering())
{
this->MouseInControl=true;
return;
}
if (event.Leaving())
{
this->MouseInControl=false;
return;
}
if (event.LeftUp())
{
this->mState=false;
dc.DrawBitmap(*mOffBitmap, 0, 0, TRUE);
//Refresh();
//Click(); // Sending the event here makes the bitmap show properly (released) but it is
// not what we want (a machine shall activate the output when button is depressed not released)
}
if (event.LeftDown() && MouseInControl)
{
this->mState=true;
dc.DrawBitmap(*mOnBitmap, 0, 0, TRUE);
//Refresh();
Click();
}
event.Skip();
} // wxKickBitmapButton::OnMouse
// ----------------------------------------------------------------------------
void wxKickBitmapButton::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
if (this->mState)
dc.DrawBitmap(*mOnBitmap, 0, 0, TRUE);
else
dc.DrawBitmap(*mOffBitmap, 0, 0, TRUE);
} // wxKickBitmapButton::OnPaint
// ----------------------------------------------------------------------------
void wxKickBitmapButton::Click (void)
{
wxCommandEvent event(wxEVT_BUTTON, mId);
event.SetEventObject(this);
ProcessEvent (event);
} // wxKickBitmapButton::Click
// ----------------------------------------------------------------------------