Skip to content

Commit

Permalink
drawing avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroslavChuiko committed Feb 5, 2022
1 parent 884c11d commit 7607e60
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
Binary file added client/data/img/user_avatars/avatar1.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 added client/data/img/user_avatars/avatar2.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 added client/data/img/user_avatars/avatar3.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 added client/data/img/user_avatars/avatar4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions client/data/styles/leftbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@
/* background-color: rgb(103, 58, 183); */
/* PURPLE */
background-color: rgb(156, 39, 176);
background-image: url("../img/user-avatar4.png");
/* background-image: url("../img/user-avatar4.png"); */
/* background-size: 25px 25px; */
background-size: contain;
/* background-size: contain;
background-position: 50% 50%;
background-repeat: no-repeat;
background-repeat: no-repeat; */

border-radius: 50%;
}
Expand Down
3 changes: 3 additions & 0 deletions client/inc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <arpa/inet.h>
#include <pthread.h>
#include <gtk/gtk.h>
#include <cairo.h>
// #include <netinet/in.h>
// #include <arpa/inet.h>

#ifdef __MACH__
#include "../../libraries/openssl/openssl/ssl.h"
Expand Down
34 changes: 31 additions & 3 deletions client/src/gui/chatlist.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
#include "../../inc/client.h"

static gboolean da_expose(GtkWidget *widget, cairo_t *cr, gpointer data)
{
char* a = "client/data/img/user_avatars/avatar2.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)
{
GtkWidget *chatlist_container = get_widget_by_name_r(main_window, "chatlist");
Expand All @@ -24,10 +52,10 @@ void add_chatlist_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(da_expose), NULL); // Получить avatar пользовтеля
gtk_widget_set_halign(avatar, GTK_ALIGN_START);
gtk_widget_set_valign(avatar, GTK_ALIGN_CENTER);
add_class(avatar, "chatlist_item_avatar");
Expand Down

0 comments on commit 7607e60

Please sign in to comment.