#define MASK_A 0xFF000000
#endif
+// Debugging...
+//#define DEBUG_GUI_BUTTON
+#ifdef DEBUG_GUI_BUTTON
+#include "log.h"
+#endif
+
//
// Button class implementation
//
}
Button::Button(uint32 x, uint32 y, std::string s, Element * parent/*= NULL*/):
- Element(x, y, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, parent),
+ Element(x, y, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xCF, 0x00, 0xFF, parent),
activated(false), clicked(false), inside(false),
buttonUp(NULL), buttonDown(NULL), buttonHover(NULL), surfacesAreLocal(true),
activatedSave(false), clickedSave(false), insideSave(false)
buttonHover = SDL_CreateRGBSurface(SDL_SWSURFACE, extents.w, extents.h, 32,
MASK_R, MASK_G, MASK_B, MASK_A);
+//bleh
+uint8 r1, g1, b1, a1;
+SDL_GetRGBA(fgColor, screen->format, &r1, &g1, &b1, &a1);
+fgColor = SDL_MapRGBA(buttonUp->format, r1, g1, b1, a1);
+SDL_GetRGBA(bgColor, screen->format, &r1, &g1, &b1, &a1);
+bgColor = SDL_MapRGBA(buttonUp->format, r1, g1, b1, a1);
+fgColorHL = SDL_MapRGBA(buttonUp->format, 0xFF, 0xFF, 0xFF, 0xFF);
+bgColorHL = SDL_MapRGBA(buttonUp->format, 0x4F, 0xFF, 0x4F, 0xFF);
+//helb
+
// Need to create backgrounds before we do this stuff...
SDL_FillRect(buttonUp, NULL, bgColor);
SDL_FillRect(buttonDown, NULL, fgColor);
- SDL_FillRect(buttonHover, NULL, bgColor);
+ SDL_FillRect(buttonHover, NULL, bgColorHL);
DrawStringTrans(buttonUp, GetFontWidth(), 0, fgColor, s.c_str());
DrawStringTrans(buttonDown, GetFontWidth(), 0, fgColor, s.c_str());
- DrawStringTrans(buttonHover, GetFontWidth(), 0, fgColor, s.c_str());
+ DrawStringTrans(buttonHover, GetFontWidth(), 0, fgColorHL, s.c_str());
+
+#ifdef DEBUG_GUI_BUTTON
+ WriteLog("Button::Button()...\n");
+ WriteLog("\tbuttonUp w/h = %u/%u\n", buttonUp->w, buttonUp->h);
+ WriteLog("\tbuttonDown w/h = %u/%u\n", buttonDown->w, buttonDown->h);
+ WriteLog("\tbuttonHover w/h = %u/%u\n", buttonHover->w, buttonHover->h);
+#endif
}
Button::~Button()
void Button::Draw(void)
{
+#ifdef DEBUG_GUI_BUTTON
+ WriteLog("Button::Draw()...\n");
+#endif
if (buttonUp == NULL)
return; // Bail out if no surface was created...
picToShow = buttonDown;
SDL_Rect rect = GetScreenCoords();
+#ifdef DEBUG_GUI_BUTTON
+ WriteLog(" coords: x=%u, y=%u\n", rect.x, rect.y);
+ WriteLog(" picToShow=%08X\n", picToShow);
+#endif
//Need to do coverage list blitting here, to avoid unnecessary drawing when doing mouseovers
//Also, need to add suport in Gui()...
SDL_BlitSurface(picToShow, NULL, screen, &rect); // This handles alpha blending too! :-D
+#ifdef DEBUG_GUI_BUTTON
+ WriteLog(" width: w=%u, h=%u\n", rect.w, rect.h);
+#endif
needToRefreshScreen = true;
+
+#ifdef DEBUG_GUI_BUTTON
+// SDL_FillRect(screen, &extents, fgColor);
+#endif
}
void Button::Notify(Element *)
//#define DESTRUCTOR_TESTING
// Rendering experiment...
-#define USE_COVERAGE_LISTS
+//BAH
+//#define USE_COVERAGE_LISTS
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define MASK_R 0xFF000000
MASK_R, MASK_G, MASK_B, MASK_A))
{
//Could probably move this into the initializer list as well...
- closeButton = new Button(w - (cbWidth + 1), 1, cbUp, cbHover, cbDown, this);
- list.push_back(closeButton);
+// closeButton = new Button(w - (cbWidth + 1), 1, cbUp, cbHover, cbDown, this);
+// list.push_back(closeButton);
CreateBackstore();
Draw(); // Can we do this in the constructor??? Mebbe.
void Window::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
{
+#if 1
// Handle the items this window contains...
for(uint32 i=0; i<list.size(); i++)
// Make coords relative to upper right corner of this window...
list[i]->HandleMouseButton(x - extents.x, y - extents.y, mouseDown);
+#else //? This works in draggablewindow2...
+ // Handle the items this window contains...
+ for(uint32 i=0; i<list.size(); i++)
+ {
+ // Make coords relative to upper right corner of this window...
+ list[i]->HandleMouseButton(x - extents.x, y - extents.y, mouseDown);
+
+ if (list[i]->Inside(x - extents.x, y - extents.y))
+ clicked = false;
+ }
+#endif
}
void Window::Draw(void)
#endif
//Prolly don't need this since the close button will do this for us...
+//Close button isn't mandatory anymore...
needToRefreshScreen = true;
}
+// This is only called if a close button has been added
void Window::Notify(Element * e)
{
if (e == closeButton)
{
list.push_back(e);
}
+
+void Window::AddCloseButton(void)
+{
+ // Only allow this to happen once!
+ if (closeButton == NULL)
+ {
+ closeButton = new Button(extents.w - (cbWidth + 1), 1, cbUp, cbHover, cbDown, this);
+ list.push_back(closeButton);
+ }
+}