2016-06-08 17:13:02 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-06-08 11:02:21 +02:00
|
|
|
#include "common/file.h"
|
|
|
|
#include "image/bmp.h"
|
|
|
|
|
2016-06-08 16:07:53 +02:00
|
|
|
#include "macventure/macventure.h"
|
|
|
|
#include "macventure/gui.h"
|
|
|
|
|
2016-06-08 11:02:21 +02:00
|
|
|
namespace MacVenture {
|
|
|
|
|
2016-06-08 16:07:53 +02:00
|
|
|
/* priority, name, action, shortcut, enabled*/
|
|
|
|
#define MV_MENU5(p, n, a, s, e) Graphics::MenuData{p, n, a, s, e}
|
|
|
|
#define MV_MENU4(p, n, a, s) Graphics::MenuData{p, n, a, s, false}
|
|
|
|
#define MV_MENUtop(n, a, s) Graphics::MenuData{-1, n, a, s, true}
|
|
|
|
|
|
|
|
static const Graphics::MenuData menuSubItems[] = {
|
|
|
|
{ -1, "Hello World", 0, 0, false },
|
|
|
|
{ 0, "How yo duin", 0, 0, false },
|
|
|
|
};
|
|
|
|
|
2016-06-08 17:13:02 +02:00
|
|
|
Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) {
|
2016-06-08 16:07:53 +02:00
|
|
|
_engine = engine;
|
2016-06-08 17:13:02 +02:00
|
|
|
_resourceManager = resman;
|
2016-06-08 11:02:21 +02:00
|
|
|
initGUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
Gui::~Gui() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::draw() {
|
|
|
|
_wm.draw();
|
|
|
|
}
|
|
|
|
|
2016-06-08 17:13:02 +02:00
|
|
|
bool Gui::processEvent(Common::Event &event) {
|
|
|
|
return _wm.processEvent(event);
|
|
|
|
}
|
|
|
|
|
2016-06-08 11:02:21 +02:00
|
|
|
void Gui::initGUI() {
|
|
|
|
_screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8());
|
|
|
|
_wm.setScreen(&_screen);
|
2016-06-08 19:02:15 +02:00
|
|
|
_outConsoleWindow = _wm.addWindow(false, true, true);
|
|
|
|
_outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120));
|
|
|
|
_outConsoleWindow->setActive(false);
|
2016-06-08 11:02:21 +02:00
|
|
|
|
2016-06-08 16:07:53 +02:00
|
|
|
_menu = _wm.addMenu();
|
|
|
|
|
2016-06-08 17:13:02 +02:00
|
|
|
if (!loadMenus())
|
|
|
|
error("Could not load menus");
|
2016-06-08 16:07:53 +02:00
|
|
|
|
|
|
|
_menu->calcDimensions();
|
|
|
|
|
2016-06-08 19:02:15 +02:00
|
|
|
loadBorder(_outConsoleWindow, "border_inac.bmp", false);
|
2016-06-08 11:02:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) {
|
|
|
|
Common::File borderfile;
|
|
|
|
|
|
|
|
if (!borderfile.open(filename)) {
|
|
|
|
debug(1, "Cannot open border file");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Image::BitmapDecoder bmpDecoder;
|
|
|
|
Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size());
|
|
|
|
Graphics::Surface source;
|
|
|
|
Graphics::TransparentSurface *surface = new Graphics::TransparentSurface();
|
|
|
|
|
|
|
|
if (stream) {
|
|
|
|
debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename);
|
|
|
|
bmpDecoder.loadStream(*stream);
|
|
|
|
source = *(bmpDecoder.getSurface());
|
|
|
|
|
|
|
|
source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette());
|
|
|
|
surface->create(source.w, source.h, source.format);
|
|
|
|
surface->copyFrom(source);
|
|
|
|
surface->applyColorKey(255, 0, 255, false);
|
|
|
|
|
|
|
|
target->setBorder(*surface, active);
|
|
|
|
|
|
|
|
borderfile.close();
|
|
|
|
|
|
|
|
delete stream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 17:13:02 +02:00
|
|
|
bool Gui::loadMenus() {
|
|
|
|
Common::MacResIDArray resArray;
|
|
|
|
Common::SeekableReadStream *res;
|
|
|
|
Common::MacResIDArray::const_iterator iter;
|
|
|
|
|
|
|
|
if ((resArray = _resourceManager->getResIDArray(MKTAG('M', 'E', 'N', 'U'))).size() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_menu->addMenuItem("(c)");
|
2016-06-08 19:02:15 +02:00
|
|
|
_menu->addMenuSubItem(0, "Hello", 0, 0, 'K', false);
|
2016-06-08 17:13:02 +02:00
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
for (iter = resArray.begin(); iter != resArray.end(); ++iter) {
|
|
|
|
res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter);
|
2016-06-08 19:02:15 +02:00
|
|
|
bool enabled;
|
|
|
|
uint16 key;
|
|
|
|
uint8 titleLength;
|
|
|
|
char* title;
|
2016-06-08 17:13:02 +02:00
|
|
|
|
|
|
|
Graphics::MenuData data;
|
|
|
|
int menunum = -1; // High level menus have level -1
|
|
|
|
/* Skip menuID, width, height, resourceID, placeholder */
|
|
|
|
for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); }
|
2016-06-08 19:02:15 +02:00
|
|
|
enabled = res->readUint32BE();
|
|
|
|
titleLength = res->readByte();
|
|
|
|
title = new char[titleLength + 1];
|
2016-06-08 17:13:02 +02:00
|
|
|
res->read(title, titleLength);
|
|
|
|
title[titleLength] = '\0';
|
|
|
|
|
|
|
|
if (titleLength > 2) {
|
|
|
|
_menu->addMenuItem(title);
|
|
|
|
|
|
|
|
// Read submenu items
|
|
|
|
while (titleLength = res->readByte()) {
|
|
|
|
title = new char[titleLength + 1];
|
|
|
|
res->read(title, titleLength);
|
|
|
|
title[titleLength] = '\0';
|
2016-06-08 19:02:15 +02:00
|
|
|
// Skip icon
|
|
|
|
res->readUint16BE();
|
|
|
|
key = res->readUint16BE();
|
|
|
|
// Skip key, mark, style
|
|
|
|
for (int skip = 0; skip < 2; skip++) { res->readUint16BE(); }
|
|
|
|
_menu->addMenuSubItem(i, title, 0, 0, key, false);
|
2016-06-08 17:13:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2016-06-08 16:07:53 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 11:02:21 +02:00
|
|
|
} // End of namespace MacVenture
|