added mouse over effect

svn-id: r4466
This commit is contained in:
Max Horn 2002-07-06 12:57:51 +00:00
parent 71080f98ab
commit 671678a6c5
7 changed files with 54 additions and 24 deletions

View file

@ -43,6 +43,19 @@ void Dialog::handleClick(int x, int y, int button)
w->handleClick(button);
}
void Dialog::handleMouseMoved(int x, int y, int button)
{
Widget *w = findWidget(x - _x, y - _y);
if (_mouseWidget != w) {
if (_mouseWidget)
_mouseWidget->handleMouseLeft(button);
if (w)
w->handleMouseEntered(button);
_mouseWidget = w;
}
}
/*
* Determine the widget at location (x,y) if any. Assumes the coordinates are
* in the local coordinate system, i.e. relative to the top left of the dialog.

View file

@ -35,9 +35,10 @@ protected:
Widget *_firstWidget;
int16 _x, _y;
uint16 _w, _h;
Widget *_mouseWidget;
public:
Dialog(NewGui *gui, int x, int y, int w, int h)
: _gui(gui), _firstWidget(0), _x(x), _y(y), _w(w), _h(h)
: _gui(gui), _firstWidget(0), _x(x), _y(y), _w(w), _h(h), _mouseWidget(0)
{}
virtual void draw();
@ -46,6 +47,7 @@ public:
virtual void handleClick(int x, int y, int button);
virtual void handleKey(char key, int modifiers) // modifiers = alt/shift/ctrl etc.
{ if (key == 27) close(); }
virtual void handleMouseMoved(int x, int y, int button);
virtual void handleCommand(uint32 cmd)
{}

View file

@ -53,7 +53,7 @@ void Widget::draw()
}
// Now perform the actual widget draw
drawWidget(false);
drawWidget(_flags & WIDGET_HILITED);
if (_flags & WIDGET_BORDER) {
_x -= 4;

View file

@ -29,9 +29,10 @@ class Dialog;
enum {
WIDGET_ENABLED = 1 << 0,
WIDGET_INVISIBLE = 1 << 1,
WIDGET_BORDER = 1 << 2,
WIDGET_CLEARBG = 1 << 3,
WIDGET_WANT_TICKLE = 1 << 4,
WIDGET_HILITED = 1 << 2,
WIDGET_BORDER = 1 << 3,
WIDGET_CLEARBG = 1 << 4,
WIDGET_WANT_TICKLE = 1 << 5,
};
/* Widget */
@ -47,7 +48,9 @@ protected:
public:
Widget(Dialog *boss, int x, int y, int w, int h);
virtual void handleClick(int button) {}
virtual void handleClick(int button) {}
virtual void handleMouseEntered(int button) {}
virtual void handleMouseLeft(int button) {}
void draw();
void setFlags(int flags) { _flags |= flags; }
@ -76,13 +79,16 @@ protected:
/* ButtonWidget */
class ButtonWidget : public StaticTextWidget {
protected:
uint8 _hotkey;
uint32 _cmd;
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 handleMouseEntered(int button) { printf("handleMouseEntered\n"); setFlags(WIDGET_HILITED); draw(); }
void handleMouseLeft(int button) { printf("handleMouseLeft\n"); clearFlags(WIDGET_HILITED); draw(); }
};

View file

@ -61,6 +61,10 @@ void NewGui::loop()
_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->_mouseButStat);
_old_mouse.x = _s->mouse.x;
_old_mouse.y = _s->mouse.y;
}
_s->drawDirtyScreenParts();

View file

@ -44,21 +44,26 @@ public:
NewGui(Scumm *s);
protected:
Scumm *_s;
bool _active;
bool _need_redraw;
Dialog *_activeDialog;
Scumm *_s;
bool _active;
bool _need_redraw;
Dialog *_activeDialog;
Dialog *_pauseDialog;
Dialog *_saveLoadDialog;
Dialog *_pauseDialog;
Dialog *_saveLoadDialog;
// sound state
bool _old_soundsPaused;
bool _old_soundsPaused;
// mouse cursor state
bool _old_cursor_mode;
int _old_cursorHotspotX, _old_cursorHotspotY, _old_cursorWidth, _old_cursorHeight;
byte _old_grabbedCursor[2048];
bool _old_cursor_mode;
int _old_cursorHotspotX, _old_cursorHotspotY, _old_cursorWidth, _old_cursorHeight;
byte _old_grabbedCursor[2048];
// mouse pos
struct {
int16 x,y;
} _old_mouse;
void saveState();
void restoreState();

14
scumm.h
View file

@ -74,7 +74,7 @@ enum {
};
struct ScummPoint {
int x,y;
int x, y;
};
struct MemBlkHeader {
@ -417,12 +417,12 @@ struct ArrayHeader {
};
struct SentenceTab {
byte unk5;
byte unk2;
uint16 unk4;
uint16 unk3;
byte unk;
byte pad;
byte unk5;
byte unk2;
uint16 unk4;
uint16 unk3;
byte unk;
byte pad;
};
struct StringTab {