1 #include "CUIStyle.h"
2 
3 #include "CUIControls.h"
4 #include "CUISlider.h"
5 #include "../util/i18n.h"
6 
7 
Translate(const std::string & text) const8 std::string CUIStyle::Translate(const std::string& text) const
9 {
10     if (text == "New")
11         return UserString("COLOR_DLG_NEW");
12     else if (text == "Old")
13         return UserString("COLOR_DLG_OLD");
14     else if (text == "R:")
15         return UserString("COLOR_DLG_RED");
16     else if (text == "G:")
17         return UserString("COLOR_DLG_GREEN");
18     else if (text == "B:")
19         return UserString("COLOR_DLG_BLUE");
20     else if (text == "H:")
21         return UserString("COLOR_DLG_HUE");
22     else if (text == "S:")
23         return UserString("COLOR_DLG_SATURATION");
24     else if (text == "V:")
25         return UserString("COLOR_DLG_VALUE");
26     else if (text == "A:")
27         return UserString("COLOR_DLG_ALPHA");
28     else if (text == "Ok")
29         return UserString("OK");
30     else if (text == "Cancel")
31         return UserString("CANCEL");
32     else if (text == "File(s):")
33         return UserString("FILE_DLG_FILES");
34     else if (text == "Type(s):")
35         return UserString("FILE_DLG_FILE_TYPES");
36     else if (text == "%1% exists.\nOk to overwrite it?")
37         return UserString("FILE_DLG_OVERWRITE_PROMPT");
38     else if (text == "\"%1%\"\nis a directory.")
39         return UserString("FILE_DLG_FILENAME_IS_A_DIRECTORY");
40     else if (text == "File \"%1%\"\ndoes not exist.")
41         return UserString("FILE_DLG_FILE_DOES_NOT_EXIST");
42     else if (text == "Device is not ready.")
43         return UserString("FILE_DLG_DEVICE_IS_NOT_READY");
44     else if (text == "Save")
45         return UserString("SAVE");
46     else if (text == "Open")
47         return UserString("OPEN");
48 
49     return UserString("ERROR");
50 }
51 
NewButton(const std::string & str,const std::shared_ptr<GG::Font> & font,GG::Clr color,GG::Clr text_color,GG::Flags<GG::WndFlag> flags) const52 std::shared_ptr<GG::Button> CUIStyle::NewButton(const std::string& str, const std::shared_ptr<GG::Font>& font,
53                                                 GG::Clr color, GG::Clr text_color/* = CLR_BLACK*/,
54                                                 GG::Flags<GG::WndFlag> flags/* = INTERACTIVE*/) const
55 { return GG::Wnd::Create<CUIButton>(str); }
56 
57 
NewDropDownList(size_t num_shown_elements,GG::Clr color) const58 std::shared_ptr<GG::DropDownList> CUIStyle::NewDropDownList(size_t num_shown_elements, GG::Clr color) const
59 { return GG::Wnd::Create<CUIDropDownList>(num_shown_elements); }
60 
NewEdit(const std::string & str,const std::shared_ptr<GG::Font> & font,GG::Clr color,GG::Clr text_color,GG::Clr interior) const61 std::shared_ptr<GG::Edit> CUIStyle::NewEdit(const std::string& str, const std::shared_ptr<GG::Font>& font,
62                                             GG::Clr color, GG::Clr text_color/* = GG::CLR_BLACK*/,
63                                             GG::Clr interior/* = GG::CLR_ZERO*/) const
64 { return GG::Wnd::Create<CUIEdit>(str); }
65 
NewListBox(GG::Clr color,GG::Clr interior) const66 std::shared_ptr<GG::ListBox> CUIStyle::NewListBox(GG::Clr color, GG::Clr interior/* = GG::CLR_ZERO*/) const
67 { return GG::Wnd::Create<CUIListBox>(); }
68 
NewScroll(GG::Orientation orientation,GG::Clr color,GG::Clr interior) const69 std::shared_ptr<GG::Scroll> CUIStyle::NewScroll(GG::Orientation orientation, GG::Clr color, GG::Clr interior) const
70 { return GG::Wnd::Create<CUIScroll>(orientation); }
71 
NewIntSlider(int min,int max,GG::Orientation orientation,GG::Clr color,int tab_width,int line_width) const72 std::shared_ptr<GG::Slider<int>> CUIStyle::NewIntSlider(int min, int max, GG::Orientation orientation,
73                                                         GG::Clr color, int tab_width, int line_width/* = 5*/) const
74 { return GG::Wnd::Create<CUISlider<int>>(min, max, orientation); }
75 
76 
NewTabBar(const std::shared_ptr<GG::Font> & font,GG::Clr color,GG::Clr text_color) const77 std::shared_ptr<GG::TabBar> CUIStyle::NewTabBar(const std::shared_ptr<GG::Font>& font, GG::Clr color,
78                                                 GG::Clr text_color/* = GG::CLR_BLACK*/) const
79 { return GG::Wnd::Create<CUITabBar>(font, color, text_color); }
80 
NewScrollUpButton(GG::Clr color) const81 std::shared_ptr<GG::Button> CUIStyle::NewScrollUpButton(GG::Clr color) const
82 { return nullptr; }
83 
NewScrollDownButton(GG::Clr color) const84 std::shared_ptr<GG::Button> CUIStyle::NewScrollDownButton(GG::Clr color) const
85 { return NewScrollUpButton(color); }
86 
NewVScrollTabButton(GG::Clr color) const87 std::shared_ptr<GG::Button> CUIStyle::NewVScrollTabButton(GG::Clr color) const
88 {
89     return GG::Wnd::Create<CUIScroll::ScrollTab>(GG::VERTICAL, 1,
90                                                  (color == GG::CLR_ZERO) ? ClientUI::CtrlColor() : color,
91                                                  ClientUI::CtrlBorderColor());
92 }
93 
NewScrollLeftButton(GG::Clr color) const94 std::shared_ptr<GG::Button> CUIStyle::NewScrollLeftButton(GG::Clr color) const
95 { return NewScrollUpButton(color); }
96 
NewScrollRightButton(GG::Clr color) const97 std::shared_ptr<GG::Button> CUIStyle::NewScrollRightButton(GG::Clr color) const
98 { return NewScrollUpButton(color); }
99 
NewHScrollTabButton(GG::Clr color) const100 std::shared_ptr<GG::Button> CUIStyle::NewHScrollTabButton(GG::Clr color) const
101 {
102     return GG::Wnd::Create<CUIScroll::ScrollTab>(GG::HORIZONTAL, 1,
103                                                  (color == GG::CLR_ZERO) ? ClientUI::CtrlColor() : color,
104                                                  ClientUI::CtrlBorderColor());
105 }
106 
NewVSliderTabButton(GG::Clr color) const107 std::shared_ptr<GG::Button> CUIStyle::NewVSliderTabButton(GG::Clr color) const
108 { return GG::Wnd::Create<CUIScroll::ScrollTab>(GG::VERTICAL, 0, ClientUI::CtrlColor(), ClientUI::CtrlBorderColor()); }
109 
NewHSliderTabButton(GG::Clr color) const110 std::shared_ptr<GG::Button> CUIStyle::NewHSliderTabButton(GG::Clr color) const
111 { return GG::Wnd::Create<CUIScroll::ScrollTab>(GG::HORIZONTAL, 0, ClientUI::CtrlColor(), ClientUI::CtrlBorderColor()); }
112 
NewSpinIncrButton(const std::shared_ptr<GG::Font> & font,GG::Clr color) const113 std::shared_ptr<GG::Button> CUIStyle::NewSpinIncrButton(
114     const std::shared_ptr<GG::Font>& font, GG::Clr color) const
115 { return GG::Wnd::Create<CUIArrowButton>(ShapeOrientation::UP, false, GG::INTERACTIVE | GG::REPEAT_BUTTON_DOWN); }
116 
NewSpinDecrButton(const std::shared_ptr<GG::Font> & font,GG::Clr color) const117 std::shared_ptr<GG::Button> CUIStyle::NewSpinDecrButton(
118     const std::shared_ptr<GG::Font>& font, GG::Clr color) const
119 { return GG::Wnd::Create<CUIArrowButton>(ShapeOrientation::DOWN, false, GG::INTERACTIVE | GG::REPEAT_BUTTON_DOWN); }
120 
NewTabBarTab(const std::string & str,const std::shared_ptr<GG::Font> & font,GG::Flags<GG::TextFormat> format,GG::Clr color,GG::Clr text_color) const121 std::shared_ptr<GG::StateButton> CUIStyle::NewTabBarTab(
122     const std::string& str, const std::shared_ptr<GG::Font>& font,
123     GG::Flags<GG::TextFormat> format, GG::Clr color,
124     GG::Clr text_color/* = GG::CLR_BLACK*/) const
125 {
126     auto retval = GG::Wnd::Create<CUIStateButton>(str, format, std::make_shared<CUITabRepresenter>());
127     retval->SetColor(ClientUI::WndColor());
128     retval->GetLabel()->SetTextColor(DarkenClr(ClientUI::TextColor()));
129     retval->Resize(retval->MinUsableSize() + GG::Pt(GG::X(12), GG::Y0));
130     return retval;
131 }
132 
NewTabBarLeftButton(const std::shared_ptr<GG::Font> & font,GG::Clr color,GG::Clr text_color) const133 std::shared_ptr<GG::Button> CUIStyle::NewTabBarLeftButton(
134     const std::shared_ptr<GG::Font>& font,
135     GG::Clr color, GG::Clr text_color/* = GG::CLR_BLACK*/) const
136 { return GG::Wnd::Create<CUIArrowButton>(ShapeOrientation::LEFT, true, GG::INTERACTIVE); }
137 
NewTabBarRightButton(const std::shared_ptr<GG::Font> & font,GG::Clr color,GG::Clr text_color) const138 std::shared_ptr<GG::Button> CUIStyle::NewTabBarRightButton(
139     const std::shared_ptr<GG::Font>& font,
140     GG::Clr color, GG::Clr text_color/* = GG::CLR_BLACK*/) const
141 { return GG::Wnd::Create<CUIArrowButton>(ShapeOrientation::RIGHT, true, GG::INTERACTIVE); }
142