Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroslavChuiko committed Feb 6, 2022
1 parent c05eb04 commit f84deca
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 48 deletions.
Binary file added client/data/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified client/data/img/send.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed client/data/img/send2.png
Binary file not shown.
Binary file removed client/data/img/send3.png
Binary file not shown.
2 changes: 1 addition & 1 deletion client/data/styles/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

.input-msg_send-btn {
border-radius: 50%;
background-image: url("../img/send3.png");
background-image: url("../img/send.png");
background-size: 25px 25px;
background-position: 50% 50%;
background-repeat: no-repeat;
Expand Down
3 changes: 2 additions & 1 deletion client/inc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ t_avatar_color get_avatar_color();
void handle_error(const char* error);

//GUI UTILS
void load_css();
void on_crossing (GtkWidget *widget, GdkEventCrossing *event);
void add_class(GtkWidget *widget, char *class_name);
void remove_class(GtkWidget *widget, char *class_name);
Expand All @@ -52,7 +53,7 @@ char *ellipsis_str(const char *str, int overflow_len);
GtkWidget* create_new_window(char *title, int width, int height, bool resizable);
GtkWidget *create_popup_window(int width, int height);
void destroy_popup_window(GtkWidget *widget, gpointer chat_screen);
void build_authorizatioin_window();
void build_authorization_window();
void build_chat_window();

//DRAW AVATAR
Expand Down
10 changes: 4 additions & 6 deletions client/src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ int main(int argc, char **argv) {

gtk_init(&argc, &argv);

// CSS
GtkCssProvider *styles = gtk_css_provider_new();
gtk_css_provider_load_from_path(styles, "client/data/styles/main.css", NULL);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(styles), GTK_STYLE_PROVIDER_PRIORITY_USER);
//
load_css();
build_authorization_window();

build_authorizatioin_window();
// gtk_window_set_icon_from_file(GTK_WINDOW(main_window), "client/data/img/logo.png", NULL);
// gtk_window_set_icon_name(GTK_WINDOW(main_window), "UChat");

pthread_create(&utils->th_reader, NULL, handle_server_updates, utils);

Expand Down
4 changes: 2 additions & 2 deletions client/src/gui/build_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ GtkWidget* create_new_window(char *title, int width, int height, bool resizable)
return window;
}

void build_authorizatioin_window()
void build_authorization_window()
{
if (main_window)
gtk_widget_destroy(main_window);

main_window = create_new_window("login", 500, 0, false);
main_window = create_new_window("Authorization", 500, 0, false);

GtkWidget* main_area = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_name(main_area, "main_area");
Expand Down
2 changes: 1 addition & 1 deletion client/src/gui/delete_account_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void delete_account_btn_click(GtkWidget *widget, gpointer data) {

if (handle_delete_account_request() == R_SUCCESS) {
client_cleanup(false);
build_authorizatioin_window();
build_authorization_window();
}

}
Expand Down
30 changes: 0 additions & 30 deletions client/src/gui/draw_avatar.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
gboolean draw_user_avatar(GtkWidget *widget, cairo_t *cr, gpointer data)
{
if (widget) {}
// (void)data;
int avatar_color = (int)data;

char *path = "client/data/img/user_avatars/avatar";
Expand Down Expand Up @@ -36,35 +35,6 @@ gboolean draw_user_avatar(GtkWidget *widget, cairo_t *cr, gpointer data)
return FALSE;
}

// gboolean draw_message_avatar(GtkWidget *widget, cairo_t *cr, gpointer data)
// {
// if (widget) {}
// t_msg *message = (t_msg*)data;

// GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(message->avatar_path, 27, 27, FALSE, NULL);
// gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
// g_object_unref(G_OBJECT(pixbuf));

// double x = 0;
// double y = 0;
// double width = 27;
// double height = 27;
// double aspect = 1.0;
// double corner_radius = height / 2.0;
// double radius = corner_radius / aspect;
// double degrees = 3.14159265358979 / 180.0;

// cairo_new_sub_path (cr);
// cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
// cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
// cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
// cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
// cairo_close_path (cr);

// cairo_fill(cr);
// return FALSE;
// }

gboolean draw_chat_avatar(GtkWidget *widget, cairo_t *cr, gpointer data)
{
if (widget) {}
Expand Down
7 changes: 7 additions & 0 deletions client/src/gui/gui_utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "../../inc/client.h"

void load_css()
{
GtkCssProvider *styles = gtk_css_provider_new();
gtk_css_provider_load_from_path(styles, "client/data/styles/main.css", NULL);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(styles), GTK_STYLE_PROVIDER_PRIORITY_USER);
}

void add_class(GtkWidget *widget, char *class_name)
{
GtkStyleContext *context = gtk_widget_get_style_context(widget);
Expand Down
7 changes: 1 addition & 6 deletions client/src/gui/logout_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ void logout_btn_click(GtkWidget *widget, gpointer data)
handle_logout_request(false);
client_cleanup(false);
pthread_create(&utils->th_reader, NULL, handle_server_updates, NULL);
build_authorizatioin_window();
build_authorization_window();
}

// void cancel_btn_click(GtkWidget *widget, gpointer data) {
// GtkWidget *toplevel = gtk_widget_get_toplevel(widget);
// gtk_widget_destroy(toplevel);
// }

void build_confirm_logout_window(GtkWidget *widget, gpointer data) {
if(widget){}
(void)data;
Expand Down
2 changes: 1 addition & 1 deletion client/src/gui/update_chat_field.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void add_message(t_msg *message) {

GtkWidget *avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(avatar), 27, 27);
// g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_message_avatar), message->); // Получить avatar пользовтеля
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_user_avatar), (gpointer)message->avatar_color); // Получить avatar пользовтеля
gtk_widget_set_halign(avatar, cur_user ? GTK_ALIGN_START : GTK_ALIGN_END);
gtk_widget_set_valign(avatar, GTK_ALIGN_START);
if (!cur_user) {
Expand Down

0 comments on commit f84deca

Please sign in to comment.