Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Now can send stickers and embed files(images, yet). New look of text …
Browse files Browse the repository at this point in the history
…messages. Alpha 0.7.4
  • Loading branch information
Pavlo Litovka committed Dec 25, 2020
1 parent 3394956 commit fb29e48
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 77 deletions.
17 changes: 17 additions & 0 deletions client/data/css/msg_screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@
font-weight: 400;
font-size: 13px;
}
#msg_name
{
font-family: 'Uni Sans', 'Helvetica Neue Light', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-weight: 400;
font-size: 10px;
margin-right: 18px;
margin-left: 18px;
margin-bottom: 2px;
}
#single
{
border-radius: 13px;
Expand All @@ -124,6 +133,14 @@
border-radius: 10px;
padding: 6px;
}
#sticker_body
{
margin: 4px 0 4px 0;
}
#embedded_body
{
margin: 4px 0 4px 0;
}
#hidden
{
opacity: 0;
Expand Down
4 changes: 4 additions & 0 deletions client/data/css/themes/dark/msg_dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
{
color: rgba(230, 230, 233, 0.85);
}
#msg_name
{
color: #d4d4d4;
}
#single
{
background-color: rgba(53, 53, 53, 0);
Expand Down
4 changes: 4 additions & 0 deletions client/data/css/themes/default/msg_default.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
{
color: #657dc9;
}
#msg_name
{
color: #657dc9;
}
#nickname
{
color: rgba(101, 124, 201, 0.85);
Expand Down
4 changes: 4 additions & 0 deletions client/data/css/themes/light/msg_light.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
{
color: rgba(52, 55, 64, 0.85);
}
#msg_name
{
color: #343740;
}
#single
{
background-color: rgba(235, 235, 235, 0);
Expand Down
12 changes: 12 additions & 0 deletions client/inc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ struct s_chat // Selected user in chatlist
struct s_chat *next;
} t_chat;

struct
{
GtkWidget *main;
GtkWidget *embedded_view;
} t_msg;

//-------> Settings
struct
Expand Down Expand Up @@ -231,10 +236,17 @@ gboolean draw_event_pokemon(GtkWidget *widget, cairo_t *cr, int size);
gboolean draw_event_avatar_list(GtkWidget *widget, cairo_t *cr, char* path);
gboolean draw_event_status(GtkWidget *widget, cairo_t *cr, int size);
gboolean draw_event_sticker_list(GtkWidget *widget, cairo_t *cr, char* path);
gboolean draw_event_sticker(GtkWidget *widget, cairo_t *cr, char* path);
gboolean draw_event_embedded(GtkWidget *widget, cairo_t *cr, char* path);
gboolean draw_event_embedded_full(GtkWidget *widget, cairo_t *cr, char* path);

GtkWidget *create_chatlist(t_chat_list* list);
void new_outgoing_message(GtkWidget *messages_block);
void new_incoming_message(GtkWidget *messages_block);
void new_outgoing_sticker(GtkWidget *messages_block, int sticker_num);
void new_incoming_sticker(GtkWidget *messages_block, int sticker_num);
void new_outgoing_embedded(GtkWidget *messages_block, char* path);
void new_incoming_embedded(GtkWidget *messages_block, char* path);

// Events
void event_enter_notify(GtkWidget *widget);
Expand Down
2 changes: 1 addition & 1 deletion client/src/client_auto.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ void test_autofill()
t_account.avatar_chosen = 54;
t_account.avatar = get_avatar_by_number(t_account.avatar_chosen);

t_application.app = "PokeChat alpha 0.7.2";
t_application.app = "PokeChat alpha 0.7.4";
t_application.user = getenv("USER");
}
192 changes: 171 additions & 21 deletions client/src/creator_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,214 @@ void new_outgoing_message(GtkWidget *messages_block)
}

GtkWidget *message_body = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
//gtk_widget_set_size_request(messages_body, CHAT_W, 100);
gtk_widget_set_name(GTK_WIDGET(message_body), "messages_body");
gtk_box_pack_start(GTK_BOX(messages_block), message_body, FALSE, FALSE, 0);

GtkWidget *avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(avatar), 35, 35);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar_account), (int*)35);
gtk_box_pack_end(GTK_BOX(message_body), avatar, FALSE, FALSE, 0);

GtkWidget *name_message_block = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
gtk_box_pack_end(GTK_BOX(message_body), name_message_block, FALSE, FALSE, 0);
GtkWidget *nickname = gtk_label_new(t_account.username);
gtk_widget_set_name(GTK_WIDGET(nickname), "msg_name");
gtk_widget_set_halign(GTK_WIDGET(nickname), GTK_ALIGN_END);
gtk_box_pack_start(GTK_BOX(name_message_block), nickname, FALSE, FALSE, 0);

