/************************************************************************* * sbBase.cpp - base types, platform-independent * * author: Konstantin Maslyuk "Kalemas" mailto:kalemas@mail.ru * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. ************************************************************************/ #ifndef SBBASE_H #define SBBASE_H #include #include #include #ifndef _WIN32_WCE #include #include #include #endif void sbMessage ( const char * format , ... ); #define sbAssert(condition) ((condition)?(sbMessage("sbAssert : " #condition ". at %s : %d\n", __FILE__, __LINE__), __debugbreak()) : 0) #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif /* * sbRect - screen rect */ struct sbRect { sbRect (int _left_ = 0, int _top_ = 0, int _right_ = 0, int _bottom_ = 0) : left (_left_) , top (_top_) , right (_right_) , bottom (_bottom_) { ; } inline int width () const { return (right - left); } inline int height () const { return (bottom - top); } inline bool inRect (int x, int y) const { return (x >= left && x < right && y >= top && y < bottom); } int left, top, right, bottom; }; /* * sbColor - color */ struct sbColor { sbColor ( unsigned char _red_ = 0, unsigned char _green_ = 0, unsigned char _blue_ = 0, unsigned char _alpha_ = 0 ) : red (_red_) , green(_green_) , blue (_blue_) , alpha (_alpha_) { ; } sbColor ( const char * color ) /* "RRGGBBAA" */ { char * stoped; unsigned long data = strtoul (color,&stoped,16); memcpy(&alpha,&data,sizeof(unsigned char)*4); } unsigned char alpha, blue, green, red; }; struct sbPoint { sbPoint(int _x_ = 0, int _y_ = 0) : x(_x_) , y(_y_) {;} int x, y; }; typedef void * sbThread; typedef void * sbSurface; typedef void * sbBitmap; typedef void * sbFont; sbThread sbThreadCreate ( void (*executor) (bool *) ); void sbThreadDestroy ( sbThread threadData ); void sbGetScreenRect ( sbRect & rect ); void sbUpdateScreen (); void sbDrawBitmap ( sbSurface, const sbRect * rect, sbBitmap bitmap, bool stretch = false ); sbBitmap sbLoadBitmap ( const TCHAR * filename ); void sbDeleteBitmap ( sbBitmap bitmap ); void sbDrawText ( sbSurface, int x, int y, const TCHAR * text, int count ); sbPoint sbGetTextExtent ( sbFont, const TCHAR * text, int count ); sbFont sbMakeFont ( int size, const TCHAR *face, bool bold, bool italic ); void sbDeleteFont ( sbFont ); void sbBitBlt ( sbSurface, sbRect toRect , sbSurface fromRc, sbPoint fromXy ); void sbStretchBlt ( sbSurface, sbRect toRect , sbSurface fromRc, sbRect fromRect ); sbSurface sbSurfaceCreate ( int width, int height ); void sbSurfaceDestroy ( sbSurface ); sbFont sbSelectFont ( sbSurface, sbFont ); void sbSelectColor ( sbSurface, sbColor ); void sbFillRect ( sbSurface, const sbRect * rect, sbColor color ); void sbDrawGradient ( sbSurface, const sbRect * rect, sbColor startColor, sbColor endColor, bool vertical ); void sbDrawLine ( sbSurface, sbPoint from, sbPoint to, sbColor, int thickness ); void sbSetTimer ( const int timer, int refreshRate ); void sbKillTimer ( const int timer ); long sbGetTickCount (); void sbSleep ( int milliseconds ); const char * sbGetLocale (); int sbWcsToMbs ( const TCHAR * wcs , char * mbs = NULL , int length = 0 ); void sbSetSip ( bool on ); bool sbQueryBox ( const TCHAR * question ); void sbWaitMode ( bool wait ); void sbExit ( int code ); enum { MSG_MOUSE_L_UP = 1000, MSG_MOUSE_L_DOWN, MSG_MOUSE_MOVE }; #endif