took painelf's change, modified it a lot, and now here's the result :-)

svn-id: r4540
This commit is contained in:
Max Horn 2002-07-13 18:32:09 +00:00
parent 101613f6fd
commit 1238d74227
11 changed files with 157 additions and 55 deletions

View file

@ -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) { if (_flags & WIDGET_ENABLED) {
_selectedItem = (y - 2) / LINE_HEIGHT + _currentPos; _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)
{ {
} }

View file

@ -51,8 +51,8 @@ public:
int getSelected() const { return _selectedItem; } int getSelected() const { return _selectedItem; }
void setNumberingMode(int numberingMode) { _numberingMode = numberingMode; } void setNumberingMode(int numberingMode) { _numberingMode = numberingMode; }
virtual void handleClick(int x, int y, int button); virtual void handleMouseDown(int x, int y, int button);
virtual void handleKey(char key, int modifiers); virtual void handleKeyDown(char key, int modifiers);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
protected: protected:

View file

@ -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; int old_pos = _currentPos;
@ -97,11 +97,14 @@ void ScrollBarWidget::handleClick(int x, int y, int button)
} }
} }
void ScrollBarWidget::handleMouseUp(int x, int y, int button)
{
if (_isDraggingSlider)
_isDraggingSlider = false;
}
void ScrollBarWidget::handleMouseMoved(int x, int y, int button) void ScrollBarWidget::handleMouseMoved(int x, int y, int button)
{ {
if (button == 0)
_isDraggingSlider = false;
if (_isDraggingSlider) { if (_isDraggingSlider) {
int old_pos = _currentPos; int old_pos = _currentPos;
_sliderPos = y - _sliderDeltaMouseDownPos; _sliderPos = y - _sliderDeltaMouseDownPos;

View file

@ -54,13 +54,14 @@ public:
int _currentPos; int _currentPos;
public: public:
ScrollBarWidget(Dialog *boss, int x, int y, int w, int h); 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 handleMouseMoved(int x, int y, int button);
void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); } 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(); void recalc();
protected: protected:

View file

@ -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); Widget *w = findWidget(x - _x, y - _y);
if (w) 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 // ESC closes all dialogs by default
if (key == 27) if (key == 27)
close(); close();
// FIXME: Only if not focused widget
// Hotkey handling // Hotkey handling
Widget *w = _firstWidget; Widget *w = _firstWidget;
key = toupper(key); key = toupper(key);
while (w) { while (w) {
if (w->_type == kButtonWidget && key == toupper(((ButtonWidget *)w)->_hotkey)) { 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; break;
} }
w = w->_next; w = w->_next;
@ -109,6 +122,11 @@ void Dialog::handleKey(char key, int modifiers)
// and also for an editable list widget. // 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) void Dialog::handleMouseMoved(int x, int y, int button)
{ {
Widget *w = findWidget(x - _x, y - _y); 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) { if (w->getFlags() & WIDGET_TRACK_MOUSE) {
w->handleMouseMoved(x - _x - w->_x, y - _y - w->_y, button); w->handleMouseMoved(x - _x - w->_x, y - _y - w->_y, button);
} }
//FIXME: Focused widget recieves mouseup
} }

View file

@ -53,8 +53,10 @@ public:
virtual void draw(); virtual void draw();
//virtual void handleIdle(); // Called periodically //virtual void handleIdle(); // Called periodically
virtual void handleClick(int x, int y, int button); virtual void handleMouseDown(int x, int y, int button);
virtual void handleKey(char key, int modifiers); // modifiers = alt/shift/ctrl etc. 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 handleMouseMoved(int x, int y, int button);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
@ -102,14 +104,14 @@ class PauseDialog : public Dialog {
public: public:
PauseDialog(NewGui *gui); PauseDialog(NewGui *gui);
virtual void handleClick(int x, int y, int button) virtual void handleMouseDown(int x, int y, int button)
{ close(); } { close(); }
virtual void handleKey(char key, int modifiers) virtual void handleKeyDown(char key, int modifiers)
{ {
if (key == 32) if (key == 32)
close(); close();
else else
Dialog::handleKey(key, modifiers); Dialog::handleKeyDown(key, modifiers);
} }
}; };

