aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2002-07-13 18:32:09 +0000
committerMax Horn2002-07-13 18:32:09 +0000
commit1238d7422705e88097d21a3d0e34683262be4331 (patch)
tree1c91aec348222a0955b638e9308ab7a85f5965ec
parent101613f6fd6226bd0d205efe395de4e2b1009731 (diff)
downloadscummvm-rg350-1238d7422705e88097d21a3d0e34683262be4331.tar.gz
scummvm-rg350-1238d7422705e88097d21a3d0e34683262be4331.tar.bz2
scummvm-rg350-1238d7422705e88097d21a3d0e34683262be4331.zip
took painelf's change, modified it a lot, and now here's the result :-)
svn-id: r4540
-rw-r--r--gui/ListWidget.cpp4
-rw-r--r--gui/ListWidget.h4
-rw-r--r--gui/ScrollBarWidget.cpp9
-rw-r--r--gui/ScrollBarWidget.h7
-rw-r--r--gui/dialog.cpp28
-rw-r--r--gui/dialog.h12
-rw-r--r--gui/widget.cpp23
-rw-r--r--gui/widget.h13
-rw-r--r--newgui.cpp62
-rw-r--r--newgui.h28
-rw-r--r--scummvm.cpp20
11 files changed, 156 insertions, 54 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index ca501fe617..096c8cd1d5 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -83,7 +83,7 @@ ListWidget::~ListWidget()
{
}
-void ListWidget::handleClick(int x, int y, int button)
+void ListWidget::handleMouseDown(int x, int y, int button)
{
if (_flags & WIDGET_ENABLED) {
_selectedItem = (y - 2) / LINE_HEIGHT + _currentPos;
@@ -91,7 +91,7 @@ void ListWidget::handleClick(int x, int y, int button)
}
}
-void ListWidget::handleKey(char key, int modifiers)
+void ListWidget::handleKeyDown(char key, int modifiers)
{
}
diff --git a/gui/ListWidget.h b/gui/ListWidget.h
index 35a827e017..d3f7b7760d 100644
--- a/gui/ListWidget.h
+++ b/gui/ListWidget.h
@@ -51,8 +51,8 @@ public:
int getSelected() const { return _selectedItem; }
void setNumberingMode(int numberingMode) { _numberingMode = numberingMode; }
- virtual void handleClick(int x, int y, int button);
- virtual void handleKey(char key, int modifiers);
+ virtual void handleMouseDown(int x, int y, int button);
+ virtual void handleKeyDown(char key, int modifiers);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
protected:
diff --git a/gui/ScrollBarWidget.cpp b/gui/ScrollBarWidget.cpp
index d5a9607f4c..79db84ca30 100644
--- a/gui/ScrollBarWidget.cpp
+++ b/gui/ScrollBarWidget.cpp
@@ -68,7 +68,7 @@ ScrollBarWidget::ScrollBarWidget(Dialog *boss, int x, int y, int w, int h)
}
-void ScrollBarWidget::handleClick(int x, int y, int button)
+void ScrollBarWidget::handleMouseDown(int x, int y, int button)
{
int old_pos = _currentPos;
@@ -97,11 +97,14 @@ void ScrollBarWidget::handleClick(int x, int y, int button)
}
}
-void ScrollBarWidget::handleMouseMoved(int x, int y, int button)
+void ScrollBarWidget::handleMouseUp(int x, int y, int button)
{
- if (button == 0)
+ if (_isDraggingSlider)
_isDraggingSlider = false;
+}
+void ScrollBarWidget::handleMouseMoved(int x, int y, int button)
+{
if (_isDraggingSlider) {
int old_pos = _currentPos;
_sliderPos = y - _sliderDeltaMouseDownPos;
diff --git a/gui/ScrollBarWidget.h b/gui/ScrollBarWidget.h
index 842e0e767d..c4b54b446c 100644
--- a/gui/ScrollBarWidget.h
+++ b/gui/ScrollBarWidget.h
@@ -54,13 +54,14 @@ public:
int _currentPos;
public:
ScrollBarWidget(Dialog *boss, int x, int y, int w, int h);
-// virtual ~ScrollBarWidget();
- void handleClick(int x, int y, int button);
+ void handleMouseDown(int x, int y, int button);
+ void handleMouseUp(int x, int y, int button);
void handleMouseMoved(int x, int y, int button);
void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); }
- void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); _part = kNoPart; _isDraggingSlider = false; draw(); }
+ void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); _part = kNoPart; draw(); }
+ // FIXME: Shouldn't these be private?
void recalc();
protected:
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index 828a630168..52556d5fcf 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -80,25 +80,38 @@ void Dialog::draw()
}
}
-void Dialog::handleClick(int x, int y, int button)
+void Dialog::handleMouseDown(int x, int y, int button)
+{
+ // FIXME: If outside focused widget, widget loses focus
+
+ Widget *w = findWidget(x - _x, y - _y);
+ if (w)
+ w->handleMouseDown(x - _x - w->_x, y - _y - w->_y, button);
+}
+
+void Dialog::handleMouseUp(int x, int y, int button)
{
Widget *w = findWidget(x - _x, y - _y);
if (w)
- w->handleClick(x - _x - w->_x, y - _y - w->_y, button);
+ w->handleMouseUp(x - _x - w->_x, y - _y - w->_y, button);
}
-void Dialog::handleKey(char key, int modifiers)
+void Dialog::handleKeyDown(char key, int modifiers)
{
// ESC closes all dialogs by default
if (key == 27)
close();
+ // FIXME: Only if not focused widget
+
// Hotkey handling
Widget *w = _firstWidget;
key = toupper(key);
while (w) {
if (w->_type == kButtonWidget && key == toupper(((ButtonWidget *)w)->_hotkey)) {
- w->handleClick(0, 0, 1);
+ // FIXME: Calling both handlers is bad style, but we don't really know which one we're supposed to call
+ w->handleMouseDown(0, 0, 1);
+ w->handleMouseUp(0, 0, 1);
break;
}
w = w->_next;
@@ -109,6 +122,11 @@ void Dialog::handleKey(char key, int modifiers)
// and also for an editable list widget.
}
+void Dialog::handleKeyUp(char key, int modifiers)
+{
+ // FIXME: Focused widget recieves keyup
+}
+
void Dialog::handleMouseMoved(int x, int y, int button)
{
Widget *w = findWidget(x - _x, y - _y);
@@ -127,6 +145,8 @@ void Dialog::handleMouseMoved(int x, int y, int button)
if (w->getFlags() & WIDGET_TRACK_MOUSE) {
w->handleMouseMoved(x - _x - w->_x, y - _y - w->_y, button);
}
+
+ //FIXME: Focused widget recieves mouseup
}
diff --git a/gui/dialog.h b/gui/dialog.h
index 29a4b76795..460fa6e0bf 100644
--- a/gui/dialog.h
+++ b/gui/dialog.h
@@ -53,8 +53,10 @@ public:
virtual void draw();
//virtual void handleIdle(); // Called periodically
- virtual void handleClick(int x, int y, int button);
- virtual void handleKey(char key, int modifiers); // modifiers = alt/shift/ctrl etc.
+ virtual void handleMouseDown(int x, int y, int button);
+ virtual void handleMouseUp(int x, int y, int button);
+ virtual void handleKeyDown(char key, int modifiers); // modifiers = alt/shift/ctrl etc.
+ virtual void handleKeyUp(char key, int modifiers); // modifiers = alt/shift/ctrl etc.
virtual void handleMouseMoved(int x, int y, int button);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
@@ -102,14 +104,14 @@ class PauseDialog : public Dialog {
public:
PauseDialog(NewGui *gui);
- virtual void handleClick(int x, int y, int button)
+ virtual void handleMouseDown(int x, int y, int button)
{ close(); }
- virtual void handleKey(char key, int modifiers)
+ virtual void handleKeyDown(char key, int modifiers)
{
if (key == 32)
close();
else
- Dialog::handleKey(key, modifiers);
+ Dialog::handleKeyDown(key, modifiers);
}
};
diff --git a/gui/widget.cpp b/gui/widget.cpp
index f170ddadc2..22bf54096c 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -127,7 +127,7 @@ ButtonWidget::~ButtonWidget()
}
}
-void ButtonWidget::handleClick(int x, int y, int button)
+void ButtonWidget::handleMouseDown(int x, int y, int button)
{
if (_flags & WIDGET_ENABLED)
sendCommand(_cmd, 0);
@@ -155,7 +155,7 @@ CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const c
_type = kCheckboxWidget;
}
-void CheckboxWidget::handleClick(int x, int y, int button)
+void CheckboxWidget::handleMouseDown(int x, int y, int button)
{
if (_flags & WIDGET_ENABLED) {
_state = !_state;
@@ -190,8 +190,8 @@ SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const char
_type = kSliderWidget;
}
-void SliderWidget::handleMouseMoved(int x, int y, int state) {
- if (state == 1) {
+void SliderWidget::handleMouseMoved(int x, int y, int button) {
+ if (_isDragging) {
int newvalue = x * 100 / _w;
if (newvalue != _value) {
@@ -217,3 +217,18 @@ void SliderWidget::drawWidget(bool hilite)
// Draw the 'bar'
gui->fillRect(_x + 2 + ((_w - 5) * _value / 100), _y + 2, 2, _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
}
+
+void SliderWidget::handleMouseDown(int x, int y, int button) {
+ int barx;
+
+ barx=2 + ((_w - 5) * _old_value / 100);
+
+ // only start dragging if mouse is over bar
+ if (x > (barx-3) && x < (barx+3))
+ _isDragging=true;
+}
+
+void SliderWidget::handleMouseUp(int x, int y, int button) {
+ if (_isDragging)
+ _isDragging=false;
+}
diff --git a/gui/widget.h b/gui/widget.h
index b9fc92cc52..e237e24824 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -86,11 +86,13 @@ public:
Widget(Dialog *boss, int x, int y, int w, int h);
virtual ~Widget() {}
- virtual void handleClick(int x, int y, int button) {}
+ virtual void handleMouseDown(int x, int y, int button) {}
+ virtual void handleMouseUp(int x, int y, int button) {}
virtual void handleMouseEntered(int button) {}
virtual void handleMouseLeft(int button) {}
virtual void handleMouseMoved(int x, int y, int button) {}
- virtual void handleKey(char key, int modifiers) {}
+ virtual void handleKeyDown(char key, int modifiers) {}
+ virtual void handleKeyUp(char key, int modifiers) {}
void draw();
void setFlags(int flags) { _flags |= flags; }
@@ -130,7 +132,7 @@ public:
void setCmd(uint32 cmd) { _cmd = cmd; }
uint32 getCmd() const { return _cmd; }
- void handleClick(int x, int y, int button);
+ void handleMouseDown(int x, int y, int button);
void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); }
void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
};
@@ -144,7 +146,7 @@ public:
void setState(bool state) { _state = state; }
bool getState() const { return _state; }
- void handleClick(int x, int y, int button);
+ void handleMouseDown(int x, int y, int button);
virtual void handleMouseEntered(int button) {}
virtual void handleMouseLeft(int button) {}
@@ -156,12 +158,15 @@ protected:
class SliderWidget : public ButtonWidget {
protected:
uint8 _value, _old_value;
+ bool _isDragging;
public:
SliderWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0);
void setValue(uint8 value) { _value = value; }
uint8 getValue() const { return _value; }
void handleMouseMoved(int x, int y, int button);
+ void handleMouseDown(int x, int y, int button);
+ void handleMouseUp(int x, int y, int button);
protected:
void drawWidget(bool hilite);
diff --git a/newgui.cpp b/newgui.cpp
index 33f515592d..e80e2d9986 100644
--- a/newgui.cpp
+++ b/newgui.cpp
@@ -81,16 +81,16 @@ void NewGui::loop()
if (_use_alpha_blending)
activeDialog->setupScreenBuf();
#if 1
- // FIXME - hack to encode our own custom GUI colors. Since we have to live
- // with a given 8 bit palette, the result is not always as nice as one
- // would wish, but this is just an experiment after all.
- _bgcolor = RGBMatch(_s->_currentPalette, 0, 0, 0);
-
- _color = RGBMatch(_s->_currentPalette, 80, 80, 80);
- _shadowcolor = RGBMatch(_s->_currentPalette, 64, 64, 64);
-
- _textcolor = RGBMatch(_s->_currentPalette, 32, 192, 32);
- _textcolorhi = RGBMatch(_s->_currentPalette, 0, 256, 0);
+ // FIXME - hack to encode our own custom GUI colors. Since we have to live
+ // with a given 8 bit palette, the result is not always as nice as one
+ // would wish, but this is just an experiment after all.
+ _bgcolor = RGBMatch(_s->_currentPalette, 0, 0, 0);
+
+ _color = RGBMatch(_s->_currentPalette, 80, 80, 80);
+ _shadowcolor = RGBMatch(_s->_currentPalette, 64, 64, 64);
+
+ _textcolor = RGBMatch(_s->_currentPalette, 32, 192, 32);
+ _textcolorhi = RGBMatch(_s->_currentPalette, 0, 256, 0);
#endif
_prepare_for_gui = false;
}
@@ -101,19 +101,41 @@ void NewGui::loop()
}
_s->animateCursor();
- _s->getKeyInput(0);
- if (_s->_mouseButStat & MBS_LEFT_CLICK) {
- activeDialog->handleClick(_s->mouse.x, _s->mouse.y, _s->_mouseButStat);
- } else if (_s->_lastKeyHit) {
- activeDialog->handleKey(_s->_lastKeyHit, 0);
- } else if (_old_mouse.x != _s->mouse.x || _old_mouse.y != _s->mouse.y) {
- activeDialog->handleMouseMoved(_s->mouse.x, _s->mouse.y, _s->_leftBtnPressed);
- _old_mouse.x = _s->mouse.x;
- _old_mouse.y = _s->mouse.y;
+
+ if (_eventList.size() > 0)
+ {
+ OSystem::Event t;
+
+ for (int i = 0; i < _eventList.size(); i++)
+ {
+ t = _eventList.getEvent(i);
+
+ switch(t.event_code) {
+ case OSystem::EVENT_KEYDOWN:
+ activeDialog->handleKeyDown(t.kbd.ascii, t.kbd.flags);
+ break;
+// case OSystem::EVENT_KEYUP:
+// activeDialog->handleKeyUp(t.kbd.ascii, t.kbd.flags);
+ break;
+ case OSystem::EVENT_MOUSEMOVE:
+ activeDialog->handleMouseMoved(t.mouse.x, t.mouse.y, 0);
+ break;
+ // We don't distinguish between mousebuttons (for now at least)
+ case OSystem::EVENT_LBUTTONDOWN:
+ case OSystem::EVENT_RBUTTONDOWN:
+ activeDialog->handleMouseDown(t.mouse.x, t.mouse.y, 1);
+ break;
+ case OSystem::EVENT_LBUTTONUP:
+ case OSystem::EVENT_RBUTTONUP:
+ activeDialog->handleMouseUp(t.mouse.x, t.mouse.y, 1);
+ break;
+ }
+ }
+
+ _eventList.clear();
}
_s->drawDirtyScreenParts();
- _s->_mouseButStat = 0;
}
#pragma mark -
diff --git a/newgui.h b/newgui.h
index 2f0fa53b10..7bbc6bb462 100644
--- a/newgui.h
+++ b/newgui.h
@@ -22,6 +22,8 @@
#define NEWGUI_H
#include "scummsys.h"
+#include "system.h" // For events
+#include "scumm.h" // For events
class Dialog;
class Scumm;
@@ -43,6 +45,27 @@ public:
void pop() { if (_size > 0) _stack[--_size] = 0; }
};
+
+class EventList {
+protected:
+ OSystem::Event _stack[100];
+ int _size;
+public:
+ EventList() : _size(0) {}
+
+ void addEvent(const OSystem::Event &d) {
+ if (_size<(100-1))
+ _stack[_size++] = d;
+ else
+ error("EventList overflow.");
+ }
+
+ const OSystem::Event &getEvent(int i) const { return _stack[i]; }
+ int size() const { return _size; }
+ void clear() { _size = 0; }
+};
+
+
// This class hopefully will replace the old Gui class completly one day
class NewGui {
friend class Dialog;
@@ -64,6 +87,8 @@ public:
NewGui(Scumm *s);
+ void handleEvent(const OSystem::Event &event) { _eventList.addEvent(event); }
+
protected:
Scumm *_s;
bool _use_alpha_blending;
@@ -88,6 +113,9 @@ protected:
struct {
int16 x,y;
} _old_mouse;
+
+ // List of events to be handled
+ EventList _eventList;
void saveState();
void restoreState();
diff --git a/scummvm.cpp b/scummvm.cpp
index 7de5b8c5ab..bcef02223b 100644
--- a/scummvm.cpp
+++ b/scummvm.cpp
@@ -1254,6 +1254,7 @@ void Scumm::waitForTimer(int msec_delay) {
for(;;) {
while (_system->poll_event(&event)) {
+
switch(event.event_code) {
case OSystem::EVENT_KEYDOWN:
if (event.kbd.keycode >= '0' && event.kbd.keycode<='9'
@@ -1309,6 +1310,12 @@ void Scumm::waitForTimer(int msec_delay) {
_rightBtnPressed &= ~msDown;
break;
}
+
+ // if newgui is running, copy event to EventList, and let the GUI handle it itself
+ // we might consider this approach for ScummLoop as well, and clean up the current mess
+ if (_newgui->isActive())
+ _newgui->handleEvent(event);
+
}
#ifdef COMPRESSED_SOUND_FILE
if (updateMP3CD() == -1)
@@ -1557,12 +1564,11 @@ void Scumm::setupGUIColors() {
_gui->_textcolor = getDefaultGUIColor(2);
_gui->_textcolorhi = getDefaultGUIColor(6);
_gui->_shadowcolor = getDefaultGUIColor(8);
-#if 0
- _newgui->_bgcolor = getDefaultGUIColor(0);
- _newgui->_color = getDefaultGUIColor(1);
- _newgui->_textcolor = getDefaultGUIColor(2);
- _newgui->_textcolorhi = getDefaultGUIColor(6);
- _newgui->_shadowcolor = getDefaultGUIColor(8);
-#endif
+
+ _newgui->_bgcolor = _gui->_bgcolor;
+ _newgui->_color = _gui->_color;
+ _newgui->_textcolor = _gui->_textcolor;
+ _newgui->_textcolorhi = _gui->_textcolorhi;
+ _newgui->_shadowcolor = _gui->_shadowcolor;
}
}