made most stuff in gui class protected, as it should be; moved internal definitions from gui.h to gui.cpp; added up/down arrows to save dialog (ugly, but better than nothing IMO

svn-id: r4234
This commit is contained in:
Max Horn 2002-05-08 00:27:09 +00:00
parent d3ceb767d8
commit 02a75c0521
5 changed files with 143 additions and 62 deletions

View File

@ -153,7 +153,7 @@ void Scumm::drawDirtyScreenParts()
}
/* Handle shaking */
if (_shakeEnabled && !_gui->_active) {
if (_shakeEnabled && !_gui->isActive()) {
_shakeFrame = (_shakeFrame + 1) & (NUM_SHAKE_POSITIONS - 1);
_system->set_shake_pos(shake_positions[_shakeFrame]);
}

120
gui.cpp
View File

@ -42,6 +42,39 @@ bool get_key_mapping;
uint16 _key_mapping_required;
#endif
enum {
GUI_NONE = 0,
GUI_RESTEXT = 1,
GUI_IMAGE = 2,
GUI_STAT = 3,
GUI_CUSTOMTEXT = 4,
GUI_VARTEXT = 5,
GUI_ACTIONTEXT = 6,
GUI_KEYTEXT = 7,
GUI_SCROLLTEXT = 8,
GUI_NEXTTEXT = 9,
GUI_UPDOWNARROW = 10
};
enum {
GWF_BORDER = 1,
GWF_CLEARBG = 2,
GWF_PARENT = 4,
GWF_DELAY = 8,
GWF_DEFAULT = GWF_BORDER|GWF_CLEARBG,
GWF_BUTTON = GWF_BORDER|GWF_CLEARBG|GWF_DELAY
};
struct GuiWidget {
byte _type;
byte _page;
byte _flags;
int16 _x,_y;
uint16 _w,_h;
uint16 _id;
byte _string_number;
};
enum {
SAVELOAD_DIALOG,
PAUSE_DIALOG,
@ -53,6 +86,33 @@ enum {
};
#define IMG_SIZE 8
// Triangles pointing up-/downwards, used for save/load dialog
static uint32 up_arrow[IMG_SIZE] = {
0x00011000,
0x00011000,
0x00100100,
0x00100100,
0x01000010,
0x01000010,
0x10000001,
0x10000001,
};
static uint32 down_arrow[IMG_SIZE] = {
0x10000001,
0x10000001,
0x01000010,
0x01000010,
0x00100100,
0x00100100,
0x00011000,
0x00011000,
};
void Gui::draw(int start, int end)
{
int i;
@ -111,6 +171,10 @@ void Gui::drawChar(const char str, int xx, int yy)
tmp = &guifont[0];
tmp += 224 + (str + 1) * 8;
byte *ptr = getBasePtr(xx, yy);
if (ptr == NULL)
return;
for (y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
unsigned char color;
@ -120,8 +184,10 @@ void Gui::drawChar(const char str, int xx, int yy)
}
color = ((buffer & mask) != 0);
if (color)
vline(xx + x, yy + y, yy + y);
ptr[x] = _color;
// vline(xx + x, yy + y, yy + y);
}
ptr += 320;
}
_color = tempc;
@ -169,7 +235,8 @@ void Gui::drawWidget(const GuiWidget * w)
case GUI_KEYTEXT:
case GUI_ACTIONTEXT:
case GUI_RESTEXT:
case GUI_NEXTTEXT:{
case GUI_NEXTTEXT:
{
char text[500];
text[0] = '\0';
@ -217,7 +284,40 @@ void Gui::drawWidget(const GuiWidget * w)
break;
}
case GUI_IMAGE:
;
break;
case GUI_UPDOWNARROW:
{
uint32 *data;
byte color = (_clickWidget && _clickWidget == w->_id) ? _textcolorhi : _textcolor;
if (w->_string_number == 0)
data = up_arrow;
else
data = down_arrow;
// Center the image
x += w->_w/2 - IMG_SIZE/2;
y += w->_h/2 - IMG_SIZE/2;
if (w->_flags & GWF_BORDER) {
x -= 4;
y -= 4;
}
byte *ptr = getBasePtr(x, y);
if (ptr == NULL)
return;
for (int y2 = 0; y2 < IMG_SIZE; y2++) {
uint32 mask = 0xF0000000;
for (int x2 = 0; x2 < IMG_SIZE; x2++) {
if (data[y2] & mask)
ptr[x2] = color;
mask >>= 4;
}
ptr += 320;
}
}
break;
}
}
@ -313,10 +413,10 @@ void Gui::lineto(int x, int y)
_curY = y;
if (x2 < x)
x2 ^= x ^= x2 ^= x;
x2 ^= x ^= x2 ^= x; // Swap x2 and x
if (y2 < y)
y2 ^= y ^= y2 ^= y;
y2 ^= y ^= y2 ^= y; // Swap y2 and y
ptr = getBasePtr(x, y);
@ -449,10 +549,10 @@ const GuiWidget save_load_dialog[] = {
{GUI_RESTEXT, 0x04, 0, 40, 5, 128, 16, 0, 3}, /* Name your SAVE game */
{GUI_STAT, 0xFF, GWF_DEFAULT, 6, 16, 170, 96, 0, 0},
{GUI_RESTEXT, 0x01, GWF_DEFAULT, 180, 20, 16, 40, 0, 0},
{GUI_RESTEXT, 0x01, GWF_DEFAULT, 180, 66, 16, 40, 0, 0},
{GUI_RESTEXT, 0xFE, GWF_DEFAULT, 180, 20, 16, 40, 1, 0},
{GUI_RESTEXT, 0xFE, GWF_DEFAULT, 180, 66, 16, 40, 2, 0},
{GUI_UPDOWNARROW, 0x01, GWF_BUTTON, 180, 20, 16, 40, 0, 0}, /* Up (dummy) */
{GUI_UPDOWNARROW, 0x01, GWF_BUTTON, 180, 66, 16, 40, 0, 1}, /* Down (dummy) */
{GUI_UPDOWNARROW, 0xFE, GWF_BUTTON, 180, 20, 16, 40, 1, 0}, /* Up */
{GUI_UPDOWNARROW, 0xFE, GWF_BUTTON, 180, 66, 16, 40, 2, 1}, /* Down */
{GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 20, 160, 10, 20, 0},
{GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 30, 160, 10, 21, 0},
@ -653,7 +753,7 @@ void Gui::handleCommand(int cmd)
getSavegameNames(_slotIndex - 9);
draw(20, 28);
return;
case 2:
case 2: /* down button */
if (_slotIndex > 80)
return;
getSavegameNames(_slotIndex + 9);

77
gui.h
View File

@ -21,56 +21,37 @@
#if !defined(gui_h)
#define gui_h
struct ResString {
int num;
char string[80];
};
enum {
GUI_NONE = 0,
GUI_RESTEXT = 1,
GUI_IMAGE = 2,
GUI_STAT = 3,
GUI_CUSTOMTEXT = 4,
GUI_VARTEXT = 5,
GUI_ACTIONTEXT = 6,
GUI_KEYTEXT = 7,
GUI_SCROLLTEXT = 8,
GUI_NEXTTEXT = 9
};
enum {
GWF_BORDER = 1,
GWF_CLEARBG = 2,
GWF_PARENT = 4,
GWF_DELAY = 8,
GWF_DEFAULT = GWF_BORDER|GWF_CLEARBG,
GWF_BUTTON = GWF_BORDER|GWF_CLEARBG|GWF_DELAY
};
struct GuiWidget {
byte _type;
byte _page;
byte _flags;
int16 _x,_y;
uint16 _w,_h;
uint16 _id;
byte _string_number;
};
// Forward declaration for GuiWidget
struct GuiWidget;
#define SAVEGAME_NAME_LEN 32
class Gui {
public:
byte _color,_shadowcolor;
byte _bgcolor;
byte _textcolor;
byte _textcolorhi;
// Init
void init(Scumm *s);
// Dialogs
void saveLoadDialog();
void pause();
void options();
void launcher();
void loop();
bool isActive() { return _active; }
protected:
Scumm *_s;
const GuiWidget *_widgets[4];
int _return_to;
int _curX, _curY;
VirtScreen *_vs;
byte _color,_shadowcolor;
byte _bgcolor;
byte _textcolor;
byte _textcolorhi;
bool _old_cursor_mode;
int _parentX, _parentY;
byte _active;
@ -80,17 +61,17 @@ public:
int _clickWidget;
char *_queryMess;
/* optiondialog specifics */
// optiondialog specifics
int _gui_variables[100];
/* savedialog specifics */
// savedialog specifics
int _slotIndex;
int _editString;
int _editLen;
bool valid_games[9];
char game_names[9][SAVEGAME_NAME_LEN];
void loop();
void init(Scumm *s);
// Drawing
void draw(int start, int end);
void draw(int item) { draw(item,-1); }
void drawWidget(const GuiWidget *w);
@ -104,6 +85,8 @@ public:
void widgetBorder(const GuiWidget *w);
byte *getBasePtr(int x, int y);
const GuiWidget *widgetFromPos(int x, int y);
// Actions
void leftMouseClick(int x, int y);
void handleCommand(int cmd);
void close();
@ -117,12 +100,6 @@ public:
char _gui_scroller[255];
// Dialogs
void saveLoadDialog();
void pause();
void options();
void launcher();
void handleSoundDialogCommand(int cmd);
void handleOptionsDialogCommand(int cmd);
void handleKeysDialogCommand(int cmd);

View File

@ -21,6 +21,10 @@
#if !defined(guimaps_h)
#define guimaps_h
struct ResString {
int num;
char string[80];
};
// String maps
static const char* string_map_table_custom[] = {

View File

@ -1282,7 +1282,7 @@ void Scumm::mainRun()
new_time = _system->get_msecs();
waitForTimer(delta * 15 + last_time - new_time);
last_time = _system->get_msecs();
if (_gui->_active) {
if (_gui->isActive()) {
_gui->loop();
delta = 5;
} else {