]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui.cpp
Small change: CVS -> SVN in About dialog.
[virtualjaguar] / src / gui.cpp
index 28b626fb424996477573b239769d84fc8f225dc7..9c8ec59e80f39f6678d9016dc74875d5e5f0f52b 100644 (file)
@@ -5,6 +5,8 @@
 // by James L. Hammons
 //
 
+#include "gui.h"
+
 #include <stdarg.h>
 #include <sys/types.h>                                                         // For MacOS <dirent.h> dependency
 #include <dirent.h>
@@ -24,7 +26,9 @@
 #include "zlib.h"
 #include "unzip.h"
 #include "sdlemu_opengl.h"
-#include "gui.h"
+#include "log.h"
+#include "jaguar.h"
+#include "eeprom.h"
 
 using namespace std;                                                           // For STL stuff
 
@@ -36,7 +40,9 @@ class Window;                                                                         // Forward declaration...
 void DrawTransparentBitmapDeprecated(uint32 * screen, uint32 x, uint32 y, uint32 * bitmap);
 void DrawTransparentBitmap(uint32 * screen, uint32 x, uint32 y, const void * bitmap);
 void DrawBitmap(uint32 * screen, uint32 x, uint32 y, const void * bitmap);
-void ClearScreenRectangle(uint32 * screen, uint32 x, uint32 y, uint32 w, uint32 h);
+//Should call this FillScreenRectangle with a number representing the RGBA value to fill. !!! FIX !!!
+//void ClearScreenRectangle(uint32 * screen, uint32 x, uint32 y, uint32 w, uint32 h);
+void FillScreenRectangle(uint32 * screen, uint32 x, uint32 y, uint32 w, uint32 h, uint32 color);
 void DrawStringTrans(uint32 * screen, uint32 x, uint32 y, uint32 color, uint8 opacity, const char * text, ...);
 void DrawStringOpaque(uint32 * screen, uint32 x, uint32 y, uint32 color1, uint32 color2, const char * text, ...);
 void DrawString(uint32 * screen, uint32 x, uint32 y, bool invert, const char * text, ...);
@@ -66,7 +72,7 @@ bool exitGUI = false;                                                         // GUI (emulator) done variable
 int mouseX = 0, mouseY = 0;
 uint32 background[1280 * 256];                                         // GUI background buffer
 
-char separator[] = "--------------------------------------------------------";
+const char separator[] = "--------------------------------------------------------";
 
 //
 // Case insensitive string compare function
@@ -78,7 +84,7 @@ int stringCmpi(const string &s1, const string &s2)
        // Select the first element of each string:
        string::const_iterator p1 = s1.begin(), p2 = s2.begin();
 
-       while (p1 != s1.end() && p2 != s2.end())                // Don\92t run past the end
+       while (p1 != s1.end() && p2 != s2.end())                // Dont run past the end
        {
                if (toupper(*p1) != toupper(*p2))                       // Compare upper-cased chars
                        return (toupper(*p1) < toupper(*p2) ? -1 : 1);// Report which was lexically greater
@@ -214,7 +220,7 @@ void Button::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
                        {
                                // Doesn't clip in y axis! !!! FIX !!!
                                if (extents.x + x < pitch)
-                                       screenBuffer[addr + x + (y * pitch)] 
+                                       screenBuffer[addr + x + (y * pitch)]
 //                                     = (clicked && inside ? fgColor : (inside ? 0x43F0 : bgColor));
 //43F0 -> 010000 11111 10000 -> 0100 0001 1111 1111 1000 0100 -> 41 FF 84
                                                = (clicked && inside ? fgColor : (inside ? 0xFF84FF41 : bgColor));
@@ -327,7 +333,7 @@ void PushButton::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
                {
                        // Doesn't clip in y axis! !!! FIX !!!
                        if (extents.x + x < pitch)
-                               screenBuffer[addr + x + (y * pitch)] 
+                               screenBuffer[addr + x + (y * pitch)]
                                        = (clicked && inside ? fgColor : (inside ? 0x43F0 : bgColor));
                }
        }*/
@@ -593,9 +599,11 @@ class TextEdit: public Element
 {
        public:
                TextEdit(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = 0): Element(x, y, w, h),
-                       fgColor(0xFF8484FF), bgColor(0xFF84FF4D), text(""), caretPos(0) {}
-               TextEdit(uint32 x, uint32 y, string s, uint32 fg = 0xFF8484FF, uint32 bg = 0xFF84FF4D):
-                       Element(x, y, 0, 0), fgColor(fg), bgColor(bg), text(s), caretPos(0) {}
+                       fgColor(0xFF8484FF), bgColor(0xFF84FF4D), text(""), caretPos(0),
+                       maxScreenSize(10) {}
+               TextEdit(uint32 x, uint32 y, string s, uint32 mss = 10, uint32 fg = 0xFF8484FF,
+                       uint32 bg = 0xFF84FF4D): Element(x, y, 0, 0), fgColor(fg), bgColor(bg), text(s),
+                       caretPos(0), maxScreenSize(mss) {}
                virtual void HandleKey(SDLKey key);
                virtual void HandleMouseMove(uint32 x, uint32 y) {}
                virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown) {}
@@ -606,6 +614,7 @@ class TextEdit: public Element
                uint32 fgColor, bgColor;
                string text;
                uint32 caretPos;
+               uint32 maxScreenSize;
 };
 
 //Set different filters depending on type passed in on construction, e.g., filename, amount, etc...?
