summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-06-06 16:48:29 +0200
committerlonkaars <loek@pipeframe.xyz>2022-06-06 16:48:29 +0200
commita909440c7671075127a98cffd7f1714114fc17bd (patch)
treee39ea84db612d7293c0011a23965b94026ce4337
parent6f4f05707740e43182317eb6d3d69a43f52815b2 (diff)
use pads for body and tab bar
-rw-r--r--client/setup.c7
-rw-r--r--client/ui.c18
-rw-r--r--client/ui.h5
-rw-r--r--client/ui_dirc.c28
4 files changed, 42 insertions, 16 deletions
diff --git a/client/setup.c b/client/setup.c
index fd37c13..22f7e4c 100644
--- a/client/setup.c
+++ b/client/setup.c
@@ -39,6 +39,13 @@ void w2_client_setup(int argc, char **argv) {
w2_send_info();
+ g_w2_ui_width = getmaxx(g_w2_ui_win);
+ g_w2_ui_height = getmaxy(g_w2_ui_win);
+
+ g_w2_ui_pad_tabbar = newpad(1, g_w2_ui_width);
+ g_w2_ui_pad_body = newpad(g_w2_ui_height - 5, g_w2_ui_width);
+ scrollok(g_w2_ui_pad_body, true);
+
// check endianness
g_w2_endianness = *_ptest;
}
diff --git a/client/ui.c b/client/ui.c
index 3835126..7731215 100644
--- a/client/ui.c
+++ b/client/ui.c
@@ -11,11 +11,23 @@
#include "ui.h"
WINDOW *g_w2_ui_win;
+WINDOW *g_w2_ui_pad_tabbar;
+WINDOW *g_w2_ui_pad_body;
unsigned int g_w2_ui_width = 0;
unsigned int g_w2_ui_height = 0;
void (*g_w2_ui_current_tab)(bool first) = &w2_ui_dirc;
void (*g_w2_ui_last_tab)(bool first) = NULL;
+void w2_wmvaddstr(WINDOW *win, unsigned int y, unsigned int x, char *str) {
+ wmove(win, y, x);
+ waddstr(win, str);
+}
+
+void w2_wmvaddnstr(WINDOW *win, unsigned int y, unsigned int x, char *str, unsigned int len) {
+ wmove(win, y, x);
+ waddnstr(win, str, len);
+}
+
void w2_ui_main() {
g_w2_ui_width = getmaxx(g_w2_ui_win);
g_w2_ui_height = getmaxy(g_w2_ui_win);
@@ -30,7 +42,9 @@ void w2_ui_paint() {
g_w2_ui_last_tab = g_w2_ui_current_tab;
w2_timer_start(W2_TIMER_UPDATE);
}
- refresh();
+ prefresh(g_w2_ui_pad_tabbar, 0, 0, 2, 0, 2, g_w2_ui_width - 1);
+ prefresh(g_w2_ui_pad_body, 0, 0, 4, 0, g_w2_ui_height - 2, g_w2_ui_width - 1);
+ // wrefresh(g_w2_ui_win);
}
void w2_ui_paint_statusbar() {
@@ -67,5 +81,5 @@ void w2_ui_paint_statusbar() {
void w2_ui_paint_tabbar() {
char temp[g_w2_ui_width];
sprintf(temp, "-- tab bar here --");
- mvaddstr(2, g_w2_ui_width / 2 - strlen(temp) / 2, temp);
+ w2_wmvaddstr(g_w2_ui_pad_tabbar, 0, g_w2_ui_width / 2 - strlen(temp) / 2, temp);
}
diff --git a/client/ui.h b/client/ui.h
index 0d375de..a4c4ed1 100644
--- a/client/ui.h
+++ b/client/ui.h
@@ -6,6 +6,8 @@
#define W2_UI_UPDATE_FPS (60)
extern WINDOW *g_w2_ui_win;
+extern WINDOW *g_w2_ui_pad_tabbar;
+extern WINDOW *g_w2_ui_pad_body;
extern unsigned int g_w2_ui_width;
extern unsigned int g_w2_ui_height;
extern void (*g_w2_ui_current_tab)(bool first);
@@ -25,3 +27,6 @@ void w2_ui_paint_statusbar();
void w2_ui_paint_tabbar();
void w2_ui_dirc(bool first);
+
+void w2_wmvaddstr(WINDOW *win, unsigned int y, unsigned int x, char *str);
+void w2_wmvaddnstr(WINDOW *win, unsigned int y, unsigned int x, char *str, unsigned int len);
diff --git a/client/ui_dirc.c b/client/ui_dirc.c
index ed69cd2..c23134b 100644
--- a/client/ui_dirc.c
+++ b/client/ui_dirc.c
@@ -50,7 +50,7 @@ void w2_ui_bar_graph(unsigned int y, unsigned int x, unsigned int width, double
temp[width - 1] = '|';
for (unsigned int i = 0; i < width - 2; i++) temp[i + 1] = i < width * value ? '*' : ' ';
- mvaddnstr(y, x, temp, width);
+ w2_wmvaddnstr(g_w2_ui_pad_body, y, x, temp, width);
}
void w2_ui_bar_graph_pm(unsigned int y, unsigned int x, unsigned int width, double value) {
@@ -67,23 +67,23 @@ void w2_ui_bar_graph_pm(unsigned int y, unsigned int x, unsigned int width, doub
temp[i + 1] = i > hw ? ' ' : (hw - i) < -(hw * value) ? '*' : ' ';
}
- mvaddnstr(y, x, temp, width + 2);
+ w2_wmvaddnstr(g_w2_ui_pad_body, y, x, temp, width + 2);
}
void w2_ui_dirc_paint(int left, int right) {
- mvaddstr(4, 0, "left drive: ");
- w2_ui_bar_graph_pm(4, 13, g_w2_ui_width - 13, (double)left / 255);
- mvaddstr(5, 0, "right drive: ");
- w2_ui_bar_graph_pm(5, 13, g_w2_ui_width - 13, (double)right / 255);
+ w2_wmvaddstr(g_w2_ui_pad_body, 0, 0, "left drive: ");
+ w2_ui_bar_graph_pm(0, 13, g_w2_ui_width - 13, (double)left / 255);
+ w2_wmvaddstr(g_w2_ui_pad_body, 1, 0, "right drive: ");
+ w2_ui_bar_graph_pm(1, 13, g_w2_ui_width - 13, (double)right / 255);
- mvaddstr(7, 0,
- " controls:\n"
- "\n"
- " <q> <w> <e> forward\n"
- " <a> <s> <d> backward\n"
- "left both right\n"
- "\n"
- "<space> send dirc mode command");
+ w2_wmvaddstr(g_w2_ui_pad_body, 3, 0,
+ " controls:\n"
+ "\n"
+ " <q> <w> <e> forward\n"
+ " <a> <s> <d> backward\n"
+ "left both right\n"
+ "\n"
+ "<space> send dirc mode command");
}
void w2_ui_dirc(bool first) {