encapsulate control.lbl so setText() is required
This commit is contained in:
@@ -75,10 +75,10 @@ void cButton::draw(){
|
|||||||
} else if(type == BTN_PUSH) {
|
} else if(type == BTN_PUSH) {
|
||||||
to_rect.top += 42;
|
to_rect.top += 42;
|
||||||
style.colour = textClr;
|
style.colour = textClr;
|
||||||
int w = string_length(lbl, style);
|
int w = string_length(getText(), style);
|
||||||
to_rect.inset((w - 30) / -2,0);
|
to_rect.inset((w - 30) / -2,0);
|
||||||
}
|
}
|
||||||
std::string label = lbl, keyDesc = getAttachedKeyDescription();
|
std::string label = getText(), keyDesc = getAttachedKeyDescription();
|
||||||
for(size_t key_pos = label.find_first_of(KEY_PLACEHOLDER); key_pos < label.size(); key_pos = label.find_first_of(KEY_PLACEHOLDER)) {
|
for(size_t key_pos = label.find_first_of(KEY_PLACEHOLDER); key_pos < label.size(); key_pos = label.find_first_of(KEY_PLACEHOLDER)) {
|
||||||
label.replace(key_pos, 1, keyDesc);
|
label.replace(key_pos, 1, keyDesc);
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ void cButton::validatePostParse(ticpp::Element& elem, std::string fname, const s
|
|||||||
if(labelledButtons.count(type)) {
|
if(labelledButtons.count(type)) {
|
||||||
if(!attrs.count("color") && !attrs.count("colour") && parent->getBg() == cDialog::BG_DARK)
|
if(!attrs.count("color") && !attrs.count("colour") && parent->getBg() == cDialog::BG_DARK)
|
||||||
setColour(sf::Color::White);
|
setColour(sf::Color::White);
|
||||||
if(!lbl.empty() && !attrs.count("width"))
|
if(!getText().empty() && !attrs.count("width"))
|
||||||
throw xMissingAttr(elem.Value(), "width", elem.Row(), elem.Column(), fname);
|
throw xMissingAttr(elem.Value(), "width", elem.Row(), elem.Column(), fname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -603,8 +603,8 @@ cControl::storage_t cControl::store() const {
|
|||||||
|
|
||||||
void cControl::restore(storage_t to) {
|
void cControl::restore(storage_t to) {
|
||||||
if(to.find("text") != to.end())
|
if(to.find("text") != to.end())
|
||||||
lbl = boost::any_cast<std::string>(to["text"]);
|
setText(boost::any_cast<std::string>(to["text"]));
|
||||||
else lbl = "";
|
else setText("");
|
||||||
if(to.find("visible") != to.end())
|
if(to.find("visible") != to.end())
|
||||||
boost::any_cast<bool>(to["visible"]) ? show() : hide();
|
boost::any_cast<bool>(to["visible"]) ? show() : hide();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -435,8 +435,6 @@ protected:
|
|||||||
/// The parent window of the control.
|
/// The parent window of the control.
|
||||||
/// This is for use in implementing draw().
|
/// This is for use in implementing draw().
|
||||||
sf::RenderWindow* inWindow;
|
sf::RenderWindow* inWindow;
|
||||||
/// The control's current text.
|
|
||||||
std::string lbl;
|
|
||||||
/// Whether the control is visible
|
/// Whether the control is visible
|
||||||
bool visible, depressed = false; ///< Whether the control is depressed; only applicable for clickable controls
|
bool visible, depressed = false; ///< Whether the control is depressed; only applicable for clickable controls
|
||||||
/// The control's bounding rect.
|
/// The control's bounding rect.
|
||||||
@@ -457,6 +455,8 @@ protected:
|
|||||||
void playClickSound();
|
void playClickSound();
|
||||||
private:
|
private:
|
||||||
friend class cDialog; // TODO: This is only so it can access parseColour... hack!
|
friend class cDialog; // TODO: This is only so it can access parseColour... hack!
|
||||||
|
/// The control's current text.
|
||||||
|
std::string lbl;
|
||||||
eControlType type;
|
eControlType type;
|
||||||
std::map<eDlogEvt, boost::any> event_handlers;
|
std::map<eDlogEvt, boost::any> event_handlers;
|
||||||
// Transient values only used during parsing
|
// Transient values only used during parsing
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ void cLed::draw(){
|
|||||||
style.colour = textClr;
|
style.colour = textClr;
|
||||||
to_rect.right = frame.right;
|
to_rect.right = frame.right;
|
||||||
to_rect.left = frame.left + 18; // Possibly could be 20
|
to_rect.left = frame.left + 18; // Possibly could be 20
|
||||||
win_draw_string(*inWindow,to_rect,lbl,wrapLabel ? eTextMode::WRAP : eTextMode::LEFT_TOP,style);
|
win_draw_string(*inWindow,to_rect,getText(),wrapLabel ? eTextMode::WRAP : eTextMode::LEFT_TOP,style);
|
||||||
}
|
}
|
||||||
|
|
||||||
inWindow->setActive();
|
inWindow->setActive();
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ void cTextMsg::setFixed(bool w, bool h) {
|
|||||||
|
|
||||||
void cTextMsg::calculate_layout() {
|
void cTextMsg::calculate_layout() {
|
||||||
to_rect = frame;
|
to_rect = frame;
|
||||||
msg = lbl;
|
msg = getText();
|
||||||
for(const auto& key : keyRefs) {
|
for(const auto& key : keyRefs) {
|
||||||
size_t pos = msg.find_first_of(KEY_PLACEHOLDER);
|
size_t pos = msg.find_first_of(KEY_PLACEHOLDER);
|
||||||
if(pos == std::string::npos) break;
|
if(pos == std::string::npos) break;
|
||||||
@@ -125,7 +125,7 @@ void cTextMsg::recalcRect() {
|
|||||||
style.pointSize = textSize;
|
style.pointSize = textSize;
|
||||||
style.underline = underlined;
|
style.underline = underlined;
|
||||||
style.lineHeight = textSize + 2;
|
style.lineHeight = textSize + 2;
|
||||||
std::string test = lbl;
|
std::string test = getText();
|
||||||
size_t lines = 1, cur_line_chars = 0, max_line_chars = 0;
|
size_t lines = 1, cur_line_chars = 0, max_line_chars = 0;
|
||||||
// Substitute | with newlines for measuring
|
// Substitute | with newlines for measuring
|
||||||
for(auto& c : test) {
|
for(auto& c : test) {
|
||||||
@@ -160,7 +160,7 @@ void cTextMsg::recalcRect() {
|
|||||||
temp.create(frame.width(), frame.height());
|
temp.create(frame.width(), frame.height());
|
||||||
rectangle test_rect = calc_rect;
|
rectangle test_rect = calc_rect;
|
||||||
test_rect.offset(-test_rect.left, -test_rect.top);
|
test_rect.offset(-test_rect.left, -test_rect.top);
|
||||||
rects = draw_string_hilite(temp, test_rect, lbl, style, hilites, sf::Color::Black);
|
rects = draw_string_hilite(temp, test_rect, getText(), style, hilites, sf::Color::Black);
|
||||||
if(rects.empty()) return;
|
if(rects.empty()) return;
|
||||||
// Basically take the the union of the rects, and add 8 to its height or width
|
// Basically take the the union of the rects, and add 8 to its height or width
|
||||||
rectangle combo = rects.back();
|
rectangle combo = rects.back();
|
||||||
|
|||||||
Reference in New Issue
Block a user