Skip to content
Permalink
Browse files

GRAPHICS: MACGUI: Allow loading menus from resource forks

  • Loading branch information...
ccawley2011 authored and bluegr committed Aug 10, 2019
1 parent aca627b commit 92a3a3a8a551f32abc9654d3731ae3d297280878
Showing with 50 additions and 0 deletions.
  1. +47 −0 graphics/macgui/macmenu.cpp
  2. +3 −0 graphics/macgui/macmenu.h
@@ -22,6 +22,7 @@

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

#include "graphics/primitives.h"
#include "graphics/font.h"
@@ -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) {
MacMenuItem *menu = _items[id];

@@ -28,6 +28,7 @@

namespace Common {
class U32String;
class MacResManager;
}

namespace Graphics {
@@ -61,6 +62,8 @@ class MacMenu : public BaseMacWindow {
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::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 clearSubMenu(int id);

0 comments on commit 92a3a3a

Please sign in to comment.
You can’t perform that action at this time.