GG
TabWnd.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3  Copyright (C) 2006 T. Zachary Laine
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public License
7  as published by the Free Software Foundation; either version 2.1
8  of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free
17  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  02111-1307 USA
19 
20  If you do not wish to comply with the terms of the LGPL please
21  contact the author as other terms are available for a fee.
22 
23  Zach Laine
24  whatwasthataddress@gmail.com */
25 
29 #ifndef _GG_TabWnd_h_
30 #define _GG_TabWnd_h_
31 
32 #include <GG/Button.h>
33 
34 
35 namespace GG {
36 
37 class TabBar;
38 class WndEvent;
39 
42 class GG_API OverlayWnd : public Wnd
43 {
44 public:
46 
49  typedef boost::signal<void (std::size_t)> WndChangedSignalType;
51 
53 
54  OverlayWnd(X x, Y y, X w, Y h, Flags<WndFlag> flags = Flags<WndFlag>());
55  ~OverlayWnd();
57 
59  virtual Pt MinUsableSize() const;
60 
62  bool Empty() const;
63 
65  std::size_t NumWnds() const;
66 
68  Wnd* CurrentWnd() const;
69 
73  std::size_t CurrentWndIndex() const;
74 
76  const std::vector<Wnd*>& Wnds() const;
78 
80 
83  std::size_t AddWnd(Wnd* wnd);
84 
89  void InsertWnd(std::size_t index, Wnd* wnd);
90 
93  Wnd* RemoveWnd(std::size_t index);
94 
97  Wnd* RemoveWnd(Wnd* wnd);
98 
101  void SetCurrentWnd(std::size_t index);
103 
106  static const std::size_t NO_WND;
107 
108 protected:
110  OverlayWnd();
111 
112 
113 private:
114  std::vector<Wnd*> m_wnds;
115  std::size_t m_current_wnd_index;
116 };
117 
118 
121 class GG_API TabWnd : public Wnd
122 {
123 public:
125 
128  typedef boost::signal<void (std::size_t)> WndChangedSignalType;
130 
132 
133  TabWnd(X x, Y y, X w, Y h, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK,
136 
138  virtual Pt MinUsableSize() const;
139 
141  bool Empty() const;
142 
144  std::size_t NumWnds() const;
145 
147  Wnd* CurrentWnd() const;
148 
152  std::size_t CurrentWndIndex() const;
154 
156 
159  std::size_t AddWnd(Wnd* wnd, const std::string& name);
160 
165  void InsertWnd(std::size_t index, Wnd* wnd, const std::string& name);
166 
170  Wnd* RemoveWnd(const std::string& name);
171 
174  void SetCurrentWnd(std::size_t index);
176 
178 
181  static const std::size_t NO_WND;
182 
183 protected:
185  TabWnd();
186 
187 
189 
190  const TabBar* GetTabBar() const;
191 
193  const OverlayWnd* GetOverlayWnd() const;
194 
197  const std::map<std::string, Wnd*>& WndNames() const;
199 
200 private:
201  void TabChanged(std::size_t tab_index, bool signal);
202 
203  TabBar* m_tab_bar;
204  OverlayWnd* m_overlay;
205  std::map<std::string, Wnd*> m_named_wnds;
206 };
207 
208 
214 class GG_API TabBar : public Control
215 {
216 public:
218 
221  typedef boost::signal<void (std::size_t)> TabChangedSignalType;
223 
225 
226  TabBar(X x, Y y, X w, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK,
229 
231  virtual Pt MinUsableSize() const;
232 
234  bool Empty() const;
235 
237  std::size_t NumTabs() const;
238 
242  std::size_t CurrentTabIndex() const;
243 
245  Clr TextColor() const;
247 
249  virtual void SizeMove(const Pt& ul, const Pt& lr);
250  virtual void Render();
251 
255  std::size_t AddTab(const std::string& name);
256 
261  void InsertTab(std::size_t index, const std::string& name);
262 
265  void RemoveTab(const std::string& name);
266 
269  void SetCurrentTab(std::size_t index);
271 
273 
276  static const std::size_t NO_TAB;
277 
279  static const X BUTTON_WIDTH;
280 
281 protected:
283  TabBar();
284 
285 
287  const Button* LeftButton() const;
288  const Button* RightButton() const;
290 
292  virtual bool EventFilter(Wnd* w, const WndEvent& event);
293 
296  void RaiseCurrentTabButton();
298 
299 private:
300  virtual void DistinguishCurrentTab(const std::vector<StateButton*>& tab_buttons);
301 
302  void TabChanged(std::size_t index, bool signal);
303  void LeftClicked();
304  void RightClicked();
305  void BringTabIntoView(std::size_t index);
306 
307  RadioButtonGroup* m_tabs;
308  std::vector<StateButton*> m_tab_buttons;
309  boost::shared_ptr<Font> m_font;
310  Button* m_left_button;
311  Button* m_right_button;
312  Layout* m_left_right_button_layout;
313  Flags<TextFormat> m_format;
314  Clr m_text_color;
315  TabBarStyle m_style;
316  std::size_t m_first_tab_shown;
317 };
318 
319 } // namespace GG
320 
321 #endif