00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXDEFS_H
00022 #define FXDEFS_H
00023
00024
00025
00026
00027
00028 #ifndef TRUE
00029 #define TRUE 1
00030 #endif
00031 #ifndef FALSE
00032 #define FALSE 0
00033 #endif
00034 #ifndef MAYBE
00035 #define MAYBE 2
00036 #endif
00037 #ifndef NULL
00038 #define NULL 0
00039 #endif
00040
00041
00042 #ifdef WIN32
00043 #define PATHSEP '\\'
00044 #define PATHSEPSTRING "\\"
00045 #define PATHLISTSEP ';'
00046 #define PATHLISTSEPSTRING ";"
00047 #define ISPATHSEP(c) ((c)=='\\' || (c)=='/')
00048 #else
00049 #define PATHSEP '/'
00050 #define PATHSEPSTRING "/"
00051 #define PATHLISTSEP ':'
00052 #define PATHLISTSEPSTRING ":"
00053 #define ISPATHSEP(c) ((c)=='/')
00054 #endif
00055
00056
00057 #ifdef WIN32
00058 #define ENDLINE "\r\n"
00059 #else
00060 #define ENDLINE "\n"
00061 #endif
00062
00063
00064
00065 #ifdef _DEBUG
00066 #ifndef DEBUG
00067 #define DEBUG
00068 #endif
00069 #endif
00070 #ifdef _NDEBUG
00071 #ifndef NDEBUG
00072 #define NDEBUG
00073 #endif
00074 #endif
00075
00076
00077
00078 #ifdef WIN32
00079 #define FXLOCAL
00080 #define FXEXPORT __declspec(dllexport)
00081 #define FXIMPORT __declspec(dllimport)
00082 #else
00083 #if defined(__GNUC__) && (__GNUC__ >= 4)
00084 #define FXLOCAL __attribute__((visibility("hidden")))
00085 #define FXEXPORT __attribute__((visibility("default")))
00086 #define FXIMPORT
00087 #else
00088 #define FXLOCAL
00089 #define FXEXPORT
00090 #define FXIMPORT
00091 #endif
00092 #endif
00093
00094
00095
00096 #ifdef FOXDLL
00097 #ifdef FOXDLL_EXPORTS
00098 #define FXAPI FXEXPORT
00099 #define FXTEMPLATE_EXTERN
00100 #else
00101 #define FXAPI FXIMPORT
00102 #define FXTEMPLATE_EXTERN extern
00103 #endif
00104 #else
00105 #define FXAPI
00106 #define FXTEMPLATE_EXTERN
00107 #endif
00108
00109
00110
00111 #if defined(__GNUC__)
00112 #define FXALIGNED(x) __attribute__((aligned(x)))
00113 #elif defined(_MSC_VER)
00114 #define FXALIGNED(x) __declspec(align(x))
00115 #else
00116 #define FXALIGNED(x)
00117 #endif
00118
00119
00120
00121 #if defined(__GNUC__)
00122 #define FXTHREADLOCAL __thread
00123 #elif defined(_MSC_VER)
00124 #define FXTHREADLOCAL __declspec(thread)
00125 #else
00126 #define FXTHREADLOCAL
00127 #endif
00128
00129
00130
00131 #ifdef WIN32
00132 #ifndef CALLBACK
00133 #define CALLBACK __stdcall
00134 #endif
00135 #endif
00136
00137
00138
00139 #ifdef _MSC_VER
00140 #pragma warning(disable: 4251)
00141 #pragma warning(disable: 4231)
00142 #pragma warning(disable: 4244)
00143 #endif
00144
00145
00146
00147 #if defined(_CC_GNU_) || defined(__GNUG__) || defined(__GNUC__)
00148 #define FX_PRINTF(fmt,arg) __attribute__((format(printf,fmt,arg)))
00149 #define FX_SCANF(fmt,arg) __attribute__((format(scanf,fmt,arg)))
00150 #define FX_FORMAT(arg) __attribute__((format_arg(arg)))
00151 #else
00152 #define FX_PRINTF(fmt,arg)
00153 #define FX_SCANF(fmt,arg)
00154 #define FX_FORMAT(arg)
00155 #endif
00156
00157
00158 #ifdef WIN32
00159 struct tagMSG;
00160 #else
00161 union _XEvent;
00162 #endif
00163
00164
00165 namespace FX {
00166
00167
00168
00169 enum FXExponent {
00170 EXP_NEVER=FALSE,
00171 EXP_ALWAYS=TRUE,
00172 EXP_AUTO=MAYBE
00173 };
00174
00175
00176
00177 enum {
00178 SEARCH_FORWARD = 0,
00179 SEARCH_BACKWARD = 1,
00180 SEARCH_NOWRAP = 0,
00181 SEARCH_WRAP = 2,
00182 SEARCH_EXACT = 0,
00183 SEARCH_IGNORECASE = 4,
00184 SEARCH_REGEX = 8,
00185 SEARCH_PREFIX = 16
00186 };
00187
00188
00189
00190
00191
00192 class FXObject;
00193 class FXStream;
00194 class FXString;
00195
00196
00197
00198 typedef char FXchar;
00199 typedef unsigned char FXuchar;
00200 typedef bool FXbool;
00201 typedef unsigned short FXushort;
00202 typedef short FXshort;
00203 typedef unsigned int FXuint;
00204 typedef int FXint;
00205 typedef float FXfloat;
00206 typedef double FXdouble;
00207 #ifdef WIN32
00208 typedef unsigned int FXwchar;
00209 #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
00210 typedef unsigned short FXnchar;
00211 #elif defined(__WATCOMC__) && !defined(_WCHAR_T_DEFINED)
00212 typedef long char FXnchar;
00213 #else
00214 typedef wchar_t FXnchar;
00215 #endif
00216 #else
00217 typedef wchar_t FXwchar;
00218 typedef unsigned short FXnchar;
00219 #endif
00220 #if defined(__LP64__) || defined(_LP64) || (_MIPS_SZLONG == 64) || (__WORDSIZE == 64)
00221 typedef unsigned long FXulong;
00222 typedef long FXlong;
00223 #elif defined(_MSC_VER) || (defined(__BCPLUSPLUS__) && __BORLANDC__ > 0x500) || defined(__WATCOM_INT64__)
00224 typedef unsigned __int64 FXulong;
00225 typedef __int64 FXlong;
00226 #elif defined(__GNUG__) || defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__MWERKS__) || defined(__SC__) || defined(_LONGLONG)
00227 typedef unsigned long long FXulong;
00228 typedef long long FXlong;
00229 #else
00230 #error "FXlong and FXulong not defined for this architecture!"
00231 #endif
00232
00233
00234 #if defined(_MSC_VER) && defined(_WIN64)
00235 typedef __int64 FXival;
00236 typedef unsigned __int64 FXuval;
00237 #else
00238 typedef long FXival;
00239 typedef unsigned long FXuval;
00240 #endif
00241
00242
00243
00244 #ifdef WIN32
00245 typedef void* FXID;
00246 #else
00247 typedef unsigned long FXID;
00248 #endif
00249
00250
00251 typedef FXlong FXTime;
00252
00253
00254 typedef unsigned long FXPixel;
00255
00256
00257 typedef FXuint FXColor;
00258
00259
00260 typedef FXuint FXHotKey;
00261
00262
00263 #ifdef WIN32
00264 typedef void* FXInputHandle;
00265 #else
00266 typedef FXint FXInputHandle;
00267 #endif
00268
00269
00270 #ifdef WIN32
00271 typedef tagMSG FXRawEvent;
00272 #else
00273 typedef _XEvent FXRawEvent;
00274 #endif
00275
00276
00277
00278 #ifdef WIN32
00279 typedef FXushort FXDragType;
00280 #else
00281 typedef FXID FXDragType;
00282 #endif
00283
00284
00285
00286 const FXdouble PI=3.1415926535897932384626433833;
00287
00288
00289 const FXdouble EULER=2.7182818284590452353602874713;
00290
00291
00292 const FXdouble DTOR=0.0174532925199432957692369077;
00293
00294
00295 const FXdouble RTOD=57.295779513082320876798154814;
00296
00297 #if !defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__SC__) || defined(__BCPLUSPLUS__)
00298
00299 const FXTime forever=9223372036854775807LL;
00300 #else
00301
00302 const FXTime forever=9223372036854775807L;
00303 #endif
00304
00305
00306
00307
00308
00309 #if __GNUC__ >= 3
00310 #define __likely(cond) __builtin_expect(!!(cond),1)
00311 #define __unlikely(cond) __builtin_expect(!!(cond),0)
00312 #else
00313 #define __likely(cond) (!!(cond))
00314 #define __unlikely(cond) (!!(cond))
00315 #endif
00316
00317
00318 #define FXABS(val) (((val)>=0)?(val):-(val))
00319
00320
00321 #define FXSGN(val) (((val)<0)?-1:1)
00322
00323
00324 #define FXSGNZ(val) ((val)<0?-1:(val)>0?1:0)
00325
00326
00327 #define FXMAX(a,b) (((a)>(b))?(a):(b))
00328
00329
00330 #define FXMIN(a,b) (((a)>(b))?(b):(a))
00331
00332
00333 #define FXMIN3(x,y,z) ((x)<(y)?FXMIN(x,z):FXMIN(y,z))
00334
00335
00336 #define FXMAX3(x,y,z) ((x)>(y)?FXMAX(x,z):FXMAX(y,z))
00337
00338
00339 #define FXMIN4(x,y,z,w) (FXMIN(FXMIN(x,y),FXMIN(z,w)))
00340
00341
00342 #define FXMAX4(x,y,z,w) (FXMAX(FXMAX(x,y),FXMAX(z,w)))
00343
00344
00345 #define FXMINMAX(lo,hi,a,b) ((a)<(b)?((lo)=(a),(hi)=(b)):((lo)=(b),(hi)=(a)))
00346
00347
00348 #define FXCLAMP(lo,x,hi) ((x)<(lo)?(lo):((x)>(hi)?(hi):(x)))
00349
00350
00351 #define FXSWAP(a,b,t) ((t)=(a),(a)=(b),(b)=(t))
00352
00353
00354 #define FXLERP(a,b,f) ((a)+((b)-(a))*(f))
00355
00356
00357 #define STRUCTOFFSET(str,member) (((char *)(&(((str *)0)->member)))-((char *)0))
00358
00359
00360 #define ARRAYNUMBER(array) (sizeof(array)/sizeof(array[0]))
00361
00362
00363 #define CONTAINER(ptr,str,mem) ((str*)(((char*)(ptr))-STRUCTOFFSET(str,mem)))
00364
00365
00366 #define MKUINT(l,h) ((((FX::FXuint)(l))&0xffff) | (((FX::FXuint)(h))<<16))
00367
00368
00369 #define FXSEL(type,id) ((((FX::FXuint)(id))&0xffff) | (((FX::FXuint)(type))<<16))
00370
00371
00372 #define FXSELTYPE(s) ((FX::FXushort)(((s)>>16)&0xffff))
00373
00374
00375 #define FXSELID(s) ((FX::FXushort)((s)&0xffff))
00376
00377
00378 #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))
00379
00380
00381 #define FXISUTF(c) (((c)&0xC0)!=0x80)
00382
00383
00384 #define FXAVGCOLOR(ca,cb) (((ca)&(cb))+((((ca)^(cb))&0xFEFEFEFE)>>1))
00385
00386
00387
00388 #if FOX_BIGENDIAN == 1
00389
00390
00391 #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)))
00392
00393
00394 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)<<24) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<8) | 0x000000ff)
00395
00396
00397 #define FXREDVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff))
00398
00399
00400 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff))
00401
00402
00403 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff))
00404
00405
00406 #define FXALPHAVAL(rgba) ((FX::FXuchar)((rgba)&0xff))
00407
00408
00409 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((3-(comp))<<3))&0xff))
00410
00411 #endif
00412
00413
00414
00415 #if FOX_BIGENDIAN == 0
00416
00417
00418 #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))
00419
00420
00421 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b)<<16) | 0xff000000)
00422
00423
00424 #define FXREDVAL(rgba) ((FX::FXuchar)((rgba)&0xff))
00425
00426
00427 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff))
00428
00429
00430 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff))
00431
00432
00433 #define FXALPHAVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff))
00434
00435
00436 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((comp)<<3))&0xff))
00437
00438 #endif
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 #ifndef NDEBUG
00449 #define FXASSERT(exp) (__likely(exp)?((void)0):(void)FX::fxassert(#exp,__FILE__,__LINE__))
00450 #else
00451 #define FXASSERT(exp) ((void)0)
00452 #endif
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 #ifndef NDEBUG
00463 #define FXVERIFY(exp) (__likely(exp)?((void)0):(void)FX::fxverify(#exp,__FILE__,__LINE__))
00464 #else
00465 #define FXVERIFY(exp) ((void)(exp))
00466 #endif
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 #ifndef NDEBUG
00482 #define FXTRACE(arguments) FX::fxtrace arguments
00483 #else
00484 #define FXTRACE(arguments) ((void)0)
00485 #endif
00486
00487
00488
00489
00490
00491
00492
00493 #define FXMALLOC(ptr,type,no) (FX::fxmalloc((void **)(ptr),sizeof(type)*(no)))
00494
00495
00496
00497
00498
00499
00500
00501 #define FXCALLOC(ptr,type,no) (FX::fxcalloc((void **)(ptr),sizeof(type)*(no)))
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512 #define FXRESIZE(ptr,type,no) (FX::fxresize((void **)(ptr),sizeof(type)*(no)))
00513
00514
00515
00516
00517
00518
00519
00520
00521 #define FXMEMDUP(ptr,src,type,no) (FX::fxmemdup((void **)(ptr),(const void*)(src),sizeof(type)*(no)))
00522
00523
00524
00525
00526
00527
00528
00529 #define FXFREE(ptr) (FX::fxfree((void **)(ptr)))
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540 #ifdef __OpenBSD__
00541 #define FLOAT_MATH_FUNCTIONS
00542 #endif
00543 #ifndef FLOAT_MATH_FUNCTIONS
00544 #ifndef __USE_ISOC99
00545 #ifndef __APPLE__
00546 #define fabsf(x) ((float)fabs((double)(x)))
00547 #define ceilf(x) ((float)ceil((double)(x)))
00548 #define floorf(x) ((float)floor((double)(x)))
00549 #define fmodf(x,y) ((float)fmod((double)(x),(double)(y)))
00550 #endif
00551 #define sqrtf(x) ((float)sqrt((double)(x)))
00552 #define sinf(x) ((float)sin((double)(x)))
00553 #define cosf(x) ((float)cos((double)(x)))
00554 #define tanf(x) ((float)tan((double)(x)))
00555 #define asinf(x) ((float)asin((double)(x)))
00556 #define acosf(x) ((float)acos((double)(x)))
00557 #define atanf(x) ((float)atan((double)(x)))
00558 #define atan2f(y,x) ((float)atan2((double)(y),(double)(x)))
00559 #define powf(x,y) ((float)pow((double)(x),(double)(y)))
00560 #define expf(x) ((float)exp((double)(x)))
00561 #define logf(x) ((float)log((double)(x)))
00562 #define log10f(x) ((float)log10((double)(x)))
00563 #endif
00564 #endif
00565
00566
00567
00568
00569
00570 extern FXAPI FXuint fxrandom(FXuint& seed);
00571
00572
00573 extern FXAPI FXbool fxmalloc(void** ptr,unsigned long size);
00574
00575
00576 extern FXAPI FXbool fxcalloc(void** ptr,unsigned long size);
00577
00578
00579 extern FXAPI FXbool fxresize(void** ptr,unsigned long size);
00580
00581
00582 extern FXAPI FXbool fxmemdup(void** ptr,const void* src,unsigned long size);
00583
00584
00585 extern FXAPI void fxfree(void** ptr);
00586
00587
00588 extern FXAPI void fxerror(const FXchar* format,...) FX_PRINTF(1,2) ;
00589
00590
00591 extern FXAPI void fxwarning(const FXchar* format,...) FX_PRINTF(1,2) ;
00592
00593
00594 extern FXAPI void fxmessage(const FXchar* format,...) FX_PRINTF(1,2) ;
00595
00596
00597 extern FXAPI void fxassert(const FXchar* expression,const FXchar* filename,unsigned int lineno);
00598
00599
00600 extern FXAPI void fxverify(const FXchar* expression,const FXchar* filename,unsigned int lineno);
00601
00602
00603 extern FXAPI void fxtrace(FXint level,const FXchar* format,...) FX_PRINTF(2,3) ;
00604
00605
00606 extern FXAPI void fxsleep(FXuint n);
00607
00608
00609 extern FXAPI FXint fxgetpid();
00610
00611
00612 extern FXAPI FXbool fxtoDOS(FXchar*& string,FXint& len);
00613
00614
00615 extern FXAPI FXbool fxfromDOS(FXchar*& string,FXint& len);
00616
00617
00618 extern FXAPI FXchar *fxstrdup(const FXchar* str);
00619
00620
00621 extern FXAPI FXuint fxstrhash(const FXchar* str);
00622
00623
00624 extern FXAPI void fxrgb_to_hsv(FXfloat& h,FXfloat& s,FXfloat& v,FXfloat r,FXfloat g,FXfloat b);
00625
00626
00627 extern FXAPI void fxhsv_to_rgb(FXfloat& r,FXfloat& g,FXfloat& b,FXfloat h,FXfloat s,FXfloat v);
00628
00629
00630 extern FXAPI void fxrgb_to_hsl(FXfloat& h,FXfloat& s,FXfloat& l,FXfloat r,FXfloat g,FXfloat b);
00631
00632
00633 extern FXAPI void fxhsl_to_rgb(FXfloat& r,FXfloat& g,FXfloat& b,FXfloat h,FXfloat s,FXfloat l);
00634
00635
00636 extern FXAPI FXint fxieeefloatclass(FXfloat number);
00637
00638
00639 extern FXAPI FXint fxieeedoubleclass(FXdouble number);
00640
00641
00642 extern FXAPI FXbool fxIsFinite(FXfloat number);
00643
00644
00645 extern FXAPI FXbool fxIsFinite(FXdouble number);
00646
00647
00648 extern FXAPI FXbool fxIsInf(FXfloat number);
00649
00650
00651 extern FXAPI FXbool fxIsInf(FXdouble number);
00652
00653
00654 extern FXAPI FXbool fxIsNan(FXfloat number);
00655
00656
00657 extern FXAPI FXbool fxIsNan(FXdouble number);
00658
00659
00660 extern FXAPI FXwchar fxkeysym2ucs(FXwchar sym);
00661
00662
00663 extern FXAPI FXwchar fxucs2keysym(FXwchar ucs);
00664
00665
00666 extern FXAPI FXint fxparsegeometry(const FXchar *string,FXint& x,FXint& y,FXint& w,FXint& h);
00667
00668
00669 extern FXAPI FXbool fxisconsole(const FXchar *path);
00670
00671
00672 extern FXAPI const FXuchar fxversion[3];
00673
00674
00675 extern FXAPI FXint fxTraceLevel;
00676
00677
00678 extern FXAPI FXwchar wc(const FXchar *ptr);
00679
00680
00681 extern FXAPI FXwchar wc(const FXnchar *ptr);
00682
00683
00684 extern FXAPI FXint wclen(const FXchar *ptr);
00685
00686
00687 extern FXAPI FXint wclen(const FXnchar *ptr);
00688
00689
00690 extern FXAPI FXint wcvalidate(const FXchar* string,FXint pos);
00691
00692
00693 extern FXAPI FXint wcvalidate(const FXnchar *string,FXint pos);
00694
00695
00696 extern FXAPI FXint wcinc(const FXchar* string,FXint pos);
00697
00698
00699 extern FXAPI FXint wcinc(const FXnchar *string,FXint pos);
00700
00701
00702 extern FXAPI FXint wcdec(const FXchar* string,FXint pos);
00703
00704
00705 extern FXAPI FXint wcdec(const FXnchar *string,FXint pos);
00706
00707
00708 extern FXAPI FXint utfslen(const FXwchar *str,FXint n);
00709
00710
00711 extern FXAPI FXint utfslen(const FXwchar *str);
00712
00713
00714 extern FXAPI FXint utfslen(const FXnchar *str,FXint n);
00715
00716
00717 extern FXAPI FXint utfslen(const FXnchar *str);
00718
00719
00720 extern FXAPI FXint wcslen(const FXchar *str,FXint n);
00721
00722
00723 extern FXAPI FXint wcslen(const FXchar *str);
00724
00725
00726 extern FXAPI FXint ncslen(const FXchar *str,FXint n);
00727
00728
00729 extern FXAPI FXint ncslen(const FXchar *str);
00730
00731
00732
00733 extern FXAPI FXint utf2wc(FXwchar& w,const FXchar* src);
00734
00735
00736
00737 extern FXAPI FXint wc2utf(FXchar* dst,FXwchar w);
00738
00739
00740
00741 extern FXAPI FXint utf2wcs(FXwchar *dst,FXint dn,const FXchar *src,FXint sn);
00742
00743
00744 extern FXAPI FXint utf2ncs(FXnchar *dst,FXint dn,const FXchar *src,FXint sn);
00745
00746
00747 extern FXAPI FXint wc2utfs(FXchar* dst,FXint dn,const FXwchar *src,FXint sn);
00748
00749
00750 extern FXAPI FXint nc2utfs(FXchar* dst,FXint dn,const FXnchar *src,FXint sn);
00751
00752
00753 extern FXAPI FXTime fxgetticks();
00754
00755 }
00756
00757 #endif