Mercurial > fife-parpg
comparison ext/guichan-0.8.1/include/guichan/widgets/scrollarea.hpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /* _______ __ __ __ ______ __ __ _______ __ __ | |
2 * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ | |
3 * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / | |
4 * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / | |
5 * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / | |
6 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / | |
7 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ | |
8 * | |
9 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson | |
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_SCROLLAREA_HPP | |
45 #define GCN_SCROLLAREA_HPP | |
46 | |
47 #include <string> | |
48 | |
49 #include "guichan/basiccontainer.hpp" | |
50 #include "guichan/mouselistener.hpp" | |
51 #include "guichan/platform.hpp" | |
52 | |
53 namespace gcn | |
54 { | |
55 /** | |
56 * Implementation if a scrollable area used to view widgets larger than the scroll area. | |
57 * A scroll area can be customized to always show scroll bars or to show them only when | |
58 * necessary. | |
59 */ | |
60 class GCN_CORE_DECLSPEC ScrollArea: | |
61 public BasicContainer, | |
62 public MouseListener | |
63 { | |
64 public: | |
65 | |
66 /** | |
67 * Scrollpolicies for the horizontal and vertical scrollbar. | |
68 * The policies are: | |
69 * | |
70 * SHOW_ALWAYS - Always show the scrollbars no matter what. | |
71 * SHOW_NEVER - Never show the scrollbars no matter waht. | |
72 * SHOW_AUTO - Show the scrollbars only when needed. That is if the | |
73 * content grows larger then the ScrollArea. | |
74 */ | |
75 enum ScrollPolicy | |
76 { | |
77 SHOW_ALWAYS = 0, | |
78 SHOW_NEVER, | |
79 SHOW_AUTO | |
80 }; | |
81 | |
82 /** | |
83 * Constructor. | |
84 */ | |
85 ScrollArea(); | |
86 | |
87 /** | |
88 * Constructor. | |
89 * | |
90 * @param content The content of the scroll area. | |
91 */ | |
92 ScrollArea(Widget *content); | |
93 | |
94 /** | |
95 * Constructor. | |
96 * | |
97 * @param content The content of the scroll area. | |
98 * @param hPolicy The policy for the horizontal scrollbar. See enum with | |
99 * policies. | |
100 * @param vPolicy The policy for the vertical scrollbar. See enum with | |
101 * policies. | |
102 */ | |
103 ScrollArea(Widget *content, | |
104 ScrollPolicy hPolicy, | |
105 ScrollPolicy vPolicy); | |
106 | |
107 /** | |
108 * Destructor. | |
109 */ | |
110 virtual ~ScrollArea(); | |
111 | |
112 /** | |
113 * Sets the content. | |
114 * | |
115 * @param widget The content of the scroll area. | |
116 */ | |
117 void setContent(Widget* widget); | |
118 | |
119 /** | |
120 * Gets the content. | |
121 * | |
122 * @return The content of the scroll area. | |
123 */ | |
124 Widget* getContent(); | |
125 | |
126 /** | |
127 * Sets the horizontal scrollbar policy. See enum with policies. | |
128 * | |
129 * @param hPolicy The policy for the horizontal scrollbar. | |
130 * @see getHorizontalScrollPolicy | |
131 */ | |
132 void setHorizontalScrollPolicy(ScrollPolicy hPolicy); | |
133 | |
134 /** | |
135 * Gets the horizontal scrollbar policy. See enum with policies. | |
136 * | |
137 * @return The policy for the horizontal scrollbar policy. | |
138 * @see setHorizontalScrollPolicy, setScrollPolicy | |
139 */ | |
140 ScrollPolicy getHorizontalScrollPolicy() const; | |
141 | |
142 /** | |
143 * Sets the vertical scrollbar policy. See enum with policies. | |
144 * | |
145 * @param vPolicy The policy for the vertical scrollbar. | |
146 * @see getVerticalScrollPolicy | |
147 */ | |
148 void setVerticalScrollPolicy(ScrollPolicy vPolicy); | |
149 | |
150 /** | |
151 * Gets the vertical scrollbar policy. See enum with policies. | |
152 * | |
153 * @return The policy for the vertical scrollbar. | |
154 * @see setVerticalScrollPolicy, setScrollPolicy | |
155 */ | |
156 ScrollPolicy getVerticalScrollPolicy() const; | |
157 | |
158 /** | |
159 * Sets the horizontal and vertical scrollbar policy. | |
160 * | |
161 * @param hPolicy The policy for the horizontal scrollbar. | |
162 * @param vPolicy The policy for the vertical scrollbar. | |
163 * @see getVerticalScrollPolicy, getHorizontalScrollPolicy | |
164 */ | |
165 void setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy); | |
166 | |
167 /** | |
168 * Sets the amount to scroll vertically. | |
169 * | |
170 * @param vScroll The amount to scroll. | |
171 * @see getVerticalScrollAmount | |
172 */ | |
173 void setVerticalScrollAmount(int vScroll); | |
174 | |
175 /** | |
176 * Gets the amount that is scrolled vertically. | |
177 * | |
178 * @return The scroll amount on vertical scroll. | |
179 * @see setVerticalScrollAmount, setScrollAmount | |
180 */ | |
181 int getVerticalScrollAmount() const; | |
182 | |
183 /** | |
184 * Sets the amount to scroll horizontally. | |
185 * | |
186 * @param hScroll The amount to scroll. | |
187 * @see getHorizontalScrollAmount | |
188 */ | |
189 void setHorizontalScrollAmount(int hScroll); | |
190 | |
191 /** | |
192 * Gets the amount that is scrolled horizontally. | |
193 * | |
194 * @return The scroll amount on horizontal scroll. | |
195 * @see setHorizontalScrollAmount, setScrollAmount | |
196 */ | |
197 int getHorizontalScrollAmount() const; | |
198 | |
199 /** | |
200 * Sets the amount to scroll horizontally and vertically. | |
201 * | |
202 * @param hScroll The amount to scroll on horizontal scroll. | |
203 * @param vScroll The amount to scroll on vertical scroll. | |
204 * @see getHorizontalScrollAmount, getVerticalScrollAmount | |
205 */ | |
206 void setScrollAmount(int hScroll, int vScroll); | |
207 | |
208 /** | |
209 * Gets the maximum amount of horizontal scroll. | |
210 * | |
211 * @return The horizontal max scroll. | |
212 */ | |
213 int getHorizontalMaxScroll(); | |
214 | |
215 /** | |
216 * Gets the maximum amount of vertical scroll. | |
217 * | |
218 * @return The vertical max scroll. | |
219 */ | |
220 int getVerticalMaxScroll(); | |
221 | |
222 /** | |
223 * Sets the width of the scroll bars. | |
224 * | |
225 * @param width The width of the scroll bars. | |
226 * @see getScrollbarWidth | |
227 */ | |
228 void setScrollbarWidth(int width); | |
229 | |
230 /** | |
231 * Gets the width of the scroll bars. | |
232 * | |
233 * @return the width of the ScrollBar. | |
234 * @see setScrollbarWidth | |
235 */ | |
236 int getScrollbarWidth() const; | |
237 | |
238 /** | |
239 * Sets the amount to scroll in pixels when the left scroll button is | |
240 * pushed. | |
241 * | |
242 * @param amount The amount to scroll in pixels. | |
243 * @see getLeftButtonScrollAmount | |
244 */ | |
245 void setLeftButtonScrollAmount(int amount); | |
246 | |
247 /** | |
248 * Sets the amount to scroll in pixels when the right scroll button is | |
249 * pushed. | |
250 * | |
251 * @param amount The amount to scroll in pixels. | |
252 * @see getRightButtonScrollAmount | |
253 */ | |
254 void setRightButtonScrollAmount(int amount); | |
255 | |
256 /** | |
257 * Sets the amount to scroll in pixels when the up scroll button is | |
258 * pushed. | |
259 * | |
260 * @param amount The amount to scroll in pixels. | |
261 * @see getUpButtonScrollAmount | |
262 */ | |
263 void setUpButtonScrollAmount(int amount); | |
264 | |
265 /** | |
266 * Sets the amount to scroll in pixels when the down scroll button is | |
267 * pushed. | |
268 * | |
269 * @param amount The amount to scroll in pixels. | |
270 * @see getDownButtonScrollAmount | |
271 */ | |
272 void setDownButtonScrollAmount(int amount); | |
273 | |
274 /** | |
275 * Gets the amount to scroll in pixels when the left scroll button is | |
276 * pushed. | |
277 * | |
278 * @return The amount to scroll in pixels. | |
279 * @see setLeftButtonScrollAmount | |
280 */ | |
281 int getLeftButtonScrollAmount() const; | |
282 | |
283 /** | |
284 * Gets the amount to scroll in pixels when the right scroll button is | |
285 * pushed. | |
286 * | |
287 * @return The amount to scroll in pixels. | |
288 * @see setRightButtonScrollAmount | |
289 */ | |
290 int getRightButtonScrollAmount() const; | |
291 | |
292 /** | |
293 * Gets the amount to scroll in pixels when the up scroll button is | |
294 * pushed. | |
295 * | |
296 * @return The amount to scroll in pixels. | |
297 * @see setUpButtonScrollAmount | |
298 */ | |
299 int getUpButtonScrollAmount() const; | |
300 | |
301 /** | |
302 * Gets the amount to scroll in pixels when the down scroll button is | |
303 * pushed. | |
304 * | |
305 * @return The amount to scroll in pixels. | |
306 * @see setDownButtonScrollAmount | |
307 */ | |
308 int getDownButtonScrollAmount() const; | |
309 | |
310 /** | |
311 * Sets the scroll area to be opaque, that is sets the scoll area | |
312 * to display its background. | |
313 * | |
314 * @param opaque True if the scoll area should be opaque, false otherwise. | |
315 */ | |
316 void setOpaque(bool opaque); | |
317 | |
318 /** | |
319 * Checks if the scroll area is opaque, that is if the scroll area | |
320 * displays its background. | |
321 * | |
322 * @return True if the scroll area is opaque, false otherwise. | |
323 */ | |
324 bool isOpaque() const; | |
325 | |
326 | |
327 // Inherited from BasicContainer | |
328 | |
329 virtual void showWidgetPart(Widget* widget, Rectangle area); | |
330 | |
331 virtual Rectangle getChildrenArea(); | |
332 | |
333 virtual Widget *getWidgetAt(int x, int y); | |
334 | |
335 | |
336 // Inherited from Widget | |
337 | |
338 virtual void draw(Graphics *graphics); | |
339 | |
340 virtual void logic(); | |
341 | |
342 void setWidth(int width); | |
343 | |
344 void setHeight(int height); | |
345 | |
346 void setDimension(const Rectangle& dimension); | |
347 | |
348 | |
349 // Inherited from MouseListener | |
350 | |
351 virtual void mousePressed(MouseEvent& mouseEvent); | |
352 | |
353 virtual void mouseReleased(MouseEvent& mouseEvent); | |
354 | |
355 virtual void mouseDragged(MouseEvent& mouseEvent); | |
356 | |
357 virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); | |
358 | |
359 virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); | |
360 | |
361 protected: | |
362 /** | |
363 * Draws the background of the scroll area, that is | |
364 * the area behind the content. | |
365 * | |
366 * @param graphics a Graphics object to draw with. | |
367 */ | |
368 virtual void drawBackground(Graphics *graphics); | |
369 | |
370 /** | |
371 * Draws the up button. | |
372 * | |
373 * @param graphics a Graphics object to draw with. | |
374 */ | |
375 virtual void drawUpButton(Graphics *graphics); | |
376 | |
377 /** | |
378 * Draws the down button. | |
379 * | |
380 * @param graphics a Graphics object to draw with. | |
381 */ | |
382 virtual void drawDownButton(Graphics *graphics); | |
383 | |
384 /** | |
385 * Draws the left button. | |
386 * | |
387 * @param graphics a Graphics object to draw with. | |
388 */ | |
389 virtual void drawLeftButton(Graphics *graphics); | |
390 | |
391 /** | |
392 * Draws the right button. | |
393 * | |
394 * @param graphics a Graphics object to draw with. | |
395 */ | |
396 virtual void drawRightButton(Graphics *graphics); | |
397 | |
398 /** | |
399 * Draws the vertical scroll bar. | |
400 * | |
401 * @param graphics a Graphics object to draw with. | |
402 */ | |
403 virtual void drawVBar(Graphics* graphics); | |
404 | |
405 /** | |
406 * Draws the horizontal scroll bar. | |
407 * | |
408 * @param graphics a Graphics object to draw with. | |
409 */ | |
410 virtual void drawHBar(Graphics* graphics); | |
411 | |
412 /** | |
413 * Draws the vertical marker. | |
414 * | |
415 * @param graphics a Graphics object to draw with. | |
416 */ | |
417 virtual void drawVMarker(Graphics* graphics); | |
418 | |
419 /** | |
420 * Draws the horizontal marker. | |
421 * | |
422 * @param graphics a Graphics object to draw with. | |
423 */ | |
424 virtual void drawHMarker(Graphics* graphics); | |
425 | |
426 /** | |
427 * Checks the policies for the scroll bars. | |
428 */ | |
429 virtual void checkPolicies(); | |
430 | |
431 /** | |
432 * Gets the up button dimension. | |
433 * | |
434 * @return the dimension of the up button. | |
435 */ | |
436 Rectangle getUpButtonDimension(); | |
437 | |
438 /** | |
439 * Gets the down button dimension. | |
440 * | |
441 * @return the dimension of the down button. | |
442 */ | |
443 Rectangle getDownButtonDimension(); | |
444 | |
445 /** | |
446 * Gets the left button dimension. | |
447 * | |
448 * @return the dimension of the left button. | |
449 */ | |
450 Rectangle getLeftButtonDimension(); | |
451 | |
452 /** | |
453 * Gets the right button dimension. | |
454 * | |
455 * @return the dimension of the right button. | |
456 */ | |
457 Rectangle getRightButtonDimension(); | |
458 | |
459 /** | |
460 * Gets the vertical scrollbar dimension. | |
461 * | |
462 * @return the dimension of the vertical scrollbar. | |
463 */ | |
464 Rectangle getVerticalBarDimension(); | |
465 | |
466 /** | |
467 * Gets the horizontal scrollbar dimension. | |
468 * | |
469 * @return the dimension of the horizontal scrollbar. | |
470 */ | |
471 Rectangle getHorizontalBarDimension(); | |
472 | |
473 /** | |
474 * Gets the vertical marker dimension. | |
475 * | |
476 * @return the dimension of the vertical marker. | |
477 */ | |
478 Rectangle getVerticalMarkerDimension(); | |
479 | |
480 /** | |
481 * Gets the horizontal marker dimension. | |
482 * | |
483 * @return the dimension of the horizontal marker. | |
484 */ | |
485 Rectangle getHorizontalMarkerDimension(); | |
486 | |
487 /** | |
488 * Holds the vertical scroll amount. | |
489 */ | |
490 int mVScroll; | |
491 | |
492 /** | |
493 * Holds the horizontal scroll amount. | |
494 */ | |
495 int mHScroll; | |
496 | |
497 /** | |
498 * Holds the width of the scroll bars. | |
499 */ | |
500 int mScrollbarWidth; | |
501 | |
502 /** | |
503 * Holds the horizontal scroll bar policy. | |
504 */ | |
505 ScrollPolicy mHPolicy; | |
506 | |
507 /** | |
508 * Holds the vertical scroll bar policy. | |
509 */ | |
510 ScrollPolicy mVPolicy; | |
511 | |
512 /** | |
513 * True if the vertical scroll bar is visible, false otherwise. | |
514 */ | |
515 bool mVBarVisible; | |
516 | |
517 /** | |
518 * True if the horizontal scroll bar is visible, false otherwise. | |
519 */ | |
520 bool mHBarVisible; | |
521 | |
522 /** | |
523 * True if the up button is pressed, false otherwise. | |
524 */ | |
525 bool mUpButtonPressed; | |
526 | |
527 /** | |
528 * True if the down button is pressed, false otherwise. | |
529 */ | |
530 bool mDownButtonPressed; | |
531 | |
532 /** | |
533 * True if the left button is pressed, false otherwise. | |
534 */ | |
535 bool mLeftButtonPressed; | |
536 | |
537 /** | |
538 * True if the right button is pressed, false otherwise. | |
539 */ | |
540 bool mRightButtonPressed; | |
541 | |
542 /** | |
543 * Holds the up button scroll amount. | |
544 */ | |
545 int mUpButtonScrollAmount; | |
546 | |
547 /** | |
548 * Holds the down button scroll amount. | |
549 */ | |
550 int mDownButtonScrollAmount; | |
551 | |
552 /** | |
553 * Holds the left button scroll amount. | |
554 */ | |
555 int mLeftButtonScrollAmount; | |
556 | |
557 /** | |
558 * Holds the right button scroll amount. | |
559 */ | |
560 int mRightButtonScrollAmount; | |
561 | |
562 /** | |
563 * True if the vertical marked is dragged. | |
564 */ | |
565 bool mIsVerticalMarkerDragged; | |
566 | |
567 /** | |
568 * True if the horizontal marked is dragged. | |
569 */ | |
570 bool mIsHorizontalMarkerDragged; | |
571 | |
572 /** | |
573 * Holds the horizontal markers drag offset. | |
574 */ | |
575 int mHorizontalMarkerDragOffset; | |
576 | |
577 /** | |
578 * Holds the vertical markers drag offset. | |
579 */ | |
580 int mVerticalMarkerDragOffset; | |
581 | |
582 /** | |
583 * True if the scroll area should be opaque (that is | |
584 * display its background), false otherwise. | |
585 */ | |
586 bool mOpaque; | |
587 }; | |
588 } | |
589 | |
590 #endif // end GCN_SCROLLAREA_HPP |