diff --git a/contrib/media/fplay/skin/skin.asm b/contrib/media/fplay/skin/skin.asm index 141ab669a3..8a9cf57a03 100644 --- a/contrib/media/fplay/skin/skin.asm +++ b/contrib/media/fplay/skin/skin.asm @@ -101,3 +101,4 @@ _res_progress_bar: file 'pbar.raw' _res_prg_level: file 'prg_level.raw' _res_def_font: file 'IstokWeb.ttf' + diff --git a/contrib/media/fplay/winlib/link.h b/contrib/media/fplay/winlib/link.h new file mode 100644 index 0000000000..8f72bb3411 --- /dev/null +++ b/contrib/media/fplay/winlib/link.h @@ -0,0 +1,60 @@ + +typedef struct link +{ + struct link *prev; + struct link *next; +}link_t; + +#define LIST_INITIALIZE(name) \ + link_t name = { .prev = &name, .next = &name } + +#define list_get_instance(link, type, member) \ + ((type *)(((u8_t *)(link)) - ((u8_t *)&(((type *)NULL)->member)))) + +static inline void link_initialize(link_t *link) +{ + link->prev = NULL; + link->next = NULL; +} + +static inline void list_initialize(link_t *head) +{ + head->prev = head; + head->next = head; +} + +static inline void list_append(link_t *link, link_t *head) +{ + link->prev = head->prev; + link->next = head; + head->prev->next = link; + head->prev = link; +} + +static inline void list_remove(link_t *link) +{ + link->next->prev = link->prev; + link->prev->next = link->next; + link_initialize(link); +} + +static inline int list_empty(link_t *head) +{ + return head->next == head ? 1 : 0; +} + +static inline void list_prepend(link_t *link, link_t *head) +{ + link->next = head->next; + link->prev = head; + head->next->prev = link; + head->next = link; +} + +static inline void list_insert(link_t *new, link_t *old) +{ + new->prev = old->prev; + new->next = old; + new->prev->next = new; + old->prev = new; +} diff --git a/contrib/media/fplay/winlib/timer.h b/contrib/media/fplay/winlib/timer.h new file mode 100644 index 0000000000..ebd983958c --- /dev/null +++ b/contrib/media/fplay/winlib/timer.h @@ -0,0 +1,46 @@ + + +static uint32_t update_timers(uint32_t realtime) +{ + ostimer_t *timer; + uint32_t exp_time = -1; + + timer = (ostimer_t*)timers.next; + while( &timer->link != &timers) + { + ostimer_t *tmp; + + tmp = timer; + timer = (ostimer_t*)timer->link.next; + + if( tmp->exp_time < realtime) + { + list_remove(&tmp->link); + send_message(tmp->ctrl, MSG_TIMER, tmp->tmr_arg, tmp); + } + }; + + timer = (ostimer_t*)timers.next; + while( &timer->link != &timers) + { + if( exp_time > timer->exp_time) + exp_time = timer->exp_time; + timer = (ostimer_t*)timer->link.next; + } + return exp_time; +}; + +int set_timer(ctrl_t *ctrl, ostimer_t *timer, uint32_t delay) +{ + if( ctrl && timer &&delay) + { + timer->ctrl = ctrl; + timer->exp_time = realtime + delay; + + if( exp_time > timer->exp_time) + exp_time = timer->exp_time; + + list_append(&timer->link, &timers); + }; + return 0; +} diff --git a/contrib/media/fplay/winlib/window.c b/contrib/media/fplay/winlib/window.c index 06cd4d55e2..6964231d97 100644 --- a/contrib/media/fplay/winlib/window.c +++ b/contrib/media/fplay/winlib/window.c @@ -18,12 +18,13 @@ uint32_t cursor_nesw; int win_font; +static window_t Window; static pos_t old_pos; ctrl_t *mouse_capture = NULL; -static link_t timers; +static link_t timers; static uint32_t realtime; static uint32_t wait_time; static uint32_t exp_time; @@ -35,16 +36,31 @@ static int need_update; void adjust_frame(window_t *win); +//#include "timer.h" +ctrl_t *win_get_child(window_t *win, int x, int y) +{ + ctrl_t *child = NULL; -#include "control.inc" -//#include "io.inc" -#include "timer.inc" - -//#include "button.inc" -//#include "scroller.inc" - -static window_t Window; + if( win ) + { + if(pt_in_rect(&win->client, x, y)) + { + ctrl_t *tmp = (ctrl_t*)win->child.next; + while( &tmp->link != &win->child ) + { + if(pt_in_rect(&tmp->rc, x, y)) + { + child = get_child(tmp, x, y); + return child == NULL ? tmp : child; + }; + tmp = (ctrl_t*)tmp->link.next; + }; + } + else child = (ctrl_t*)(&win->frame); + }; + return child; +}; void init_frame(window_t *win);