From 75283bf0fd00aa9a2b0e9978e6dcc3d5ba23c353 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Sat, 4 Aug 2012 17:51:02 +0000 Subject: [PATCH] Fixed TextBox line breaking & slider. --- client/UIFramework/CIntObjectClasses.cpp | 22 +++++++++++++++------- client/UIFramework/CIntObjectClasses.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/client/UIFramework/CIntObjectClasses.cpp b/client/UIFramework/CIntObjectClasses.cpp index 25948a4b4..a25718e6e 100644 --- a/client/UIFramework/CIntObjectClasses.cpp +++ b/client/UIFramework/CIntObjectClasses.cpp @@ -1306,11 +1306,6 @@ void CBoundedLabel::recalculateLines(const std::string &Txt) int lineCapacity = pos.h / lineHeight; lines = CMessage::breakText(Txt, pos.w, font); - if(lines.size() > lineCapacity) //we need to add a slider - { - lines = CMessage::breakText(Txt, pos.w - 32 - 10, font); - OBJ_CONSTRUCTION_CAPTURING_ALL; - } maxH = lineHeight * lines.size(); maxW = 0; @@ -1342,15 +1337,28 @@ CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts F void CTextBox::recalculateLines(const std::string &Txt) { - CBoundedLabel::recalculateLines (Txt); + //TODO: merge with CBoundedlabel::recalculateLines + vstd::clear_pointer(slider); + lines.clear(); const Font &f = *graphics->fonts[font]; int lineHeight = f.height; int lineCapacity = pos.h / lineHeight; - vstd::clear_pointer(slider); + lines = CMessage::breakText(Txt, pos.w, font); if (lines.size() > lineCapacity) //we need to add a slider + { + lines = CMessage::breakText(Txt, pos.w - 32 - 10, font); + OBJ_CONSTRUCTION_CAPTURING_ALL; slider = new CSlider(pos.w - 32, 0, pos.h, boost::bind(&CTextBox::sliderMoved, this, _1), lineCapacity, lines.size(), 0, false, sliderStyle); + if(active) + slider->activate(); + } + + maxH = lineHeight * lines.size(); + maxW = 0; + BOOST_FOREACH(const std::string &line, lines) + vstd::amax(maxW, f.getWidth(line.c_str())); } void CTextBox::showAll(SDL_Surface * to) diff --git a/client/UIFramework/CIntObjectClasses.h b/client/UIFramework/CIntObjectClasses.h index 85ce9eee1..73362385f 100644 --- a/client/UIFramework/CIntObjectClasses.h +++ b/client/UIFramework/CIntObjectClasses.h @@ -363,7 +363,7 @@ public: : CLabel (x, y, Font, Align, Color, Text){}; void setTxt(const std::string &Txt); void setBounds(int limitW, int limitH); - void recalculateLines(const std::string &Txt); + virtual void recalculateLines(const std::string &Txt); void showAll(SDL_Surface * to); };