scummvm/engines/cge/vmenu.cpp

143 lines
3.5 KiB
C++
Raw Normal View History

/* 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 Soltys source code
* Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
*/
2011-06-13 09:57:24 +00:00
#include "cge/vmenu.h"
#include "cge/events.h"
#include "cge/cge_main.h"
2011-06-10 20:57:09 +00:00
namespace CGE {
2011-07-03 14:22:26 +00:00
MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) {
2011-07-19 06:09:16 +00:00
int h = kFontHigh + 2 * kMenuBarVM;
int i = (w += 2 * kMenuBarHM) * h;
uint8 *p = (uint8 *)malloc(sizeof(uint8) * i);
2011-07-19 06:42:58 +00:00
memset(p + w, kPixelTransp, i - 2 * w);
2011-07-19 05:50:07 +00:00
memset(p, kMenuBarLT, w);
memset(p + i - w, kMenuBarRB, w);
2011-07-19 06:09:16 +00:00
uint8 *p1 = p;
uint8 *p2 = p + i - 1;
for (int cpt = 0; cpt < h; cpt++) {
2011-07-19 05:50:07 +00:00
*p1 = kMenuBarLT;
*p2 = kMenuBarRB;
2011-06-13 09:57:24 +00:00
p1 += w;
p2 -= w;
}
_ts = new BitmapPtr[2];
2011-09-16 21:54:08 +00:00
_ts[0] = new Bitmap(_vm, w, h, p);
_ts[1] = NULL;
2011-07-03 09:28:22 +00:00
setShapeList(_ts);
_flags._slav = true;
_flags._tran = true;
_flags._kill = true;
_flags._bDel = true;
}
2011-07-03 14:22:26 +00:00
Vmenu *Vmenu::_addr = NULL;
2011-08-19 14:04:10 +00:00
int Vmenu::_recent = -1;
2011-06-13 09:57:24 +00:00
2011-07-03 14:22:26 +00:00
Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y)
2012-07-04 21:36:11 +00:00
: Talk(vm, VMGather(list), kTBRect), _menu(list), _bar(NULL), _vmgt(NULL), _vm(vm) {
2011-07-03 14:22:26 +00:00
Choice *cp;
2011-06-13 09:57:24 +00:00
2011-07-03 14:22:26 +00:00
_addr = this;
2011-09-05 19:21:42 +00:00
delete[] _vmgt;
2011-07-03 14:22:26 +00:00
_items = 0;
for (cp = list; cp->_text; cp++)
_items++;
_flags._bDel = true;
_flags._kill = true;
2011-06-13 11:07:45 +00:00
if (x < 0 || y < 0)
2011-07-01 23:02:14 +00:00
center();
2011-06-13 11:07:45 +00:00
else
2011-07-19 05:50:07 +00:00
gotoxy(x - _w / 2, y - (kTextVMargin + kFontHigh / 2));
2011-09-16 21:54:08 +00:00
_vm->_vga->_showQ->insert(this, _vm->_vga->_showQ->last());
2011-07-19 05:50:07 +00:00
_bar = new MenuBar(_vm, _w - 2 * kTextHMargin);
_bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin - kMenuBarVM);
2011-09-16 21:54:08 +00:00
_vm->_vga->_showQ->insert(_bar, _vm->_vga->_showQ->last());
}
Vmenu::~Vmenu() {
2011-07-03 14:22:26 +00:00
_addr = NULL;
2011-06-13 09:57:24 +00:00
}
#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
void Vmenu::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) {
2011-08-19 14:04:10 +00:00
if (!_items)
return;
Sprite::touch(mask, x, y, keyCode);
2011-08-19 14:04:10 +00:00
y -= kTextVMargin - 1;
int n = 0;
bool ok = false;
uint16 h = kFontHigh + kTextLineSpace;
if (y >= 0) {
n = y / h;
if (n < _items)
ok = (x >= kTextHMargin && x < _w - kTextHMargin/* && y % h < FONT_HIG*/);
else
n = _items - 1;
}
2011-08-19 14:04:10 +00:00
_bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin + n * h - kMenuBarVM);
2011-08-19 14:04:10 +00:00
if (ok && (mask & kMouseLeftUp)) {
_items = 0;
_vm->_commandHandlerTurbo->addCommand(kCmdKill, -1, 0, this);
2011-08-19 14:04:10 +00:00
_recent = n;
assert(_menu[n].Proc);
CALL_MEMBER_FN(*_vm, _menu[n].Proc)();
}
}
2011-09-05 19:21:42 +00:00
char *Vmenu::VMGather(Choice *list) {
Choice *cp;
int len = 0, h = 0;
for (cp = list; cp->_text; cp++) {
len += strlen(cp->_text);
h++;
}
_vmgt = new char[len + h];
if (_vmgt) {
*_vmgt = '\0';
for (cp = list; cp->_text; cp++) {
if (*_vmgt)
strcat(_vmgt, "|");
strcat(_vmgt, cp->_text);
h++;
}
}
return _vmgt;
}
2011-06-10 20:57:09 +00:00
} // End of namespace CGE