00001 00002 #ifndef MYX_H___ 00003 #define MYX_H___ 00004 00005 00006 00007 #ifdef __STRICT_ANSI__ 00008 # define inline __inline__ 00009 #endif 00010 #define INLINE inline 00011 00012 00013 #include <stdlib.h> 00014 #include <stdio.h> 00015 #include <stdarg.h> 00016 00017 #include <math.h> 00018 #include <string.h> 00019 #include <locale.h> 00020 #include <limits.h> 00021 00022 #include <unistd.h> 00023 #include <sys/select.h> 00024 #include <sys/time.h> 00025 #include <sys/types.h> 00026 #include <dirent.h> 00027 00028 #include <X11/X.h> 00029 #include <X11/Xlib.h> 00030 #include <X11/Xresource.h> 00031 #include <X11/Xutil.h> 00032 00033 #ifdef _FILE_OFFSET_BITS 00034 #undef _FILE_OFFSET_BITS 00035 #endif 00036 #include <wand/magick-wand.h> 00037 00038 00039 #ifdef BX_AUDIO 00040 # include <SDL_audio.h> 00041 #endif 00042 00043 #define UNUSED __attribute__ ((unused)) 00044 00045 typedef unsigned char UChar; 00046 typedef unsigned long ULong; 00047 typedef unsigned int UInt; 00048 typedef unsigned short UShort; 00049 00050 extern const char * MyX_EventString []; 00051 00052 typedef struct MyX_Channel { 00053 ULong mask, shift, length, max; 00054 } MyX_Channel; 00055 00056 typedef struct MyX_TrueColor 00057 { 00058 MyX_Channel green; 00059 MyX_Channel red; 00060 MyX_Channel blue; 00061 } MyX_TrueColor; 00062 00063 typedef struct MyX_PseudoColor 00064 { 00065 Colormap colormap; 00066 ULong palette [6][6][6]; 00067 XColor samples [256]; 00068 } MyX_PseudoColor; 00069 00070 00071 typedef struct MyX MyX; 00072 00073 typedef void (* MyX_TimerHandler) (MyX * myx, void * data, 00074 struct timeval * expected); 00075 00076 typedef struct MyX_Timer 00077 { 00078 struct timeval expected; 00079 MyX_TimerHandler handler; 00080 void * data; 00081 } MyX_Timer; 00082 00083 #define MYX_MAX_TIMERS 10000 00084 00085 typedef struct MyX_TimerQueue { 00086 ULong nb_timers; 00087 MyX_Timer timers [MYX_MAX_TIMERS]; 00088 } MyX_TimerQueue; 00089 00090 00091 struct MyX { 00092 Display * display; 00093 Window root; 00094 int screen; 00095 GC gc, gc_sys; 00096 XFontStruct * font_fixed, * font_variable; 00097 int do_loop; 00098 Visual * visual; 00099 UInt depth; 00100 MyX_PseudoColor pseudoColor; 00101 MyX_TrueColor trueColor; 00102 XContext dataContext, handlersContext; 00103 MyX_TimerQueue timerQueue; 00104 int ignoreAutoRepeat; 00105 }; 00106 00107 typedef void (* MyX_Handler) (MyX * myx, XEvent * event, void * data); 00108 00109 #define MYX_MAX_EVENTS LASTEvent 00110 00111 typedef struct MyX_Handlers { 00112 MyX_Handler table [MYX_MAX_EVENTS]; 00113 } MyX_Handlers; 00114 00115 typedef struct MyX_Sprite 00116 { 00117 Pixmap image, mask; 00118 UInt width, height; 00119 int x_flip, y_flip; 00120 } MyX_Sprite; 00121 00122 typedef struct MyX_Geometry { 00123 Window root; 00124 int x, y; 00125 UInt w, h; 00126 UInt border, depth; 00127 } MyX_Geometry; 00128 00129 typedef struct MyX_Tree { 00130 Window root, parent, * children; 00131 UInt nb_children; 00132 } MyX_Tree; 00133 00134 int MyX_Init (MyX * myx, char * displayName); 00135 int MyX_InitColor (MyX * myx); 00136 void MyX_Clean (MyX * myx); 00137 00138 int MyX_LoadImage (MyX * myx, char filename [], 00139 XImage ** img, XImage ** msk, 00140 UInt * width, UInt * height); 00141 00142 void MyX_PutImage (MyX* myx, Drawable d, GC gc, XImage* img, int x, int y); 00143 00144 void MyX_XFlipImage (XImage * img); 00145 void MyX_YFlipImage (XImage * img); 00146 void MyX_XYFlipImage(XImage * img); 00147 00148 int MyX_LoadPixmap (MyX * myx, char filename [], 00149 Pixmap * img, Pixmap * msk, 00150 UInt * width, UInt * height); 00151 00152 void MyX_PutPixmap (MyX * myx, Drawable d, GC gc, Pixmap p, int x, int y); 00153 00154 void MyX_XFlipPixmap (MyX * myx, Pixmap p); 00155 void MyX_YFlipPixmap (MyX * myx, Pixmap p); 00156 void MyX_XYFlipPixmap(MyX * myx, Pixmap p); 00157 00158 int MyX_LoadSprite (MyX * myx, char filename [], MyX_Sprite * s, int transp); 00159 void MyX_FreeSprite (MyX * myx, MyX_Sprite * s); 00160 00161 void MyX_PutSprite (MyX* myx, Drawable d, GC gc, 00162 MyX_Sprite * s, int x, int y); 00163 00164 void MyX_PutFxSprite (MyX * myx, Drawable d, GC gc, UInt fx, 00165 MyX_Sprite * s, int x, int y); 00166 00167 void MyX_XFlipSprite (MyX * myx, MyX_Sprite * s, int x_flip); 00168 void MyX_YFlipSprite (MyX * myx, MyX_Sprite * s, int y_flip); 00169 void MyX_XYFlipSprite(MyX * myx, MyX_Sprite * s, int x_flip, int y_flip); 00170 00171 00172 INLINE double MyRound (double x); 00173 INLINE ULong MyX_RGB (MyX * myx, UChar r, UChar g, UChar b); 00174 INLINE ULong MyX_RGBF (MyX * myx, double r, double g, double b); 00175 INLINE ULong MyX_AverageColors (MyX * myx, ULong p1, ULong p2); 00176 INLINE ULong MyX_BlendColors (MyX * myx, ULong p1, double alpha, ULong p2); 00177 00178 int MyX_CallWithinDelay (MyX * myx, MyX_TimerHandler handler, void * data, 00179 struct timeval * delay, struct timeval * from); 00180 00181 00182 void MyX_WaitEvents (MyX * myx, struct timeval * max_delay); 00183 00184 void MyX_EventLoop (MyX * myx); 00185 00186 void MyX_IgnoreAutoRepeat (MyX * myx, int ignoreAutoRepeat); 00187 00188 void MyX_InitHandlers (MyX_Handlers * hanlders); 00189 00190 void MyX_SetHandler (MyX_Handlers * handlers, 00191 int eventType, MyX_Handler handler); 00192 00193 Window MyX_CreateWindow (MyX * myx, MyX_Handlers * handlers, void * data, 00194 Window parent, int x, int y, UInt w, UInt h); 00195 00196 void MyX_GetGeometry (MyX * myx, Drawable d, MyX_Geometry * g); 00197 void MyX_QueryTree (MyX * myx, Window w, MyX_Tree * t); 00198 00199 void MyX_DestroyWindowContext (MyX * myx, Window window); 00200 00201 void MyX_SetWindowHandlers (MyX * myx, Window w, MyX_Handlers * h); 00202 MyX_Handlers * MyX_GetWindowHandlers (MyX * myx, Window window); 00203 void MyX_SetWindowData (MyX * myx, Window window, void * data); 00204 void * MyX_GetWindowData (MyX * myx, Window window); 00205 00206 #ifndef M_PI 00207 # define M_PI 3.14159265358979323846 00208 #endif 00209 00210 #ifndef timerisset 00211 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 00212 #endif 00213 00214 #ifndef timerclear 00215 # define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 00216 #endif 00217 00218 #ifndef timercmp 00219 #define timercmp(a,b,CMP) \ 00220 (((a)->tv_sec == (b)->tv_sec) ? \ 00221 ((a)->tv_usec CMP (b)->tv_usec) : \ 00222 ((a)->tv_sec CMP (b)->tv_sec)) 00223 #endif 00224 00225 #ifndef timeradd 00226 #define timeradd(a,b,result) \ 00227 do { \ 00228 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 00229 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 00230 if ((result)->tv_usec >= 1000000) \ 00231 { \ 00232 ++(result)->tv_sec; \ 00233 (result)->tv_usec -= 1000000; \ 00234 } \ 00235 } while (0) 00236 #endif 00237 00238 #ifndef timersub 00239 #define timersub(a,b,result) \ 00240 do { \ 00241 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 00242 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 00243 if ((result)->tv_usec < 0) { \ 00244 --(result)->tv_sec; \ 00245 (result)->tv_usec += 1000000; \ 00246 } \ 00247 } while (0) 00248 #endif 00249 00250 #endif