]> Shamusworld >> Repos - apple2/commitdiff
More GUI refinements, added "text" control
authorShamus Hammons <jlhamm@acm.org>
Mon, 2 Feb 2009 15:25:25 +0000 (15:25 +0000)
committerShamus Hammons <jlhamm@acm.org>
Mon, 2 Feb 2009 15:25:25 +0000 (15:25 +0000)
Makefile
src/apple2.cpp
src/apple2.h
src/floppy.cpp
src/floppy.h
src/gui/gui.cpp
src/gui/text.cpp [new file with mode: 0644]
src/gui/text.h [new file with mode: 0644]

index 311d13e57afc14bfd06d2afe276efee39234aa9d..c0697cbc76ea16808f3008d6585ca7e52538258a 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -78,6 +78,7 @@ OBJS = \
        obj/gui.o             \
        obj/guimisc.o         \
        obj/menu.o            \
+       obj/text.o            \
        obj/textedit.o        \
        obj/window.o          \
                           \
index 34e7f80a5f8d1a6cdd5ebd1b9f17fbb8a26c5d74..fa7323a6d217adb2a8ddfb32a6a87b32c0432409 100755 (executable)
@@ -62,13 +62,14 @@ uint8 ram[0x10000], rom[0x10000];                           // RAM & ROM spaces
 uint8 diskRom[0x100];                                                  // Disk ROM space
 V65C02REGS mainCPU;
 uint8 appleType = APPLE_TYPE_II;
+FloppyDrive floppyDrive;
 
 // Local variables
 
 static uint8 lastKeyPressed = 0;
 static bool keyDown = false;
 
-static FloppyDrive floppyDrive;
+//static FloppyDrive floppyDrive;
 
 enum { LC_BANK_1, LC_BANK_2 };
 
index cff8eedce4537f1a212014aace7affeba38b27f2..65fae5cd68f0cd24f25e883ffde6ee9d81907d4c 100755 (executable)
@@ -3,6 +3,7 @@
 //
 
 #include "types.h"
+#include "floppy.h"
 
 enum { APPLE_TYPE_II, APPLE_TYPE_IIE, APPLE_TYPE_IIC };
 
@@ -10,3 +11,4 @@ enum { APPLE_TYPE_II, APPLE_TYPE_IIE, APPLE_TYPE_IIC };
 
 extern uint8 ram[0x10000], rom[0x10000];               // RAM & ROM pointers
 extern uint8 appleType;
+extern FloppyDrive floppyDrive;
index 942ffd9b088a245b59639f26e8aab8056099a83f..dc558cf7959d3471ebd4a3ba57a5c967ebae1b1f 100755 (executable)
@@ -37,6 +37,7 @@ uint8 FloppyDrive::doSector[16] = {
        0x0, 0x7, 0xE, 0x6, 0xD, 0x5, 0xC, 0x4, 0xB, 0x3, 0xA, 0x2, 0x9, 0x1, 0x8, 0xF };
 uint8 FloppyDrive::poSector[16] = {
        0x0, 0x8, 0x1, 0x9, 0x2, 0xA, 0x3, 0xB, 0x4, 0xC, 0x5, 0xD, 0x6, 0xE, 0x7, 0xF };
+char FloppyDrive::nameBuf[MAX_PATH];
 
 // FloppyDrive class implementation...
 
@@ -462,6 +463,43 @@ void FloppyDrive::DenybblizeImage(uint8 driveNum)
        }
 }
 
