Skip to content

Commit

Permalink
WAGE: Draw dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Feb 14, 2016
1 parent 5f5280d commit 8760362
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 7 deletions.
8 changes: 4 additions & 4 deletions engines/wage/design.cpp
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions engines/wage/design.h
Expand Up @@ -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);
Expand Down
67 changes: 65 additions & 2 deletions engines/wage/dialog.cpp
Expand Up @@ -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() {
Expand All @@ -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
17 changes: 16 additions & 1 deletion engines/wage/dialog.h
Expand Up @@ -50,19 +50,34 @@

namespace Wage {

struct DialogButton {
Common::String text;
Common::Rect bounds;
};

typedef Common::Array<DialogButton *> 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
Expand Down

0 comments on commit 8760362

Please sign in to comment.