Skip to content

Commit

Permalink
WAGE: Removed dependency of Menu on Wage::Design
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Apr 28, 2016
1 parent 72b8f3a commit 859cd9d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
2 changes: 2 additions & 0 deletions engines/wage/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
namespace Wage {

class Menu;
class Scene;
class WageEngine;

enum {
kCursorHeight = 12
Expand Down
52 changes: 34 additions & 18 deletions engines/wage/macmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@
#include "common/system.h"
#include "common/keyboard.h"

#include "wage/wage.h"
#include "wage/entities.h"
#include "wage/design.h"
#include "graphics/primitives.h"

#include "wage/gui.h"
#include "wage/macwindowmanager.h"
#include "wage/macmenu.h"
#include "wage/world.h"

namespace Wage {

Expand Down Expand Up @@ -98,8 +96,8 @@ Menu::Menu(int id, const Common::Rect &bounds, MacWindowManager *wm, Gui *gui)

_bbox.left = 0;
_bbox.top = 0;
_bbox.right = _screen.w - 1;
_bbox.bottom = kMenuHeight - 1;
_bbox.right = _screen.w;
_bbox.bottom = kMenuHeight;

_menuActivated = false;
_activeItem = -1;
Expand Down Expand Up @@ -295,6 +293,17 @@ void Menu::calcMenuBounds(MenuItem *menu) {
menu->subbbox.bottom = y2;
}

static void drawPixelPlain(int x, int y, int color, void *data) {
Graphics::ManagedSurface *surface = (Graphics::ManagedSurface *)data;

if (x >= 0 && x < surface->w && y >= 0 && y < surface->h)
*((byte *)surface->getBasePtr(x, y)) = (byte)color;
}

static void drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color) {
Graphics::drawRoundRect(rect, arc, color, true, drawPixelPlain, surface);
}

bool Menu::draw(Graphics::ManagedSurface *g, bool forceRedraw) {
Common::Rect r(_bbox);

Expand All @@ -303,11 +312,11 @@ bool Menu::draw(Graphics::ManagedSurface *g, bool forceRedraw) {

_contentIsDirty = true;

Design::drawFilledRoundRect(&_screen, r, kDesktopArc, kColorWhite, _wm->getPatterns(), kPatternSolid);
drawFilledRoundRect(&_screen, r, kDesktopArc, kColorWhite);
r.top = 7;
Design::drawFilledRect(&_screen, r, kColorWhite, _wm->getPatterns(), kPatternSolid);
_screen.fillRect(r, kColorWhite);
r.top = kMenuHeight - 1;
Design::drawFilledRect(&_screen, r, kColorBlack, _wm->getPatterns(), kPatternSolid);
_screen.fillRect(r, kColorBlack);

for (uint i = 0; i < _items.size(); i++) {
int color = kColorBlack;
Expand All @@ -317,9 +326,10 @@ bool Menu::draw(Graphics::ManagedSurface *g, bool forceRedraw) {
Common::Rect hbox = it->bbox;

hbox.left -= 1;
hbox.right += 2;
hbox.right += 3;
hbox.bottom += 1;

Design::drawFilledRect(&_screen, hbox, kColorBlack, _wm->getPatterns(), kPatternSolid);
_screen.fillRect(hbox, kColorBlack);
color = kColorWhite;

if (!it->subitems.empty())
Expand All @@ -340,10 +350,12 @@ void Menu::renderSubmenu(MenuItem *menu) {
if (r->width() == 0 || r->height() == 0)
return;

Design::drawFilledRect(&_screen, *r, kColorWhite, _wm->getPatterns(), kPatternSolid);
Design::drawRect(&_screen, *r, 1, kColorBlack, _wm->getPatterns(), kPatternSolid);
Design::drawVLine(&_screen, r->right + 1, r->top + 3, r->bottom + 1, 1, kColorBlack, _wm->getPatterns(), kPatternSolid);
Design::drawHLine(&_screen, r->left + 3, r->right + 1, r->bottom + 1, 1, kColorBlack, _wm->getPatterns(), kPatternSolid);
_screen.fillRect(*r, kColorWhite);
_screen.frameRect(*r, kColorBlack);
_screen.vLine(r->right, r->top + 3, r->bottom + 1, kColorBlack);
_screen.vLine(r->right + 1, r->top + 3, r->bottom + 1, kColorBlack);
_screen.hLine(r->left + 3, r->bottom, r->right + 1, kColorBlack);
_screen.hLine(r->left + 3, r->bottom + 1, r->right + 1, kColorBlack);

int x = r->left + kMenuDropdownPadding;
int y = r->top + 1;
Expand All @@ -357,7 +369,7 @@ void Menu::renderSubmenu(MenuItem *menu) {
color = kColorWhite;
Common::Rect trect(r->left, y - (_wm->hasBuiltInFonts() ? 1 : 0), r->right, y + _font->getFontHeight());

Design::drawFilledRect(&_screen, trect, kColorBlack, _wm->getPatterns(), kPatternSolid);
_screen.fillRect(trect, kColorBlack);
}

if (!text.empty()) {
Expand Down Expand Up @@ -394,13 +406,17 @@ void Menu::renderSubmenu(MenuItem *menu) {
}
}
} else { // Delimiter
Design::drawHLine(&_screen, r->left + 1, r->right - 1, y + kMenuDropdownItemHeight / 2, 1, kColorBlack, _wm->getPatterns(), kPatternStripes);
bool flip = r->left & 2;
for (int xx = r->left + 1; xx <= r->right - 1; xx++) {
drawPixelPlain(xx, y + kMenuDropdownItemHeight / 2, (flip ? kColorBlack : kColorWhite), &_screen);
flip = !flip;
}
}

y += kMenuDropdownItemHeight;
}

g_system->copyRectToScreen(_screen.getBasePtr(r->left, r->top), _screen.pitch, r->left, r->top, r->width() + 3, r->height() + 3);
g_system->copyRectToScreen(_screen.getBasePtr(r->left, r->top), _screen.pitch, r->left, r->top, r->width() + 2, r->height() + 2);
}

bool Menu::processEvent(Common::Event &event) {
Expand Down
13 changes: 7 additions & 6 deletions engines/wage/macwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "common/events.h"

#include "wage/macwindow.h"
#include "wage/macwindowmanager.h"

namespace Wage {

Expand Down Expand Up @@ -201,11 +202,11 @@ void MacWindow::drawBorder() {
drawBox(g, x + width - size + 1, y + size, size - 4, height - 2 * size - 1);

if (active) {
fillRect(g, x + size, y + 5, width - 2 * size - 1, 8);
fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8);
fillRect(g, x + 5, y + size, 8, height - 2 * size - 1);
fillRect(g, x + size, y + 5, width - 2 * size - 1, 8, kColorBlack);
fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8, kColorBlack);
fillRect(g, x + 5, y + size, 8, height - 2 * size - 1, kColorBlack);
if (!scrollable) {
fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1);
fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1, kColorBlack);
} else {
int x1 = x + width - 15;
int y1 = y + size + 1;
Expand All @@ -215,7 +216,7 @@ void MacWindow::drawBorder() {
g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[yy][xx] != 0 ? kColorBlack : kColorWhite));
}

fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2);
fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2, kColorBlack);

y1 += height - 2 * size - ARROW_H - 2;
for (int yy = 0; yy < ARROW_H; yy++) {
Expand All @@ -235,7 +236,7 @@ void MacWindow::drawBorder() {
}
if (closeable) {
if (_highlightedPart == kBorderCloseButton) {
fillRect(g, x + 6, y + 6, 6, 6);
fillRect(g, x + 6, y + 6, 6, 6, kColorBlack);
} else {
drawBox(g, x + 5, y + 5, 7, 7);
}
Expand Down
4 changes: 1 addition & 3 deletions engines/wage/macwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@

#include "graphics/managed_surface.h"

#include "wage/macwindowmanager.h"

namespace Wage {

class MacWindowManager;
Expand Down Expand Up @@ -134,7 +132,7 @@ class MacWindow : public BaseMacWindow {
private:
void drawBorder();
void drawBox(Graphics::ManagedSurface *g, int x, int y, int w, int h);
void fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h, int color = kColorBlack);
void fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h, int color);
const Graphics::Font *getTitleFont();
void updateInnerDims();
WindowClick isInBorder(int x, int y);
Expand Down

0 comments on commit 859cd9d

Please sign in to comment.