Skip to content

Commit

Permalink
GRAPHICS: MACGUI: Allow loading menus from resource forks
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 authored and bluegr committed Aug 11, 2019
1 parent aca627b commit 92a3a3a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
47 changes: 47 additions & 0 deletions graphics/macgui/macmenu.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


#include "common/system.h" #include "common/system.h"
#include "common/keyboard.h" #include "common/keyboard.h"
#include "common/macresman.h"


#include "graphics/primitives.h" #include "graphics/primitives.h"
#include "graphics/font.h" #include "graphics/font.h"
Expand Down Expand Up @@ -307,6 +308,52 @@ void MacMenu::calcDimensions() {
} }
} }


void MacMenu::loadMenuResource(Common::MacResManager *resFork, uint16 id) {
Common::SeekableReadStream *res = resFork->getResource(MKTAG('M', 'E', 'N', 'U'), id);
assert(res);

uint16 menuID = res->readUint16BE();
/* uint16 width = */ res->readUint16BE();
/* uint16 height = */ res->readUint16BE();
/* uint16 resourceID = */ res->readUint16BE();
/* uint16 placeholder = */ res->readUint16BE();
uint32 initialState = res->readUint32BE();
Common::String menuTitle = res->readPascalString();

if (!menuTitle.empty()) {
int menu = addMenuItem(menuTitle);
initialState >>= 1;

// Read submenu items
int action = menuID << 16;
while (true) {
Common::String subMenuTitle = res->readPascalString();
if (subMenuTitle.empty())
break;

/* uint8 icon = */ res->readByte();
uint8 key = res->readByte();
/* uint8 mark = */ res->readByte();
uint8 style = res->readByte();

addMenuSubItem(menu, subMenuTitle, action++, style, key, initialState & 1);
initialState >>= 1;
}
}

delete res;
}

void MacMenu::loadMenuBarResource(Common::MacResManager *resFork, uint16 id) {
Common::SeekableReadStream *res = resFork->getResource(MKTAG('M', 'B', 'A', 'R'), id);
assert(res);

uint16 count = res->readUint16BE();
for (int i = 0; i < count; i++) {
loadMenuResource(resFork, res->readUint16BE());
}
}

void MacMenu::clearSubMenu(int id) { void MacMenu::clearSubMenu(int id) {
MacMenuItem *menu = _items[id]; MacMenuItem *menu = _items[id];


Expand Down
3 changes: 3 additions & 0 deletions graphics/macgui/macmenu.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


namespace Common { namespace Common {
class U32String; class U32String;
class MacResManager;
} }


namespace Graphics { namespace Graphics {
Expand Down Expand Up @@ -61,6 +62,8 @@ class MacMenu : public BaseMacWindow {
int addMenuItem(const Common::U32String &name); int addMenuItem(const Common::U32String &name);
void addMenuSubItem(int id, const Common::String &text, int action, int style = 0, char shortcut = 0, bool enabled = true); void addMenuSubItem(int id, const Common::String &text, int action, int style = 0, char shortcut = 0, bool enabled = true);
void addMenuSubItem(int id, const Common::U32String &text, int action, int style = 0, char shortcut = 0, bool enabled = true); void addMenuSubItem(int id, const Common::U32String &text, int action, int style = 0, char shortcut = 0, bool enabled = true);
void loadMenuResource(Common::MacResManager *resFork, uint16 id);
void loadMenuBarResource(Common::MacResManager *resFork, uint16 id);
void createSubMenuFromString(int id, const char *string, int commandId); void createSubMenuFromString(int id, const char *string, int commandId);
void clearSubMenu(int id); void clearSubMenu(int id);


Expand Down

0 comments on commit 92a3a3a

Please sign in to comment.