Skip to content

Commit

Permalink
GLK: Splitting font related info from Conf into their own classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jan 1, 2019
1 parent f25b3d9 commit 1021da1
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 223 deletions.
61 changes: 26 additions & 35 deletions engines/glk/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,23 @@ Conf::Conf(InterpreterType interpType) {
_imageW = g_system->getWidth();
_imageH = g_system->getHeight();
_cellW = _cellH = 8;
_leading = 0;
_baseLine = 0;

get("moreprompt", _morePrompt, "\207 more \207");
get("morecolor", _moreColor);
get("morecolor", _moreSave);
get("morefont", _moreFont, PROPB);
get("morealign", _moreAlign);
get("monoaspect", _monoAspect, 1.0);
get("propaspect", _propAspect, 1.0);
get("monosize", _monoSize, 11);
get("monor", _monoR);
get("monob", _monoR);
get("monoi", _monoI);
get("monoz", _monoZ);
get("monofont", _monoFont, "Liberation Mono");
get("propsize", _propSize, 12);
get("propr", _propR);
get("propb", _propR);
get("propi", _propI);
get("propz", _propZ);
get("propfont", _propFont, "Linux Libertine O");

get("moreprompt", _propInfo._morePrompt, "\207 more \207");
get("morecolor", _propInfo._moreColor);
get("morecolor", _propInfo._moreSave);
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);
get("rows", _rows, 25);
get("cols", _cols, 60);

if (ConfMan.hasKey("leading"))
_leading = static_cast<int>(atof(ConfMan.get("leading").c_str()) + 0.5);
_monoInfo._leading = _propInfo._leading = static_cast<int>(atof(ConfMan.get("leading").c_str()) + 0.5);
if (ConfMan.hasKey("baseline"))
_baseLine = static_cast<int>(atof(ConfMan.get("baseline").c_str()) + 0.5);
_propInfo._baseLine = static_cast<int>(atof(ConfMan.get("baseline").c_str()) + 0.5);

