Skip to content

Commit

Permalink
WAGE: Highlight first level menus
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 11, 2016
1 parent db503e9 commit 2d2c8ab
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
5 changes: 5 additions & 0 deletions engines/wage/gui.cpp
Expand Up @@ -613,4 +613,9 @@ Designed *Gui::getClickTarget(int x, int y) {
return NULL;
}

void Gui::mouseClick(int x, int y) {
if (_menu->mouseClick(x, y))
_menuDirty = true;
}

} // End of namespace Wage
1 change: 1 addition & 0 deletions engines/wage/gui.h
Expand Up @@ -82,6 +82,7 @@ class Gui {
void appendText(Common::String &str);
void clearOutput();
void mouseMove(int x, int y);
void mouseClick(int x, int y);
Designed *getClickTarget(int x, int y);
void drawInput();
void setSceneDirty() { _sceneDirty = true; }
Expand Down
42 changes: 39 additions & 3 deletions engines/wage/menu.cpp
Expand Up @@ -132,7 +132,7 @@ Menu::Menu(Gui *gui) : _gui(gui) {
for (int i = 0; menuSubItems[i].menunum; i++) {
MenuData *m = &menuSubItems[i];

_items[i]->subitems.push_back(new MenuSubItem(m->title, m->action, m->shortcut));
_items[m->menunum]->subitems.push_back(new MenuSubItem(m->title, m->action, m->shortcut));
}

MenuItem *commands = new MenuItem("Commands");
Expand All @@ -145,6 +145,15 @@ Menu::Menu(Gui *gui) : _gui(gui) {
MenuItem *weapons = new MenuItem("Weapons");
_items.push_back(weapons);
}

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

_menuActivated = false;
_activeItem = -1;
_activeSubItem = -1;
}

Menu::~Menu() {
Expand All @@ -160,7 +169,7 @@ const Graphics::Font *Menu::getMenuFont() {
}

void Menu::render() {
Common::Rect r(0, 0, _gui->_screen.w - 1, kMenuHeight - 1);
Common::Rect r(_bbox);
Patterns p;
p.push_back(fillPattern);

Expand All @@ -176,12 +185,39 @@ void Menu::render() {

for (int i = 0; i < _items.size(); i++) {
int w = font->getStringWidth(_items[i]->name);
font->drawString(&_gui->_screen, _items[i]->name, x, y, w, kColorBlack);
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;
_items[i]->bbox.top = y;
_items[i]->bbox.right = x + w;
_items[i]->bbox.bottom = y + font->getFontHeight();
}

x += w + 13;
}

g_system->copyRectToScreen(_gui->_screen.getPixels(), _gui->_screen.pitch, 0, 0, _gui->_screen.w, kMenuHeight);
}

bool Menu::mouseClick(int x, int y) {
if (_bbox.contains(x, y)) {
for (int i = 0; i < _items.size(); i++)
if (_items[i]->bbox.contains(x, y)) {
_activeItem = i;

return true;
}
}

return false;
}

} // End of namespace Wage
8 changes: 8 additions & 0 deletions engines/wage/menu.h
Expand Up @@ -58,13 +58,21 @@ class Menu {
~Menu();

void render();
bool mouseClick(int x, int y);

Common::Rect _bbox;

private:
Gui *_gui;

private:
const Graphics::Font *getMenuFont();
Common::Array<MenuItem *> _items;

bool _menuActivated;

int _activeItem;
int _activeSubItem;
};

} // End of namespace Wage
Expand Down
1 change: 1 addition & 0 deletions engines/wage/wage.cpp
Expand Up @@ -145,6 +145,7 @@ void WageEngine::processEvents() {
_gui->mouseMove(event.mouse.x, event.mouse.y);
break;
case Common::EVENT_LBUTTONDOWN:
_gui->mouseClick(event.mouse.x, event.mouse.y);
break;
case Common::EVENT_LBUTTONUP:
{
Expand Down

0 comments on commit 2d2c8ab

Please sign in to comment.