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

Linux Cross Reference
Tina4/src/tv/tv_props.c

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

  1 /** @(#)Drawing properties of a tv (background, color, font, line width etc).
  2  **/
  3 #include <math.h>
  4 #include <stdio.h>
  5 #include <string.h>
  6 #include <limits.h>
  7 #include <tina/sys.h>
  8 #include <tina/sysfuncs.h>
  9 #include <tina/math.h>
 10 #include <tina/tv.h>
 11 #include <tina/tvfuncs.h>
 12 #include <tina/tw_Xfuncs.h>
 13 
 14 /* EXTERNS */
 15 extern void tv_screen_set_linewidth();
 16 extern void tv_screen_named_font_set();
 17 extern void tv_screen_background_set();
 18 extern void tv_screen_set_op();
 19 
 20 
 21 /* Set the background color of a tv to Tina pixel (index in
 22  * cmap_lookup) given */
 23 void    tv_background_set(Tv * tv, Tina_pixel color)
 24 {
 25     if (tv && tv->tv_screen 
 26         && tv->cmap_data_visible->type == cmap_type_dynamic)
 27     {
 28         tv_screen_background_set(tv->tv_screen,
 29                                tv->cmap_data_visible->std_lut[color]);
 30     }
 31 }
 32 
 33 
 34 /* Set the foreground color of a tv to X pixel given at 'color' in tv's
 35  * std_lut */
 36 void    tv_color_set(Tv * tv, Tina_pixel color)
 37 {
 38     if (tv)
 39         tv->color = color;
 40     if (tv && tv->tv_screen && tv->cmap_data_visible )
 41     {
 42         tv_screen_color_set(tv->tv_screen, tv->cmap_data_visible->std_lut[color]);
 43     }
 44 }
 45 
 46 /* Set the foreground color of a tv to X pixel given.  NOT using tv's
 47  * std_lut */
 48 void    tv_color_reset(Tv * tv, Tina_pixel color)
 49 {
 50     if (tv && tv->tv_screen)
 51     {
 52         tv_screen_color_set(tv->tv_screen, color);
 53     }
 54 }
 55 
 56 /* Find the pixel value at point pos */
 57 int     tv_get_pixel(Tv * tv, Ipos pos)
 58 {
 59     if (tv == NULL || tv->tv_screen == NULL)
 60         return (0);
 61     return (tv_screen_get_pixel(tv->tv_screen, pos));
 62 }
 63 
 64 /* Find the approximate grey level of the pixel at point pos */
 65 Tina_pixel tv_get_grey(Tv * tv, Ipos pos)
 66 {
 67     Tina_pixel color = 0;
 68     unsigned long min_diff = ULONG_MAX;
 69     unsigned long pixel;
 70     int     i;
 71 
 72     if (tv == NULL || tv->tv_screen == NULL)
 73         return (0);
 74 
 75     pixel = tv_screen_get_pixel(tv->tv_screen, pos);
 76 
 77     /* Find the closest match in cmap_lookup to the pixel */
 78     for (i = 0; i < CMAPLOOKUPSIZE; i++)
 79     {
 80         int     diff = abs((int) (tv->cmap_data_visible->std_lut[i] - pixel));
 81 
 82         if (diff < min_diff)
 83         {
 84             min_diff = diff;
 85             color = i;
 86         }
 87     }
 88 
 89     return (color);
 90 }
 91 
 92 
 93 /* Set the foreground color of a tv to X pixel given */
 94 void    tv_set_color(Tv * tv, Tina_pixel color)
 95 {
 96     tv_color_set(tv, color);
 97 }
 98 
 99 int     tv_color_get(Tv * tv)
