hippo-canvas r7259 - in trunk: . common/hippo linux/hippo python



Author: otaylor
Date: Sat May 24 22:22:26 2008
New Revision: 7259
URL: http://svn.gnome.org/viewvc/hippo-canvas?rev=7259&view=rev

Log:
- Add create_surface() method to HippoContext
- Bind paint() virtual function of HippoCanvasItem in Python
- Add a constructor for hippo.Rectangle() in Python


Modified:
   trunk/Makefile-python.am
   trunk/common/hippo/hippo-canvas-box.c
   trunk/common/hippo/hippo-canvas-context.c
   trunk/common/hippo/hippo-canvas-context.h
   trunk/linux/hippo/hippo-canvas-helper.c
   trunk/python/hippo.defs
   trunk/python/hippo.override

Modified: trunk/Makefile-python.am
==============================================================================
--- trunk/Makefile-python.am	(original)
+++ trunk/Makefile-python.am	Sat May 24 22:22:26 2008
@@ -38,6 +38,7 @@
 hippo.c: $(PYTHONDEFS_FILES)
 	($(PYGTK_CODEGEN) \
 	    --load-types $(PYTHONSRCDIR)/arg-types.py \
+            --register $(PYGTK_DEFSDIR)/pango.defs \
             --register $(PYGTK_DEFSDIR)/gtk-types.defs \
 	    --override $(PYTHONSRCDIR)/hippo.override \
 	    --prefix pyhippo $(PYTHONSRCDIR)/hippo.defs) > gen-hippo.c \

Modified: trunk/common/hippo/hippo-canvas-box.c
==============================================================================
--- trunk/common/hippo/hippo-canvas-box.c	(original)
+++ trunk/common/hippo/hippo-canvas-box.c	Sat May 24 22:22:26 2008
@@ -45,6 +45,10 @@
 
 /* Canvas context methods */
 static PangoLayout*     hippo_canvas_box_create_layout          (HippoCanvasContext   *context);
