apps/examples/pdcurses: Add a very simple example that just shows the entire character set (7-bit only). It adapts to the size of the framebuffer and, hence, can be used with very tiny displays. In fact it looks really dumb on big displays.
This commit is contained in:
parent
28f5176a0d
commit
f42031e65b
@ -44,6 +44,7 @@ CONFIG_EXAMPLES_PDCURSES_STACKSIZE ?= 2048
|
||||
PRIORITY = $(CONFIG_EXAMPLES_PDCURSES_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_PDCURSES_STACKSIZE)
|
||||
|
||||
CHARSETNAME = charset
|
||||
FIREWORKNAME = firework
|
||||
NEWDEMONAME = newdemo
|
||||
PANELNAME = panel
|
||||
@ -56,6 +57,7 @@ XMASNAME = xmas
|
||||
ASRCS =
|
||||
CSRCS = tui.c
|
||||
|
||||
CHARSETMAINSRC = charset_main.c
|
||||
FIREWORKMAINSRC = firework_main.c
|
||||
NEWDEMOMAINSRC = newdemo_main.c
|
||||
PANELMAINSRC = panel_main.c
|
||||
@ -64,11 +66,12 @@ TESTCURSMAINSRC = testcurs_main.c
|
||||
TUIMAINSRC = tui_main.c
|
||||
WORMMAINSRC = worm_main.c
|
||||
XMASMAINSRC = xmas_main.c
|
||||
MAINSRCS = $(FIREWORKMAINSRC) $(NEWDEMOMAINSRC) $(PANELMAINSRC) $(RAINMAINSRC) $(TESTCURSMAINSRC) $(TUIMAINSRC) $(WORMMAINSRC) $(XMASMAINSRC)
|
||||
MAINSRCS = $(CHARSETMAINSRC) $(FIREWORKMAINSRC) $(NEWDEMOMAINSRC) $(PANELMAINSRC) $(RAINMAINSRC) $(TESTCURSMAINSRC) $(TUIMAINSRC) $(WORMMAINSRC) $(XMASMAINSRC)
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
CHARSETMAINOBJ = $(CHARSETMAINSRC:.c=$(OBJEXT))
|
||||
FIREWORKMAINOBJ = $(FIREWORKMAINSRC:.c=$(OBJEXT))
|
||||
NEWDEMOMAINOBJ = $(NEWDEMOMAINSRC:.c=$(OBJEXT))
|
||||
PANELMAINOBJ = $(PANELMAINSRC:.c=$(OBJEXT))
|
||||
@ -77,7 +80,7 @@ TESTCURSMAINOBJ = $(TESTCURSMAINSRC:.c=$(OBJEXT))
|
||||
TUIMAINOBJ = $(TUIMAINSRC:.c=$(OBJEXT))
|
||||
WORMMAINOBJ = $(WORMMAINSRC:.c=$(OBJEXT))
|
||||
XMASMAINOBJ = $(XMASMAINSRC:.c=$(OBJEXT))
|
||||
MAINOBJS = $(FIREWORKMAINOBJ) $(NEWDEMOMAINOBJ) $(PANELMAINOBJ) $(RAINMAINOBJ) $(TESTCURSMAINOBJ) $(TUIMAINOBJ) $(WORMMAINOBJ) $(XMASMAINOBJ)
|
||||
MAINOBJS = $(CHARSETMAINOBJ) $(FIREWORKMAINOBJ) $(NEWDEMOMAINOBJ) $(PANELMAINOBJ) $(RAINMAINOBJ) $(TESTCURSMAINOBJ) $(TUIMAINOBJ) $(WORMMAINOBJ) $(XMASMAINOBJ)
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
|
||||
@ -119,6 +122,11 @@ $(MAINOBJS): %$(OBJEXT): %.c
|
||||
$(Q) touch $@
|
||||
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
$(BIN_DIR)$(DELIM)$(CHARSETNAME): $(OBJS) $(CHARSETMAINOBJ)
|
||||
@echo "LD: $(CHARSETNAME)"
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(CHARSETNAME) $(ARCHCRT0OBJ) $(CHARSETMAINOBJ) $(LDLIBS)
|
||||
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(CHARSETNAME)
|
||||
|
||||
$(BIN_DIR)$(DELIM)$(FIREWORKNAME): $(OBJS) $(FIREWORKMAINOBJ)
|
||||
@echo "LD: $(FIREWORKNAME)"
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(FIREWORKNAME) $(ARCHCRT0OBJ) $(FIREWORKMAINOBJ) $(LDLIBS)
|
||||
@ -159,7 +167,7 @@ $(BIN_DIR)$(DELIM)$(XMASNAME): $(OBJS) $(XMASMAINOBJ)
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(XMASNAME) $(ARCHCRT0OBJ) $(XMASMAINOBJ) $(LDLIBS)
|
||||
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(XMASNAME)
|
||||
|
||||
install: $(BIN_DIR)$(DELIM)$(FIREWORKNAME) $(BIN_DIR)$(DELIM)$(NEWDEMONAME) $(BIN_DIR)$(DELIM)$(PANELNAME) $(BIN_DIR)$(DELIM)$(RAINNAME) $(BIN_DIR)$(DELIM)$(TESTCURSNAME) $(BIN_DIR)$(DELIM)$(TUINAME) $(BIN_DIR)$(DELIM)$(WORMNAME) $(BIN_DIR)$(DELIM)$(XMASNAME)
|
||||
install: $(BIN_DIR)$(DELIM)$(CHARSETNAME) $(BIN_DIR)$(DELIM)$(FIREWORKNAME) $(BIN_DIR)$(DELIM)$(NEWDEMONAME) $(BIN_DIR)$(DELIM)$(PANELNAME) $(BIN_DIR)$(DELIM)$(RAINNAME) $(BIN_DIR)$(DELIM)$(TESTCURSNAME) $(BIN_DIR)$(DELIM)$(TUINAME) $(BIN_DIR)$(DELIM)$(WORMNAME) $(BIN_DIR)$(DELIM)$(XMASNAME)
|
||||
else
|
||||
install:
|
||||
endif
|
||||
@ -167,6 +175,9 @@ endif
|
||||
preconfig:
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(CHARSETNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(CHARSETNAME),$(PRIORITY),$(STACKSIZE),$(CHARSETNAME)_main)
|
||||
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(FIREWORKNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(FIREWORKNAME),$(PRIORITY),$(STACKSIZE),$(FIREWORKNAME)_main)
|
||||
|
||||
@ -191,7 +202,7 @@ $(BUILTIN_REGISTRY)$(DELIM)$(WORMNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(XMASNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(XMASNAME),$(PRIORITY),$(STACKSIZE),$(XMASNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(FIREWORKNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(NEWDEMONAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(PANELNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(RAINNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(TESTCURSNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(TUINAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(WORMNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(XMASNAME)_main.bdat
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(CHARSETNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(FIREWORKNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(NEWDEMONAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(PANELNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(RAINNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(TESTCURSNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(TUINAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(WORMNAME)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(XMASNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
137
examples/pdcurses/charset_main.c
Normal file
137
examples/pdcurses/charset_main.c
Normal file
@ -0,0 +1,137 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/pdcurses/charset_main.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Adapted by: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "graphics/curses.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define FIRST_CH 0x20
|
||||
#define LAST_CH 0x7e
|
||||
#define NUM_CH (LAST_CH - FIRST_CH + 1)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static short color_table[] =
|
||||
{
|
||||
COLOR_RED, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
|
||||
COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int charset_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
chtype ch;
|
||||
int lastch;
|
||||
int width;
|
||||
int height;
|
||||
int xoffset;
|
||||
int yoffset;
|
||||
int row;
|
||||
int col;
|
||||
int i;
|
||||
|
||||
/* Initialize */
|
||||
|
||||
traceon();
|
||||
initscr();
|
||||
noecho();
|
||||
|
||||
/* Setup colors */
|
||||
|
||||
if (has_colors())
|
||||
{
|
||||
start_color();
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
init_pair(i, color_table[i], COLOR_BLACK);
|
||||
}
|
||||
|
||||
/* Set up geometry */
|
||||
|
||||
width = COLS - 2;
|
||||
if (width > NUM_CH)
|
||||
{
|
||||
width = NUM_CH;
|
||||
}
|
||||
|
||||
xoffset = (COLS - width) / 2;
|
||||
|
||||
height = (NUM_CH + width - 1) / width;
|
||||
lastch = LAST_CH;
|
||||
|
||||
if (height > LINES)
|
||||
{
|
||||
height = LINES;
|
||||
lastch = FIRST_CH + width * height - 1;
|
||||
}
|
||||
|
||||
yoffset = (LINES - height) / 2;
|
||||
|
||||
/* Now display the character set */
|
||||
|
||||
ch = FIRST_CH;
|
||||
for (row = yoffset; row < yoffset + height; row++)
|
||||
{
|
||||
for (col = xoffset; col < xoffset + width; col++)
|
||||
{
|
||||
mvaddch(row, col, ch);
|
||||
if (++ch > lastch)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
refresh();
|
||||
endwin();
|
||||
return 0;
|
||||
}
|
@ -149,7 +149,14 @@ int main(int argc, FAR char *argv[])
|
||||
int firework_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
int i, start, end, row, diff, flag, direction, seed;
|
||||
int start;
|
||||
int end;
|
||||
int row;
|
||||
int diff;
|
||||
int flag;
|
||||
int direction;
|
||||
int seed;
|
||||
int i;
|
||||
|
||||
traceon();
|
||||
initscr();
|
||||
|
@ -303,7 +303,7 @@ static inline void PDC_set_bg(FAR struct pdc_fbstate_s *fbstate,
|
||||
#endif
|
||||
|
||||
/* Convert endcol to a byte offset (taking the ceiling so that includes
|
||||
* the final byte than may have only one pixels in it).
|
||||
* the final byte than may have only one pixel in it).
|
||||
*/
|
||||
|
||||
endcol = (endcol + 1) >> 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user