1 /*
2     GUILIB:  An example GUI framework library for use with SDL
3 */
4 
5 /* This is a very generic scrollbar widget */
6 
7 #ifndef _GUI_scrollbar_h
8 #define _GUI_scrollbar_h
9 
10 #include "GUI_widget.h"
11 #include "GUI_scroll.h"
12 
13 /* The possible orientation of the scrollbar */
14 typedef enum { SCROLLBAR_HORIZONTAL, SCROLLBAR_VERTICAL } orientation;
15 
16 class GUI_ScrollBar : public GUI_Widget {
17 
18 public:
19 	/* Passed the sensitive areas, orientation, and initial widget */
20 	GUI_ScrollBar(SDL_Rect &first, SDL_Rect &middle, SDL_Rect &last,
21 			orientation direction, GUI_Scrollable *widget = NULL);
22 	GUI_ScrollBar(orientation direction, GUI_Scrollable *widget = NULL);
23 
24 	/* Link a scrollable widget to this scrollbar */
25 	virtual int AddScrollable(GUI_Scrollable *widget);
26 
27 	/* Show the widget  */
28 	virtual void Display(void) = 0;
29 
30 	/* Continue scrolling while mouse is held down */
31 	virtual GUI_status Idle(void);
32 
33 	/* Mouse hits activate us */
34 	virtual GUI_status MouseDown(int x, int y, int button);
35 
36 protected:
37 	/* The scrollable widget */
38 	GUI_Scrollable *target;
39 
40 	/* The areas:  Scroll up 1,  Position at, Scroll down 1 */
41 	SDL_Rect sensitive_neg;
42 	SDL_Rect sensitive_mid;
43 	SDL_Rect sensitive_pos;
44 	orientation whichxy;
45 
46 	/* Time at which the display will be scrolled while the mouse button
47 	   is being held down.
48 	 */
49 	Uint32 next_scroll;
50 
51 	/* Function to find the bounds of the widget */
52 	virtual void FindBounds(void);
53 
54 	/* The functions to activate the scrolling */
55 	virtual void Scroll(int amount);
56 	virtual void ScrollTo(int position);
57 };
58 
59 
60 class GUI_ScrollButtons : public GUI_ScrollBar {
61 
62 public:
63 	/* The possible orientation of the scrollbar:
64 		GUI_ScrollBar::HORIZONTAL, GUI_ScrollBar::VERTICAL
65 	 */
66 
67 	/* Passed the sensitive images, orientation, and initial widget */
68 	GUI_ScrollButtons(int x1, int y1, SDL_Surface *image1, SDL_Rect &middle,
69 	                  int x2, int y2, SDL_Surface *image2,
70 			orientation direction, GUI_Scrollable *widget = NULL);
71 
72 	/* Show the widget  */
73 	virtual void Display(void);
74 
75 protected:
76 	/* scroll button images */
77 	SDL_Surface *image_neg;
78 	SDL_Surface *image_pos;
79 };
80 
81 #endif /* _GUI_scrollbar_h */
82