]> Shamusworld >> Repos - apple2/commitdiff
GUI refactoring...
authorShamus Hammons <jlhamm@acm.org>
Fri, 30 Jan 2009 18:20:05 +0000 (18:20 +0000)
committerShamus Hammons <jlhamm@acm.org>
Fri, 30 Jan 2009 18:20:05 +0000 (18:20 +0000)
apple2.cfg
src/apple2.cpp
src/gui/button.cpp
src/gui/button.h
src/gui/gui.cpp
src/gui/window.cpp
src/gui/window.h

index d2bda19e42b53d2a6cde7091961afe3d6dd4c749..2762779184c32fde7eb64cdbc494e0e291e8dde1 100755 (executable)
@@ -24,7 +24,7 @@ autoSaveState = 1
 #floppyImage1 = ./disks/bt1_boot.dsk
 # Yes
 #floppyImage1 = ./disks/bt2_boot.dsk
-# Yes (but segfaults in the timer routine in the title screen)
+# Yes (but segfaults in the timer routine in the title screen--NB: Not anymore...)
 floppyImage1 = ./disks/bt3_boot_fixed.dsk
 floppyImage2 = ./disks/bt3_character_fixed.dsk
 # Yes
index 6b24271cc009ef9d84dbaee7f0fa802285a9d777..34e7f80a5f8d1a6cdd5ebd1b9f17fbb8a26c5d74 100755 (executable)
@@ -851,11 +851,13 @@ memcpy(ram + 0xD000, ram + 0xC000, 0x1000);
 
 //     gui = new GUI(surface);                                         // Set up the GUI system object...
        gui = new GUI(mainSurface);                                     // Set up the GUI system object...
+#if 0
        gui->AddMenuTitle("Apple2");
        gui->AddMenuItem("Test!", TestWindow/*, hotkey*/);
        gui->AddMenuItem("");
        gui->AddMenuItem("Quit", QuitEmulator, SDLK_q);
        gui->CommitItemsToMenu();
+#endif
 
        SetupBlurTable();                                                       // Set up the color TV emulation blur table
        running = true;                                                         // Set running status...
index b5af684a92c9e1d0492116f514fc5568c1fc7bec..731b0389a63f382f61c74abbc403e5ce3d770bba 100755 (executable)
 #define MASK_A 0xFF000000
 #endif
 
+// Debugging...
+//#define DEBUG_GUI_BUTTON
+#ifdef DEBUG_GUI_BUTTON
+#include "log.h"
+#endif
+
 //
 // Button class implementation
 //
@@ -86,7 +92,7 @@ Button::Button(uint32 x, uint32 y, uint32 w, uint32 h, std::string s, Element *
 }
 
 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)
@@ -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 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()
@@ -165,6 +188,9 @@ void Button::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
 
 void Button::Draw(void)
 {
+#ifdef DEBUG_GUI_BUTTON
+       WriteLog("Button::Draw()...\n");
+#endif
        if (buttonUp == NULL)
                return;                                                                 // Bail out if no surface was created...
 
@@ -179,12 +205,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 *)
index 8009486f0bf6c0c75460f04de218542df32ba91a..0f73b7bad6d6c4942b7436eb4d43085c2f73b4d9 100755 (executable)
@@ -35,6 +35,8 @@ class Button: public Element
        protected:
                bool activated, clicked, inside;
                SDL_Surface * buttonUp, * buttonDown, * buttonHover;
+               uint32 fgColorHL;
+               uint32 bgColorHL;
 
        private:
                bool surfacesAreLocal;
index fa652146737a3f0a8ebc3c513c89f772b59ec02c..408f4b02be28321cdda3e7f56f8559739b94cbc0 100755 (executable)
@@ -21,6 +21,7 @@
 #include "gui.h"
 #include "menu.h"                                                              // Element class methods are pulled in here...
 #include "window.h"
+#include "button.h"
 #include "video.h"
 
 // Debug support
@@ -43,7 +44,9 @@ GUI::GUI(SDL_Surface * surface): menuItem(new MenuItems())
 //     windowList.push_back(new Menu());
 
 // Create drive windows, and config windows here...
-
+       windowList.push_back(new Window(30, 30, 200, 100));
+       windowList.push_back(new Window(30, 140, 200, 100));
+       windowList.push_back(new Button(30, 250, "Click!"));
 }
 
 GUI::~GUI()
@@ -96,6 +99,7 @@ void GUI::Run(void)
        SDL_EnableKeyRepeat(150, 75);
 
        // Initial update... [Now handled correctly in the constructor]
+       // Uh, still needed here, though... Only makes sense that it should
        for(i=windowList.begin(); i!=windowList.end(); i++)
                (*i)->Draw();
 
index 0f460eaa8f428411b109870bd2eed0803fff8ac4..9298cf97bc90d6be27d5e311ebdba384ba009ad0 100755 (executable)
@@ -22,7 +22,8 @@
 //#define DESTRUCTOR_TESTING
 
 // Rendering experiment...
-#define USE_COVERAGE_LISTS
+//BAH
+//#define USE_COVERAGE_LISTS
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
 #define MASK_R 0xFF000000
@@ -54,8 +55,8 @@ Window::Window(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*
                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.
@@ -99,10 +100,22 @@ void Window::HandleMouseMove(uint32 x, uint32 y)
 
 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)
@@ -127,9 +140,11 @@ 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)
@@ -146,3 +161,13 @@ void Window::AddElement(Element * e)
 {
        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);
+       }
+}
index 7ff215032fbb9dca36b16328332fa4c94e89dca9..24b478b9ac7a53a9308fc9d028514bc8951fd717 100755 (executable)
@@ -24,6 +24,7 @@ class Window: public Element
                virtual void Draw(void);
                virtual void Notify(Element *);
                void AddElement(Element * e);
+               void AddCloseButton(void);
 
        protected:
                void (* handler)(Element *);