GtkWidget *message = gtk_label_new(msg_data.content);
gtk_widget_set_name(GTK_WIDGET(message), "message");
gtk_label_set_line_wrap(GTK_LABEL(message), TRUE);
gtk_label_set_line_wrap_mode(GTK_LABEL(message), PANGO_WRAP_WORD_CHAR);
gtk_label_set_max_width_chars(GTK_LABEL(message), 50);
// GtkWidget *nickname = gtk_frame_new("PAXANDDOS");
// gtk_frame_set_label_widget (GTK_FRAME(nickname), message); Не работает
GtkWidget *name_time_block = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
gtk_box_pack_end(GTK_BOX(name_message_block), message, FALSE, FALSE, 0);

GtkWidget *time_label = gtk_label_new(mx_str_gettime());
GtkWidget *nickname = gtk_label_new(t_account.username);
gtk_widget_set_name(GTK_WIDGET(time_label), "name_time");
gtk_widget_set_name(GTK_WIDGET(nickname), "name_time");
gtk_box_pack_start(GTK_BOX(name_time_block), time_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_time_block), nickname, FALSE, FALSE, 0);
gtk_widget_set_valign(GTK_WIDGET(name_time_block), GTK_ALIGN_CENTER);
gtk_widget_set_valign(GTK_WIDGET(time_label), GTK_ALIGN_CENTER);
gtk_box_pack_end(GTK_BOX(message_body), time_label, FALSE, FALSE, 0);

gtk_box_pack_end(GTK_BOX(message_body), message, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(message_body), name_time_block, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(messages_block), message_body, FALSE, FALSE, 0);
gtk_container_set_focus_vadjustment(GTK_CONTAINER(message_body), NULL);
gtk_widget_show_all(GTK_WIDGET(message_body));
}

void new_incoming_message(GtkWidget *messages_block)
{
GtkWidget *message_body = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
//gtk_widget_set_size_request(messages_body, CHAT_W, 100);
gtk_widget_set_name(GTK_WIDGET(message_body), "messages_body");
gtk_box_pack_start(GTK_BOX(messages_block), message_body, FALSE, FALSE, 0);

GtkWidget *avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(avatar), 35, 35);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar), (int*)35);
gtk_box_pack_start(GTK_BOX(message_body), avatar, FALSE, FALSE, 0);

GtkWidget *name_message_block = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
gtk_box_pack_start(GTK_BOX(message_body), name_message_block, FALSE, FALSE, 0);
GtkWidget *nickname = gtk_label_new("PAXANDDOS");
gtk_widget_set_name(GTK_WIDGET(nickname), "msg_name");
gtk_widget_set_halign(GTK_WIDGET(nickname), GTK_ALIGN_START);
gtk_box_pack_start(GTK_BOX(name_message_block), nickname, FALSE, FALSE, 0);

GtkWidget *message = gtk_label_new(msg_data.content);
gtk_widget_set_name(GTK_WIDGET(message), "message");
gtk_label_set_line_wrap(GTK_LABEL(message), TRUE);
gtk_label_set_line_wrap_mode(GTK_LABEL(message), PANGO_WRAP_WORD_CHAR);
gtk_label_set_max_width_chars(GTK_LABEL(message), 50);
// GtkWidget *nickname = gtk_frame_new("PAXANDDOS");
// gtk_frame_set_label_widget (GTK_FRAME(nickname), message); Не работает
gtk_box_pack_start(GTK_BOX(name_message_block), message, FALSE, FALSE, 0);

GtkWidget *time_label = gtk_label_new(mx_str_gettime());
gtk_widget_set_name(GTK_WIDGET(time_label), "name_time");
gtk_widget_set_valign(GTK_WIDGET(time_label), GTK_ALIGN_CENTER);
gtk_box_pack_start(GTK_BOX(message_body), time_label, FALSE, FALSE, 0);

gtk_widget_show_all(GTK_WIDGET(message_body));
}

void new_outgoing_sticker(GtkWidget *messages_block, int sticker_num)
{
char *path = "client/data/stickers/";
path = mx_strjoin(path, mx_itoa(sticker_num));
path = mx_strjoin(path, ".png");

GtkWidget *sticker_body = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
gtk_widget_set_name(GTK_WIDGET(sticker_body), "sticker_body");
gtk_box_pack_start(GTK_BOX(messages_block), sticker_body, FALSE, FALSE, 0);

GtkWidget *avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(avatar), 35, 35);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar_account), (int*)35);
gtk_box_pack_end(GTK_BOX(sticker_body), avatar, FALSE, FALSE, 0);

