From dacf6e0625d10ff47d2aad0ca8d705f90f030119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Wed, 22 Jul 2020 22:52:51 -0300 Subject: Update architecture --- src/client/window.cpp | 74 ++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 57 deletions(-) (limited to 'src/client/window.cpp') diff --git a/src/client/window.cpp b/src/client/window.cpp index 9e389fe..14128bf 100644 --- a/src/client/window.cpp +++ b/src/client/window.cpp @@ -1,16 +1,12 @@ #include -class Window { - Socket io; - char *view; +struct Window { int width; int height; - int cursor_x; - int cursor_y; - - public: + char *view; + int *line_ends; - Window() : cursor_x(0), cursor_y(0) { + Window() { initscr(); cbreak(); noecho(); @@ -20,66 +16,30 @@ class Window { getmaxyx(stdscr, height, width); view = new char[width * height]; - for (int i = 0; i < width * height; i++) { - view[i] = 0; - } + for (int i = 0; i < width * height; view[i++] = 0); - io.connect(); + line_ends = new int[height]; + for (int i = 0; i < height; line_ends[i++] = 0); } ~Window() { + delete[] view; + delete[] line_ends; endwin(); } - void redraw() { - clear(); - - int8_t msg[5]; - msg[0] = OP_SHOW; - encode2(width, msg, 1); - encode2(height, msg, 3); - io.send(msg, 5); - io.recv(view, width * height); - for (int i = 0; i < width * height; i++) { - printw("%c", view[i]); - } - move(cursor_y, cursor_x); - } - - char pos(size_t x, size_t y) { - return view[x + y * width]; + int get_input() { + return getch(); } - void move_left() { - int8_t mov[2]; - if (cursor_x > 0) { - mov[0] = OP_MOVE1; - mov[1] = -1; - io.send(mov, 2); - cursor_x--; - } + void set_cursor(int x, int y) { + move(y, x); } - void move_right() { - int8_t mov[2]; - if (cursor_x < width - 1 && pos(cursor_x + 1, cursor_y) != 0) { - mov[0] = OP_MOVE1; - mov[1] = 1; - io.send(mov, 2); - cursor_x++; + void update() { + clear(); + for (int i = 0; i < width * height; i++) { + printw("%c", view[i]); } } - - void delete_element() { - int8_t del[1]; - del[0] = OP_DELETE; - io.send(del, 1); - } - - void insert_element(int input) { - int8_t ins[2]; - ins[0] = OP_INSERT; - ins[1] = input; - io.send(ins, 2); - } }; -- cgit v1.2.3