![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * FOX Definitions, Types, and Macros * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: fxdefs.h,v 1.211 2009/01/21 12:35:21 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXDEFS_H 00024 #define FXDEFS_H 00025 00026 00027 /******************************** Definitions ********************************/ 00028 00029 // Truth values 00030 #ifndef TRUE 00031 #define TRUE 1 00032 #endif 00033 #ifndef FALSE 00034 #define FALSE 0 00035 #endif 00036 #ifndef MAYBE 00037 #define MAYBE 2 00038 #endif 00039 #ifndef NULL 00040 #define NULL 0 00041 #endif 00042 00043 // Path separator 00044 #ifdef WIN32 00045 #define PATHSEP '\\' 00046 #define PATHSEPSTRING "\\" 00047 #define PATHLISTSEP ';' 00048 #define PATHLISTSEPSTRING ";" 00049 #define ISPATHSEP(c) ((c)=='\\' || (c)=='/') 00050 #else 00051 #define PATHSEP '/' 00052 #define PATHSEPSTRING "/" 00053 #define PATHLISTSEP ':' 00054 #define PATHLISTSEPSTRING ":" 00055 #define ISPATHSEP(c) ((c)=='/') 00056 #endif 00057 00058 // End Of Line 00059 #ifdef WIN32 00060 #define ENDLINE "\r\n" 00061 #else 00062 #define ENDLINE "\n" 00063 #endif 00064 00065 00066 // For Windows 00067 #ifdef _DEBUG 00068 #ifndef DEBUG 00069 #define DEBUG 00070 #endif 00071 #endif 00072 #ifdef _NDEBUG 00073 #ifndef NDEBUG 00074 #define NDEBUG 00075 #endif 00076 #endif 00077 00078 00079 // Shared library support 00080 #ifdef WIN32 00081 #define FXLOCAL 00082 #define FXEXPORT __declspec(dllexport) 00083 #define FXIMPORT __declspec(dllimport) 00084 #else 00085 #if defined(__GNUC__) && (__GNUC__ >= 4) 00086 #define FXLOCAL __attribute__ ((visibility("hidden"))) 00087 #define FXEXPORT __attribute__ ((visibility("default"))) 00088 #define FXIMPORT 00089 #else 00090 #define FXLOCAL 00091 #define FXEXPORT 00092 #define FXIMPORT 00093 #endif 00094 #endif 00095 00096 // Define FXAPI for DLL builds 00097 #ifdef FOXDLL 00098 #ifdef FOXDLL_EXPORTS 00099 #define FXAPI FXEXPORT 00100 #define FXTEMPLATE_EXTERN 00101 #else 00102 #define FXAPI FXIMPORT 00103 #define FXTEMPLATE_EXTERN extern 00104 #endif 00105 #else 00106 #define FXAPI 00107 #define FXTEMPLATE_EXTERN 00108 #endif 00109 00110 // Callback 00111 #ifdef WIN32 00112 #ifndef CALLBACK 00113 #define CALLBACK __stdcall 00114 #endif 00115 #endif 00116 00117 00118 // Disable some warnings in VC++ 00119 #ifdef _MSC_VER 00120 #pragma warning(disable: 4251) 00121 #pragma warning(disable: 4231) 00122 #pragma warning(disable: 4244) 00123 #endif 00124 00125 00126 // Checking printf and scanf format strings 00127 #if defined(_CC_GNU_) || defined(__GNUG__) || defined(__GNUC__) 00128 #define FX_PRINTF(fmt,arg) __attribute__((format(printf,fmt,arg))) 00129 #define FX_SCANF(fmt,arg) __attribute__((format(scanf,fmt,arg))) 00130 #else 00131 #define FX_PRINTF(fmt,arg) 00132 #define FX_SCANF(fmt,arg) 00133 #endif 00134 00135 00136 // Raw event type 00137 #ifndef WIN32 00138 union _XEvent; 00139 #else 00140 struct tagMSG; 00141 #endif 00142 00143 00144 namespace FX { 00145 00146 00147 // FOX System Defined Selector Types 00148 enum FXSelType { 00149 SEL_NONE, 00150 SEL_KEYPRESS, /// Key pressed 00151 SEL_KEYRELEASE, /// Key released 00152 SEL_LEFTBUTTONPRESS, /// Left mouse button pressed 00153 SEL_LEFTBUTTONRELEASE, /// Left mouse button released 00154 SEL_MIDDLEBUTTONPRESS, /// Middle mouse button pressed 00155 SEL_MIDDLEBUTTONRELEASE, /// Middle mouse button released 00156 SEL_RIGHTBUTTONPRESS, /// Right mouse button pressed 00157 SEL_RIGHTBUTTONRELEASE, /// Right mouse button released 00158 SEL_MOTION, /// Mouse motion 00159 SEL_ENTER, /// Mouse entered window 00160 SEL_LEAVE, /// Mouse left window 00161 SEL_FOCUSIN, /// Focus into window 00162 SEL_FOCUSOUT, /// Focus out of window 00163 SEL_KEYMAP, 00164 SEL_UNGRABBED, /// Lost the grab (Windows) 00165 SEL_PAINT, /// Must repaint window 00166 SEL_CREATE, 00167 SEL_DESTROY, 00168 SEL_UNMAP, /// Window was hidden 00169 SEL_MAP, /// Window was shown 00170 SEL_CONFIGURE, /// Resize 00171 SEL_SELECTION_LOST, /// Widget lost selection 00172 SEL_SELECTION_GAINED, /// Widget gained selection 00173 SEL_SELECTION_REQUEST, /// Inquire selection data 00174 SEL_RAISED, /// Window to top of stack 00175 SEL_LOWERED, /// Window to bottom of stack 00176 SEL_CLOSE, /// Close window 00177 SEL_DELETE, /// Delete window 00178 SEL_MINIMIZE, /// Iconified 00179 SEL_RESTORE, /// No longer iconified or maximized 00180 SEL_MAXIMIZE, /// Maximized 00181 SEL_UPDATE, /// GUI update 00182 SEL_COMMAND, /// GUI command 00183 SEL_CLICKED, /// Clicked 00184 SEL_DOUBLECLICKED, /// Double-clicked 00185 SEL_TRIPLECLICKED, /// Triple-clicked 00186 SEL_MOUSEWHEEL, /// Mouse wheel 00187 SEL_CHANGED, /// GUI has changed 00188 SEL_VERIFY, /// Verify change 00189 SEL_DESELECTED, /// Deselected 00190 SEL_SELECTED, /// Selected 00191 SEL_INSERTED, /// Inserted 00192 SEL_REPLACED, /// Replaced 00193 SEL_DELETED, /// Deleted 00194 SEL_OPENED, /// Opened 00195 SEL_CLOSED, /// Closed 00196 SEL_EXPANDED, /// Expanded 00197 SEL_COLLAPSED, /// Collapsed 00198 SEL_BEGINDRAG, /// Start a drag 00199 SEL_ENDDRAG, /// End a drag 00200 SEL_DRAGGED, /// Dragged 00201 SEL_LASSOED, /// Lassoed 00202 SEL_TIMEOUT, /// Timeout occurred 00203 SEL_SIGNAL, /// Signal received 00204 SEL_CLIPBOARD_LOST, /// Widget lost clipboard 00205 SEL_CLIPBOARD_GAINED, /// Widget gained clipboard 00206 SEL_CLIPBOARD_REQUEST, /// Inquire clipboard data 00207 SEL_CHORE, /// Background chore 00208 SEL_FOCUS_SELF, /// Focus on widget itself 00209 SEL_FOCUS_RIGHT, /// Focus moved right 00210 SEL_FOCUS_LEFT, /// Focus moved left 00211 SEL_FOCUS_DOWN, /// Focus moved down 00212 SEL_FOCUS_UP, /// Focus moved up 00213 SEL_FOCUS_NEXT, /// Focus moved to next widget 00214 SEL_FOCUS_PREV, /// Focus moved to previous widget 00215 SEL_DND_ENTER, /// Drag action entering potential drop target 00216 SEL_DND_LEAVE, /// Drag action leaving potential drop target 00217 SEL_DND_DROP, /// Drop on drop target 00218 SEL_DND_MOTION, /// Drag position changed over potential drop target 00219 SEL_DND_REQUEST, /// Inquire drag and drop data 00220 SEL_IO_READ, /// Read activity on a pipe 00221 SEL_IO_WRITE, /// Write activity on a pipe 00222 SEL_IO_EXCEPT, /// Except activity on a pipe 00223 SEL_PICKED, /// Picked some location 00224 SEL_QUERY_TIP, /// Message inquiring about tooltip 00225 SEL_QUERY_HELP, /// Message inquiring about statusline help 00226 SEL_DOCKED, /// Toolbar docked 00227 SEL_FLOATED, /// Toolbar floated 00228 SEL_SPACEBALLMOTION, /// Moved space ball puck 00229 SEL_SPACEBALLBUTTONPRESS, /// Pressed space ball button 00230 SEL_SPACEBALLBUTTONRELEASE, /// Released space ball button 00231 SEL_SESSION_NOTIFY, /// Session is about to close 00232 SEL_SESSION_CLOSED, /// Session is closed 00233 SEL_IME_START, /// IME mode 00234 SEL_IME_END, /// IME mode 00235 SEL_LAST 00236 }; 00237 00238 00239 /// FOX Keyboard and Button states 00240 enum { 00241 SHIFTMASK = 0x001, /// Shift key is down 00242 CAPSLOCKMASK = 0x002, /// Caps Lock key is down 00243 CONTROLMASK = 0x004, /// Ctrl key is down 00244 #ifdef __APPLE__ 00245 ALTMASK = 0x2000, /// Alt key is down 00246 METAMASK = 0x10, /// Meta key is down 00247 #else 00248 ALTMASK = 0x008, /// Alt key is down 00249 METAMASK = 0x040, /// Meta key is down 00250 #endif 00251 NUMLOCKMASK = 0x010, /// Num Lock key is down 00252 SCROLLLOCKMASK = 0x0E0, /// Scroll Lock key is down (seems to vary) 00253 LEFTBUTTONMASK = 0x100, /// Left mouse button is down 00254 MIDDLEBUTTONMASK = 0x200, /// Middle mouse button is down 00255 RIGHTBUTTONMASK = 0x400 /// Right mouse button is down 00256 }; 00257 00258 00259 /// FOX Mouse buttons 00260 enum { 00261 LEFTBUTTON = 1, 00262 MIDDLEBUTTON = 2, 00263 RIGHTBUTTON = 3 00264 }; 00265 00266 00267 /// FOX window crossing modes 00268 enum { 00269 CROSSINGNORMAL, /// Normal crossing event 00270 CROSSINGGRAB, /// Crossing due to mouse grab 00271 CROSSINGUNGRAB /// Crossing due to mouse ungrab 00272 }; 00273 00274 00275 /// FOX window visibility modes 00276 enum { 00277 VISIBILITYTOTAL, 00278 VISIBILITYPARTIAL, 00279 VISIBILITYNONE 00280 }; 00281 00282 00283 /// Options for fxfilematch 00284 enum { 00285 FILEMATCH_FILE_NAME = 1, /// No wildcard can ever match `/' 00286 FILEMATCH_NOESCAPE = 2, /// Backslashes don't quote special chars 00287 FILEMATCH_PERIOD = 4, /// Leading `.' is matched only explicitly 00288 FILEMATCH_LEADING_DIR = 8, /// Ignore `/...' after a match 00289 FILEMATCH_CASEFOLD = 16 /// Compare without regard to case 00290 }; 00291 00292 00293 /// Drag and drop actions 00294 enum FXDragAction { 00295 DRAG_REJECT = 0, /// Reject all drop actions 00296 DRAG_ASK = 1, /// Ask 00297 DRAG_COPY = 2, /// Copy 00298 DRAG_MOVE = 3, /// Move 00299 DRAG_LINK = 4, /// Link 00300 DRAG_PRIVATE = 5, /// Private 00301 DRAG_ACCEPT = 6 /// Accept any drop action 00302 }; 00303 00304 00305 /// Clipboard actions 00306 enum FXClipAction { 00307 CLIP_COPY = 0, /// Copy to clipboard 00308 CLIP_CUT = 1 /// Clip to clipboard 00309 }; 00310 00311 00312 /// Origin of data 00313 enum FXDNDOrigin { 00314 FROM_SELECTION = 0, /// Primary selection 00315 FROM_CLIPBOARD = 1, /// Clipboard 00316 FROM_DRAGNDROP = 2 /// Drag and drop source 00317 }; 00318 00319 00320 /// Exponent display 00321 enum FXExponent { 00322 EXP_NEVER=FALSE, /// Never use exponential notation 00323 EXP_ALWAYS=TRUE, /// Always use exponential notation 00324 EXP_AUTO=MAYBE /// Use exponential notation if needed 00325 }; 00326 00327 00328 /// Search modes for search/replace dialogs 00329 enum { 00330 SEARCH_FORWARD = 0, /// Search forward (default) 00331 SEARCH_BACKWARD = 1, /// Search backward 00332 SEARCH_NOWRAP = 0, /// Don't wrap (default) 00333 SEARCH_WRAP = 2, /// Wrap around to start 00334 SEARCH_EXACT = 0, /// Exact match (default) 00335 SEARCH_IGNORECASE = 4, /// Ignore case 00336 SEARCH_REGEX = 8, /// Regular expression match 00337 SEARCH_PREFIX = 16 /// Prefix of subject string 00338 }; 00339 00340 00341 /********************************* Typedefs **********************************/ 00342 00343 // Forward declarations 00344 class FXObject; 00345 class FXStream; 00346 class FXString; 00347 00348 00349 // Streamable types; these are fixed size! 00350 typedef char FXchar; 00351 typedef unsigned char FXuchar; 00352 typedef bool FXbool; 00353 typedef unsigned short FXushort; 00354 typedef short FXshort; 00355 typedef unsigned int FXuint; 00356 typedef int FXint; 00357 typedef float FXfloat; 00358 typedef double FXdouble; 00359 typedef FXObject *FXObjectPtr; 00360 #ifdef WIN32 00361 typedef unsigned int FXwchar; 00362 #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) 00363 typedef unsigned short FXnchar; 00364 #elif defined(__WATCOMC__) && !defined(_WCHAR_T_DEFINED) 00365 typedef long char FXnchar; 00366 #else 00367 typedef wchar_t FXnchar; 00368 #endif 00369 #else 00370 typedef wchar_t FXwchar; 00371 typedef unsigned short FXnchar; 00372 #endif 00373 #if defined(__LP64__) || defined(_LP64) || (_MIPS_SZLONG == 64) || (__WORDSIZE == 64) 00374 typedef unsigned long FXulong; 00375 typedef long FXlong; 00376 #elif defined(_MSC_VER) || (defined(__BCPLUSPLUS__) && __BORLANDC__ > 0x500) || defined(__WATCOM_INT64__) 00377 typedef unsigned __int64 FXulong; 00378 typedef __int64 FXlong; 00379 #elif defined(__GNUG__) || defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__MWERKS__) || defined(__SC__) || defined(_LONGLONG) 00380 typedef unsigned long long FXulong; 00381 typedef long long FXlong; 00382 #else 00383 #error "FXlong and FXulong not defined for this architecture!" 00384 #endif 00385 00386 // Integral types large enough to hold value of a pointer 00387 #if defined(_MSC_VER) && defined(_WIN64) 00388 typedef __int64 FXival; 00389 typedef unsigned __int64 FXuval; 00390 #else 00391 typedef long FXival; 00392 typedef unsigned long FXuval; 00393 #endif 00394 00395 00396 // Handle to something in server 00397 #ifndef WIN32 00398 typedef unsigned long FXID; 00399 #else 00400 typedef void* FXID; 00401 #endif 00402 00403 // Time since January 1, 1970 (UTC) 00404 typedef FXlong FXTime; 00405 00406 // Pixel type (could be color index) 00407 typedef unsigned long FXPixel; 00408 00409 // RGBA pixel value 00410 typedef FXuint FXColor; 00411 00412 // Hot key 00413 typedef FXuint FXHotKey; 00414 00415 // Drag type 00416 #ifndef WIN32 00417 typedef FXID FXDragType; 00418 #else 00419 typedef FXushort FXDragType; 00420 #endif 00421 00422 // Input source handle type 00423 #ifndef WIN32 00424 typedef FXint FXInputHandle; 00425 #else 00426 typedef void* FXInputHandle; 00427 #endif 00428 00429 // Raw event type 00430 #ifndef WIN32 00431 typedef _XEvent FXRawEvent; 00432 #else 00433 typedef tagMSG FXRawEvent; 00434 #endif 00435 00436 00437 /// Pi 00438 const FXdouble PI=3.1415926535897932384626433833; 00439 00440 /// Euler constant 00441 const FXdouble EULER=2.7182818284590452353602874713; 00442 00443 /// Multiplier for degrees to radians 00444 const FXdouble DTOR=0.0174532925199432957692369077; 00445 00446 /// Multiplier for radians to degrees 00447 const FXdouble RTOD=57.295779513082320876798154814; 00448 00449 #if !defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__SC__) || defined(__BCPLUSPLUS__) 00450 /// A time in the far, far future 00451 const FXTime forever=9223372036854775807LL; 00452 #else 00453 /// A time in the far, far future 00454 const FXTime forever=9223372036854775807L; 00455 #endif 00456 00457 00458 /********************************** Macros ***********************************/ 00459 00460 00461 /// Abolute value 00462 #define FXABS(val) (((val)>=0)?(val):-(val)) 00463 00464 /// Return 1 if val >= 0 and -1 otherwise 00465 #define FXSGN(val) (((val)<0)?-1:1) 00466 00467 /// Return 1 if val > 0, -1 if val < 0, and 0 otherwise 00468 #define FXSGNZ(val) ((val)<0?-1:(val)>0?1:0) 00469 00470 /// Return the maximum of a or b 00471 #define FXMAX(a,b) (((a)>(b))?(a):(b)) 00472 00473 /// Return the minimum of a or b 00474 #define FXMIN(a,b) (((a)>(b))?(b):(a)) 00475 00476 /// Return the minimum of x, y and z 00477 #define FXMIN3(x,y,z) ((x)<(y)?FXMIN(x,z):FXMIN(y,z)) 00478 00479 /// Return the maximum of x, y and z 00480 #define FXMAX3(x,y,z) ((x)>(y)?FXMAX(x,z):FXMAX(y,z)) 00481 00482 /// Return the minimum of x, y, z, and w 00483 #define FXMIN4(x,y,z,w) (FXMIN(FXMIN(x,y),FXMIN(z,w))) 00484 00485 /// Return the maximum of of x, y, z, and w 00486 #define FXMAX4(x,y,z,w) (FXMAX(FXMAX(x,y),FXMAX(z,w))) 00487 00488 /// Return minimum and maximum of a, b 00489 #define FXMINMAX(lo,hi,a,b) ((a)<(b)?((lo)=(a),(hi)=(b)):((lo)=(b),(hi)=(a))) 00490 00491 /// Clamp value x to range [lo..hi] 00492 #define FXCLAMP(lo,x,hi) ((x)<(lo)?(lo):((x)>(hi)?(hi):(x))) 00493 00494 /// Swap a pair of numbers 00495 #define FXSWAP(a,b,t) ((t)=(a),(a)=(b),(b)=(t)) 00496 00497 /// Linear interpolation between a and b, where 0<=f<=1 00498 #define FXLERP(a,b,f) ((a)+((b)-(a))*(f)) 00499 00500 /// Offset of member in a structure 00501 #define STRUCTOFFSET(str,member) (((char *)(&(((str *)0)->member)))-((char *)0)) 00502 00503 /// Number of elements in a static array 00504 #define ARRAYNUMBER(array) (sizeof(array)/sizeof(array[0])) 00505 00506 /// Container class of a member class 00507 #define CONTAINER(ptr,str,mem) ((str*)(((char*)(ptr))-STRUCTOFFSET(str,mem))) 00508 00509 /// Make int out of two shorts 00510 #define MKUINT(l,h) ((((FX::FXuint)(l))&0xffff) | (((FX::FXuint)(h))<<16)) 00511 00512 /// Make selector from message type and message id 00513 #define FXSEL(type,id) ((((FX::FXuint)(id))&0xffff) | (((FX::FXuint)(type))<<16)) 00514 00515 /// Get type from selector 00516 #define FXSELTYPE(s) ((FX::FXushort)(((s)>>16)&0xffff)) 00517 00518 /// Get ID from selector 00519 #define FXSELID(s) ((FX::FXushort)((s)&0xffff)) 00520 00521 /// Reverse bits in byte 00522 #define FXBITREVERSE(b) (((b&0x01)<<7)|((b&0x02)<<5)|((b&0x04)<<3)|((b&0x08)<<1)|((b&0x10)>>1)|((b&0x20)>>3)|((b&0x40)>>5)|((b&0x80)>>7)) 00523 00524 /// Test if character c is at the start of a utf8 sequence 00525 #define FXISUTF(c) (((c)&0xC0)!=0x80) 00526 00527 /// Average of two FXColor ca and FXColor cb 00528 #define FXAVGCOLOR(ca,cb) (((ca)&(cb))+((((ca)^(cb))&0xFEFEFEFE)>>1)) 00529 00530 00531 // Definitions for big-endian machines 00532 #if FOX_BIGENDIAN == 1 00533 00534 /// Make RGBA color 00535 #define FXRGBA(r,g,b,a) (((FX::FXuint)(FX::FXuchar)(r)<<24) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<8) | ((FX::FXuint)(FX::FXuchar)(a))) 00536 00537 /// Make RGB color 00538 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)<<24) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<8) | 0x000000ff) 00539 00540 /// Get red value from RGBA color 00541 #define FXREDVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 00542 00543 /// Get green value from RGBA color 00544 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 00545 00546 /// Get blue value from RGBA color 00547 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 00548 00549 /// Get alpha value from RGBA color 00550 #define FXALPHAVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 00551 00552 /// Get component value of RGBA color 00553 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((3-(comp))<<3))&0xff)) 00554 00555 #endif 00556 00557 00558 // Definitions for little-endian machines 00559 #if FOX_BIGENDIAN == 0 00560 00561 /// Make RGBA color 00562 #define FXRGBA(r,g,b,a) (((FX::FXuint)(FX::FXuchar)(r)) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b)<<16) | ((FX::FXuint)(FX::FXuchar)(a)<<24)) 00563 00564 /// Make RGB color 00565 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b)<<16) | 0xff000000) 00566 00567 /// Get red value from RGBA color 00568 #define FXREDVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 00569 00570 /// Get green value from RGBA color 00571 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 00572 00573 /// Get blue value from RGBA color 00574 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 00575 00576 /// Get alpha value from RGBA color 00577 #define FXALPHAVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 00578 00579 /// Get component value of RGBA color 00580 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((comp)<<3))&0xff)) 00581 00582 #endif 00583 00584 00585 /** 00586 * FXASSERT() prints out a message when the expression fails, 00587 * and nothing otherwise. Unlike assert(), FXASSERT() will not 00588 * terminate the execution of the application. 00589 * When compiling your application for release, all assertions 00590 * are compiled out; thus there is no impact on execution speed. 00591 */ 00592 #ifndef NDEBUG 00593 #define FXASSERT(exp) ((exp)?((void)0):(void)FX::fxassert(#exp,__FILE__,__LINE__)) 00594 #else 00595 #define FXASSERT(exp) ((void)0) 00596 #endif 00597 00598 00599 /** 00600 * FXVERIFY prints out a message when the expression fails, 00601 * and nothing otherwise. 00602 * When compiling your application for release, these messages 00603 * are compiled out, but unlike FXASSERT, FXVERIFY will still execute 00604 * the expression. 00605 */ 00606 #ifndef NDEBUG 00607 #define FXVERIFY(exp) ((exp)?((void)0):(void)FX::fxverify(#exp,__FILE__,__LINE__)) 00608 #else 00609 #define FXVERIFY(exp) ((void)(exp)) 00610 #endif 00611 00612 00613 /** 00614 * FXTRACE() allows you to trace the execution of your application 00615 * with increasing levels of detail the higher the trace level. 00616 * The trace level is determined by variable fxTraceLevel, which 00617 * may be set from the command line with "-tracelevel <level>". 00618 * When compiling your application for release, all trace statements 00619 * are compiled out, just like FXASSERT. 00620 * A statement like: FXTRACE((10,"The value of x=%d\n",x)) will 00621 * generate output only if fxTraceLevel is set to 11 or greater. 00622 * The default value fxTraceLevel=0 will block all trace outputs. 00623 * Note the double parentheses! 00624 */ 00625 #ifndef NDEBUG 00626 #define FXTRACE(arguments) FX::fxtrace arguments 00627 #else 00628 #define FXTRACE(arguments) ((void)0) 00629 #endif 00630 00631 /** 00632 * Allocate a memory block of no elements of type and store a pointer 00633 * to it into the address pointed to by ptr. 00634 * Return FALSE if size!=0 and allocation fails, TRUE otherwise. 00635 * An allocation of a zero size block returns a NULL pointer. 00636 */ 00637 #define FXMALLOC(ptr,type,no) (FX::fxmalloc((void **)(ptr),sizeof(type)*(no))) 00638 00639 /** 00640 * Allocate a zero-filled memory block no elements of type and store a pointer 00641 * to it into the address pointed to by ptr. 00642 * Return FALSE if size!=0 and allocation fails, TRUE otherwise. 00643 * An allocation of a zero size block returns a NULL pointer. 00644 */ 00645 #define FXCALLOC(ptr,type,no) (FX::fxcalloc((void **)(ptr),sizeof(type)*(no))) 00646 00647 /** 00648 * Resize the memory block referred to by the pointer at the address ptr, to a 00649 * hold no elements of type. 00650 * Returns FALSE if size!=0 and reallocation fails, TRUE otherwise. 00651 * If reallocation fails, pointer is left to point to old block; a reallocation 00652 * to a zero size block has the effect of freeing it. 00653 * The ptr argument must be the address where the pointer to the allocated 00654 * block is to be stored. 00655 */ 00656 #define FXRESIZE(ptr,type,no) (FX::fxresize((void **)(ptr),sizeof(type)*(no))) 00657 00658 /** 00659 * Allocate and initialize memory from another block. 00660 * Return FALSE if size!=0 and source!=NULL and allocation fails, TRUE otherwise. 00661 * An allocation of a zero size block returns a NULL pointer. 00662 * The ptr argument must be the address where the pointer to the allocated 00663 * block is to be stored. 00664 */ 00665 #define FXMEMDUP(ptr,src,type,no) (FX::fxmemdup((void **)(ptr),(const void*)(src),sizeof(type)*(no))) 00666 00667 /** 00668 * Free a block of memory allocated with either FXMALLOC, FXCALLOC, FXRESIZE, or FXMEMDUP. 00669 * It is OK to call free a NULL pointer. The argument must be the address of the 00670 * pointer to the block to be released. The pointer is set to NULL to prevent 00671 * any further references to the block after releasing it. 00672 */ 00673 #define FXFREE(ptr) (FX::fxfree((void **)(ptr))) 00674 00675 00676 /** 00677 * These are some of the ISO C99 standard single-precision transcendental functions. 00678 * On LINUX, specify _GNU_SOURCE or _ISOC99_SOURCE to enable native implementation; 00679 * otherwise, these macros will be used. Apple OS-X implements fabsf(x), ceilf(x), 00680 * floorf(x), and fmodf(x,y). 00681 * Define FLOAT_MATH_FUNCTIONS if these functions are available in some other 00682 * library you're linking to. 00683 */ 00684 #ifdef __OpenBSD__ 00685 #define FLOAT_MATH_FUNCTIONS 00686 #endif 00687 #ifndef FLOAT_MATH_FUNCTIONS 00688 #ifndef __USE_ISOC99 00689 #ifndef __APPLE__ 00690 #define fabsf(x) ((float)fabs((double)(x))) 00691 #define ceilf(x) ((float)ceil((double)(x))) 00692 #define floorf(x) ((float)floor((double)(x))) 00693 #define fmodf(x,y) ((float)fmod((double)(x),(double)(y))) 00694 #endif 00695 #define sqrtf(x) ((float)sqrt((double)(x))) 00696 #define sinf(x) ((float)sin((double)(x))) 00697 #define cosf(x) ((float)cos((double)(x))) 00698 #define tanf(x) ((float)tan((double)(x))) 00699 #define asinf(x) ((float)asin((double)(x))) 00700 #define acosf(x) ((float)acos((double)(x))) 00701 #define atanf(x) ((float)atan((double)(x))) 00702 #define atan2f(y,x) ((float)atan2((double)(y),(double)(x))) 00703 #define powf(x,y) ((float)pow((double)(x),(double)(y))) 00704 #define expf(x) ((float)exp((double)(x))) 00705 #define logf(x) ((float)log((double)(x))) 00706 #define log10f(x) ((float)log10((double)(x))) 00707 #endif 00708 #endif 00709 00710 00711 /********************************** Globals **********************************/ 00712 00713 /// Simple, thread-safe, random number generator 00714 extern FXAPI FXuint fxrandom(FXuint& seed); 00715 00716 /// Allocate memory 00717 extern FXAPI FXbool fxmalloc(void** ptr,unsigned long size); 00718 00719 /// Allocate cleaned memory 00720 extern FXAPI FXbool fxcalloc(void** ptr,unsigned long size); 00721 00722 /// Resize memory 00723 extern FXAPI FXbool fxresize(void** ptr,unsigned long size); 00724 00725 /// Duplicate memory 00726 extern FXAPI FXbool fxmemdup(void** ptr,const void* src,unsigned long size); 00727 00728 /// Free memory, resets ptr to NULL afterward 00729 extern FXAPI void fxfree(void** ptr); 00730 00731 /// Error routine 00732 extern FXAPI void fxerror(const char* format,...) FX_PRINTF(1,2) ; 00733 00734 /// Warning routine 00735 extern FXAPI void fxwarning(const char* format,...) FX_PRINTF(1,2) ; 00736 00737 /// Log message to [typically] stderr 00738 extern FXAPI void fxmessage(const char* format,...) FX_PRINTF(1,2) ; 00739 00740 /// Assert failed routine:- usually not called directly but called through FXASSERT 00741 extern FXAPI void fxassert(const char* expression,const char* filename,unsigned int lineno); 00742 00743 /// Verify failed routine:- usually not called directly but called through FXVERIFY 00744 extern FXAPI void fxverify(const char* expression,const char* filename,unsigned int lineno); 00745 00746 /// Trace printout routine:- usually not called directly but called through FXTRACE 00747 extern FXAPI void fxtrace(unsigned int level,const char* format,...) FX_PRINTF(2,3) ; 00748 00749 /// Sleep n microseconds 00750 extern FXAPI void fxsleep(FXuint n); 00751 00752 /// Match a file name with a pattern 00753 extern FXAPI FXbool fxfilematch(const FXchar *string,const FXchar *pattern="*",FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME)); 00754 00755 /// Get highlight color 00756 extern FXAPI FXColor makeHiliteColor(FXColor clr); 00757 00758 /// Get shadow color 00759 extern FXAPI FXColor makeShadowColor(FXColor clr); 00760 00761 /// Get process id 00762 extern FXAPI FXint fxgetpid(); 00763 00764 /// Convert string of length len to MSDOS; return new string and new length 00765 extern FXAPI FXbool fxtoDOS(FXchar*& string,FXint& len); 00766 00767 /// Convert string of length len from MSDOS; return new string and new length 00768 extern FXAPI FXbool fxfromDOS(FXchar*& string,FXint& len); 00769 00770 /// Duplicate string 00771 extern FXAPI FXchar *fxstrdup(const FXchar* str); 00772 00773 /// Calculate a hash value from a string 00774 extern FXAPI FXuint fxstrhash(const FXchar* str); 00775 00776 /// Get RGB value from color name 00777 extern FXAPI FXColor fxcolorfromname(const FXchar* colorname); 00778 00779 /// Get name of (closest) color to RGB 00780 extern FXAPI FXchar* fxnamefromcolor(FXchar *colorname,FXColor color); 00781 00782 /// Convert RGB to HSV 00783 extern FXAPI void fxrgb_to_hsv(FXfloat& h,FXfloat& s,FXfloat& v,FXfloat r,FXfloat g,FXfloat b); 00784 00785 /// Convert HSV to RGB 00786 extern FXAPI void fxhsv_to_rgb(FXfloat& r,FXfloat& g,FXfloat& b,FXfloat h,FXfloat s,FXfloat v); 00787 00788 /// Float number classification: 0=OK, +/-1=Inf, +/-2=NaN 00789 extern FXAPI FXint fxieeefloatclass(FXfloat number); 00790 00791 /// Double number classification: 0=OK, +/-1=Inf, +/-2=NaN 00792 extern FXAPI FXint fxieeedoubleclass(FXdouble number); 00793 00794 /// Test for finite float 00795 extern FXAPI FXbool fxIsFinite(FXfloat number); 00796 00797 /// Test for finite double 00798 extern FXAPI FXbool fxIsFinite(FXdouble number); 00799 00800 /// Test for infinite float 00801 extern FXAPI FXbool fxIsInf(FXfloat number); 00802 00803 /// Test for infinite double 00804 extern FXAPI FXbool fxIsInf(FXdouble number); 00805 00806 /// Text for not-a-number float 00807 extern FXAPI FXbool fxIsNan(FXfloat number); 00808 00809 /// Text for not-a-number double 00810 extern FXAPI FXbool fxIsNan(FXdouble number); 00811 00812 /// Convert keysym to unicode character 00813 extern FXAPI FXwchar fxkeysym2ucs(FXwchar sym); 00814 00815 /// Convert unicode character to keysym 00816 extern FXAPI FXwchar fxucs2keysym(FXwchar ucs); 00817 00818 /// Parse geometry, a-la X11 geometry specification 00819 extern FXAPI FXint fxparsegeometry(const FXchar *string,FXint& x,FXint& y,FXint& w,FXint& h); 00820 00821 /// True if executable with given path is a console application 00822 extern FXAPI FXbool fxisconsole(const FXchar *path); 00823 00824 /// Version number that the library has been compiled with 00825 extern FXAPI const FXuchar fxversion[3]; 00826 00827 /// Controls tracing level 00828 extern FXAPI FXuint fxTraceLevel; 00829 00830 /// Return wide character from utf8 string at ptr 00831 extern FXAPI FXwchar wc(const FXchar *ptr); 00832 00833 /// Return wide character from utf16 string at ptr 00834 extern FXAPI FXwchar wc(const FXnchar *ptr); 00835 00836 /// Return number of FXchar's of wide character at ptr 00837 extern FXAPI FXint wclen(const FXchar *ptr); 00838 00839 /// Return number of FXnchar's of narrow character at ptr 00840 extern FXAPI FXint wclen(const FXnchar *ptr); 00841 00842 /// Return start of utf8 character containing position 00843 extern FXAPI FXint wcvalidate(const FXchar* string,FXint pos); 00844 00845 /// Return start of utf16 character containing position 00846 extern FXAPI FXint wcvalidate(const FXnchar *string,FXint pos); 00847 00848 /// Advance to next utf8 character start 00849 extern FXAPI FXint wcinc(const FXchar* string,FXint pos); 00850 00851 /// Advance to next utf16 character start 00852 extern FXAPI FXint wcinc(const FXnchar *string,FXint pos); 00853 00854 /// Retreat to previous utf8 character start 00855 extern FXAPI FXint wcdec(const FXchar* string,FXint pos); 00856 00857 /// Retreat to previous utf16 character start 00858 extern FXAPI FXint wcdec(const FXnchar *string,FXint pos); 00859 00860 /// Length of utf8 representation of wide characters string str of length n 00861 extern FXAPI FXint utfslen(const FXwchar *str,FXint n); 00862 00863 /// Length of utf8 representation of wide character string str 00864 extern FXAPI FXint utfslen(const FXwchar *str); 00865 00866 /// Length of utf8 representation of narrow characters string str of length n 00867 extern FXAPI FXint utfslen(const FXnchar *str,FXint n); 00868 00869 /// Length of utf8 representation of narrow characters string str 00870 extern FXAPI FXint utfslen(const FXnchar *str); 00871 00872 /// Length of wide character representation of utf8 string str of length n 00873 extern FXAPI FXint wcslen(const FXchar *str,FXint n); 00874 00875 /// Length of wide character representation of utf8 string str 00876 extern FXAPI FXint wcslen(const FXchar *str); 00877 00878 /// Length of narrow character representation of utf8 string str of length n 00879 extern FXAPI FXint ncslen(const FXchar *str,FXint n); 00880 00881 /// Length of narrow character representation of utf8 string str 00882 extern FXAPI FXint ncslen(const FXchar *str); 00883 00884 /// Copy utf8 string of length sn to wide character string dst of size dn 00885 extern FXAPI FXint utf2wcs(FXwchar *dst,FXint dn,const FXchar *src,FXint sn); 00886 00887 /// Copy utf8 string of length sn to narrow character string dst of size dn 00888 extern FXAPI FXint utf2ncs(FXnchar *dst,FXint dn,const FXchar *src,FXint sn); 00889 00890 /// Copy wide character substring of length sn to dst of size dn 00891 extern FXAPI FXint wc2utfs(FXchar* dst,FXint dn,const FXwchar *src,FXint sn); 00892 00893 /// Copy narrow character substring of length sn to dst of size dn 00894 extern FXAPI FXint nc2utfs(FXchar* dst,FXint dn,const FXnchar *src,FXint sn); 00895 00896 /// Return clock ticks from cpu tick-counter 00897 extern FXAPI FXTime fxgetticks(); 00898 00899 } 00900 00901 #endif
![]() |