From 876036230246418aa86711d33f485f5c83e769c4 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 19 Jan 2016 18:16:36 +0100 Subject: [PATCH] WAGE: Draw dialog --- engines/wage/design.cpp | 8 ++--- engines/wage/design.h | 1 + engines/wage/dialog.cpp | 67 +++++++++++++++++++++++++++++++++++++++-- engines/wage/dialog.h | 17 ++++++++++- 4 files changed, 86 insertions(+), 7 deletions(-) diff --git a/engines/wage/design.cpp b/engines/wage/design.cpp index 3db9d27f4c84..8e5c753321f6 100644 --- a/engines/wage/design.cpp +++ b/engines/wage/design.cpp @@ -443,11 +443,11 @@ void Design::drawBitmap(Graphics::Surface *surface, Common::ReadStream &in) { } void Design::drawRect(Graphics::Surface *surface, Common::Rect &rect, int thickness, int color, Patterns &patterns, byte fillType) { + drawRect(surface, rect.left, rect.top, rect.right, rect.bottom, thickness, color, patterns, fillType); +} + +void Design::drawRect(Graphics::Surface *surface, int x1, int y1, int x2, int y2, int thickness, int color, Patterns &patterns, byte fillType) { plotData pd(surface, &patterns, fillType, thickness); - int x1 = rect.left; - int y1 = rect.top; - int x2 = rect.right; - int y2 = rect.bottom; Graphics::drawLine(x1, y1, x2, y1, kColorBlack, drawPixel, &pd); Graphics::drawLine(x2, y1, x2, y2, kColorBlack, drawPixel, &pd); diff --git a/engines/wage/design.h b/engines/wage/design.h index 26f832e7675b..d98d30ce933a 100644 --- a/engines/wage/design.h +++ b/engines/wage/design.h @@ -70,6 +70,7 @@ class Design { void paint(Graphics::Surface *canvas, Patterns &patterns, int x, int y); bool isPointOpaque(int x, int y); static void drawRect(Graphics::Surface *surface, Common::Rect &rect, int thickness, int color, Patterns &patterns, byte fillType); + static void drawRect(Graphics::Surface *surface, int x1, int y1, int x2, int y2, int thickness, int color, Patterns &patterns, byte fillType); static void drawFilledRect(Graphics::Surface *surface, Common::Rect &rect, int color, Patterns &patterns, byte fillType); static void drawFilledRoundRect(Graphics::Surface *surface, Common::Rect &rect, int arc, int color, Patterns &patterns, byte fillType); static void drawHLine(Graphics::Surface *surface, int x1, int x2, int y, int thickness, int color, Patterns &patterns, byte fillType); diff --git a/engines/wage/dialog.cpp b/engines/wage/dialog.cpp index 665bf52d3bd8..eb29f80cff52 100644 --- a/engines/wage/dialog.cpp +++ b/engines/wage/dialog.cpp @@ -48,18 +48,34 @@ #include "common/system.h" #include "wage/wage.h" +#include "wage/design.h" #include "wage/gui.h" #include "wage/dialog.h" namespace Wage { -Dialog::Dialog(Gui *gui) : _gui(gui) { +enum { + kDialogWidth = 292, + kDialogHeight = 114 +}; + +Dialog::Dialog(Gui *gui, const char *text, DialogButtonArray *buttons) : _gui(gui), _text(text), _buttons(buttons) { assert(_gui->_engine); assert(_gui->_engine->_world); _font = getDialogFont(); - _tempSurface.create(_gui->_screen.w, _font->getFontHeight(), Graphics::PixelFormat::createFormatCLUT8()); + _tempSurface.create(kDialogWidth, kDialogHeight, Graphics::PixelFormat::createFormatCLUT8()); + + _bbox.left = (_gui->_screen.w - kDialogWidth) / 2; + _bbox.top = (_gui->_screen.h - kDialogHeight) / 2; + _bbox.right = (_gui->_screen.w + kDialogWidth) / 2; + _bbox.bottom = (_gui->_screen.h + kDialogHeight) / 2; + + _defaultButton = NULL; + _pressedButton = NULL; + + _mouseOverPressedButton = false; } Dialog::~Dialog() { @@ -69,4 +85,51 @@ const Graphics::Font *Dialog::getDialogFont() { return _gui->getFont("Chicago-12", Graphics::FontManager::kBigGUIFont); } +void Dialog::paint() { + Design::drawFilledRect(&_gui->_screen, _bbox, kColorWhite, _gui->_patterns, kPatternSolid); + _font->drawString(&_gui->_screen, _text, _bbox.left + 24, _bbox.right + 32, _bbox.width(), kColorBlack); + + static int boxOutline[] = { 1, 0, 0, 1, 1 }; + drawOutline(_bbox, boxOutline, ARRAYSIZE(boxOutline)); + + for (int i = 0; i < _buttons->size(); i++) { + DialogButton *button = _buttons->operator[](i); + static int buttonOutline[] = { 0, 0, 0, 0, 1 }; + + if (button == _defaultButton) { + buttonOutline[0] = buttonOutline[1] = 1; + } else { + buttonOutline[0] = buttonOutline[1] = 0; + } + + int color = kColorBlack; + + if (_pressedButton == button && _mouseOverPressedButton) { + Common::Rect bb(button->bounds.left + 5, button->bounds.top + 5, + button->bounds.right - 5, button->bounds.bottom - 5); + + Design::drawFilledRect(&_gui->_screen, bb, kColorBlack, _gui->_patterns, kPatternSolid); + + color = kColorWhite; + } + int w = _font->getStringWidth(button->text); + int x = button->bounds.left + (button->bounds.width() - w) / 2; + int y = button->bounds.top + 19; + + _font->drawString(&_gui->_screen, button->text, _bbox.left + x, _bbox.right + y, _bbox.width(), color); + + drawOutline(button->bounds, buttonOutline, ARRAYSIZE(buttonOutline)); + } + + g_system->copyRectToScreen(_gui->_screen.getBasePtr(_bbox.left, _bbox.top), _gui->_screen.pitch, + _bbox.left, _bbox.top, _bbox.width(), _bbox.height()); +} + +void Dialog::drawOutline(Common::Rect &bounds, int *spec, int speclen) { + for (int i = 0; i < speclen; i++) + if (spec[i] != 0) + Design::drawRect(&_gui->_screen, bounds.left + i, bounds.top + i, bounds.right - 1 - 2*i, bounds.bottom - 1 - 2*i, + 1, kColorBlack, _gui->_patterns, kPatternSolid); +} + } // End of namespace Wage diff --git a/engines/wage/dialog.h b/engines/wage/dialog.h index 63f7dedf61b7..747d9dea05f0 100644 --- a/engines/wage/dialog.h +++ b/engines/wage/dialog.h @@ -50,19 +50,34 @@ namespace Wage { +struct DialogButton { + Common::String text; + Common::Rect bounds; +}; + +typedef Common::Array DialogButtonArray; + class Dialog { public: - Dialog(Gui *gui); + Dialog(Gui *gui, const char *text, DialogButtonArray *buttons); ~Dialog(); private: Gui *_gui; Graphics::Surface _tempSurface; + Common::Rect _bbox; + Common::String _text; const Graphics::Font *_font; + DialogButtonArray *_buttons; + DialogButton *_pressedButton; + DialogButton *_defaultButton; + bool _mouseOverPressedButton; private: const Graphics::Font *getDialogFont(); + void drawOutline(Common::Rect &bounds, int *spec, int speclen); + void paint(); }; } // End of namespace Wage