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

Linux Cross Reference
Tina6/tina-tools/tinatool/draw/drawTv_props.c

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

  1 /*********
  2  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  3  * University of Manchester, UK.  All rights reserved.
  4  * 
  5  * Redistribution and use in source and binary forms, with or without modification, 
  6  * are permitted provided that the following conditions are met:
  7  * 
  8  *   . Redistributions of source code must retain the above copyright notice, 
  9  *     this list of conditions and the following disclaimer.
 10  *    
 11  *   . Redistributions in binary form must reproduce the above copyright notice,
 12  *     this list of conditions and the following disclaimer in the documentation 
 13  *     and/or other materials provided with the distribution.
 14  * 
 15  *   . Neither the name of the University of Manchester nor the names of its
 16  *     contributors may be used to endorse or promote products derived from this 
 17  *     software without specific prior written permission.
 18  * 
 19  * 
 20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 30  * POSSIBILITY OF SUCH DAMAGE.
 31  *
 32  **********
 33  *
 34  * Program :    TINA
 35  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_props.c,v $
 36  * Date    :  $Date: 2007/02/15 01:55:50 $
 37  * Version :  $Revision: 1.3 $
 38  * CVS Id  :  $Id: drawTv_props.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 39  *
 40  * Author  : Legacy TINA
 41  *
 42  * Notes :
 43  * Drawing properties of a tv (background, color, font, line width etc).
 44  *
 45  *********
 46 */
 47 
 48 #if HAVE_CONFIG_H
 49   #include <config.h>
 50 #endif
 51 
 52 #include <math.h>
 53 #include <stdio.h>
 54 #include <string.h>
 55 #include <stdlib.h>
 56 #include <limits.h>
 57 #include <tina/sys/sysDef.h>
 58 #include <tina/sys/sysPro.h>
 59 #include <tina/math/mathDef.h>
 60 #include <tinatool/draw/draw_TvDef.h>
 61 #include <tinatool/draw/draw_TvPro.h>
 62 #include <tinatool/gphx/gphxPro.h>
 63 
 64 #include "drawTv_props.h"
 65 
 66 /* EXTERNS
 67 extern void tv_screen_set_linewidth();
 68 extern void tv_screen_named_font_set();
 69 extern void tv_screen_background_set();
 70 extern void tv_screen_set_op();
 71 */
 72 
 73 
 74 /* Set the background color of a tv to Tina pixel (index in
 75  * cmap_lookup) given */
 76 void    tv_background_set(Tv * tv, Tina_pixel color)
 77 {
 78     if (tv && tv->tv_screen 
 79         && tv->cmap_data_visible->type == cmap_type_dynamic)
 80     {
 81         tv_screen_background_set(tv->tv_screen,
 82                                tv->cmap_data_visible->std_lut[color]);
 83     }
 84 }
 85 
 86 
 87 /* Set the foreground color of a tv to X pixel given a 'color' in tv's
 88  * std_lut */
 89 void    tv_color_set(Tv * tv, Tina_pixel color)
 90 {
 91     if (tv)
 92         tv->color = color;
 93     if (tv && tv->tv_screen && tv->cmap_data_visible )
 94     {
 95         tv_screen_color_set(tv->tv_screen, tv->cmap_data_visible->std_lut[color]);
 96     }
 97 }
 98 
 99 
