Skip to content

Commit

Permalink
WAGE: Precalculate menu dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 11, 2016
1 parent a65fdcf commit db9a966
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions engines/wage/gui.h
Expand Up @@ -65,6 +65,8 @@ enum WindowType {

enum {
kMenuHeight = 20,
kMenuLeftMargin = 7,
kMenuSpacing = 13,
kMenuPadding = 6,
kMenuItemHeight = 20,
kBorderWidth = 17,
Expand Down
34 changes: 19 additions & 15 deletions engines/wage/menu.cpp
Expand Up @@ -146,6 +146,24 @@ Menu::Menu(Gui *gui) : _gui(gui) {
_items.push_back(weapons);
}

// Calculate menu dimensions
_font = getMenuFont();
int y = _gui->_builtInFonts ? 3 : 2;
int x = 18;

for (int i = 0; i < _items.size(); i++) {
int w = _font->getStringWidth(_items[i]->name);

if (_items[i]->bbox.bottom == 0) {
_items[i]->bbox.left = x - kMenuLeftMargin;
_items[i]->bbox.top = y;
_items[i]->bbox.right = x + w + kMenuSpacing - kMenuLeftMargin;
_items[i]->bbox.bottom = y + _font->getFontHeight();
}

x += w + kMenuSpacing;
}

_bbox.left = 0;
_bbox.top = 0;
_bbox.right = _gui->_screen.w - 1;
Expand Down Expand Up @@ -179,29 +197,15 @@ void Menu::render() {
r.top = kMenuHeight - 1;
Design::drawFilledRect(&_gui->_screen, r, kColorBlack, p, 1);

const Graphics::Font *font = getMenuFont();
int y = _gui->_builtInFonts ? 3 : 2;
int x = 18;

for (int i = 0; i < _items.size(); i++) {
int w = font->getStringWidth(_items[i]->name);
int color = kColorBlack;

if (_activeItem == i) {
Design::drawFilledRect(&_gui->_screen, _items[i]->bbox, kColorBlack, p, 1);
color = kColorWhite;
}

font->drawString(&_gui->_screen, _items[i]->name, x, y, w, color);

if (_items[i]->bbox.bottom == 0) {
_items[i]->bbox.left = x - 7;
_items[i]->bbox.top = y;
_items[i]->bbox.right = x + w + 6;
_items[i]->bbox.bottom = y + font->getFontHeight();
}

x += w + 13;
_font->drawString(&_gui->_screen, _items[i]->name, _items[i]->bbox.left + kMenuLeftMargin, _items[i]->bbox.top, _items[i]->bbox.width(), color);
}

g_system->copyRectToScreen(_gui->_screen.getPixels(), _gui->_screen.pitch, 0, 0, _gui->_screen.w, kMenuHeight);
Expand Down
2 changes: 2 additions & 0 deletions engines/wage/menu.h
Expand Up @@ -72,6 +72,8 @@ class Menu {
const Graphics::Font *getMenuFont();
Common::Array<MenuItem *> _items;

const Graphics::Font *_font;

int _activeItem;
int _activeSubItem;
};
Expand Down

0 comments on commit db9a966

Please sign in to comment.