2015-12-26 12:12:30 +00: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.
|
|
|
|
*
|
|
|
|
* MIT License:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
* conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-03 20:59:57 +00:00
|
|
|
#include "common/timer.h"
|
2015-12-31 17:50:34 +00:00
|
|
|
#include "common/unzip.h"
|
2016-01-01 00:43:59 +00:00
|
|
|
#include "graphics/cursorman.h"
|
2015-12-31 17:50:34 +00:00
|
|
|
#include "graphics/fonts/bdf.h"
|
2016-01-01 00:43:59 +00:00
|
|
|
#include "graphics/palette.h"
|
2016-01-09 00:25:23 +00:00
|
|
|
|
2015-12-26 12:12:30 +00:00
|
|
|
#include "wage/wage.h"
|
2015-12-28 11:38:26 +00:00
|
|
|
#include "wage/design.h"
|
|
|
|
#include "wage/entities.h"
|
2016-01-11 10:16:00 +00:00
|
|
|
#include "wage/menu.h"
|
2015-12-26 12:12:30 +00:00
|
|
|
#include "wage/gui.h"
|
2016-01-02 01:39:47 +00:00
|
|
|
#include "wage/world.h"
|
2015-12-26 12:12:30 +00:00
|
|
|
|
|
|
|
namespace Wage {
|
|
|
|
|
2016-01-01 00:43:59 +00:00
|
|
|
static const byte palette[] = {
|
|
|
|
0, 0, 0, // Black
|
|
|
|
0x80, 0x80, 0x80, // Gray
|
|
|
|
0xff, 0xff, 0xff, // White
|
|
|
|
0x00, 0xff, 0x00 // Green
|
|
|
|
};
|
|
|
|
|
2016-01-18 21:09:48 +00:00
|
|
|
static byte fillPatterns[][8] = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, // kPatternSolid
|
|
|
|
{ 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }, // kPatternStripes
|
|
|
|
{ 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }, // kPatternCheckers
|
|
|
|
{ 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa } // kPatternCheckers2
|
|
|
|
};
|
2016-01-01 00:43:59 +00:00
|
|
|
|
|
|
|
static const byte macCursorArrow[] = {
|
|
|
|
2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
2, 0, 2, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
2, 0, 0, 2, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
2, 0, 0, 0, 2, 3, 3, 3, 3, 3, 3,
|
|
|
|
2, 0, 0, 0, 0, 2, 3, 3, 3, 3, 3,
|
|
|
|
2, 0, 0, 0, 0, 0, 2, 3, 3, 3, 3,
|
|
|
|
2, 0, 0, 0, 0, 0, 0, 2, 3, 3, 3,
|
|
|
|
2, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3,
|
|
|
|
2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3,
|
|
|
|
2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2,
|
|
|
|
2, 0, 0, 2, 0, 0, 2, 3, 3, 3, 3,
|
|
|
|
2, 0, 2, 3, 2, 0, 0, 2, 3, 3, 3,
|
|
|
|
2, 2, 3, 3, 2, 0, 0, 2, 3, 3, 3,
|
|
|
|
2, 3, 3, 3, 3, 2, 0, 0, 2, 3, 3,
|
|
|
|
3, 3, 3, 3, 3, 2, 0, 0, 2, 3, 3,
|
|
|
|
3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 3
|
|
|
|
};
|
|
|
|
|
|
|
|
static const byte macCursorBeam[] = {
|
|
|
|
0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3,
|
|
|
|
3, 3, 0, 3, 0, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 0, 3, 0, 3, 3, 3, 3, 3, 3,
|
|
|
|
0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3,
|
|
|
|
};
|
2015-12-29 00:46:39 +00:00
|
|
|
|
2016-02-03 22:27:55 +00:00
|
|
|
static void cursorTimerHandler(void *refCon) {
|
2016-01-03 20:59:57 +00:00
|
|
|
Gui *gui = (Gui *)refCon;
|
|
|
|
|
|
|
|
int x = gui->_cursorX;
|
|
|
|
int y = gui->_cursorY;
|
|
|
|
|
|
|
|
if (x == 0 && y == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!gui->_screen.getPixels())
|
|
|
|
return;
|
|
|
|
|
|
|
|
x += gui->_consoleTextArea.left;
|
|
|
|
y += gui->_consoleTextArea.top;
|
|
|
|
|
2016-01-03 23:13:28 +00:00
|
|
|
gui->_screen.vLine(x, y, y + kCursorHeight, gui->_cursorState ? kColorBlack : kColorWhite);
|
2016-01-03 23:09:10 +00:00
|
|
|
|
|
|
|
if (!gui->_cursorOff)
|
|
|
|
gui->_cursorState = !gui->_cursorState;
|
2016-01-03 20:59:57 +00:00
|
|
|
|
2016-01-03 23:13:28 +00:00
|
|
|
g_system->copyRectToScreen(gui->_screen.getBasePtr(x, y), gui->_screen.pitch, x, y, 1, kCursorHeight);
|
2016-01-03 20:59:57 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 01:39:47 +00:00
|
|
|
Gui::Gui(WageEngine *engine) {
|
|
|
|
_engine = engine;
|
2015-12-28 11:38:26 +00:00
|
|
|
_scene = NULL;
|
|
|
|
_sceneDirty = true;
|
2016-01-02 01:53:30 +00:00
|
|
|
_consoleDirty = true;
|
2016-01-01 17:48:16 +00:00
|
|
|
_bordersDirty = true;
|
2016-01-02 01:53:30 +00:00
|
|
|
_menuDirty = true;
|
2016-01-03 14:31:24 +00:00
|
|
|
_consoleFullRedraw = true;
|
2015-12-28 11:38:26 +00:00
|
|
|
_screen.create(g_system->getWidth(), g_system->getHeight(), Graphics::PixelFormat::createFormatCLUT8());
|
2015-12-29 00:46:39 +00:00
|
|
|
|
2015-12-31 16:45:36 +00:00
|
|
|
_scrollPos = 0;
|
2016-01-03 14:31:24 +00:00
|
|
|
_consoleLineHeight = 8; // Dummy value which makes sense
|
|
|
|
_consoleNumLines = 24; // Dummy value
|
2015-12-31 17:50:34 +00:00
|
|
|
_builtInFonts = false;
|
2016-01-01 17:48:16 +00:00
|
|
|
_sceneIsActive = false;
|
2015-12-31 16:45:36 +00:00
|
|
|
|
2016-01-03 20:59:57 +00:00
|
|
|
_cursorX = 0;
|
|
|
|
_cursorY = 0;
|
|
|
|
_cursorState = false;
|
2016-01-03 23:09:10 +00:00
|
|
|
_cursorOff = false;
|
2016-01-03 20:59:57 +00:00
|
|
|
|
2016-02-03 10:01:41 +00:00
|
|
|
_inTextSelection = false;
|
2016-02-03 18:02:08 +00:00
|
|
|
_selectionStartX = _selectionStartY = -1;
|
|
|
|
_selectionEndX = _selectionEndY = -1;
|
2016-02-03 10:01:41 +00:00
|
|
|
|
2016-01-01 00:43:59 +00:00
|
|
|
g_system->getPaletteManager()->setPalette(palette, 0, 4);
|
|
|
|
|
|
|
|
CursorMan.replaceCursorPalette(palette, 0, 4);
|
|
|
|
CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
|
|
|
|
_cursorIsArrow = true;
|
|
|
|
CursorMan.showMouse(true);
|
|
|
|
|
2016-01-18 21:09:48 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(fillPatterns); i++)
|
|
|
|
_patterns.push_back(fillPatterns[i]);
|
2016-01-13 22:00:30 +00:00
|
|
|
|
2015-12-31 17:50:34 +00:00
|
|
|
loadFonts();
|
2016-01-03 20:59:57 +00:00
|
|
|
|
2016-02-03 22:27:55 +00:00
|
|
|
g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "wageCursor");
|
2016-01-11 10:16:00 +00:00
|
|
|
|
|
|
|
_menu = new Menu(this);
|
2015-12-26 12:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui::~Gui() {
|
2016-01-06 22:40:41 +00:00
|
|
|
_screen.free();
|
2016-01-07 00:24:42 +00:00
|
|
|
_console.free();
|
2016-02-03 22:27:55 +00:00
|
|
|
g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler);
|
2016-01-11 10:16:00 +00:00
|
|
|
delete _menu;
|
2015-12-26 12:12:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 11:39:29 +00:00
|
|
|
const Graphics::Font *Gui::getFont(const char *name, Graphics::FontManager::FontUsage fallback) {
|
|
|
|
const Graphics::Font *font;
|
|
|
|
|
|
|
|
if (!_builtInFonts) {
|
|
|
|
font = FontMan.getFontByName(name);
|
|
|
|
|
|
|
|
if (!font)
|
|
|
|
warning("Cannot load font %s", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_builtInFonts || !font)
|
|
|
|
font = FontMan.getFontByUsage(fallback);
|
|
|
|
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Graphics::Font *Gui::getConsoleFont() {
|
|
|
|
char fontName[128];
|
|
|
|
Scene *scene = _engine->_world->_player->_currentScene;
|
|
|
|
|
|
|
|
snprintf(fontName, 128, "%s-%d", scene->getFontName(), scene->_fontSize);
|
|
|
|
|
|
|
|
return getFont(fontName, Graphics::FontManager::kConsoleFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Graphics::Font *Gui::getTitleFont() {
|
|
|
|
return getFont("Chicago-12", Graphics::FontManager::kBigGUIFont);
|
|
|
|
}
|
|
|
|
|
2016-01-01 23:55:45 +00:00
|
|
|
void Gui::clearOutput() {
|
|
|
|
_out.clear();
|
2016-01-05 18:31:25 +00:00
|
|
|
_lines.clear();
|
|
|
|
_consoleFullRedraw = true;
|
2016-01-01 23:55:45 +00:00
|
|
|
}
|
|
|
|
|
2016-01-22 16:18:49 +00:00
|
|
|
void Gui::appendText(const char *s) {
|
|
|
|
Common::String str(s);
|
2016-01-02 01:53:30 +00:00
|
|
|
_consoleDirty = true;
|
|
|
|
|
2015-12-31 16:45:36 +00:00
|
|
|
if (!str.contains('\n')) {
|
|
|
|
_out.push_back(str);
|
2016-01-03 11:23:17 +00:00
|
|
|
flowText(str);
|
2015-12-31 16:45:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, we got new lines, need to split it
|
|
|
|
// and push substrings individually
|
|
|
|
Common::String tmp = "";
|
|
|
|
|
2016-01-06 22:39:35 +00:00
|
|
|
for (uint i = 0; i < str.size(); i++) {
|
2015-12-31 16:45:36 +00:00
|
|
|
if (str[i] == '\n') {
|
|
|
|
_out.push_back(tmp);
|
2016-01-03 11:23:17 +00:00
|
|
|
flowText(tmp);
|
2015-12-31 16:45:36 +00:00
|
|
|
tmp = "";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp += str[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
_out.push_back(tmp);
|
2016-01-03 11:23:17 +00:00
|
|
|
flowText(tmp);
|
2015-12-30 17:22:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-28 11:38:26 +00:00
|
|
|
void Gui::draw() {
|
2016-01-02 01:39:47 +00:00
|
|
|
if (_scene != _engine->_world->_player->_currentScene || _sceneDirty) {
|
|
|
|
_scene = _engine->_world->_player->_currentScene;
|
2016-01-04 22:46:31 +00:00
|
|
|
|
|
|
|
// Draw desktop
|
|
|
|
Common::Rect r(0, 0, _screen.w - 1, _screen.h - 1);
|
2016-01-13 22:00:30 +00:00
|
|
|
Design::drawFilledRoundRect(&_screen, r, kDesktopArc, kColorBlack, _patterns, kPatternCheckers);
|
2016-01-04 22:46:31 +00:00
|
|
|
g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h);
|
|
|
|
|
2016-01-02 01:53:30 +00:00
|
|
|
_sceneDirty = true;
|
2016-01-04 22:46:31 +00:00
|
|
|
_consoleDirty = true;
|
|
|
|
_menuDirty = true;
|
|
|
|
_consoleFullRedraw = true;
|
2016-01-02 01:39:47 +00:00
|
|
|
|
2016-01-18 20:34:18 +00:00
|
|
|
_scene->paint(&_screen, _scene->_designBounds->left, _scene->_designBounds->top);
|
|
|
|
|
2016-01-18 20:58:31 +00:00
|
|
|
_sceneArea.left = _scene->_designBounds->left + kBorderWidth - 2;
|
|
|
|
_sceneArea.top = _scene->_designBounds->top + kBorderWidth - 2;
|
2016-01-18 20:34:18 +00:00
|
|
|
_sceneArea.setWidth(_scene->_designBounds->width() - 2 * kBorderWidth);
|
|
|
|
_sceneArea.setHeight(_scene->_designBounds->height() - 2 * kBorderWidth);
|
|
|
|
|
2016-01-18 20:58:31 +00:00
|
|
|
_consoleTextArea.left = _scene->_textBounds->left + kBorderWidth - 2;
|
|
|
|
_consoleTextArea.top = _scene->_textBounds->top + kBorderWidth - 2;
|
2016-01-18 20:34:18 +00:00
|
|
|
_consoleTextArea.setWidth(_scene->_textBounds->width() - 2 * kBorderWidth);
|
|
|
|
_consoleTextArea.setHeight(_scene->_textBounds->height() - 2 * kBorderWidth);
|
2015-12-28 11:38:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 01:53:30 +00:00
|
|
|
if (_scene && (_bordersDirty || _sceneDirty))
|
2016-01-03 11:23:17 +00:00
|
|
|
paintBorder(&_screen, _sceneArea, kWindowScene);
|
2016-01-02 01:53:30 +00:00
|
|
|
|
2015-12-30 17:22:46 +00:00
|
|
|
// Render console
|
2016-01-04 22:46:31 +00:00
|
|
|
if (_consoleDirty || _consoleFullRedraw)
|
2016-01-03 11:23:17 +00:00
|
|
|
renderConsole(&_screen, _consoleTextArea);
|
2016-01-01 17:48:16 +00:00
|
|
|
|
2016-01-04 22:46:31 +00:00
|
|
|
if (_bordersDirty || _consoleDirty || _consoleFullRedraw)
|
2016-01-03 11:23:17 +00:00
|
|
|
paintBorder(&_screen, _consoleTextArea, kWindowConsole);
|
2016-01-01 17:48:16 +00:00
|
|
|
|
2016-01-02 01:53:30 +00:00
|
|
|
if (_menuDirty)
|
2016-01-11 10:16:00 +00:00
|
|
|
_menu->render();
|
2015-12-30 00:58:42 +00:00
|
|
|
|
2016-01-02 01:53:30 +00:00
|
|
|
_sceneDirty = false;
|
|
|
|
_consoleDirty = false;
|
|
|
|
_bordersDirty = false;
|
|
|
|
_menuDirty = false;
|
2016-01-03 14:31:24 +00:00
|
|
|
_consoleFullRedraw = false;
|
2015-12-28 11:38:26 +00:00
|
|
|
}
|
|
|
|
|
2015-12-26 12:12:30 +00:00
|
|
|
void Gui::drawBox(Graphics::Surface *g, int x, int y, int w, int h) {
|
2015-12-26 12:25:33 +00:00
|
|
|
Common::Rect r(x, y, x + w + 1, y + h + 1);
|
2015-12-26 12:12:30 +00:00
|
|
|
|
2015-12-26 12:25:33 +00:00
|
|
|
g->fillRect(r, kColorWhite);
|
2015-12-26 12:12:30 +00:00
|
|
|
g->frameRect(r, kColorBlack);
|
|
|
|
}
|
|
|
|
|
2015-12-26 12:54:20 +00:00
|
|
|
void Gui::fillRect(Graphics::Surface *g, int x, int y, int w, int h) {
|
2015-12-30 00:46:51 +00:00
|
|
|
Common::Rect r(x, y, x + w, y + h);
|
2015-12-26 12:54:20 +00:00
|
|
|
|
|
|
|
g->fillRect(r, kColorBlack);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ARROW_W 12
|
|
|
|
#define ARROW_H 6
|
|
|
|
const int arrowPixels[ARROW_H][ARROW_W] = {
|
|
|
|
{0,0,0,0,0,1,1,0,0,0,0,0},
|
|
|
|
{0,0,0,0,1,1,1,1,0,0,0,0},
|
|
|
|
{0,0,0,1,1,1,1,1,1,0,0,0},
|
|
|
|
{0,0,1,1,1,1,1,1,1,1,0,0},
|
|
|
|
{0,1,1,1,1,1,1,1,1,1,1,0},
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,1}};
|
|
|
|
|
2016-01-03 11:23:17 +00:00
|
|
|
void Gui::paintBorder(Graphics::Surface *g, Common::Rect &r, WindowType windowType) {
|
2015-12-31 17:07:01 +00:00
|
|
|
bool active, scrollable, closeable, closeBoxPressed, drawTitle;
|
2016-01-03 11:23:17 +00:00
|
|
|
const int size = kBorderWidth;
|
|
|
|
int x = r.left - size;
|
|
|
|
int y = r.top - size;
|
|
|
|
int width = r.width() + 2 * size;
|
|
|
|
int height = r.height() + 2 * size;
|
2015-12-31 16:55:33 +00:00
|
|
|
|
|
|
|
switch (windowType) {
|
|
|
|
case kWindowScene:
|
2016-01-01 17:48:16 +00:00
|
|
|
active = _sceneIsActive;
|
2015-12-31 16:55:33 +00:00
|
|
|
scrollable = false;
|
2016-01-01 17:48:16 +00:00
|
|
|
closeable = _sceneIsActive;
|
2015-12-31 16:55:33 +00:00
|
|
|
closeBoxPressed = false;
|
2015-12-31 17:07:01 +00:00
|
|
|
drawTitle = true;
|
2015-12-31 16:55:33 +00:00
|
|
|
break;
|
|
|
|
case kWindowConsole:
|
2016-01-01 17:48:16 +00:00
|
|
|
active = !_sceneIsActive;
|
2015-12-31 16:55:33 +00:00
|
|
|
scrollable = true;
|
2016-01-01 17:48:16 +00:00
|
|
|
closeable = !_sceneIsActive;
|
2015-12-31 16:55:33 +00:00
|
|
|
closeBoxPressed = false;
|
2015-12-31 17:07:01 +00:00
|
|
|
drawTitle = false;
|
2015-12-31 16:55:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-02-03 22:21:45 +00:00
|
|
|
drawBox(g, x, y, size, size);
|
|
|
|
drawBox(g, x + width - size - 1, y, size, size);
|
|
|
|
drawBox(g, x + width - size - 1, y + height - size - 1, size, size);
|
|
|
|
drawBox(g, x, y + height - size - 1, size, size);
|
|
|
|
drawBox(g, x + size, y + 2, width - 2 * size - 1, size - 4);
|
|
|
|
drawBox(g, x + size, y + height - size + 1, width - 2 * size - 1, size - 4);
|
|
|
|
drawBox(g, x + 2, y + size, size - 4, height - 2 * size - 1);
|
|
|
|
drawBox(g, x + width - size + 1, y + size, size - 4, height - 2 * size - 1);
|
2015-12-26 12:12:30 +00:00
|
|
|
|
|
|
|
if (active) {
|
2016-02-03 22:21:45 +00:00
|
|
|
fillRect(g, x + size, y + 5, width - 2 * size - 1, 8);
|
|
|
|
fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8);
|
|
|
|
fillRect(g, x + 5, y + size, 8, height - 2 * size - 1);
|
2015-12-26 12:12:30 +00:00
|
|
|
if (!scrollable) {
|
2016-02-03 22:21:45 +00:00
|
|
|
fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1);
|
2015-12-26 12:12:30 +00:00
|
|
|
} else {
|
|
|
|
int x1 = x + width - 15;
|
|
|
|
int y1 = y + size + 1;
|
2015-12-26 12:54:20 +00:00
|
|
|
for (int yy = 0; yy < ARROW_H; yy++) {
|
|
|
|
for (int xx = 0; xx < ARROW_W; xx++) {
|
|
|
|
if (arrowPixels[yy][xx] != 0) {
|
2016-02-03 22:21:45 +00:00
|
|
|
g->hLine(x1 + xx, y1 + yy, x1 + xx, kColorBlack);
|
2015-12-26 23:51:18 +00:00
|
|
|
} else {
|
2016-02-03 22:21:45 +00:00
|
|
|
g->hLine(x1 + xx, y1 + yy, x1 + xx, kColorWhite);
|
2015-12-26 12:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 22:21:45 +00:00
|
|
|
fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2);
|
|
|
|
y1 += height - 2 * size - ARROW_H - 2;
|
2015-12-26 12:54:20 +00:00
|
|
|
for (int yy = 0; yy < ARROW_H; yy++) {
|
|
|
|
for (int xx = 0; xx < ARROW_W; xx++) {
|
2016-02-03 22:21:45 +00:00
|
|
|
if (arrowPixels[ARROW_H - yy - 1][xx] != 0) {
|
|
|
|
g->hLine(x1 + xx, y1 + yy, x1 + xx, kColorBlack);
|
2015-12-26 23:51:18 +00:00
|
|
|
} else {
|
2016-02-03 22:21:45 +00:00
|
|
|
g->hLine(x1 + xx, y1 + yy, x1 + xx, kColorWhite);
|
2015-12-26 12:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (closeable) {
|
|
|
|
if (closeBoxPressed) {
|
2015-12-26 12:54:20 +00:00
|
|
|
fillRect(g, x + 6, y + 6, 6, 6);
|
2015-12-26 12:12:30 +00:00
|
|
|
} else {
|
|
|
|
drawBox(g, x + 5, y + 5, 7, 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-31 17:07:01 +00:00
|
|
|
if (drawTitle) {
|
2016-01-03 11:39:29 +00:00
|
|
|
const Graphics::Font *font = getTitleFont();
|
|
|
|
int yOff = _builtInFonts ? 3 : 1;
|
2015-12-31 17:07:01 +00:00
|
|
|
|
2016-01-18 21:14:45 +00:00
|
|
|
int w = font->getStringWidth(_scene->_name) + 10;
|
2016-02-03 22:21:45 +00:00
|
|
|
int maxWidth = width - size * 2 - 7;
|
2015-12-31 17:07:01 +00:00
|
|
|
if (w > maxWidth)
|
2015-12-26 12:12:30 +00:00
|
|
|
w = maxWidth;
|
|
|
|
drawBox(g, x + (width - w) / 2, y, w, size);
|
2016-01-18 21:14:45 +00:00
|
|
|
font->drawString(g, _scene->_name, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack);
|
2015-12-26 12:12:30 +00:00
|
|
|
}
|
2016-01-03 21:11:58 +00:00
|
|
|
|
2016-01-30 22:53:52 +00:00
|
|
|
if (x + width > _screen.w)
|
|
|
|
width = _screen.w - x;
|
|
|
|
if (y + height > _screen.h)
|
|
|
|
height = _screen.h - y;
|
|
|
|
|
2016-01-03 21:11:58 +00:00
|
|
|
g_system->copyRectToScreen(g->getBasePtr(x, y), g->pitch, x, y, width, height);
|
2015-12-26 12:12:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-31 16:45:36 +00:00
|
|
|
enum {
|
|
|
|
kConWOverlap = 20,
|
|
|
|
kConHOverlap = 20,
|
2016-01-01 01:58:34 +00:00
|
|
|
kConWPadding = 3,
|
2016-01-01 01:49:23 +00:00
|
|
|
kConHPadding = 4,
|
2016-01-03 14:31:24 +00:00
|
|
|
kConOverscan = 3
|
2015-12-31 16:45:36 +00:00
|
|
|
};
|
|
|
|
|
2016-01-27 10:11:02 +00:00
|
|
|
void Gui::flowText(Common::String &str) {
|
2016-01-03 11:23:17 +00:00
|
|
|
Common::StringArray wrappedLines;
|
|
|
|
int textW = _consoleTextArea.width() - kConWPadding * 2;
|
2016-01-03 11:39:29 +00:00
|
|
|
const Graphics::Font *font = getConsoleFont();
|
2016-01-03 11:23:17 +00:00
|
|
|
|
|
|
|
font->wordWrapText(str, textW, wrappedLines);
|
|
|
|
|
|
|
|
if (wrappedLines.size() == 0) // Sometimes we have empty lines
|
|
|
|
_lines.push_back("");
|
|
|
|
|
|
|
|
for (Common::StringArray::const_iterator j = wrappedLines.begin(); j != wrappedLines.end(); ++j)
|
|
|
|
_lines.push_back(*j);
|
2016-01-03 14:31:24 +00:00
|
|
|
|
2016-01-06 22:39:35 +00:00
|
|
|
uint pos = _scrollPos;
|
2016-01-03 14:31:24 +00:00
|
|
|
_scrollPos = MAX<int>(0, (_lines.size() - _consoleNumLines) * _consoleLineHeight);
|
|
|
|
|
2016-01-04 10:17:51 +00:00
|
|
|
_cursorX = kConWPadding;
|
2016-01-03 20:59:57 +00:00
|
|
|
|
|
|
|
if (_scrollPos)
|
2016-01-04 10:17:51 +00:00
|
|
|
_cursorY = (_consoleNumLines) * _consoleLineHeight + kConHPadding;
|
2016-01-03 20:59:57 +00:00
|
|
|
else
|
2016-01-04 10:11:27 +00:00
|
|
|
_cursorY = (_lines.size()) * _consoleLineHeight + kConHPadding;
|
2016-01-03 20:59:57 +00:00
|
|
|
|
2016-01-03 14:31:24 +00:00
|
|
|
if (pos != _scrollPos)
|
|
|
|
_consoleFullRedraw = true;
|
2016-01-03 14:34:26 +00:00
|
|
|
|
|
|
|
if (!_engine->_temporarilyHidden)
|
|
|
|
draw();
|
2016-01-03 11:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::renderConsole(Graphics::Surface *g, Common::Rect &r) {
|
2016-01-03 14:31:24 +00:00
|
|
|
bool fullRedraw = _consoleFullRedraw;
|
2015-12-31 16:45:36 +00:00
|
|
|
bool textReflow = false;
|
2016-01-03 11:23:17 +00:00
|
|
|
int surfW = r.width() + kConWOverlap * 2;
|
|
|
|
int surfH = r.height() + kConHOverlap * 2;
|
2015-12-31 16:45:36 +00:00
|
|
|
|
2015-12-31 16:55:33 +00:00
|
|
|
Common::Rect boundsR(kConWOverlap - kConOverscan, kConHOverlap - kConOverscan,
|
2016-01-03 11:23:17 +00:00
|
|
|
r.width() + kConWOverlap + kConOverscan, r.height() + kConHOverlap + kConOverscan);
|
2015-12-31 16:45:36 +00:00
|
|
|
Common::Rect fullR(0, 0, surfW, surfH);
|
|
|
|
|
|
|
|
if (_console.w != surfW || _console.h != surfH) {
|
|
|
|
if (_console.w != surfW)
|
|
|
|
textReflow = true;
|
2015-12-30 17:41:18 +00:00
|
|
|
|
|
|
|
_console.free();
|
|
|
|
|
2015-12-31 16:45:36 +00:00
|
|
|
_console.create(surfW, surfH, Graphics::PixelFormat::createFormatCLUT8());
|
2015-12-30 17:41:18 +00:00
|
|
|
fullRedraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fullRedraw)
|
|
|
|
_console.fillRect(fullR, kColorWhite);
|
|
|
|
|
2016-01-03 11:39:29 +00:00
|
|
|
const Graphics::Font *font = getConsoleFont();
|
2015-12-31 18:01:26 +00:00
|
|
|
|
2016-01-03 14:31:24 +00:00
|
|
|
_consoleLineHeight = font->getFontHeight();
|
2016-01-03 11:23:17 +00:00
|
|
|
int textW = r.width() - kConWPadding * 2;
|
|
|
|
int textH = r.height() - kConHPadding * 2;
|
2015-12-31 16:45:36 +00:00
|
|
|
|
|
|
|
if (textReflow) {
|
|
|
|
_lines.clear();
|
|
|
|
|
2016-01-06 22:39:35 +00:00
|
|
|
for (uint i = 0; i < _out.size(); i++)
|
2016-01-03 11:23:17 +00:00
|
|
|
flowText(_out[i]);
|
2015-12-31 16:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 14:31:24 +00:00
|
|
|
const int firstLine = _scrollPos / _consoleLineHeight;
|
|
|
|
const int lastLine = MIN((_scrollPos + textH) / _consoleLineHeight + 1, _lines.size());
|
2015-12-31 16:45:36 +00:00
|
|
|
const int xOff = kConWOverlap;
|
|
|
|
const int yOff = kConHOverlap;
|
|
|
|
int x1 = xOff + kConWPadding;
|
2016-01-03 14:31:24 +00:00
|
|
|
int y1 = yOff - (_scrollPos % _consoleLineHeight) + kConHPadding;
|
|
|
|
|
|
|
|
if (fullRedraw)
|
2016-01-04 10:11:27 +00:00
|
|
|
_consoleNumLines = (r.height() - 2 * kConWPadding) / _consoleLineHeight - 2;
|
2015-12-31 16:45:36 +00:00
|
|
|
|
|
|
|
for (int line = firstLine; line < lastLine; line++) {
|
|
|
|
const char *str = _lines[line].c_str();
|
2016-02-03 18:02:08 +00:00
|
|
|
int color = kColorBlack;
|
|
|
|
|
2016-02-04 10:12:33 +00:00
|
|
|
if ((line > _selectionStartY && line < _selectionEndY) ||
|
|
|
|
(line > _selectionEndY && line < _selectionStartY)) {
|
2016-02-03 18:02:08 +00:00
|
|
|
color = kColorWhite;
|
2016-02-04 10:12:33 +00:00
|
|
|
Common::Rect trect(0, y1, _console.w, y1 + _consoleLineHeight);
|
|
|
|
|
|
|
|
Design::drawFilledRect(&_console, trect, kColorBlack, _patterns, kPatternSolid);
|
2016-02-03 18:02:08 +00:00
|
|
|
}
|
2015-12-31 16:45:36 +00:00
|
|
|
|
2016-02-04 10:32:06 +00:00
|
|
|
if (line == _selectionStartY || line == _selectionEndY) {
|
|
|
|
if (_selectionStartY != _selectionEndY) {
|
|
|
|
int color1 = kColorWhite;
|
|
|
|
int color2 = kColorBlack;
|
|
|
|
int midpoint = _selectionStartX;
|
|
|
|
|
|
|
|
if (_selectionStartY > _selectionEndY)
|
|
|
|
SWAP(color1, color2);
|
|
|
|
|
|
|
|
if (line == _selectionEndY) {
|
|
|
|
SWAP(color1, color2);
|
|
|
|
midpoint = _selectionEndY;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String beg(_lines[line].c_str(), &_lines[line].c_str()[midpoint]);
|
|
|
|
Common::String end(&_lines[line].c_str()[midpoint]);
|
|
|
|
|
|
|
|
warning("beg: %s end: %s", beg.c_str(), end.c_str());
|
|
|
|
|
|
|
|
int rectW = font->getStringWidth(beg) + kConWPadding + kConWOverlap;
|
|
|
|
Common::Rect trect(0, y1, _console.w, y1 + _consoleLineHeight);
|
|
|
|
if (color1 == kColorWhite)
|
|
|
|
trect.right = rectW;
|
|
|
|
else
|
|
|
|
trect.left = rectW;
|
|
|
|
|
|
|
|
Design::drawFilledRect(&_console, trect, kColorBlack, _patterns, kPatternSolid);
|
|
|
|
|
|
|
|
font->drawString(&_console, beg, x1, y1, textW, color1);
|
|
|
|
font->drawString(&_console, end, x1 + rectW, y1, textW, color2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (*str)
|
|
|
|
font->drawString(&_console, _lines[line], x1, y1, textW, color);
|
|
|
|
}
|
2015-12-31 16:45:36 +00:00
|
|
|
|
2016-01-03 14:31:24 +00:00
|
|
|
y1 += _consoleLineHeight;
|
2015-12-31 16:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 11:23:17 +00:00
|
|
|
g->copyRectToSurface(_console, r.left - kConOverscan, r.top - kConOverscan, boundsR);
|
2016-01-03 21:11:58 +00:00
|
|
|
g_system->copyRectToScreen(g->getBasePtr(r.left, r.top), g->pitch, r.left, r.top, r.width(), r.height());
|
2015-12-30 17:41:18 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:09:10 +00:00
|
|
|
void Gui::drawInput() {
|
|
|
|
if (!_screen.getPixels())
|
|
|
|
return;
|
|
|
|
|
2016-01-04 22:17:27 +00:00
|
|
|
if (_sceneIsActive) {
|
|
|
|
_sceneIsActive = false;
|
|
|
|
_bordersDirty = true;
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:09:10 +00:00
|
|
|
const Graphics::Font *font = getConsoleFont();
|
|
|
|
|
2016-01-04 10:11:27 +00:00
|
|
|
int x = kConWPadding + _consoleTextArea.left;
|
2016-01-03 23:09:10 +00:00
|
|
|
int y = _cursorY + _consoleTextArea.top;
|
|
|
|
Common::String text(_engine->_inputText);
|
|
|
|
int textW = font->getStringWidth(text);
|
|
|
|
|
|
|
|
// undraw cursor
|
|
|
|
_cursorOff = true;
|
|
|
|
_cursorState = false;
|
2016-02-03 22:27:55 +00:00
|
|
|
cursorTimerHandler(this);
|
2016-01-03 23:09:10 +00:00
|
|
|
_cursorOff = false;
|
|
|
|
|
|
|
|
Common::Rect r(x, y, x + textW + 10, y + font->getFontHeight());
|
|
|
|
|
|
|
|
_screen.fillRect(r, kColorWhite);
|
|
|
|
|
|
|
|
font->drawString(&_screen, text, x, y, _screen.w, kColorBlack);
|
|
|
|
|
|
|
|
g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, textW + 10, font->getFontHeight());
|
|
|
|
|
2016-01-03 23:13:28 +00:00
|
|
|
_cursorX = font->getStringWidth(_engine->_inputText) + kConHPadding;
|
2016-01-03 23:09:10 +00:00
|
|
|
}
|
|
|
|
|
2015-12-31 17:50:34 +00:00
|
|
|
void Gui::loadFonts() {
|
|
|
|
Common::Archive *dat;
|
|
|
|
|
|
|
|
dat = Common::makeZipArchive("wage.dat");
|
|
|
|
|
|
|
|
if (!dat) {
|
|
|
|
warning("Could not find wage.dat. Falling back to built-in fonts");
|
|
|
|
_builtInFonts = true;
|
2016-01-03 23:47:16 +00:00
|
|
|
|
|
|
|
return;
|
2015-12-31 17:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::ArchiveMemberList list;
|
|
|
|
dat->listMembers(list);
|
|
|
|
|
|
|
|
for (Common::ArchiveMemberList::iterator it = list.begin(); it != list.end(); ++it) {
|
|
|
|
Common::SeekableReadStream *stream = dat->createReadStreamForMember((*it)->getName());
|
|
|
|
|
|
|
|
Graphics::BdfFont *font = Graphics::BdfFont::loadFont(*stream);
|
|
|
|
|
|
|
|
delete stream;
|
|
|
|
|
|
|
|
Common::String fontName = (*it)->getName();
|
|
|
|
|
|
|
|
// Trim the .bdf extension
|
|
|
|
for (int i = fontName.size() - 1; i >= 0; --i) {
|
|
|
|
if (fontName[i] == '.') {
|
|
|
|
while ((uint)i < fontName.size()) {
|
|
|
|
fontName.deleteLastChar();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FontMan.assignFontToName(fontName, font);
|
|
|
|
|
|
|
|
debug(2, " %s", fontName.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
_builtInFonts = false;
|
|
|
|
|
|
|
|
delete dat;
|
|
|
|
}
|
2015-12-26 12:12:30 +00:00
|
|
|
|
2016-01-29 17:31:19 +00:00
|
|
|
void Gui::regenCommandsMenu() {
|
|
|
|
_menu->regenCommandsMenu();
|
|
|
|
}
|
|
|
|
|
2016-01-15 10:25:50 +00:00
|
|
|
void Gui::regenWeaponsMenu() {
|
|
|
|
_menu->regenWeaponsMenu();
|
|
|
|
}
|
|
|
|
|
2016-02-02 19:21:19 +00:00
|
|
|
void Gui::processMenuShortCut(byte flags, uint16 ascii) {
|
|
|
|
_menu->processMenuShortCut(flags, ascii);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-01 00:43:59 +00:00
|
|
|
void Gui::mouseMove(int x, int y) {
|
2016-01-11 19:31:24 +00:00
|
|
|
if (_menu->_menuActivated) {
|
|
|
|
if (_menu->mouseMove(x, y))
|
|
|
|
_menuDirty = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-03 18:02:08 +00:00
|
|
|
if (_inTextSelection) {
|
|
|
|
updateTextSelection(x, y);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-01 00:43:59 +00:00
|
|
|
if (_consoleTextArea.contains(x, y)) {
|
|
|
|
if (_cursorIsArrow) {
|
|
|
|
CursorMan.replaceCursor(macCursorBeam, 11, 16, 3, 8, 3);
|
|
|
|
_cursorIsArrow = false;
|
|
|
|
}
|
|
|
|
} else if (_cursorIsArrow == false) {
|
|
|
|
CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
|
|
|
|
_cursorIsArrow = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-03 09:48:26 +00:00
|
|
|
Designed *Gui::mouseUp(int x, int y) {
|
2016-01-11 19:31:24 +00:00
|
|
|
if (_menu->_menuActivated) {
|
2016-01-11 19:46:57 +00:00
|
|
|
if (_menu->mouseRelease(x, y)) {
|
|
|
|
_sceneDirty = true;
|
|
|
|
_consoleDirty = true;
|
|
|
|
_bordersDirty = true;
|
2016-01-11 19:31:24 +00:00
|
|
|
_menuDirty = true;
|
2016-01-11 19:46:57 +00:00
|
|
|
}
|
2016-01-11 19:31:24 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-02-03 18:02:08 +00:00
|
|
|
|
|
|
|
if (_inTextSelection)
|
|
|
|
_inTextSelection = false;
|
|
|
|
|
2016-01-01 17:48:16 +00:00
|
|
|
if (_sceneArea.contains(x, y)) {
|
|
|
|
if (!_sceneIsActive) {
|
|
|
|
_sceneIsActive = true;
|
|
|
|
_bordersDirty = true;
|
|
|
|
}
|
|
|
|
|
2016-01-09 00:34:06 +00:00
|
|
|
for (ObjList::const_iterator it = _scene->_objs.begin(); it != _scene->_objs.end(); ++it) {
|
2016-01-01 17:48:16 +00:00
|
|
|
if ((*it)->_design->isPointOpaque(x - _sceneArea.left + kBorderWidth, y - _sceneArea.top + kBorderWidth))
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
2016-01-09 00:34:06 +00:00
|
|
|
for (ChrList::const_iterator it = _scene->_chrs.begin(); it != _scene->_chrs.end(); ++it) {
|
2016-01-01 17:48:16 +00:00
|
|
|
if ((*it)->_design->isPointOpaque(x - _sceneArea.left + kBorderWidth, y - _sceneArea.top + kBorderWidth))
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
} else if (_consoleTextArea.contains(x, y)) {
|
|
|
|
if (_sceneIsActive) {
|
|
|
|
_sceneIsActive = false;
|
|
|
|
_bordersDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-03 09:48:26 +00:00
|
|
|
void Gui::mouseDown(int x, int y) {
|
2016-02-03 10:01:41 +00:00
|
|
|
if (_menu->mouseClick(x, y)) {
|
2016-01-11 19:17:38 +00:00
|
|
|
_menuDirty = true;
|
2016-02-03 10:01:41 +00:00
|
|
|
} else if (_consoleTextArea.contains(x, y)) {
|
|
|
|
startMarking(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-03 18:02:08 +00:00
|
|
|
int Gui::calcTextX(int x, int textLine) {
|
2016-02-03 10:24:50 +00:00
|
|
|
const Graphics::Font *font = getConsoleFont();
|
|
|
|
Common::String str = _lines[textLine];
|
|
|
|
|
2016-02-03 18:02:08 +00:00
|
|
|
x -= _consoleTextArea.left + kConWOverlap + kConWPadding;
|
|
|
|
|
2016-02-03 10:24:50 +00:00
|
|
|
for (int i = str.size(); i >= 0; i--) {
|
2016-02-03 18:02:08 +00:00
|
|
|
if (font->getStringWidth(str) < x) {
|
|
|
|
return i;
|
2016-02-03 10:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
str.deleteLastChar();
|
|
|
|
}
|
2016-02-03 10:01:41 +00:00
|
|
|
|
2016-02-03 18:02:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Gui::calcTextY(int y) {
|
|
|
|
y -= _consoleTextArea.top + kConHOverlap + kConHPadding;
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
|
|
|
|
const int firstLine = _scrollPos / _consoleLineHeight;
|
|
|
|
int textLine = (y - _scrollPos % _consoleLineHeight) / _consoleLineHeight + firstLine;
|
|
|
|
|
|
|
|
return textLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::startMarking(int x, int y) {
|
|
|
|
warning("x: %d y: %d", x, y);
|
|
|
|
_selectionStartY = calcTextY(y);
|
|
|
|
_selectionStartX = calcTextX(x, _selectionStartY);
|
|
|
|
|
2016-02-03 10:01:41 +00:00
|
|
|
_inTextSelection = true;
|
|
|
|
|
2016-02-03 18:02:08 +00:00
|
|
|
warning("x: %d y: %d", _selectionStartX, _selectionStartY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::updateTextSelection(int x, int y) {
|
|
|
|
warning("x: %d y: %d", x, y);
|
|
|
|
_selectionEndY = calcTextY(y);
|
|
|
|
_selectionEndX = calcTextX(x, _selectionStartY);
|
|
|
|
|
|
|
|
_consoleFullRedraw = true;
|
2016-01-11 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2015-12-26 12:12:30 +00:00
|
|
|
} // End of namespace Wage
|