From f27143165f1f3c2e47aaa65c4da24875e1639ceb Mon Sep 17 00:00:00 2001 From: Joursoir Date: Sat, 12 Dec 2020 12:44:08 +0000 Subject: some changes in work spec-symbols; clui: refactor; --- src/client/clui/Client.cpp | 21 ++++++++------------- src/client/clui/WindowInterface.cpp | 4 ++-- src/client/clui/clui.cpp | 26 +++++++++++++------------- 3 files changed, 23 insertions(+), 28 deletions(-) (limited to 'src/client/clui') diff --git a/src/client/clui/Client.cpp b/src/client/clui/Client.cpp index 9b697b6..fa89710 100644 --- a/src/client/clui/Client.cpp +++ b/src/client/clui/Client.cpp @@ -1,17 +1,11 @@ #include +#include "../dimensions_client.hpp" #include "Client.hpp" #include "clui.hpp" -#define CHAT_HEIGHT 20 -#define CHAT_WIDTH 59 -#define PLAYERS_WIDTH 20 -#define PLAYERS_HEIGHT 12 -#define TIPS_WIDTH 20 -#define TIPS_HEIGHT 8 -#define INPUT_HEIGHT 4 -#define INPUT_WIDTH 80 - +const int input_lines = 2; +const int input_columns = 78; const int key_enter = 10; const int key_escape = 27; const int key_backspace = 127; @@ -19,10 +13,11 @@ const int key_backspace = 127; Client::Client(const char* ip, int port) : ClientBase(ip, port), in_buf_used(0), exit_flag(false) { - chat = new WindowChat(CHAT_HEIGHT, CHAT_WIDTH, 0, 0, 0); - players = new WindowPlayers(PLAYERS_HEIGHT, PLAYERS_WIDTH, 0, 60, 0); - tips = new WindowTips(TIPS_HEIGHT, TIPS_WIDTH, PLAYERS_HEIGHT, 60, 0); - input = new WindowInput(INPUT_HEIGHT, INPUT_WIDTH, 20, 0, 0); + // y+2 and x+2 for outlines + chat = new WindowChat(CHAT_LINES+2, CHAT_COLUMNS+2, 0, 0, 0); + players = new WindowPlayers(PLAYERS_LINES+2, PLAYERS_COLUMNS+2, 0, CHAT_COLUMNS+2+1, 0); + tips = new WindowTips(TIPS_LINES+2, TIPS_COLUMNS+2, PLAYERS_LINES+2, CHAT_COLUMNS+2+1, 0); + input = new WindowInput(input_lines+2, input_columns+2, CHAT_LINES+2, 0, 0); } Client::~Client() diff --git a/src/client/clui/WindowInterface.cpp b/src/client/clui/WindowInterface.cpp index 336d3b1..ffa8bc5 100644 --- a/src/client/clui/WindowInterface.cpp +++ b/src/client/clui/WindowInterface.cpp @@ -22,9 +22,9 @@ void WindowInterface::SetCursor(int y, int x) void WindowInterface::Clear(bool full) { - werase(this->GetWindow()); + werase(GetWindow()); if(!full) - box(this->GetWindow(), ch_line, ch_line); + box(GetWindow(), ch_line, ch_line); } void WindowInterface::Update() diff --git a/src/client/clui/clui.cpp b/src/client/clui/clui.cpp index 7b32478..46d3821 100644 --- a/src/client/clui/clui.cpp +++ b/src/client/clui/clui.cpp @@ -2,6 +2,7 @@ #include #include +#include "../dimensions_client.hpp" #include "clui.hpp" WindowChat::~WindowChat() @@ -18,7 +19,7 @@ void WindowChat::AddMessage(const char *msg, const char spec_ch) message *recent_msg = new message; int len = strlen(msg); - int lines = (len / oneline_len) + 1; + int lines = (len / CHAT_COLUMNS) + 1; strcpy(recent_msg->text, msg); recent_msg->num_lines = lines; @@ -36,7 +37,7 @@ void WindowChat::ChatRedraw() return; Clear(false); - int available_lines = lines_in_chat; + int available_lines = CHAT_LINES; bool remove = false; message *tmp; @@ -75,9 +76,9 @@ void WindowChat::PrintMessage(int line, message *m) else wattron(w, A_BOLD); wmove(w, line-need_print+1, 1); - char *tmp = new char[oneline_len]; - int str = oneline_len * (m->num_lines - need_print); - memcpy(tmp, m->text + str, oneline_len); + char *tmp = new char[CHAT_COLUMNS]; + int str = CHAT_COLUMNS * (m->num_lines - need_print); + memcpy(tmp, m->text + str, CHAT_COLUMNS); wprintw(w, tmp); if(m->spec_char == SYSTEM_CHAR) wattroff(w, A_ITALIC); @@ -133,8 +134,8 @@ WindowTips::WindowTips(int num_y, int num_x, int by, int bx, char ch) : WindowInterface(num_y, num_x, by, bx, ch) { mvwprintw(w, num_y-7, 1, " Tips"); - mvwprintw(w, num_y-6, 1, "Online: "); - mvwprintw(w, num_y-5, 1, "Online room: "); + mvwprintw(w, TIPS_LINE_GONLINE, 1, "Online: "); + mvwprintw(w, TIPS_LINE_RONLINE, 1, "Online room: "); mvwprintw(w, num_y-4, 1, ""); mvwprintw(w, num_y-3, 1, "ESC - exit"); mvwprintw(w, num_y-2, 1, "ENTER - send msg"); @@ -144,15 +145,14 @@ WindowTips::WindowTips(int num_y, int num_x, int by, int bx, char ch) void WindowTips::SetGeneralOnline(const char *online) { // clear line: - wmove(w, ny-6, 1); + wmove(w, TIPS_LINE_GONLINE, 1); for(int i = 1; i < nx-1; i++) waddch(w, ' '); // print online char *str = new char[nx]; sprintf(str, "Online: %s", online); - mvwprintw(w, ny-6, 1, str); - Update(); + mvwprintw(w, TIPS_LINE_GONLINE, 1, str); delete[] str; Update(); } @@ -160,16 +160,16 @@ void WindowTips::SetGeneralOnline(const char *online) void WindowTips::SetRoomOnline(const char *online) { // clear line: - wmove(w, ny-5, 1); + wmove(w, TIPS_LINE_RONLINE, 1); for(int i = 1; i < nx-1; i++) waddch(w, ' '); // print online char *str = new char[nx]; sprintf(str, "Online room: %s", online); - mvwprintw(w, ny-5, 1, str); - Update(); + mvwprintw(w, TIPS_LINE_RONLINE, 1, str); delete[] str; + Update(); } -- cgit v1.2.3-18-g5258