diff --git a/src/dialogxml/widgets/button.cpp b/src/dialogxml/widgets/button.cpp index 08e1dcea0..5dcb5df43 100644 --- a/src/dialogxml/widgets/button.cpp +++ b/src/dialogxml/widgets/button.cpp @@ -75,10 +75,10 @@ void cButton::draw(){ } else if(type == BTN_PUSH) { to_rect.top += 42; style.colour = textClr; - int w = string_length(lbl, style); + int w = string_length(getText(), style); 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)) { 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(!attrs.count("color") && !attrs.count("colour") && parent->getBg() == cDialog::BG_DARK) 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); } } diff --git a/src/dialogxml/widgets/control.cpp b/src/dialogxml/widgets/control.cpp index 40f78c9a9..8a67712cf 100644 --- a/src/dialogxml/widgets/control.cpp +++ b/src/dialogxml/widgets/control.cpp @@ -603,8 +603,8 @@ cControl::storage_t cControl::store() const { void cControl::restore(storage_t to) { if(to.find("text") != to.end()) - lbl = boost::any_cast(to["text"]); - else lbl = ""; + setText(boost::any_cast(to["text"])); + else setText(""); if(to.find("visible") != to.end()) boost::any_cast(to["visible"]) ? show() : hide(); } diff --git a/src/dialogxml/widgets/control.hpp b/src/dialogxml/widgets/control.hpp index e1f4adb90..dd988aae7 100644 --- a/src/dialogxml/widgets/control.hpp +++ b/src/dialogxml/widgets/control.hpp @@ -435,8 +435,6 @@ protected: /// The parent window of the control. /// This is for use in implementing draw(). sf::RenderWindow* inWindow; - /// The control's current text. - std::string lbl; /// Whether the control is visible bool visible, depressed = false; ///< Whether the control is depressed; only applicable for clickable controls /// The control's bounding rect. @@ -457,6 +455,8 @@ protected: void playClickSound(); private: friend class cDialog; // TODO: This is only so it can access parseColour... hack! + /// The control's current text. + std::string lbl; eControlType type; std::map event_handlers; // Transient values only used during parsing diff --git a/src/dialogxml/widgets/led.cpp b/src/dialogxml/widgets/led.cpp index 6c1210f0f..87513e7c9 100644 --- a/src/dialogxml/widgets/led.cpp +++ b/src/dialogxml/widgets/led.cpp @@ -104,7 +104,7 @@ void cLed::draw(){ style.colour = textClr; to_rect.right = frame.right; 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(); diff --git a/src/dialogxml/widgets/message.cpp b/src/dialogxml/widgets/message.cpp index 3d692b6dc..ec96ec995 100644 --- a/src/dialogxml/widgets/message.cpp +++ b/src/dialogxml/widgets/message.cpp @@ -97,7 +97,7 @@ void cTextMsg::setFixed(bool w, bool h) { void cTextMsg::calculate_layout() { to_rect = frame; - msg = lbl; + msg = getText(); for(const auto& key : keyRefs) { size_t pos = msg.find_first_of(KEY_PLACEHOLDER); if(pos == std::string::npos) break; @@ -125,7 +125,7 @@ void cTextMsg::recalcRect() { style.pointSize = textSize; style.underline = underlined; style.lineHeight = textSize + 2; - std::string test = lbl; + std::string test = getText(); size_t lines = 1, cur_line_chars = 0, max_line_chars = 0; // Substitute | with newlines for measuring for(auto& c : test) { @@ -160,7 +160,7 @@ void cTextMsg::recalcRect() { temp.create(frame.width(), frame.height()); rectangle test_rect = calc_rect; 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; // Basically take the the union of the rects, and add 8 to its height or width rectangle combo = rects.back();