More GUI refinements, added "text" control

This commit is contained in:
Shamus Hammons 2009-02-02 15:25:25 +00:00
parent 3cff304619
commit a13cd9b31d
8 changed files with 115 additions and 1 deletions

View File

@ -78,6 +78,7 @@ OBJS = \
obj/gui.o \
obj/guimisc.o \
obj/menu.o \
obj/text.o \
obj/textedit.o \
obj/window.o \
\

View File

@ -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 };

View File

@ -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;

View File

@ -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
/*

View File

@ -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__

View File

@ -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
@ -37,6 +39,15 @@
#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()

28
src/gui/text.cpp Normal file
View File

@ -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());
}

29
src/gui/text.h Normal file
View File

@ -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__