diff options
author | Joursoir <chat@joursoir.net> | 2020-12-08 12:48:16 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2020-12-08 12:48:16 +0000 |
commit | 27cd9aded215835ffde615153600476bf9be2473 (patch) | |
tree | 0018a18a3d1b5891321d8218001c02128af82380 /src/client/gui | |
parent | f7bd80577164da7540ad93fb2fa93df38168133b (diff) | |
download | want-chat-27cd9aded215835ffde615153600476bf9be2473.tar.gz want-chat-27cd9aded215835ffde615153600476bf9be2473.tar.bz2 want-chat-27cd9aded215835ffde615153600476bf9be2473.zip |
create base class for all client, add some functionality to gui
Diffstat (limited to 'src/client/gui')
-rw-r--r-- | src/client/gui/Client.cpp | 6 | ||||
-rw-r--r-- | src/client/gui/Client.hpp | 18 | ||||
-rw-r--r-- | src/client/gui/Makefile | 4 | ||||
-rw-r--r-- | src/client/gui/OO_FLTK.hpp | 7 | ||||
-rw-r--r-- | src/client/gui/main.cpp (renamed from src/client/gui/client.cpp) | 51 |
5 files changed, 61 insertions, 25 deletions
diff --git a/src/client/gui/Client.cpp b/src/client/gui/Client.cpp new file mode 100644 index 0000000..2465ab7 --- /dev/null +++ b/src/client/gui/Client.cpp @@ -0,0 +1,6 @@ +#include "Client.hpp" + +void Client::ShowMessage(const char *msg) +{ + chat->value(msg); +}
\ No newline at end of file diff --git a/src/client/gui/Client.hpp b/src/client/gui/Client.hpp new file mode 100644 index 0000000..1ab7a84 --- /dev/null +++ b/src/client/gui/Client.hpp @@ -0,0 +1,18 @@ +#ifndef WC_GUI_CLIENT_H +#define WC_GUI_CLIENT_H + +#include "../ClientBase.hpp" +#include "OO_FLTK.hpp" + +class Client : public ClientBase { + ChatBaseOutput *chat; +public: + Client(const char* ip, int port, ChatBaseOutput *cb_out) + : ClientBase(ip, port), chat(cb_out) {} + ~Client() {} + + virtual void HandleActions() {} + virtual void ShowMessage(const char *msg); +}; + +#endif
\ No newline at end of file diff --git a/src/client/gui/Makefile b/src/client/gui/Makefile index 67ff3e2..a72e64d 100644 --- a/src/client/gui/Makefile +++ b/src/client/gui/Makefile @@ -1,7 +1,7 @@ CPP = g++ CPPFLAGS = -Wall -g -lfltk -SOURCES = client.cpp OO_FLTK.cpp -OBJECTS = $(SOURCES:.cpp=.o) +SOURCES = main.cpp OO_FLTK.cpp ../ClientBase.cpp Client.cpp +OBJECTS = main.o OO_FLTK.o ClientBase.o Client.o EXECUTABLE = client .PHONY: all clean diff --git a/src/client/gui/OO_FLTK.hpp b/src/client/gui/OO_FLTK.hpp index 2f52f97..b581321 100644 --- a/src/client/gui/OO_FLTK.hpp +++ b/src/client/gui/OO_FLTK.hpp @@ -1,3 +1,6 @@ +#ifndef WC_OOFLTK_H +#define WC_OOFLTK_H + #include <FL/Fl.H> #include <FL/Fl_Box.H> #include <FL/Fl_Input.H> @@ -23,4 +26,6 @@ class ChatBaseOutput : public Fl_Multiline_Output { public: ChatBaseOutput(int x, int y, int w, int h, const char *lb = 0); ~ChatBaseOutput() {} -};
\ No newline at end of file +}; + +#endif
\ No newline at end of file diff --git a/src/client/gui/client.cpp b/src/client/gui/main.cpp index d365288..3839454 100644 --- a/src/client/gui/client.cpp +++ b/src/client/gui/main.cpp @@ -1,10 +1,11 @@ +#include <cerrno> #include <FL/Fl.H> +#include <FL/fl_ask.H> #include <FL/Fl_Window.H> -#include <FL/Fl_Box.H> -#include <FL/Fl_Multiline_Output.H> -#include <FL/Fl_Input.H> #include "OO_FLTK.hpp" +#include "../../config.hpp" +#include "Client.hpp" const int spacing = 20; const int border = 2; @@ -26,48 +27,54 @@ int main(int argc, char **argv) win->color(FL_BLACK); // - BoxOutline *ol_chat = new BoxOutline( - spacing, spacing, chat_w+border*2, chat_h+border*2); + + 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 < 18; i++) - sprintf(buffer, "%sNickname: some text some text some text some text some te\n", buffer); - chat->value(buffer); + /*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);*/ // int start_players_x = spacing + border + chat_w + border + spacing; - BoxOutline *ol_players = new BoxOutline( - start_players_x, spacing, player_w+border*2, player_h+border*2); + BoxOutline 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] = ""; + /*char buffer1[1024] = ""; for(int i = 0; i < 18; i++) sprintf(buffer1, "%sHackerspronickname\n", buffer1); - players->value(buffer1); + players->value(buffer1);*/ // int start_input_y = spacing + border + chat_h + border + spacing; - BoxOutline *outline_input = new BoxOutline( - spacing, start_input_y, input_w+border*2, input_h+border*2); + 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); + // win->end(); win->show(); - return Fl::run(); -} -// 59 - 1 - 20 + 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()) + { + user->Run(); + } -/* I need this widgets: -- Button -- Inputbox -- Box */
\ No newline at end of file + return 0; +}
\ No newline at end of file |