GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to draw by myself the backgorund of gtk+ window?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> General GTK+ Discussion
Author Message
sawerset



Joined: 16 Jul 2008
Posts: 1

PostPosted: Wed Jul 16, 2008 11:29 pm    Post subject: How to draw by myself the backgorund of gtk+ window? Reply with quote

I need to do such thing to draw some rectangles and circles as a background and to place above them buttons, labels.
Is it posible?
How it can be done?
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 643
Location: Falun, WI USA

PostPosted: Sun Jul 20, 2008 1:19 am    Post subject: Reply with quote

you can hack the expose event of your widget to insert drawing code,
something like this (note that this doesn't work very well, but it's just an eample):
Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <gtk/gtk.h>
#include <math.h>

gboolean button_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
{
    cairo_t *cr;
    GtkAllocation alloc;

    alloc = wi->allocation;

    cr = gdk_cairo_create(wi->window);
    cairo_arc(cr, alloc.width/2, alloc.height/2, MIN(alloc.width/3, alloc.height/3), 0, M_PI*2);
    cairo_stroke(cr);

    return FALSE;    /* continue the event */
}

int main(int argc, char **argv)
{
    GtkWidget *win;
    GtkWidget *button;

    gtk_init(&argc, &argv);

    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(win), "delete_event", G_CALLBACK(gtk_main_quit), NULL);
    gtk_container_set_border_width(GTK_CONTAINER(win), 10);

    button = gtk_button_new();
    g_signal_connect_after(G_OBJECT(button), "expose_event", G_CALLBACK(button_expose), NULL);
    gtk_container_add(GTK_CONTAINER(win), button);
    gtk_widget_show(button);

    gtk_widget_show(win);

    gtk_main();

    return 0;
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> General GTK+ Discussion All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP