1 /********************************************************************************
2 *                                                                               *
3 *                        G I F   C u r s o r   O b j e c t                      *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 2000,2005 by Daniel Gehriger.   All Rights Reserved.            *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXGIFCursor.cpp,v 1.29 2005/01/16 16:06:07 fox Exp $                     *
23 ********************************************************************************/
24 #include "xincs.h"
25 #include "fxver.h"
26 #include "fxdefs.h"
27 #include "FXHash.h"
28 #include "FXThread.h"
29 #include "FXStream.h"
30 #include "FXMemoryStream.h"
31 #include "FXString.h"
32 #include "FXSize.h"
33 #include "FXPoint.h"
34 #include "FXRectangle.h"
35 #include "FXSettings.h"
36 #include "FXRegistry.h"
37 #include "FXApp.h"
38 #include "FXGIFCursor.h"
39 
40 
41 /*
42   Notes:
43   - Tossed old code now that FXCursor has an RGBA representation.
44   - Now uses actual alpha color from the GIF file.
45   - Need function to force alpha channel based on transparent color.
46   - Optionally let system guess a transparancy color based on the corners.
47   - If that doesn't work, you can force a specific transparency color.
48 */
49 
50 
51 using namespace FX;
52 
53 /*******************************************************************************/
54 
55 namespace FX {
56 
57 
58 // Suggested file extension
59 const FXchar FXGIFCursor::fileExt[]="gif";
60 
61 
62 // Object implementation
63 FXIMPLEMENT(FXGIFCursor,FXCursor,NULL,0)
64 
65 
66 // Constructor
FXGIFCursor(FXApp * a,const void * pix,FXint hx,FXint hy)67 FXGIFCursor::FXGIFCursor(FXApp* a,const void *pix,FXint hx,FXint hy):FXCursor(a,NULL,0,0,0,0){
68   if(pix){
69     FXMemoryStream ms;
70     ms.open(FXStreamLoad,(FXuchar*)pix);
71     fxloadGIF(ms,data,width,height);
72     hotx=FXCLAMP(0,hx,width-1);
73     hoty=FXCLAMP(0,hy,height-1);
74     options|=CURSOR_OWNED;
75     ms.close();
76     }
77   }
78 
79 
80 // Save object to stream
savePixels(FXStream & store) const81 FXbool FXGIFCursor::savePixels(FXStream& store) const {
82   if(fxsaveGIF(store,data,width,height)){
83     return TRUE;
84     }
85   return FALSE;
86   }
87 
88 
89 // Load object from stream
loadPixels(FXStream & store)90 FXbool FXGIFCursor::loadPixels(FXStream& store){
91   if(options&CURSOR_OWNED){FXFREE(&data);}
92   if(fxloadGIF(store,data,width,height)){
93     options|=CURSOR_OWNED;
94     return TRUE;
95     }
96   return FALSE;
97   }
98 
99 }
100 
101 
102