]> git.vomp.tv Git - vompclient.git/blob - wbutton.cc
Preparations for dynamic mode switching
[vompclient.git] / wbutton.cc
1 /*\r
2     Copyright 2004-2005 Chris Tallon\r
3 \r
4     This file is part of VOMP.\r
5 \r
6     VOMP is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     VOMP is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with VOMP; if not, write to the Free Software\r
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
19 */\r
20 \r
21 #include "wbutton.h"\r
22 \r
23 #include "colour.h"\r
24 \r
25 WButton::WButton()\r
26 {\r
27 \r
28   setSize(70, 21/*fontHeight*/);\r
29 \r
30   mytext = NULL;\r
31   active = 0;\r
32   tag = 0;\r
33   dimmed = false;\r
34 }\r
35 \r
36 WButton::~WButton()\r
37 {\r
38   if (mytext) delete[] mytext;\r
39 }\r
40 \r
41 void WButton::setText(const char* takeText)\r
42 {\r
43   int length = strlen(takeText);\r
44   mytext = new char[length + 1];\r
45   strcpy(mytext, takeText);\r
46 }\r
47 \r
48 void WButton::setActive(UCHAR tactive)\r
49 {\r
50   dimmed = false;\r
51   active = tactive;\r
52 }\r
53 \r
54 void WButton::dim()\r
55 {\r
56   // a bolt on for now - an active but dimmed state\r
57   dimmed = true;\r
58   active = false;\r
59 }\r
60 \r
61 void WButton::draw()\r
62 {\r
63   if (dimmed)\r
64   {\r
65     fillColour(DrawStyle::BLACK);\r
66     drawTextCentre(mytext, area.w / 2, 0, DrawStyle::SELECTHIGHLIGHT);\r
67   }\r
68   else if (active)\r
69   {\r
70     fillColour(DrawStyle::SELECTHIGHLIGHT);\r
71     drawTextCentre(mytext, area.w / 2, 0, DrawStyle::DARKTEXT);\r
72   }\r
73   else\r
74   {\r
75     fillColour(DrawStyle::BUTTONBACKGROUND);\r
76     drawTextCentre(mytext, area.w / 2, 0, DrawStyle::LIGHTTEXT);\r
77   }\r
78 }\r
79 \r
80 void WButton::setTag(int newTag)\r
81 {\r
82   tag = newTag;\r
83 }\r
84 \r
85 int WButton::getTag()\r
86 {\r
87   return tag;\r
88 }\r
89 \r
90 // Sorry, I've broken these in the boxx upgrade - chris\r
91 \r
92 bool WButton::mouseMove(int x, int y)\r
93 {\r
94   if ((x-getRootBoxOffsetX())>=0 && (y-getRootBoxOffsetY())>=0\r
95     && (x-getRootBoxOffsetX())<=(int)area.w && (y-getRootBoxOffsetY())<=(int)area.h && !active)\r
96   {\r
97     setActive(1);\r
98     return true;\r
99   }\r
100   return false;\r
101 }\r
102 \r
103 bool WButton::mouseLBDOWN(int x, int y)\r
104 {\r
105   if ((x-getRootBoxOffsetX())>=0 && (y-getRootBoxOffsetY())>=0\r
106     && (x-getRootBoxOffsetX())<=(int)area.w && (y-getRootBoxOffsetY())<=(int)area.h && active)\r
107   {\r
108     return true;\r
109   }\r
110   return false;\r
111 }\r