comparison ext/guichan-0.8.2/include/guichan/contrib/widgets/adjustingcontainer.hpp @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
1 /* _______ __ __ __ ______ __ __ _______ __ __
2 * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
3 * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4 * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
5 * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
6 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8 *
9 * Copyright (c) 2007 - 2008 Josh Matthews and Olof Naessén
10 *
11 *
12 * Per Larsson a.k.a finalman
13 * Olof Naessén a.k.a jansem/yakslem
14 *
15 * Visit: http://guichan.sourceforge.net
16 *
17 * License: (BSD)
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
26 * distribution.
27 * 3. Neither the name of Guichan nor the names of its contributors may
28 * be used to endorse or promote products derived from this software
29 * without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
37 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 #ifndef GCN_CONTRIB_ADJUSTINGCONTAINER_HPP
45 #define GCN_CONTRIB_ADJUSTINGCONTAINER_HPP
46
47 #include "guichan/widgets/container.hpp"
48
49 #include <vector>
50
51 namespace gcn
52 {
53 namespace contrib
54 {
55 /**
56 * Self-adjusting Container class. AdjustingContainers are an easy way to
57 * have Guichan position a group of widgets for you. It organizes elements
58 * in a table layout, with fixed columns and variable rows. The user specifies
59 *
60 * @verbitam
61 * <ul>
62 * <li>the number of columns</li>
63 * <li>horizontal spacing between columns</li>
64 * <li>vertical spacing between rows</li>
65 * <li>padding around the sides of the container</li>
66 * <li>each column's alignment</li>
67 * </ul>
68 * @endverbitam
69 *
70 * These properties give the user a lot of flexibility to make the
71 * widgets look just right.
72 * @code
73 * AdjustingContainer *adjust = new AdjustingContainer;
74 * adjust->setPadding(5, 5, 5, 5); //left, right, top, bottom
75 * adjust->setHorizontalSpacing(3);
76 * adjust->setVerticalSpacing(3);
77 * adjust->setColumns(3);
78 * adjust->setColumnAlignment(0, AdjustingContainer::LEFT);
79 * adjust->setColumnAlignment(1, AdjustingContainer::CENTER);
80 * adjust->setColumnAlignment(2, AdjustingContainer::RIGHT);
81 * top->add(adjust);
82 *
83 * for(int j = 0; j < 9; j++)
84 * {
85 * gcn::Label *l;
86 * int r = rand() % 3;
87 * if(r == 0)
88 * l = new gcn::Label("Short");
89 * else if(r == 1)
90 * l = new gcn::Label("A longer phrase");
91 * else
92 * l = new gcn::Label("Extravagent and wordy text");
93 * adjust->add(l);
94 * @endcode
95 *
96 * Output:
97 * @verbitam
98 * <pre>
99 *+---------------------------------------------------------------------------+
100 *| |
101 *| A longer phrase Short Extravagent and wordy text |
102 *| |
103 *| Short Extravagent and wordy text Short |
104 *| |
105 *| Short A longer phrase A longer phrase |
106 *| |
107 *+---------------------------------------------------------------------------+
108 * </pre>
109 * @endverbitam
110 * As you can see, each column is only as big as its largest element.
111 * The AdjustingContainer will resize itself and rearrange its contents
112 * based on whatever widgets it contains, allowing dynamic addition and
113 * removal while the program is running. It also plays nicely with ScrollAreas,
114 * allowing you to show a fixed, maximum size while not limiting the actual
115 * container.
116 *
117 * For more help with using AdjustingContainers, try the Guichan forums
118 * (http://guichan.sourceforge.net/forum/) or email mrlachatte@gmail.com.
119 *
120 * @author Josh Matthews
121 */
122 class AdjustingContainer : public gcn::Container
123 {
124 public:
125 /**
126 * Constructor.
127 */
128 AdjustingContainer();
129
130 /**
131 * Destructor.
132 */
133 virtual ~AdjustingContainer();
134
135 /**
136 * Set the number of columns to divide the widgets into.
137 * The number of rows is derived automatically from the number
138 * of widgets based on the number of columns. Default column
139 * alignment is left.
140 *
141 * @param numberOfColumns the number of columns.
142 */
143 virtual void setNumberOfColumns(unsigned int numberOfColumns);
144
145 /**
146 * Set a specific column's alignment.
147 *
148 * @param column the column number, starting from 0.
149 * @param alignment the column's alignment. See enum with alignments.
150 */
151 virtual void setColumnAlignment(unsigned int column, unsigned int alignment);
152
153 /**
154 * Set the padding for the sides of the container.
155 *
156 * @param paddingLeft left padding.
157 * @param paddingRight right padding.
158 * @param paddingTop top padding.
159 * @param paddingBottom bottom padding.
160 */
161 virtual void setPadding(unsigned int paddingLeft,
162 unsigned int paddingRight,
163 unsigned int paddingTop,
164 unsigned int paddingBottom);
165
166 /**
167 * Set the spacing between rows.
168 *
169 * @param verticalSpacing spacing in pixels.
170 */
171 virtual void setVerticalSpacing(unsigned int verticalSpacing);
172
173 /**
174 * Set the horizontal spacing between columns.
175 *
176 * @param horizontalSpacing spacing in pixels.
177 */
178 virtual void setHorizontalSpacing(unsigned int horizontalSpacing);
179
180 /**
181 * Rearrange the widgets and resize the container.
182 */
183 virtual void adjustContent();
184
185
186 // Inherited from Container
187
188 virtual void logic();
189
190 virtual void add(Widget *widget);
191
192 virtual void add(Widget *widget, int x, int y);
193
194 virtual void remove(Widget *widget);
195
196 virtual void clear();
197
198 /**
199 * Possible alignment values for each column.
200 *
201 * LEFT - Align content to the left of the column.
202 * MIDDLE - Align content to the middle of the column.
203 * RIGHT - Align content to the right of the column.
204 */
205 enum
206 {
207 LEFT = 0,
208 CENTER,
209 RIGHT
210 };
211
212 protected:
213
214 /**
215 * Adjust the size of the container to fit all the widgets.
216 */
217 virtual void adjustSize();
218
219 std::vector<Widget*> mContainedWidgets;
220 std::vector<unsigned int> mColumnWidths;
221 std::vector<unsigned int> mColumnAlignment;
222 std::vector<unsigned int> mRowHeights;
223 unsigned int mWidth;
224 unsigned int mHeight;
225 unsigned int mNumberOfColumns;
226 unsigned int mNumberOfRows;
227 unsigned int mPaddingLeft;
228 unsigned int mPaddingRight;
229 unsigned int mPaddingTop;
230 unsigned int mPaddingBottom;
231 unsigned int mVerticalSpacing;
232 unsigned int mHorizontalSpacing;
233 };
234 }
235 }
236
237 #endif