From e9d93dac434bc319821c909c022d8e1b3c6445b3 Mon Sep 17 00:00:00 2001 From: Dmitry Kalyanov Date: Sun, 8 Nov 2009 15:10:21 +0300 Subject: [PATCH] Use gobject:with-foreign-boxed-array in Gdk --- gdk/gdk.drawing-primitives.lisp | 70 ++++++--------------------------------- gdk/gdk.region.lisp | 29 +++------------- 2 files changed, 15 insertions(+), 84 deletions(-) diff --git a/gdk/gdk.drawing-primitives.lisp b/gdk/gdk.drawing-primitives.lisp index 03e7324..6d32034 100644 --- a/gdk/gdk.drawing-primitives.lisp +++ b/gdk/gdk.drawing-primitives.lisp @@ -28,18 +28,8 @@ (n :int)) (defun draw-points (drawable gc points) - (let ((n (length points))) - (with-foreign-object (points-ptr 'point-cstruct n) - (let ((i 0)) - (map nil - (lambda (pt) - (gobject::copy-slots-to-native - pt - (inc-pointer points-ptr (* i (foreign-type-size 'point-cstruct))) - (gobject::g-boxed-cstruct-wrapper-info-cstruct-description (gobject::get-g-boxed-foreign-info 'point))) - (incf i)) - points)) - (gdk-draw-points drawable gc points-ptr n)))) + (with-foreign-boxed-array (n points-ptr point points) + (gdk-draw-points drawable gc points-ptr n))) (export 'draw-points) @@ -60,18 +50,8 @@ (n :int)) (defun draw-lines (drawable gc points) - (let ((n (length points))) - (with-foreign-object (points-ptr 'point-cstruct n) - (let ((i 0)) - (map nil - (lambda (pt) - (gobject::copy-slots-to-native - pt - (inc-pointer points-ptr (* i (foreign-type-size 'point-cstruct))) - (gobject::g-boxed-cstruct-wrapper-info-cstruct-description (gobject::get-g-boxed-foreign-info 'point))) - (incf i)) - points)) - (gdk-draw-lines drawable gc points-ptr n)))) + (with-foreign-boxed-array (n points-ptr point points) + (gdk-draw-lines drawable gc points-ptr n))) (export 'draw-lines) @@ -98,18 +78,8 @@ (n-segments :int)) (defun draw-segments (drawable gc segments) - (let ((n (length segments))) - (with-foreign-object (segments-ptr 'segment-cstruct n) - (let ((i 0)) - (map nil - (lambda (segment) - (gobject::copy-slots-to-native - segment - (inc-pointer segments-ptr (* i (foreign-type-size 'segment-cstruct))) - (gobject::g-boxed-cstruct-wrapper-info-cstruct-description (gobject::get-g-boxed-foreign-info 'segment))) - (incf i)) - segments)) - (gdk-draw-segments drawable gc segments-ptr n)))) + (with-foreign-boxed-array (n segments-ptr segment segments) + (gdk-draw-segments drawable gc segments-ptr n))) (export 'draw-segments) @@ -143,18 +113,8 @@ (n-points :int)) (defun draw-polygon (drawable gc filled points) - (let ((n (length points))) - (with-foreign-object (points-ptr 'point-cstruct n) - (let ((i 0)) - (map nil - (lambda (point) - (gobject::copy-slots-to-native - point - (inc-pointer points-ptr (* i (foreign-type-size 'point-cstruct))) - (gobject::g-boxed-cstruct-wrapper-info-cstruct-description (gobject::get-g-boxed-foreign-info 'point))) - (incf i)) - points)) - (gdk-draw-polygon drawable gc filled points-ptr n)))) + (with-foreign-boxed-array (n points-ptr point points) + (gdk-draw-polygon drawable gc filled points-ptr n))) (export 'draw-polygon) @@ -165,18 +125,8 @@ (n :int)) (defun draw-trapezoids (drawable gc trapezoids) - (let ((n (length trapezoids))) - (with-foreign-object (trapezoids-ptr 'trapezoid-cstruct n) - (let ((i 0)) - (map nil - (lambda (trapezoid) - (gobject::copy-slots-to-native - trapezoid - (inc-pointer trapezoids-ptr (* i (foreign-type-size 'trapezoid-cstruct))) - (gobject::g-boxed-cstruct-wrapper-info-cstruct-description (gobject::get-g-boxed-foreign-info 'trapezoid))) - (incf i)) - trapezoids)) - (gdk-draw-trapezoids drawable gc trapezoids-ptr n)))) + (with-foreign-boxed-array (n trapezoids-ptr trapezoid trapezoids) + (gdk-draw-trapezoids drawable gc trapezoids-ptr n))) (export 'draw-trapezoids) diff --git a/gdk/gdk.region.lisp b/gdk/gdk.region.lisp index ae6a303..cb03290 100644 --- a/gdk/gdk.region.lisp +++ b/gdk/gdk.region.lisp @@ -30,17 +30,8 @@ (fill-rule gdk-fill-rule)) (defun region-from-polygon (points fill-rule) - (let ((n (length points))) - (with-foreign-object (pts 'point-cstruct n) - (let ((i 0)) - (map nil (lambda (pt) - (gobject::copy-slots-to-native - pt - (inc-pointer pts (* i (foreign-type-size 'point-cstruct))) - (gobject::g-boxed-cstruct-wrapper-info-cstruct-description (gobject::get-g-boxed-foreign-info 'point))) - (incf i)) - points)) - (gdk-region-polygon pts n fill-rule)))) + (with-foreign-boxed-array (n pts point points) + (gdk-region-polygon pts n fill-rule))) (export 'region-from-polygon) @@ -161,18 +152,8 @@ (data :pointer)) (defun region-spans-intersect-foreach (region spans sorted fn) - (let ((n (length spans))) - (with-stable-pointer (ptr fn) - (with-foreign-object (spans-ptr 'span-cstruct n) - (let ((i 0)) - (map nil - (lambda (span) - (gobject::copy-slots-to-native - span - (inc-pointer spans-ptr (* i (foreign-type-size 'span-cstruct))) - (gobject::g-boxed-cstruct-wrapper-info-cstruct-description (gobject::get-g-boxed-foreign-info 'span))) - (incf i)) - spans)) - (gdk-region-spans-intersect-foreach region spans-ptr n sorted (callback gdk-region-spans-intersect-foreach) ptr))))) + (with-stable-pointer (ptr fn) + (with-foreign-boxed-array (n spans-ptr span spans) + (gdk-region-spans-intersect-foreach region spans-ptr n sorted (callback gdk-region-spans-intersect-foreach) ptr)))) (export 'region-spans-intersect-foreach) -- 1.7.10.4