Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
High-Voltaged committed Feb 5, 2022
2 parents 9440eb3 + 3bf356a commit 23f8686
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 57 deletions.
Binary file removed client/data/img/user-avatar.png
Binary file not shown.
Binary file removed client/data/img/user-avatar2.png
Binary file not shown.
Binary file removed client/data/img/user-avatar3.png
Binary file not shown.
9 changes: 5 additions & 4 deletions client/inc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void build_chat_window();

//DRAW AVATAR
gboolean draw_user_avatar(GtkWidget *widget, cairo_t *cr, gpointer data);
gboolean draw_message_avatar(GtkWidget *widget, cairo_t *cr, gpointer data);
gboolean draw_chat_avatar(GtkWidget *widget, cairo_t *cr, gpointer data);

//AUTH
void build_login_menu();
Expand All @@ -74,7 +76,7 @@ void focus_out_repassword_field(GtkWidget *widget, gpointer data);
bool is_empty_field(GtkWidget *field, GtkWidget *notify_label);

//CHATLIST
void add_chatlist_item(int id, char *chat_name);
void add_chatlist_item(int id, char *chat_name, t_avatar_color avatar_color);
void build_chatlist_message(char *message);

//CHATLIST EVENTS
Expand All @@ -86,8 +88,7 @@ void set_current_chat(GtkWidget *chatlist_item);
void chatlist_item_on_click(GtkWidget *widget, gpointer data);
void activate_chat(GtkWidget *chatlist_item);

void build_start_messaging_label();////////////////////////////////
// void build_delete_chat_btn();/////////////?????????????????????????????
void build_start_messaging_label();

//SEARCH CHAT
void search_field_change_event(GtkWidget *widget, gpointer data);
Expand All @@ -107,7 +108,7 @@ void create_chat_btn_click(GtkWidget *widget, gpointer data);

//JOIN CHAT
void join_chat_event(GtkWidget *widget, GdkEventButton *event, gpointer data);
void add_join_chat_item(int id, char *chat_name);
void add_join_chat_item(int id, char *chat_name, t_avatar_color avatar_color);

//LOG OUT
void logout_btn_click(GtkWidget *widget, gpointer data);
Expand Down
2 changes: 1 addition & 1 deletion client/src/gui/build_chat_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void build_leftbar(GtkWidget *chat_screen)

GtkWidget *user_avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(user_avatar), 27, 27);
g_signal_connect(G_OBJECT(user_avatar), "draw", G_CALLBACK(draw_user_avatar), (gpointer)27); // Получить avatar пользовтеля
g_signal_connect(G_OBJECT(user_avatar), "draw", G_CALLBACK(draw_user_avatar), NULL); // Получить avatar пользовтеля
gtk_widget_set_halign(user_avatar, GTK_ALIGN_START);
gtk_widget_set_valign(user_avatar, GTK_ALIGN_CENTER);
gtk_box_pack_start(GTK_BOX(leftbar_footer), user_avatar, FALSE, FALSE, 0);
Expand Down
6 changes: 4 additions & 2 deletions client/src/gui/build_rightbar_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ void build_rightbar_chat() {
gtk_widget_set_hexpand(chat_header, TRUE);
add_class(chat_header, "chat_header");

GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
GtkWidget *avatar = gtk_drawing_area_new();
// GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_size_request(GTK_WIDGET(avatar), 42, 42);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_chat_avatar), (gpointer)utils->current_chat->avatar_color);
gtk_widget_set_halign(avatar, GTK_ALIGN_START);
gtk_widget_set_valign(avatar, GTK_ALIGN_CENTER);
gtk_box_pack_start(GTK_BOX(chat_header), avatar, FALSE, FALSE, 0);
add_class(avatar, "chatlist_item_avatar");
// add_class(avatar, "chatlist_item_avatar");

GtkWidget *chat_header_title = gtk_label_new(utils->current_chat->name);
gtk_widget_set_name(chat_header_title, "chat_header_title");
Expand Down
60 changes: 30 additions & 30 deletions client/src/gui/chatlist.c
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#include "../../inc/client.h"

static gboolean da_expose(GtkWidget *widget, cairo_t *cr, gpointer data)
{
char* a = "client/data/img/user_avatars/avatar4.png";
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(a, 42, 42, FALSE, NULL); // get_pixbuf_with_size(a, 34, 34);
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
g_object_unref(G_OBJECT(pixbuf));

double x = 0,
y = 0,
width = 42,
height = 42,
aspect = 1.0, /* aspect ratio */
corner_radius = height / 2.0; /* and corner curvature radius */
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);
if (widget) {}
return FALSE;
}

void add_chatlist_item(int id, char *chat_name)
// static gboolean da_expose(GtkWidget *widget, cairo_t *cr, gpointer data)
// {
// char* a = "client/data/img/user_avatars/avatar4.png";
// GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(a, 42, 42, FALSE, NULL); // get_pixbuf_with_size(a, 34, 34);
// gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
// g_object_unref(G_OBJECT(pixbuf));

// double x = 0,
// y = 0,
// width = 42,
// height = 42,
// aspect = 1.0, /* aspect ratio */
// corner_radius = height / 2.0; /* and corner curvature radius */
// 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);
// if (widget) {}
// return FALSE;
// }

