Features/GTK3/Porting: Difference between revisions
DanielDrake (talk | contribs) No edit summary |
|||
| Line 171: | Line 171: | ||
== Tips to Activity Developers == | == Tips to Activity Developers == | ||
'' | ===Going from Drawable to Cairo=== | ||
GTK-3 does not support gtk Drawable objects, so the first step is to get your activity running under Cairo. | |||
# From activity.Activity, you inherit a canvas. Get its window. | |||
win = self.canvas.get_window() | |||
# Create a Cairo context from the window. | |||
cr = win.cairo_create() | |||
# Create a Cairo surface from the context | |||
surface = cr.get_target() | |||
# Create an XLib surface to be used for drawing | |||
xlib_surface = surface.create_similar(cairo.CONTENT_COLOR, | |||
gtk.gdk.screen_width(), | |||
gtk.gdk.screen_height()) | |||
# You'll need a Cairo context from which you'll build a GTK Cairo context | |||
cr = cairo.Context(xlib_surface) | |||
cr = gtk.gdk.CairoContext(cr) | |||
# Use this context as you would a Drawable, substituting Cairo commands for gtk commands, e.g., | |||
cr.move_to(0, 0) | |||
cr.set_source_rgb(r, g, b) # Cairo uses floats from 0 to 1 for RGB values | |||
cr.rectangle(x, y, w, h) | |||
cr.fill() | |||
# To invalidate a region to forse a refresh, use: | |||
self.canvas.queue_draw_area(x, y, w, h) | |||
:* Example: abacus-cairo | :* Example: abacus-cairo | ||
:* Example: abacus-gtk3 | :* Example: abacus-gtk3 | ||