1 /*
2     GUILIB:  An example GUI framework library for use with SDL
3 */
4 
5 /* This is a very generic button widget - NOT ANY LONGER*/
6 
7 #ifndef _GUI_button_h
8 #define _GUI_button_h
9 
10 #include "GUI_widget.h"
11 #include "GUI_font.h"
12 
13 /* design constants */
14 #define BUTTON3D_UP 1
15 #define BUTTON3D_DOWN 2
16 #define BUTTON2D_UP 3
17 #define BUTTON2D_DOWN 4
18 
19 /* alignment constants */
20 #define BUTTON_TEXTALIGN_LEFT 1
21 #define BUTTON_TEXTALIGN_CENTER 2
22 #define BUTTON_TEXTALIGN_RIGHT 3
23 
24 /* color constants */
25 
26 // Button face color
27 const Uint8 BF_R=180,BF_G=180,BF_B=180;
28 // Button light color
29 const Uint8 BL_R=220,BL_G=220,BL_B=220;
30 // Button shadow color
31 const Uint8 BS_R=140,BS_G=140,BS_B=140;
32 // 2D Button inverse text color
33 const Uint8 BI1_R=255,BI1_G=255,BI1_B=255;
34 // 2D Button inverse background color
35 const Uint8 BI2_R=0,BI2_G=0,BI2_B=0;
36 
37 
38 /* This is the definition of the "I've been activated" callback */
39 typedef GUI_status (*GUI_ActiveProc)(void *data);
40 
41 class GUI_Button : public GUI_Widget {
42 
43 public:
44 	/* Passed the button data, position, images (pressed/unpressed) and callback */
45 	GUI_Button(void *data, int x, int y, SDL_Surface *image,
46 		   SDL_Surface *image2, GUI_ActiveProc activeproc = NULL);
47 
48 	/* I don't know what this one is for */
49 	GUI_Button(void *data, int x, int y, int w, int h,
50 		   GUI_ActiveProc activeproc = NULL);
51 
52 	/* Passed the button data, position, width, height, a caption, a font,
53 	   an alignment (one of the constants above), if it should be a checkbutton (1/0),
54 	   the callback and a flag if it should be 2D (1) or 3D (0) */
55 	GUI_Button(void *data, int x, int y, int w, int h, char* text,
56 		   GUI_Font *font, int alignment, int is_checkbutton,
57 		   GUI_ActiveProc activeproc = NULL, int flat = 0);
58 
59 	~GUI_Button();
60 
61 	/* change features of a text button (if one of the dimensions is negativ, it's ignored) */
62 	virtual void ChangeTextButton(int x, int y, int w, int h, char* text, int alignment);
63 
64 	/* Show the widget  */
65 	virtual void Display(void);
66 
67 	/* Mouse hits activate us */
68 	virtual GUI_status MouseDown(int x, int y, int button);
69 	virtual GUI_status MouseUp(int x, int y, int button);
70 	virtual GUI_status MouseMotion(int x, int y, Uint8 state);
71 
72 	/* Clickable or not ... */
73 	virtual void Disable();
74 	virtual void Enable(int flag = 1);
75 
76 	/* yields current state */
Enabled()77 	virtual int Enabled()
78 	  {return enabled;}
79 
80 	/* yields flag if button is a checkbutton */
IsCheckButton()81 	virtual int IsCheckButton()
82 	  {return is_checkable;}
83 
84 protected:
85 	/* yields an appropriate image */
86 	virtual SDL_Surface* CreateTextButtonImage(int style, char *text, int alignment);
87 
88 	/* The button font */
89 	GUI_Font *buttonFont;
90 
91 	/* The button images */
92 	SDL_Surface *button,*button2;
93 
94 	/* The activation callback */
95 	GUI_ActiveProc ActiveProc;
96 
97 	/* remember me! - flags */
98 	int enabled;
99 	int flatbutton;
100 	int freebutton,freefont;
101 
102 	/* Checkbutton flags */
103 	int is_checkable;
104 	int checked;
105 };
106 
107 #endif /* _GUI_button_h */
108