~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-tools/tinatool/gphx/gdk2/gphxGdk_draw.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :  TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/gphx/gdk2/gphxGdk_draw.c,v $
 37  * Date    :  $Date: 2009/03/23 15:41:27 $
 38  * Version :  $Revision: 1.2 $
 39  * CVS Id  :  $Id: gphxGdk_draw.c,v 1.2 2009/03/23 15:41:27 paul Exp $
 40  *
 41  * Author  :  giob@man.ac.uk, paul.bromiley@manchester.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  gphxGdk_draw.c
 47  *  @brief Functions to draw GDK drawing primitives (points, lines, arcs, etc.).
 48  *
 49  *  Note: the functions in this file are duplicated for each graphics lib (x11, GDK, etc ...).
 50  *
 51  *  Note: GDK make all of the colourmap handling redundant by providing the gdk_draw_rgb_image
 52  *  function.  The tv_screen_col_image function is an initial experiment in using this 
 53  *  functionality.  After the reversioning to TINA6 (at which point the other graphics 
 54  *  libraries will be removed), one long-term aim should be to remove all of the colormap
 55  *  functinality from TINA. PAB 09/09/09.
 56  *
 57  */
 58 
 59 
 60 #include "gphxGdk_draw.h"
 61 
 62 #if HAVE_CONFIG_H
 63   #include <config.h>
 64 #endif
 65 
 66 #include <gtk/gtk.h>
 67 #include <tinatool/gphx/gdk2/gphx_GdkDef.h>
 68 
 69 
 70 /**
 71  * @brief   Flush X buffer and wait for all requests to be processed.  
 72  * @param   tv_screen  Pointer to current tv_screen.
 73  * 
 74  * Tv_screen is not used - left in function prototype for compatibility with Xv 
 75  * and motif Tina.
 76  */
 77 void    tv_screen_flush(Tv_screen *tv_screen)
 78 {
 79   if (tv_screen == NULL)
 80     return;
 81 
 82   gdk_flush();
 83 }
 84 
 85 /**
 86  * @brief   Clear the window of the specified Tv_screen.  
 87  * @param   tv_screen  Pointer to Tv_screen to be cleared.
 88  */
 89 void    tv_screen_erase(Tv_screen *tv_screen)
 90 {
 91   if (tv_screen)
 92     gdk_window_clear(tv_screen->window);
 93 }
 94 
 95 /**
 96  * @brief   Draw a point (single pixel) at screen location pos.  
 97  * @param   tv_screen  Pointer to Tv_screen on which to draw point.
 98  * @param   pos        Position of point to be drawn.
 99  */
