1 #include "IconTextBrowseWnd.h"
2 
3 #include <GG/StaticGraphic.h>
4 
5 #include "ClientUI.h"
6 #include "CUIControls.h"
7 
8 namespace {
9     const int       EDGE_PAD(3);
10 
11     /** Returns height of rows of text in InfoTextBrowseWnd. */
IconTextBrowseWndRowHeight()12     int IconTextBrowseWndRowHeight() {
13         return ClientUI::Pts()*3/2;
14     }
15 
16     const GG::X     ICON_BROWSE_TEXT_WIDTH(400);
17     const GG::X     ICON_BROWSE_ICON_WIDTH(64);
18     const GG::Y     ICON_BROWSE_ICON_HEIGHT(64);
19 }
20 
IconTextBrowseWnd(const std::shared_ptr<GG::Texture> texture,const std::string & title_text,const std::string & main_text)21 IconTextBrowseWnd::IconTextBrowseWnd(const std::shared_ptr<GG::Texture> texture,
22                                      const std::string& title_text,
23                                      const std::string& main_text) :
24     GG::BrowseInfoWnd(GG::X0, GG::Y0, ICON_BROWSE_TEXT_WIDTH + ICON_BROWSE_ICON_WIDTH, GG::Y1),
25     m_texture(texture),
26     m_title_text(title_text),
27     m_main_text(main_text)
28 { RequirePreRender(); }
29 
WndHasBrowseInfo(const Wnd * wnd,std::size_t mode) const30 bool IconTextBrowseWnd::WndHasBrowseInfo(const Wnd* wnd, std::size_t mode) const {
31     assert(mode <= wnd->BrowseModes().size());
32     return true;
33 }
34 
PreRender()35 void IconTextBrowseWnd::PreRender() {
36     GG::Wnd::PreRender();
37 
38     m_icon = GG::Wnd::Create<GG::StaticGraphic>(m_texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE, GG::INTERACTIVE);
39     m_icon->Resize(GG::Pt(ICON_BROWSE_ICON_WIDTH, ICON_BROWSE_ICON_HEIGHT));
40     AttachChild(m_icon);
41 
42     const GG::Y ROW_HEIGHT(IconTextBrowseWndRowHeight());
43 
44     m_title_text_label = GG::Wnd::Create<CUILabel>(m_title_text, GG::FORMAT_LEFT);
45     m_title_text_label->MoveTo(GG::Pt(m_icon->Width() + GG::X(EDGE_PAD), GG::Y0));
46     m_title_text_label->Resize(GG::Pt(ICON_BROWSE_TEXT_WIDTH, ROW_HEIGHT));
47     m_title_text_label->SetFont(ClientUI::GetBoldFont());
48 
49     m_main_text_label = GG::Wnd::Create<CUILabel>(m_main_text, GG::FORMAT_LEFT | GG::FORMAT_TOP | GG::FORMAT_WORDBREAK);
50     m_main_text_label->MoveTo(GG::Pt(m_icon->Width() + GG::X(EDGE_PAD), ROW_HEIGHT));
51     m_main_text_label->Resize(GG::Pt(ICON_BROWSE_TEXT_WIDTH, ICON_BROWSE_ICON_HEIGHT));
52     m_main_text_label->SetResetMinSize(true);
53     m_main_text_label->Resize(m_main_text_label->MinSize());
54 
55     AttachChild(m_title_text_label);
56     AttachChild(m_main_text_label);
57 
58     Resize(GG::Pt(ICON_BROWSE_TEXT_WIDTH + ICON_BROWSE_ICON_WIDTH,
59                   std::max(m_icon->Height(), ROW_HEIGHT + m_main_text_label->Height())));
60 }
61 
Render()62 void IconTextBrowseWnd::Render() {
63     GG::Pt      ul = UpperLeft();
64     GG::Pt      lr = LowerRight();
65     const GG::Y ROW_HEIGHT(IconTextBrowseWndRowHeight());
66     GG::FlatRectangle(ul, lr, ClientUI::WndColor(), ClientUI::WndOuterBorderColor(), 1);    // main background
67     GG::FlatRectangle(GG::Pt(ul.x + ICON_BROWSE_ICON_WIDTH, ul.y), GG::Pt(lr.x, ul.y + ROW_HEIGHT),
68                       ClientUI::WndOuterBorderColor(), ClientUI::WndOuterBorderColor(), 0);    // top title filled background
69 }
70