@@ -616,9 +625,11 @@ void TextEdit::HandleKey(SDLKey key)
        {
                //Need to handle shift key as well...
                text[caretPos++] = key;
+               Draw();
        }
        else if (key == SDLK_BACKSPACE)
        {
+
        }
        else if (key == SDLK_DELETE)
        {
@@ -629,8 +640,13 @@ void TextEdit::HandleKey(SDLKey key)
 void TextEdit::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
 {
        if (text.length() > 0)
+       {
+               FillScreenRectangle(screenBuffer, extents.x + offsetX, extents.y + offsetY, FONT_WIDTH * maxScreenSize, FONT_HEIGHT, bgColor);
 //             DrawString(screenBuffer, extents.x + offsetX, extents.y + offsetY, false, "%s", text.c_str());
                DrawStringOpaque(screenBuffer, extents.x + offsetX, extents.y + offsetY, fgColor, bgColor, "%s", text.c_str());
+       }
+
+       // Draw the caret (underscore? or vertical line?)
 }
 
 
@@ -935,14 +951,14 @@ FileList::FileList(uint32 x, uint32 y, uint32 w, uint32 h): Window(x, y, w, h)
                while ((de = readdir(dp)) != NULL)
                {
                        char * ext = strrchr(de->d_name, '.');
-       
+
                        if (ext != NULL)
                                if (strcasecmp(ext, ".zip") == 0 || strcasecmp(ext, ".j64") == 0
                                        || strcasecmp(ext, ".abs") == 0 || strcasecmp(ext, ".jag") == 0
                                        || strcasecmp(ext, ".rom") == 0)
                                        files->AddItem(string(de->d_name));
                }
-       
+
                closedir(dp);
        }
        else
