1 /* Very basic widgets for SDL
2  * Ben Lynn
3  */
4 /*
5 Copyright (C) 2004 Benjamin Lynn (blynn@cs.stanford.edu)
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21 #ifndef WIDGET_H
22 #define WIDGET_H
23 
24 #include <SDL.h>
25 
26 enum {
27     signal_activate = 0,
28     signal_count
29 };
30 
31 struct widget_s {
32     int x, y;
33     int w, h;
34     int localx, localy;
35     struct widget_s *parent;
36     void (*update)(struct widget_s *);
37     void (*handle_click)(struct widget_s *, int, int, int);
38     void (*computexy)(struct widget_s *);
39     //TODO: replace with hash table?
40     void (*signal_handler[signal_count])(struct widget_s *w, void *data);
41     void *data[signal_count];
42 };
43 typedef struct widget_s widget_t[1];
44 typedef struct widget_s *widget_ptr;
45 
46 void widget_init(widget_ptr wid);
47 void widget_computexy(widget_ptr wid);
48 void widget_put_geometry(void *p, int x, int y, int w, int h);
49 void widget_put_handler(widget_ptr p, void (* f)(widget_ptr, void *), int sig);
50 void widget_put_handler_data(widget_ptr p,
51 	void (* f)(widget_ptr, void *), void *data, int sig);
52 void widget_fill(widget_ptr w, int c);
53 void widget_fillrect(widget_ptr w, SDL_Rect *rect, int c);
54 void widget_blit(void *p, SDL_Surface *s, SDL_Rect *src, SDL_Rect *dst);
55 void widget_raise_signal(widget_ptr w, int sig);
56 void widget_update(void *p);
57 int in_widget(widget_ptr wid, int x, int y);
58 void widget_raised_border(widget_ptr rect);
59 void widget_raised_background(widget_ptr rect);
60 void widget_lowered_border(widget_ptr rect);
61 void widget_lowered_background(widget_ptr rect);
62 
63 extern SDL_Surface *screen;
64 #endif //WIDGET_H
65