100 void    tv_screen_point(Tv_screen *tv_screen, Ipos pos)
101 {
102   if (tv_screen == NULL)
103     return;
104 
105   gdk_draw_point(tv_screen->window, tv_screen->gc, pos.x, pos.y);  
106 }
107 
108 /**
109  * @brief   Draw an asterisk (or 3 pixel-wide dot) at pos on tv_screen.  
110  * @param   tv_screen  Pointer to Tv_screen on which to draw dot.
111  * @param   pos        Position of centre of dot to be drawn.
112  */
113 void    tv_screen_dot(Tv_screen *tv_screen, Ipos pos)
114 {
115     int     x0, x1, x2;
116     int     y0, y1, y2;
117 
118     if (tv_screen == NULL)
119         return;
120 
121     x1 = pos.x;
122     y1 = pos.y;
123     x0 = x1 - 1;
124     y0 = y1 - 1;
125     x2 = x1 + 1;
126     y2 = y1 + 1;
127     gdk_draw_line(tv_screen->window, tv_screen->gc, x0, y0, x2, y0);
128     gdk_draw_line(tv_screen->window, tv_screen->gc, x0, y1, x2, y1);
129     gdk_draw_line(tv_screen->window, tv_screen->gc, x0, y2, x2, y2);
130 }
131 
132 /**
133  * @brief   Draw a line (1 pixel wide) on tv_screen from pos1 to pos2.  
134  * @param   tv_screen  Pointer to Tv_screen on which to draw line.
135  * @param   pos1       Position of start of line.
136  * @param   pos2       Position of end of line.
137  */
138 void    tv_screen_line(Tv_screen * tv_screen, Ipos pos1, Ipos pos2)
139 {
140     if (tv_screen == NULL)
141         return;
142 
143     gdk_draw_line (tv_screen->window, tv_screen->gc,
144                    pos1.x, pos1.y,  
145                    pos2.x, pos2.y);
146 }
147 
148 /**
149  * @brief   Draw a polyline on tv_screen.  
150  * @param   tv_screen  Pointer to Tv_screen on which to draw polyline.
151  * @param   points     Positions of individual line ends.
152  */
153 void    tv_screen_polyline(Tv_screen *tv_screen, List *points)
154 {
155     int       npoints, i;
156     List     *ptr;
157     GdkPoint *xpoints;
158     Ipos      pos = {Ipos_id};
159 
160     if (tv_screen == NULL)
161         return;
162 
163     npoints = list_length(points);
164     xpoints = (GdkPoint *) ralloc((unsigned) npoints * sizeof(GdkPoint));
165     for (ptr = points, i = 0; ptr != NULL; ptr = ptr->next, ++i)
166     {
167         pos = *((Ipos *) ptr->to);
168         xpoints[i].x = pos.x;
169         xpoints[i].y = pos.y;
170     }
171     gdk_draw_lines(tv_screen->window, tv_screen->gc,
172                    xpoints, npoints);
173     rfree((void *) xpoints);
174 }
175 
176 /**
177  * @brief   Draw a circle of given radius centred at pos on tv_screen.  
178  * @param   tv_screen  Pointer to Tv_screen on which to draw circle.
179  * @param   centre     Position of centre of circle to be drawn.
180  * @param   radius     Integer radius of circle in pixels.
181  */
182 void    tv_screen_circle(Tv_screen *tv_screen, Ipos centre, int radius)
183 {
184     int     cx = centre.x;
185     int     cy = centre.y;
186 
187     if (tv_screen == NULL)
188         return;
189 
190     gdk_draw_arc(tv_screen->window, tv_screen->gc, FALSE,
191                  cx - radius, cy - radius, 
192                  2 * radius, 2 * radius, 
193                  0, 64 * 360);
194 }
195 
196 /**
197  * @brief   Draw a rectangle on tv_screen.  
198  * @param   tv_screen  Pointer to Tv_screen on which to draw rectangle.
199  * @param   pos1       Position of top left pixel of rectangle.
200  * @param   pos2       Position of bottom right pixel of rectangle.
201  */
202 void    tv_screen_rect(Tv_screen * tv_screen, Ipos pos1, Ipos pos2)
203 {
204     int     x1 = pos1.x, y1 = pos1.y;
205     int     x2 = pos2.x, y2 = pos2.y;
206 
207     if (tv_screen == NULL)
208         return;
209 
210     if (x1 == x2 && y1 == y2)
211     {                           /* a single point */
212         gdk_draw_point(tv_screen->window, tv_screen->gc, x1, y1);
213         return;
214     }
215     ORDER(int, x1, x2);
216     ORDER(int, y1, y2);
217     gdk_draw_line(tv_screen->window, tv_screen->gc, x1, y1, x1, y2 - 1);
218     gdk_draw_line(tv_screen->window, tv_screen->gc, x1, y2, x2 - 1, y2);
219     gdk_draw_line(tv_screen->window, tv_screen->gc, x2, y2, x2, y1 + 1);
220     gdk_draw_line(tv_screen->window, tv_screen->gc, x2, y1, x1 + 1, y1);
221 }
222 
223 /**
224  * @brief   Draw a filled rectangle on tv_screen.  
225  * @param   tv_screen  Pointer to Tv_screen on which to draw rectangle.
226  * @param   pos1       Position of top left pixel of rectangle.
227  * @param   pos2       Position of bottom right pixel of rectangle.
228  */
229 void    tv_screen_fillrect(Tv_screen * tv_screen, Ipos pos1, Ipos pos2)
230 {
231     int     x1 = pos1.x, y1 = pos1.y;
232     int     x2 = pos2.x, y2 = pos2.y;
233 
234     if (tv_screen == NULL)
235         return;
236 
237     gdk_draw_rectangle(tv_screen->window, tv_screen->gc, TRUE,
238                        x1, y1, 
239                        x2 - x1, y2 - y1);
240 }
241 
242 /**
243  * @brief   Draw text on tv_screen at pos.  
244  * @param   tv_screen  Pointer to Tv_screen on which to draw text.
245  * @param   string     String to be drawn.
246  * @param   pos        Position of left edge of text.
247  */
248 void    tv_screen_text(Tv_screen *tv_screen, char *string, Ipos pos)
249 {
250   GdkGCValues *gc_values;
251 
252   if (tv_screen == NULL)
253     return;
254   
255   gc_values = (GdkGCValues *) g_malloc(sizeof(GdkGCValues));
256   gdk_gc_get_values (tv_screen->gc,
257                      gc_values);
258 
259   gdk_draw_string(tv_screen->window, gc_values->font, tv_screen->gc,
260                     pos.x, pos.y, 
261                     string);
262 }
263 
264 /**
265  * @brief   Not actually used anywhere - consider removing - GAB 8 Dec 2003.  
266  * @param   .
267  * @return  .
268  * 
269  */
270 void    tv_screen_raster(Tv_screen * tv_screen, int x1, int x2, int y, char *raster)
271 {
272   /** Not actually used anywhere - consider removing - GAB 8 Dec 2003 */
273 }
274 
275 /**
276  * @brief   Display image on a canvas using the Tv's colormap
277  * @param   tv_screen  Pointer to the Tv_screen struct associated with the GDK drawable.
278  * @param   x          The x coordinate of the top-left corner in the drawable.
279  * @param   y          The y coordinate of the top-left corner in the drawable.
280  * @param   w          The width in pixels of the rectangle to be drawn into.
281  * @param   h          The height in pixels of the rectangle to be drawn into.
282  * @param   data       The image data (as pixel values).
283  *
284  *   Draw the image held in data on the drawable associated with tv_screen.
285  *   Uses a GDK RGB function to display the image with the appropriate colourmap.
286  *
287  *   Note: tv_screen_image draws a grey-level image using the colormap stored in the Tv.
288  *         tv_screen_col_image draws an RGB image letting GTK+ sort out the colormap.
289  *
290  */
291 void    tv_screen_image(Tv_screen * tv_screen, int x, int y, int w, int h, char *data)
292 {
293   GdkWindow  *window = (GdkWindow  *)(tv_screen->window);
294 
295   if (tv_screen == NULL) return;
296 
297   gdk_draw_indexed_image(window, tv_screen->gc, 
298                          (gint)x, (gint)y, (gint)w, (gint)h,
299                          GDK_RGB_DITHER_MAX, 
300                          (guchar *)data, 
301                          (gint)w,
302                          tv_screen->colormap); 
303 }
304 
305 
306 /**
307  * @brief   Display RGB image on a canvas.
308  * @param   tv_screen  Pointer to the Tv_screen struct associated with the GDK drawable.
309  * @param   x          The x coordinate of the top-left corner in the drawable.
310  * @param   y          The y coordinate of the top-left corner in the drawable.
311  * @param   w          The width in pixels of the rectangle to be drawn into.
312  * @param   h          The height in pixels of the rectangle to be drawn into.
313  * @param   data       The image data (as 24-bit packed RGB values).
314  *
315  *   Draw the image held in data on the drawable associated with tv_screen.
316  *   Uses a GDK RGB function to display the image with the appropriate colourmap.
317  *
318  *   Note: tv_screen_image draws a grey-level image using the colormap stored in the Tv.
319  *         tv_screen_col_image draws an RGB image letting GTK+ handle the colormap.
320  *
321  */
322 void    tv_screen_col_image(Tv_screen * tv_screen, int x, int y, int w, int h, char *data)
323 {
324   GdkWindow  *window = (GdkWindow  *)(tv_screen->window);
325 
326   if (tv_screen == NULL) return;
327 
328   gdk_draw_rgb_image(window, tv_screen->gc, 
329                          (gint)x, (gint)y, (gint)w, (gint)h,
330                          GDK_RGB_DITHER_MAX, 
331                          (guchar *)data, 
332                          (gint)(w*3));
333 }
334 
335 
336 /**
337  * @brief   Redisplay a stored image on a canvas.  
338  * @param   tv_screen  Pointer to the Tv_screen struct associated with the GDK drawable.
339  * @param   picture    Pointer to the Tv_picture struct in which the screen contents are stored.
340  *
341  * This function is called when the canvas is moved or uncovered after being obscured.
342  * 
343  */
344 void    tv_screen_show_picture(Tv_screen *tv_screen, Tv_picture *picture)
345 {
346   GtkWidget  *widget;
347   GdkDrawable *drawable;
348   GdkGC       *gc;
349   GdkPixbuf   *pbuf;
350 
351   widget = GTK_WIDGET(tv_screen->canvas);
352   drawable = (GdkDrawable *)(widget->window);
353   pbuf = (GdkPixbuf *)(picture->pbuf);
354   gc = (GdkGC *)(tv_screen->gc); 
355   gdk_draw_pixbuf(drawable, gc, pbuf, 0, 0, 0, 0, -1, -1, GDK_RGB_DITHER_MAX, 0, 0);
356 }
357 
358 
359 /* Gdk draw functions wrap xserver calls, and so draw to the server-side buffer: even pixbufs are 
360 server-side objects.  This causes unacceptable time-lags in mouse interactions with large stereo 
361 datasets in the threed tv, as potentially hundreds of individual calls are made to draw functions.  
362 (This is not a problem in xview or motif, as the xserver functions are called directly.)  Gdk double 
363 buffering avoids this problem by intercepting calls to the draw functions and sending them to an 
364 off-screen (client-side) buffer, which is then sent to the xserver when the 
365 tv_screen_double_buffer_end function is called. PAB 20/03/2009 */
366 
367 
368 /**
369  * @brief   Initiate Gdk double buffering.
370  * @param   tv_screen  Pointer to the Tv_screen struct associated with the GDK drawable.
371  *
372  * This function is called in threed_skeldraw, in order to avoid time lags in mouse interactions
373  * with large stereo datasets in the threed tv when the Gtk+ 2 widgets are used.  It is not 
374  * implemented for other widget sets.  It initiates gdk double buffering i.e. calls to draw 
375  * functions are intercepted and sent to a client-side buffer, which is painted to the screen 
376  * only when the tv_screen_double_buffer_end function is called. Calls to the two function must
377  * occur in matched pairs.
378  * 
379  */
380 void tv_screen_double_buffer_start(Tv_screen *tv_screen)
381 {
382   GdkRegion *region=NULL;
383 
384   region = gdk_drawable_get_visible_region(tv_screen->window);
385   gdk_window_begin_paint_region(tv_screen->window, region);
386   gdk_region_destroy(region);
387 }
388 
389 
390 /**
391  * @brief   Terminate Gdk double buffering.
392  * @param   tv_screen  Pointer to the Tv_screen struct associated with the GDK drawable.
393  *
394  * This function is called in threed_skeldraw, in order to avoid time lags in mouse interactions
395  * with large stereo datasets in the threed tv when the Gtk+ 2 widgets are used.  It is not 
396  * implemented for other widget sets.  It terminates gdk double buffering i.e. the client-side 
397  * buffer initiated with tv_screen_double_buffer_start is sent to the xserver.  Calls to the 
398  * two functions must occur in matched pairs.
399  * 
400  */
401 void tv_screen_double_buffer_end(Tv_screen *tv_screen)
402 {
403   gdk_window_end_paint(tv_screen->window);
404 }
405 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.