@@ -1031,7 +1047,7 @@ class MenuItems
 class Menu: public Element
 {
        public:
-// 1CFF -> 0 001 11 00  111 1 1111 
+// 1CFF -> 0 001 11 00  111 1 1111
 // 421F -> 0 100 00 10  000 1 1111
                Menu(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = FONT_HEIGHT,
 /*                     uint16 fgc = 0x1CFF, uint16 bgc = 0x000F, uint16 fgch = 0x421F,
@@ -1585,16 +1601,17 @@ void DrawBitmap(uint32 * screen, uint32 x, uint32 y, const void * bitmap)
 }
 
 //
-// Clear a portion of the screen
+// Fill a portion of the screen with the passed in color
 //
-void ClearScreenRectangle(uint32 * screen, uint32 x, uint32 y, uint32 w, uint32 h)
+void FillScreenRectangle(uint32 * screen, uint32 x, uint32 y, uint32 w, uint32 h, uint32 color)
+//void ClearScreenRectangle(uint32 * screen, uint32 x, uint32 y, uint32 w, uint32 h)
 {
        uint32 pitch = sdlemuGetOverlayWidthInPixels();
        uint32 address = x + (y * pitch);
 
        for(uint32 yy=0; yy<h; yy++)
                for(uint32 xx=0; xx<w; xx++)
-                       *(screen + address + xx + (yy * pitch)) = 0;
+                       *(screen + address + xx + (yy * pitch)) = color;
 }
 
 
@@ -1672,7 +1689,7 @@ Bitmap ptr = { 6, 8, 4,
 //"000011112222333344445555"
 //"000011112222333344445555"
 //"000011112222333344445555"
-};//*/ 
+};//*/
        uint32 * overlayPixels = (uint32 *)sdlemuGetOverlayPixels();
        uint32 count = 2;
 
@@ -1985,7 +2002,7 @@ return NULL;//*/
                        DrawStringTrans(backbuffer, 8, 27*8, 0xFF1FFF3F, transparency, "CRC: %08X", jaguar_mainRom_crc32);
 
                        if (showMsgFrames == 0)
-                       {                       
+                       {
                                transparency++;
 
                                if (transparency == 33)
@@ -2057,7 +2074,7 @@ Window * RunEmu(void)
        else if (jaguar_mainRom_crc32 == 0x55A0669C)
                cartType = 3;
 
-       char * cartTypeName[5] = { "2M Cartridge", "4M Cartridge", "CD BIOS", "CD Dev BIOS", "Homebrew" };
+       const char * cartTypeName[5] = { "2M Cartridge", "4M Cartridge", "CD BIOS", "CD Dev BIOS", "Homebrew" };
        uint32 elapsedTicks = SDL_GetTicks(), frameCount = 0, framesPerSecond = 0;
 
        while (!finished)
@@ -2071,6 +2088,7 @@ Window * RunEmu(void)
 //     doDSPDis = true;
 
 //Problem: Need to do this *only* when the state changes from visible to not...
+//Also, need to clear out the GUI when not on (when showMessage is active...)
 if (showGUI || showMessage)
        sdlemuEnableOverlay();
 else
@@ -2081,7 +2099,7 @@ else
                // Some QnD GUI stuff here...
                if (showGUI)
                {
-                       ClearScreenRectangle(overlayPixels, 8, 1*FONT_HEIGHT, 128, 4*FONT_HEIGHT);
+                       FillScreenRectangle(overlayPixels, 8, 1*FONT_HEIGHT, 128, 4*FONT_HEIGHT, 0x00000000);
                        extern uint32 gpu_pc, dsp_pc;
                        DrawString(overlayPixels, 8, 1*FONT_HEIGHT, false, "GPU PC: %08X", gpu_pc);
                        DrawString(overlayPixels, 8, 2*FONT_HEIGHT, false, "DSP PC: %08X", dsp_pc);
@@ -2095,7 +2113,7 @@ else
                        DrawString2(overlayPixels, 8, 27*FONT_HEIGHT, 0x001FFF3F, transparency, "CRC: %08X", jaguar_mainRom_crc32);
 
                        if (showMsgFrames == 0)
-                       {                       
+                       {
                                transparency--;
 
                                if (transparency == 0)
@@ -2146,7 +2164,7 @@ Window * About(void)
 {
        char buf[512];
 //     sprintf(buf, "Virtual Jaguar CVS %s", __DATE__);
-       sprintf(buf, "CVS %s", __DATE__);
+       sprintf(buf, "SVN %s", __DATE__);
 //fprintf(fp, "VirtualJaguar v1.0.8 (Last full build was on %s %s)\n", __DATE__, __TIME__);
 //VirtualJaguar v1.0.8 (Last full build was on Dec 30 2004 20:01:31)
 //Hardwired, bleh... !!! FIX !!!
@@ -2189,6 +2207,11 @@ Window * MiscOptions(void)
        window->AddElement(new SlideSwitch(8, 120, (bool *)&vjs.glFilter, "Sharp", "Blurry"));
        window->AddElement(new SlideSwitch(8, 152, (bool *)&vjs.renderType, "Normal render", "TV style"));
 
+       window->AddElement(new TextEdit(88, 8, vjs.ROMPath, 20, 0xFF8484FF, 0xFF000000));
+
+/*TextEdit(uint32 x, uint32 y, string s, uint32 mss = 10, uint32 fg = 0xFF8484FF,
+       uint32 bg = 0xFF84FF4D): Element(x, y, 0, 0), fgColor(fg), bgColor(bg), text(s),
+       caretPos(0), maxScreenSize(mss) {}*/
 // Missing:
 // * BIOS path
 // * ROM path