100 {
101     return (tv->color);
102 }
103 
104 int     tv_get_color(Tv * tv)
105 {
106     return (tv->color);
107 }
108 
109 int     tv_set_op(Tv * tv, int op)
110 {
111     int     oldop = 0;
112 
113     if (tv && tv->tv_screen)
114     {
115         oldop = tv->op;
116         tv->op = op;
117         if (!tv->overlay_on)
118         {
119             tv_screen_set_op(tv->tv_screen, op);
120         }
121     }
122     return (oldop);
123 }
124 
125 int     tv_get_op(Tv * tv)
126 {
127     return (tv->op);
128 }
129 
130 
131 int     tv_set_linewidth(Tv * tv, int width)
132 {
133     int     oldwidth = 0;
134 
135     if (tv)
136     {
137         oldwidth = tv->linewidth;
138         tv->linewidth = width;
139         tv_screen_set_linewidth(tv->tv_screen, width);
140     }
141     return (oldwidth);
142 }
143 
144 
145 int     tv_get_linewidth(Tv * tv)
146 {
147     return (tv->linewidth);
148 }
149 
150 
151 int     tv_set_linestyle(Tv * tv, int style)
152 {
153     int     oldstyle = 0;
154 
155     if (tv && tv->tv_screen)
156     {
157         oldstyle = tv->linestyle;
158         tv->linestyle = style;
159         tv_screen_set_linestyle(tv->tv_screen, style);
160     }
161     return (oldstyle);
162 }
163 
164 int     tv_get_linestyle(Tv * tv)
165 {
166     return (tv->linestyle);
167 }
168 
169 
170 
171 /* Set a named font in a tv and in the tv_screen it is installed on. NB
172  * MAX */
173 /* LENGTH OF font_name IS 128 */
174 void    tv_named_font_set(Tv * tv, char *font_name)
175 {
176     if (tv && tv->tv_screen)
177     {
178         (void) strncpy(tv->font_name, font_name, STRING128);
179         /* Ensure tv->font_name is NULL terminated */
180 
181         tv->font_name[STRING128 - 1] = '\0';
182 
183         tv_screen_named_font_set(tv->tv_screen, tv->font_name);
184     }
185 }
186 
187 
188 char   *tv_named_font_get(Tv * tv)
189 {
190     return (tv ? tv->font_name : "");
191 }
192 
193 
194 void    tv_save_draw(Tv * tv)
195 {
196     Tv_draw *draw;
197 
198     if (tv)
199     {
200         draw = (Tv_draw *) ts_ralloc(Tv_draw);
201         draw->overlay_on = tv->overlay_on;
202         draw->color = tv->color;
203         draw->op = tv->op;
204         draw->linewidth = tv->linewidth;
205         draw->linestyle = tv->linestyle;
206         (void) strncpy(draw->font_name, tv->font_name, STRING128);
207         /* Ensure tv->font_name is NULL terminated */
208         draw->font_name[STRING128 - 1] = '\0';
209 
210         tv->draw = ref_addtostart(tv->draw, (void *) draw, (int) rfree);
211     }
212 }
213 
214 
215 void    tv_set_overlay(Tv * tv)
216 {
217     if (tv && tv->tv_screen && tv->cmap_data_visible)
218     {
219         tv_save_draw(tv);
220         tv->overlay_on = true;
221         tv_screen_set_linewidth(tv->tv_screen, 0);
222         tv_screen_set_op(tv->tv_screen, rop_xor);
223         tv_screen_set_color(tv->tv_screen, tv->cmap_data_visible->overlay_mask);
224     }
225 }
226 
227 
228 
229 /* Reset the rgb's in a cell in a tv_screen's colormap */
230 void    tv_reset_color(Tv * tv, Tina_pixel color, int r, int g, int b)
231 {
232     extern void tv_screen_reset_color();
233 
234     if (tv && tv->tv_screen && tv->cmap_data_visible) 
235     {
236         if (tv->cmap_data_visible->type == cmap_type_dynamic)
237             tv_screen_reset_color(tv->tv_screen,
238                             (tv->cmap_data_visible->std_lut[color]),
239                               r, g, b);
240          else
241             tv_screen_alloc_color(tv->tv_screen,
242                             &(tv->cmap_data_visible->std_lut[color]),
243                               r, g, b);
244     }
245 }
246 
247 /* Reset the rgb's in a cell in a tv_screen's colormap */
248 void    tv_reset_named_color(Tv * tv, Tina_pixel color, char *color_name)
249 {
250     extern void tv_screen_reset_named_color();
251 
252     if (tv && tv->tv_screen && tv->cmap_data_visible->std_lut 
253         && tv->cmap_data_visible->type == cmap_type_dynamic)
254     {
255         tv_screen_reset_named_color(tv->tv_screen, tv->cmap_data_visible->std_lut[color],
256                                     color_name);
257 
258     }
259 }
260 
261 
262 void    tv_reset_draw(Tv * tv)
263 {
264     Tv_draw *draw;
265 
266     if (tv && tv->draw && tv->tv_screen)
267     {
268         draw = (Tv_draw *) tv->draw->to;
269         tv->overlay_on = draw->overlay_on;
270         tv->color = draw->color;
271         tv->op = draw->op;
272         tv->linewidth = draw->linewidth;
273         tv->linestyle = draw->linestyle;
274         (void) strncpy(tv->font_name, draw->font_name, STRING128);
275         /* Ensure tv->font_name is NULL terminated */
276         tv->font_name[STRING128 - 1] = '\0';
277 
278         if (tv->overlay_on)
279         {
280             tv_screen_set_op(tv->tv_screen, rop_xor);
281             tv_screen_set_color(tv->tv_screen, tv->cmap_data_visible->overlay_mask);
282         } else
283         {
284             tv_screen_set_op(tv->tv_screen, tv->op);
285             tv_screen_set_color(tv->tv_screen, tv->color);
286         }
287         tv_screen_set_linewidth(tv->tv_screen, tv->linewidth);
288         tv_screen_set_linestyle(tv->tv_screen, tv->linestyle);
289         tv_screen_named_font_set(tv->tv_screen, tv->font_name);
290 
291         tv->draw = link_rm_el(tv->draw);
292         rfree((void *) draw);
293     }
294 }
295 
296 
297 void    (*tv_set_fulldraw(Tv * tv, void (*newfulldraw) ( /* ??? */ ))) ( /* ??? */ )
298 {
299     void    (*oldfulldraw) () = NULL;
300 
301     if (tv)
302     {
303         oldfulldraw = tv->fulldraw;
304         tv->fulldraw = newfulldraw;
305     }
306     return (oldfulldraw);
307 }
308 
309 void    (*tv_set_skeldraw(Tv * tv, void (*newskeldraw) ( /* ??? */ ))) ( /* ??? */ )
310 {
311     void    (*oldskeldraw) () = NULL;
312 
313     if (tv)
314     {
315         oldskeldraw = tv->skeldraw;
316         tv->skeldraw = newskeldraw;
317     }
318     return (oldskeldraw);
319 }
320 
321 void    (*tv_set_backdraw(Tv * tv, void (*newbackdraw) ( /* ??? */ ))) ( /* ??? */ )
322 {
323     void    (*oldbackdraw) () = NULL;
324 
325     if (tv)
326     {
327         tv->backsave = true;
328         oldbackdraw = tv->backdraw;
329         tv->backdraw = newbackdraw;
330     }
331     return (oldbackdraw);
332 }
333 
334 
335 void   *tv_set_drawdata(Tv * tv, void *newdrawdata)
336 {
337     void   *olddrawdata = NULL;
338 
339     if (tv)
340     {
341         olddrawdata = tv->drawdata;
342         tv->drawdata = newdrawdata;
343     }
344     return (olddrawdata);
345 }
346 
347 
348 int     tv_set_zoomlevel(Tv * tv, int zoomlevel)
349 {
350     int     oldzoomlevel = 0;
351 
352     if (tv)
353     {
354         oldzoomlevel = tv->zoomlevel;
355         tv->zoomlevel = zoomlevel;
356     }
357     return (oldzoomlevel);
358 }
359 
360 void    tv_set_paint_mode(Tv * tv, int mode)
361 {
362     if (tv == NULL)
363         return;
364 
365     tv->paint_mode = mode;
366 }
367 
368 void    tv_get_text_extent(Tv * tv, char *string, int *xmin, int *xmax, int *ymin, int *ymax)
369 {
370     if (tv && tv->tv_screen)
371     {
372         tv_screen_get_text_extent(tv->tv_screen, tv->font_name, string,
373                                   xmin, xmax, ymin, ymax);
374     } else
375     {
376         *xmin = *xmax = *ymin = *ymax = 0;
377     }
378 }
379 

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