View file

@ -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) if (_flags & WIDGET_ENABLED)
sendCommand(_cmd, 0); sendCommand(_cmd, 0);
@ -155,7 +155,7 @@ CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const c
_type = kCheckboxWidget; _type = kCheckboxWidget;
} }
void CheckboxWidget::handleClick(int x, int y, int button) void CheckboxWidget::handleMouseDown(int x, int y, int button)
{ {
if (_flags & WIDGET_ENABLED) { if (_flags & WIDGET_ENABLED) {
_state = !_state; _state = !_state;
@ -190,8 +190,8 @@ SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const char
_type = kSliderWidget; _type = kSliderWidget;
} }
void SliderWidget::handleMouseMoved(int x, int y, int state) { void SliderWidget::handleMouseMoved(int x, int y, int button) {
if (state == 1) { if (_isDragging) {
int newvalue = x * 100 / _w; int newvalue = x * 100 / _w;
if (newvalue != _value) { if (newvalue != _value) {
@ -217,3 +217,18 @@ void SliderWidget::drawWidget(bool hilite)
// Draw the 'bar' // Draw the 'bar'
gui->fillRect(_x + 2 + ((_w - 5) * _value / 100), _y + 2, 2, _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor); 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;
}

View file

@ -86,11 +86,13 @@ public:
Widget(Dialog *boss, int x, int y, int w, int h); Widget(Dialog *boss, int x, int y, int w, int h);
virtual ~Widget() {} 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 handleMouseEntered(int button) {}
virtual void handleMouseLeft(int button) {} virtual void handleMouseLeft(int button) {}
virtual void handleMouseMoved(int x, int y, 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 draw();
void setFlags(int flags) { _flags |= flags; } void setFlags(int flags) { _flags |= flags; }
@ -130,7 +132,7 @@ public:
void setCmd(uint32 cmd) { _cmd = cmd; } void setCmd(uint32 cmd) { _cmd = cmd; }
uint32 getCmd() const { return _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 handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); }
void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); } void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
}; };
@ -144,7 +146,7 @@ public:
void setState(bool state) { _state = state; } void setState(bool state) { _state = state; }
bool getState() const { return _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 handleMouseEntered(int button) {}
virtual void handleMouseLeft(int button) {} virtual void handleMouseLeft(int button) {}
@ -156,12 +158,15 @@ protected:
class SliderWidget : public ButtonWidget { class SliderWidget : public ButtonWidget {
protected: protected:
uint8 _value, _old_value; uint8 _value, _old_value;
bool _isDragging;
public: public:
SliderWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0); 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; } void setValue(uint8 value) { _value = value; }
uint8 getValue() const { return _value; } uint8 getValue() const { return _value; }
void handleMouseMoved(int x, int y, int button); 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: protected:
void drawWidget(bool hilite); void drawWidget(bool hilite);

View file

@ -81,16 +81,16 @@ void NewGui::loop()
if (_use_alpha_blending) if (_use_alpha_blending)
activeDialog->setupScreenBuf(); activeDialog->setupScreenBuf();
#if 1 #if 1
// FIXME - hack to encode our own custom GUI colors. Since we have to live // 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 // 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. // would wish, but this is just an experiment after all.
_bgcolor = RGBMatch(_s->_currentPalette, 0, 0, 0); _bgcolor = RGBMatch(_s->_currentPalette, 0, 0, 0);
_color = RGBMatch(_s->_currentPalette, 80, 80, 80); _color = RGBMatch(_s->_currentPalette, 80, 80, 80);
_shadowcolor = RGBMatch(_s->_currentPalette, 64, 64, 64); _shadowcolor = RGBMatch(_s->_currentPalette, 64, 64, 64);
_textcolor = RGBMatch(_s->_currentPalette, 32, 192, 32); _textcolor = RGBMatch(_s->_currentPalette, 32, 192, 32);
_textcolorhi = RGBMatch(_s->_currentPalette, 0, 256, 0); _textcolorhi = RGBMatch(_s->_currentPalette, 0, 256, 0);
#endif #endif
_prepare_for_gui = false; _prepare_for_gui = false;
} }
@ -101,19 +101,41 @@ void NewGui::loop()
} }
_s->animateCursor(); _s->animateCursor();
_s->getKeyInput(0);
if (_s->_mouseButStat & MBS_LEFT_CLICK) { if (_eventList.size() > 0)
activeDialog->handleClick(_s->mouse.x, _s->mouse.y, _s->_mouseButStat); {
} else if (_s->_lastKeyHit) { OSystem::Event t;
activeDialog->handleKey(_s->_lastKeyHit, 0);
} else if (_old_mouse.x != _s->mouse.x || _old_mouse.y != _s->mouse.y) { for (int i = 0; i < _eventList.size(); i++)
activeDialog->handleMouseMoved(_s->mouse.x, _s->mouse.y, _s->_leftBtnPressed); {
_old_mouse.x = _s->mouse.x; t = _eventList.getEvent(i);
_old_mouse.y = _s->mouse.y;
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->drawDirtyScreenParts();
_s->_mouseButStat = 0;
} }
#pragma mark - #pragma mark -

View file

@ -22,6 +22,8 @@
#define NEWGUI_H #define NEWGUI_H
#include "scummsys.h" #include "scummsys.h"
#include "system.h" // For events
#include "scumm.h" // For events
class Dialog; class Dialog;
class Scumm; class Scumm;
@ -43,6 +45,27 @@ public:
void pop() { if (_size > 0) _stack[--_size] = 0; } 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 // This class hopefully will replace the old Gui class completly one day
class NewGui { class NewGui {
friend class Dialog; friend class Dialog;
@ -64,6 +87,8 @@ public:
NewGui(Scumm *s); NewGui(Scumm *s);
void handleEvent(const OSystem::Event &event) { _eventList.addEvent(event); }
protected: protected:
Scumm *_s; Scumm *_s;
bool _use_alpha_blending; bool _use_alpha_blending;
@ -88,6 +113,9 @@ protected:
struct { struct {
int16 x,y; int16 x,y;
} _old_mouse; } _old_mouse;
// List of events to be handled
EventList _eventList;
void saveState(); void saveState();
void restoreState(); void restoreState();

View file

@ -1254,6 +1254,7 @@ void Scumm::waitForTimer(int msec_delay) {
for(;;) { for(;;) {
while (_system->poll_event(&event)) { while (_system->poll_event(&event)) {
switch(event.event_code) { switch(event.event_code) {
case OSystem::EVENT_KEYDOWN: case OSystem::EVENT_KEYDOWN:
if (event.kbd.keycode >= '0' && event.kbd.keycode<='9' if (event.kbd.keycode >= '0' && event.kbd.keycode<='9'
@ -1309,6 +1310,12 @@ void Scumm::waitForTimer(int msec_delay) {
_rightBtnPressed &= ~msDown; _rightBtnPressed &= ~msDown;
break; 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 #ifdef COMPRESSED_SOUND_FILE
if (updateMP3CD() == -1) if (updateMP3CD() == -1)
@ -1557,12 +1564,11 @@ void Scumm::setupGUIColors() {
_gui->_textcolor = getDefaultGUIColor(2); _gui->_textcolor = getDefaultGUIColor(2);
_gui->_textcolorhi = getDefaultGUIColor(6); _gui->_textcolorhi = getDefaultGUIColor(6);
_gui->_shadowcolor = getDefaultGUIColor(8); _gui->_shadowcolor = getDefaultGUIColor(8);
#if 0
_newgui->_bgcolor = getDefaultGUIColor(0); _newgui->_bgcolor = _gui->_bgcolor;
_newgui->_color = getDefaultGUIColor(1); _newgui->_color = _gui->_color;
_newgui->_textcolor = getDefaultGUIColor(2); _newgui->_textcolor = _gui->_textcolor;
_newgui->_textcolorhi = getDefaultGUIColor(6); _newgui->_textcolorhi = _gui->_textcolorhi;
_newgui->_shadowcolor = getDefaultGUIColor(8); _newgui->_shadowcolor = _gui->_shadowcolor;
#endif
} }
} }