+const char * FloppyDrive::GetImageName(uint8 driveNum/*= 0*/)
+{
+       // Set up a zero-length string for return value
+       nameBuf[0] = 0;
+
+       if (driveNum > 1)
+       {
+               WriteLog("FLOPPY: Attempted to get image name for drive #%u!\n", driveNum);
+               return nameBuf;
+       }
+
+       // Now we attempt to strip out extraneous paths/extensions to get just the filename
+       const char * startOfFile = strrchr(imageName[driveNum], '/');
+       const char * startOfExt = strrchr(imageName[driveNum], '.');
+
+       // If there isn't a path, assume we're starting at the beginning
+       if (startOfFile == NULL)
+               startOfFile = &imageName[driveNum][0];
+       else
+               startOfFile++;
+
+       // If there isn't an extension, assume it's at the terminating NULL
+       if (startOfExt == NULL)
+               startOfExt = &imageName[driveNum][0] + strlen(imageName[driveNum]);
+
+       // Now copy the filename (may copy nothing!)
+       int j = 0;
+
+       for(const char * i=startOfFile; i<startOfExt; i++)
+               nameBuf[j++] = *i;
+
+       nameBuf[j] = 0;
+
+       return nameBuf;
+}
+
+
 // Memory mapped I/O functions
 
 /*
index d0207ca8fb3d26ee66ad7a26418b8215bb361182..29043439b5b1ac826c0a998dc75beb012a31d78c 100755 (executable)
@@ -27,6 +27,7 @@ class FloppyDrive
                bool SaveImageAs(const char * filename, uint8 driveNum = 0);
                void CreateBlankImage(uint8 driveNum = 0);
                void SwapImages(void);
+               const char * GetImageName(uint8 driveNum = 0);
 
                // I/O functions ($C0Ex accesses)
 
@@ -64,6 +65,7 @@ class FloppyDrive
                static uint8 header[21];
                static uint8 doSector[16];
                static uint8 poSector[16];
+               static char nameBuf[MAX_PATH];
 };
 
 #endif // __FLOPPY_H__
index 408f4b02be28321cdda3e7f56f8559739b94cbc0..d61cfe4e620cd870b143a095754a3aa1d7a229c0 100755 (executable)
@@ -22,7 +22,9 @@
 #include "menu.h"                                                              // Element class methods are pulled in here...
 #include "window.h"
 #include "button.h"
+#include "text.h"
 #include "video.h"
+#include "apple2.h"
 
 // Debug support
 //#define 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
+
+*/
+
 
 GUI::GUI(SDL_Surface * surface): menuItem(new MenuItems())
 {
@@ -47,6 +58,8 @@ GUI::GUI(SDL_Surface * surface): menuItem(new MenuItems())
        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)));
 }
 
 GUI::~GUI()
diff --git a/src/gui/text.cpp b/src/gui/text.cpp
new file mode 100644 (file)
index 0000000..2dbae7e
--- /dev/null
@@ -0,0 +1,28 @@
+//
+// Static text class
+//
+// by James L. Hammons
+//
+
+#include "text.h"
+
+#include "guimisc.h"
+
+Text::Text(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*/, Element * parent/*= NULL*/):
+       Element(x, y, w, h, parent)
+{
+       fgColor = 0xFF8484FF, bgColor = 0xFF84FF4D;
+}
+
+Text::Text(uint32 x, uint32 y, std::string s, uint32 fg/*= 0xFF8484FF*/, uint32 bg/*= 0xFF84FF4D*/, Element * parent/*= NULL*/):
+       Element(x, y, 0, 0, parent), text(s)
+{
+       fgColor = fg, bgColor = bg;
+}
+
+void Text::Draw(void)
+{
+       if (text.length() > 0)
+//             DrawString(screenBuffer, extents.x + offsetX, extents.y + offsetY, false, "%s", text.c_str());
+               DrawStringOpaque(screen, extents.x, extents.y, fgColor, bgColor, "%s", text.c_str());
+}
diff --git a/src/gui/text.h b/src/gui/text.h
new file mode 100644 (file)
index 0000000..696fd46
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// Static text class
+//
+// by James L. Hammons
+//
+
+#ifndef __TEXT_H__
+#define __TEXT_H__
+
+#include <string>
+#include "element.h"
+
+class Text: public Element
+{
+       public:
+               Text(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = 0, Element * parent = NULL);
+               Text(uint32 x, uint32 y, std::string s, uint32 fg = 0xFF8484FF, uint32 bg = 0xFF84FF4D, Element * parent = NULL);
+               virtual void HandleKey(SDLKey key) {}
+               virtual void HandleMouseMove(uint32 x, uint32 y) {}
+               virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown) {}
+               virtual void Draw(void);
+               virtual void Notify(Element *) {}
+
+       protected:
+//             uint32 fgColor, bgColor;
+               std::string text;
+};
+
+#endif // __TEXT_H__