2018-10-20 21:04:41 -07: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-11-13 19:47:07 -08:00
|
|
|
#include "glk/conf.h"
|
|
|
|
#include "glk/utils.h"
|
|
|
|
#include "glk/windows.h"
|
2018-10-20 21:04:41 -07:00
|
|
|
#include "common/config-manager.h"
|
2018-10-20 22:06:18 -07:00
|
|
|
#include "common/system.h"
|
2018-10-20 21:04:41 -07:00
|
|
|
|
2018-11-13 20:05:59 -08:00
|
|
|
namespace Glk {
|
2018-10-20 21:04:41 -07:00
|
|
|
|
|
|
|
const byte WHITE[3] = { 0xff, 0xff, 0xff };
|
|
|
|
const byte BLUE[3] = { 0x00, 0x00, 0x60 };
|
|
|
|
const byte SCROLL_BG[3] = { 0xb0, 0xb0, 0xb0 };
|
|
|
|
const byte SCROLL_FG[3] = { 0x80, 0x80, 0x80 };
|
|
|
|
|
2019-01-31 20:50:34 -08:00
|
|
|
WindowStyleStatic T_STYLES[style_NUMSTYLES] = {
|
2018-11-10 05:42:22 +00:00
|
|
|
{ PROPR, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< Normal
|
|
|
|
{ PROPI, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< Emphasized
|
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< Preformatted
|
|
|
|
{ PROPB, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< Header
|
|
|
|
{ PROPB, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< Subheader
|
|
|
|
{ PROPZ, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< Alert
|
|
|
|
{ PROPR, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< Note
|
|
|
|
{ PROPR, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< BlockQuote
|
|
|
|
{ PROPB, { 0xff, 0xff, 0xff }, { 0x00, 0x60, 0x00 }, 0 }, ///< Input
|
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 }, ///< User1
|
2018-12-17 21:23:57 -08:00
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x00, 0x00, 0x00 }, 0 } ///< User2
|
2018-10-20 21:48:22 -07:00
|
|
|
};
|
|
|
|
|
2019-01-31 20:50:34 -08:00
|
|
|
WindowStyleStatic G_STYLES[style_NUMSTYLES] = {
|
2018-11-10 05:42:22 +00:00
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< Normal
|
|
|
|
{ MONOI, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< Emphasized
|
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< Preformatted
|
|
|
|
{ MONOB, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< Header
|
|
|
|
{ MONOB, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< Subheader
|
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< Alert
|
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< Note
|
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< BlockQuote
|
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< Input
|
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 }, ///< User1
|
2018-12-17 21:23:57 -08:00
|
|
|
{ MONOR, { 0xff, 0xff, 0xff }, { 0x60, 0x60, 0x60 }, 0 } ///< User2
|
2018-10-20 21:48:22 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
Conf *g_conf;
|
|
|
|
|
2018-11-18 16:33:30 -08:00
|
|
|
Conf::Conf(InterpreterType interpType) {
|
2018-10-20 21:04:41 -07:00
|
|
|
g_conf = this;
|
2018-10-20 22:06:18 -07:00
|
|
|
_imageW = g_system->getWidth();
|
|
|
|
_imageH = g_system->getHeight();
|
2018-12-31 18:34:42 -08:00
|
|
|
|
|
|
|
get("moreprompt", _propInfo._morePrompt, "\207 more \207");
|
2019-01-31 20:50:34 -08:00
|
|
|
get("morecolor", _propInfo._moreColor, nullptr);
|
|
|
|
get("morecolor", _propInfo._moreSave, nullptr);
|
2018-12-31 18:34:42 -08:00
|
|
|
get("morefont", _propInfo._moreFont, PROPB);
|
|
|
|
get("morealign", _propInfo._moreAlign);
|
|
|
|
get("monoaspect", _monoInfo._aspect, 1.0);
|
|
|
|
get("propaspect", _propInfo._aspect, 1.0);
|
|
|
|
get("monosize", _monoInfo._size, 11);
|
|
|
|
get("propsize", _propInfo._size, 12);
|
2018-10-20 21:04:41 -07:00
|
|
|
get("rows", _rows, 25);
|
|
|
|
get("cols", _cols, 60);
|
|
|
|
|
2018-10-30 19:45:16 -07:00
|
|
|
if (ConfMan.hasKey("leading"))
|
2018-12-31 18:34:42 -08:00
|
|
|
_monoInfo._leading = _propInfo._leading = static_cast<int>(atof(ConfMan.get("leading").c_str()) + 0.5);
|
2018-10-30 19:45:16 -07:00
|
|
|
if (ConfMan.hasKey("baseline"))
|
2018-12-31 18:34:42 -08:00
|
|
|
_propInfo._baseLine = static_cast<int>(atof(ConfMan.get("baseline").c_str()) + 0.5);
|
2018-10-30 19:45:16 -07:00
|
|
|
|
2018-10-20 21:04:41 -07:00
|
|
|
if (ConfMan.hasKey("minrows"))
|
|
|
|
_rows = MAX(_rows, strToInt(ConfMan.get("minrows").c_str()));
|
|
|
|
if (ConfMan.hasKey("maxrows"))
|
|
|
|
_rows = MIN(_rows, strToInt(ConfMan.get("maxrows").c_str()));
|
|
|
|
if (ConfMan.hasKey("mincols"))
|
|
|
|
_cols = MAX(_cols, strToInt(ConfMan.get("mincols").c_str()));
|
|
|
|
if (ConfMan.hasKey("maxcols"))
|
|
|
|
_cols = MIN(_cols, strToInt(ConfMan.get("maxcols").c_str()));
|
|
|
|
|
2018-12-08 15:25:03 -08:00
|
|
|
const int DEFAULT_MARGIN_X = (interpType == INTERPRETER_FROTZ) ? 0 : 15;
|
2018-11-18 16:33:30 -08:00
|
|
|
const int DEFAULT_MARGIN_Y = (interpType == INTERPRETER_FROTZ) ? 0 : 15;
|
|
|
|
|
2018-10-20 21:04:41 -07:00
|
|
|
get("lockrows", _lockRows);
|
|
|
|
get("lockcols", _lockCols);
|
2018-11-18 16:33:30 -08:00
|
|
|
get("wmarginx", _wMarginX, DEFAULT_MARGIN_X);
|
|
|
|
get("wmarginy", _wMarginY, DEFAULT_MARGIN_Y);
|
2018-10-20 21:04:41 -07:00
|
|
|
_wMarginSaveX = _wMarginX;
|
|
|
|
_wMarginSaveY = _wMarginY;
|
|
|
|
|
|
|
|
get("wpaddingx", _wPaddingX);
|
|
|
|
get("wpaddingy", _wPaddingY);
|
2018-10-30 21:19:21 -07:00
|
|
|
get("wborderx", _wBorderX);
|
|
|
|
get("wbordery", _wBorderY);
|
2018-10-20 21:04:41 -07:00
|
|
|
get("tmarginx", _tMarginX, 7);
|
|
|
|
get("tmarginy", _tMarginY, 7);
|
|
|
|
get("gamma", _gamma, 1.0);
|
2018-11-10 05:42:22 +00:00
|
|
|
|
2018-12-31 18:34:42 -08:00
|
|
|
get("linkcolor", _propInfo._linkColor, BLUE);
|
2019-01-31 20:50:34 -08:00
|
|
|
_monoInfo._linkColor = _propInfo._linkColor;
|
|
|
|
_propInfo._linkSave = _propInfo._linkColor;
|
2018-12-31 18:34:42 -08:00
|
|
|
|
2019-01-31 20:50:34 -08:00
|
|
|
get("bordercolor", _borderColor, nullptr);
|
|
|
|
get("bordercolor", _borderSave, nullptr);
|
2018-10-20 21:04:41 -07:00
|
|
|
get("windowcolor", _windowColor, WHITE);
|
|
|
|
get("windowcolor", _windowSave, WHITE);
|
|
|
|
get("lcd", _lcd, 1);
|
2019-01-31 20:50:34 -08:00
|
|
|
get("caretcolor", _propInfo._caretColor, nullptr);
|
|
|
|
get("caretcolor", _propInfo._caretSave, nullptr);
|
2018-12-31 18:34:42 -08:00
|
|
|
get("caretshape", _propInfo._caretShape, 2);
|
2018-10-20 21:04:41 -07:00
|
|
|
|
2018-12-31 18:34:42 -08:00
|
|
|
_propInfo._linkStyle = _monoInfo._linkStyle = ConfMan.hasKey("linkstyle")
|
|
|
|
&& !strToInt(ConfMan.get("linkstyle").c_str()) ? 0 : 1;
|
2018-10-20 21:04:41 -07:00
|
|
|
|
|
|
|
get("scrollwidth", _scrollWidth);
|
|
|
|
get("scrollbg", _scrollBg, SCROLL_BG);
|
|
|
|
get("scrollfg", _scrollFg, SCROLL_FG);
|
2018-12-31 18:34:42 -08:00
|
|
|
get("justify", _propInfo._justify);
|
|
|
|
get("quotes", _propInfo._quotes, 1);
|
|
|
|
get("dashes", _propInfo._dashes, 1);
|
|
|
|
get("spaces", _propInfo._spaces);
|
|
|
|
get("caps", _propInfo._caps);
|
2018-10-21 10:53:32 -07:00
|
|
|
get("graphics", _graphics, true);
|
|
|
|
get("sound", _sound, true);
|
2018-10-20 21:04:41 -07:00
|
|
|
get("speak", _speak);
|
|
|
|
get("speak_input", _speakInput);
|
|
|
|
get("speak_language", _speakLanguage);
|
|
|
|
get("stylehint", _styleHint, 1);
|
2018-10-21 10:53:32 -07:00
|
|
|
get("safeclicks", _safeClicks);
|
2018-10-20 21:04:41 -07:00
|
|
|
|
2018-11-23 11:38:30 -08:00
|
|
|
// For simplicity's sake, only allow graphics when in non-paletted graphics modes
|
|
|
|
if (g_system->getScreenFormat().bytesPerPixel == 1)
|
|
|
|
_graphics = false;
|
|
|
|
|
2018-10-20 21:48:22 -07:00
|
|
|
Common::copy(T_STYLES, T_STYLES + style_NUMSTYLES, _tStyles);
|
|
|
|
Common::copy(G_STYLES, G_STYLES + style_NUMSTYLES, _gStyles);
|
|
|
|
|
2018-12-09 11:36:20 -08:00
|
|
|
char buffer[256];
|
2018-11-09 20:04:08 -08:00
|
|
|
const char *const TG_COLOR[2] = { "tcolor_%d", "gcolor_%d" };
|
|
|
|
for (int tg = 0; tg < 2; ++tg) {
|
|
|
|
for (int style = 0; style <= 10; ++style) {
|
|
|
|
Common::String key = Common::String::format(TG_COLOR[tg], style);
|
|
|
|
if (!ConfMan.hasKey(key))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
strncpy(buffer, ConfMan.get(key).c_str(), 254);
|
|
|
|
buffer[255] = '\0';
|
|
|
|
char *fg = strtok(buffer, "\r\n\t ");
|
|
|
|
char *bg = strtok(nullptr, "\r\n\t ");
|
|
|
|
|
|
|
|
if (tg == 0) {
|
2019-01-31 20:50:34 -08:00
|
|
|
_tStyles[style].fg = parseColor(fg);
|
|
|
|
_tStyles[style].bg = parseColor(bg);
|
2018-11-09 20:04:08 -08:00
|
|
|
} else {
|
2019-01-31 20:50:34 -08:00
|
|
|
_gStyles[style].fg = parseColor(fg);
|
|
|
|
_gStyles[style].bg = parseColor(bg);
|
2018-11-09 20:04:08 -08:00
|
|
|
}
|
2018-10-20 21:48:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 20:04:08 -08:00
|
|
|
const char *const TG_FONT[2] = { "tfont_%d", "gfont_%d" };
|
|
|
|
for (int tg = 0; tg < 2; ++tg) {
|
|
|
|
for (int style = 0; style <= 10; ++style) {
|
|
|
|
Common::String key = Common::String::format(TG_FONT[tg], style);
|
|
|
|
if (!ConfMan.hasKey(key))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
strncpy(buffer, ConfMan.get(key).c_str(), 254);
|
|
|
|
buffer[255] = '\0';
|
|
|
|
char *font = strtok(buffer, "\r\n\t ");
|
|
|
|
|
|
|
|
if (tg == 0)
|
2018-11-25 11:42:00 -08:00
|
|
|
_tStyles[style].font = Screen::getFontId(font);
|
2018-11-09 20:04:08 -08:00
|
|
|
else
|
2018-11-25 11:42:00 -08:00
|
|
|
_gStyles[style].font = Screen::getFontId(font);
|
2018-11-09 20:04:08 -08:00
|
|
|
}
|
2018-10-20 21:48:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::copy(_tStyles, _tStyles + style_NUMSTYLES, _tStylesDefault);
|
|
|
|
Common::copy(_gStyles, _gStyles + style_NUMSTYLES, _gStylesDefault);
|
2018-10-20 21:04:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Conf::get(const Common::String &key, Common::String &field, const char *defaultVal) {
|
|
|
|
field = ConfMan.hasKey(key) ? ConfMan.get(key) : defaultVal;
|
|
|
|
field.trim();
|
|
|
|
}
|
|
|
|
|
2019-01-31 20:50:34 -08:00
|
|
|
void Conf::get(const Common::String &key, uint &color, const byte *defaultColor) {
|
2018-10-20 21:48:22 -07:00
|
|
|
if (ConfMan.hasKey(key)) {
|
2019-01-31 20:50:34 -08:00
|
|
|
color = parseColor(ConfMan.get(key));
|
2018-10-20 21:04:41 -07:00
|
|
|
} else if (defaultColor) {
|
2019-01-31 20:50:34 -08:00
|
|
|
color = g_system->getScreenFormat().RGBToColor(defaultColor[0], defaultColor[1], defaultColor[2]);
|
2018-10-20 21:04:41 -07:00
|
|
|
} else {
|
2019-01-31 20:50:34 -08:00
|
|
|
color = 0;
|
2018-10-20 21:04:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Conf::get(const Common::String &key, int &field, int defaultVal) {
|
|
|
|
field = ConfMan.hasKey(key) ? strToInt(ConfMan.get(key).c_str()) : defaultVal;
|
|
|
|
}
|
|
|
|
|
2018-10-21 10:53:32 -07:00
|
|
|
void Conf::get(const Common::String &key, bool &field, bool defaultVal) {
|
|
|
|
field = ConfMan.hasKey(key) ? strToInt(ConfMan.get(key).c_str()) != 0 : defaultVal;
|
|
|
|
}
|
|
|
|
|
2018-10-20 21:04:41 -07:00
|
|
|
void Conf::get(const Common::String &key, FACES &field, FACES defaultFont) {
|
2018-11-25 11:42:00 -08:00
|
|
|
field = ConfMan.hasKey(key) ? Screen::getFontId(ConfMan.get(key)) : defaultFont;
|
2018-10-20 21:04:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Conf::get(const Common::String &key, double &field, double defaultVal) {
|
|
|
|
field = ConfMan.hasKey(key) ? atof(ConfMan.get(key).c_str()) : defaultVal;
|
|
|
|
}
|
|
|
|
|
2019-01-31 20:50:34 -08:00
|
|
|
uint Conf::parseColor(const Common::String &str) {
|
2018-10-20 21:48:22 -07:00
|
|
|
char r[3], g[3], b[3];
|
2019-01-31 20:50:34 -08:00
|
|
|
uint rv, gv, bv;
|
2018-10-20 21:48:22 -07:00
|
|
|
|
|
|
|
if (str.size() == 6) {
|
2018-11-10 05:42:22 +00:00
|
|
|
r[0] = str[0];
|
|
|
|
r[1] = str[1];
|
|
|
|
r[2] = 0;
|
|
|
|
g[0] = str[2];
|
|
|
|
g[1] = str[3];
|
|
|
|
g[2] = 0;
|
|
|
|
b[0] = str[4];
|
|
|
|
b[1] = str[5];
|
|
|
|
b[2] = 0;
|
2018-10-20 21:48:22 -07:00
|
|
|
|
2019-01-31 20:50:34 -08:00
|
|
|
rv = strtol(r, nullptr, 16);
|
|
|
|
gv = strtol(g, nullptr, 16);
|
|
|
|
bv = strtol(b, nullptr, 16);
|
|
|
|
return g_system->getScreenFormat().RGBToColor(rv, gv, bv);
|
2018-10-20 21:48:22 -07:00
|
|
|
}
|
2019-01-31 20:50:34 -08:00
|
|
|
|
|
|
|
return 0;
|
2018-10-20 21:48:22 -07:00
|
|
|
}
|
|
|
|
|
2018-11-13 20:05:59 -08:00
|
|
|
} // End of namespace Glk
|