]> Shamusworld >> Repos - apple2/blobdiff - src/gui/window.cpp
Converted to SDL 2, added fullscreen toggle.
[apple2] / src / gui / window.cpp
index 0f460eaa8f428411b109870bd2eed0803fff8ac4..48e3db62241d1b308170149b517d2772884ee5ce 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
@@ -42,7 +43,7 @@
 // NOTE: FG/BG colors are hard-wired
 //
 
-Window::Window(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*/,
+Window::Window(uint32_t x/*= 0*/, uint32_t y/*= 0*/, uint32_t w/*= 0*/, uint32_t h/*= 0*/,
        void (* f)(Element *)/*= NULL*/):
        Element(x, y, w, h, 0x4D, 0xFF, 0x84, 0xFF, 0x1F, 0x84, 0x84, 0xFF), handler(f),
        cbWidth((closeBox[0] << 8) | closeBox[1]), cbHeight((closeBox[2] << 8) | closeBox[3]),
@@ -51,11 +52,11 @@ Window::Window(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*
        cbDown(SDL_CreateRGBSurfaceFrom(&closeBoxDown[4], cbWidth, cbHeight, 32, cbWidth * 4,
                MASK_R, MASK_G, MASK_B, MASK_A)),
        cbHover(SDL_CreateRGBSurfaceFrom(&closeBoxHover[4], cbWidth, cbHeight, 32, cbWidth * 4,
-               MASK_R, MASK_G, MASK_B, MASK_A))
+               MASK_R, MASK_G, MASK_B, MASK_A)), drawBackground(true)
 {
 //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.
@@ -66,7 +67,7 @@ Window::~Window()
 #ifdef DESTRUCTOR_TESTING
 printf("Inside ~Window()...\n");
 #endif
-       for(uint32 i=0; i<list.size(); i++)
+       for(uint32_t i=0; i<list.size(); i++)
                if (list[i])
                        delete list[i];
 
@@ -75,9 +76,9 @@ printf("Inside ~Window()...\n");
        SDL_FreeSurface(cbHover);
 }
 
-void Window::HandleKey(SDLKey key)
+void Window::HandleKey(SDL_Scancode key)
 {
-       if (key == SDLK_ESCAPE)
+       if (key == SDL_SCANCODE_ESCAPE)
        {
                SDL_Event event;
                event.type = SDL_USEREVENT, event.user.code = WINDOW_CLOSE;
@@ -85,24 +86,36 @@ void Window::HandleKey(SDLKey key)
        }
 
        // Handle the items this window contains...
-       for(uint32 i=0; i<list.size(); i++)
+       for(uint32_t i=0; i<list.size(); i++)
                list[i]->HandleKey(key);
 }
 
-void Window::HandleMouseMove(uint32 x, uint32 y)
+void Window::HandleMouseMove(uint32_t x, uint32_t y)
 {
        // Handle the items this window contains...
-       for(uint32 i=0; i<list.size(); i++)
+       for(uint32_t i=0; i<list.size(); i++)
                // Make coords relative to upper right corner of this window...
                list[i]->HandleMouseMove(x - extents.x, y - extents.y);
 }
 
-void Window::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
+void Window::HandleMouseButton(uint32_t x, uint32_t y, bool mouseDown)
 {
+#if 1
        // Handle the items this window contains...
-       for(uint32 i=0; i<list.size(); i++)
+       for(uint32_t 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_t 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)
@@ -114,22 +127,29 @@ void Window::Draw(void)
                SDL_FillRect(screen, &(*i), bgColor);
 
        // Handle the items this window contains...
-       for(uint32 i=0; i<list.size(); i++)
+       for(uint32_t i=0; i<list.size(); i++)
                list[i]->Draw();
 #else
-       // These are *always* top level and parentless, so no need to traverse up through
-       // the parent chain...
-       SDL_FillRect(screen, &extents, bgColor);
+       if (drawBackground)
+       {
+               // These are *always* top level and parentless, so no need to traverse up through
+               // the parent chain...
+               SDL_FillRect(screen, &extents, bgColor);
+       }
+       else
+               RestoreScreenFromBackstore();
 
        // Handle the items this window contains...
-       for(uint32 i=0; i<list.size(); i++)
+       for(uint32_t i=0; i<list.size(); i++)
                list[i]->Draw();
 #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 +166,18 @@ 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);
+       }
+}
+
+void Window::SetBackgroundDraw(bool state)
+{
+       drawBackground = state;
+}