From 6ad6896385a2068046fb779db2f8f27f537d71f4 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Tue, 3 Feb 2009 05:30:08 +0000 Subject: [PATCH] diskwindow is *almost* usable! --- src/floppy.cpp | 27 +++++++++++++++++++++++++++ src/floppy.h | 2 ++ src/gui/text.cpp | 5 +++++ src/gui/text.h | 1 + src/gui/window.cpp | 18 ++++++++++++++---- src/gui/window.h | 2 ++ 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/floppy.cpp b/src/floppy.cpp index dc558cf..56ea414 100755 --- a/src/floppy.cpp +++ b/src/floppy.cpp @@ -146,6 +146,8 @@ bool FloppyDrive::SaveImage(uint8 driveNum/*= 0*/) fwrite(disk[driveNum], 1, diskSize[driveNum], fp); fclose(fp); + WriteLog("FLOPPY: Successfully wrote image file '%s'...\n", imageName[driveNum]); + return true; } @@ -499,6 +501,31 @@ const char * FloppyDrive::GetImageName(uint8 driveNum/*= 0*/) return nameBuf; } +void FloppyDrive::EjectImage(uint8 driveNum/*= 0*/) +{ + // Probably want to save a dirty image... ;-) + SaveImage(driveNum); + + WriteLog("FLOPPY: Ejected image file '%s' from drive %u...\n", imageName[driveNum], driveNum); + + if (disk[driveNum]) + delete[] disk[driveNum]; + + disk[driveNum] = NULL; + diskSize[driveNum] = 0; + diskType[driveNum] = DT_UNKNOWN; + imageDirty[driveNum] = false; + imageName[driveNum][0] = 0; // Zero out filenames + memset(nybblizedImage[driveNum], 0xFF, 232960); // Doesn't matter if 00s or FFs... + +} + +bool FloppyDrive::DriveIsEmpty(uint8 driveNum/*= 0*/) +{ + // This is kinda gay, but it works + return (imageName[driveNum][0] == 0 ? true : false); +} + // Memory mapped I/O functions diff --git a/src/floppy.h b/src/floppy.h index 2904343..7fe310f 100755 --- a/src/floppy.h +++ b/src/floppy.h @@ -28,6 +28,8 @@ class FloppyDrive void CreateBlankImage(uint8 driveNum = 0); void SwapImages(void); const char * GetImageName(uint8 driveNum = 0); + void EjectImage(uint8 driveNum = 0); + bool DriveIsEmpty(uint8 driveNum = 0); // I/O functions ($C0Ex accesses) diff --git a/src/gui/text.cpp b/src/gui/text.cpp index cd65a6a..d149035 100644 --- a/src/gui/text.cpp +++ b/src/gui/text.cpp @@ -29,3 +29,8 @@ void Text::Draw(void) DrawStringOpaque(screen, r.x, r.y, fgColor, bgColor, "%s", text.c_str()); } } + +void Text::SetText(std::string s) +{ + text = s; +} diff --git a/src/gui/text.h b/src/gui/text.h index 696fd46..df3614b 100644 --- a/src/gui/text.h +++ b/src/gui/text.h @@ -20,6 +20,7 @@ class Text: public Element virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown) {} virtual void Draw(void); virtual void Notify(Element *) {} + void SetText(std::string s); protected: // uint32 fgColor, bgColor; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 9298cf9..28c0212 100755 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -52,7 +52,7 @@ 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); @@ -130,9 +130,14 @@ void Window::Draw(void) for(uint32 i=0; iDraw(); #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