From e708c1e5cd14e1eed2f9e68ff4335cdd00b93f20 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 21 Jun 2014 01:57:18 +0200 Subject: CGE2: Implement "quit menu". Now the "main switch" on the menu panel is working. Also move a couple of defines from cge2_main.h to cge2.h during the process. --- engines/cge2/vmenu.cpp | 154 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 engines/cge2/vmenu.cpp (limited to 'engines/cge2/vmenu.cpp') diff --git a/engines/cge2/vmenu.cpp b/engines/cge2/vmenu.cpp new file mode 100644 index 0000000000..55ddc2aec0 --- /dev/null +++ b/engines/cge2/vmenu.cpp @@ -0,0 +1,154 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/cge2.h" +#include "cge2/vmenu.h" +#include "cge2/events.h" + +namespace CGE2 { + +void StartCountDownChoice::proc() { + _vm->switchScene(-1); +} + +void ResetQSwitchChoice::proc() { + _vm->_commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 1, nullptr); + _vm->keyClick(); +} + +MenuBar::MenuBar(CGE2Engine *vm, uint16 w, byte *c) : Talk(vm) { + _color = c; + int h = kFontHigh + 2 * kMenuBarVerticalMargin, i = (w += 2 * kMenuBarHorizontalMargin) * h; + uint8 *p = new uint8[i]; + uint8 *p1; + uint8 *p2; + uint8 lt = _color[kLt]; + uint8 rb = _color[kRb]; + BitmapPtr b; + + memset(p + w, kPixelTransp, i - 2 * w); + memset(p, lt, w); + memset(p + i - w, rb, w); + p1 = p; + p2 = p + i - 1; + for (i = 0; i < h; i++) { + *p1 = lt; + *p2 = rb; + p1 += w; + p2 -= w; + } + b = new Bitmap[1]; + b[0] = Bitmap(vm, w, h, p); + delete[] p; + setShapeList(b, 1); + _flags._slav = true; + _flags._tran = true; + _flags._kill = true; +} + +VMenu *VMenu::_addr = nullptr; + +VMenu::VMenu(CGE2Engine *vm, Common::Array list, V2D pos, ColorBank col) + : Talk(vm, vmGather(list), kTBRect, col), _menu(list), _bar(nullptr), _items(list.size()), _vm(vm) { + delete[] _vmgt; // Lefotver of vmGather. + + _addr = this; + _recent = -1; + _flags._kill = true; + + if (pos.x < 0 || pos.y < 0) + center(); + else + gotoxyz(V2D(_vm, pos.x - _siz.x / 2, pos.y - (kTextVMargin + kFontHigh / 2))); + + _vm->_vga->_showQ->append(this); + _bar = new MenuBar(_vm, _siz.x - 2 * kTextHMargin, _color); + _bar->gotoxyz(V2D(_vm, _pos2D.x, _pos2D.y + kTextVMargin - kMenuBarVerticalMargin)); + _vm->_vga->_showQ->append(_bar); +} + +char *VMenu::vmGather(Common::Array list) { + int len = 0; + int h = 0; + + for (int i = 0; i < list.size(); i++) { + len += strlen(list[i]->_text); + ++h; + } + _vmgt = new char[len + h]; + if (_vmgt) { + *_vmgt = '\0'; + for (int i = 0; i < list.size(); i++) { + if (*_vmgt) + strcat(_vmgt, "|"); + strcat(_vmgt, list[i]->_text); + ++h; + } + } + return _vmgt; +} + + +VMenu::~VMenu() { + _addr = nullptr; + + for (int i = 0; i < _menu.size(); i++) { + delete _menu[i]; + } +} + +void VMenu::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { + int h = kFontHigh + kTextLineSpace; + int n = 0; + bool ok = false; + + if (_items) { + Sprite::touch(mask, pos, keyCode); + + pos.y -= kTextVMargin - 1; + if (pos.y >= 0) { + if (pos.x < 0) + pos.x = -pos.x; + n = pos.y / h; + if (n < _items) + ok = (pos.x <= (_siz.x >> 1) - kTextHMargin); + else + n = _items - 1; + } + + _bar->gotoxyz(V2D(_vm, _pos2D.x, _pos2D.y + kTextVMargin + n * h - kMenuBarVerticalMargin)); + n = _items - 1 - n; + + if (ok && (mask & kMouseLeftUp)) { + _items = 0; + _vm->_commandHandlerTurbo->addCommand(kCmdKill, -1, 0, this); + _menu[_recent = n]->proc(); + } + } +} + +} // End of namespace CGE2 -- cgit v1.2.3