]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/pushbutton.cpp
Creating Qt/Experimental branch of trunk.
[virtualjaguar] / src / gui / pushbutton.cpp
1 //
2 // PushButton class
3 //
4 // by James L. Hammons
5 //
6
7 #include "pushbutton.h"
8
9 #include "guimisc.h"
10
11 PushButton::PushButton(uint32 x, uint32 y, bool * st, std::string s):
12         Element(x, y, 16, 16), state(st), inside(false), text(s)
13 {
14         if (st == NULL)
15                 state = &internalState;
16 }
17
18 void PushButton::HandleMouseMove(uint32 x, uint32 y)
19 {
20         inside = Inside(x, y);
21 }
22
23 void PushButton::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
24 {
25         if (inside && mouseDown)
26                 *state = !(*state);
27 }
28
29 void PushButton::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
30 {
31         if (*state)
32                 DrawTransparentBitmap(screenBuffer, extents.x + offsetX, extents.y + offsetY, &pbDown);
33         else
34                 DrawTransparentBitmap(screenBuffer, extents.x + offsetX, extents.y + offsetY, &pbUp);
35
36         if (text.length() > 0)
37                 DrawString(screenBuffer, extents.x + offsetX + 24, extents.y + offsetY, false, "%s", text.c_str());
38 }