]> Shamusworld >> Repos - apple2/blobdiff - src/gui/gui.cpp
Add new files that makes this stuff work. D'oh!
[apple2] / src / gui / gui.cpp
index 2841992fc2ba07e8ddf2ab7cff55d1ee9f996067..7c6e219782d001fbd2c7c7680964c0abb341b267 100755 (executable)
 #include "gui.h"
 #include "menu.h"                                                              // Element class methods are pulled in here...
 #include "window.h"
+#include "button.h"
+#include "text.h"
+#include "diskwindow.h"
 #include "video.h"
+#include "apple2.h"
 
 // Debug support
-
 //#define DEBUG_MAIN_LOOP
 
+// New main screen buffering
+// This works, but the colors are rendered incorrectly. Also, it seems that there's
+// fullscreen blitting still going on--dragging the disk is fast at first but then
+// gets painfully slow. Not sure what's going on there.
+#define USE_NEW_MAINBUFFERING
+
 //#ifdef DEBUG_MAIN_LOOP
 #include "log.h"
 //#endif
 
+/*
+Work flow: Draw floppy drive.
+If disk in drive, MO shows eject graphic, otherwise show load graphic.
+If hit 'new blank image':
+       If disk in drive, ask if want to save if modified
+       else, load it
+If hit 'swap disks', swap disks.
+*/
+
 
-GUI::GUI(SDL_Surface * mainSurface): menuItem(new MenuItems())
+GUI::GUI(SDL_Surface * surface): menuItem(new MenuItems())
 {
-       windowList.push_back(new Menu());
-       Element::SetScreen(mainSurface);
+       Element::SetScreen(surface);
+//     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!"));
+       windowList.push_back(new Text(30, 20, floppyDrive.GetImageName(0)));
+       windowList.push_back(new Text(30, 130, floppyDrive.GetImageName(1)));
+       windowList.push_back(new DiskWindow(&floppyDrive, 240, 20));
 }
 
 GUI::~GUI()
@@ -88,15 +114,21 @@ 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();
 
+#ifndef USE_NEW_MAINBUFFERING
        RenderScreenBuffer();
+#else
+       FlipMainScreen();
+#endif
 
        // Main loop
        while (!exitGUI)
        {
-               if (SDL_PollEvent(&event))
+//             if (SDL_PollEvent(&event))
+               if (SDL_WaitEvent(&event))
                {
 #ifdef DEBUG_MAIN_LOOP
 WriteLog("An event was found!");
@@ -153,7 +185,11 @@ WriteLog(" -- SDL_USEREVENT\n");
 
 //Dirty rectangle is also possible...
                                else if (event.user.code == SCREEN_REFRESH_NEEDED)
+#ifndef USE_NEW_MAINBUFFERING
                                        RenderScreenBuffer();
+#else
+                                       FlipMainScreen();
+#endif
                        }
                        else if (event.type == SDL_ACTIVEEVENT)
                        {
@@ -161,7 +197,11 @@ WriteLog(" -- SDL_USEREVENT\n");
                                if (event.active.state == SDL_APPMOUSEFOCUS)
                                        showMouse = (event.active.gain ? true : false);
 
+#ifndef USE_NEW_MAINBUFFERING
                                RenderScreenBuffer();
+#else
+                                       FlipMainScreen();
+#endif
                        }
                        else if (event.type == SDL_KEYDOWN)
                        {
@@ -192,7 +232,7 @@ WriteLog(" -- SDL_MOUSEMOTION\n");
 //Though, it seems to screw other things up. Maybe it IS better to pass it to all windows?
 //Or maybe to just the ones that aren't completely obscured?
 //Probably. Right now, a disk's close button that should be obscured by one sitting on
-//top of it gets redrawn. Not good.
+//top of it gets redrawn. Not good. !!! FIX !!!
                                for(i=windowList.begin(); i!=windowList.end(); i++)
                                        (*i)->HandleMouseMove(mouse.x, mouse.y);
 //                             windowList.back()->HandleMouseMove(mouse.x, mouse.y);
@@ -215,7 +255,7 @@ We could do the following:
   than one is clicked on, take the one highest in the Z order (closer to the end
   of the list).
 
-- If item is highest in Z order, pack click through to window and exit.
+- If item is highest in Z order, pass click through to window and exit.
 
 - Otherwise, restore backing store on each window in reverse order.
 
@@ -257,7 +297,7 @@ it overlaps and just do restore/redraw for those that overlap. To wit:
                                                // iterator to a regular iterator requires backing the iterator
                                                // up a position after grabbing it's base() OR going forward
                                                // one position with the reverse iterator before grabbing base().
-                                               // Ugly, but it get the job done...
+                                               // Ugly, but it gets the job done...
                                                hit = (++ri).base();
                                                // Put it back where we found it, so the tests following this
                                                // don't fail...
@@ -347,9 +387,12 @@ Also, when doing a window drag, the coverage lists for all windows have to be re
 //*misses* to everyone else... Otherwise, you can have overlapping draggable windows
 //and be able to drag both by clicking on a point that intersects both...
 //(though that may be an interesting way to handle things!)
+//The thing is that you want to do it on purpose (like with a special grouping widget)
+//instead of by accident. So, !!! FIX !!!
                                // Pass the click on to all windows
-                               for(i=windowList.begin(); i!=windowList.end(); i++)
-                                       (*i)->HandleMouseButton(event.button.x, event.button.y, true);
+//                             for(i=windowList.begin(); i!=windowList.end(); i++)
+//                                     (*i)->HandleMouseButton(event.button.x, event.button.y, true);
+                               windowList.back()->HandleMouseButton(event.button.x, event.button.y, true);
 
 //                             // & bail if nothing changed...
                                if (movedWindow)
@@ -360,6 +403,8 @@ Also, when doing a window drag, the coverage lists for all windows have to be re
 //the Z order where the previous window was.
                                for(i=windowList.begin(); i!=windowList.end(); i++)
                                {
+//One other little quirk: Probably need to clear the backing store as well!
+//Not sure...
                                        (*i)->ResetCoverageList();
 
                                        // This looks odd, but it's just a consequence of iterator weirdness.
@@ -394,13 +439,21 @@ else
 
                        if (Element::ScreenNeedsRefreshing())
                        {
+#ifndef USE_NEW_MAINBUFFERING
 #ifdef DEBUG_MAIN_LOOP
 WriteLog("Screen refresh called!\n");
 #endif
                                RenderScreenBuffer();
                                Element::ScreenWasRefreshed();
+#else
+                               FlipMainScreen();
+                               Element::ScreenWasRefreshed();
+#endif
                        }
                }
+//hm. Works, but slows things way down.
+//Now we use WaitEvents() instead. Yay!
+//SDL_Delay(10);
        }
 
        SDL_EnableKeyRepeat(0, 0);