]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/slideswitch.cpp
Major refactoring of GUI: Phase I
[virtualjaguar] / src / gui / slideswitch.cpp
1 //
2 // SlideSwitch class
3 //
4 // by James L. Hammons
5 //
6
7 #include "slideswitch.h"
8
9 #include "guimisc.h"
10
11 SlideSwitch::SlideSwitch(uint32 x, uint32 y, bool * st, std::string s1, std::string s2):
12         Element(x, y, 16, 32), state(st), inside(false), text1(s1), text2(s2)
13 {
14 }
15
16 void SlideSwitch::HandleMouseMove(uint32 x, uint32 y)
17 {
18         inside = Inside(x, y);
19 }
20
21 void SlideSwitch::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
22 {
23         if (inside && mouseDown)
24         {
25                 *state = !(*state);
26         }
27 }
28
29 void SlideSwitch::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
30 {
31         DrawTransparentBitmapDeprecated(screenBuffer, extents.x + offsetX, extents.y + offsetY, (*state ? slideSwitchDown : slideSwitchUp));
32
33         if (text1.length() > 0)
34                 DrawString(screenBuffer, extents.x + offsetX + 24, extents.y + offsetY, false, "%s", text1.c_str());
35
36         if (text2.length() > 0)
37                 DrawString(screenBuffer, extents.x + offsetX + 24, extents.y + offsetY + 16, false, "%s", text2.c_str());
38 }