+static cairo_surface_t* hippo_canvas_box_create_surface         (HippoCanvasContext   *context,
+                                                                 cairo_content_t       content,
+                                                                 int                   width,
+                                                                 int                   height);
 static cairo_surface_t* hippo_canvas_box_load_image             (HippoCanvasContext   *context,
                                                                  const char           *image_name);
 static guint32          hippo_canvas_box_get_color              (HippoCanvasContext   *context,
@@ -248,6 +252,7 @@
 hippo_canvas_box_iface_init_context (HippoCanvasContextIface *klass)
 {
     klass->create_layout = hippo_canvas_box_create_layout;
+    klass->create_surface = hippo_canvas_box_create_surface;
     klass->load_image = hippo_canvas_box_load_image;
     klass->get_color = hippo_canvas_box_get_color;
     klass->register_widget_item = hippo_canvas_box_register_widget_item;
@@ -1218,6 +1223,20 @@
 }
 
 static cairo_surface_t*
+hippo_canvas_box_create_surface(HippoCanvasContext *context,
+                                cairo_content_t     content,
+                                int                 width,
+                                int                 height)
+{
+    HippoCanvasBox *box = HIPPO_CANVAS_BOX(context);
+    
+    g_assert(box->context != NULL);
+    
+    /* Chain to our parent context */
+    return hippo_canvas_context_create_surface(box->context, content, width, height);
+}
+
+static cairo_surface_t*
 hippo_canvas_box_load_image(HippoCanvasContext *context,
                             const char         *image_name)
 {

Modified: trunk/common/hippo/hippo-canvas-context.c
==============================================================================
--- trunk/common/hippo/hippo-canvas-context.c	(original)
+++ trunk/common/hippo/hippo-canvas-context.c	Sat May 24 22:22:26 2008
@@ -60,6 +60,17 @@
 }
 
 cairo_surface_t*
+hippo_canvas_context_create_surface(HippoCanvasContext *context,
+                                    cairo_content_t     content,
+                                    int                 width,
+                                    int                 height)
+{
+    g_return_val_if_fail(HIPPO_IS_CANVAS_CONTEXT(context), NULL);
+
+    return HIPPO_CANVAS_CONTEXT_GET_IFACE(context)->create_surface(context, content, width, height);
+}
+
+cairo_surface_t*
 hippo_canvas_context_load_image(HippoCanvasContext *context,
                                 const char         *image_name)
 {

Modified: trunk/common/hippo/hippo-canvas-context.h
==============================================================================
--- trunk/common/hippo/hippo-canvas-context.h	(original)
+++ trunk/common/hippo/hippo-canvas-context.h	Sat May 24 22:22:26 2008
@@ -53,6 +53,10 @@
     GTypeInterface base_iface;
 
     PangoLayout*     (* create_layout)  (HippoCanvasContext  *context);
+    cairo_surface_t* (* create_surface) (HippoCanvasContext  *context,
+                                         cairo_content_t      content,
+                                         int                  width,
+                                         int                  height);
 
     cairo_surface_t* (* load_image)     (HippoCanvasContext  *context,
                                          const char          *image_name);
@@ -89,6 +93,11 @@
 
 PangoLayout*     hippo_canvas_context_create_layout          (HippoCanvasContext *context);
 
+cairo_surface_t* hippo_canvas_context_create_surface         (HippoCanvasContext *context,
+                                                              cairo_content_t     content,
+                                                              int                 width,
+                                                              int                 height);
+
 cairo_surface_t* hippo_canvas_context_load_image             (HippoCanvasContext *context,
                                                               const char         *image_name);
 guint32          hippo_canvas_context_get_color              (HippoCanvasContext *context,

Modified: trunk/linux/hippo/hippo-canvas-helper.c
==============================================================================
--- trunk/linux/hippo/hippo-canvas-helper.c	(original)
+++ trunk/linux/hippo/hippo-canvas-helper.c	Sat May 24 22:22:26 2008
@@ -11,6 +11,9 @@
 #include <gtk/gtkwindow.h>
 #include <gtk/gtklabel.h>
 
+#include <gdk/gdkx.h>
+#include <cairo-xlib.h>
+
 /* Gap between the area we are tipping and the tooltip */
 #define TOOLTIP_PADDING 4
 /* Maximum width of a tippable area before we position the tooltip by the pointer */
@@ -43,6 +46,10 @@
                                               GParamSpec   *pspec);
 
 static PangoLayout*     hippo_canvas_helper_create_layout          (HippoCanvasContext *context);
+static cairo_surface_t* hippo_canvas_helper_create_surface         (HippoCanvasContext *context,
+                                                                    cairo_content_t     content,
+                                                                    int                 width,
+                                                                    int                 height);
 static cairo_surface_t* hippo_canvas_helper_load_image             (HippoCanvasContext *context,
                                                                     const char         *image_name);
 static guint32          hippo_canvas_helper_get_color              (HippoCanvasContext *context,
@@ -148,6 +155,7 @@
 hippo_canvas_helper_iface_init (HippoCanvasContextIface *klass)
 {
     klass->create_layout = hippo_canvas_helper_create_layout;
+    klass->create_surface = hippo_canvas_helper_create_surface;
     klass->load_image = hippo_canvas_helper_load_image;
     klass->get_color = hippo_canvas_helper_get_color;
     klass->register_widget_item = hippo_canvas_helper_register_widget_item;
@@ -790,6 +798,36 @@
     return gtk_widget_create_pango_layout(helper->widget, NULL);
 }
 
+static cairo_surface_t*
+hippo_canvas_helper_create_surface(HippoCanvasContext *context,
+                                   cairo_content_t     content,
+                                   int                 width,
+                                   int                 height)
+{
+    /* This feels like a really round-about way of doing things, but
+     * I can't think of a better way. There's no way to get a cairo
+     * xlib surface without a visual other than create_similar(), and
+     * no visual for CAIRO_FORMAT_ALPHA.
+     */
+    HippoCanvasHelper *helper = HIPPO_CANVAS_HELPER(context);
+    GdkScreen *screen = gtk_widget_get_screen(helper->widget);
+    GdkDisplay *display = gdk_screen_get_display(screen);
+    GdkWindow *root = gdk_screen_get_root_window(screen);
+    GdkVisual *visual = gdk_drawable_get_visual(root);
+    cairo_surface_t *root_surface;
+    cairo_surface_t *surface;
+
+    root_surface = cairo_xlib_surface_create(GDK_DISPLAY_XDISPLAY(display),
+                                             GDK_DRAWABLE_XID(root),
+                                             GDK_VISUAL_XVISUAL(visual),
+                                             gdk_screen_get_width(screen),
+                                             gdk_screen_get_height(screen));
+    surface = cairo_surface_create_similar(root_surface, content, width, height);
+    cairo_surface_destroy(root_surface);
+
+    return surface;
+}
+
 static HippoCanvasLoadImageHook hippo_canvas_helper_load_image_hook = NULL;
 
 void

Modified: trunk/python/hippo.defs
==============================================================================
--- trunk/python/hippo.defs	(original)
+++ trunk/python/hippo.defs	Sat May 24 22:22:26 2008
@@ -787,6 +787,17 @@
   (return-type "PangoLayout*")
 )
 
+(define-method create_surface
+  (of-object "HippoCanvasContext")
+  (c-name "hippo_canvas_context_create_surface")
+  (return-type "cairo_surface_t*")
+  (parameters
+    '("int" "content")
+    '("int" "width")
+    '("int" "height")
+  )
+)
+
 (define-method load_image
   (of-object "HippoCanvasContext")
   (c-name "hippo_canvas_context_load_image")
@@ -1024,6 +1035,16 @@
   )
 )
 
+(define-virtual paint
+  (of-object "HippoCanvasItem")
+  (c-name "hippo_canvas_item_paint")
+  (return-type "none")
+  (parameters
+    '("cairo_t*" "cr")
+    '("HippoRectangle*" "damaged_area")
+  )
+)
+
 (define-method get_allocation
   (of-object "HippoCanvasItem")
   (c-name "hippo_canvas_item_get_allocation")
@@ -1517,6 +1538,12 @@
   (return-type "GType")
 )
 
+(define-function rectangle_new
+  (c-name "hippo_rectangle_new")
+  (is-constructor-of "HippoRectangle")
+  (return-type "HippoRectangle*")
+)
+
 (define-method intersect
   (of-object "HippoRectangle")
   (c-name "hippo_rectangle_intersect")

Modified: trunk/python/hippo.override
==============================================================================
--- trunk/python/hippo.override	(original)
+++ trunk/python/hippo.override	Sat May 24 22:22:26 2008
@@ -1040,6 +1040,23 @@
   	return result;
 }
 %%
+override hippo_rectangle_new args
+static int
+_wrap_hippo_rectangle_new(PyGBoxed *self, PyObject *args, PyObject *kwargs)
+{
+    HippoRectangle rect = { 0, 0, 0, 0 };
+
+    if (!PyArg_ParseTuple(args, "|iiii:HippoRectangle.__init__",
+			  &rect.x, &rect.y, &rect.width, &rect.height))
+	return -1;
+	    
+    self->boxed = hippo_rectangle_copy(&rect);
+    self->free_on_dealloc = TRUE;
+    self->gtype = HIPPO_TYPE_RECTANGLE;
+
+    return 0;
+}
+%%
 init
 if (PyType_Ready(&PyHippoCanvasBoxChild_Type) < 0) {
     g_warning("could not ready hippo.CanvasBoxChild");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]