From 1bdb63b74206de4238a84166eb0b8fd0f2c986ff Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 18 Mar 2019 12:14:49 -0600 Subject: [PATCH] apps/examples/pwfb: Add a toolbar to the example windows. --- examples/pwfb/Kconfig | 5 ++ examples/pwfb/pwfb_events.c | 103 ++++++++++++++++++++++++++-------- examples/pwfb/pwfb_internal.h | 17 +++++- examples/pwfb/pwfb_main.c | 44 +++++++++++---- 4 files changed, 136 insertions(+), 33 deletions(-) diff --git a/examples/pwfb/Kconfig b/examples/pwfb/Kconfig index afd2bee0d..2da6b8574 100644 --- a/examples/pwfb/Kconfig +++ b/examples/pwfb/Kconfig @@ -40,6 +40,11 @@ config EXAMPLES_PWFB_COLOR3 ---help--- The color of window 3. Default depends on config EXAMPLES_PWFB_BPP. +config EXAMPLES_PWFB_TBCOLOR + hex "Toolbar Color" + ---help--- + The color of the toolbar. Default depends on config EXAMPLES_PWFB_BPP. + config EXAMPLES_PWFB_FONTCOLOR hex "Font Color" ---help--- diff --git a/examples/pwfb/pwfb_events.c b/examples/pwfb/pwfb_events.c index 5538d8a83..602b08ea2 100644 --- a/examples/pwfb/pwfb_events.c +++ b/examples/pwfb/pwfb_events.c @@ -55,26 +55,46 @@ * Private Function Prototypes ****************************************************************************/ -static void pwfb_redraw(NXTKWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - bool morem, FAR void *arg); -static void pwfb_position(NXTKWINDOW hwnd, FAR const struct nxgl_size_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg); +static void pwfb_wndo_redraw(NXTKWINDOW hwnd, + FAR const struct nxgl_rect_s *rect, bool morem, FAR void *arg); +static void pwfb_wndo_position(NXTKWINDOW hwnd, FAR + FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg); +static void pwfb_tb_redraw(NXTKWINDOW hwnd, + FAR const struct nxgl_rect_s *rect, bool morem, FAR void *arg); +static void pwfb_tb_position(NXTKWINDOW hwnd, + FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg); /**************************************************************************** * Public Data ****************************************************************************/ -const struct nx_callback_s g_pwfb_cb = +const struct nx_callback_s g_pwfb_wncb = { - pwfb_redraw, /* redraw */ - pwfb_position /* position */ + pwfb_wndo_redraw, /* redraw */ + pwfb_wndo_position /* position */ #ifdef CONFIG_NX_XYINPUT - , NULL /* mousein */ + , NULL /* mousein */ #endif #ifdef CONFIG_NX_KBD - , NULL /* kbdin */ + , NULL /* kbdin */ +#endif +}; + +const struct nx_callback_s g_pwfb_tbcb = +{ + pwfb_tb_redraw, /* redraw */ + pwfb_tb_position /* position */ +#ifdef CONFIG_NX_XYINPUT + , NULL /* mousein */ +#endif +#ifdef CONFIG_NX_KBD + , NULL /* kbdin */ #endif }; @@ -83,35 +103,37 @@ const struct nx_callback_s g_pwfb_cb = ****************************************************************************/ /**************************************************************************** - * Name: pwfb_redraw + * Name: pwfb_wndo_redraw ****************************************************************************/ -static void pwfb_redraw(NXTKWINDOW hwnd, FAR const struct nxgl_rect_s *rect, - bool more, FAR void *arg) +static void pwfb_wndo_redraw(NXTKWINDOW hwnd, + FAR const struct nxgl_rect_s *rect, + bool more, FAR void *arg) { /* There should be no redraw requests when using per-window framebuffers */ - printf("pwfb_redraw: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n", + printf("pwfb_wndo_redraw: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n", hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, more ? "true" : "false"); } /**************************************************************************** - * Name: pwfb_position + * Name: pwfb_wndo_position ****************************************************************************/ -static void pwfb_position(NXTKWINDOW hwnd, FAR const struct nxgl_size_s *size, - FAR const struct nxgl_point_s *pos, - FAR const struct nxgl_rect_s *bounds, - FAR void *arg) +static void pwfb_wndo_position(NXTKWINDOW hwnd, + FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) { FAR struct pwfb_state_s *st = (FAR struct pwfb_state_s *)arg; #ifdef CONFIG_EXAMPLES_PWFB_VERBOSE /* Report the position */ - printf("pwfb_position: hwnd=%p size=(%d,%d) pos=(%d,%d) " + printf("pwfb_wndo_position: hwnd=%p size=(%d,%d) pos=(%d,%d) " "bounds={(%d,%d),(%d,%d)}\n", hwnd, size->w, size->h, pos->x, pos->y, bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); @@ -131,10 +153,47 @@ static void pwfb_position(NXTKWINDOW hwnd, FAR const struct nxgl_size_s *size, st->haveres = true; sem_post(&st->semevent); - printf("pwfb_position: Have xres=%d yres=%d\n", st->xres, st->yres); + printf("pwfb_wndo_position: Have xres=%d yres=%d\n", + st->xres, st->yres); } } +/**************************************************************************** + * Name: pwfb_tb_redraw + ****************************************************************************/ + +static void pwfb_tb_redraw(NXTKWINDOW hwnd, + FAR const struct nxgl_rect_s *rect, + bool more, FAR void *arg) +{ + printf("pwfb_tb_redraw: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n", + hwnd, + rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, + more ? "true" : "false"); +} + +/**************************************************************************** + * Name: pwfb_tb_position + ****************************************************************************/ + +static void pwfb_tb_position(NXTKWINDOW hwnd, + FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) +{ +#ifdef CONFIG_EXAMPLES_PWFB_VERBOSE + FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg; + + /* Report the position */ + + printf("pwfb_tb_position: hwnd=%p size=(%d,%d) pos=(%d,%d) " + "bounds={(%d,%d),(%d,%d)}\n", + hwnd, size->w, size->h, pos->x, pos->y, + bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); +#endif +} + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/examples/pwfb/pwfb_internal.h b/examples/pwfb/pwfb_internal.h index 54682f0b6..dadd6f8b6 100644 --- a/examples/pwfb/pwfb_internal.h +++ b/examples/pwfb/pwfb_internal.h @@ -128,6 +128,16 @@ # endif #endif +#ifndef CONFIG_EXAMPLES_PWFB_TBCOLOR +# if CONFIG_EXAMPLES_PWFB_BPP == 24 || CONFIG_EXAMPLES_PWFB_BPP == 32 +# define CONFIG_EXAMPLES_PWFB_TBCOLOR 0x00a9a9a9 +# elif CONFIG_EXAMPLES_PWFB_BPP == 16 +# define CONFIG_EXAMPLES_PWFB_TBCOLOR 0xad55 +# else +# define CONFIG_EXAMPLES_PWFB_TBCOLOR 'T' +# endif +#endif + #ifndef CONFIG_EXAMPLES_PWFB_FONTCOLOR # if CONFIG_EXAMPLES_PWFB_BPP == 24 || CONFIG_EXAMPLES_PWFB_BPP == 32 # define CONFIG_EXAMPLES_PWFB_FONTCOLOR 0x00000000 @@ -177,6 +187,10 @@ struct pwfb_state_s nxgl_coord_t xres; /* Horizontal resolution */ nxgl_coord_t yres; /* Vertical resolution */ + /* Common toolbar properties */ + + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Toolbar color */ + /* Font properties */ uint8_t fheight; /* Max height of a font in pixels */ @@ -194,7 +208,8 @@ struct pwfb_state_s /* NX callback vtables */ -extern const struct nx_callback_s g_pwfb_cb; +extern const struct nx_callback_s g_pwfb_wncb; +extern const struct nx_callback_s g_pwfb_tbcb; /**************************************************************************** * Public Function Prototypes diff --git a/examples/pwfb/pwfb_main.c b/examples/pwfb/pwfb_main.c index 58566cefa..1fe6c7a55 100644 --- a/examples/pwfb/pwfb_main.c +++ b/examples/pwfb/pwfb_main.c @@ -203,6 +203,7 @@ static bool pwfb_state_initialize(FAR struct pwfb_state_s *st) st->wndo[0].color[0] = CONFIG_EXAMPLES_PWFB_COLOR1; st->wndo[1].color[0] = CONFIG_EXAMPLES_PWFB_COLOR2; st->wndo[2].color[0] = CONFIG_EXAMPLES_PWFB_COLOR3; + st->color[0] = CONFIG_EXAMPLES_PWFB_TBCOLOR; /* Connect each widnow to the font cache. They cannot share the * font cache becuse of the differing background colors. @@ -367,6 +368,7 @@ static bool pwfb_configure_window(FAR struct pwfb_state_s *st, int wndx, FAR const char *ptr; struct nxgl_rect_s rect; struct nxgl_point_s textpos; + nxgl_coord_t tbheight; int ret; /* Set the size of the window */ @@ -396,12 +398,14 @@ static bool pwfb_configure_window(FAR struct pwfb_state_s *st, int wndx, goto errout_with_hwnd; } - /* There is a race condition here we resolve by making the main thread - * lowest in priority. In order for the size and position to take effect, - * a command is sent to server which responds with an event. So we need - * to be synchronized at this point or the following fill will fail because - * it depends on current knowlede of the size and position. - */ + /* Create a toolbar */ + + tbheight = size->h >> 3; + ret = nxtk_opentoolbar(wndo->hwnd, tbheight, &g_pwfb_tbcb, st); + if (ret < 0) + { + printf("nxeq_opentoolbar: nxtk_opentoolbar failed: %d\n", errno); + } /* Create a bounding box. This is actually too large because it does not * account for the boarder widths. However, NX should clip the fill to @@ -411,7 +415,7 @@ static bool pwfb_configure_window(FAR struct pwfb_state_s *st, int wndx, rect.pt1.x = 0; rect.pt1.y = 0; rect.pt2.x = size->w - 1; - rect.pt2.y = size->h - 1; + rect.pt2.y = size->h - tbheight - 1; /* Fill the window with the selected color */ @@ -424,6 +428,26 @@ static bool pwfb_configure_window(FAR struct pwfb_state_s *st, int wndx, goto errout_with_hwnd; } + /* Fill the toolbar with the selected color */ + + rect.pt2.y = tbheight - 1; + + ret = nxtk_filltoolbar(wndo->hwnd, &rect, st->color); + if (ret < 0) + { + printf("pwfb_configure_window: ERROR: " + "nxtk_filltoobar failed: %d\n", + errno); + goto errout_with_hwnd; + } + + /* There is a race condition here we resolve by making the main thread + * lowest in priority. In order for the size and position to take effect, + * a command is sent to server which responds with an event. So we need + * to be synchronized at this point or the following fill will fail because + * it depends on current knowlede of the size and position. + */ + /* Add the text to the display, character at a time */ textpos.x = st->spwidth; @@ -533,7 +557,7 @@ int pwfb_main(int argc, char *argv[]) printf("pwfb_main: Open window 1\n"); wstate.wndo[0].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, - &g_pwfb_cb, (FAR void *)&wstate); + &g_pwfb_wncb, (FAR void *)&wstate); if (wstate.wndo[0].hwnd == NULL) { printf("pwfb_main: ERROR: " @@ -576,7 +600,7 @@ int pwfb_main(int argc, char *argv[]) printf("pwfb_main: Open window 2\n"); wstate.wndo[1].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, - &g_pwfb_cb, (FAR void *)&wstate); + &g_pwfb_wncb, (FAR void *)&wstate); if (wstate.wndo[1].hwnd == NULL) { printf("pwfb_main: ERROR: " @@ -604,7 +628,7 @@ int pwfb_main(int argc, char *argv[]) printf("pwfb_main: Open window 3\n"); wstate.wndo[2].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, - &g_pwfb_cb, (FAR void *)&wstate); + &g_pwfb_wncb, (FAR void *)&wstate); if (wstate.wndo[2].hwnd == NULL) { printf("pwfb_main: ERROR: "