mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-23 04:33:09 +00:00
Misc text drawing improvements.
Added carets/text edit widgets. svn-id: r33684
This commit is contained in:
parent
21989844a9
commit
7c132d340a
@ -27,6 +27,8 @@
|
||||
#include "gui/eval.h"
|
||||
#include "gui/newgui.h"
|
||||
|
||||
#include "gui/ThemeEval.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text)
|
||||
@ -52,10 +54,10 @@ void EditTextWidget::setEditString(const String &str) {
|
||||
}
|
||||
|
||||
void EditTextWidget::reflowLayout() {
|
||||
_leftPadding = g_gui.evaluator()->getVar("EditTextWidget.leftPadding", 0);
|
||||
_rightPadding = g_gui.evaluator()->getVar("EditTextWidget.rightPadding", 0);
|
||||
_leftPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Left", 0);
|
||||
_rightPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Right", 0);
|
||||
|
||||
_font = (Theme::FontStyle)g_gui.evaluator()->getVar("EditTextWidget.font", Theme::kFontStyleNormal);
|
||||
_font = (Theme::FontStyle)g_gui.xmlEval()->getVar("EditTextWidget.Font", Theme::kFontStyleNormal);
|
||||
|
||||
EditableWidget::reflowLayout();
|
||||
}
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include "gui/PopUpWidget.h"
|
||||
#include "engines/engine.h"
|
||||
|
||||
#include "gui/ThemeEval.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
//
|
||||
@ -380,9 +382,9 @@ void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
||||
}
|
||||
|
||||
void PopUpWidget::reflowLayout() {
|
||||
_leftPadding = g_gui.evaluator()->getVar("PopUpWidget.leftPadding", 0);
|
||||
_rightPadding = g_gui.evaluator()->getVar("PopUpWidget.rightPadding", 0);
|
||||
_labelSpacing = g_gui.evaluator()->getVar("PopUpWidget.labelSpacing", 0);
|
||||
_leftPadding = g_gui.xmlEval()->getVar("Globals.PopUpWidget.Padding.Left", 0);
|
||||
_rightPadding = g_gui.xmlEval()->getVar("Globals.PopUpWidget.Padding.Right", 0);
|
||||
_labelSpacing = g_gui.xmlEval()->getVar("Globals.PopUpWidget.labelSpacing", 10);
|
||||
|
||||
Widget::reflowLayout();
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ bool ThemeParser::parserCallback_font(ParserNode *node) {
|
||||
else if (!parseIntegerKey(node->values["color"].c_str(), 3, &red, &green, &blue))
|
||||
return parserError("Error when parsing color value for font definition.");
|
||||
|
||||
if (!_theme->addFont(node->values["id"], red, green, blue))
|
||||
if (!_theme->addFont(node->values["id"], node->values["file"], red, green, blue))
|
||||
return parserError("Error when loading Font in theme engine.");
|
||||
|
||||
return true;
|
||||
|
@ -343,7 +343,7 @@ protected:
|
||||
XML_KEY(fonts)
|
||||
XML_KEY(font)
|
||||
XML_PROP(id, true)
|
||||
XML_PROP(type, true)
|
||||
XML_PROP(file, true)
|
||||
XML_PROP(color, true)
|
||||
KEY_END()
|
||||
KEY_END()
|
||||
|
@ -89,7 +89,8 @@ const ThemeRenderer::TextDataInfo ThemeRenderer::kTextDataDefaults[] = {
|
||||
{kTextDataDisabled, "text_disabled"},
|
||||
{kTextDataInverted, "text_inverted"},
|
||||
{kTextDataButton, "text_button"},
|
||||
{kTextDataButtonHover, "text_button_hover"}
|
||||
{kTextDataButtonHover, "text_button_hover"},
|
||||
{kTextDataNormalFont, "text_normal"}
|
||||
};
|
||||
|
||||
|
||||
@ -232,7 +233,7 @@ bool ThemeRenderer::addTextData(const Common::String &drawDataId, const Common::
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ThemeRenderer::addFont(const Common::String &fontId, int r, int g, int b) {
|
||||
bool ThemeRenderer::addFont(const Common::String &fontId, const Common::String &file, int r, int g, int b) {
|
||||
TextData textId = getTextDataId(fontId);
|
||||
|
||||
if (textId == -1)
|
||||
@ -243,8 +244,22 @@ bool ThemeRenderer::addFont(const Common::String &fontId, int r, int g, int b) {
|
||||
|
||||
_texts[textId] = new TextDrawData;
|
||||
|
||||
// TODO: Allow the user to specify the font he wants, instead of choosing based on resolution
|
||||
_texts[textId]->_fontPtr = _font;
|
||||
// _texts[textId]->_fontPtr = _font;
|
||||
|
||||
if (file == "default") {
|
||||
_texts[textId]->_fontPtr = _font;
|
||||
} else {
|
||||
_texts[textId]->_fontPtr = FontMan.getFontByName(file);
|
||||
|
||||
if (!_texts[textId]->_fontPtr) {
|
||||
_texts[textId]->_fontPtr = loadFont(file.c_str());
|
||||
|
||||
if (!_texts[textId]->_fontPtr)
|
||||
error("Couldn't load %s font '%s'", fontId.c_str(), file.c_str());
|
||||
|
||||
FontMan.assignFontToName(file, _texts[textId]->_fontPtr);
|
||||
}
|
||||
}
|
||||
|
||||
_texts[textId]->_color.r = r;
|
||||
_texts[textId]->_color.g = g;
|
||||
@ -552,8 +567,12 @@ void ThemeRenderer::drawDialogBackground(const Common::Rect &r, uint16 hints, Wi
|
||||
void ThemeRenderer::drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state) {
|
||||
if (!ready())
|
||||
return;
|
||||
|
||||
debugWidgetPosition("Caret", r);
|
||||
|
||||
if (erase) {
|
||||
restoreBackground(r);
|
||||
addDirtyRect(r);
|
||||
} else
|
||||
queueDD(kDDCaret, r);
|
||||
}
|
||||
|
||||
void ThemeRenderer::drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align) {
|
||||
@ -636,19 +655,28 @@ void ThemeRenderer::drawText(const Common::Rect &r, const Common::String &str, W
|
||||
queueDDText(kTextDataInverted, r, str, false, useEllipsis, align);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (font) {
|
||||
case kFontStyleNormal:
|
||||
queueDDText(kTextDataNormalFont, r, str, true, useEllipsis, align);
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case kStateDisabled:
|
||||
queueDDText(kTextDataDisabled, r, str, true, useEllipsis, align);
|
||||
break;
|
||||
return;
|
||||
|
||||
case kStateHighlight:
|
||||
queueDDText(kTextDataHover, r, str, true, useEllipsis, align);
|
||||
break;
|
||||
return;
|
||||
|
||||
case kStateEnabled:
|
||||
queueDDText(kTextDataDefault, r, str, true, useEllipsis, align);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,6 +174,7 @@ protected:
|
||||
kTextDataInverted,
|
||||
kTextDataButton,
|
||||
kTextDataButtonHover,
|
||||
kTextDataNormalFont,
|
||||
kTextDataMAX
|
||||
};
|
||||
|
||||
@ -264,10 +265,30 @@ public:
|
||||
/**
|
||||
* FONT MANAGEMENT METHODS
|
||||
*/
|
||||
const Graphics::Font *getFont(FontStyle font) const { return _font; }
|
||||
int getFontHeight(FontStyle font = kFontStyleBold) const { if (_initOk) return _font->getFontHeight(); return 0; }
|
||||
int getStringWidth(const Common::String &str, FontStyle font) const { if (_initOk) return _font->getStringWidth(str); return 0; }
|
||||
int getCharWidth(byte c, FontStyle font) const { if (_initOk) return _font->getCharWidth(c); return 0; }
|
||||
|
||||
TextData fontStyleToData(FontStyle font) const {
|
||||
switch (font) {
|
||||
case kFontStyleNormal:
|
||||
return kTextDataNormalFont;
|
||||
|
||||
default:
|
||||
return kTextDataDefault;
|
||||
}
|
||||
}
|
||||
|
||||
const Graphics::Font *getFont(FontStyle font) const { return _texts[fontStyleToData(font)]->_fontPtr; }
|
||||
|
||||
int getFontHeight(FontStyle font = kFontStyleBold) const {
|
||||
return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getFontHeight() : 0;
|
||||
}
|
||||
|
||||
int getStringWidth(const Common::String &str, FontStyle font) const {
|
||||
return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getStringWidth(str) : 0;
|
||||
}
|
||||
|
||||
int getCharWidth(byte c, FontStyle font) const {
|
||||
return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getCharWidth(c) : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -372,7 +393,7 @@ public:
|
||||
* @param cached Whether this DD set will be cached beforehand.
|
||||
*/
|
||||
bool addDrawData(const Common::String &data, bool cached);
|
||||
bool addFont(const Common::String &fontName, int r, int g, int b);
|
||||
bool addFont(const Common::String &fontName, const Common::String &file, int r, int g, int b);
|
||||
|
||||
/**
|
||||
* Adds a new TextStep from the ThemeParser. This will be deprecated/removed once the
|
||||
@ -391,7 +412,7 @@ public:
|
||||
* this checks if the renderer is initialized AND if the theme
|
||||
* is loaded.
|
||||
*/
|
||||
bool ready() {
|
||||
bool ready() const {
|
||||
return _initOk && _themeOk;
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -59,29 +59,33 @@
|
||||
|
||||
<fonts>
|
||||
<font id = 'text_default'
|
||||
type = 'default'
|
||||
file = 'default'
|
||||
color = 'black'
|
||||
/>
|
||||
<font id = 'text_hover'
|
||||
type = 'default'
|
||||
file = 'default'
|
||||
color = 'bgreen'
|
||||
/>
|
||||
<font id = 'text_disabled'
|
||||
type = 'default'
|
||||
file = 'default'
|
||||
color = '128, 128, 128'
|
||||
/>
|
||||
<font id = 'text_inverted'
|
||||
type = 'default'
|
||||
file = 'default'
|
||||
color = '0, 0, 0'
|
||||
/>
|
||||
<font id = 'text_button'
|
||||
type = 'default'
|
||||
file = 'default'
|
||||
color = 'white'
|
||||
/>
|
||||
<font id = 'text_button_hover'
|
||||
type = 'default'
|
||||
file = 'default'
|
||||
color = 'blandyellow'
|
||||
/>
|
||||
<font id = 'text_normal'
|
||||
file = 'helvr12-l1.bdf'
|
||||
color = 'black'
|
||||
/>
|
||||
</fonts>
|
||||
|
||||
<defaults fill = 'gradient' fg_color = 'white' bevel_color = '237, 169, 72'/>
|
||||
@ -298,10 +302,24 @@
|
||||
horizontal_align = 'right'
|
||||
/>
|
||||
</drawdata>
|
||||
|
||||
<drawdata id = 'widget_textedit' cache = false>
|
||||
<drawstep func = 'roundedsq'
|
||||
fill = 'foreground'
|
||||
radius = 4
|
||||
fg_color = 'blandyellow'
|
||||
shadow = 0
|
||||
bevel = 1
|
||||
bevel_color = 'shadowcolor'
|
||||
/>
|
||||
</drawdata>
|
||||
|
||||
/* Tanoku-TODO: text editing width + CARET!
|
||||
/* <drawdata id = 'widget_textedit' cache = false>
|
||||
<drawstep func = 'roundedsq' */
|
||||
<drawdata id = 'caret' cache = false>
|
||||
<drawstep func = 'square'
|
||||
fill = 'foreground'
|
||||
fg_color = 'black'
|
||||
/>
|
||||
</drawdata>
|
||||
|
||||
<drawdata id = 'default_bg' cache = false>
|
||||
<drawstep func = 'roundedsq'
|
||||
@ -435,6 +453,7 @@
|
||||
|
||||
<def var = 'ListWidget.hlLeftPadding' value = '8'/>
|
||||
<def var = 'ListWidget.hlRightPadding' value = '16'/>
|
||||
<def var = 'PopUpWidget.labelSpacing' value = '10' />
|
||||
|
||||
<widget name = 'OptionsLabel'
|
||||
size = '110, Globals.Line.Height'
|
||||
|
Loading…
x
Reference in New Issue
Block a user