lib: added implicit ctor converter from DatabaseDatabase to DBListType
[barry/progweb.git] / desktop / src / PNGButton.cc
blob3ed0bf4436733ded653d551017c2ffb998c9f054
1 ///
2 /// \file PNGButton.cc
3 /// Class for turning a set of PNG images into buttons
4 ///
6 /*
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 //////////////////////////////////////////////////////////////////////////////
26 // PNGButton
28 PNGButton::PNGButton(wxWindow *parent, int ID, int x, int y, bool enabled)
29 : m_parent(parent)
30 , m_id(ID)
31 , m_x(x)
32 , m_y(y)
33 , m_state(0)
34 , m_enabled(enabled)
36 // normal[0]
37 m_bitmaps[BUTTON_STATE_NORMAL] = LoadButtonBitmap(BUTTON_STATE_NORMAL);
39 // focus[1]
40 m_bitmaps[BUTTON_STATE_FOCUS] = LoadButtonBitmap(BUTTON_STATE_FOCUS);
42 // pushed[2]
43 m_bitmaps[BUTTON_STATE_PUSHED] = LoadButtonBitmap(BUTTON_STATE_PUSHED);
46 wxBitmap PNGButton::LoadButtonBitmap(int state)
48 wxString file = GetButtonFilename(m_id, state);
49 wxImage image(file);
50 wxBitmap bmp(image);
51 if( !image.IsOk() || !bmp.IsOk() ) {
52 wxGetApp().Yield();
53 throw std::runtime_error("Cannot load button bitmap.");
55 return bmp;
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);
65 wxMemoryDC grab_dc;
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)
78 if( !m_enabled )
79 return;
81 m_state = BUTTON_STATE_NORMAL;
82 Draw(dc);
85 void PNGButton::Focus(wxDC &dc)
87 if( !m_enabled )
88 return;
90 m_state = BUTTON_STATE_FOCUS;
91 Draw(dc);
94 void PNGButton::Push(wxDC &dc)
96 if( !m_enabled )
97 return;
99 m_state = BUTTON_STATE_PUSHED;
100 Draw(dc);
103 void PNGButton::Click(wxDC &dc)
105 if( !m_enabled )
106 return;
108 if( IsPushed() ) {
109 // return to normal
110 m_state = BUTTON_STATE_NORMAL;
111 Draw(dc);
113 // send the event
114 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_id);
115 m_parent->GetEventHandler()->ProcessEvent(event);