diff options
author | Joursoir <chat@joursoir.net> | 2020-12-07 19:06:36 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2020-12-07 19:06:36 +0000 |
commit | f7bd80577164da7540ad93fb2fa93df38168133b (patch) | |
tree | 1cade2044219a324867607346a4c9611214a26f8 /src/client | |
parent | 9457a74c256bdf090667a5b19238cb5dfd7e031e (diff) | |
download | want-chat-f7bd80577164da7540ad93fb2fa93df38168133b.tar.gz want-chat-f7bd80577164da7540ad93fb2fa93df38168133b.tar.bz2 want-chat-f7bd80577164da7540ad93fb2fa93df38168133b.zip |
add objects level for use fltk
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/gui/Makefile | 2 | ||||
-rw-r--r-- | src/client/gui/OO_FLTK.cpp | 48 | ||||
-rw-r--r-- | src/client/gui/OO_FLTK.hpp | 26 | ||||
-rwxr-xr-x | src/client/gui/client | bin | 46288 -> 0 bytes | |||
-rw-r--r-- | src/client/gui/client.cpp | 60 |
5 files changed, 87 insertions, 49 deletions
diff --git a/src/client/gui/Makefile b/src/client/gui/Makefile index 2bc0969..67ff3e2 100644 --- a/src/client/gui/Makefile +++ b/src/client/gui/Makefile @@ -1,6 +1,6 @@ CPP = g++ CPPFLAGS = -Wall -g -lfltk -SOURCES = client.cpp +SOURCES = client.cpp OO_FLTK.cpp OBJECTS = $(SOURCES:.cpp=.o) EXECUTABLE = client diff --git a/src/client/gui/OO_FLTK.cpp b/src/client/gui/OO_FLTK.cpp new file mode 100644 index 0000000..9dc088d --- /dev/null +++ b/src/client/gui/OO_FLTK.cpp @@ -0,0 +1,48 @@ +#include "OO_FLTK.hpp" +#include "../../const_vars.hpp" + +BoxOutline::BoxOutline(int x, int y, int w, int h, const char *lb) + : Fl_Box(x, y, w, h, lb) +{ + box(FL_FLAT_BOX); + color(FL_WHITE); +} + +ChatInput::ChatInput(int x, int y, int w, int h, const char *lb) + : Fl_Input(x, y, w, h, lb) +{ + callback(CallbackFunction, 0); + when(FL_WHEN_ENTER_KEY | FL_WHEN_NOT_CHANGED); + + box(FL_FLAT_BOX); + color(FL_BLACK); + + cursor_color(FL_WHITE); + textfont(FL_COURIER); + textsize(20); + textcolor(FL_WHITE); + + maximum_size(max_usermsg_len); +} + +void ChatInput::SendMessage(void *user) +{ + if(strlen(value()) < 1) + return; + + printf("SendMessage\n"); + // send message to server + value(""); + take_focus(); +} + +ChatBaseOutput::ChatBaseOutput(int x, int y, int w, int h, const char *lb) + : Fl_Multiline_Output(x, y, w, h, lb) +{ + box(FL_FLAT_BOX); + color(FL_BLACK); + + textfont(FL_COURIER); + textsize(20); + textcolor(FL_WHITE); +}
\ No newline at end of file diff --git a/src/client/gui/OO_FLTK.hpp b/src/client/gui/OO_FLTK.hpp new file mode 100644 index 0000000..2f52f97 --- /dev/null +++ b/src/client/gui/OO_FLTK.hpp @@ -0,0 +1,26 @@ +#include <FL/Fl.H> +#include <FL/Fl_Box.H> +#include <FL/Fl_Input.H> +#include <FL/Fl_Multiline_Output.H> + +class BoxOutline : public Fl_Box { +public: + BoxOutline(int x, int y, int w, int h, const char *lb = 0); + ~BoxOutline() {} +}; + +class ChatInput : public Fl_Input { +public: + ChatInput(int x, int y, int w, int h, const char *lb = 0); + virtual ~ChatInput() {} + virtual void SendMessage(void *user); +private: + static void CallbackFunction(Fl_Widget *w, void *user) + { static_cast<ChatInput*>(w)->SendMessage(user); } +}; + +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 diff --git a/src/client/gui/client b/src/client/gui/client Binary files differdeleted file mode 100755 index 778511e..0000000 --- a/src/client/gui/client +++ /dev/null diff --git a/src/client/gui/client.cpp b/src/client/gui/client.cpp index 42407aa..d365288 100644 --- a/src/client/gui/client.cpp +++ b/src/client/gui/client.cpp @@ -2,7 +2,9 @@ #include <FL/Fl_Window.H> #include <FL/Fl_Box.H> #include <FL/Fl_Multiline_Output.H> -#include <FL/Fl_Multiline_Input.H> +#include <FL/Fl_Input.H> + +#include "OO_FLTK.hpp" const int spacing = 20; const int border = 2; @@ -12,7 +14,7 @@ const int chat_h = 440; const int player_w = 225; const int player_h = chat_h; const int input_w = chat_w + border + spacing + border + player_w; -const int input_h = 55; +const int input_h = 40; // 55 const int win_w = spacing + border + (input_w) + border + spacing; const int win_h = spacing + border + chat_h + border + @@ -24,76 +26,38 @@ int main(int argc, char **argv) win->color(FL_BLACK); // - - Fl_Box *outline_chat = new Fl_Box( + BoxOutline *ol_chat = new BoxOutline( spacing, spacing, chat_w+border*2, chat_h+border*2); - outline_chat->box(FL_FLAT_BOX); - outline_chat->color(FL_WHITE); - - - Fl_Multiline_Output *box_chat = new Fl_Multiline_Output( + ChatBaseOutput *chat = new ChatBaseOutput( spacing+border, spacing+border, chat_w, chat_h); - box_chat->box(FL_FLAT_BOX); - box_chat->color(FL_BLACK); - - box_chat->textfont(FL_COURIER); - box_chat->textsize(20); - box_chat->textcolor(FL_WHITE); // 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); - } - box_chat->value(buffer); + chat->value(buffer); // int start_players_x = spacing + border + chat_w + border + spacing; - Fl_Box *outline_players = new Fl_Box( + BoxOutline *ol_players = new BoxOutline( start_players_x, spacing, player_w+border*2, player_h+border*2); - outline_players->box(FL_FLAT_BOX); - outline_players->color(FL_WHITE); - - - Fl_Multiline_Output *box_players = new Fl_Multiline_Output( + ChatBaseOutput *players = new ChatBaseOutput( start_players_x + border, spacing+border, player_w, player_h); - box_players->box(FL_FLAT_BOX); - box_players->color(FL_BLACK); - - box_players->textfont(FL_COURIER); - box_players->textsize(20); - box_players->textcolor(FL_WHITE); // 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); - } - box_players->value(buffer1); + players->value(buffer1); // int start_input_y = spacing + border + chat_h + border + spacing; - Fl_Box *outline_input = new Fl_Box( + BoxOutline *outline_input = new BoxOutline( spacing, start_input_y, input_w+border*2, input_h+border*2); - outline_input->box(FL_FLAT_BOX); - outline_input->color(FL_WHITE); - - - Fl_Multiline_Input *box_input = new Fl_Multiline_Input(spacing+border, + ChatInput *input = new ChatInput(spacing+border, start_input_y+border, input_w, input_h); - - box_input->box(FL_FLAT_BOX); - box_input->color(FL_BLACK); - - box_input->cursor_color(FL_WHITE); - box_input->textfont(FL_COURIER); - box_input->textsize(20); - box_input->textcolor(FL_WHITE); - // win->end(); |