GG
Scroll.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3  Copyright (C) 2003-2008 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 
28 #ifndef _GG_Scroll_h_
29 #define _GG_Scroll_h_
30 
31 #include <GG/Control.h>
32 
33 
34 namespace GG {
35 
36 class Button;
37 
54 class GG_API Scroll : public Control
55 {
56 public:
58  enum ScrollRegion {
59  SBR_NONE,
60  SBR_PAGE_DN,
61  SBR_PAGE_UP
62  };
63 
65  typedef boost::signal<void (int, int, int, int)> ScrolledSignalType;
66  typedef boost::signal<void (int, int, int, int)> ScrolledAndStoppedSignalType;
67 
68 
70 
71  Scroll(X x, Y y, X w, Y h, Orientation orientation, Clr color, Clr interior,
74 
76  virtual Pt MinUsableSize() const;
77 
78  std::pair<int, int> PosnRange() const;
79  std::pair<int, int> ScrollRange() const;
80  unsigned int LineSize() const;
81  unsigned int PageSize() const;
82 
83  Clr InteriorColor() const;
84  Orientation ScrollOrientation() const;
85 
88 
89 
91  virtual void Render();
92 
93  virtual void SizeMove(const Pt& ul, const Pt& lr);
94 
95  virtual void Disable(bool b = true);
96  virtual void SetColor(Clr c);
97 
98  void SetInteriorColor(Clr c);
99  void SizeScroll(int min, int max, unsigned int line, unsigned int page);
100  void SetMax(int max);
101  void SetMin(int min);
102  void SetLineSize(unsigned int line);
103  void SetPageSize(unsigned int page);
104 
105  void ScrollTo(int p);
106  void ScrollLineIncr();
107  void ScrollLineDecr();
108  void ScrollPageIncr();
109  void ScrollPageDecr();
110 
111 
112 protected:
114  Scroll();
115 
116 
118  unsigned int TabSpace() const;
119  unsigned int TabWidth() const;
120  ScrollRegion RegionUnder(const Pt& pt);
121 
122  Button* TabButton() const;
123  Button* IncrButton() const;
124  Button* DecrButton() const;
125 
126 
128  virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
129  virtual void LButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
130  virtual void LClick(const Pt& pt, Flags<ModKey> mod_keys);
131  virtual void MouseHere(const Pt& pt, Flags<ModKey> mod_keys);
132 
133  virtual bool EventFilter(Wnd* w, const WndEvent& event);
135 
136 private:
137  void UpdatePosn();
138  void MoveTabToPosn();
139  void ScrollLineIncrImpl(bool signal);
140  void ScrollLineDecrImpl(bool signal);
141 
142  Clr m_int_color;
143  const Orientation m_orientation;
144  int m_posn;
145  int m_range_min;
146  int m_range_max;
147  unsigned int m_line_sz;
148  unsigned int m_page_sz;
149  Button* m_tab;
150  Button* m_incr;
151  Button* m_decr;
152  ScrollRegion m_initial_depressed_region;
153  ScrollRegion m_depressed_region;
154  bool m_dragging_tab;
155  bool m_tab_dragged;
156 };
157 
158 // define EnumMap and stream operators for Scroll::ScrollRegion
160  GG_ENUM_MAP_INSERT(Scroll::SBR_NONE)
161  GG_ENUM_MAP_INSERT(Scroll::SBR_PAGE_DN)
162  GG_ENUM_MAP_INSERT(Scroll::SBR_PAGE_UP)
164 
165 GG_ENUM_STREAM_IN(Scroll::ScrollRegion)
166 GG_ENUM_STREAM_OUT(Scroll::ScrollRegion)
167 
171 GG_API void SignalScroll(const Scroll& scroll, bool stopped);
172 
173 } // namespace GG
174 
175 #endif