GtkWidget *sticker = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(sticker), 200, 200);
g_signal_connect(G_OBJECT(sticker), "draw", G_CALLBACK(draw_event_sticker), (char*)path);
gtk_box_pack_end(GTK_BOX(sticker_body), sticker, FALSE, FALSE, 0);

GtkWidget *name_time_block = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
GtkWidget *time_label = gtk_label_new(mx_str_gettime());
GtkWidget *nickname = gtk_label_new("PAXANDDOS");
GtkWidget *nickname = gtk_label_new(t_account.username);
gtk_widget_set_name(GTK_WIDGET(time_label), "name_time");
gtk_widget_set_name(GTK_WIDGET(nickname), "name_time");
gtk_box_pack_start(GTK_BOX(name_time_block), time_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_time_block), nickname, FALSE, FALSE, 0);
gtk_widget_set_valign(GTK_WIDGET(name_time_block), GTK_ALIGN_CENTER);
gtk_box_pack_end(GTK_BOX(sticker_body), name_time_block, FALSE, FALSE, 0);

gtk_box_pack_start(GTK_BOX(message_body), avatar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(message_body), message, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(message_body), name_time_block, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(messages_block), message_body, FALSE, FALSE, 0);
gtk_widget_show_all(GTK_WIDGET(message_body));
gtk_container_set_focus_vadjustment(GTK_CONTAINER(sticker_body), NULL);
gtk_widget_show_all(GTK_WIDGET(sticker_body));
}

void new_incoming_sticker(GtkWidget *messages_block, int sticker_num)
{
char *path = "client/data/stickers/";
path = mx_strjoin(path, mx_itoa(sticker_num));
path = mx_strjoin(path, ".png");

GtkWidget *sticker_body = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
gtk_widget_set_name(GTK_WIDGET(sticker_body), "sticker_body");
gtk_box_pack_start(GTK_BOX(messages_block), sticker_body, FALSE, FALSE, 0);

GtkWidget *avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(avatar), 35, 35);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar), (int*)35);
gtk_box_pack_start(GTK_BOX(sticker_body), avatar, FALSE, FALSE, 0);

GtkWidget *sticker = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(sticker), 200, 200);
g_signal_connect(G_OBJECT(sticker), "draw", G_CALLBACK(draw_event_sticker), (char*)path);
gtk_box_pack_start(GTK_BOX(sticker_body), sticker, FALSE, FALSE, 0);

GtkWidget *name_time_block = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
GtkWidget *time_label = gtk_label_new(mx_str_gettime());
GtkWidget *nickname = gtk_label_new("Gazaris");
gtk_widget_set_name(GTK_WIDGET(time_label), "name_time");
gtk_widget_set_name(GTK_WIDGET(nickname), "name_time");
gtk_box_pack_start(GTK_BOX(name_time_block), time_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_time_block), nickname, FALSE, FALSE, 0);
gtk_widget_set_valign(GTK_WIDGET(name_time_block), GTK_ALIGN_CENTER);
gtk_box_pack_start(GTK_BOX(sticker_body), name_time_block, FALSE, FALSE, 0);

gtk_container_set_focus_vadjustment(GTK_CONTAINER(sticker_body), NULL);
gtk_widget_show_all(GTK_WIDGET(sticker_body));
}

void new_outgoing_embedded(GtkWidget *messages_block, char* path)
{
GtkWidget *embedded_body = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
gtk_widget_set_name(GTK_WIDGET(embedded_body), "embedded_body");
gtk_box_pack_start(GTK_BOX(messages_block), embedded_body, FALSE, FALSE, 0);

GtkWidget *avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(avatar), 35, 35);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar_account), (int*)35);
gtk_box_pack_end(GTK_BOX(embedded_body), avatar, FALSE, FALSE, 0);

const GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
int a = gdk_pixbuf_get_width(pixbuf), b = gdk_pixbuf_get_height(pixbuf);
g_object_unref(G_OBJECT(pixbuf));
printf("File: %i x %i\n", a, b);
int old_b = b;
if(b > 200) b = 200;
a = b * a / old_b;
printf("Resized: %i x %i\n", a, b);

GtkWidget *embedded = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(embedded), a, b);
g_signal_connect(G_OBJECT(embedded), "draw", G_CALLBACK(draw_event_embedded), (char*)path);
//gtk_box_pack_end(GTK_BOX(embedded_body), embedded, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(embedded_body), embedded, FALSE, FALSE, 0);

