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 Cairo from pixbuf
Goto page Previous  1, 2
 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Sat Dec 06, 2008 10:31 am    Post subject: Reply with quote

dreblen wrote:
Okay, I still don't understand why you need to use cairo if you're loading an svg, but I know why it appears that your window is transparent.
It's because your svg is larger than the default window size.
If you resize the window, you'll see that the rest of shape is there too, it's just outside of the window.


Sorry, I didn't think of it, but why the window isn't blue?

Back to top
dreblen
Never Seen the Sunlight


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

PostPosted: Sat Dec 06, 2008 7:45 pm    Post subject: Reply with quote

It's not blue because the svg was only used for the mask, if you want to make it blue then you could use gtk.Widget.modify_bg:
Code: (Python)
1
win.modify_bg(gtk.STATE_NORMAL, gdk.Color(0, 0, 0xFFFF))

C
http://library.gnome.org/devel/gtk/unstable/GtkWidget.html#gtk-widget-modify-bg
PyGTK
http://pygtk.org/docs/pygtk/class-gtkwidget.html#method-gtkwidget--modify-bg
Back to top
nadavvin
Familiar Face


Joined: 06 Dec 2007
Posts: 19

PostPosted: Sat Dec 06, 2008 8:55 pm    Post subject: Reply with quote

dreblen wrote:
It's not blue because the svg was only used for the mask, if you want to make it blue then you could use gtk.Widget.modify_bg:
Code: (Python)
1
win.modify_bg(gtk.STATE_NORMAL, gdk.Color(0, 0, 0xFFFF))

C
http://library.gnome.org/devel/gtk/unstable/GtkWidget.html#gtk-widget-modify-bg
PyGTK
http://pygtk.org/docs/pygtk/class-gtkwidget.html#method-gtkwidget--modify-bg


I guess it's only used for the mask, However I meant that the image will also paint the form and not only define its shape, therefore I try to do it in Cairo.

Code: (Python)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

def expose(win, event):    # -widget, +win
# /dreblen
   
global supports_alpha, img

    pixbuf = gdk.pixbuf_new_from_file('1.svg')
    pix, mask = pixbuf.render_pixmap_and_mask()
    cr = win.window.cairo_create()
    cr.set_source_pixmap(pix,0,0)
    cr.paint()
    win.shape_combine_mask(mask, 0, 0)

    return False


Back to top
tadeboro
Never Seen the Sunlight


Joined: 23 Jul 2008
Posts: 2135
Location: Slovenia

PostPosted: Sun Dec 07, 2008 2:21 pm    Post subject: Reply with quote

Hello.

I think your expose event handler should look something like this:
Code: (Python)
1
2
3
4
5
6
7
8
9
10
11
def expose(win, event):    # -widget, +win
# /dreblen
   
global supports_alpha, img

    pixbuf = gdk.pixbuf_new_from_file('1.svg')
    pix, mask = pixbuf.render_pixmap_and_mask()
    win.shape_combine_mask(mask, 0, 0)
    win.draw_pixbuf( None, pixbuf, 0, 0, 0, 0, -1, -1, gtk.gdk.RGB_DITHER_NORMAL, 0, 0 )

    return False

BTW, my python skills are quite poor, so please check my code against PyGTK docs at: http://www.pygtk.org/docs/pygtk/class-gdkdrawable.html#method-gdkdrawable--draw-pixbuf
Back to top
colossus73
Familiar Face


Joined: 18 Aug 2008
Posts: 46

PostPosted: Mon Jan 05, 2009 9:14 pm    Post subject: Re: How to draw Cairo from pixbuf Reply with quote

nadavvin wrote:
Hello

I'm trying to create customize, not rectangle window:
http://www.gtkforums.com/viewtopic.php?t=2234


Maybe this awesome example can help you:
http://macslow.thepimp.net/?p=26
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 


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