NCBI C Toolkit Cross Reference

C/vibrant/imagelst.c


  1 /*  imagelst.c
  2 * ===========================================================================
  3 *
  4 *                            PUBLIC DOMAIN NOTICE                          
  5 *               National Center for Biotechnology Information
  6 *                                                                          
  7 *  This software/database is a "United States Government Work" under the   
  8 *  terms of the United States Copyright Act.  It was written as part of    
  9 *  the author's official duties as a United States Government employee and 
 10 *  thus cannot be copyrighted.  This software/database is freely available 
 11 *  to the public for use. The National Library of Medicine and the U.S.    
 12 *  Government have not placed any restriction on its use or reproduction.  
 13 *                                                                          
 14 *  Although all reasonable efforts have been taken to ensure the accuracy  
 15 *  and reliability of the software and data, the NLM and the U.S.          
 16 *  Government do not and cannot warrant the performance or results that    
 17 *  may be obtained by using this software or data. The NLM and the U.S.    
 18 *  Government disclaim all warranties, express or implied, including       
 19 *  warranties of performance, merchantability or fitness for any particular
 20 *  purpose.                                                                
 21 *                                                                          
 22 *  Please cite the author in any work or product based on this material.   
 23 *
 24 * ===========================================================================
 25 *
 26 * File Name:  imagelst.c
 27 *
 28 * Author:  Vladimir Soussov
 29 *   
 30 * File Description:  image list
 31 *
 32 *
 33 * $Log: imagelst.c,v $
 34 * Revision 1.4  2001/03/28 01:33:52  juran
 35 * Added "continue" to "for (...);" to avoid warnings.
 36 *
 37 * Revision 1.3  1998/07/02 18:24:32  vakatov
 38 * Cleaned the code & made it pass through the C++ compilation
 39 *
 40 * Revision 1.2  1998/04/01 17:44:03  soussov
 41 * changed tp include <>
 42 *
 43 * Revision 1.1  1998/03/31 21:22:23  sirotkin
 44 * With Vladimir - moved from distrib/internal/taxonomy/tree
 45 *
 46 * Revision 6.0  1997/08/25 18:29:43  madden
 47 * Revision changed to 6.0
 48 *
 49 * Revision 1.2  1997/06/03 17:59:45  soussov
 50 * Minor changes for SGI C-compiler
 51 *
 52 * Revision 1.1  1997/05/30 16:16:13  soussov
 53 * Set of files for ncbitree library
 54 *
 55 * Revision 1.1  1997/05/29 20:44:22  soussov
 56 * Initial version of tree library
 57 *
 58 *
 59 */
 60 
 61 #include <imagelst.h>
 62 
 63 _ImageListPtr ilst_new(Uint2 n, Uint2 size_x, Uint2 size_y)
 64 {
 65     _ImageListPtr il;
 66     Uint2 i;
 67 
 68     il= (_ImageListPtr) MemNew(sizeof(_ImageList));
 69     if(il == NULL) return NULL;
 70     if(n == 0) n= NOF_IMG_DEFAULT;
 71 
 72     if((il->icon= (Image*) MemNew(n*sizeof(Image))) == NULL) {
 73         MemFree(il);
 74         return NULL;
 75     }
 76 
 77     il->nof_images= n;
 78     il->img_size_x= size_x;
 79     il->img_size_y= size_y;
 80 
 81     for (i = 0; i < n; il->icon[i++] = NULL) continue;
 82 
 83     return il;
 84 }
 85 
 86 /*****************************************************
 87  * free image list
 88  */
 89 void ilst_free(_ImageListPtr il)
 90 {
 91     Uint2 i;
 92 
 93     for(i= 0; i < il->nof_images; i++) {
 94         if(il->icon[i] != NULL) {
 95             DeleteImage(il->icon[i]);
 96         }
 97     }
 98 
 99     MemFree(il->icon);
100     MemFree(il);
101 }
102 
103 /*****************************************************
104  * add image to image list
105  * this function adds new image to image list using either img or file
106  */
107 Uint2 ilst_add(_ImageListPtr il, Image img, CharPtr fileName, ImageFileFormat f)
108 {
109     Uint2 i, k;
110 
111     for(i= 0; i < il->nof_images; i++) {
112         if(il->icon[i] == NULL) break;
113     }
114 
115     if(i >= il->nof_images) {
116         /* we need more memory */
117         i= il->nof_images;
118         il->nof_images+= i/2;
119         if ((il->icon= (Image*) MemMore(il->icon, il->nof_images*sizeof(Image))) == NULL) return 0xFFFF;
120         for(k= i; k < il->nof_images; il->icon[k++]= NULL) continue;
121     }
122 
123 
124     if((img == NULL) && (fileName != NULL)) {
125         switch(f) {
126         case IMAGE_GIF: img= LoadImageGIF(fileName); break;
127         case IMAGE_BMP: img= LoadImageBMP(fileName); break;
128         }
129     }
130 
131     il->icon[i]= img;
132     return i;
133 }
134 
135 /*****************************************************
136  * replace image in image list
137  */
138 Boolean ilst_replace(_ImageListPtr il, Uint2 i_ind, Image img, CharPtr fileName, ImageFileFormat f)
139 {
140 
141     if(i_ind >= il->nof_images) return FALSE;
142 
143     if(il->icon[i_ind] != NULL) DeleteImage(il->icon[i_ind]);
144 
145     if((img == NULL) && (fileName != NULL)) {
146         switch(f) {
147         case IMAGE_GIF: img= LoadImageGIF(fileName); break;
148         case IMAGE_BMP: img= LoadImageBMP(fileName); break;
149         }
150     }
151 
152     il->icon[i_ind]= img;
153 
154     return TRUE;
155 }
156 
157 /*****************************************************
158  * remove image from the list
159  */
160 void ilst_remove(_ImageListPtr il, Uint2 i_ind)
161 {
162     if((il != NULL) && (i_ind < il->nof_images) && (il->icon[i_ind] != NULL)) {
163         DeleteImage(il->icon[i_ind]);
164         il->icon[i_ind] = NULL;
165     }
166 }
167     
168 /*****************************************************
169  * get image size
170  */
171 Boolean ilst_size(_ImageListPtr il, Uint2 i_ind, Uint2Ptr x, Uint2Ptr y)
172 {
173     if(il == (_ImageListPtr)0x8) {
174         *x= *y= 8;
175     }
176     else if(il != NULL) {
177         *x= il->img_size_x;
178         *y= il->img_size_y;
179     }
180 
181     if((*x != 0) && (*y != 0)) return TRUE;
182 
183     if((il != NULL) && (i_ind < il->nof_images) && (il->icon[i_ind] != NULL)) {
184         GetImageSize(il->icon[i_ind], x, y);
185         return TRUE;
186     }
187 
188     return FALSE;
189 }
190 
191 static void draw_check(Int2 x0, Int2 y0)
192 {
193     Black();
194     Solid();
195     MoveTo(x0, y0+3);
196     LineTo(x0+1, y0+3);
197     LineTo(x0+1, y0+5);
198     MoveTo(x0+2, y0+4);
199     LineTo(x0+2, y0+7);
200     LineTo(x0+3, y0+7);
201     LineTo(x0+3, y0+5);
202     LineTo(x0+4, y0+5);
203     LineTo(x0+4, y0+3);
204     MoveTo(x0+5, y0+4);
205     LineTo(x0+5, y0+2);
206     MoveTo(x0+6, y0+1);
207     LineTo(x0+6, y0+3);
208     MoveTo(x0+7, y0);
209     LineTo(x0+7, y0+1);
210 }
211 
212 static Boolean draw8(Uint2 ind, Int2 x, Int2 y)
213 {
214         draw_check(x, y);
215         return TRUE;
216 }
217 
218 /*****************************************************
219  * draw image
220  */
221 Boolean ilst_draw(_ImageListPtr il, Uint2 i_ind, Int2 x, Int2 y)
222 {
223     if(il == (_ImageListPtr)0x8) return draw8(i_ind, x, y);
224 
225     if((il != NULL) && (i_ind < il->nof_images) && (il->icon[i_ind] != NULL)) {
226         PoinT p;
227 
228         p.x= x;
229         p.y= y;
230 
231         ImageShow(il->icon[i_ind], p);
232 
233         return TRUE;
234     }
235     return FALSE;
236 }
237 
238         
239     
240     
241 

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.