100 /* Set the foreground color of a tv to RGB values, bypassing the std_lut */
101 /*
102  * Note: the plan here is that this function converts r,g,b, to a long
103  * unsigned int.  The equivalent of tv_set_color will be written to 
104  * convert a named color into r,g,b using a table.
105  */
106 void    tv_color_set_rgb(Tv * tv, int r, int g, int b)
107 {
108     long unsigned int color;
109 
110     if(r>255) r=255;
111     if(r>255) g=255;
112     if(r>255) b=255;
113     if(r<0) r=0;
114     if(g<0) g=0;
115     if(b<0) b=0;
116 
117     color = 65536*r+256*g+b;
118 
119     if (tv && tv->tv_screen)
120     {
121         tv_screen_rgb_set(tv->tv_screen, color);
122     }
123 }
124 
125 
126 /* Set the foreground color of a tv to X pixel given.  NOT using tv's
127  * std_lut. Note: in GTK TINA the std_lut gets used later on anyway.*/
128 void    tv_color_reset(Tv * tv, Tina_pixel color)
129 {
130     if (tv && tv->tv_screen)
131     {
132         tv_screen_color_set(tv->tv_screen, color);
133     }
134 }
135 
136 /* Find the pixel value at point pos */
137 int     tv_get_pixel(Tv * tv, Ipos pos)
138 {
139     if (tv == NULL || tv->tv_screen == NULL)
140         return (0);
141     return (tv_screen_get_pixel(tv->tv_screen, pos));
142 }
143 
144 /* Find the approximate grey level of the pixel at point pos */
145 Tina_pixel tv_get_grey(Tv * tv, Ipos pos)
146 {
147     Tina_pixel color = 0;
148     unsigned long min_diff = ULONG_MAX;
149     unsigned long pixel;
150     int     i;
151 
152     if (tv == NULL || tv->tv_screen == NULL)
153         return (0);
154 
155     pixel = tv_screen_get_pixel(tv->tv_screen, pos);
156 
157     /* Find the closest match in cmap_lookup to the pixel */
158     for (i = 0; i < CMAPLOOKUPSIZE; i++)
159     {
160         int     diff = abs((int) (tv->cmap_data_visible->std_lut[i] - pixel));
161 
162         if (diff < min_diff)
163         {
164             min_diff = diff;
165             color = i;
166         }
167     }
168 
169     return (color);
170 }
171 
172 
173 /* Set the foreground color of a tv to X pixel given */
174 void    tv_set_color(Tv * tv, Tina_pixel color)
175 {
176     tv_color_set(tv, color);
177 }
178 
179 int     tv_color_get(Tv * tv)
180 {
181     return (tv->color);
182 }
183 
184 int     tv_get_color(Tv * tv)
185 {
186     return (tv->color);
187 }
188 
189 int     tv_set_op(Tv * tv, int op)
190 {
191     int     oldop = 0;
192 
193     if (tv && tv->tv_screen)
194     {
195         oldop = tv->op;
196         tv->op = op;
197         if (!tv->overlay_on)
198         {
199             tv_screen_set_op(tv->tv_screen, op);
200         }
201     }
202     return (oldop);
203 }
204 
205 int     tv_get_op(Tv * tv)
206 {
207     return (tv->op);
208 }
209 
210 
211 int     tv_set_linewidth(Tv * tv, int width)
212 {
213     int     oldwidth = 0;
214 
215     if (tv)
216     {
217         oldwidth = tv->linewidth;
218         tv->linewidth = width;
219         tv_screen_set_linewidth(tv->tv_screen, width);
220     }
221     return (oldwidth);
222 }
223 
224 
225 int     tv_get_linewidth(Tv * tv)
226 {
227     return (tv->linewidth);
228 }
229 
230 
231 int     tv_set_linestyle(Tv * tv, int style)
232 {
233     int     oldstyle = 0;
234 
235     if (tv && tv->tv_screen)
236     {
237         oldstyle = tv->linestyle;
238         tv->linestyle = style;
239         tv_screen_set_linestyle(tv->tv_screen, style);
240     }
241     return (oldstyle);
242 }
243 
244 int     tv_get_linestyle(Tv * tv)
245 {
246     return (tv->linestyle);
247 }
248 
249 
250 
251 /* Set a named font in a tv and in the tv_screen it is installed on. NB
252  * MAX */
253 /* LENGTH OF font_name IS 128 */
254 void    tv_named_font_set(Tv * tv, char *font_name)
255 {
256     if (tv && tv->tv_screen)
257     {
258         (void) strncpy(tv->font_name, font_name, STRING128);
259         /* Ensure tv->font_name is NULL terminated */
260 
261         tv->font_name[STRING128 - 1] = '\0';
262 
263         tv_screen_named_font_set(tv->tv_screen, tv->font_name);
264     }
265 }
266 
267 
268 char   *tv_named_font_get(Tv * tv)
269 {
270     return (tv ? tv->font_name : "");
271 }
272 
273 
274 void    tv_save_draw(Tv * tv)
275 {
276     Tv_draw *draw;
277 
278     if (tv)
279     {
280         draw = (Tv_draw *) ts_ralloc(Tv_draw);
281         draw->overlay_on = tv->overlay_on;
282         draw->color = tv->color;
283         draw->op = tv->op;
284         draw->linewidth = tv->linewidth;
285         draw->linestyle = tv->linestyle;
286         (void) strncpy(draw->font_name, tv->font_name, STRING128);
287         /* Ensure tv->font_name is NULL terminated */
288         draw->font_name[STRING128 - 1] = '\0';
289 
290         tv->draw = ref_addtostart(tv->draw, (void *) draw, (int) rfree);
291     }
292 }
293 
294 
295 void    tv_set_overlay(Tv * tv)
296 {
297     if (tv && tv->tv_screen && tv->cmap_data_visible)
298     {
299         tv_save_draw(tv);
300         tv->overlay_on = true;
301         tv_screen_set_linewidth(tv->tv_screen, 0);
302         tv_screen_set_op(tv->tv_screen, rop_xor);
303         tv_screen_set_color(tv->tv_screen, tv->cmap_data_visible->overlay_mask);
304     }
305 }
306 
307 
308 
309 /* Reset the rgb's in a cell in a tv_screen's colormap */
310 void    tv_reset_color(Tv * tv, Tina_pixel color, int r, int g, int b)
311 {
312     extern void tv_screen_reset_color();
313 
314     if (tv && tv->tv_screen && tv->cmap_data_visible) 
315     {
316         if (tv->cmap_data_visible->type == cmap_type_dynamic)
317             tv_screen_reset_color(tv->tv_screen,
318                             (tv->cmap_data_visible->std_lut[color]),
319                               r, g, b);
320          else
321             tv_screen_alloc_color(tv->tv_screen,
322                                   /* warning: passing argument 2 of 'tv_screen_alloc_color' from incompatible pointer type */
323                             &(tv->cmap_data_visible->std_lut[color]),
324                               r, g, b);
325     }
326 }
327 
328 /* Reset the rgb's in a cell in a tv_screen's colormap */
329 void    tv_reset_named_color(Tv * tv, Tina_pixel color, char *color_name)
330 {
331     extern void tv_screen_reset_named_color();
332 
333     if (tv && tv->tv_screen && tv->cmap_data_visible->std_lut 
334         && tv->cmap_data_visible->type == cmap_type_dynamic)
335     {
336         tv_screen_reset_named_color(tv->tv_screen, tv->cmap_data_visible->std_lut[color],
337                                     color_name);
338 
339     }
340 }
341 
342 
343 void    tv_reset_draw(Tv * tv)
344 {
345     Tv_draw *draw;
346 
347     if (tv && tv->draw && tv->tv_screen)
348     {
349         draw = (Tv_draw *) tv->draw->to;
350         tv->overlay_on = draw->overlay_on;
351         tv->color = draw->color;
352         tv->op = draw->op;
353         tv->linewidth = draw->linewidth;
354         tv->linestyle = draw->linestyle;
355         (void) strncpy(tv->font_name, draw->font_name, STRING128);
356         /* Ensure tv->font_name is NULL terminated */
357         tv->font_name[STRING128 - 1] = '\0';
358 
359         if (tv->overlay_on)
360         {
361             tv_screen_set_op(tv->tv_screen, rop_xor);
362             tv_screen_set_color(tv->tv_screen, tv->cmap_data_visible->overlay_mask);
363         } else
364         {
365             tv_screen_set_op(tv->tv_screen, tv->op);
366             tv_screen_set_color(tv->tv_screen, tv->color);
367         }
368         tv_screen_set_linewidth(tv->tv_screen, tv->linewidth);
369         tv_screen_set_linestyle(tv->tv_screen, tv->linestyle);
370         tv_screen_named_font_set(tv->tv_screen, tv->font_name);
371 
372         tv->draw = link_rm_el(tv->draw);
373         rfree((void *) draw);
374     }
375 }
376 
377 
378 void    (*tv_set_fulldraw(Tv * tv, void (*newfulldraw) ( /* ??? */ ))) ( /* ??? */ )
379 {
380     void    (*oldfulldraw) () = NULL;
381 
382     if (tv)
383     {
384         oldfulldraw = tv->fulldraw;
385         tv->fulldraw = newfulldraw;
386     }
387     return (oldfulldraw);
388 }
389 
390 void    (*tv_set_skeldraw(Tv * tv, void (*newskeldraw) ( /* ??? */ ))) ( /* ??? */ )
391 {
392     void    (*oldskeldraw) () = NULL;
393 
394     if (tv)
395     {
396         oldskeldraw = tv->skeldraw;
397         tv->skeldraw = newskeldraw;
398     }
399     return (oldskeldraw);
400 }
401 
402 void    (*tv_set_backdraw(Tv * tv, void (*newbackdraw) ( /* ??? */ ))) ( /* ??? */ )
403 {
404     void    (*oldbackdraw) () = NULL;
405 
406     if (tv)
407     {
408         tv->backsave = true;
409         oldbackdraw = tv->backdraw;
410         tv->backdraw = newbackdraw;
411     }
412     return (oldbackdraw);
413 }
414 
415 
416 void   *tv_set_drawdata(Tv * tv, void *newdrawdata)
417 {
418     void   *olddrawdata = NULL;
419 
420     if (tv)
421     {
422         olddrawdata = tv->drawdata;
423         tv->drawdata = newdrawdata;
424     }
425     return (olddrawdata);
426 }
427 
428 
429 int     tv_set_zoomlevel(Tv * tv, int zoomlevel)
430 {
431     int     oldzoomlevel = 0;
432 
433     if (tv)
434     {
435         oldzoomlevel = tv->zoomlevel;
436         tv->zoomlevel = zoomlevel;
437     }
438     return (oldzoomlevel);
439 }
440 
441 void    tv_set_paint_mode(Tv * tv, int mode)
442 {
443     if (tv == NULL)
444         return;
445 
446     tv->paint_mode = mode;
447 }
448 
449 void    tv_get_text_extent(Tv * tv, char *string, int *xmin, int *xmax, int *ymin, int *ymax)
450 {
451     if (tv && tv->tv_screen)
452     {
453         tv_screen_get_text_extent(tv->tv_screen, tv->font_name, string,
454                                   xmin, xmax, ymin, ymax);
455     } else
456     {
457         *xmin = *xmax = *ymin = *ymax = 0;
458     }
459 }
460 

~ [ 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.