1 #include "TextBrowseWnd.h"
2 
3 #include "CUIControls.h"
4 
5 namespace {
6     /** Returns height of rows of text in InfoTextBrowseWnd. */
IconTextBrowseWndRowHeight()7     int IconTextBrowseWndRowHeight() {
8         return ClientUI::Pts()*3/2;
9     }
10 
11     const int       EDGE_PAD(3);
12 
13     const GG::Y     ICON_BROWSE_ICON_HEIGHT(64);
14 }
15 
TextBrowseWnd(const std::string & title_text,const std::string & main_text,GG::X w)16 TextBrowseWnd::TextBrowseWnd(const std::string& title_text, const std::string& main_text, GG::X w /* = GG::X(200) */) :
17     GG::BrowseInfoWnd(GG::X0, GG::Y0, w, GG::Y1)
18 {
19     const GG::Y ROW_HEIGHT(IconTextBrowseWndRowHeight());
20 
21     m_offset = GG::Pt(GG::X0, ICON_BROWSE_ICON_HEIGHT/2); //lower the window
22 
23     m_title_text = GG::Wnd::Create<CUILabel>(title_text, GG::FORMAT_LEFT);
24     m_title_text->MoveTo(GG::Pt(GG::X(EDGE_PAD) + m_offset.x, GG::Y0 + m_offset.y));
25     m_title_text->Resize(GG::Pt(w, ROW_HEIGHT));
26     m_title_text->SetFont(ClientUI::GetBoldFont());
27 
28     m_main_text = GG::Wnd::Create<CUILabel>(main_text, GG::FORMAT_LEFT | GG::FORMAT_TOP | GG::FORMAT_WORDBREAK);
29     m_main_text->MoveTo(GG::Pt(GG::X(EDGE_PAD) + m_offset.x, ROW_HEIGHT + m_offset.y));
30     m_main_text->Resize(GG::Pt(w, ICON_BROWSE_ICON_HEIGHT));
31     m_main_text->SetResetMinSize(true);
32     m_main_text->Resize(m_main_text->MinSize());
33 }
34 
CompleteConstruction()35 void TextBrowseWnd::CompleteConstruction() {
36     GG::BrowseInfoWnd::CompleteConstruction();
37 
38     AttachChild(m_main_text);
39     AttachChild(m_title_text);
40 
41     Resize(GG::Pt(Width(), IconTextBrowseWndRowHeight() + m_main_text->Height()));
42 }
43 
WndHasBrowseInfo(const Wnd * wnd,std::size_t mode) const44 bool TextBrowseWnd::WndHasBrowseInfo(const Wnd* wnd, std::size_t mode) const {
45     assert(mode <= wnd->BrowseModes().size());
46     return true;
47 }
48 
Render()49 void TextBrowseWnd::Render() {
50     GG::Pt      ul = UpperLeft();
51     GG::Pt      lr = LowerRight();
52     const GG::Y ROW_HEIGHT(IconTextBrowseWndRowHeight());
53     GG::FlatRectangle(ul + m_offset, lr + m_offset, ClientUI::WndColor(), ClientUI::WndOuterBorderColor(), 1);    // main background
54     GG::FlatRectangle(ul + m_offset, GG::Pt(lr.x, ul.y + ROW_HEIGHT) + m_offset, ClientUI::WndOuterBorderColor(), ClientUI::WndOuterBorderColor(), 0);    // top title filled background
55 }
56