void add_chatlist_item(int id, char *chat_name, t_avatar_color avatar_color)
{
GtkWidget *chatlist_container = get_widget_by_name_r(main_window, "chatlist");

Expand All @@ -55,7 +55,7 @@ void add_chatlist_item(int id, char *chat_name)
GtkWidget *avatar = gtk_drawing_area_new();
// GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_size_request(GTK_WIDGET(avatar), 42, 42);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(da_expose), NULL); // Получить avatar пользовтеля
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_chat_avatar), (gpointer)avatar_color);
gtk_widget_set_halign(avatar, GTK_ALIGN_START);
gtk_widget_set_valign(avatar, GTK_ALIGN_CENTER);
add_class(avatar, "chatlist_item_avatar");
Expand Down
5 changes: 3 additions & 2 deletions client/src/gui/chatlist_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ void update_chatlist()
clear_container(chatlist_container);

while (chatlist)
{
add_chatlist_item(chatlist->id, chatlist->name);
{

add_chatlist_item(chatlist->id, chatlist->name, chatlist->avatar_color);
chatlist = chatlist->next;
}

Expand Down
83 changes: 73 additions & 10 deletions client/src/gui/draw_avatar.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,82 @@
gboolean draw_user_avatar(GtkWidget *widget, cairo_t *cr, gpointer data)
{
if (widget) {}
// (void)data;
int size = (int)data;
// char* a = utils->current_user->avatar_path;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(utils->current_user->avatar_path, size, size, FALSE, NULL); // get_pixbuf_with_size(a, 34, 34);
(void)data;

GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(utils->current_user->avatar_path, 27, 27, FALSE, NULL); // get_pixbuf_with_size(a, 34, 34);
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; /* aspect ratio */
double corner_radius = height / 2.0; /* and corner curvature radius */
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_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) {}
int avatar_color = (int)data;

char *path = "client/data/img/user_avatars/avatar";
char *tmp = mx_strjoin(path, mx_itoa(avatar_color+1));
path = mx_strjoin(tmp, ".png");
mx_strdel(&tmp);

GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(path, 42, 42, FALSE, NULL);
mx_strdel(&path);
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
g_object_unref(G_OBJECT(pixbuf));

double x = 0,
y = 0,
width = size,
height = size,
aspect = 1.0, /* aspect ratio */
corner_radius = height / 2.0; /* and corner curvature radius */
double x = 0;
double y = 0;
double width = 42;
double height = 42;
double aspect = 1.0;
double corner_radius = height / 2.0;
double radius = corner_radius / aspect;
double degrees = 3.14159265358979 / 180.0;

Expand Down
8 changes: 4 additions & 4 deletions client/src/gui/join_chat_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void join_chat_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
(void)data;
}

void add_join_chat_item(int id, char *chat_name)
void add_join_chat_item(int id, char *chat_name, t_avatar_color avatar_color)
{
GtkWidget *chatlist_container = get_widget_by_name_r(main_window, "chatlist");

Expand All @@ -43,10 +43,10 @@ void add_join_chat_item(int id, char *chat_name)
add_class(chatlist_item_id, "hidden");
gtk_box_pack_start(GTK_BOX(chatlist_item), chatlist_item_id, FALSE, FALSE, 0);

// GtkWidget *avatar = gtk_drawing_area_new();
GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
GtkWidget *avatar = gtk_drawing_area_new();
// GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_size_request(GTK_WIDGET(avatar), 42, 42);
// g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar), (gpointer)(intptr_t)list->avatar); // Получить avatar пользовтеля
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_chat_avatar), (gpointer)avatar_color);
gtk_widget_set_halign(avatar, GTK_ALIGN_START);
gtk_widget_set_valign(avatar, GTK_ALIGN_CENTER);
add_class(avatar, "chatlist_item_avatar");
Expand Down
2 changes: 1 addition & 1 deletion client/src/gui/search_chats_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static void build_found_chats(t_chat *chat_list)

while (chat_list)
{
add_join_chat_item(chat_list->id, chat_list->name);
add_join_chat_item(chat_list->id, chat_list->name, chat_list->avatar_color);
chat_list = chat_list->next;
}
}
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_user_avatar), (gpointer)27); // Получить avatar пользовтеля
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_message_avatar), message); // Получить 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
2 changes: 1 addition & 1 deletion client/src/request_handlers/get_user_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ t_response_code handle_get_user_image(int user_id, char** avatar_path) {

// Reciving len of encoded image
int len_encoded = 0;
usleep(2000000);
usleep(500000);
if(recv(utils->server_fd, &len_encoded, sizeof(int), 0) == 0) {
printf("Error while receiving length\n");
mx_strdel(&file_path);
Expand Down
2 changes: 1 addition & 1 deletion server/src/api/handle_update_user_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void handle_update_user_image(const cJSON* data, t_server_utils* utils){

// Get len of encoded image
int len_encoded = 0;
usleep(2000000);
usleep(500000);
recv(utils->user->client_fd, &len_encoded, sizeof(int), 0);
//printf("%d\n", len_encoded);

Expand Down

0 comments on commit 23f8686

Please sign in to comment.