X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fbutton.cpp;h=8d69fbda044a9b025a88a0b7d0ed2d975f615297;hb=f36d026c7b8b398b88765ec5b67a3c767fe5fbad;hp=b5af684a92c9e1d0492116f514fc5568c1fc7bec;hpb=eeb2935c12ef41a63049126748c2574b324403a5;p=apple2 diff --git a/src/gui/button.cpp b/src/gui/button.cpp old mode 100755 new mode 100644 index b5af684..8d69fbd --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -2,9 +2,9 @@ // BUTTON.CPP // // Graphical User Interface button class -// by James L. Hammons +// by James Hammons // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ @@ -26,6 +26,12 @@ #define MASK_A 0xFF000000 #endif +// Debugging... +//#define DEBUG_GUI_BUTTON +#ifdef DEBUG_GUI_BUTTON +#include "log.h" +#endif + // // Button class implementation // @@ -36,7 +42,7 @@ Some notes about this class: - Button colors are hardwired (for plain text buttons) */ -Button::Button(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*/, +Button::Button(uint32_t x/*= 0*/, uint32_t y/*= 0*/, uint32_t w/*= 0*/, uint32_t h/*= 0*/, Element * parent/*= NULL*/): Element(x, y, w, h, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, parent), activated(false), clicked(false), inside(false), @@ -46,7 +52,7 @@ Button::Button(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0* // Should we make a local button bitmap here? } -Button::Button(uint32 x, uint32 y, uint32 w, uint32 h, SDL_Surface * upImg, Element * parent/*= NULL*/): +Button::Button(uint32_t x, uint32_t y, uint32_t w, uint32_t h, SDL_Surface * upImg, Element * parent/*= NULL*/): Element(x, y, w, h, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, parent), activated(false), clicked(false), inside(false), buttonUp(upImg), buttonDown(NULL), buttonHover(NULL), surfacesAreLocal(false), @@ -55,7 +61,7 @@ Button::Button(uint32 x, uint32 y, uint32 w, uint32 h, SDL_Surface * upImg, Elem // if (upImg == NULL) // return; // -// uint32 width = ((Bitmap *)upImg)->width, height = ((Bitmap *)upImg)->height; +// uint32_t width = ((Bitmap *)upImg)->width, height = ((Bitmap *)upImg)->height; // // buttonUp = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, // 32, MASK_R, MASK_G, MASK_B, MASK_A); @@ -64,7 +70,7 @@ Button::Button(uint32 x, uint32 y, uint32 w, uint32 h, SDL_Surface * upImg, Elem // Should we make a local button bitmap here? NO--it's passed in! } -Button::Button(uint32 x, uint32 y, SDL_Surface * bU, SDL_Surface * bH/*= NULL*/, +Button::Button(uint32_t x, uint32_t y, SDL_Surface * bU, SDL_Surface * bH/*= NULL*/, SDL_Surface * bD/*= NULL*/, Element * parent/*= NULL*/): Element(x, y, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, parent), activated(false), clicked(false), inside(false), @@ -76,7 +82,7 @@ Button::Button(uint32 x, uint32 y, SDL_Surface * bU, SDL_Surface * bH/*= NULL*/, extents.h = buttonUp->h; } -Button::Button(uint32 x, uint32 y, uint32 w, uint32 h, std::string s, Element * parent/*= NULL*/): +Button::Button(uint32_t x, uint32_t y, uint32_t w, uint32_t h, std::string s, Element * parent/*= NULL*/): Element(x, y, w, h, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, parent), activated(false), clicked(false), inside(false), buttonUp(NULL), buttonDown(NULL), buttonHover(NULL), surfacesAreLocal(true), @@ -85,8 +91,8 @@ Button::Button(uint32 x, uint32 y, uint32 w, uint32 h, std::string s, Element * // Create the button surfaces here... } -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), +Button::Button(uint32_t x, uint32_t y, std::string s, Element * parent/*= NULL*/): + 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) @@ -103,14 +109,31 @@ Button::Button(uint32 x, uint32 y, std::string s, Element * parent/*= NULL*/): buttonHover = SDL_CreateRGBSurface(SDL_SWSURFACE, extents.w, extents.h, 32, MASK_R, MASK_G, MASK_B, MASK_A); +//bleh +uint8_t 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() @@ -128,19 +151,25 @@ Button::~Button() } } -void Button::HandleKey(SDLKey key) +void Button::HandleKey(SDL_Scancode key) { } -void Button::HandleMouseMove(uint32 x, uint32 y) +void Button::HandleMouseMove(uint32_t x, uint32_t y) { + if (!visible) + return; + SaveStateVariables(); inside = Inside(x, y); CheckStateAndRedrawIfNeeded(); } -void Button::HandleMouseButton(uint32 x, uint32 y, bool mouseDown) +void Button::HandleMouseButton(uint32_t x, uint32_t y, bool mouseDown) { + if (!visible) + return; + SaveStateVariables(); if (inside) @@ -165,6 +194,12 @@ void Button::HandleMouseButton(uint32 x, uint32 y, bool mouseDown) void Button::Draw(void) { +#ifdef DEBUG_GUI_BUTTON + WriteLog("Button::Draw()...\n"); +#endif + if (!visible) + return; + if (buttonUp == NULL) return; // Bail out if no surface was created... @@ -179,12 +214,23 @@ void Button::Draw(void) 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 *) @@ -209,3 +255,15 @@ void Button::CheckStateAndRedrawIfNeeded(void) if (activated != activatedSave || clicked != clickedSave || inside != insideSave) Draw(); } + +void Button::SetText(std::string s) +{ + // Need to create backgrounds before we do this stuff... + SDL_FillRect(buttonUp, NULL, bgColor); + SDL_FillRect(buttonDown, NULL, fgColor); + 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, fgColorHL, s.c_str()); +}