3 /// Class for turning a set of PNG images into buttons
7 Copyright (C) 2009-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "PNGButton.h"
23 #include "barrydesktop.h"
25 //////////////////////////////////////////////////////////////////////////////
28 PNGButton::PNGButton(wxWindow
*parent
, int ID
, int x
, int y
, bool enabled
)
37 m_bitmaps
[BUTTON_STATE_NORMAL
] = LoadButtonBitmap(BUTTON_STATE_NORMAL
);
40 m_bitmaps
[BUTTON_STATE_FOCUS
] = LoadButtonBitmap(BUTTON_STATE_FOCUS
);
43 m_bitmaps
[BUTTON_STATE_PUSHED
] = LoadButtonBitmap(BUTTON_STATE_PUSHED
);
46 wxBitmap
PNGButton::LoadButtonBitmap(int state
)
48 wxString file
= GetButtonFilename(m_id
, state
);
51 if( !image
.IsOk() || !bmp
.IsOk() ) {
53 throw std::runtime_error("Cannot load button bitmap.");
58 void PNGButton::Init(wxDC
&dc
)
60 int width
= m_bitmaps
[BUTTON_STATE_NORMAL
].GetWidth();
61 int height
= m_bitmaps
[BUTTON_STATE_NORMAL
].GetHeight();
63 m_background
= wxBitmap(width
, height
);
66 grab_dc
.SelectObject(m_background
);
67 grab_dc
.Blit(0, 0, width
, height
, &dc
, m_x
, m_y
, wxCOPY
, false);
70 void PNGButton::Draw(wxDC
&dc
)
72 dc
.DrawBitmap(m_background
, m_x
, m_y
, false);
73 dc
.DrawBitmap(m_bitmaps
[m_state
], m_x
, m_y
);
76 void PNGButton::Normal(wxDC
&dc
)
81 m_state
= BUTTON_STATE_NORMAL
;
85 void PNGButton::Focus(wxDC
&dc
)
90 m_state
= BUTTON_STATE_FOCUS
;
94 void PNGButton::Push(wxDC
&dc
)
99 m_state
= BUTTON_STATE_PUSHED
;
103 void PNGButton::Click(wxDC
&dc
)
110 m_state
= BUTTON_STATE_NORMAL
;
114 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, m_id
);
115 m_parent
->GetEventHandler()->ProcessEvent(event
);