Permalink
Browse files

Add routine to render a GdkPixbuf.

  • Loading branch information...
1 parent 739b35d commit a22ecb76408d1e5afcdc8e310a1462538ab4c0b4 @jtappin jtappin committed Jan 25, 2013
Showing with 89 additions and 9 deletions.
  1. +44 −4 src/gtk-draw-hl-tmpl.f90
  2. +45 −5 src/gtk-draw-hl.f90
View
48 src/gtk-draw-hl-tmpl.f90
@@ -82,8 +82,9 @@ module gtk_draw_hl
use g, only: g_object_get_data, g_object_set_data
-!!$GTK< 3.0! use gdk, only: gdk_cairo_create
-!!$GTK>=3.0! use gdk, only: gdk_cairo_create, gdk_pixbuf_get_from_surface
+!!$GTK< 3.0! use gdk, only: gdk_cairo_create, gdk_cairo_set_source_pixbuf
+!!$GTK>=3.0! use gdk, only: gdk_cairo_create, gdk_pixbuf_get_from_surface, &
+!!$GTK>=3.0! & gdk_cairo_set_source_pixbuf
use gdk_pixbuf, only: gdk_pixbuf_get_pixels, gdk_pixbuf_get_rowstride, &
& gdk_pixbuf_new
@@ -94,7 +95,8 @@ module gtk_draw_hl
& gtk_widget_add_events, gtk_widget_get_allocation, &
& gtk_widget_get_window, gtk_widget_set_can_focus, &
& gtk_widget_set_size_request, gtk_widget_set_tooltip_text, &
- & g_signal_connect, TRUE, FALSE, CAIRO_FORMAT_ARGB32, &
+ & g_signal_connect, gtk_widget_queue_draw, TRUE, FALSE, &
+ & CAIRO_FORMAT_ARGB32, &
& CAIRO_FORMAT_RGB24, CAIRO_STATUS_SUCCESS, GDK_EXPOSURE_MASK, &
& GDK_POINTER_MOTION_MASK, &
& GDK_BUTTON_PRESS_MASK, GDK_BUTTON_RELEASE_MASK, GDK_KEY_PRESS_MASK, &
@@ -103,7 +105,6 @@ module gtk_draw_hl
& GTK_POLICY_AUTOMATIC, GDK_COLORSPACE_RGB
-
use gtk_sup
use iso_c_binding
@@ -643,6 +644,45 @@ function hl_gtk_drawing_area_get_gdk_pixbuf(area, x0, y0, xsize, ysize) &
end function hl_gtk_drawing_area_get_gdk_pixbuf
+ !+
+ subroutine hl_gtk_drawing_area_draw_pixbuf(area, pixbuf, x, y)
+ type(c_ptr), intent(in) :: area, pixbuf
+ integer(kind=c_int), intent(in), optional :: x, y
+
+ ! Render a GdkPixbuf on a drawing area
+ !
+ ! AREA: c_ptr: required: The drawing area.
+ ! PIXBUF: c_ptr: required: The pixbuf to draw.
+ ! X, Y: c_int: optional: The coordinate of the upper left corner of the
+ ! pixbuf on the drawing area (defaults 0).
+ !
+ ! If you are rendering a pixbuf among other operations then just use
+ ! gdk_cairo_set_source_pixbuf directly on the context with which you
+ ! are working.
+ !-
+
+ type(c_ptr) :: cc
+ real(kind=c_double) :: xx, yy
+
+ if (present(x)) then
+ xx = real(x,c_double)
+ else
+ xx = 0._c_double
+ end if
+ if (present(y)) then
+ yy = real(y, c_double)
+ else
+ yy = 0._c_double
+ end if
+
+ cc = hl_gtk_drawing_area_cairo_new(area)
+
+ call gdk_cairo_set_source_pixbuf(cc, pixbuf, xx, yy)
+
+ call gtk_widget_queue_draw(area)
+ call hl_gtk_drawing_area_cairo_destroy(cc)
+
+ end subroutine hl_gtk_drawing_area_draw_pixbuf
!+
function hl_gtk_drawing_area_expose_cb(area, event, data) bind(c) &
View
50 src/gtk-draw-hl.f90
@@ -27,7 +27,7 @@
! --------------------------------------------------------
! gtk-draw-hl.f90
-! Generated: Mon Jan 21 18:21:09 2013 GMT
+! Generated: Fri Jan 25 20:01:37 2013 GMT
! Please do not edit this file directly,
! Edit gtk-draw-hl-tmpl.f90, and use ./mk_gtk_hl.pl to regenerate.
! Generated for GTK+ version: 2.24.0.
@@ -81,8 +81,9 @@ module gtk_draw_hl
use g, only: g_object_get_data, g_object_set_data
- use gdk, only: gdk_cairo_create
-!!$GTK>=3.0! use gdk, only: gdk_cairo_create, gdk_pixbuf_get_from_surface
+ use gdk, only: gdk_cairo_create, gdk_cairo_set_source_pixbuf
+!!$GTK>=3.0! use gdk, only: gdk_cairo_create, gdk_pixbuf_get_from_surface, &
+!!$GTK>=3.0! & gdk_cairo_set_source_pixbuf
use gdk_pixbuf, only: gdk_pixbuf_get_pixels, gdk_pixbuf_get_rowstride, &
& gdk_pixbuf_new
@@ -93,7 +94,8 @@ module gtk_draw_hl
& gtk_widget_add_events, gtk_widget_get_allocation, &
& gtk_widget_get_window, gtk_widget_set_can_focus, &
& gtk_widget_set_size_request, gtk_widget_set_tooltip_text, &
- & g_signal_connect, TRUE, FALSE, CAIRO_FORMAT_ARGB32, &
+ & g_signal_connect, gtk_widget_queue_draw, TRUE, FALSE, &
+ & CAIRO_FORMAT_ARGB32, &
& CAIRO_FORMAT_RGB24, CAIRO_STATUS_SUCCESS, GDK_EXPOSURE_MASK, &
& GDK_POINTER_MOTION_MASK, &
& GDK_BUTTON_PRESS_MASK, GDK_BUTTON_RELEASE_MASK, GDK_KEY_PRESS_MASK, &
@@ -102,7 +104,6 @@ module gtk_draw_hl
& GTK_POLICY_AUTOMATIC, GDK_COLORSPACE_RGB
-
use gtk_sup
use iso_c_binding
@@ -642,6 +643,45 @@ function hl_gtk_drawing_area_get_gdk_pixbuf(area, x0, y0, xsize, ysize) &
end function hl_gtk_drawing_area_get_gdk_pixbuf
+ !+
+ subroutine hl_gtk_drawing_area_draw_pixbuf(area, pixbuf, x, y)
+ type(c_ptr), intent(in) :: area, pixbuf
+ integer(kind=c_int), intent(in), optional :: x, y
+
+ ! Render a GdkPixbuf on a drawing area
+ !
+ ! AREA: c_ptr: required: The drawing area.
+ ! PIXBUF: c_ptr: required: The pixbuf to draw.
+ ! X, Y: c_int: optional: The coordinate of the upper left corner of the
+ ! pixbuf on the drawing area (defaults 0).
+ !
+ ! If you are rendering a pixbuf among other operations then just use
+ ! gdk_cairo_set_source_pixbuf directly on the context with which you
+ ! are working.
+ !-
+
+ type(c_ptr) :: cc
+ real(kind=c_double) :: xx, yy
+
+ if (present(x)) then
+ xx = real(x,c_double)
+ else
+ xx = 0._c_double
+ end if
+ if (present(y)) then
+ yy = real(y, c_double)
+ else
+ yy = 0._c_double
+ end if
+
+ cc = hl_gtk_drawing_area_cairo_new(area)
+
+ call gdk_cairo_set_source_pixbuf(cc, pixbuf, xx, yy)
+
+ call gtk_widget_queue_draw(area)
+ call hl_gtk_drawing_area_cairo_destroy(cc)
+
+ end subroutine hl_gtk_drawing_area_draw_pixbuf
!+
function hl_gtk_drawing_area_expose_cb(area, event, data) bind(c) &

0 comments on commit a22ecb7

Please sign in to comment.