diff options
author | Eugene Sandulenko | 2016-01-21 11:47:58 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2016-02-14 17:12:49 +0100 |
commit | ad02d2eb953f721049623242366f7e15539746ad (patch) | |
tree | bb3c4c62e08321eccca0d2c125ed299ffddc9207 /engines | |
parent | 936609fb11e9a75f7cb5b2f0d5e22c94a7e0ff80 (diff) | |
download | scummvm-rg350-ad02d2eb953f721049623242366f7e15539746ad.tar.gz scummvm-rg350-ad02d2eb953f721049623242366f7e15539746ad.tar.bz2 scummvm-rg350-ad02d2eb953f721049623242366f7e15539746ad.zip |
WAGE: Implement dialog interaction
Diffstat (limited to 'engines')
-rw-r--r-- | engines/wage/dialog.cpp | 83 | ||||
-rw-r--r-- | engines/wage/dialog.h | 8 |
2 files changed, 86 insertions, 5 deletions
diff --git a/engines/wage/dialog.cpp b/engines/wage/dialog.cpp index b58e4af680..88b2c65d5f 100644 --- a/engines/wage/dialog.cpp +++ b/engines/wage/dialog.cpp @@ -66,7 +66,7 @@ Dialog::Dialog(Gui *gui, int width, const char *text, DialogButtonArray *buttons _font = getDialogFont(); - _tempSurface.create(width, kDialogHeight, Graphics::PixelFormat::createFormatCLUT8()); + _tempSurface.create(width + 1, kDialogHeight + 1, Graphics::PixelFormat::createFormatCLUT8()); _bbox.left = (_gui->_screen.w - width) / 2; _bbox.top = (_gui->_screen.h - kDialogHeight) / 2; @@ -80,6 +80,8 @@ Dialog::Dialog(Gui *gui, int width, const char *text, DialogButtonArray *buttons // Adjust button positions for (int i = 0; i < _buttons->size(); i++) _buttons->operator[](i)->bounds.translate(_bbox.left, _bbox.top); + + _needsRedraw = true; } Dialog::~Dialog() { @@ -127,6 +129,8 @@ void Dialog::paint() { g_system->copyRectToScreen(_gui->_screen.getBasePtr(_bbox.left, _bbox.top), _gui->_screen.pitch, _bbox.left, _bbox.top, _bbox.width() + 1, _bbox.height() + 1); + + _needsRedraw = false; } void Dialog::drawOutline(Common::Rect &bounds, int *spec, int speclen) { @@ -136,10 +140,14 @@ void Dialog::drawOutline(Common::Rect &bounds, int *spec, int speclen) { 1, kColorBlack, _gui->_patterns, kPatternSolid); } -void Dialog::run() { +int Dialog::run() { bool shouldQuit = false; + Common::Rect r(_bbox); - paint(); + r.right++; + r.bottom++; + + _gui->_screen.copyRectToSurface(_tempSurface, r.left, r.top, r); while (!shouldQuit) { Common::Event event; @@ -151,15 +159,82 @@ void Dialog::run() { shouldQuit = true; break; case Common::EVENT_MOUSEMOVE: - + mouseMove(event.mouse.x, event.mouse.y); + break; + case Common::EVENT_LBUTTONDOWN: + mouseClick(event.mouse.x, event.mouse.y); + break; + case Common::EVENT_LBUTTONUP: + shouldQuit = mouseRaise(event.mouse.x, event.mouse.y); + break; + case Common::EVENT_KEYDOWN: + switch (event.kbd.keycode) { + case Common::KEYCODE_ESCAPE: + _pressedButton = -1; + shouldQuit = true; + default: + break; + } + break; default: break; } } + if (_needsRedraw) + paint(); + g_system->updateScreen(); g_system->delayMillis(50); } + + _tempSurface.copyRectToSurface(_gui->_screen, r.left, r.top, r); + + return _pressedButton; +} + +int Dialog::matchButton(int x, int y) { + for (int i = 0; i < _buttons->size(); i++) + if (_buttons->operator[](i)->bounds.contains(x, y)) + return i; + + return -1; +} + +void Dialog::mouseMove(int x, int y) { + if (_pressedButton != -1) { + int match = matchButton(x, y); + + if (_mouseOverPressedButton && match != _pressedButton) { + _mouseOverPressedButton = false; + _needsRedraw = true; + } else if (!_mouseOverPressedButton && match == _pressedButton) { + _mouseOverPressedButton = true; + _needsRedraw = true; + } + } +} + +void Dialog::mouseClick(int x, int y) { + int match = matchButton(x, y); + + if (match) { + _pressedButton = match; + _mouseOverPressedButton = true; + + _needsRedraw = true; + } +} + +int Dialog::mouseRaise(int x, int y) { + bool res = false; + + if (_pressedButton != -1) { + if (matchButton(x, y) == _pressedButton) + res = true; + } + + return res; } } // End of namespace Wage diff --git a/engines/wage/dialog.h b/engines/wage/dialog.h index 1dc777712f..544b457c84 100644 --- a/engines/wage/dialog.h +++ b/engines/wage/dialog.h @@ -70,7 +70,7 @@ public: Dialog(Gui *gui, int width, const char *text, DialogButtonArray *buttons, int defaultButton); ~Dialog(); - void run(); + int run(); private: Gui *_gui; @@ -84,10 +84,16 @@ private: int _defaultButton; bool _mouseOverPressedButton; + bool _needsRedraw; + private: const Graphics::Font *getDialogFont(); void drawOutline(Common::Rect &bounds, int *spec, int speclen); void paint(); + void mouseMove(int x, int y); + void mouseClick(int x, int y); + int mouseRaise(int x, int y); + int matchButton(int x, int y); }; } // End of namespace Wage |