summaryrefslogtreecommitdiffstats
path: root/src/client/clui.cpp
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2020-12-06 19:47:25 +0000
committerJoursoir <chat@joursoir.net>2020-12-06 19:47:25 +0000
commite99a03a838ddcf9eecadc10a7f71837afac3b99c (patch)
tree092ac919a8a8090df9c01536f5169e27952f7776 /src/client/clui.cpp
parent91d777da4f5baeac47b3097913b2407b45bc031e (diff)
downloadwant-chat-e99a03a838ddcf9eecadc10a7f71837afac3b99c.tar.gz
want-chat-e99a03a838ddcf9eecadc10a7f71837afac3b99c.tar.bz2
want-chat-e99a03a838ddcf9eecadc10a7f71837afac3b99c.zip
some changes in reg/auth; client: remove name in arguments
Diffstat (limited to 'src/client/clui.cpp')
-rw-r--r--src/client/clui.cpp187
1 files changed, 0 insertions, 187 deletions
diff --git a/src/client/clui.cpp b/src/client/clui.cpp
deleted file mode 100644
index 78fd226..0000000
--- a/src/client/clui.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-#include <string.h>
-#include <unistd.h>
-
-#include "clui.hpp"
-
-#define CHAT_HEIGHT 20
-#define CHAT_WIDTH 59
-#define PLAYERS_WIDTH 20
-#define PLAYERS_HEIGHT 20
-#define INPUT_HEIGHT 4
-#define INPUT_WIDTH 80
-
-Interface_wc::Interface_wc(int num_y, int num_x, int by,
- int bx, char ch) : ny(num_y), nx(num_x), beg_y(by),
- beg_x(bx), ch_line(ch)
-{
- w = newwin(ny, nx, beg_y, beg_x);
- box(w, ch_line, ch_line);
- this->Update();
-}
-
-void Interface_wc::Hide()
-{
- this->Clear(true);
- this->Update();
- this->Delete();
-}
-
-void Interface_wc::Clear(bool full)
-{
- werase(this->GetWindow());
- if(!full)
- box(this->GetWindow(), ch_line, ch_line);
-}
-
-////////////////////////////////////////////////////////////////////////
-
-ChatRoom::ChatRoom() : first(0)
-{
- chat = new Interface_wc(CHAT_HEIGHT, CHAT_WIDTH, 0, 0, 0);
- players = new Interface_wc(PLAYERS_HEIGHT, PLAYERS_WIDTH, 0, 60, 0);
- input = new Interface_wc(INPUT_HEIGHT, INPUT_WIDTH, 20, 0, 0);
- nodelay(input->GetWindow(), true);
- keypad(input->GetWindow(), true);
- i_nx = 1;
- i_ny = 1;
-}
-
-ChatRoom::~ChatRoom()
-{
- if(chat)
- delete chat;
- if(players)
- delete players;
- if(input)
- delete input;
-
- // #TODO:
- /* if(first) ... delete message */
-}
-
-void ChatRoom::AddMessage(char *msg, int type)
-{
- message *recent_msg = new message;
-
- int lines = 1;
- int len = strlen(msg);
- if(len > CHAT_WIDTH-2 + CHAT_WIDTH-2) lines = 3;
- else if(len > CHAT_WIDTH-2) lines = 2;
-
- strcpy(recent_msg->msg, msg);
- recent_msg->num_lines = lines;
- recent_msg->type = type;
-
- recent_msg->prev = first;
- first = recent_msg;
-
- ChatRedraw();
-}
-
-void ChatRoom::ChatRedraw()
-{
- if(!first)
- return;
-
- chat->Clear(false);
- int available_lines = CHAT_HEIGHT - 2;
- bool remove = false;
- message *tmp;
-
- message *last;
- for(message *m = first; m; m = m->prev) {
- if(available_lines-1 >= m->num_lines) {
- PrintMessage(available_lines, m);
- available_lines -= m->num_lines;
- last = m;
- }
- else {
- tmp = m;
- remove = true;
- break;
- }
- }
-
- if(remove) {
- last->prev = 0;
- while(tmp) {
- message *m = tmp;
- tmp = tmp->prev;
- delete m;
- }
- }
-
- SetInputCursor(i_ny, i_nx);
- chat->Update();
-}
-
-void ChatRoom::PrintMessage(int line, message *m)
-{
- WINDOW *win = this->chat->GetWindow();
- int need_print = m->num_lines;
- int maxlen_oneline = CHAT_WIDTH-2;
-
- while(need_print != 0) {
- if(m->type == system_msg) wattron(win, A_ITALIC);
- else wattron(win, A_BOLD);
-
- wmove(win, line-need_print+1, 1);
-
- char *tmp = new char[maxlen_oneline];
- int str = maxlen_oneline * (m->num_lines - need_print);
- memcpy(tmp, m->msg + str, maxlen_oneline);
-
- wprintw(win, tmp);
- need_print--;
-
- if(m->type == system_msg) wattroff(win, A_ITALIC);
- else wattroff(win, A_BOLD);
-
- delete[] tmp;
- }
-}
-
-bool ChatRoom::AddCharToSendMsg(char ch)
-{
- if(i_ny == 2 && i_nx == max_usermsg_len/2-1)
- return 0;
-
- mvwaddch(input->GetWindow(), i_ny, i_nx, ch);
- i_nx++;
- if(i_nx >= max_usermsg_len/2-1) {
- if(i_ny == 1) {
- i_ny++;
- i_nx = 1;
- }
- else if(i_ny == 2)
- i_nx--;
- wmove(input->GetWindow(), i_ny, i_nx);
- }
-
- input->Update();
- return 1;
-}
-
-bool ChatRoom::RemoveCharFromMsg()
-{
- if(i_ny == 1 && i_nx == 1)
- return 0;
-
- i_nx--;
- if(i_nx < 1) {
- i_ny--;
- i_nx = max_usermsg_len/2-1;
- }
- mvwaddch(input->GetWindow(), i_ny, i_nx, ' ');
- wmove(input->GetWindow(), i_ny, i_nx);
-
- input->Update();
- return 1;
-}
-
-void ChatRoom::SetInputCursor(int y, int x)
-{
- input->SetCursor(y, x);
- i_ny = y;
- i_nx = x;
-} \ No newline at end of file