aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/dialog.cpp3
-rw-r--r--gui/dialog.h3
-rw-r--r--gui/widget.cpp53
-rw-r--r--gui/widget.h23
-rw-r--r--newgui.cpp33
-rw-r--r--newgui.h6
6 files changed, 110 insertions, 11 deletions
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index a4491d0c07..ab64eafe67 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -124,6 +124,9 @@ SaveLoadDialog::SaveLoadDialog(NewGui *gui)
addButton(200, 60, 54, 16, 'P', RES_STRING(6), kPlayCmd); // Play
addButton(200, 80, 54, 16, 'O', CUSTOM_STRING(17), kOptionsCmd); // Options
addButton(200, 100, 54, 16, 'Q', RES_STRING(8), kQuitCmd); // Quit
+
+ // FIXME - test
+ new CheckboxWidget(this, 50, 20, 100, 16, "Toggle me", 0);
}
void SaveLoadDialog::handleCommand(uint32 cmd)
diff --git a/gui/dialog.h b/gui/dialog.h
index 9d7756a2c4..e057fd136c 100644
--- a/gui/dialog.h
+++ b/gui/dialog.h
@@ -37,7 +37,6 @@ enum {
class Dialog {
friend class Widget;
- friend class StaticTextWidget;
protected:
NewGui *_gui;
Widget *_firstWidget;
@@ -57,6 +56,8 @@ public:
{ if (key == 27) close(); }
virtual void handleMouseMoved(int x, int y, int button);
virtual void handleCommand(uint32 cmd);
+
+ NewGui *getGui() { return _gui; }
protected:
Widget* findWidget(int x, int y); // Find the widget at pos x,y if any
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 0fbcfd20ba..38033a2d06 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -78,7 +78,7 @@ StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, con
void StaticTextWidget::drawWidget(bool hilite)
{
- NewGui *gui = _boss->_gui;
+ NewGui *gui = _boss->getGui();
gui->drawString(_text, _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor);
}
@@ -94,6 +94,55 @@ ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char
void ButtonWidget::handleClick(int button)
{
- if (_flags & WIDGET_ENABLED)
+ if (_flags & WIDGET_ENABLED && _cmd)
_boss->handleCommand(_cmd);
}
+
+
+#pragma mark -
+
+
+/* 8x8 checkbox bitmap */
+static uint32 checked_img[8] = {
+ 0x00000000,
+ 0x01000010,
+ 0x00100100,
+ 0x00011000,
+ 0x00011000,
+ 0x00100100,
+ 0x01000010,
+ 0x00000000,
+};
+
+CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd)
+ : ButtonWidget(boss, x, y, w, h, label, cmd), _state(false)
+{
+ _flags = WIDGET_ENABLED;
+}
+
+void CheckboxWidget::handleClick(int button)
+{
+ if (_flags & WIDGET_ENABLED) {
+ _state = !_state;
+ draw();
+ if (_cmd)
+ _boss->handleCommand(_cmd);
+ }
+}
+
+void CheckboxWidget::drawWidget(bool hilite)
+{
+ NewGui *gui = _boss->getGui();
+
+ // Draw the box
+ gui->box(_x, _y, 14, 14);
+
+ // If checked, draw cross inside the box
+ if (_state)
+ gui->drawBitmap(checked_img, _x + 3, _y + 3, gui->_textcolor);
+ else
+ gui->clearArea(_x + 3, _y + 3, 8, 8);
+
+ // Finally draw the label
+ gui->drawString(_text, _x + 20, _y + 3, _w, gui->_textcolor);
+}
diff --git a/gui/widget.h b/gui/widget.h
index 58e04d48a9..a1ea0fcf64 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -83,13 +83,30 @@ protected:
uint8 _hotkey;
public:
ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd);
- void setCmd(uint32 cmd);
- uint32 getCmd();
- void handleClick(int button);
+ void setCmd(uint32 cmd) { _cmd = cmd; }
+ uint32 getCmd() { return _cmd; }
+ void handleClick(int button);
void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); }
void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
};
+/* CheckboxWidget */
+class CheckboxWidget : public ButtonWidget {
+protected:
+ bool _state;
+public:
+ CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd);
+ void setState(bool state) { _state = state; }
+ bool getState() { return _state; }
+
+ void handleClick(int button);
+ virtual void handleMouseEntered(int button) {}
+ virtual void handleMouseLeft(int button) {}
+
+protected:
+ void drawWidget(bool hilite);
+};
+
#endif
diff --git a/newgui.cpp b/newgui.cpp
index 4a9828bb26..ab79428254 100644
--- a/newgui.cpp
+++ b/newgui.cpp
@@ -179,11 +179,14 @@ const char *NewGui::queryCustomString(int stringno)
return string_map_table_custom[stringno];
}
+
#pragma mark -
-byte *NewGui::getBasePtr(int x, int y)
+
+byte *NewGui::getBasePtr(int x, int y, VirtScreen *vs)
{
- VirtScreen *vs = _s->findVirtScreen(y);
+ if (vs == NULL)
+ vs = _s->findVirtScreen(y);
if (vs == NULL)
return NULL;
@@ -237,7 +240,7 @@ void NewGui::line(int x, int y, int x2, int y2, byte color)
void NewGui::clearArea(int x, int y, int w, int h)
{
VirtScreen *vs = _s->findVirtScreen(y);
- byte *ptr = getBasePtr(x, y);
+ byte *ptr = getBasePtr(x, y, vs);
if (ptr == NULL)
return;
@@ -280,6 +283,7 @@ void NewGui::drawChar(const char str, int xx, int yy)
_color = tempc;
}
+
void NewGui::drawString(const char *str, int x, int y, int w, byte color)
{
StringTab *st = &_s->string[5];
@@ -299,3 +303,26 @@ void NewGui::drawString(const char *str, int x, int y, int w, byte color)
drawChar(str[letter], st->xpos + (letter * 8), st->ypos);
}
}
+
+/*
+ * Draw an 8x8 bitmap at location (x,y)
+ */
+void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, byte color)
+{
+ VirtScreen *vs = _s->findVirtScreen(y);
+ byte *ptr = getBasePtr(x, y, vs);
+ if (ptr == NULL)
+ return;
+
+ for (int y2 = 0; y2 < 8; y2++) {
+ uint32 mask = 0xF0000000;
+ for (int x2 = 0; x2 < 8; x2++) {
+ if (bitmap[y2] & mask)
+ ptr[x2] = color;
+ mask >>= 4;
+ }
+ ptr += 320;
+ }
+
+ _s->setVirtscreenDirty(vs, x, y, x + 8, y + 8);
+}
diff --git a/newgui.h b/newgui.h
index 461718a27d..34e4e54812 100644
--- a/newgui.h
+++ b/newgui.h
@@ -23,8 +23,9 @@
#include "scummsys.h"
-class Scumm;
class Dialog;
+class Scumm;
+class VirtScreen;
// Extremly simple stack class, doesn't even do any error checking (for now)
class DialogStack {
@@ -92,12 +93,13 @@ protected:
public:
// Drawing
- byte *getBasePtr(int x, int y);
+ byte *getBasePtr(int x, int y, VirtScreen *vs = 0);
void box(int x, int y, int width, int height);
void line(int x, int y, int x2, int y2, byte color);
void clearArea(int x, int y, int w, int h);
void drawChar(const char c, int x, int y);
void drawString(const char *str, int x, int y, int w, byte color);
+ void drawBitmap(uint32 bitmap[8], int x, int y, byte color);
// Query a string from the resources
const char *queryResString(int stringno);