apps/examples/pwfb: Add a toolbar to the example windows.

This commit is contained in:
Gregory Nutt 2019-03-18 12:14:49 -06:00
parent 6513d9107c
commit 1bdb63b742
4 changed files with 136 additions and 33 deletions

View File

@ -40,6 +40,11 @@ config EXAMPLES_PWFB_COLOR3
---help--- ---help---
The color of window 3. Default depends on config EXAMPLES_PWFB_BPP. 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 config EXAMPLES_PWFB_FONTCOLOR
hex "Font Color" hex "Font Color"
---help--- ---help---

View File

@ -55,26 +55,46 @@
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
static void pwfb_redraw(NXTKWINDOW hwnd, FAR const struct nxgl_rect_s *rect, static void pwfb_wndo_redraw(NXTKWINDOW hwnd,
bool morem, FAR void *arg); 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, static void pwfb_wndo_position(NXTKWINDOW hwnd, FAR
FAR const struct nxgl_point_s *pos, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_rect_s *bounds, FAR const struct nxgl_point_s *pos,
FAR void *arg); 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 * Public Data
****************************************************************************/ ****************************************************************************/
const struct nx_callback_s g_pwfb_cb = const struct nx_callback_s g_pwfb_wncb =
{ {
pwfb_redraw, /* redraw */ pwfb_wndo_redraw, /* redraw */
pwfb_position /* position */ pwfb_wndo_position /* position */
#ifdef CONFIG_NX_XYINPUT #ifdef CONFIG_NX_XYINPUT
, NULL /* mousein */ , NULL /* mousein */
#endif #endif
#ifdef CONFIG_NX_KBD #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 #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, static void pwfb_wndo_redraw(NXTKWINDOW hwnd,
bool more, FAR void *arg) FAR const struct nxgl_rect_s *rect,
bool more, FAR void *arg)
{ {
/* There should be no redraw requests when using per-window framebuffers */ /* 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, hwnd,
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "true" : "false"); more ? "true" : "false");
} }
/**************************************************************************** /****************************************************************************
* Name: pwfb_position * Name: pwfb_wndo_position
****************************************************************************/ ****************************************************************************/
static void pwfb_position(NXTKWINDOW hwnd, FAR const struct nxgl_size_s *size, static void pwfb_wndo_position(NXTKWINDOW hwnd,
FAR const struct nxgl_point_s *pos, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_rect_s *bounds, FAR const struct nxgl_point_s *pos,
FAR void *arg) FAR const struct nxgl_rect_s *bounds,
FAR void *arg)
{ {
FAR struct pwfb_state_s *st = (FAR struct pwfb_state_s *)arg; FAR struct pwfb_state_s *st = (FAR struct pwfb_state_s *)arg;
#ifdef CONFIG_EXAMPLES_PWFB_VERBOSE #ifdef CONFIG_EXAMPLES_PWFB_VERBOSE
/* Report the position */ /* 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", "bounds={(%d,%d),(%d,%d)}\n",
hwnd, size->w, size->h, pos->x, pos->y, hwnd, size->w, size->h, pos->x, pos->y,
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.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; st->haveres = true;
sem_post(&st->semevent); 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 * Public Functions
****************************************************************************/ ****************************************************************************/

View File

@ -128,6 +128,16 @@
# endif # endif
#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 #ifndef CONFIG_EXAMPLES_PWFB_FONTCOLOR
# if CONFIG_EXAMPLES_PWFB_BPP == 24 || CONFIG_EXAMPLES_PWFB_BPP == 32 # if CONFIG_EXAMPLES_PWFB_BPP == 24 || CONFIG_EXAMPLES_PWFB_BPP == 32
# define CONFIG_EXAMPLES_PWFB_FONTCOLOR 0x00000000 # define CONFIG_EXAMPLES_PWFB_FONTCOLOR 0x00000000
@ -177,6 +187,10 @@ struct pwfb_state_s
nxgl_coord_t xres; /* Horizontal resolution */ nxgl_coord_t xres; /* Horizontal resolution */
nxgl_coord_t yres; /* Vertical resolution */ nxgl_coord_t yres; /* Vertical resolution */
/* Common toolbar properties */
nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Toolbar color */
/* Font properties */ /* Font properties */
uint8_t fheight; /* Max height of a font in pixels */ uint8_t fheight; /* Max height of a font in pixels */
@ -194,7 +208,8 @@ struct pwfb_state_s
/* NX callback vtables */ /* 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 * Public Function Prototypes

View File

@ -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[0].color[0] = CONFIG_EXAMPLES_PWFB_COLOR1;
st->wndo[1].color[0] = CONFIG_EXAMPLES_PWFB_COLOR2; st->wndo[1].color[0] = CONFIG_EXAMPLES_PWFB_COLOR2;
st->wndo[2].color[0] = CONFIG_EXAMPLES_PWFB_COLOR3; 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 /* Connect each widnow to the font cache. They cannot share the
* font cache becuse of the differing background colors. * 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; FAR const char *ptr;
struct nxgl_rect_s rect; struct nxgl_rect_s rect;
struct nxgl_point_s textpos; struct nxgl_point_s textpos;
nxgl_coord_t tbheight;
int ret; int ret;
/* Set the size of the window */ /* 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; goto errout_with_hwnd;
} }
/* There is a race condition here we resolve by making the main thread /* Create a toolbar */
* 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 tbheight = size->h >> 3;
* to be synchronized at this point or the following fill will fail because ret = nxtk_opentoolbar(wndo->hwnd, tbheight, &g_pwfb_tbcb, st);
* it depends on current knowlede of the size and position. 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 /* 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 * 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.x = 0;
rect.pt1.y = 0; rect.pt1.y = 0;
rect.pt2.x = size->w - 1; 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 */ /* 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; 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 */ /* Add the text to the display, character at a time */
textpos.x = st->spwidth; textpos.x = st->spwidth;
@ -533,7 +557,7 @@ int pwfb_main(int argc, char *argv[])
printf("pwfb_main: Open window 1\n"); printf("pwfb_main: Open window 1\n");
wstate.wndo[0].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, 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) if (wstate.wndo[0].hwnd == NULL)
{ {
printf("pwfb_main: ERROR: " printf("pwfb_main: ERROR: "
@ -576,7 +600,7 @@ int pwfb_main(int argc, char *argv[])
printf("pwfb_main: Open window 2\n"); printf("pwfb_main: Open window 2\n");
wstate.wndo[1].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, 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) if (wstate.wndo[1].hwnd == NULL)
{ {
printf("pwfb_main: ERROR: " printf("pwfb_main: ERROR: "
@ -604,7 +628,7 @@ int pwfb_main(int argc, char *argv[])
printf("pwfb_main: Open window 3\n"); printf("pwfb_main: Open window 3\n");
wstate.wndo[2].hwnd = nxtk_openwindow(wstate.hnx, NXBE_WINDOW_RAMBACKED, 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) if (wstate.wndo[2].hwnd == NULL)
{ {
printf("pwfb_main: ERROR: " printf("pwfb_main: ERROR: "