if (ConfMan.hasKey("minrows"))
_rows = MAX(_rows, strToInt(ConfMan.get("minrows").c_str()));
Expand Down Expand Up @@ -125,27 +113,30 @@ Conf::Conf(InterpreterType interpType) {
get("tmarginy", _tMarginY, 7);
get("gamma", _gamma, 1.0);

get("caretcolor", _caretColor);
get("caretcolor", _caretSave);
get("linkcolor", _linkColor, BLUE);
get("linkcolor", _linkSave, BLUE);
get("linkcolor", _propInfo._linkColor, BLUE);
Common::copy(&_propInfo._linkColor[0], &_propInfo._linkSave[3], &_monoInfo._linkColor[0]);
Common::copy(&_propInfo._linkColor[0], &_propInfo._linkSave[3], &_propInfo._linkSave[0]);

get("bordercolor", _borderColor);
get("bordercolor", _borderSave);
get("windowcolor", _windowColor, WHITE);
get("windowcolor", _windowSave, WHITE);
get("lcd", _lcd, 1);
get("caretshape", _caretShape, 2);
get("caretcolor", _propInfo._caretColor);
get("caretcolor", _propInfo._caretSave);
get("caretshape", _propInfo._caretShape, 2);

_linkStyle = ConfMan.hasKey("linkstyle") && !strToInt(ConfMan.get("linkstyle").c_str()) ? 0 : 1;
_propInfo._linkStyle = _monoInfo._linkStyle = ConfMan.hasKey("linkstyle")
&& !strToInt(ConfMan.get("linkstyle").c_str()) ? 0 : 1;

get("scrollwidth", _scrollWidth);
get("scrollbg", _scrollBg, SCROLL_BG);
get("scrollfg", _scrollFg, SCROLL_FG);
get("justify", _justify);
get("quotes", _quotes, 1);
get("dashes", _dashes, 1);
get("spaces", _spaces);
get("caps", _caps);
get("justify", _propInfo._justify);
get("quotes", _propInfo._quotes, 1);
get("dashes", _propInfo._dashes, 1);
get("spaces", _propInfo._spaces);
get("caps", _propInfo._caps);
get("graphics", _graphics, true);
get("sound", _sound, true);
get("speak", _speak);
Expand Down
32 changes: 3 additions & 29 deletions engines/glk/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define GLK_CONF_H

#include "glk/glk_types.h"
#include "glk/fonts.h"
#include "glk/windows.h"

namespace Glk {
Expand Down Expand Up @@ -68,26 +69,8 @@ class Conf {
*/
void parseColor(const Common::String &str, byte *color);
public:
Common::String _morePrompt;
byte _moreColor[3], _moreSave[3];
FACES _moreFont;
int _moreAlign;
double _monoAspect;
double _propAspect;
double _monoSize;
Common::String _monoR;
Common::String _monoB;
Common::String _monoI;
Common::String _monoZ;
Common::String _monoFont;
double _propSize;
Common::String _propR;
Common::String _propB;
Common::String _propI;
Common::String _propZ;
Common::String _propFont;
int _leading;
int _baseLine;
MonoFontInfo _monoInfo;
PropFontInfo _propInfo;
int _cols, _rows;
int _lockCols, _lockRows;
int _wMarginX, _wMarginY;
Expand All @@ -96,20 +79,11 @@ class Conf {
int _wBorderX, _wBorderY;
int _tMarginX, _tMarginY;
double _gamma;
byte _caretColor[3], _caretSave[3];
byte _linkColor[3], _linkSave[3];
byte _borderColor[3], _borderSave[3];
byte _windowColor[3], _windowSave[3];
int _lcd;
int _caretShape;
int _linkStyle;
int _scrollWidth;
byte _scrollBg[3], _scrollFg[3];
int _justify;
int _quotes;
int _dashes;
int _spaces;
int _caps;
bool _graphics;
bool _sound;
bool _speak;
Expand Down
2 changes: 1 addition & 1 deletion engines/glk/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void Events::initializeCursors() {

// Setup selection cusor sized to the vertical line size
Surface &sel = _cursors[CURSOR_IBEAM];
sel.create(5, g_conf->_leading, g_system->getScreenFormat());
sel.create(5, g_conf->_propInfo._leading, g_system->getScreenFormat());
sel.fillRect(Common::Rect(0, 0, sel.w, sel.h), TRANSPARENT);
sel.hLine(0, 0, 4, 0);
sel.hLine(0, sel.h - 1, 4, 0);
Expand Down
83 changes: 83 additions & 0 deletions engines/glk/fonts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* 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.
*
*/

#include "glk/fonts.h"
#include "glk/glk.h"
#include "glk/screen.h"
#include "glk/windows.h"

namespace Glk {

FontInfo::FontInfo() : _size(0), _aspect(0), _cellW(0), _cellH(0), _leading(0), _baseLine(0),
_linkStyle(0), _moreFont(PROPB), _moreAlign(0), _caps(0) {
Common::fill(&_linkColor[0], &_linkColor[3], 0);
Common::fill(&_linkSave[0], &_linkSave[3], 0);
Common::fill(&_moreColor[0], &_moreColor[3], 0);
Common::fill(&_moreSave[0], &_moreSave[3], 0);
}

/*--------------------------------------------------------------------------*/

PropFontInfo::PropFontInfo() : _justify(0), _quotes(0), _dashes(0), _spaces(0), _caretShape(0) {
Common::fill(&_caretColor[0], &_caretColor[3], 0);
Common::fill(&_caretSave[0], &_caretSave[3], 0);
}

/*--------------------------------------------------------------------------*/

void PropFontInfo::drawCaret(const Point &pos) {
const byte *rgb = _caretColor;
Graphics::Screen &s = *g_vm->_screen;
uint color = s.format.RGBToColor(rgb[0], rgb[1], rgb[2]);
int x = pos.x / GLI_SUBPIX, y = pos.y;

switch (_caretShape) {
case SMALL_DOT:
s.hLine(x + 0, y + 1, x + 0, color);
s.hLine(x - 1, y + 2, x + 1, color);
s.hLine(x - 2, y + 3, x + 2, color);
break;

case FAT_DOT:
s.hLine(x + 0, y + 1, x + 0, color);
s.hLine(x - 1, y + 2, x + 1, color);
s.hLine(x - 2, y + 3, x + 2, color);
s.hLine(x - 3, y + 4, x + 3, color);
break;

case THIN_LINE:
s.vLine(x, y - _baseLine + 1, y - 1, color);
break;

case FAT_LINE:
s.fillRect(Rect(x, y - _baseLine + 1, x + 1, y - 1), color);
break;

default:
// BLOCK
s.fillRect(Rect(x, y - _baseLine + 1, x + _cellW, y - 1), color);
break;
}
}


} // End of namespace Glk
90 changes: 90 additions & 0 deletions engines/glk/fonts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* 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.
*
*/

#ifndef GLK_FONTS_H
#define GLK_FONTS_H

#include "glk/glk_types.h"
#include "glk/utils.h"

namespace Glk {

enum FACES { MONOR, MONOB, MONOI, MONOZ, PROPR, PROPB, PROPI, PROPZ, CUSTOM, CUSTOM2 };
enum TYPES { MONOF, PROPF };
enum STYLES { FONTR, FONTB, FONTI, FONTZ };

/**
* Font configuration info
*/
struct FontInfo {
double _size;
double _aspect;
int _cellW, _cellH;
int _leading;
int _baseLine;
byte _linkColor[3], _linkSave[3];
byte _moreColor[3], _moreSave[3];
int _linkStyle;
FACES _moreFont;
int _moreAlign;
Common::String _morePrompt;
int _caps;

/**
* Constructor
*/
FontInfo();
};

/**
* Font info for mono (fixed size) fonts
*/
struct MonoFontInfo : public FontInfo {
};

/**
* Font info fro proportinate (variable size) fonts
*/
struct PropFontInfo : public MonoFontInfo {
byte _caretColor[3], _caretSave[3];
int _caretShape;
int _justify;
int _quotes;
int _dashes;
int _spaces;

/**
* Constructor
*/
PropFontInfo();

/**
* Draws the text input caret at the given position
* @remarks The position specifies the caret's bottom-left corner,
* and the X position is in multiples of GLI_SUBPIX
*/
void drawCaret(const Point &pos);
};

} // End of namespace Glk

#endif
2 changes: 1 addition & 1 deletion engines/glk/frotz/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void FrotzScreen::loadFonts(Common::Archive *archive) {
if (!f.open("NotoSansRunic-Regular.ttf", *archive))
error("Could not load font");

_fonts.push_back(Graphics::loadTTFFont(f, g_conf->_propSize, Graphics::kTTFSizeModeCharacter));
_fonts.push_back(Graphics::loadTTFFont(f, g_conf->_propInfo._size, Graphics::kTTFSizeModeCharacter));
f.close();
}

Expand Down
4 changes: 2 additions & 2 deletions engines/glk/glk_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ void GlkAPI::glk_stylehint_set(uint wintype, uint style, uint hint, int val) {
}

if (wintype == wintype_TextBuffer && style == style_Normal && hint == stylehint_TextColor) {
memcpy(g_conf->_moreColor, styles[style].fg, 3);
memcpy(g_conf->_caretColor, styles[style].fg, 3);
memcpy(g_conf->_propInfo._moreColor, styles[style].fg, 3);
memcpy(g_conf->_propInfo._caretColor, styles[style].fg, 3);
}
}

Expand Down
1 change: 1 addition & 0 deletions engines/glk/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MODULE_OBJS := \
conf.o \
detection.o \
events.o \
fonts.o \
glk.o \
glk_api.o \
picture.o \
Expand Down
Loading

0 comments on commit 1021da1

Please sign in to comment.