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

Linux Cross Reference
Tina5/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 at '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 /* Set the foreground color of a tv to X pixel given.  NOT using tv's
100  * std_lut */
101 void    tv_color_reset(Tv * tv, Tina_pixel color)
102 {
103     if (tv && tv->tv_screen)
104     {
105         tv_screen_color_set(tv->tv_screen, color);
106     }
107 }
108 
109 /* Find the pixel value at point pos */
110 int     tv_get_pixel(Tv * tv, Ipos pos)
111 {
112     if (tv == NULL || tv->tv_screen == NULL)
113         return (0);
114     return (tv_screen_get_pixel(tv->tv_screen, pos));
115 }
116 
117 /* Find the approximate grey level of the pixel at point pos */
118 Tina_pixel tv_get_grey(Tv * tv, Ipos pos)
119 {
120     Tina_pixel color = 0;
121     unsigned long min_diff = ULONG_MAX;
122     unsigned long pixel;
123     int     i;
124 
125     if (tv == NULL || tv->tv_screen == NULL)
126         return (0);
127 
128     pixel = tv_screen_get_pixel(tv->tv_screen, pos);
129 
130     /* Find the closest match in cmap_lookup to the pixel */
131     for (i = 0; i < CMAPLOOKUPSIZE; i++)
132     {
133         int     diff = abs((int) (tv->cmap_data_visible->std_lut[i] - pixel));
134 
135         if (diff < min_diff)
136         {
137             min_diff = diff;
138             color = i;
139         }
140     }
141 
142     return (color);
143 }
144 
145 
146 /* Set the foreground color of a tv to X pixel given */
147 void    tv_set_color(Tv * tv, Tina_pixel color)
148 {
149     tv_color_set(tv, color);
150 }
151 
152 int     tv_color_get(Tv * tv)
153 {
154     return (tv->color);
155 }
156 
157 int     tv_get_color(Tv * tv)
158 {
159     return (tv->color);
160 }
161 
162 int     tv_set_op(Tv * tv, int op)
163 {
164     int     oldop = 0;
165 
166     if (tv && tv->tv_screen)
167     {
168         oldop = tv->op;
169         tv->op = op;
170         if (!tv->overlay_on)
171         {
172             tv_screen_set_op(tv->tv_screen, op);
173         }
174     }
175     return (oldop);
176 }
177 
178 int     tv_get_op(Tv * tv)
179 {
180     return (tv->op);
181 }
182 
183 
184 int     tv_set_linewidth(Tv * tv, int width)
185 {
186     int     oldwidth = 0;
187 
188     if (tv)
189     {
190         oldwidth = tv->linewidth;
191         tv->linewidth = width;
192         tv_screen_set_linewidth(tv->tv_screen, width);
193     }
194     return (oldwidth);
195 }
196 
197 
198 int     tv_get_linewidth(Tv * tv)
199 {
200     return (tv->linewidth);
201 }
202 
203 
204 int     tv_set_linestyle(Tv * tv, int style)
205 {
206     int     oldstyle = 0;
207 
208     if (tv && tv->tv_screen)
209     {
210         oldstyle = tv->linestyle;
211         tv->linestyle = style;
212         tv_screen_set_linestyle(tv->tv_screen, style);
213     }
214     return (oldstyle);
215 }
216 
217 int     tv_get_linestyle(Tv * tv)
218 {
219     return (tv->linestyle);
220 }
221 
222 
223 
224 /* Set a named font in a tv and in the tv_screen it is installed on. NB
225  * MAX */
226 /* LENGTH OF font_name IS 128 */
227 void    tv_named_font_set(Tv * tv, char *font_name)
228 {
229     if (tv && tv->tv_screen)
230     {
231         (void) strncpy(tv->font_name, font_name, STRING128);
232         /* Ensure tv->font_name is NULL terminated */
233 
234         tv->font_name[STRING128 - 1] = '\0';
235 
236         tv_screen_named_font_set(tv->tv_screen, tv->font_name);
237     }
238 }
239 
240 
241 char   *tv_named_font_get(Tv * tv)
242 {
243     return (tv ? tv->font_name : "");
244 }
245 
246 
247 void    tv_save_draw(Tv * tv)
248 {
249     Tv_draw *draw;
250 
251     if (tv)
252     {
253         draw = (Tv_draw *) ts_ralloc(Tv_draw);
254         draw->overlay_on = tv->overlay_on;
255         draw->color = tv->color;
256         draw->op = tv->op;
257         draw->linewidth = tv->linewidth;
258         draw->linestyle = tv->linestyle;
259         (void) strncpy(draw->font_name, tv->font_name, STRING128);
260         /* Ensure tv->font_name is NULL terminated */
261         draw->font_name[STRING128 - 1] = '\0';
262 
263         tv->draw = ref_addtostart(tv->draw, (void *) draw, (int) rfree);
264     }
265 }
266 
267 
268 void    tv_set_overlay(Tv * tv)
269 {
270     if (tv && tv->tv_screen && tv->cmap_data_visible)
271     {
272         tv_save_draw(tv);
273         tv->overlay_on = true;
274         tv_screen_set_linewidth(tv->tv_screen, 0);
275         tv_screen_set_op(tv->tv_screen, rop_xor);
276         tv_screen_set_color(tv->tv_screen, tv->cmap_data_visible->overlay_mask);
277     }
278 }
279 
280 
281 
282 /* Reset the rgb's in a cell in a tv_screen's colormap */
283 void    tv_reset_color(Tv * tv, Tina_pixel color, int r, int g, int b)
284 {
285     extern void tv_screen_reset_color();
286 
287     if (tv && tv->tv_screen && tv->cmap_data_visible) 
288     {
289         if (tv->cmap_data_visible->type == cmap_type_dynamic)
290             tv_screen_reset_color(tv->tv_screen,
291                             (tv->cmap_data_visible->std_lut[color]),
292                               r, g, b);
293          else
294             tv_screen_alloc_color(tv->tv_screen,
295                                   /* warning: passing argument 2 of 'tv_screen_alloc_color' from incompatible pointer type */
296                             &(tv->cmap_data_visible->std_lut[color]),
297                               r, g, b);
298     }
299 }
300 
301 /* Reset the rgb's in a cell in a tv_screen's colormap */
302 void    tv_reset_named_color(Tv * tv, Tina_pixel color, char *color_name)
303 {
304     extern void tv_screen_reset_named_color();
305 
306     if (tv && tv->tv_screen && tv->cmap_data_visible->std_lut 
307         && tv->cmap_data_visible->type == cmap_type_dynamic)
308     {
309         tv_screen_reset_named_color(tv->tv_screen, tv->cmap_data_visible->std_lut[color],
310                                     color_name);
311 
312     }
313 }
314 
315 
316 void    tv_reset_draw(Tv * tv)
317 {
318     Tv_draw *draw;
319 
320     if (tv && tv->draw && tv->tv_screen)
321     {
322         draw = (Tv_draw *) tv->draw->to;
323         tv->overlay_on = draw->overlay_on;
324         tv->color = draw->color;
325         tv->op = draw->op;
326         tv->linewidth = draw->linewidth;
327         tv->linestyle = draw->linestyle;
328         (void) strncpy(tv->font_name, draw->font_name, STRING128);
329         /* Ensure tv->font_name is NULL terminated */
330         tv->font_name[STRING128 - 1] = '\0';
331 
332         if (tv->overlay_on)
333         {
334             tv_screen_set_op(tv->tv_screen, rop_xor);
335             tv_screen_set_color(tv->tv_screen, tv->cmap_data_visible->overlay_mask);
336         } else
337         {
338             tv_screen_set_op(tv->tv_screen, tv->op);
339             tv_screen_set_color(tv->tv_screen, tv->color);
340         }
341         tv_screen_set_linewidth(tv->tv_screen, tv->linewidth);
342         tv_screen_set_linestyle(tv->tv_screen, tv->linestyle);
343         tv_screen_named_font_set(tv->tv_screen, tv->font_name);
344 
345         tv->draw = link_rm_el(tv->draw);
346         rfree((void *) draw);
347     }
348 }
349 
350 
351 void    (*tv_set_fulldraw(Tv * tv, void (*newfulldraw) ( /* ??? */ ))) ( /* ??? */ )
352 {
353     void    (*oldfulldraw) () = NULL;
354 
355     if (tv)
356     {
357         oldfulldraw = tv->fulldraw;
358         tv->fulldraw = newfulldraw;
359     }
360     return (oldfulldraw);
361 }
362 
363 void    (*tv_set_skeldraw(Tv * tv, void (*newskeldraw) ( /* ??? */ ))) ( /* ??? */ )
364 {
365     void    (*oldskeldraw) () = NULL;
366 
367     if (tv)
368     {
369         oldskeldraw = tv->skeldraw;
370         tv->skeldraw = newskeldraw;
371     }
372     return (oldskeldraw);
373 }
374 
375 void    (*tv_set_backdraw(Tv * tv, void (*newbackdraw) ( /* ??? */ ))) ( /* ??? */ )
376 {
377     void    (*oldbackdraw) () = NULL;
378 
379     if (tv)
380     {
381         tv->backsave = true;
382         oldbackdraw = tv->backdraw;
383         tv->backdraw = newbackdraw;
384     }
385     return (oldbackdraw);
386 }
387 
388 
389 void   *tv_set_drawdata(Tv * tv, void *newdrawdata)
390 {
391     void   *olddrawdata = NULL;
392 
393     if (tv)
394     {
395         olddrawdata = tv->drawdata;
396         tv->drawdata = newdrawdata;
397     }
398     return (olddrawdata);
399 }
400 
401 
402 int     tv_set_zoomlevel(Tv * tv, int zoomlevel)
403 {
404     int     oldzoomlevel = 0;
405 
406     if (tv)
407     {
408         oldzoomlevel = tv->zoomlevel;
409         tv->zoomlevel = zoomlevel;
410     }
411     return (oldzoomlevel);
412 }
413 
414 void    tv_set_paint_mode(Tv * tv, int mode)
415 {
416     if (tv == NULL)
417         return;
418 
419     tv->paint_mode = mode;
420 }
421 
422 void    tv_get_text_extent(Tv * tv, char *string, int *xmin, int *xmax, int *ymin, int *ymax)
423 {
424     if (tv && tv->tv_screen)
425     {
426         tv_screen_get_text_extent(tv->tv_screen, tv->font_name, string,
427                                   xmin, xmax, ymin, ymax);
428     } else
429     {
430         *xmin = *xmax = *ymin = *ymax = 0;
431     }
432 }
433 

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