From b8c7736999a83e35498314010136335033393583 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 16 Dec 2013 19:27:51 -0600 Subject: [PATCH] Added missing files. :-P --- apple2.cfg | 6 +- src/gui/diskselector.cpp | 238 +++++++++++++++++++++++++++++++++++++++ src/gui/diskselector.h | 29 +++++ 3 files changed, 270 insertions(+), 3 deletions(-) create mode 100644 src/gui/diskselector.cpp create mode 100644 src/gui/diskselector.h diff --git a/apple2.cfg b/apple2.cfg index be2aca1..31500bd 100644 --- a/apple2.cfg +++ b/apple2.cfg @@ -32,7 +32,7 @@ autoSaveState = 1 #floppyImage1 = ./disks/Oregon Trail (Disk 1 of 2).dsk #floppyImage2 = ./disks/Oregon Trail (Disk 2 of 2).dsk # Yes -#floppyImage1 = ./disks/bt1_boot.dsk +floppyImage1 = ./disks/bt1_boot.dsk # Yes #floppyImage1 = ./disks/bt2_boot.dsk # Yes @@ -79,8 +79,8 @@ autoSaveState = 1 #floppyImage2 = ./disks/u2master-jlh.dsk #floppyImage2 = ./disks/u2player-jlh.dsk # Yes -floppyImage1 = ./disks/Ultima_II_-_Program_Disk.dsk -floppyImage2 = ./disks/Ultima_II_-_Player_Disk-jlh.dsk +#floppyImage1 = ./disks/Ultima_II_-_Program_Disk.dsk +#floppyImage2 = ./disks/Ultima_II_-_Player_Disk-jlh.dsk # Yes #floppyImage1 = ./disks/TheHeist.dsk # Yes diff --git a/src/gui/diskselector.cpp b/src/gui/diskselector.cpp new file mode 100644 index 0000000..45f86f7 --- /dev/null +++ b/src/gui/diskselector.cpp @@ -0,0 +1,238 @@ +// +// diskselector.cpp +// +// Floppy disk selector GUI +// by James Hammons +// +// JLH = James Hammons +// +// WHO WHEN WHAT +// --- ---------- ------------------------------------------------------------ +// JLH 10/13/2013 Created this file +// +// STILL TO DO: +// +// + +#include "diskselector.h" +#include +#include +#include +#include +#include "font14pt.h" +#include "log.h" +#include "settings.h" +#include "video.h" + +// +// Case insensitve string comparison voodoo +// +struct ci_char_traits : public std::char_traits +{ + static bool eq(char c1, char c2) { return toupper(c1) == toupper(c2); } + static bool ne(char c1, char c2) { return toupper(c1) != toupper(c2); } + static bool lt(char c1, char c2) { return toupper(c1) < toupper(c2); } + static int compare(const char * s1, const char * s2, size_t n) + { + while (n-- != 0) + { + if (toupper(*s1) < toupper(*s2)) return -1; + if (toupper(*s1) > toupper(*s2)) return 1; + ++s1; ++s2; + } + return 0; + } + static const char * find(const char * s, int n, char a) + { + while (n-- > 0 && toupper(*s) != toupper(a)) + { + ++s; + } + return s; + } +}; + +typedef std::basic_string ci_string; +// +// END Case insensitve string comparison voodoo +// + + +static SDL_Texture * window = NULL; +static SDL_Texture * charStamp = NULL; +static uint32_t windowPixels[400 * 300]; +static uint32_t stamp[FONT_WIDTH * FONT_HEIGHT]; +bool DiskSelector::showWindow = false; +std::vector imageList; + + +void DiskSelector::Init(SDL_Renderer * renderer) +{ + window = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, + SDL_TEXTUREACCESS_TARGET, 400, 300); +// charStamp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, + charStamp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, + SDL_TEXTUREACCESS_TARGET, FONT_WIDTH, FONT_HEIGHT); + + if (!window) + { + WriteLog("GUI (DiskSelector): Could not create window!\n"); + return; + } + + if (SDL_SetTextureBlendMode(window, SDL_BLENDMODE_BLEND) == -1) + WriteLog("GUI (DiskSelector): Could not set blend mode for window.\n"); + + if (SDL_SetTextureBlendMode(charStamp, SDL_BLENDMODE_BLEND) == -1) + WriteLog("GUI (DiskSelector): Could not set blend mode for charStamp.\n"); + + for(uint32_t i=0; i<400*300; i++) + windowPixels[i] = 0xB000FF00; + + SDL_UpdateTexture(window, NULL, windowPixels, 128 * sizeof(Uint32)); + FindDisks(NULL); + DrawFilenames(renderer); +} + + +void DiskSelector::FindDisks(const char * path) +{ + DIR * dir = opendir(settings.disksPath); + + if (!dir) + { + WriteLog("GUI (DiskSelector)::FindDisks: Could not open directory \"%s\%!\n", settings.disksPath); + return; + } + + imageList.clear(); + dirent * ent; + + while ((ent = readdir(dir)) != NULL) + { + if (HasLegalExtension(ent->d_name)) + imageList.push_back(ci_string(ent->d_name)); + } + + closedir(dir); + std::sort(imageList.begin(), imageList.end()); +#if 0 +{ + std::vector::iterator i; + for(i=imageList.begin(); i!=imageList.end(); i++) + printf("GUI::DS::Found \"%s\"\n", (*i).c_str()); +} +#endif +} + + +bool DiskSelector::HasLegalExtension(const char * name) +{ + const char * ext = strrchr(name, '.'); + + if ((strcasecmp(ext, ".dsk") == 0) || (strcasecmp(ext, ".do") == 0) + || (strcasecmp(ext, ".po") == 0) || (strcasecmp(ext, ".nib") == 0)) + return true; + + return false; +} + + +void DiskSelector::DrawFilenames(SDL_Renderer * renderer) +{ + if (SDL_SetRenderTarget(renderer, window) < 0) + { + WriteLog("GUI: Could not set Render Target to overlay... (%s)\n", SDL_GetError()); + return; + } + + // 3 columns of 16 chars apiece (with 8X16 font), 18 rows + + int count = 0; + + while (count < imageList.size()) + { + int currentX = (count / 18) * 17; + int currentY = (count % 18); + + for(unsigned int i=0; i<16; i++) + { + if (i >= imageList[count].length()) + break; + + DrawCharacter(renderer, currentX + i, currentY, imageList[count][i]); + } + + count++; + + if (count >= (18 * 3)) + break; + } + + // Set render target back to default + SDL_SetRenderTarget(renderer, NULL); +} + + +void DiskSelector::DrawCharacter(SDL_Renderer * renderer, int x, int y, uint8_t c) +{ +#if 0 +// uint32_t pixel = 0xFF7F0000; + uint8_t * ptr = (uint8_t *)&font2[(c - 0x20) * FONT_WIDTH * FONT_HEIGHT]; + + for(int j=0; j +#include + +class DiskSelector +{ + public: + DiskSelector() {} + ~DiskSelector() {} + + // Everything is class methods/variables + static void Init(SDL_Renderer *); + static void FindDisks(const char *); + static bool HasLegalExtension(const char *); + static void DrawFilenames(SDL_Renderer *); + static void DrawCharacter(SDL_Renderer *, int, int, uint8_t); + static void MouseDown(int32_t, int32_t, uint32_t); + static void MouseUp(int32_t, int32_t, uint32_t); + static void MouseMove(int32_t, int32_t, uint32_t); + static void Render(SDL_Renderer *); + + public: + static bool showWindow; +}; + +#endif // __DISKSELECTOR_H__ +