summaryrefslogtreecommitdiffstats
path: root/src/client/gui/main.cpp
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2020-12-09 16:12:53 +0000
committerJoursoir <chat@joursoir.net>2020-12-09 16:12:53 +0000
commit1baf22ad58cc1a9aa9089ca9a09fc80a453cb3c9 (patch)
tree16bc9aa1391fb76a9f7d540485dc9b949799dbc9 /src/client/gui/main.cpp
parent27cd9aded215835ffde615153600476bf9be2473 (diff)
downloadwant-chat-1baf22ad58cc1a9aa9089ca9a09fc80a453cb3c9.tar.gz
want-chat-1baf22ad58cc1a9aa9089ca9a09fc80a453cb3c9.tar.bz2
want-chat-1baf22ad58cc1a9aa9089ca9a09fc80a453cb3c9.zip
gui: receive msg from server to chat and move it
Diffstat (limited to 'src/client/gui/main.cpp')
-rw-r--r--src/client/gui/main.cpp46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/client/gui/main.cpp b/src/client/gui/main.cpp
index 3839454..211e020 100644
--- a/src/client/gui/main.cpp
+++ b/src/client/gui/main.cpp
@@ -9,9 +9,11 @@
const int spacing = 20;
const int border = 2;
+const int indent = 5;
const int chat_w = 695;
const int chat_h = 440;
+const int chat_line_h = 440 / lines_in_chat;
const int player_w = 225;
const int player_h = chat_h;
const int input_w = chat_w + border + spacing + border + player_w;
@@ -21,6 +23,7 @@ const int win_w = spacing + border + (input_w) + border + spacing;
const int win_h = spacing + border + chat_h + border +
spacing + border + input_h + border + spacing;
+
int main(int argc, char **argv)
{
Fl_Window *win = new Fl_Window(win_w, win_h, "WantChat");
@@ -28,52 +31,47 @@ int main(int argc, char **argv)
//
- BoxOutline ol_chat(spacing, spacing, chat_w+border*2, chat_h+border*2);
- ChatBaseOutput *chat = new ChatBaseOutput(
- spacing+border, spacing+border, chat_w, chat_h);
-
- // only for test, please not going to beat me :)
- /*char buffer[2048] = "";
- for(int i = 0; i < 17; i++)
- sprintf(buffer, "%s\n", buffer);
- sprintf(buffer, "%sWelcome to WantChat! What is your name?\n", buffer);
- chat->value(buffer);*/
+ BoxBackground ol_chat(spacing, spacing,
+ chat_w+border*2, chat_h+border*2);
+ BoxBackground ol_black(spacing+border, spacing+border,
+ chat_w, chat_h, 0, FL_BLACK);
+
+ ChatBaseOutput **chat = new ChatBaseOutput*[18];
+ int y = 0;
+ for(int i = 0 ; i < 18; i++) {
+ chat[i] = new ChatBaseOutput(spacing+border+indent,
+ spacing+border+y, chat_w-indent, chat_line_h);
+ y += chat_line_h;
+ }
//
int start_players_x = spacing + border + chat_w + border + spacing;
- BoxOutline ol_players(start_players_x, spacing, player_w+border*2, player_h+border*2);
+ BoxBackground ol_players(start_players_x, spacing, player_w+border*2, player_h+border*2);
ChatBaseOutput *players = new ChatBaseOutput(
start_players_x + border, spacing+border, player_w, player_h);
- // only for test, please not going to beat me :) (x2)
- /*char buffer1[1024] = "";
- for(int i = 0; i < 18; i++)
- sprintf(buffer1, "%sHackerspronickname\n", buffer1);
- players->value(buffer1);*/
-
//
+ Client *user = new Client(SERVER_IP, SERVER_PORT, chat);
+
int start_input_y = spacing + border + chat_h + border + spacing;
- BoxOutline ol_input(spacing, start_input_y, input_w+border*2, input_h+border*2);
- ChatInput *input = new ChatInput(spacing+border,
- start_input_y+border, input_w, input_h);
+ BoxBackground ol_input(spacing, start_input_y, input_w+border*2, input_h+border*2);
+ ChatInput input(spacing+border, start_input_y+border, input_w, input_h, 0, user);
//
win->end();
win->show();
- Client *user = new Client(SERVER_IP, SERVER_PORT, chat);
if(user->ConstuctorError()) {
- perror("server");
fl_choice("Server error", "Exit", 0, 0);
win->hide();
}
- while(Fl::wait())
+ while(user->Run())
{
- user->Run();
+ Fl::wait(0);
}
return 0;