Remove the global TextStyle; this should fix some of the textual glitches

This commit is contained in:
2014-04-21 01:49:07 -04:00
parent f9a21dd068
commit 002ee640da
23 changed files with 411 additions and 461 deletions

View File

@@ -55,18 +55,15 @@ void cButton::draw(){
inWindow->setActive();
if(visible){
TEXT.font = "Geneva";
if(foundSilom()) {
TEXT.style = sf::Text::Regular;
TEXT.font = "Silom";
} else TEXT.style = sf::Text::Bold;
if(type == BTN_TINY) TEXT.pointSize = 9;
else if(type == BTN_PUSH) TEXT.pointSize = 10;
else TEXT.pointSize = 12;
TextStyle style;
if(type == BTN_TINY) style.pointSize = 9;
else if(type == BTN_PUSH) style.pointSize = 10;
else style.pointSize = 12;
from_rect = btnRects[type][depressed];
to_rect = frame;
rect_draw_some_item(buttons[btnGW[type]],from_rect,*inWindow,to_rect,sf::BlendAlpha);
TEXT.colour = sf::Color::Black;
style.colour = sf::Color::Black;
style.lineHeight = 8;
int textMode = 1;
if(type == BTN_TINY) {
textMode = 2;
@@ -74,12 +71,11 @@ void cButton::draw(){
} else if(type == BTN_PUSH) {
to_rect.top += 34;
}
win_draw_string(*inWindow,to_rect,lbl,textMode,8);
win_draw_string(*inWindow,to_rect,lbl,textMode,style);
// TODO: Adjust string location as appropriate
// Tiny button string location should be shifted right 20 pixels (or possibly 18)
// Push button string should be centred below the button
// Others may need adjustments too, not sure
TEXT.colour = sf::Color::Black;
// TODO: How is it supposed to know it's a default button when this fact is stored in the dialog, not the button?
if(key.spec && key.k == key_enter) drawFrame(2,frameStyle); // frame default button, to provide a visual cue that it's the default
}else{
@@ -192,7 +188,7 @@ void cLed::init(){
cLed::cLed(cDialog* parent) :
cButton(parent,CTRL_LED),
state(led_off),
textFont(SILOM),
textFont(FONT_BOLD),
textSize(10),
color(parent->defTextClr) {
setBtnType(BTN_LED);
@@ -247,19 +243,17 @@ void cLed::draw(){
inWindow->setActive();
if(visible){
TEXT.font = "Geneva";
if(foundSilom()) TEXT.style = sf::Text::Regular;
else TEXT.style = sf::Text::Bold;
TEXT.pointSize = 9;
TextStyle style;
style.pointSize = 9;
style.lineHeight = 8;
from_rect = ledRects[state][depressed];
to_rect = frame;
to_rect.right = to_rect.left + 14;
rect_draw_some_item(buttons[btnGW[BTN_LED]],from_rect,*inWindow,to_rect);
TEXT.colour = parent->defTextClr;
style.colour = parent->defTextClr;
to_rect.right = frame.right;
to_rect.left = frame.left + 18; // Possibly could be 20
win_draw_string(*inWindow,to_rect,lbl,2,8);
TEXT.colour = sf::Color::Black;
win_draw_string(*inWindow,to_rect,lbl,2,style);
}else{
tileImage(*inWindow,frame,bg_gworld,bg[parent->bg]);
}

View File

@@ -15,6 +15,7 @@
#include <map>
#include <vector>
#include "control.h"
#include "graphtool.h" // for eFont
enum eBtnType { // w x h
BTN_SM = 0, // 23x23 (PICT id 2000 / 2001)
@@ -84,7 +85,7 @@ public:
void draw();
private:
eLedState state;
eTextFont textFont;
eFont textFont;
sf::Color color;
short textSize;
static RECT ledRects[3][2];

View File

@@ -264,19 +264,6 @@ bool cControl::triggerFocusHandler(cDialog& me __attribute__((unused)), std::str
return true;
}
std::string cControl::font_nums[4] = {"Dungeon", "Geneva", "Silom", "MaidenWord"};
void cControl::init(){
// Check if Silom is available
// TODO: Ultimately, I'd like to distribute all needed fonts with the game, rendering this unnecessary
try {
ResMgr::get<FontRsrc>("Silom");
found_silom = true;
} catch(ResMgr::xResMgrErr) {
found_silom = false;
}
}
void cControl::drawFrame(short amt, bool med_or_lt){
// dk_gray had a 0..65535 component of 12287, and med_gray had a 0..65535 component of 24574
static sf::Color lt_gray = {224,224,224},dk_gray = {48,48,48},med_gray = {96,96,96};
@@ -295,12 +282,6 @@ void cControl::drawFrame(short amt, bool med_or_lt){
undo_clip(*inWindow);
}
bool cControl::found_silom;
bool cControl::foundSilom(){
return found_silom;
}
cControl::~cControl() {}
eControlType cControl::getType(){

View File

@@ -43,8 +43,6 @@ enum eControlType {
CTRL_SCROLL,// A scrollbar (not implemented yet)
};
enum eTextFont {DUNGEON, GENEVA, SILOM, MAIDENWORD};
//typedef bool (*click_callback_t)(cDialog&/*me*/,std::string/*id*/, eKeyMod/*mods*/);
//typedef bool (*focus_callback_t)(cDialog&/*me*/,std::string/*id*/,bool/*losing*/); // losing is true if losing focus, false if gaining focus.
typedef std::function<bool(cDialog&,std::string,eKeyMod)> click_callback_t;
@@ -70,7 +68,6 @@ public:
class cControl {
public:
static void init();
void attachKey(cKey key);
void detachKey();
void setTextToKey();
@@ -111,12 +108,9 @@ protected:
RECT frame;
int frameStyle;
cKey key;
static bool foundSilom();
static std::string font_nums[4];
void drawFrame(short amt, bool med_or_lt);
private:
eControlType type;
static bool found_silom;
};
#endif

View File

@@ -225,13 +225,13 @@ template<> pair<string,cTextMsg*> cDialog::parse(Element& who /*text*/){
std::string val;
attr->GetValue(&val);
if(val == "dungeon")
p.second->setFormat(TXT_FONT, DUNGEON);
else if(val == "geneva")
p.second->setFormat(TXT_FONT, GENEVA);
else if(val == "silom")
p.second->setFormat(TXT_FONT, SILOM);
p.second->setFormat(TXT_FONT, FONT_DUNGEON);
else if(val == "plain")
p.second->setFormat(TXT_FONT, FONT_PLAIN);
else if(val == "bold")
p.second->setFormat(TXT_FONT, FONT_BOLD);
else if(val == "maidenword")
p.second->setFormat(TXT_FONT, MAIDENWORD);
p.second->setFormat(TXT_FONT, FONT_MAIDWORD);
else throw xBadVal("text",name,val,attr->Row(),attr->Column(),fname);
}else if(name == "size"){
std::string val;
@@ -584,13 +584,13 @@ template<> pair<string,cLed*> cDialog::parse(Element& who /*LED*/){
std::string val;
attr->GetValue(&val);
if(val == "dungeon")
p.second->setFormat(TXT_FONT, DUNGEON);
else if(val == "geneva")
p.second->setFormat(TXT_FONT, GENEVA);
else if(val == "silom")
p.second->setFormat(TXT_FONT, SILOM);
p.second->setFormat(TXT_FONT, FONT_DUNGEON);
else if(val == "plain")
p.second->setFormat(TXT_FONT, FONT_PLAIN);
else if(val == "bold")
p.second->setFormat(TXT_FONT, FONT_BOLD);
else if(val == "maidenword")
p.second->setFormat(TXT_FONT, MAIDENWORD);
p.second->setFormat(TXT_FONT, FONT_MAIDWORD);
else throw xBadVal("text",name,val,attr->Row(),attr->Column(),fname);
}else if(name == "size"){
std::string val;
@@ -857,7 +857,6 @@ void cDialog::recalcRect(){
}
void cDialog::init(){
cControl::init();
cButton::init();
cLed::init();
cPict::init();
@@ -1145,7 +1144,7 @@ bool cDialog::addLabelFor(std::string key, std::string label, eLabelPos where, s
labelCtrl = new cTextMsg(*this);
}
labelCtrl->setText(label);
labelCtrl->setFormat(TXT_FONT, bold ? SILOM : GENEVA);
labelCtrl->setFormat(TXT_FONT, bold ? FONT_BOLD : FONT_PLAIN);
if(bg == BG_DARK && dynamic_cast<cButton*>(&ctrl) != NULL)
labelCtrl->setColour(defTextClr);
else labelCtrl->setColour(ctrl.getColour());

View File

@@ -265,10 +265,11 @@ cThreeChoice::cThreeChoice
}
void cThreeChoice::init_strings(std::vector<std::string>& strings, unsigned short left){
TextStyle style;
RECT cur_text_rect = {2, left, 0, 0};
size_t total_len, str_width, str_height;
for (unsigned int i = 0; i < strings.size(); i++)
total_len += string_length(strings[i]);
total_len += string_length(strings[i], style);
total_len = total_len * 12;
str_width = s_sqrt(total_len) + 20;
//print_nums(0,total_len,str_width);
@@ -279,7 +280,7 @@ void cThreeChoice::init_strings(std::vector<std::string>& strings, unsigned shor
for(unsigned int j = 0; j < strings.size(); j++){
std::ostringstream sout;
sout << "str" << j + 1;
str_height = ((string_length(strings[j]) + 60) / str_width) * 12 + 16;
str_height = ((string_length(strings[j], style) + 60) / str_width) * 12 + 16;
cur_text_rect.bottom = cur_text_rect.top + str_height;
cTextMsg* str = new cTextMsg(*me);
str->setText(strings[j]);

View File

@@ -88,19 +88,20 @@ void cTextField::draw(){
std::string contents = getText();
RECT rect = frame;
rect.inset(2,6);
TEXT.font = "Geneva";
TEXT.style = sf::Text::Regular;
TEXT.pointSize = 12;
TEXT.colour = sf::Color::Black;
TextStyle style;
style.font = FONT_PLAIN;
style.pointSize = 12;
style.colour = sf::Color::Black;
style.lineHeight = 14;
// TODO: Proper support for multiline fields
int ip_offset, sel_offset;
if(haveFocus) {
std::string pre_ip = contents.substr(0, insertionPoint);
// TODO: Update string_length to take a std::string
ip_offset = string_length(pre_ip);
ip_offset = string_length(pre_ip, style);
if(insertionPoint != selectionPoint) {
std::string pre_sel = contents.substr(0, selectionPoint);
sel_offset = string_length(pre_sel);
sel_offset = string_length(pre_sel, style);
int sel_start = std::min(ip_offset, sel_offset) + 1;
int sel_width = abs(ip_offset - sel_offset) + 3;
RECT selectRect = frame;
@@ -122,7 +123,7 @@ void cTextField::draw(){
}
}
// TODO: Update win_draw_string to take a std::string
win_draw_string(*inWindow, rect, contents, 0, 14);
win_draw_string(*inWindow, rect, contents, 0, style);
}
void cTextField::handleInput(cKey key) {

View File

@@ -43,10 +43,10 @@ void cTextMsg::setFormat(eFormat prop, short val) throw(xUnsupportedProp){
textSize = val;
break;
case TXT_FONT:
if(val == DUNGEON) textFont = DUNGEON;
else if(val == GENEVA) textFont = GENEVA;
else if(val == MAIDENWORD) textFont = MAIDENWORD;
else textFont = SILOM; // Defaults to Silom if an invalid value is provided.
if(val == FONT_DUNGEON) textFont = FONT_DUNGEON;
else if(val == FONT_PLAIN) textFont = FONT_PLAIN;
else if(val == FONT_MAIDWORD) textFont = FONT_MAIDWORD;
else textFont = FONT_BOLD; // Defaults to bold if an invalid value is provided.
break;
case TXT_WRAP:
throw xUnsupportedProp(prop);
@@ -76,7 +76,7 @@ short cTextMsg::getFormat(eFormat prop) throw(xUnsupportedProp){
cTextMsg::cTextMsg(cDialog& parent) :
cControl(CTRL_TEXT,parent),
drawFramed(false),
textFont(SILOM),
textFont(FONT_BOLD),
textSize(10),
color(parent.defTextClr),
clickable(false),
@@ -85,7 +85,7 @@ cTextMsg::cTextMsg(cDialog& parent) :
cTextMsg::cTextMsg(sf::RenderWindow& parent) :
cControl(CTRL_TEXT,parent),
drawFramed(false),
textFont(SILOM),
textFont(FONT_BOLD),
textSize(10),
color(cDialog::defaultBackground == cDialog::BG_DARK ? sf::Color::White : sf::Color::Black),
clickable(false),
@@ -101,10 +101,9 @@ void cTextMsg::draw(){
inWindow->setActive();
if(visible){
TEXT.font = font_nums[textFont];
if(textFont == SILOM && !foundSilom()) TEXT.style = sf::Text::Bold;
else TEXT.style = sf::Text::Regular;
TEXT.pointSize = textSize;
TextStyle style;
style.font = textFont;
style.pointSize = textSize;
if(drawFramed) drawFrame(2,frameStyle);
sf::Color draw_color = color;
if(clickable && depressed){
@@ -112,13 +111,15 @@ void cTextMsg::draw(){
draw_color.g = 256 - draw_color.g;
draw_color.b = 256 - draw_color.b;
}
TEXT.colour = draw_color;
style.colour = draw_color;
if (to_rect.bottom - to_rect.top < 20) { // essentially, it's a single line
style.lineHeight = 12;
to_rect.left += 3;
win_draw_string(*inWindow,to_rect,lbl,3,12);
win_draw_string(*inWindow,to_rect,lbl,3,style);
}else {
style.lineHeight = textSize + 2;
to_rect.inset(4,4);
win_draw_string(*inWindow,to_rect,lbl,0,textSize + 2);
win_draw_string(*inWindow,to_rect,lbl,0,style);
}
}
}

View File

@@ -13,6 +13,7 @@
#include <string>
#include "control.h"
#include "graphtool.h" // for eFont
class cTextMsg : public cControl {
public:
@@ -31,7 +32,7 @@ public:
private:
bool drawFramed, clickable;
short textSize;
eTextFont textFont;
eFont textFont;
sf::Color color;
std::string fromList;
click_callback_t onClick;