1 /* Very basic widgets for SDL
5 Copyright (C) 2004 Benjamin Lynn (blynn@cs.stanford.edu)
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.
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.
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.
24 void widget_computexy(widget_ptr wid
)
29 wid
->x
+= wid
->parent
->x
;
30 wid
->y
+= wid
->parent
->y
;
34 void widget_init(widget_ptr wid
)
40 wid
->handle_click
= NULL
;
41 for (i
=0; i
<signal_count
; i
++) {
42 wid
->signal_handler
[i
] = NULL
;
45 wid
->computexy
= widget_computexy
;
48 void widget_put_geometry(void *p
, int x
, int y
, int w
, int h
)
50 struct widget_s
*wid
= (struct widget_s
*) p
;
57 void widget_put_handler(widget_ptr p
, void (* f
)(widget_ptr
, void *), int sig
)
59 p
->signal_handler
[sig
] = f
;
62 void widget_put_handler_data(widget_ptr p
,
63 void (* f
)(widget_ptr
, void *), void *data
, int sig
)
65 p
->signal_handler
[sig
] = f
;
69 void widget_fill(widget_ptr w
, int c
)
77 SDL_FillRect(screen
, &rect
, ctable
[c
]);
80 void widget_fillrect(widget_ptr w
, SDL_Rect
*rect
, int c
)
88 SDL_FillRect(screen
, &r
, ctable
[c
]);
91 void widget_blit(void *p
, SDL_Surface
*s
, SDL_Rect
*src
, SDL_Rect
*dst
)
93 widget_ptr wid
= (widget_ptr
) p
;
96 SDL_BlitSurface(s
, src
, screen
, dst
);
101 void widget_raise_signal(widget_ptr w
, int sig
)
104 f
= w
->signal_handler
[sig
];
110 void widget_update(void *p
)
112 ((widget_ptr
) p
)->update(p
);
115 int in_widget(widget_ptr wid
, int x
, int y
)
117 return (wid
->x
<= x
&& x
< wid
->x
+ wid
->w
118 && wid
->y
<= y
&& y
< wid
->y
+ wid
->h
);
121 void widget_box(widget_ptr w
, int x0
, int y0
, int x1
, int y1
, int c
)
129 SDL_FillRect(screen
, &r
, ctable
[c
]);
132 void widget_raised_border(widget_ptr rect
)
137 widget_box(rect
, 1, y0
- 1, x0
- 1, y0
- 1, c_shadow
);
138 widget_box(rect
, x0
- 1, 1, x0
- 1, y0
- 1, c_shadow
);
140 widget_box(rect
, 0, 0, x0
, 0, c_highlight
);
141 widget_box(rect
, 0, 0, 0, y0
, c_highlight
);
143 widget_box(rect
, 0, y0
, x0
, y0
, c_darkshadow
);
144 widget_box(rect
, x0
, 0, x0
, y0
, c_darkshadow
);
147 void widget_raised_background(widget_ptr rect
)
149 widget_fill(rect
, c_background
);
150 widget_raised_border(rect
);
153 void widget_lowered_border(widget_ptr rect
)
158 widget_box(rect
, 2, y1
, x1
- 1, y1
, c_background
);
159 widget_box(rect
, x1
- 1, 2, x1
- 1, y1
, c_background
);
161 widget_box(rect
, 1, y1
, x1
- 1, y1
, c_highlight
);
162 widget_box(rect
, x1
, 1, x1
, y1
, c_highlight
);
164 widget_box(rect
, 0, 0, 0, y1
, c_shadow
);
165 widget_box(rect
, 0, 0, x1
, 0, c_shadow
);
167 widget_box(rect
, 1, 1, 1, y1
- 1, c_darkshadow
);
168 widget_box(rect
, 1, 1, x1
- 1, 1, c_darkshadow
);
171 void widget_lowered_background(widget_ptr rect
)
173 widget_fill(rect
, c_background
);
174 widget_lowered_border(rect
);