scummvm/engines/cge/vmenu.cpp

156 lines
3.3 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 11:57:24 +02:00
#include "cge/vmenu.h"
#include "cge/events.h"
#include "cge/cge_main.h"
2011-06-10 22:57:09 +02:00
namespace CGE {
2011-06-13 11:57:24 +02:00
#define RELIEF 1
#if RELIEF
#define MB_LT LGRAY
#define MB_RB DGRAY
#else
2011-06-13 11:57:24 +02:00
#define MB_LT DGRAY
#define MB_RB LGRAY
#endif
2011-07-03 16:22:26 +02:00
MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) {
2011-06-13 11:57:24 +02:00
int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h;
uint8 *p = farnew(uint8, i), * p1, * p2;
2011-06-13 11:57:24 +02:00
memset(p + w, TRANS, i - 2 * w);
memset(p, MB_LT, w);
memset(p + i - w, MB_RB, w);
p1 = p;
p2 = p + i - 1;
for (i = 0; i < h; i++) {
2011-06-13 11:57:24 +02:00
*p1 = MB_LT;
*p2 = MB_RB;
p1 += w;
p2 -= w;
}
2011-07-03 11:28:22 +02:00
_ts[0] = new Bitmap(w, h, p);
setShapeList(_ts);
2011-06-29 16:13:17 +02:00
_flags._slav = true;
_flags._tran = true;
_flags._kill = true;
_flags._bDel = true;
}
2011-06-13 11:57:24 +02:00
static char *vmgt;
2011-07-03 16:22:26 +02:00
char *VMGather(Choice *list) {
Choice *cp;
2011-06-13 11:57:24 +02:00
int len = 0, h = 0;
2011-07-03 16:22:26 +02:00
for (cp = list; cp->_text; cp++) {
len += strlen(cp->_text);
2011-06-29 16:13:17 +02:00
h++;
2011-06-13 11:57:24 +02:00
}
vmgt = new char[len + h];
if (vmgt) {
*vmgt = '\0';
2011-07-03 16:22:26 +02:00
for (cp = list; cp->_text; cp++) {
2011-06-13 13:07:45 +02:00
if (*vmgt)
2011-06-13 11:57:24 +02:00
strcat(vmgt, "|");
2011-07-03 16:22:26 +02:00
strcat(vmgt, cp->_text);
2011-06-29 16:13:17 +02:00
h++;
2011-06-13 11:57:24 +02:00
}
}
return vmgt;
}
2011-07-03 16:22:26 +02:00
Vmenu *Vmenu::_addr = NULL;
int Vmenu::_recent = -1;
2011-06-13 11:57:24 +02:00
2011-07-03 16:22:26 +02:00
Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y)
: Talk(vm, VMGather(list), RECT), _menu(list), _bar(NULL), _vm(vm) {
Choice *cp;
2011-06-13 11:57:24 +02:00
2011-07-03 16:22:26 +02:00
_addr = this;
2011-06-13 11:57:24 +02:00
delete[] vmgt;
2011-07-03 16:22:26 +02:00
_items = 0;
for (cp = list; cp->_text; cp++)
_items++;
2011-06-29 16:13:17 +02:00
_flags._bDel = true;
_flags._kill = true;
2011-06-13 13:07:45 +02:00
if (x < 0 || y < 0)
2011-07-02 01:02:14 +02:00
center();
2011-06-13 13:07:45 +02:00
else
2011-07-02 01:02:14 +02:00
gotoxy(x - _w / 2, y - (TEXT_VM + FONT_HIG / 2));
2011-07-03 16:22:26 +02:00
_vga->_showQ->insert(this, _vga->_showQ->last());
_bar = new MenuBar(_vm, _w - 2 * TEXT_HM);
_bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM - MB_VM);
_vga->_showQ->insert(_bar, _vga->_showQ->last());
}
Vmenu::~Vmenu() {
2011-07-03 16:22:26 +02:00
_addr = NULL;
2011-06-13 11:57:24 +02:00
}
2011-07-03 16:22:26 +02:00
void Vmenu::touch(uint16 mask, int x, int y) {
uint16 h = FONT_HIG + TEXT_LS;
2011-06-13 11:57:24 +02:00
bool ok = false;
2011-07-03 16:22:26 +02:00
if (_items) {
2011-07-02 01:02:14 +02:00
Sprite::touch(mask, x, y);
2011-06-13 11:57:24 +02:00
y -= TEXT_VM - 1;
int n = 0;
2011-06-13 11:57:24 +02:00
if (y >= 0) {
n = y / h;
2011-07-03 16:22:26 +02:00
if (n < _items)
2011-06-29 16:13:17 +02:00
ok = (x >= TEXT_HM && x < _w - TEXT_HM/* && y % h < FONT_HIG*/);
2011-06-13 13:07:45 +02:00
else
2011-07-03 16:22:26 +02:00
n = _items - 1;
2011-06-13 11:57:24 +02:00
}
2011-07-03 16:22:26 +02:00
_bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM + n * h - MB_VM);
2011-06-13 11:57:24 +02:00
if (ok && (mask & L_UP)) {
2011-07-03 16:22:26 +02:00
_items = 0;
2011-06-13 11:57:24 +02:00
SNPOST_(SNKILL, -1, 0, this);
2011-07-03 16:22:26 +02:00
//_menu[_recent = n].Proc();
warning("Missing call to proc()");
2011-06-13 11:57:24 +02:00
}
}
}
2011-06-10 22:57:09 +02:00
} // End of namespace CGE