9 //#include "font14pt.h"
12 // Various constructors
14 Button::Button(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*/):
15 Element(x, y, w, h), activated(false), clicked(false), inside(false),
16 fgColor(0xFFFFFFFF), bgColor(0xFF00FF00), pic(NULL), elementToTell(NULL)
20 Button::Button(uint32 x, uint32 y, uint32 w, uint32 h, uint32 * p):
21 Element(x, y, w, h), activated(false), clicked(false), inside(false),
22 fgColor(0xFFFFFFFF), bgColor(0xFF00FF00), pic(p), elementToTell(NULL)
26 // Button::Button(uint32 x, uint32 y, uint32 * p): Element(x, y, 0, 0),
28 Button::Button(uint32 x, uint32 y, uint32 * p, uint32 * pH/*= NULL*/, uint32 * pD/*= NULL*/):
29 Element(x, y, 0, 0), activated(false), clicked(false), inside(false),
30 fgColor(0xFFFFFFFF), bgColor(0xFF00FF00), pic(p), picHover(pH), picDown(pD),
34 extents.w = pic[0], extents.h = pic[1];
37 Button::Button(uint32 x, uint32 y, uint32 w, uint32 h, std::string s):
38 Element(x, y, w, h), activated(false), clicked(false), inside(false),
39 fgColor(0xFFFFFFFF), bgColor(0xFF00FF00), pic(NULL), text(s), elementToTell(NULL)
43 Button::Button(uint32 x, uint32 y, std::string s):
44 Element(x, y, 0, FONT_HEIGHT), activated(false), clicked(false), inside(false),
45 fgColor(0xFFFFFFFF), bgColor(0xFF00FF00), pic(NULL), text(s), elementToTell(NULL)
47 extents.w = s.length() * FONT_WIDTH;
52 void Button::HandleMouseMove(uint32 x, uint32 y)
54 inside = Inside(x, y);
57 void Button::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
64 if (clicked && !mouseDown)
66 clicked = false, activated = true;
68 // Send a message that we're activated (if there's someone to tell, that is)
70 elementToTell->Notify(this);
74 clicked = activated = false;
77 void Button::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
79 uint32 addr = (extents.x + offsetX) + ((extents.y + offsetY) * pitch);
81 if (text.length() > 0) // Simple text button
84 for(uint32 y=0; y<extents.h; y++)
86 for(uint32 x=0; x<extents.w; x++)
88 // Doesn't clip in y axis! !!! FIX !!!
89 if (extents.x + x < pitch)
90 screenBuffer[addr + x + (y * pitch)]
91 // = (clicked && inside ? fgColor : (inside ? 0x43F0 : bgColor));
92 //43F0 -> 010000 11111 10000 -> 0100 0001 1111 1111 1000 0100 -> 41 FF 84
93 = (clicked && inside ? fgColor : (inside ? 0xFF84FF41 : bgColor));
97 DrawString(screenBuffer, extents.x + offsetX, extents.y + offsetY, false, "%s", text.c_str());
99 else // Graphical button
101 uint32 * picToShow = pic;
103 if (picHover != NULL && inside && !clicked)
104 picToShow = picHover;
106 if (picDown != NULL && inside && clicked)
109 DrawTransparentBitmapDeprecated(screenBuffer, extents.x + offsetX, extents.y + offsetY, picToShow);
113 bool Button::ButtonClicked(void)
118 void Button::SetNotificationElement(Element * e)