int nxlines_main(int argc, char *argv[]) { nxgl_mxpixel_t color; int ret; /* Initialize NX */ ret = nxlines_initialize(); message("nxlines_main: NX handle=%p\n", g_nxlines.hnx); if (!g_nxlines.hnx || ret < 0) { message("nxlines_main: Failed to get NX handle: %d\n", errno); g_nxlines.code = NXEXIT_NXOPEN; goto errout; } /* Set the background to the configured background color */ message("nxlines_main: Set background color=%d\n", CONFIG_EXAMPLES_NXLINES_BGCOLOR); color = CONFIG_EXAMPLES_NXLINES_BGCOLOR; ret = nx_setbgcolor(g_nxlines.hnx, &color); if (ret < 0) { message("nxlines_main: nx_setbgcolor failed: %d\n", errno); g_nxlines.code = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Get the background window */ ret = nx_requestbkgd(g_nxlines.hnx, &g_nxlinescb, NULL); if (ret < 0) { message("nxlines_main: nx_setbgcolor failed: %d\n", errno); g_nxlines.code = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } /* Wait until we have the screen resolution. We'll have this immediately * unless we are dealing with the NX server. */ while (!g_nxlines.havepos) { (void)sem_wait(&g_nxlines.sem); } message("nxlines_main: Screen resolution (%d,%d)\n", g_nxlines.xres, g_nxlines.yres); /* Now, say perform the lines (these test does not return so the remaining * logic is cosmetic). */ nxlines_test(g_nxlines.hbkgd); /* Release background */ (void)nx_releasebkgd(g_nxlines.hbkgd); /* Close NX */ errout_with_nx: message("nxlines_main: Close NX\n"); nx_close(g_nxlines.hnx); errout: return g_nxlines.code; }
int nxtext_main(int argc, char **argv) { FAR struct nxtext_state_s *bgstate; NXWINDOW hwnd = NULL; nxgl_mxpixel_t color; int popcnt; int bkgndx; int ret; /* Initialize NX */ ret = nxtext_initialize(); message("nxtext_main: NX handle=%p\n", g_hnx); if (!g_hnx || ret < 0) { message("nxtext_main: Failed to get NX handle: %d\n", errno); g_exitcode = NXEXIT_NXOPEN; goto errout; } /* Get the configured font handles */ g_bghfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXTEXT_BGFONTID); if (!g_bghfont) { message("nxtext_main: Failed to get background font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } g_puhfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXTEXT_PUFONTID); if (!g_puhfont) { message("nxtext_main: Failed to get pop-up font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } /* Set the background to the configured background color */ message("nxtext_main: Set background color=%d\n", CONFIG_EXAMPLES_NXTEXT_BGCOLOR); color = CONFIG_EXAMPLES_NXTEXT_BGCOLOR; ret = nx_setbgcolor(g_hnx, &color); if (ret < 0) { message("nxtext_main: nx_setbgcolor failed: %d\n", errno); g_exitcode = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Get the background window */ bgstate = nxbg_getstate(); ret = nx_requestbkgd(g_hnx, &g_nxtextcb, bgstate); if (ret < 0) { message("nxtext_main: nx_setbgcolor failed: %d\n", errno); g_exitcode = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } /* Wait until we have the screen resolution. We'll have this immediately * unless we are dealing with the NX server. */ while (!b_haveresolution) { (void)sem_wait(&g_semevent); } message("nxtext_main: Screen resolution (%d,%d)\n", g_xres, g_yres); /* Now loop, adding text to the background and periodically presenting * a pop-up window. */ popcnt = 0; bkgndx = 0; for (;;) { /* Sleep for one second */ sleep(1); popcnt++; /* Each three seconds, create a pop-up window. Destroy the pop-up * window after two more seconds. */ if (popcnt == 3) { /* Create a pop-up window */ hwnd = nxpu_open(); /* Give keyboard input to the top window (which should be the pop-up) */ #ifdef CONFIG_NX_KBD message("nxtext_main: Send keyboard input: %s\n", g_pumsg); ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_pumsg), g_pumsg); if (ret < 0) { message("nxtext_main: nx_kbdin failed: %d\n", errno); goto errout_with_hwnd; } #endif } else if (popcnt == 5) { /* Destroy the pop-up window and restart the sequence */ message("nxtext_main: Close pop-up\n"); (void)nxpu_close(hwnd); popcnt = 0; } /* Give another line of text to the background window. Force this * text to go the background by calling the background window interfaces * directly. */ nxbg_write(g_bgwnd, (FAR const uint8_t *)g_bgmsg[bkgndx], strlen(g_bgmsg[bkgndx])); if (++bkgndx >= BGMSG_LINES) { bkgndx = 0; } } /* Close the pop-up window */ errout_with_hwnd: if (popcnt >= 3) { message("nxtext_main: Close pop-up\n"); (void)nxpu_close(hwnd); } //errout_with_bkgd: (void)nx_releasebkgd(g_bgwnd); errout_with_nx: #ifdef CONFIG_NX_MULTIUSER /* Disconnect from the server */ message("nxtext_main: Disconnect from the server\n"); nx_disconnect(g_hnx); #else /* Close the server */ message("nxtext_main: Close NX\n"); nx_close(g_hnx); #endif errout: return g_exitcode; }
int nximage_main(int argc, char *argv[]) #endif { nxgl_mxpixel_t color; int ret; /* Initialize NX */ ret = nximage_initialize(); printf("nximage_main: NX handle=%p\n", g_nximage.hnx); if (!g_nximage.hnx || ret < 0) { printf("nximage_main: Failed to get NX handle: %d\n", errno); g_nximage.code = NXEXIT_NXOPEN; goto errout; } /* Set the background to the configured background color */ color = nximage_bgcolor(); printf("nximage_main: Set background color=%u\n", color); ret = nx_setbgcolor(g_nximage.hnx, &color); if (ret < 0) { printf("nximage_main: nx_setbgcolor failed: %d\n", errno); g_nximage.code = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Get the background window */ ret = nx_requestbkgd(g_nximage.hnx, &g_nximagecb, NULL); if (ret < 0) { printf("nximage_main: nx_setbgcolor failed: %d\n", errno); g_nximage.code = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } /* Wait until we have the screen resolution. We'll have this immediately * unless we are dealing with the NX server. */ while (!g_nximage.havepos) { (void)sem_wait(&g_nximage.sem); } printf("nximage_main: Screen resolution (%d,%d)\n", g_nximage.xres, g_nximage.yres); /* Now, put up the NuttX logo and wait a bit so that it visible. */ nximage_image(g_nximage.hbkgd); sleep(5); /* Release background */ (void)nx_releasebkgd(g_nximage.hbkgd); /* Close NX */ errout_with_nx: printf("nximage_main: Close NX\n"); nx_close(g_nximage.hnx); errout: return g_nximage.code; }
int nxhello_main(int argc, char *argv[]) #endif { nxgl_mxpixel_t color; int ret; /* Initialize NX */ ret = nxhello_initialize(); printf("nxhello_main: NX handle=%p\n", g_nxhello.hnx); if (!g_nxhello.hnx || ret < 0) { printf("nxhello_main: Failed to get NX handle: %d\n", errno); g_nxhello.code = NXEXIT_NXOPEN; goto errout; } /* Get the default font handle */ g_nxhello.hfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXHELLO_FONTID); if (!g_nxhello.hfont) { printf("nxhello_main: Failed to get font handle: %d\n", errno); g_nxhello.code = NXEXIT_FONTOPEN; goto errout; } /* Set the background to the configured background color */ printf("nxhello_main: Set background color=%d\n", CONFIG_EXAMPLES_NXHELLO_BGCOLOR); color = CONFIG_EXAMPLES_NXHELLO_BGCOLOR; ret = nx_setbgcolor(g_nxhello.hnx, &color); if (ret < 0) { printf("nxhello_main: nx_setbgcolor failed: %d\n", errno); g_nxhello.code = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Get the background window */ ret = nx_requestbkgd(g_nxhello.hnx, &g_nxhellocb, NULL); if (ret < 0) { printf("nxhello_main: nx_setbgcolor failed: %d\n", errno); g_nxhello.code = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } /* Wait until we have the screen resolution. We'll have this immediately * unless we are dealing with the NX server. */ while (!g_nxhello.havepos) { (void)sem_wait(&g_nxhello.sem); } printf("nxhello_main: Screen resolution (%d,%d)\n", g_nxhello.xres, g_nxhello.yres); /* Now, say hello and exit, sleeping a little before each. */ sleep(1); nxhello_hello(g_nxhello.hbkgd); sleep(5000); /* Release background */ (void)nx_releasebkgd(g_nxhello.hbkgd); /* Close NX */ errout_with_nx: printf("nxhello_main: Close NX\n"); nx_close(g_nxhello.hnx); errout: return g_nxhello.code; }