GtkWidget *name_time_block = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
GtkWidget *time_label = gtk_label_new(mx_str_gettime());
GtkWidget *nickname = gtk_label_new(t_account.username);
gtk_widget_set_name(GTK_WIDGET(time_label), "name_time");
gtk_widget_set_name(GTK_WIDGET(nickname), "name_time");
gtk_box_pack_start(GTK_BOX(name_time_block), time_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_time_block), nickname, FALSE, FALSE, 0);
gtk_widget_set_valign(GTK_WIDGET(name_time_block), GTK_ALIGN_CENTER);
gtk_box_pack_end(GTK_BOX(embedded_body), name_time_block, FALSE, FALSE, 0);

gtk_container_set_focus_vadjustment(GTK_CONTAINER(embedded_body), NULL);
gtk_widget_show_all(GTK_WIDGET(embedded_body));
}

void new_incoming_embedded(GtkWidget *messages_block, char* path)
{
GtkWidget *embedded_body = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
gtk_widget_set_name(GTK_WIDGET(embedded_body), "embedded_body");
gtk_box_pack_start(GTK_BOX(messages_block), embedded_body, FALSE, FALSE, 0);

GtkWidget *avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(avatar), 35, 35);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar_account), (int*)35);
gtk_box_pack_start(GTK_BOX(embedded_body), avatar, FALSE, FALSE, 0);

const GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
int a = gdk_pixbuf_get_width(pixbuf), b = gdk_pixbuf_get_height(pixbuf);
g_object_unref(G_OBJECT(pixbuf));
printf("File: %i x %i\n", a, b);
int old_b = b;
if(b > 200) b = 200;
a = b * a / old_b;
printf("Resized: %i x %i\n", a, b);

GtkWidget *embedded = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(embedded), a, b);
g_signal_connect(G_OBJECT(embedded), "draw", G_CALLBACK(draw_event_embedded), (char*)path);
//gtk_box_pack_end(GTK_BOX(embedded_body), embedded, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(embedded_body), embedded, FALSE, FALSE, 0);

GtkWidget *name_time_block = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
GtkWidget *time_label = gtk_label_new(mx_str_gettime());
GtkWidget *nickname = gtk_label_new(t_account.username);
gtk_widget_set_name(GTK_WIDGET(time_label), "name_time");
gtk_widget_set_name(GTK_WIDGET(nickname), "name_time");
gtk_box_pack_start(GTK_BOX(name_time_block), time_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_time_block), nickname, FALSE, FALSE, 0);
gtk_widget_set_valign(GTK_WIDGET(name_time_block), GTK_ALIGN_CENTER);
gtk_box_pack_start(GTK_BOX(embedded_body), name_time_block, FALSE, FALSE, 0);

gtk_container_set_focus_vadjustment(GTK_CONTAINER(embedded_body), NULL);
gtk_widget_show_all(GTK_WIDGET(embedded_body));
}
3 changes: 1 addition & 2 deletions client/src/creator_stickers.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void onsticker_click(GtkWidget *widget) {
GList *parent = gtk_container_get_children(GTK_CONTAINER(widget));
GList *children = gtk_container_get_children(GTK_CONTAINER(parent->data));
char* chosen = (char*)gtk_label_get_text(GTK_LABEL(children->data));
// chosen - > send sticker
new_outgoing_sticker(t_chat.chat_screen, atoi(chosen));
printf("Sticker: %s\n", chosen);
if(chosen) {}
gtk_widget_destroy(GTK_WIDGET(t_chat.stickers));
Expand Down Expand Up @@ -83,7 +83,6 @@ void create_stickerlist(GtkWidget *main)
sticker_num++;
if(sticker_num > 42) break;
}
if(sticker_num > 42) break;
}
gtk_container_add(GTK_CONTAINER(scrollable), stickers);

Expand Down
Loading

1 comment on commit fb29e48

@PAXANDDOS
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сегодня добавил возможность передавать стикеры и изображения с компьютера. С файлами осталось реализовать лишь на серверной стороне. Хотел сделать так чтобы диалоговое окно видило лишь файлы определенного формата, но не получилось, эту проблему подробнее описал тут,буду благодарен, если кто-то сможет помочь. Также при отображении передаваемых картинок с компьютера, если изображение слишком много весит (пробовал на изображениях 1мб и 100мб), то чат начинает очень-очень сильно тормозить, надо будет придумать алгоритм сжатия изображений для удобной передачи, также эту проблему описал тут.

Please sign in to comment.