00001
00039 #ifndef WIN_H_INCLUDED
00040 #define WIN_H_INCLUDED
00041
00042 #include <app/win.h>
00043 #include "gfx/gfx.h"
00044 #include "membag.h"
00045
00170
00171 #define WIN_ATTR_POSITION (1 << 0)
00172
00173 #define WIN_ATTR_SIZE (1 << 1)
00174
00175 #define WIN_ATTR_BACKGROUND (1 << 2)
00176
00177 #define WIN_ATTR_EVENTHANDLER (1 << 3)
00178
00179 #define WIN_ATTR_BEHAVIOR (1 << 4)
00180
00181 #define WIN_ATTR_CUSTOM (1 << 5)
00182
00184 #define WIN_BEHAVIOR_RAISE_ON_PRESS (1 << 0)
00185
00186 #define WIN_BEHAVIOR_REDRAW_PARENT (1 << 1)
00187
00188
00190 struct win_window;
00191
00193 struct win_point {
00194 gfx_coord_t x;
00195 gfx_coord_t y;
00196 };
00197
00199 struct win_area {
00200 struct win_point pos;
00201 struct win_point size;
00202 };
00203
00205 struct win_clip_region {
00207 struct win_point origin;
00209 struct win_point NW;
00211 struct win_point SE;
00212 };
00213
00215 enum win_pointer_event_type {
00217 WIN_POINTER_PRESS,
00219 WIN_POINTER_MOVE,
00221 WIN_POINTER_RELEASE,
00222 };
00223
00225 struct win_pointer_event {
00227 struct win_point pos;
00229 bool is_relative;
00231 struct win_point last_pos;
00233 win_button_mask_t buttons;
00235 enum win_pointer_event_type type;
00236 };
00237
00239 enum win_keyboard_event_type {
00240 WIN_KEYBOARD_PRESS,
00241 WIN_KEYBOARD_RELEASE
00242 };
00243
00245 struct win_keyboard_event {
00246 win_keycode_t keycode;
00247 enum win_keyboard_event_type type;
00248 };
00249
00251 struct win_command_event {
00252 struct win_window *sender;
00253 struct win_window *recipient;
00254 win_command_t data;
00255 };
00256
00258 enum win_event_type {
00260 WIN_EVENT_POINTER,
00262 WIN_EVENT_KEYBOARD,
00264 WIN_EVENT_COMMAND,
00266 WIN_EVENT_RAISE,
00268 WIN_EVENT_UNRAISE,
00270 WIN_EVENT_GETFOCUS,
00272 WIN_EVENT_LOSEFOCUS,
00274 WIN_EVENT_DRAW,
00276 WIN_EVENT_ATTRIBUTES,
00278 WIN_EVENT_DESTROY,
00279 };
00280
00282 struct win_event {
00283 clock_jiffy_t timestamp;
00284 enum win_event_type type;
00285 union {
00287 struct win_pointer_event pointer;
00289 struct win_keyboard_event keyboard;
00291 struct win_command_event command;
00292 };
00293 };
00294
00300 typedef bool (*win_event_handler_t)(
00301 struct win_window *win,
00302 enum win_event_type type,
00303 const void *data);
00304
00306 typedef uint8_t win_behavior_t;
00307
00309 struct win_attributes {
00311 struct win_area area;
00312
00314 struct gfx_bitmap *background;
00315
00317 win_event_handler_t event_handler;
00319 win_behavior_t behavior;
00321 void *custom;
00322 };
00323
00325 typedef uint8_t win_attribute_mask_t;
00326
00328 void win_init(void);
00329
00331 struct win_window *win_get_root(void);
00332
00334 struct win_window *win_get_parent(const struct win_window *win);
00335
00337 void win_reset_root_geometry(void);
00338
00340 void win_set_attributes(
00341 struct win_window *win,
00342 const struct win_attributes *new_attributes,
00343 win_attribute_mask_t attribute_mask);
00344
00346 void win_set_area(
00347 struct win_window *win,
00348 const struct win_area *new_area,
00349 win_attribute_mask_t attribute_mask);
00350
00352 const struct win_attributes *win_get_attributes(const struct win_window *win);
00353
00355 const struct win_area *win_get_area(const struct win_window *win);
00356
00358 void *win_get_custom_data(const struct win_window *win);
00359
00361 struct win_window *win_create(
00362 struct win_window *parent,
00363 const struct win_attributes *attributes);
00364
00366 void win_destroy(struct win_window *win);
00367
00369 void win_reparent(
00370 struct win_window *child,
00371 struct win_window *new_parent);
00372
00374 void win_show(struct win_window *win);
00375
00377 void win_redraw(const struct win_window *win);
00378
00380 void win_hide(struct win_window *win);
00381
00383 void win_raise(struct win_window *win);
00384
00386 void win_lower(struct win_window *win);
00387
00389 void win_queue_pointer_event(const struct win_pointer_event *event);
00390
00392 void win_queue_keyboard_event(const struct win_keyboard_event *event);
00393
00395 void win_queue_command_event(const struct win_command_event *event);
00396
00398 void win_process_events(void);
00399
00401 void win_set_keyboard_focus(struct win_window *win);
00402
00404 void win_grab_pointer(struct win_window *win);
00405
00407 void win_translate_win_to_root(struct win_window const *start_win,
00408 struct win_point *return_pos);
00409
00411 bool win_is_inside_clip(
00412 const struct win_clip_region *clip,
00413 const struct win_point *point);
00414
00416 bool win_is_inside_area(
00417 const struct win_area *area,
00418 const struct win_point *point);
00419
00421 bool win_is_inside_window(
00422 const struct win_window *win,
00423 const struct win_point *point);
00424
00426 void win_compute_union(struct win_area *area, const struct win_area *merge);
00427
00429 bool win_compute_intersection(
00430 struct win_clip_region *clip,
00431 const struct win_area *area);
00432
00434 bool win_compute_clipping(
00435 const struct win_window *win,
00436 const struct win_area *dirty_area,
00437 struct win_clip_region *clip);
00438
00440
00441 #endif