From 47ec6776398f3d4d142dff90fd2e40122fa7d711 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 17 Apr 2017 21:40:01 +0000 Subject: [PATCH] Half way there with the help screen --- gateway.c | 13 ++++++++- gui.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ gui.h | 8 ++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 gui.c create mode 100644 gui.h diff --git a/gateway.c b/gateway.c index d5baaf5..9977c8c 100644 --- a/gateway.c +++ b/gateway.c @@ -33,6 +33,7 @@ #include "server.h" #include "gateway.h" #include "config.h" +#include "gui.h" #define VERSION "V1.8.6" bool run = TRUE; @@ -161,6 +162,9 @@ struct TBandwidth }; int LEDCounts[2]; + +int help_win_displayed = 0; + pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER; #pragma pack(1) @@ -367,7 +371,10 @@ void ChannelPrintf(int Channel, int row, int column, const char *format, ... ) mvwaddstr( Config.LoRaDevices[Channel].Window, row, column, Buffer ); - wrefresh( Config.LoRaDevices[Channel].Window ); + if (! help_win_displayed) + { + wrefresh( Config.LoRaDevices[Channel].Window ); + } pthread_mutex_unlock( &var ); // unlock once you are done @@ -1773,6 +1780,10 @@ ProcessKeyPress( int ch ) case 'c': ReTune( Channel, -0.001 ); break; + case 'h': + help_win_displayed = 1; + gui_show_help(); + break; default: //LogMessage("KeyPress %d\n", ch); return; diff --git a/gui.c b/gui.c new file mode 100644 index 0000000..f017287 --- /dev/null +++ b/gui.c @@ -0,0 +1,81 @@ +#include "gui.h" + +extern int help_win_displayed; + +WINDOW *create_help_win(int height, int width, int starty, int startx); +void destroy_help_win(WINDOW *local_win); + +WINDOW *create_help_win(int height, int width, int starty, int startx) +{ WINDOW *local_win; + + local_win = newwin(height, width, starty, startx); + box(local_win, 0 , 0); /* 0, 0 gives default characters + * for the vertical and horizontal + * lines */ + wbkgd( local_win, COLOR_PAIR( 2 ) ); + wrefresh(local_win); /* Show that box */ + + return local_win; +} + +void destroy_help_win(WINDOW *local_win) +{ + /* box(local_win, ' ', ' '); : This won't produce the desired + * result of erasing the window. It will leave it's four corners + * and so an ugly remnant of window. + */ + wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); + /* The parameters taken are + * 1. win: the window on which to operate + * 2. ls: character to be used for the left side of the window + * 3. rs: character to be used for the right side of the window + * 4. ts: character to be used for the top side of the window + * 5. bs: character to be used for the bottom side of the window + * 6. tl: character to be used for the top left corner of the window + * 7. tr: character to be used for the top right corner of the window + * 8. bl: character to be used for the bottom left corner of the window + * 9. br: character to be used for the bottom right corner of the window + */ + wrefresh(local_win); + delwin(local_win); +} + +void gui_show_help () +{ + + WINDOW *help_win; + + int startx, starty, width, height; + int ch; + + height = 14; + width = 76; + starty = 1; /* Calculating for a center placement */ + startx = 2; /* of the window */ + help_win = create_help_win(height, width, starty, startx); + + while((ch = getch()) != 'c') + { + switch(ch) + { case KEY_LEFT: + destroy_help_win(help_win); + help_win = create_help_win(height, width, starty,--startx); + break; + case KEY_RIGHT: + destroy_help_win(help_win); + help_win = create_help_win(height, width, starty,++startx); + break; + case KEY_UP: + destroy_help_win(help_win); + help_win = create_help_win(height, width, --starty,startx); + break; + case KEY_DOWN: + destroy_help_win(help_win); + help_win = create_help_win(height, width, ++starty,startx); + break; + } + } + + help_win_displayed = 0; + +} diff --git a/gui.h b/gui.h new file mode 100644 index 0000000..7fe8f67 --- /dev/null +++ b/gui.h @@ -0,0 +1,8 @@ +#ifndef _GUI_H +#define _GUI_H + +#include + +void gui_show_help (); + +#endif