From 487bc7ed3b401ffd54ae3988368c92fe7551d9b1 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 8 Jul 2011 19:41:48 +0000 Subject: Fix a few NXTEXT bugs (there are many more) git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3756 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/nxtext/nxtext_bkgd.c | 51 +++++++++++++++++++++++----- apps/examples/nxtext/nxtext_internal.h | 5 +++ apps/examples/nxtext/nxtext_main.c | 18 +++++----- apps/examples/nxtext/nxtext_popup.c | 61 +++++++++++++++++++++++++--------- nuttx/TODO | 8 +++-- 5 files changed, 109 insertions(+), 34 deletions(-) diff --git a/apps/examples/nxtext/nxtext_bkgd.c b/apps/examples/nxtext/nxtext_bkgd.c index 0ec326b49..4daed7b84 100644 --- a/apps/examples/nxtext/nxtext_bkgd.c +++ b/apps/examples/nxtext/nxtext_bkgd.c @@ -93,6 +93,8 @@ static struct nxtext_glyph_s g_bgglyph[CONFIG_EXAMPLES_NXTEXT_GLCACHE]; * Public Data ****************************************************************************/ +/* Background window call table */ + const struct nx_callback_s g_bgcb = { nxbg_redraw, /* redraw */ @@ -105,6 +107,10 @@ const struct nx_callback_s g_bgcb = #endif }; +/* Background window handle */ + +NXHANDLE g_bgwnd; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -175,7 +181,11 @@ static void nxbg_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, if (!b_haveresolution) { - /* Save the window size */ + /* Save the background window handle */ + + g_bgwnd = hwnd; + + /* Save the background window size */ st->wsize.w = size->w; st->wsize.h = size->h; @@ -223,7 +233,6 @@ static void nxbg_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, static void nxbg_scroll(NXWINDOW hwnd, int lineheight) { - struct nxgl_rect_s rect; int i; int j; @@ -277,13 +286,9 @@ static void nxbg_scroll(NXWINDOW hwnd, int lineheight) g_bgstate.pos.y -= lineheight; } - /* Then re-draw the entry display */ + /* Then re-draw the entire display */ - rect.pt1.x = 0; - rect.pt1.y = 0; - rect.pt2.x = g_bgstate.wsize.w -1; - rect.pt2.y = g_bgstate.wsize.h -1; - nxbg_fillwindow(hwnd, &rect, &g_bgstate); + nxbg_refresh(hwnd); } /**************************************************************************** @@ -291,7 +296,11 @@ static void nxbg_scroll(NXWINDOW hwnd, int lineheight) ****************************************************************************/ /**************************************************************************** - * Name: nxbg_initstate + * Name: nxbg_getstate + * + * Description: + * Initialize the background window state structure. + * ****************************************************************************/ FAR struct nxtext_state_s *nxbg_getstate(void) @@ -328,6 +337,10 @@ FAR struct nxtext_state_s *nxbg_getstate(void) /**************************************************************************** * Name: nxbg_write + * + * Description: + * Put a sequence of bytes in the window. + * ****************************************************************************/ void nxbg_write(NXWINDOW hwnd, FAR const uint8_t *buffer, size_t buflen) @@ -366,4 +379,24 @@ void nxbg_write(NXWINDOW hwnd, FAR const uint8_t *buffer, size_t buflen) } } +/**************************************************************************** + * Name: nxbg_refresh + * + * Description: + * Re-draw the entire background. + * + ****************************************************************************/ + +void nxbg_refresh(NXWINDOW hwnd) +{ + struct nxgl_rect_s rect; + + rect.pt1.x = 0; + rect.pt1.y = 0; + rect.pt2.x = g_bgstate.wsize.w - 1; + rect.pt2.y = g_bgstate.wsize.h - 1; + nxbg_fillwindow(hwnd, &rect, &g_bgstate); +} + + diff --git a/apps/examples/nxtext/nxtext_internal.h b/apps/examples/nxtext/nxtext_internal.h index c1fc76b48..4b7982171 100644 --- a/apps/examples/nxtext/nxtext_internal.h +++ b/apps/examples/nxtext/nxtext_internal.h @@ -252,6 +252,10 @@ struct nxtext_state_s extern NXHANDLE g_hnx; +/* Background window handle */ + +extern NXHANDLE g_bgwnd; + /* NX callback vtables */ extern const struct nx_callback_s g_bgcb; @@ -285,6 +289,7 @@ extern FAR void *nxtext_listener(FAR void *arg); extern FAR struct nxtext_state_s *nxbg_getstate(void); extern void nxbg_write(NXWINDOW hwnd, FAR const uint8_t *buffer, size_t buflen); +extern void nxbg_refresh(NXWINDOW hwnd); /* Pop-up window interfaces */ diff --git a/apps/examples/nxtext/nxtext_main.c b/apps/examples/nxtext/nxtext_main.c index ce598c1a6..08f79169b 100644 --- a/apps/examples/nxtext/nxtext_main.c +++ b/apps/examples/nxtext/nxtext_main.c @@ -44,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -332,10 +331,6 @@ int user_start(int argc, char *argv[]) int bkgndx; int ret; - /* Seed the random number generator */ - - srand(0x1234); - /* Initialize NX */ ret = nxtext_initialize(); @@ -403,6 +398,13 @@ int user_start(int argc, char *argv[]) message("user_start: Close pop-up\n"); (void)nxpu_close(hwnd); + + /* NOTE: The following should not be necessary. This is + * a temporary workaround for a bug in the TOD list: + * "When a window is closed, the display is not updated." + */ + + nxbg_refresh(g_bgwnd); popcnt = 0; } else if (popcnt >= 3) @@ -411,7 +413,7 @@ int user_start(int argc, char *argv[]) hwnd = nxpu_open(); - /* Give keyboard input to the top window */ + /* Give keyboard input to the top window (which should be the pop-up) */ #ifdef CONFIG_NX_KBD message("user_start: Send keyboard input: %s\n", g_pumsg); @@ -428,7 +430,7 @@ int user_start(int argc, char *argv[]) * text to go the background by calling the kbdin method directly. */ - nxbg_write(g_hnx, (FAR const uint8_t *)g_bgmsg[bkgndx], strlen(g_bgmsg[bkgndx])); + nxbg_write(g_bgwnd, (FAR const uint8_t *)g_bgmsg[bkgndx], strlen(g_bgmsg[bkgndx])); if (++bkgndx >= BGMSG_LINES) { bkgndx = 0; @@ -445,7 +447,7 @@ errout_with_hwnd: } //errout_with_bkgd: - (void)nx_releasebkgd(g_hnx); + (void)nx_releasebkgd(g_bgwnd); errout_with_nx: #ifdef CONFIG_NX_MULTIUSER diff --git a/apps/examples/nxtext/nxtext_popup.c b/apps/examples/nxtext/nxtext_popup.c index b59a84500..d6b80d6ea 100644 --- a/apps/examples/nxtext/nxtext_popup.c +++ b/apps/examples/nxtext/nxtext_popup.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -88,6 +87,8 @@ static void nxpu_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, * Private Data ****************************************************************************/ +/* Pop-up NX callbacks */ + static const struct nx_callback_s g_pucb = { nxpu_redraw, /* redraw */ @@ -100,12 +101,21 @@ static const struct nx_callback_s g_pucb = #endif }; +/* Pop-up state information */ + static struct nxtext_state_s g_pustate; #ifdef CONFIG_NX_KBD static struct nxtext_bitmap_s g_pubm[NBM_CACHE]; static struct nxtext_glyph_s g_puglyph[NGLYPH_CACHE]; #endif +/* Some random numbers */ + +static const uint8_t g_rand8[9] = +{ + 0x18, 0x8d, 0x60, 0x42, 0xb7, 0xc2, 0x2d, 0xea, 0x6b +}; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -114,6 +124,23 @@ static struct nxtext_glyph_s g_puglyph[NGLYPH_CACHE]; * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: nxpu_randpos + ****************************************************************************/ + +static fb_coord_t nxpu_randpos(fb_coord_t value) +{ + static uint8_t ndx = 0; + uint8_t rand8 = g_rand8[ndx]; + + if (++ndx >= 9) + { + ndx = 0; + } + + return (fb_coord_t)(((uint32_t)value * (uint32_t)rand8) >> 8); +} + /**************************************************************************** * Name: nxpu_setsize ****************************************************************************/ @@ -123,7 +150,7 @@ static inline int nxpu_setsize(NXWINDOW hwnd, FAR struct nxgl_size_s *size) int ret = nx_setsize(hwnd, size); if (ret < 0) { - message("user_start: nx_setsize failed: %d\n", errno); + message("nxpu_setsize: nx_setsize failed: %d\n", errno); g_exitcode = NXEXIT_NXSETSIZE; } return ret; @@ -138,7 +165,7 @@ static inline int nxpu_setposition(NXWINDOW hwnd, FAR struct nxgl_point_s *pos) int ret = nx_setposition(hwnd, pos); if (ret < 0) { - message("user_start: nx_setposition failed: %d\n", errno); + message("nxpu_setposition: nx_setposition failed: %d\n", errno); g_exitcode = NXEXIT_NXSETPOSITION; } return ret; @@ -307,38 +334,42 @@ NXWINDOW nxpu_open(void) /* Create a pop-up window */ - message("user_start: Create pop-up\n"); + message("nxpu_open: Create pop-up\n"); nxpu_initstate(); hwnd = nx_openwindow(g_hnx, &g_pucb, (FAR void *)&g_pustate); - message("user_start: hwnd=%p\n", hwnd); + message("nxpu_open: hwnd=%p\n", hwnd); if (!hwnd) { - message("user_start: nx_openwindow failed: %d\n", errno); + message("nxpu_open: nx_openwindow failed: %d\n", errno); g_exitcode = NXEXIT_NXOPENWINDOW; goto errout_with_state; } - /* Set the size of the pop-up window */ + /* Select the size of the pop-up window */ size.w = g_xres / 4; size.h = g_yres / 4; - message("user_start: Set pop-up size to (%d,%d)\n", size.w, size.h); - ret = nxpu_setsize(hwnd, &size); + /* Select a random position for pop-up window */ + + pt.x = nxpu_randpos(g_xres - size.w); + pt.y = nxpu_randpos(g_yres - size.h); + + /* Set the position for the pop-up window */ + + message("nxpu_open: Set pop-up postion to (%d,%d)\n", pt.x, pt.y); + ret = nxpu_setposition(hwnd, &pt); if (ret < 0) { goto errout_with_hwnd; } - /* Set a random position for pop-up */ - - pt.x = ((uint32_t)(g_xres - size.w) * rand()) >> 16; - pt.y = ((uint32_t)(g_yres - size.h) * rand()) >> 16; + /* Set the size of the pop-up window */ - message("user_start: Set pop-up postion to (%d,%d)\n", pt.x, pt.y); - ret = nxpu_setposition(hwnd, &pt); + message("nxpu_open: Set pop-up size to (%d,%d)\n", size.w, size.h); + ret = nxpu_setsize(hwnd, &size); if (ret < 0) { goto errout_with_hwnd; diff --git a/nuttx/TODO b/nuttx/TODO index 497ee752d..443372345 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated July 3, 2011) +NuttX TODO List (Last updated July 8, 2011) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ nuttx/ @@ -14,7 +14,7 @@ nuttx/ (2) USB (drivers/usbdev, drivers/usbhost) (6) Libraries (lib/) (13) File system/Generic drivers (fs/, drivers/) - (1) Graphics subystem (graphics/) + (2) Graphics subystem (graphics/) (1) Pascal add-on (pcode/) (1) Documentation (Documentation/) (4) Build system / Toolchains @@ -484,6 +484,10 @@ o Graphics subystem (graphics/) Status: Open Priority: Medium + Description: When a window is closed, the display is not updated. + Status: Open + Priority: High + o Pascal Add-On (pcode/) ^^^^^^^^^^^^^^^^^^^^^^ -- cgit v1.2.3