Merge pull request #181 from mmuman/ctk-ncurses-try4
TODOs: - Check FreeBSD - Adjust Makefile.target
This commit is contained in:
commit
d5d8de7372
1
examples/email/Makefile.native.defines
Normal file
1
examples/email/Makefile.native.defines
Normal file
@ -0,0 +1 @@
|
||||
DEFINES = WITH_GUI
|
1
examples/ftp/Makefile.native.defines
Normal file
1
examples/ftp/Makefile.native.defines
Normal file
@ -0,0 +1 @@
|
||||
DEFINES = WITH_GUI
|
1
examples/irc/Makefile.native.defines
Normal file
1
examples/irc/Makefile.native.defines
Normal file
@ -0,0 +1 @@
|
||||
DEFINES = WITH_GUI
|
1
examples/webbrowser/Makefile.native.defines
Normal file
1
examples/webbrowser/Makefile.native.defines
Normal file
@ -0,0 +1 @@
|
||||
DEFINES = WITH_GUI
|
@ -10,12 +10,12 @@ ifeq ($(UIP_CONF_IPV6),1)
|
||||
CFLAGS += -DWITH_UIP6=1
|
||||
endif
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev
|
||||
CONTIKI_TARGET_DIRS = . dev ctk
|
||||
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o}
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES = contiki-main.c clock.c leds.c leds-arch.c \
|
||||
button-sensor.c pir-sensor.c vib-sensor.c xmem.c \
|
||||
sensors.c irq.c cfs-posix.c cfs-posix-dir.c
|
||||
sensors.c irq.c cfs-posix.c cfs-posix-dir.c ctk-curses.c
|
||||
|
||||
ifeq ($(HOST_OS),Windows)
|
||||
CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c
|
||||
@ -30,10 +30,19 @@ CONTIKI_TARGET_SOURCEFILES += tapdev6.c
|
||||
endif
|
||||
endif
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
CONTIKI_SOURCEFILES += $(CTK) ctk-conio.c $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
### Define the CPU directory
|
||||
CONTIKI_CPU=$(CONTIKI)/cpu/native
|
||||
include $(CONTIKI)/cpu/native/Makefile.native
|
||||
|
||||
ifeq ($(HOST_OS),Windows)
|
||||
CFLAGS += -I/usr/include/ncurses
|
||||
endif
|
||||
|
||||
CURSES_LIBS ?= -lncurses
|
||||
|
||||
TARGET_LIBFILES += $(CURSES_LIBS)
|
||||
|
||||
|
@ -165,12 +165,111 @@ typedef unsigned short uip_stats_t;
|
||||
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
#include <ctype.h>
|
||||
#define ctk_arch_isprint isprint
|
||||
|
||||
#include "ctk/ctk-curses.h"
|
||||
|
||||
#define CH_ULCORNER -10
|
||||
#define CH_URCORNER -11
|
||||
#define CH_LLCORNER -12
|
||||
#define CH_LRCORNER -13
|
||||
#define CH_ENTER '\n'
|
||||
#define CH_DEL '\b'
|
||||
#define CH_CURS_UP -1
|
||||
#define CH_CURS_LEFT -2
|
||||
#define CH_CURS_RIGHT -3
|
||||
#define CH_CURS_DOWN -4
|
||||
|
||||
#define CTK_CONF_MENU_KEY -5 /* F10 */
|
||||
#define CTK_CONF_WINDOWSWITCH_KEY -6 /* Ctrl-Tab */
|
||||
#define CTK_CONF_WIDGETUP_KEY -7 /* Shift-Tab */
|
||||
#define CTK_CONF_WIDGETDOWN_KEY '\t'
|
||||
#define CTK_CONF_WIDGET_FLAGS 0
|
||||
#define CTK_CONF_SCREENSAVER 1
|
||||
|
||||
#ifdef PLATFORM_BUILD
|
||||
#define CTK_CONF_MOUSE_SUPPORT 1
|
||||
#define CTK_CONF_WINDOWS 1
|
||||
#define CTK_CONF_WINDOWMOVE 1
|
||||
#define CTK_CONF_WINDOWCLOSE 1
|
||||
#define CTK_CONF_ICONS 1
|
||||
#define CTK_CONF_ICON_BITMAPS 0
|
||||
#define CTK_CONF_ICON_TEXTMAPS 1
|
||||
#define CTK_CONF_MENUS 1
|
||||
#define CTK_CONF_MENUWIDTH 16
|
||||
#define CTK_CONF_MAXMENUITEMS 10
|
||||
#else /* PLATFORM_BUILD */
|
||||
#define CTK_CONF_MOUSE_SUPPORT 1
|
||||
#define CTK_CONF_WINDOWS 0
|
||||
#define CTK_CONF_WINDOWMOVE 0
|
||||
#define CTK_CONF_WINDOWCLOSE 0
|
||||
#define CTK_CONF_ICONS 0
|
||||
#define CTK_CONF_MENUS 0
|
||||
#endif /* PLATFORM_BUILD */
|
||||
|
||||
/* CTK-specific color constants */
|
||||
#define CTK_COLOR_BLACK 0
|
||||
#define CTK_COLOR_RED 1
|
||||
#define CTK_COLOR_GREEN 2
|
||||
#define CTK_COLOR_YELLOW 3
|
||||
#define CTK_COLOR_BLUE 4
|
||||
#define CTK_COLOR_MAGENTA 5
|
||||
#define CTK_COLOR_CYAN 6
|
||||
#define CTK_COLOR_WHITE 7
|
||||
|
||||
/* base background color for widgets */
|
||||
#define COLOR_BG CTK_COLOR_BLUE
|
||||
|
||||
#define BORDERCOLOR CTK_COLOR_BLACK
|
||||
#define SCREENCOLOR CTK_COLOR_BLACK
|
||||
#define BACKGROUNDCOLOR CTK_COLOR_BLACK
|
||||
#define WINDOWCOLOR_FOCUS CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define WINDOWCOLOR CTK_COLOR_CYAN | COLOR_BG * 0x10
|
||||
#define DIALOGCOLOR CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR_HLINK CTK_COLOR_CYAN | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR_FWIN CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR CTK_COLOR_CYAN | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR_DIALOG CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR_FOCUS CTK_COLOR_YELLOW | COLOR_BG * 0x10
|
||||
#define MENUCOLOR CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define OPENMENUCOLOR CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define ACTIVEMENUITEMCOLOR CTK_COLOR_YELLOW | COLOR_BG * 0x10
|
||||
|
||||
|
||||
typedef unsigned long clock_time_t;
|
||||
|
||||
#define CLOCK_CONF_SECOND 1000
|
||||
|
||||
#define LOG_CONF_ENABLED 1
|
||||
|
||||
#define PROGRAM_HANDLER_CONF_MAX_NUMDSCS 10
|
||||
#define PROGRAM_HANDLER_CONF_QUIT_MENU 1
|
||||
|
||||
#define EMAIL_CONF_WIDTH 78
|
||||
#define EMAIL_CONF_HEIGHT 17
|
||||
#ifndef PLATFORM_BUILD
|
||||
#define EMAIL_CONF_ERASE 0
|
||||
#endif
|
||||
|
||||
#define IRC_CONF_WIDTH 78
|
||||
#define IRC_CONF_HEIGHT 17
|
||||
#define IRC_CONF_SYSTEM_STRING "*nix"
|
||||
|
||||
#define SHELL_CONF_WITH_PROGRAM_HANDLER 1
|
||||
|
||||
#define SHELL_GUI_CONF_XSIZE 78
|
||||
#define SHELL_GUI_CONF_YSIZE 17
|
||||
|
||||
#ifdef PLATFORM_BUILD
|
||||
#define TELNETD_CONF_GUI 1
|
||||
#endif /* PLATFORM_BUILD */
|
||||
|
||||
#ifdef PLATFORM_BUILD
|
||||
#define WWW_CONF_WEBPAGE_WIDTH 78
|
||||
#define WWW_CONF_WEBPAGE_HEIGHT 17
|
||||
#endif /* PLATFORM_BUILD */
|
||||
|
||||
/* Not part of C99 but actually present */
|
||||
int strcasecmp(const char*, const char*);
|
||||
|
||||
|
@ -43,6 +43,9 @@
|
||||
#include "contiki.h"
|
||||
#include "net/netstack.h"
|
||||
|
||||
#include "ctk/ctk.h"
|
||||
#include "ctk/ctk-curses.h"
|
||||
|
||||
#include "dev/serial-line.h"
|
||||
|
||||
#include "net/uip.h"
|
||||
@ -188,6 +191,10 @@ main(int argc, char **argv)
|
||||
process_start(&etimer_process, NULL);
|
||||
ctimer_init();
|
||||
|
||||
#if WITH_GUI
|
||||
process_start(&ctk_process, NULL);
|
||||
#endif
|
||||
|
||||
set_rime_addr();
|
||||
|
||||
queuebuf_init();
|
||||
@ -263,6 +270,12 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
etimer_request_poll();
|
||||
|
||||
#if WITH_GUI
|
||||
if(console_resize()) {
|
||||
ctk_restore();
|
||||
}
|
||||
#endif /* WITH_GUI */
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
517
platform/native/ctk/ctk-curses.c
Normal file
517
platform/native/ctk/ctk-curses.c
Normal file
@ -0,0 +1,517 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: François Revol <revol@free.fr>
|
||||
*/
|
||||
|
||||
#include <curses.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <term.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "ctk/ctk.h"
|
||||
|
||||
#include "ctk-curses.h"
|
||||
|
||||
/* references:
|
||||
* http://math.hws.edu/orr/s04/cpsc225/curses.html
|
||||
* http://linux.die.net/man/3/ncurses
|
||||
* http://linux.die.net/HOWTO/NCURSES-Programming-HOWTO/index.html
|
||||
*/
|
||||
|
||||
#define MKPAIR(bg, fg) (bg << 3 | fg)
|
||||
|
||||
static unsigned char width;
|
||||
static unsigned char height;
|
||||
|
||||
static unsigned char color;
|
||||
static unsigned char reversed;
|
||||
|
||||
static ctk_arch_key_t keys[256];
|
||||
static unsigned char keys_in, keys_out;
|
||||
static unsigned char available;
|
||||
|
||||
static unsigned short xpos;
|
||||
static unsigned short ypos;
|
||||
static unsigned char button;
|
||||
|
||||
/* map CTK colors to curses colors */
|
||||
static unsigned char ctk_color_map[8] = {
|
||||
COLOR_BLACK,
|
||||
COLOR_RED,
|
||||
COLOR_GREEN,
|
||||
COLOR_YELLOW,
|
||||
COLOR_BLUE,
|
||||
COLOR_MAGENTA,
|
||||
COLOR_CYAN,
|
||||
COLOR_WHITE
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned char
|
||||
map_color(unsigned char color)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = ctk_color_map[color & 0x0f];
|
||||
c |= ctk_color_map[(color >> 4) & 0x07] << 4;
|
||||
return c;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
ctrlhandler(int sig)
|
||||
{
|
||||
/* make sure we call console_exit() to leave the terminal in a clean state */
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
console_init(void)
|
||||
{
|
||||
/* mouse support is ncurses-specific */
|
||||
#ifdef NCURSES_MOUSE_VERSION
|
||||
mmask_t oldmask;
|
||||
#endif
|
||||
static unsigned char done;
|
||||
int bg, fg;
|
||||
|
||||
if(done) {
|
||||
return;
|
||||
}
|
||||
done = 1;
|
||||
|
||||
initscr();
|
||||
start_color();
|
||||
cbreak();
|
||||
|
||||
/* don't echo typed characters */
|
||||
noecho();
|
||||
/* disable return -> newline translation */
|
||||
nonl();
|
||||
|
||||
/* hide text cursor, CTK draws its own */
|
||||
curs_set(0);
|
||||
|
||||
intrflush(stdscr, FALSE);
|
||||
keypad(stdscr, TRUE);
|
||||
|
||||
#ifdef NCURSES_MOUSE_VERSION
|
||||
/* done here because ctk_mouse_init() is called before anyway */
|
||||
mousemask(ALL_MOUSE_EVENTS, &oldmask);
|
||||
#endif
|
||||
|
||||
screensize(&width, &height);
|
||||
|
||||
/* we must declare all possible color pairs */
|
||||
for(fg = 0; fg < 8; fg++) {
|
||||
for(bg = 0; bg < 8; bg++) {
|
||||
init_pair(MKPAIR(bg, fg), fg, bg);
|
||||
}
|
||||
}
|
||||
|
||||
/* set window title */
|
||||
putp("\033]0;Contiki\a");
|
||||
|
||||
/* don't block on read, just timeout 1ms */
|
||||
timeout(1);
|
||||
|
||||
/* make sure we return the terminal in a clean state */
|
||||
signal(SIGINT, ctrlhandler);
|
||||
atexit(console_exit);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
console_exit(void)
|
||||
{
|
||||
static unsigned char done;
|
||||
|
||||
if(done) {
|
||||
return;
|
||||
}
|
||||
done = 1;
|
||||
|
||||
revers(0);
|
||||
clrscr();
|
||||
gotoxy(0, 0);
|
||||
|
||||
endwin();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
console_resize(void)
|
||||
{
|
||||
unsigned char new_width;
|
||||
unsigned char new_height;
|
||||
|
||||
screensize(&new_width, &new_height);
|
||||
|
||||
if(new_width != width || new_height != height) {
|
||||
width = new_width;
|
||||
height = new_height;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
setcolor(void)
|
||||
{
|
||||
int bg, fg;
|
||||
int attrs;
|
||||
|
||||
fg = (color & 0x0F);
|
||||
bg = (color & 0xF0) >> 4;
|
||||
|
||||
attrs = COLOR_PAIR(MKPAIR(bg, fg));
|
||||
if(reversed) {
|
||||
attrs |= WA_REVERSE;
|
||||
}
|
||||
attrset(attrs);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
wherex(void)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
getyx(stdscr, y, x);
|
||||
(void)y;
|
||||
return (unsigned char)x;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
wherey(void)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
getyx(stdscr, y, x);
|
||||
(void)x;
|
||||
return (unsigned char)y;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
clrscr(void)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
bgcolor(unsigned char c)
|
||||
{
|
||||
c = map_color(c);
|
||||
color = ((c << 4) | (color & 0xF0));
|
||||
/* Presume this to be one of the first calls. */
|
||||
console_init();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
bordercolor(unsigned char c)
|
||||
{
|
||||
/* Presume this to be one of the first calls. */
|
||||
console_init();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
screensize(unsigned char *x, unsigned char *y)
|
||||
{
|
||||
int mx, my;
|
||||
|
||||
getmaxyx(stdscr, my, mx);
|
||||
*x = (unsigned char)mx;
|
||||
*y = (unsigned char)my;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
revers(unsigned char c)
|
||||
{
|
||||
reversed = c;
|
||||
setcolor();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
console_cputc(char c)
|
||||
{
|
||||
int ch = c;
|
||||
|
||||
/* usually ACS_* don't fit in a char */
|
||||
switch (c) {
|
||||
case CH_ULCORNER:
|
||||
ch = ACS_ULCORNER;
|
||||
break;
|
||||
case CH_LLCORNER:
|
||||
ch = ACS_LLCORNER;
|
||||
break;
|
||||
case CH_URCORNER:
|
||||
ch = ACS_URCORNER;
|
||||
break;
|
||||
case CH_LRCORNER:
|
||||
ch = ACS_LRCORNER;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
addch(ch);
|
||||
refresh();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
console_cputs(char *str)
|
||||
{
|
||||
addstr(str);
|
||||
refresh();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
cclear(unsigned char length)
|
||||
{
|
||||
hline(' ', length);
|
||||
refresh();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
chline(unsigned char length)
|
||||
{
|
||||
hline(ACS_HLINE, length);
|
||||
refresh();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
cvline(unsigned char length)
|
||||
{
|
||||
vline(ACS_VLINE, length);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
gotoxy(unsigned char x, unsigned char y)
|
||||
{
|
||||
move(y, x);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
cclearxy(unsigned char x, unsigned char y, unsigned char length)
|
||||
{
|
||||
gotoxy(x, y);
|
||||
cclear(length);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
chlinexy(unsigned char x, unsigned char y, unsigned char length)
|
||||
{
|
||||
gotoxy(x, y);
|
||||
chline(length);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
cvlinexy(unsigned char x, unsigned char y, unsigned char length)
|
||||
{
|
||||
gotoxy(x, y);
|
||||
cvline(length);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
cputsxy(unsigned char x, unsigned char y, char *str)
|
||||
{
|
||||
gotoxy(x, y);
|
||||
console_cputs(str);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
cputcxy(unsigned char x, unsigned char y, char c)
|
||||
{
|
||||
gotoxy(x, y);
|
||||
console_cputc(c);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
textcolor(unsigned char c)
|
||||
{
|
||||
color = map_color(c);
|
||||
setcolor();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
console_readkey(int k)
|
||||
{
|
||||
ctk_arch_key_t key;
|
||||
|
||||
key = (ctk_arch_key_t) k;
|
||||
/*fprintf(stderr, "key: %d\n", k); */
|
||||
switch (k) {
|
||||
#ifdef NCURSES_MOUSE_VERSION
|
||||
case KEY_MOUSE:
|
||||
{
|
||||
MEVENT event;
|
||||
|
||||
if(getmouse(&event) == OK) {
|
||||
xpos = event.x;
|
||||
ypos = event.y;
|
||||
button = event.bstate & BUTTON1_PRESSED
|
||||
|| event.bstate & BUTTON1_CLICKED
|
||||
|| event.bstate & BUTTON1_DOUBLE_CLICKED;
|
||||
/*fprintf(stderr, "mevent: %d: %d, %d, %d, %lx ; %d\n",
|
||||
event.id, event.x, event.y, event.z, event.bstate, button); */
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
case KEY_LEFT:
|
||||
key = CH_CURS_LEFT;
|
||||
break;
|
||||
case KEY_UP:
|
||||
key = CH_CURS_UP;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
key = CH_CURS_RIGHT;
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
key = CH_CURS_DOWN;
|
||||
break;
|
||||
case KEY_F(9): /* Gnome uses F10 as menu trigger now... */
|
||||
case KEY_F(10):
|
||||
key = CTK_CONF_MENU_KEY;
|
||||
break;
|
||||
case '\r':
|
||||
case KEY_ENTER:
|
||||
key = CH_ENTER;
|
||||
break;
|
||||
case 127:
|
||||
case KEY_BACKSPACE:
|
||||
case KEY_DC:
|
||||
key = CH_DEL;
|
||||
break;
|
||||
case KEY_BTAB:
|
||||
case KEY_CTAB:
|
||||
case KEY_PPAGE:
|
||||
case KEY_PREVIOUS:
|
||||
key = CTK_CONF_WIDGETUP_KEY;
|
||||
break;
|
||||
case KEY_NPAGE:
|
||||
case KEY_NEXT:
|
||||
key = CTK_CONF_WIDGETDOWN_KEY;
|
||||
break;
|
||||
case KEY_STAB:
|
||||
case KEY_HOME:
|
||||
case KEY_END:
|
||||
key = CTK_CONF_WINDOWSWITCH_KEY;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(key == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
memset(keys + keys_in, key, sizeof(ctk_arch_key_t));
|
||||
keys_in++;
|
||||
available++;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
console_read(void)
|
||||
{
|
||||
int k;
|
||||
|
||||
k = getch();
|
||||
if(k != ERR) {
|
||||
console_readkey(k);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
char
|
||||
ctk_arch_getkey(void)
|
||||
{
|
||||
char k;
|
||||
|
||||
console_read();
|
||||
k = keys[keys_out++];
|
||||
|
||||
available--;
|
||||
return k;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
ctk_arch_keyavail(void)
|
||||
{
|
||||
console_read();
|
||||
return available;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_mouse_init(void)
|
||||
{
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned short
|
||||
ctk_mouse_x(void)
|
||||
{
|
||||
console_read();
|
||||
return xpos;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned short
|
||||
ctk_mouse_y(void)
|
||||
{
|
||||
console_read();
|
||||
return ypos;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned short
|
||||
ctk_mouse_xtoc(unsigned short x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned short
|
||||
ctk_mouse_ytoc(unsigned short y)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
ctk_mouse_button(void)
|
||||
{
|
||||
console_read();
|
||||
return button;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_mouse_hide(void)
|
||||
{
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_mouse_show(void)
|
||||
{
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
66
platform/native/ctk/ctk-curses.h
Normal file
66
platform/native/ctk/ctk-curses.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: François Revol <revol@free.fr>
|
||||
*/
|
||||
#ifndef __CTK_CONSOLE_H__
|
||||
#define __CTK_CONSOLE_H__
|
||||
|
||||
#define cputc console_cputc
|
||||
#define cputs console_cputs
|
||||
|
||||
void console_init(void);
|
||||
void console_exit(void);
|
||||
unsigned char console_resize(void);
|
||||
|
||||
unsigned char wherex(void);
|
||||
unsigned char wherey(void);
|
||||
void clrscr(void);
|
||||
void bgcolor(unsigned char c);
|
||||
void bordercolor(unsigned char c);
|
||||
void screensize(unsigned char *x, unsigned char *y);
|
||||
void revers(unsigned char c);
|
||||
void console_cputc(char c);
|
||||
void console_cputs(char *str);
|
||||
void cclear(unsigned char length);
|
||||
void chline(unsigned char length);
|
||||
void cvline(unsigned char length);
|
||||
void gotoxy(unsigned char x, unsigned char y);
|
||||
void cclearxy(unsigned char x, unsigned char y, unsigned char length);
|
||||
void chlinexy(unsigned char x, unsigned char y, unsigned char length);
|
||||
void cvlinexy(unsigned char x, unsigned char y, unsigned char length);
|
||||
void cputsxy(unsigned char x, unsigned char y, char *str);
|
||||
void cputcxy(unsigned char x, unsigned char y, char c);
|
||||
void textcolor(unsigned char c);
|
||||
|
||||
char ctk_arch_getkey(void);
|
||||
unsigned char ctk_arch_keyavail(void);
|
||||
|
||||
#endif /* __CTK_CONSOLE_H__ */
|
@ -116,27 +116,29 @@ typedef unsigned short uip_stats_t;
|
||||
#define CTK_CONF_MENUS 0
|
||||
#endif /* PLATFORM_BUILD */
|
||||
|
||||
#define COLOR_BLACK (0)
|
||||
#define COLOR_BLUE (1)
|
||||
#define COLOR_GRAY (1 | 2 | 4)
|
||||
#define COLOR_CYAN (1 | 2 | 8)
|
||||
#define COLOR_YELLOW (2 | 4 | 8)
|
||||
#define COLOR_WHITE (1 | 2 | 4 | 8)
|
||||
#define CTK_COLOR_BLACK (0)
|
||||
#define CTK_COLOR_BLUE (1)
|
||||
#define CTK_COLOR_GRAY (1 | 2 | 4)
|
||||
#define CTK_COLOR_CYAN (1 | 2 | 8)
|
||||
#define CTK_COLOR_YELLOW (2 | 4 | 8)
|
||||
#define CTK_COLOR_WHITE (1 | 2 | 4 | 8)
|
||||
|
||||
#define BORDERCOLOR COLOR_BLACK
|
||||
#define SCREENCOLOR COLOR_BLACK
|
||||
#define BACKGROUNDCOLOR COLOR_BLACK
|
||||
#define WINDOWCOLOR_FOCUS COLOR_WHITE | COLOR_BLUE * 0x10
|
||||
#define WINDOWCOLOR COLOR_GRAY | COLOR_BLUE * 0x10
|
||||
#define DIALOGCOLOR COLOR_WHITE | COLOR_BLUE * 0x10
|
||||
#define WIDGETCOLOR_HLINK COLOR_CYAN | COLOR_BLUE * 0x10
|
||||
#define WIDGETCOLOR_FWIN COLOR_WHITE | COLOR_BLUE * 0x10
|
||||
#define WIDGETCOLOR COLOR_GRAY | COLOR_BLUE * 0x10
|
||||
#define WIDGETCOLOR_DIALOG COLOR_WHITE | COLOR_BLUE * 0x10
|
||||
#define WIDGETCOLOR_FOCUS COLOR_YELLOW | COLOR_BLUE * 0x10
|
||||
#define MENUCOLOR COLOR_WHITE | COLOR_BLUE * 0x10
|
||||
#define OPENMENUCOLOR COLOR_WHITE | COLOR_BLUE * 0x10
|
||||
#define ACTIVEMENUITEMCOLOR COLOR_YELLOW | COLOR_BLUE * 0x10
|
||||
#define COLOR_BG CTK_COLOR_BLUE
|
||||
|
||||
#define BORDERCOLOR CTK_COLOR_BLACK
|
||||
#define SCREENCOLOR CTK_COLOR_BLACK
|
||||
#define BACKGROUNDCOLOR CTK_COLOR_BLACK
|
||||
#define WINDOWCOLOR_FOCUS CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define WINDOWCOLOR CTK_COLOR_GRAY | COLOR_BG * 0x10
|
||||
#define DIALOGCOLOR CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR_HLINK CTK_COLOR_CYAN | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR_FWIN CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR CTK_COLOR_GRAY | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR_DIALOG CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define WIDGETCOLOR_FOCUS CTK_COLOR_YELLOW | COLOR_BG * 0x10
|
||||
#define MENUCOLOR CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define OPENMENUCOLOR CTK_COLOR_WHITE | COLOR_BG * 0x10
|
||||
#define ACTIVEMENUITEMCOLOR CTK_COLOR_YELLOW | COLOR_BG * 0x10
|
||||
|
||||
|
||||
#ifdef PLATFORM_BUILD
|
||||
|
Loading…
Reference in New Issue
Block a user