Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

base.h

00001 /*
00002    OpenGUI - Drawing & Windowing library
00003 
00004    Copyright (C) 1996,2005  Marian Krivos
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public
00017    License along with this library; if not, write to the Free
00018    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020    nezmar@atlas.sk
00021 
00022    base.h - base graphics support headers
00023 
00024   $Id: base.h,v 1.55 2005/02/08 12:30:37 majo Exp $
00025 
00026   Revision 1.29  2004/09/28 08:20:41  majo
00027   Calibration stuff
00028 
00029   Revision 1.28  2004/09/27 13:26:06  majo
00030   cal4
00031 
00032   Revision 1.27  2004/09/27 10:53:42  majo
00033   calibrating part III.
00034 
00035   Revision 1.26  2004/09/27 06:59:57  majo
00036   SetParameter(void *)
00037   Calibration part I.
00038 
00039   Revision 1.25.2.1  2004/09/07 11:41:08  majo
00040   verzia 5.0.0 alpha1
00041   new containers for Windows & Controls
00042 
00043   Revision 1.25  2004/08/26 05:45:35  majo
00044   added FGDrawBuffer::arc2()
00045 
00046   Revision 1.24  2004/08/25 21:16:10  majo
00047   priebezne zmeny
00048 
00049   Revision 1.23  2004/07/13 18:07:04  majo
00050   FGSIze docs
00051 
00052   Revision 1.22  2004/07/13 17:42:22  majo
00053   Added FGSize
00054 
00055   Revision 1.21  2004/07/07 16:51:32  majo
00056   FGSize
00057   FGWindowMenu::AddteText()
00058   FGMatrix::scale_with_center()
00059 
00060   Revision 1.20  2004/05/30 11:52:55  majo
00061   dox
00062 
00063   Revision 1.19  2004/05/24 17:40:41  majo
00064   bugs for FGRect
00065   added FGCircle
00066 
00067   Revision 1.18  2004/04/27 17:37:10  majo
00068   fixed bug in FGRect and FGPointArray
00069 
00070   Revision 1.17  2004/04/16 08:45:25  majo
00071   fixed clipping error
00072 
00073   Revision 1.16  2004/03/24 17:13:58  majo
00074   added FGXColor
00075   added FGColorPicker
00076 
00077   Revision 1.15  2004/03/18 16:05:27  majo
00078   readded changes to branch
00079 
00080   Revision 1.13  2004/03/09 20:23:58  majo
00081   added FGImage
00082   improved FGColor & and its docs
00083 
00084   Revision 1.12  2004/03/07 20:24:23  majo
00085 
00086   kompilacia FG*
00087 
00088   Revision 1.11  2004/03/03 20:12:38  majo
00089   added class FGColor
00090   fixed Solaris compiling
00091 
00092   Revision 1.10  2004/03/01 15:19:15  majo
00093   _GTRANSP -> _GCOLORKEY
00094   added _GTRANSPARENT
00095 
00096   Revision 1.9  2004/02/29 19:58:19  majo
00097   devel state
00098 
00099   Revision 1.8  2004/02/26 21:41:28  majo
00100   class FGInternalState
00101   char* -> const char*
00102   int ink = -1  -> unsigned ink = UNDEFINED_COLOR
00103 
00104   Revision 1.7  2004/02/24 17:34:59  majo
00105   FGTwostateButton
00106 
00107   Revision 1.6  2004/02/23 20:08:46  majo
00108   *
00109 
00110   Revision 1.5  2004/02/23 20:03:50  majo
00111   added FGPoint, FGPointArray (inspired by QT)
00112   FGDrawBuffer::save_state(), restore_state().
00113   all polygon functions are using FGPointArray instead (int, int [][2]).
00114   All classes are with prexix FG* on now (DrawBuffer -> FGDrawBuffer).
00115     but there are some macros to hide this behaviour.
00116   all FGDrawBuffer by parameters overloaded methods like box(x,y,w.h,ink)
00117     are now all-in-one.
00118 
00119   Revision 1.4  2004/02/10 16:18:59  majo
00120   fixed compile warnings
00121 
00122   Revision 1.3  2004/02/02 15:12:39  majo
00123   *** empty log message ***
00124 
00125   Revision 1.2  2004/01/22 17:49:11  majo
00126   Increased version number
00127 
00128   Revision 1.1.1.1  2004/01/22 16:25:08  majo
00129   initial release
00130 
00131 */
00132 
00133 #ifndef __BASE_H
00134 #define __BASE_H
00135 
00136 //#define FG_NAMESPACE      // uncoment this line if you want namespace support
00137 
00138 #ifdef __BORLANDC__
00139 #pragma option push -b
00140 #pragma option push -a4
00141 #endif
00142 
00143 #define FG_VERSION "5.2.0"
00144 #define FG_MAJOR    5
00145 #define FG_MINOR    2
00146 #define FG_PATCH    0
00147 
00148 #include "internal.h"
00149 
00150 /*
00151   todo 5.x:
00152    + SSE FGmemcpy
00153    - new Drawable for Windows
00154    + new Transformation layer for FGDrawBuffer
00155    - Save Images Bitmap
00156    - FGTheme
00157 */
00158 
00159 #ifdef FG_NAMESPACE
00160 
00167 namespace fgl {
00168 #else
00169 #define fgl
00170 #endif
00171 
00172 #define UNDEFINED_USER_DATA ((void *)(-1L))
00173 
00174 #ifdef INDEX_COLORS
00175 
00180 typedef unsigned char FGPixel;  // type of color (must correspond with bpp)
00181 #endif
00182 
00183 #if (DIRECT_COLORS==15) | (DIRECT_COLORS==16)
00184 typedef unsigned short FGPixel;     // type of color (must correspond with bpp)
00185 #endif
00186 
00187 #ifdef TRUE_COLORS
00188 typedef unsigned int FGPixel;   // type of color (must correspond with bpp)
00189 #endif
00190 
00191 typedef void (*blitter_t) (FGPixel *, FGPixel *, int, int, int, int);
00192 typedef void (*blitter2_t) (FGPixel *, FGPixel *, int, int, int, int, unsigned);
00193 typedef void (*blitter_a_t) (FGPixel *, FGPixel *, int, int, int, int, int, unsigned ppop);
00194 typedef int  (*shapper_t) (int, int, int, int, FGPixel ink, unsigned ppop);
00195 typedef void (*clipper_t) (int, int, int, int);
00196 typedef void (*plotter_t) (FGPixel *ptr, int x, int y, int ww, FGPixel ink, unsigned ppop);
00197 typedef void (*paletter_t) (unsigned, unsigned);
00198 typedef int  (*mouser_t) (int, int, int, int&);
00199 
00200 #define CR      13
00201 #define ESC     27
00202 #define TAB     9
00203 #define LF      10
00204 
00205 #define MIN(a,b)    ( (a) < (b) ? (a) : (b) )
00206 #define MAX(a,b)    ( (a) > (b) ? (a) : (b) )
00207 
00212 enum ENUM_PPOP
00213 {
00214     _GSET,              // 0
00215     _GXOR,
00216     _GAND,
00217     _GOR,
00218     _GPLUS,
00219     _GMINUS,
00220     _GNOT,
00221     _GREPLACE_GE16,     // 7
00222     _GTRANSPARENT,      // 8
00223     _GCOLORKEY,         // 9
00224     _GREPLACE_LE32,      // 10
00225     _GREPLACE_LE48,      // 10
00226     _GREPLACE_LE64,      // 10
00227     _GREPLACE_LE80,      // 10
00228     _GREPLACE_LESS      // 11
00229 };
00230 
00235 enum ENUM_VIDEOMODE {
00236     GTEXT,
00237     G320x200,
00238     G640x480,
00239     G800x600,
00240     G1024x768,
00241     G1280x1024,
00242     G1600x1200,
00243     GCUSTOM
00244 };
00245 
00251 enum ENUM_ROTATE_DIRECTION
00252 {
00253     ROTATE_90_CW,
00254     ROTATE_90_CCW,
00255     ROTATE_180,
00256     ROTATE_HORIZONTAL,
00257     ROTATE_VERTICAL
00258 };
00259 
00260 #define FG_BUTTON_NONE          0
00261 #define FG_BUTTON_LEFT          1
00262 #define FG_BUTTON_RIGHT         2
00263 #define FG_BUTTON_MIDDLE        4
00264 #define FG_BUTTON_WHEEL_UP      8
00265 #define FG_BUTTON_WHEEL_DOWN    16
00266 
00272 
00273 const unsigned BITBLIT_COPY =           0x0000;
00275 const unsigned BITBLIT_WITH_OPERATOR =  0x0200;
00277 const unsigned BITBLIT_WITH_ALPHA =     0x0400;
00279 const unsigned BITBLIT_WITH_CLIPPING =  0x1000;
00281 const unsigned BITBLIT_WITH_DECREMENT = 0x2000;
00282 
00283 #ifdef INDEX_COLORS
00284 
00285 const FGPixel CBLACK =  0;
00287 const FGPixel CDARK = 1;
00289 const FGPixel CGRAYED =  2;
00291 const FGPixel CGRAY1 =  3;
00293 const FGPixel CGRAY2 =  4;
00295 const FGPixel CGRAY3 =  5;
00297 const FGPixel CBLUE =  6;
00299 const FGPixel CBLUELIGHT=  7;
00301 const FGPixel CGREEN =  8;
00303 const FGPixel CGREENLIGHT = 9;
00305 const FGPixel CRED  =  10;
00307 const FGPixel CREDLIGHT =  11;
00309 const FGPixel CBROWN =  12;
00311 const FGPixel CYELLOW = 13;
00313 const FGPixel CWHITED = 14;
00315 const FGPixel CWHITE =  15;
00316 
00317 #else
00318 const FGPixel CBLACK = 0;
00319 const FGPixel CDARK = FGDirectColor(0x444444U);
00320 const FGPixel CGRAYED = FGDirectColor(0x585858U);
00321 const FGPixel CGRAY1 = FGDirectColor(0x7c8074U);
00322 const FGPixel CGRAY2 = FGDirectColor(0x687884U);
00323 const FGPixel CGRAY3 =  FGDirectColor(0xa8b8acU);
00324 const FGPixel CBLUE = FGDirectColor(0x000078U);
00325 const FGPixel CBLUELIGHT = FGDirectColor(0x0000f8U);
00326 const FGPixel CGREEN = FGDirectColor(0x007800U);
00327 const FGPixel CGREENLIGHT = FGDirectColor(0x00f800U);
00328 const FGPixel CRED = FGDirectColor(0xd44448U);
00329 const FGPixel CREDLIGHT = FGDirectColor(0xf80000U);
00330 const FGPixel CBROWN = FGDirectColor(0x684028U);
00331 const FGPixel CYELLOW = FGDirectColor(0xfce000U);
00332 const FGPixel CWHITED = FGDirectColor(0xd8d0b8U);
00333 const FGPixel CWHITE = FGDirectColor(0xffffffU);
00334 #endif // TRUE_COLORS
00335 
00336 const unsigned UNDEFINED_COLOR = unsigned(0xffffffffU);
00337 const unsigned DEFAULT_COLOR_KEY = unsigned(0x12345678U);
00338 const unsigned DEFAULT_ALPHA_VALUE = unsigned(0);
00339 
00340 #ifdef INDEX_COLORS
00341 
00345 #define FGCOLOR(i) (i)
00346 #else
00347 #define FGCOLOR(i) ((fgl::FGPixel) FGDirectColor(fgl::_fgl_palette[i]))
00348 #endif
00349 
00354 extern unsigned int long _fgl_palette[256];
00355 
00360 enum ENUM_EVENTS  {
00364 NOEVENT,
00371 KEYEVENT,
00375 MOUSEEVENT,
00381 QUITEVENT,
00402 ACCELEVENT,
00407 TERMINATEEVENT,
00411 CLOSEEVENT,
00425 MOVEEVENT,
00432 CLICKRIGHTEVENT,
00439 CLICKLEFTEVENT,
00446 CLICKMIDDLEEVENT,
00450 DRAGLEFTEVENT,
00454 DRAGRIGHTEVENT,
00459 GETFOCUSEVENT,
00464 LOSTFOCUSEVENT,
00470 INITEVENT,
00476 BUTTONHOLDEVENT,
00485 WINDOWRESIZEEVENT,
00490 WINDOWMOVEEVENT,
00498 STARTDRAGLEFTEVENT,
00506 STARTDRAGRIGHTEVENT,
00511 REPAINTEVENT,
00515 NOTIFYEVENT,
00519 ICONIZEEVENT,
00523 CURSOROUTEVENT,
00530 DBLCLICKRIGHTEVENT,
00537 DBLCLICKLEFTEVENT,
00544 DBLCLICKMIDDLEEVENT,
00551 MOUSEWHEELEVENT,
00555 TABSWITCHEVENT,
00557 LASTEVENT
00558 };
00559 
00560 struct variable_record;
00561 struct fonthdr;
00562 
00566 struct FGFont
00567 {
00568         char    name[24];
00569         int type, width, height;
00570         variable_record *var; // null or ptr
00571         FGPixel *fontimg;
00572     public:
00573         FGFont()
00574         {
00575             memset(this, 0, sizeof(*this));
00576         }
00577 };
00578 
00583 typedef int FGCOORD;
00584 
00630 struct FGPoint
00631 {
00632     FGCOORD x, y;
00636     FGPoint()
00637     {
00638         x=y=0;
00639     }
00643     FGPoint(int xpos, int ypos)
00644     {
00645         x = xpos;
00646         y = ypos;
00647     }
00648 
00652     FGPoint(double xpos, double ypos)
00653     {
00654         x = (int)xpos;
00655         y = (int)ypos;
00656     }
00657 
00662     inline bool isNull() const
00663     { return x == 0 && y == 0; }
00664 
00676     inline FGPoint &operator+=( const FGPoint &p )
00677     { x+=p.x; y+=p.y; return *this; }
00678 
00690     inline FGPoint &operator-=( const FGPoint &p )
00691     { x-=p.x; y-=p.y; return *this; }
00692 
00703     inline FGPoint &operator*=( int c )
00704     { x*=(FGCOORD)c; y*=(FGCOORD)c; return *this; }
00705 
00719     inline FGPoint &operator*=( double c )
00720     { x=(FGCOORD)(x*c); y=(FGCOORD)(y*c); return *this; }
00731     inline FGPoint &operator/=( int c )
00732     {
00733         x/=(FGCOORD)c;
00734         y/=(FGCOORD)c;
00735         return *this;
00736     }
00737 
00751     inline FGPoint &operator/=( double c )
00752     {
00753         x=(FGCOORD)(x/c);
00754         y=(FGCOORD)(y/c);
00755         return *this;
00756     }
00757 
00768     int ManhattanLength(void) const
00769     {
00770         return labs(x)+labs(y);
00771     }
00772 
00773     friend inline bool   operator==( const FGPoint &, const FGPoint & );
00774     friend inline bool   operator!=( const FGPoint &, const FGPoint & );
00775     friend inline const FGPoint operator+( const FGPoint &, const FGPoint & );
00776     friend inline const FGPoint operator-( const FGPoint &, const FGPoint & );
00777     friend inline const FGPoint operator*( const FGPoint &, int );
00778     friend inline const FGPoint operator*( int, const FGPoint & );
00779     friend inline const FGPoint operator*( const FGPoint &, double );
00780     friend inline const FGPoint operator*( double, const FGPoint & );
00781     friend inline const FGPoint operator-( const FGPoint & );
00782     friend inline const FGPoint operator/( const FGPoint &, int );
00783     friend inline const FGPoint operator/( const FGPoint &, double );
00784 };
00785 
00790 inline bool operator==( const FGPoint &p1, const FGPoint &p2 )
00791 { return p1.x == p2.x && p1.y == p2.y; }
00792 
00798 inline bool operator!=( const FGPoint &p1, const FGPoint &p2 )
00799 { return p1.x != p2.x || p1.y != p2.y; }
00800 
00801 
00807 inline const FGPoint operator+( const FGPoint &p1, const FGPoint &p2 )
00808 { return FGPoint(p1.x+p2.x, p1.y+p2.y); }
00809 
00810 
00818 inline const FGPoint operator-( const FGPoint &p1, const FGPoint &p2 )
00819 { return FGPoint(p1.x-p2.x, p1.y-p2.y); }
00820 
00827 inline const FGPoint operator*( const FGPoint &p, int c )
00828 { return FGPoint(p.x*c, p.y*c); }
00829 
00836 inline const FGPoint operator*( int c, const FGPoint &p )
00837 { return FGPoint(p.x*c, p.y*c); }
00838 
00848 inline const FGPoint operator*( const FGPoint &p, double c )
00849 { return FGPoint(p.x*c, p.y*c); }
00850 
00860 inline const FGPoint operator*( double c, const FGPoint &p )
00861 { return FGPoint((FGCOORD)(p.x*c), (FGCOORD)(p.y*c)); }
00862 
00869 inline const FGPoint operator-( const FGPoint &p )
00870 { return FGPoint(-p.x, -p.y); }
00871 
00878 inline const FGPoint operator/( const FGPoint &p, int c )
00879 {
00880     return FGPoint(p.x/c, p.y/c);
00881 }
00891 inline const FGPoint operator/( const FGPoint &p, double c )
00892 {
00893     return FGPoint((FGCOORD)(p.x/c), (FGCOORD)(p.y/c));
00894 }
00895 
00917 class FGSize
00918 {
00919     enum ScaleMode
00920     {
00921         ScaleFree,
00922         ScaleMin,
00923         ScaleMax
00924     };
00925 public:
00926     FGCOORD wd;
00927     FGCOORD ht;
00928 
00929     FGSize();
00930     FGSize( int w, int h );
00931 
00932     bool   isNull() const;
00933     bool   isEmpty()    const;
00934     bool   isValid()    const;
00935 
00936     int    width()  const;
00937     int    height() const;
00938     void   setWidth( int w );
00939     void   setHeight( int h );
00940     void   transpose();
00941 
00942     FGSize expandedTo( const FGSize & ) const;
00943     FGSize boundedTo( const FGSize & ) const;
00944 
00945     void scale( int w, int h, ScaleMode mode );
00946     void scale( const FGSize &s, ScaleMode mode );
00947 
00948     FGCOORD &rwidth();
00949     FGCOORD &rheight();
00950 
00951     FGSize &operator+=( const FGSize & );
00952     FGSize &operator-=( const FGSize & );
00953     FGSize &operator*=( int c );
00954     FGSize &operator*=( double c );
00955     FGSize &operator/=( int c );
00956     FGSize &operator/=( double c );
00957 
00958     friend inline bool  operator==( const FGSize &, const FGSize & );
00959     friend inline bool  operator!=( const FGSize &, const FGSize & );
00960     friend inline const FGSize operator+( const FGSize &, const FGSize & );
00961     friend inline const FGSize operator-( const FGSize &, const FGSize & );
00962     friend inline const FGSize operator*( const FGSize &, int );
00963     friend inline const FGSize operator*( int, const FGSize & );
00964     friend inline const FGSize operator*( const FGSize &, double );
00965     friend inline const FGSize operator*( double, const FGSize & );
00966     friend inline const FGSize operator/( const FGSize &, int );
00967     friend inline const FGSize operator/( const FGSize &, double );
00968 };
00969 
00970 /*****************************************************************************
00971   FGSize inline functions
00972  *****************************************************************************/
00973 
00974 inline FGSize::FGSize()
00975 { wd = ht = -1; }
00976 
00977 inline FGSize::FGSize( int w, int h )
00978 { wd=(FGCOORD)w; ht=(FGCOORD)h; }
00979 
00980 inline bool FGSize::isNull() const
00981 { return wd==0 && ht==0; }
00982 
00983 inline bool FGSize::isEmpty() const
00984 { return wd<1 || ht<1; }
00985 
00986 inline bool FGSize::isValid() const
00987 { return wd>=0 && ht>=0; }
00988 
00989 inline int FGSize::width() const
00990 { return wd; }
00991 
00992 inline int FGSize::height() const
00993 { return ht; }
00994 
00995 inline void FGSize::setWidth( int w )
00996 { wd=(FGCOORD)w; }
00997 
00998 inline void FGSize::setHeight( int h )
00999 { ht=(FGCOORD)h; }
01000 
01001 inline FGCOORD &FGSize::rwidth()
01002 { return wd; }
01003 
01004 inline FGCOORD &FGSize::rheight()
01005 { return ht; }
01006 
01007 inline FGSize &FGSize::operator+=( const FGSize &s )
01008 { wd+=s.wd; ht+=s.ht; return *this; }
01009 
01010 inline FGSize &FGSize::operator-=( const FGSize &s )
01011 { wd-=s.wd; ht-=s.ht; return *this; }
01012 
01013 inline FGSize &FGSize::operator*=( int c )
01014 { wd*=(FGCOORD)c; ht*=(FGCOORD)c; return *this; }
01015 
01016 inline FGSize &FGSize::operator*=( double c )
01017 { wd=(FGCOORD)(wd*c); ht=(FGCOORD)(ht*c); return *this; }
01018 
01019 inline bool operator==( const FGSize &s1, const FGSize &s2 )
01020 { return s1.wd == s2.wd && s1.ht == s2.ht; }
01021 
01022 inline bool operator!=( const FGSize &s1, const FGSize &s2 )
01023 { return s1.wd != s2.wd || s1.ht != s2.ht; }
01024 
01025 inline const FGSize operator+( const FGSize & s1, const FGSize & s2 )
01026 { return FGSize(s1.wd+s2.wd, s1.ht+s2.ht); }
01027 
01028 inline const FGSize operator-( const FGSize &s1, const FGSize &s2 )
01029 { return FGSize(s1.wd-s2.wd, s1.ht-s2.ht); }
01030 
01031 inline const FGSize operator*( const FGSize &s, int c )
01032 { return FGSize(s.wd*c, s.ht*c); }
01033 
01034 inline const FGSize operator*( int c, const FGSize &s )
01035 {  return FGSize(s.wd*c, s.ht*c); }
01036 
01037 inline const FGSize operator*( const FGSize &s, double c )
01038 { return FGSize((FGCOORD)(s.wd*c), (FGCOORD)(s.ht*c)); }
01039 
01040 inline const FGSize operator*( double c, const FGSize &s )
01041 { return FGSize((FGCOORD)(s.wd*c), (FGCOORD)(s.ht*c)); }
01042 
01043 inline FGSize &FGSize::operator/=( int c )
01044 {
01045     wd/=(FGCOORD)c; ht/=(FGCOORD)c;
01046     return *this;
01047 }
01048 
01049 inline FGSize &FGSize::operator/=( double c )
01050 {
01051     wd=(FGCOORD)(wd/c); ht=(FGCOORD)(ht/c);
01052     return *this;
01053 }
01054 
01055 inline const FGSize operator/( const FGSize &s, int c )
01056 {
01057     return FGSize(s.wd/c, s.ht/c);
01058 }
01059 
01060 inline const FGSize operator/( const FGSize &s, double c )
01061 {
01062     return FGSize((FGCOORD)(s.wd/c), (FGCOORD)(s.ht/c));
01063 }
01064 
01065 inline FGSize FGSize::expandedTo( const FGSize & otherSize ) const
01066 {
01067     return FGSize( MAX(wd,otherSize.wd), MAX(ht,otherSize.ht) );
01068 }
01069 
01070 inline FGSize FGSize::boundedTo( const FGSize & otherSize ) const
01071 {
01072     return FGSize( MIN(wd,otherSize.wd), MIN(ht,otherSize.ht) );
01073 }
01074 
01078 struct FGCircle : public FGPoint
01079 {
01080     FGCOORD     r;
01081 
01085     FGCircle()
01086      : FGPoint()
01087     {
01088         r=0;
01089     }
01090 
01095     FGCircle(int xpos, int ypos, int radius)
01096     : FGPoint(xpos,ypos)
01097     {
01098         r = radius;
01099     }
01100 
01103     FGCircle(const FGPoint point, int radius)
01104     : FGPoint(point)
01105     {
01106         r = radius;
01107     }
01120     inline bool isValid(void) const
01121     {
01122         return r >= 0;
01123     }
01124 
01141     inline bool isNull(void) const
01142     { return r == 0; }
01143 
01153     inline bool isEmpty(void) const
01154     {
01155         return r < 0;
01156     }
01164     bool   contains( double xc, double yc) const
01165     {
01166         if ( ((x-xc)*(x-xc) + (y-yc)*(y-yc)) <= ((double)r*r) )
01167             return true;
01168         return 0;
01169     }
01170 };
01171 
01172 class FGDrawBuffer;
01173 
01219 struct FGRect : public FGPoint
01220 {
01221     FGCOORD     w;
01222     FGCOORD     h;
01226     FGRect()
01227      : FGPoint()
01228     {
01229         w=h=0;
01230     }
01231 
01233     FGRect(const FGRect& old) { memcpy(this, &old, sizeof(*this)); }
01234 
01245     FGRect(int xpos, int ypos, int width, int height)
01246     : FGPoint(xpos,ypos)
01247     {
01248         w = width;
01249         h = height;
01250     }
01251 
01256     FGRect(int width, int height)
01257     : FGPoint(0, 0), w(width), h(height)
01258     {}
01259 
01264     FGRect(const FGPoint r0, const FGPoint r1)
01265     : FGPoint(r0)
01266     {
01267         w = r1.x - x;
01268         h = r1.y - y;
01269     }
01270 
01275     FGRect(const FGSize& sz)
01276     : FGPoint()
01277     {
01278         w = sz.width();
01279         h = sz.height();
01280     }
01281 
01286     FGRect(const FGCircle& c)
01287     : FGPoint(c.x-c.r, c.y-c.r)
01288     {
01289         w = h = c.r*2;
01290     }
01291 
01292     FGRect(const FGDrawBuffer& sprite);
01305     inline bool isValid(void) const
01306     {
01307         return w >= 0 && h >= 0;
01308     }
01309 
01326     inline bool isNull(void) const
01327     { return w == 0 && h == 0; }
01328 
01338     inline bool isEmpty(void) const
01339     {
01340         return w < 0 || h > 0;
01341     }
01342 
01352     FGRect  normalize(void) const
01353     {
01354         return *this;
01355     }
01356 
01362     FGCOORD left(void) const { return x; }
01363 
01369     FGCOORD right(void) const { return x+w; }
01375     FGCOORD top(void) const { return y; }
01381     FGCOORD bottom(void) const { return y+h; }
01387     FGPoint topLeft(void) const { return FGPoint(x,y); }
01393     FGPoint bottomRight(void) const { return FGPoint(int(x+w), int(y+h)); }
01397     FGPoint topRight(void) const { return FGPoint(x+w,y); }
01403     FGPoint bottomLeft(void) const { return FGPoint(x,y+h); }
01409     FGPoint center(void) const { return FGPoint( int(x+w/2), int(y+h/2)); }
01419     FGRect  operator|(const FGRect &r) const;
01427     FGRect  operator&(const FGRect &r) const;
01431     FGRect&  operator|=(const FGRect &r);
01435     FGRect&  operator&=(const FGRect &r);
01443     bool   contains( const FGPoint &p, bool proper=false ) const;
01451     bool   contains( int x, int y, bool proper=false ) const;
01463     bool   contains( const FGRect &r, bool proper=false ) const;
01468     FGRect unite( const FGRect &r ) const;
01473     FGRect intersect( const FGRect &r ) const;
01481     bool   intersects( const FGRect &r ) const
01482     {
01483         return ( MAX( x, r.x ) <= MIN( w, r.w ) &&
01484              MAX( y, r.y ) <= MIN( h, r.h ) );
01485     }
01486     friend bool operator==( const FGRect &, const FGRect & );
01487     friend bool operator!=( const FGRect &, const FGRect & );
01488 };
01489 
01494 bool operator==( const FGRect &r1, const FGRect &r2 );
01499 bool operator!=( const FGRect &r1, const FGRect &r2 );
01500 
01541 struct FGPointArray
01542 {
01543     unsigned int    vertices;
01544     FGPoint*        array;
01545     bool            allocated;
01546 
01550     void resize(unsigned new_size)
01551     {
01552         if (new_size != vertices)
01553         {
01554             if (allocated)
01555                 delete [] array;
01556 
01557             array = new FGPoint[vertices = new_size];
01558             allocated = true;
01559         }
01560     }
01567     inline bool isEmpty(void) const
01568     {
01569         return vertices <= 0;
01570     }
01575     FGPointArray()
01576     {
01577         vertices=0;
01578         array = 0;
01579         allocated = false;
01580     }
01584     ~FGPointArray()
01585     {
01586         if (allocated)
01587             if (array) delete [] array;
01588         array = 0;
01589     }
01596     FGPointArray(unsigned int nPoints)
01597     : vertices(nPoints)
01598     {
01599         if (vertices > 0)
01600         {
01601             array = new FGPoint[vertices];
01602             allocated = true;
01603         }
01604     }
01608     FGPointArray(const FGPointArray& old)
01609     {
01610         vertices = old.vertices;
01611         array = new FGPoint[vertices];;
01612         allocated = true;
01613 
01614         for(unsigned int i=0; i<vertices; i++)
01615             array[i] = old.array[i];
01616     }
01623     FGPointArray(unsigned int nPoints, FGPoint* points)
01624     : vertices(nPoints)
01625     {
01626         array = new FGPoint[vertices];
01627         allocated = true;
01628         for(unsigned int i=0; i<vertices; i++)
01629             array[i] = points[i];
01630     }
01637     FGPointArray(unsigned int nPoints, FGCOORD points[][2])
01638     : vertices(nPoints)
01639     {
01640         array = new FGPoint[vertices];
01641         allocated = true;
01642 
01643         SetPoints(vertices, (FGCOORD *)points);
01644     }
01654     FGPointArray( const FGRect &r, bool closed=false )
01655     {
01656         vertices = closed ? 5 : 4;
01657         array = new FGPoint[vertices];
01658         allocated = true;
01659 
01660         array[0] = r.topLeft();
01661         array[1] = r.bottomRight();
01662         array[2] = r.topRight();
01663         array[3] = r.bottomLeft();
01664         if (vertices == 5)
01665             array[4] = r.topLeft();
01666     }
01673     FGPointArray( unsigned int nPoints, const FGCOORD *points )
01674      : vertices(nPoints)
01675     {
01676         array = new FGPoint[vertices];
01677         allocated = true;
01678 
01679         SetPoints(vertices, points);
01680     }
01698     void SetPoints( unsigned int nPoints, const FGCOORD *points )
01699     {
01700         resize(nPoints);
01701         for(unsigned int i=0; i<vertices; i++)
01702         {
01703             array[i].x = *points++;
01704             array[i].y = *points++;
01705         }
01706     }
01728     void SetPoints( unsigned nPoints, int firstx, int firsty, ... )
01729     {
01730         SetPoints(nPoints, (FGCOORD *) &firstx);
01731     }
01749     void SetPoints( unsigned int nPoints, const double *points )
01750     {
01751         resize(nPoints);
01752         for(unsigned int i=0; i<vertices; i++)
01753         {
01754             array[i].x = FGCOORD(*points++);
01755             array[i].y = FGCOORD(*points++);
01756         }
01757     }
01761     void translate( int dx, int dy )
01762     {
01763         register FGPoint *p = array;
01764         register int i = vertices;
01765         FGPoint pt( dx, dy );
01766         while ( i-- )
01767         {
01768             *p += pt;
01769             p++;
01770         }
01771     }
01775     FGRect BoundingRect() const;
01776 
01781     bool   contains(const FGPoint &p) const;
01786     bool   contains(int x, int y) const;
01787 };
01788 
01789 
01790 #define MAX_FONTS       64
01791 
01796 enum ENUM_FONTS
01797 {
01798     FONT0406,
01799     FONT0808,
01800     FONT0816,
01801     FONT1222,
01802     FONT1625,
01803     FONT2034,
01804     FONTSYS,
01805     FONTSYSMEDIUM,
01806     FONTSYSLIGHT,
01807 
01808     FONTLAST=(MAX_FONTS-1)
01809 };
01810 
01814 class FGFontProperty
01815 {
01816     public:
01818         enum FONT_STYLE { ttfSolid, ttfShaded, ttfBlended };
01819     private:
01820         void        *_font;
01821         FONT_STYLE  algorithm;
01822     public:
01829         FGFontProperty(char *n, int sz);
01833         ~FGFontProperty();
01837         void Bold(int value);
01841         void Underline(int value);
01845         void Italic(int value);
01849         void Solid(void) { algorithm = ttfSolid; }
01853         void Shaded(void) { algorithm = ttfShaded; }
01858         void Blended(void) { algorithm = ttfBlended; } // not implemented yet
01863         bool Valid(void) { return !!_font; }
01864         FONT_STYLE GetAlgorithm(void) { return algorithm; }
01865         void * GetFace(void) { return _font; }
01866         char * PrepareFont(variable_record *var, int& size, int count, int offset, char *name);
01867 };
01868 
01875 class FGFontManager
01876 {
01877         static FGFont   FGFonts[MAX_FONTS];
01878         static int      font_counter;
01879         // register variable font from memory
01880         // img and data must be allocated with malloc
01881         static int FGAPI register_font_var(variable_record *data, char *img, int size, char *desc);
01882         // register variable font from compiled font
01883         static int FGAPI register_font_image(fonthdr * hdr, char *img, char *desc);
01884         static void FGAPI deregister_fonts(void);
01885         static int FGAPI _register_font(unsigned char *source, int width, int height, int count, int offset, variable_record * type, int index, char *desc);
01886     public:
01887         FGFontManager();
01888         ~FGFontManager();
01889 
01890         static int FGAPI register_font_ttf(char *filename, int points, int count=128-' ', int offset=' ', char *desc=0);
01891         static int FGAPI register_font_fix(unsigned char *source, int width, int height, int count, int offset, char *desc);
01892         static int FGAPI register_font_file(const char *source, char *desc);
01893 
01894         static int FGAPI textwidth(int ID, const char *txt);
01895         static int FGAPI textwidth(int ID, const char *txt, int cnt);
01896         static int FGAPI charwidth(int ID, int c);
01897 
01903         static FGFont * FGAPI get_font_ptr(int ID)
01904         {
01905             if (ID<0 || ID>font_counter)
01906                 return 0;
01907             // test for defined fonts
01908             if (!FGFonts[ID].fontimg)
01909                 return 0;
01910             return &FGFonts[ID];
01911         }
01917         static inline int FGAPI GetW(int ID)
01918         {
01919             return FGFonts[ID].width;
01920         }
01925         static inline int FGAPI GetH(int ID)
01926         {
01927             return FGFonts[ID].height;
01928         }
01934         static inline variable_record * FGAPI IsVariableFont(int ID)
01935         {
01936             return FGFonts[ID].var;
01937         }
01942         static inline FGPixel * FGAPI GetFontImage(int ID)
01943         {
01944             return FGFonts[ID].fontimg;
01945         }
01950         static inline char * FGAPI GetFontName(int ID)
01951         {
01952             return FGFonts[ID].name;
01953         }
01957         static inline int FGAPI GetCounter(void)
01958         {
01959             return font_counter;
01960         }
01961 };
01962 
01963 extern FGFontManager fontman;
01964 
01968 struct FGPattern
01969 {
01970     FGPixel *data;
01971     int len, masked, reset, pos;
01972     FGPixel next(void);
01973 
01974     FGPattern(FGPixel * pp, int l, int m, int r = 1):data(pp), len(l),
01975       masked(m), reset(r), pos(0)
01976     {
01977     }
01978 };
01979 
01980 void delay(unsigned int);
01981 
01982 #ifdef _WIN32
01983 void sound(unsigned);
01984 void nosound(void);
01985 #endif
01986 
01987 void outpb(unsigned, unsigned);
01988 void outpw(unsigned, unsigned);
01989 unsigned char inpb(unsigned);
01990 unsigned short inpw(unsigned);
01991 unsigned int inpl(unsigned);
01992 void outpl(unsigned, unsigned);
01993 
01994 extern FGPattern PatternDot , PatternSlashDot , PatternSlashDotSlash , PatternSlash ;
01995 
01996 //unsigned long long _rdtsc(void);
01997 #ifndef __BORLANDC__
01998 char *strupr(register char *s);
01999 int stricmp(const char *s1, const char *s2);
02000 int strnicmp(const char *s1, const char *s2, size_t cnt);
02001 char *strlwr(char *_s);
02002 #endif
02003 
02007 int  get_point(int x, int y);
02008 void draw_hline(int x, int y, int w, FGPixel ink, unsigned ppop);
02009 void draw_box(int x, int y, int w, int h, FGPixel ink, unsigned ppop);
02010 void fill_box(int x, int y, int w, int h, FGPixel ink, unsigned ppop);
02011 void draw_point(int x, int y, FGPixel color, unsigned ppop);
02012 int  draw_line(int x, int y, int x1, int y1, FGPixel color, unsigned ppop);
02013 #define draw_line(a,b,c,d,e,f) vector_draw_line(a,b,c,d,e,f)
02014 int  FGAPI drawto_line(int x, int y, FGPixel ink, unsigned ppop);
02015 void FGAPI draw_pattern_line(int x, int y, int x1, int y1, FGPattern *, unsigned ppop);
02016 void FGAPI drawto_pattern_line(int x, int y, FGPattern *, unsigned ppop);
02017 void FGAPI draw_pattern_box(int x, int y, int a, int b, FGPattern *pat, unsigned ppop);
02018 void FGAPI draw_spline(FGPoint points[4], FGPixel ink, unsigned ppop);
02019 void calc_spline(FGPoint points[], int npts, FGPoint output[]);
02020 void FGAPI moveto(int x, int y);
02021 unsigned int FGAPI areasize(int x, int y);
02022 
02023 void FGAPI _set_default_palette(void);
02024 void FGAPI _set_fgl_palette(void);
02025 unsigned int FGAPI get_palette(unsigned int i);
02026 void _palette(unsigned, unsigned int);
02027 void FGAPI CreatePaletteEntry(int rc, int gc, int bc, int idx);
02028 
02029 int FGAPI text_out(int x, int y, char *txt, FGPixel ink, FGPixel paper, unsigned ppop, int f=FONT0816);
02030 void FGAPI fill_convex(const FGPointArray* poly, FGPixel ink, unsigned ppop);
02031 void FGAPI draw_convex(const FGPointArray* poly, FGPixel ink, unsigned ppop);
02032 void FGAPI get_block(int x, int y, int a, int b, FGPixel * p);
02033 void FGAPI put_block(int x, int y, int a, int b, FGPixel * p, unsigned ppop);
02034 void FGAPI set_clip_rect(int w, int h, int x, int y);
02035 
02036 void FGAPI fill_ellipse(int x, int y, int rx, int ry, FGPixel ink, unsigned ppop);
02037 void FGAPI draw_ellipse(int x, int y, int rx, int ry, FGPixel ink, unsigned ppop);
02038 void FGAPI draw_arc(int x, int y, double ang1, double ang2, int r, FGPixel ink, unsigned ppop);
02039 void FGAPI draw_circle(int x, int y, int r, FGPixel ink, unsigned ppop);
02040 void FGAPI fill_circle(int xs, int ys, int r, FGPixel ink, unsigned ppop);
02041 
02042 void RamToVideo(FGPixel * Image, int x, int y, int xm, int ym, int w, int h, int cx_max, int cy_max, int opcia, unsigned ppop);
02043 void VideoToRam(FGPixel * Image, int x, int y, int xm, int ym, int w, int h, int cx_max, int cy_max);
02044 void RamToRam(int x, int y, int xmax, int ymax, int xdst, int ydst, int xmaxdst, int ymaxdst, int w, int h, FGPixel * from, FGPixel * to, unsigned alpha, unsigned ppop);
02045 int gprintf(FGPixel ink, FGPixel paper, int x, int y, const char *format,...);
02052 int FGAPI GetFreeColors(void);
02053 void FGAPI SetColorFuzzy(int a);
02054 FGPixel FGAPI CreateColor(int, int, int, int);
02055 void FGAPI DeleteColor(int);
02056 void FGAPI set_transpcolor(FGPixel);
02059 void FGmemcpy(FGPixel * to, FGPixel * from, unsigned c);
02060 void FGmemset(FGPixel * to, FGPixel data, unsigned c);
02061 void FGmemcpy2(FGPixel * to, FGPixel * from, unsigned c, unsigned ppop);
02062 void FGmemset2(FGPixel * to, FGPixel data, unsigned c, unsigned ppop);
02063 
02069 void clear_frame_buffer(FGPixel c);
02070 int graph_set_mode(int mode);
02078 int graph_change_mode(int ww, int hh);
02079 void cleanup(void);
02080 int FGAPI get_colordepth(void);
02081 unsigned FGAPI GetXRes(void);
02082 unsigned FGAPI GetYRes(void);
02083 FGPixel * FGAPI GetFrameBuffer(void);
02084 
02089 enum ENUM_BUFFERING
02090 {
02091     FG_DOUBLEBUFFER=2,
02092     FG_TRIPLEBUFFER,
02093     FG_QUADBUFFER
02094 };
02095 
02100 unsigned long FGAPI FGClock(void);
02101 void FGAPI Snd(int a, int b);
02102 void FGAPI Puk(void);
02103 
02108 const char* GetVer(void);
02109 void UpdateRect(int x, int y, int xm, int ym, int w, int h);
02110 int  GetPriv(void);
02111 
02112 class FGDriver;
02113 
02114 extern FGDriver *__fg_driver;
02115 extern int sound_enabled;
02116 
02117 // draw clipped to screen line
02118 extern shapper_t   vector_draw_line;
02119 
02120 // draw clipped to screen rect
02121 extern clipper_t   vector_clip_rect;
02122 
02123 // draw clipped to screen plot
02124 extern plotter_t   vector_draw_point;
02125 
02126 // draw clipped to screen box
02127 extern shapper_t   vector_fill_box;
02128 
02129 // set 8 bit palette (shift needed for 6-bit palette)
02130 // palette_8 is accepted
02131 extern paletter_t  vector_palette;
02132 
02133 // bitblit copy
02134 extern blitter_t   vector_blit_copy;
02135 extern blitter2_t   vector_blit_op;
02136 extern blitter_a_t vector_blit_a;
02137 
02149 class FGConnector
02150 {
02151         void*   parameter1;
02152         class   FGConnector *sendTo;
02153     public:
02160         void    FGAPI SetParameter(void* a) { parameter1 = a; }
02167         void*   FGAPI GetParameter(void)  const { return parameter1; }
02168 
02169         FGConnector()
02170         {
02171             SetParameter( UNDEFINED_USER_DATA );
02172             sendTo = 0;
02173         }
02181         void    FGAPI Connect(FGConnector *from, void* par)
02182         {
02183             sendTo = from;
02184             SetParameter(par);
02185         }
02187         virtual void OnSignal(FGConnector *sender, void* value)
02188         {
02189         }
02191         void FGAPI RunSignal(void)
02192         {
02193             if (sendTo)
02194                 sendTo->OnSignal(this, parameter1);
02195         }
02196 };
02197 
02203 #define     FGCONNECT(sender, THIS, PARAM1) { (sender)->Connect((THIS), (void *)(PARAM1)); }
02204 
02209 enum ENUM_MUTEX_TYPE
02210 {
02211     fastMutEx=1,
02212     recursiveMutEx
02213 };
02214 
02219 class FGMutex
02220 {
02221 #ifdef _PTHREAD_H
02222         int             type;
02223         pthread_mutex_t m_mutex;
02224 #endif
02225 #ifdef _WIN32
02226         CRITICAL_SECTION m_mutex;
02227 #endif
02228 #ifdef FG_THREADED
02229         void init(ENUM_MUTEX_TYPE typ);
02230 #endif
02231     public:
02233         FGMutex(ENUM_MUTEX_TYPE typ = fastMutEx)
02234 #ifdef FG_THREADED
02235         ;
02236 #else
02237         {}
02238 #endif
02239 
02240         FGMutex(const FGMutex& old)
02241 #ifdef FG_THREADED
02242         ;
02243 #else
02244         {}
02245 #endif
02246 
02247         ~FGMutex()
02248 #ifdef FG_THREADED
02249         ;
02250 #else
02251         {}
02252 #endif
02253 
02254         void Lock()
02255 #ifdef FG_THREADED
02256         ;
02257 #else
02258         {}
02259 #endif
02260 
02261         void Unlock()
02262 #ifdef FG_THREADED
02263         ;
02264 #else
02265         {}
02266 #endif
02267 
02268         bool TryLock()
02269 #ifdef FG_THREADED
02270         ;
02271 #else
02272         { return true; }
02273 #endif
02274 };
02275 
02282 class FGDrawBuffer : public FGConnector
02283 {
02284         struct internal_state
02285         {
02286             unsigned       _ink;
02287             unsigned       _paper;
02288             int            _font;   // font code
02289             unsigned       _ppop;
02290             unsigned       colorkey;
02291             unsigned       alpha;
02292         };
02293 
02294     public:
02295         enum ObjectType {   WINDOW=0x4000, CHECKBUTTON, PUSHBUTTON, POINTBUTTON, EDITBOX, PROGRESSBAR,
02296             BASEMENU, BASEMENUITEM, MENUWINDOW, SLIDEBAR, MULTILINEEDIT, LISTBOX, LABEL, WINDOWPANEL,
02297             BMP_FILE, BMP_IMAGE, BMP_MEM, ROOTWINDOW, FGFRAMEBUFFER, COMBOBOX, WINDOWTEXT, WINDOWIMAGE,
02298             PUSHBUTTON_IMAGE,
02299             BMP_NONE=0 };
02300         friend class GLSurface;
02301         friend class listbox;
02302     private:
02303         static  int ID_counter;
02304         int     id;
02305         FGMutex atomic;
02306 
02307         inline void lock(void)
02308         {
02309             atomic.Lock();
02310         }
02311         inline void unlock(void)
02312         {
02313             atomic.Unlock();
02314         }
02315         void    FGAPI _symetry(int xs, int ys, int x,   int y, FGPixel color);
02316         void    FGAPI _symetry2(int xs, int ys, int x, int y, FGPixel color);
02317         void    FGAPI _init(int ww, int hh, ObjectType t, FGPixel ii=CBLACK, FGPixel pp=CWHITE, const char *nm=0);
02318         void    FGAPI turn_bitmap(int cnt, FGPixel *from, FGPixel *to);
02319     protected:
02320         int     w;
02321         int     h;
02322         int     xoff,yoff;  // coor
02323         int     wwrk,hwrk;  // sizes!!!
02324         unsigned long   status;
02325         FGMutex clip_lock;
02326         FGPixel *image;
02327         char    *name;
02328         union   { ObjectType    type; int _asd; };
02329 
02330         internal_state state;
02331         internal_state state_backup;
02332         bool        state_saved;
02333 
02334         static  const char *empty_string;
02335         static  int oldx, oldy;
02336 
02337         FGPixel *   FGAPI SetArray(FGPixel *array)
02338         {
02339             if (image) free(image);
02340             return image = array;
02341         }
02342 
02343         FGDrawBuffer(int ww, int hh, const char * nm, ObjectType t, FGPixel i, FGPixel p);
02344 
02345         void    FGAPI SetStatus(long s) {   status = s; }
02346         static int FGAPI GetCounter(void) { return ID_counter; }
02348         inline int FGAPI clip(int& xr, int& yr, int& wr, int& hr)
02349         {
02350             if (xr<xoff)
02351             {
02352                 wr -= (xoff-xr);
02353                 xr = xoff;
02354             }
02355             if (yr<yoff)
02356             {
02357                 hr -= (yoff-yr);
02358                 yr = yoff;
02359             }
02360             if (xr+wr > xoff+wwrk)
02361             {
02362 // FIXME
02363                 wr = wwrk-(xr-xoff);
02364 //              wr = wwrk;
02365             }
02366             int yoff2 = h - (hwrk+yoff);
02367             if (yr+hr > h-yoff2)
02368             {
02369                 hr = h-yr-yoff2;
02370             }
02371             return (wr<1 || hr<1) ? 0 : 1; // return if valid
02372         }
02373         inline int FGAPI clip_shape(int& xr, int& yr, int& wr, int& hr)
02374         {
02375             if (xr<0)
02376             {
02377                 wr += xr;
02378                 xr = 0;
02379             }
02380             if (yr<0)
02381             {
02382                 hr += yr;
02383                 yr = 0;
02384             }
02385             if (xr+wr>w)
02386             {
02387                 wr = w-xr;
02388             }
02389             if (yr+hr>h)
02390             {
02391                 hr = h-yr;
02392             }
02393             return (wr<1 || hr<1) ? 0 : 1; // return if valid
02394         }
02395         void    FGAPI modify_point(FGPixel *ptr, FGPixel ink);
02396         void    __line(int,int,int,int, unsigned color);
02397     public:
02400         void save_state(void)
02401         {
02402             lock();
02403             if (state_saved)
02404             {
02405                 ::printf("FGDrawBuffer::save_state() multiple call!\n");
02406             }
02407             else
02408             {
02409                 state_backup = state;
02410             }
02411             state_saved = true;
02412             unlock();
02413         }
02415         void restore_state(void)
02416         {
02417             lock();
02418             if (state_saved == false)
02419             {
02420                 ::printf("FGDrawBuffer::restore_state() called without save_state()!\n");
02421             }
02422             else
02423             {
02424                 state = state_backup;
02425             }
02426             state_saved = false;
02427             unlock();
02428         }
02432         inline FGPixel* FGAPI CalcAddr(int x, int y)
02433         {
02434             return image + (w * y + x);
02435         }
02439         void    FGAPI Resize(int dx, int dy);
02443         long    FGAPI GetStatus(void)  const    { return status; }
02446         inline  void FGAPI set_font(int font_id)
02447         {
02448             if (FGFontManager::get_font_ptr(font_id))
02449                 state._font = font_id;
02450         }
02452         inline  int FGAPI get_font(void)
02453         {
02454             return state._font;
02455         }
02457         inline int  FGAPI textwidth(const char *text)
02458         {
02459             return FGFontManager::textwidth(state._font, text);
02460         }
02463         inline int  FGAPI textwidth(char *txt, int cnt)
02464         {
02465             return FGFontManager::textwidth(state._font, txt, cnt);
02466         }
02468         inline int  FGAPI charwidth(int c)
02469         {
02470             return FGFontManager::charwidth(state._font, c);
02471         }
02473         inline int  FGAPI GetFontW(void)
02474         {
02475             return FGFontManager::GetW(state._font);
02476         }
02478         inline int  FGAPI GetFontH(void)
02479         {
02480             return FGFontManager::GetH(state._font);
02481         }
02484         inline unsigned FGAPI set_ppop(unsigned op)
02485         {
02486             unsigned oldp = state._ppop;
02487             state._ppop = op;
02488             return oldp;
02489         }
02493         inline  void FGAPI set_fcolor(FGPixel val) { state._ink = val; }
02497         inline  void FGAPI set_bcolor(FGPixel val) { state._paper = val; }
02500         inline  void FGAPI set_colors(FGPixel i, FGPixel p) { state._ink = i; state._paper = p; }
02502 
02511         int     FGAPI GetId(void)  const    { return id; }
02513         inline bool FGAPI set_clip_rect(int xx, int yy, int ww, int hh)
02514         {
02515             if (hh<1 || ww<1 || xx<0 || yy<0) return false;
02516             xoff = xx;
02517             yoff = yy;
02518             if ((xx + ww)   > w) ww -= ((xx + ww) - w);
02519             if ((yy + hh)   > h) hh -= ((yy + hh) - h);
02520             wwrk = ww;
02521             hwrk = hh;
02522             return true;
02523         }
02525         inline void FGAPI get_clip_rect(int& x,int& y,int& w,int& h)
02526         {
02527             x = xoff;
02528             y = yoff;
02529             w = wwrk;
02530             h = hwrk;
02531         }
02532         FGDrawBuffer(int ww=0, int hh=0, ObjectType=BMP_MEM, int color=CBLACK, FGPixel *buf=0);
02533         FGDrawBuffer(int ww, int hh, FGPixel *buf);
02535         FGDrawBuffer(FGDrawBuffer &);
02536 
02537         virtual ~FGDrawBuffer();
02538 
02539         // copy block from one buffer to other (with ppop or alpha)
02540         // this is software blitter only.
02541         int         FGAPI bitblit(int xdst, int ydst, int xsrc, int ysrc, int ww, int hh, class FGDrawBuffer *src, int opcia=BITBLIT_COPY);
02542         int         FGAPI hline(int x, int y, int size, FGPixel color);
02543         int         FGAPI vline(int x, int y, int size, FGPixel color);
02544 
02546         void        FGAPI moveto(int x, int y) { oldx = x; oldy = y; }
02547         int         FGAPI line(int x, int y, int x2, int y2, unsigned color = UNDEFINED_COLOR);
02548         int         FGAPI lineto(int x, int y, unsigned color = UNDEFINED_COLOR);
02549         int         FGAPI pline(int x1, int y1, int x2, int y2, FGPattern *p);
02550 
02551         void        FGAPI spline(FGPoint points[4], unsigned color = UNDEFINED_COLOR);
02552 
02553         int         FGAPI rect(int xdst, int ydst, int ww, int hh, unsigned color = UNDEFINED_COLOR);
02554         int         FGAPI box(int xdst, int ydst, int ww, int hh, unsigned color = UNDEFINED_COLOR);
02555 
02556         int         FGAPI text(int x, int y, const char *txt, unsigned i = UNDEFINED_COLOR, unsigned p = UNDEFINED_COLOR);
02557 #undef printf
02558         int         printf(int , int , const char * , ... );
02559         int         FGAPI putpixel(int x, int y, unsigned color = UNDEFINED_COLOR);
02564         int         FGAPI getpixel(int x, int y)
02565         {
02566             if (x<0 || y<0 || x>=wwrk || y>=hwrk)
02567                 return 0xFFFFFFFF;
02568             return *(image+(x+xoff)+(y+yoff)*w);
02569         }
02570         void        FGAPI stretch(int _w, int _h);
02571         void        FGAPI stretch(double ratiox, double ratioy);
02572 
02573         int         FGAPI arc(int   x,  int y,  double ang1, double ang2, int r, unsigned color = UNDEFINED_COLOR);
02574         int         FGAPI arc2(int  x,  int y,  int ang1, int ang2, int r, unsigned color = UNDEFINED_COLOR);
02575         int         FGAPI ellipse(int x, int y, int rx, int ry, unsigned color = UNDEFINED_COLOR);
02576         int         FGAPI fellipse(int x, int y, int rx, int ry, unsigned color = UNDEFINED_COLOR);
02577         int         FGAPI circle(int    xs, int ys, int r, unsigned color = UNDEFINED_COLOR);
02578         int         FGAPI fcircle(int   xs, int ys, int r, unsigned color = UNDEFINED_COLOR);
02579 
02580         void        FGAPI polygon(const FGPointArray& vertices, unsigned color = UNDEFINED_COLOR);
02581         FGRect      FGAPI fpolygon(const FGPointArray& vertices, unsigned color = UNDEFINED_COLOR);
02582 
02583         FGRect      FGAPI ftriangle(int x1, int y1, int x2, int y2, int x3, int y3, unsigned color = UNDEFINED_COLOR);
02584 
02586         FGPixel*    FGAPI GetArray(void) const { return image; }
02588         unsigned    FGAPI GetAlpha(void) const { return state.alpha; }
02590         FGPixel     FGAPI GetInk(void)  const { return (FGPixel)state._ink; }
02592         FGPixel     FGAPI GetPaper(void)  const { return    (FGPixel)state._paper; }
02594         int         FGAPI GetW(void)  const { return    w; }
02596         int         FGAPI GetH(void)  const { return    h; }
02598         int         FGAPI GetXW(void) const { return xoff; }
02600         int         FGAPI GetYW(void) const { return yoff; }
02602         int         FGAPI GetWW(void) const {   return wwrk; }
02604         int         FGAPI GetHW(void) const {   return hwrk; }
02606         enum ObjectType     FGAPI GetType(void)  const {    return type; }
02608         unsigned    FGAPI GetColorKey(void) const { return state.colorkey; }
02610         char*       FGAPI GetName(void)  const {    return name; }
02613         void        FGAPI SetColorKey(unsigned ck)
02614         {
02615             state.colorkey = ck;
02616         }
02617         void        FGAPI SetName(const char *s);
02622         void        FGAPI SetAlpha(unsigned a) { state.alpha = a; }
02624         void        FGAPI clear(int color) { FGmemset(image, color, w*h); }
02628         void        FGAPI rotate(ENUM_ROTATE_DIRECTION direction);
02629 };
02630 
02631 #define SAVE_CLIPPING(THIS) int _a,_b,_c,_d; clip_lock.Lock(); _a = (THIS)->xoff; _b = (THIS)->yoff; _c = (THIS)->wwrk; _d = (THIS)->hwrk; (THIS)->xoff = 0; (THIS)->yoff = 0; (THIS)->wwrk = (THIS)->w; (THIS)->hwrk = (THIS)->h;
02632 #define SAVE_CLIPPING2(THIS) clip_lock.Lock(); _a = (THIS)->xoff; _b = (THIS)->yoff; _c = (THIS)->wwrk; _d = (THIS)->hwrk; (THIS)->xoff = 0; (THIS)->yoff = 0; (THIS)->wwrk = (THIS)->w; (THIS)->hwrk = (THIS)->h;
02633 #define RESTORE_CLIPPING(THIS)  (THIS)->xoff = _a; (THIS)->yoff = _b; (THIS)->wwrk = _c; (THIS)->hwrk = _d; clip_lock.Unlock();
02634 
02638 struct FGMouseCursor
02639 {
02640     FGPixel *bitmap;
02641     FGPixel *mask;
02642     int xoff, yoff;
02643     unsigned w,h;
02644 
02645     FGMouseCursor(FGPixel *a, FGPixel *b, int c, int d, int e, int f)
02646         : bitmap(a), mask(b), xoff(c), yoff(d), w(e), h(f)
02647     {
02648     }
02649 };
02650 
02654 struct FGPalette
02655 {
02656         unsigned char b;
02657         unsigned char g;
02658         unsigned char r;
02659         unsigned char alfa;
02660       public:
02661         FGPalette(void)
02662         {
02663             r = g = b = alfa = 0;
02664         }
02665         FGPalette(unsigned p)
02666         {
02667             *((unsigned *) this) = p;
02668         }
02669         FGPalette(unsigned char _r, unsigned char _g, unsigned char _b)
02670         {
02671             r = _r;
02672             g = _g;
02673             b = _b;
02674             alfa = 0;
02675         }
02676         unsigned int GetValue(void)
02677         {
02678             return *((unsigned *) this);
02679         }
02680 };
02681 
02682 extern const FGMouseCursor IDC_NORMAL_SMALL;
02683 extern const FGMouseCursor IDC_NORMAL_LARGE;
02684 extern const FGMouseCursor *idc_normal;
02685 
02689 class FGInputDevice
02690 {
02691     protected:
02692         bool working;
02693 
02694         struct POINT
02695         {
02696             int x, y;
02697         };
02698 
02699         struct MATRIX
02700         {
02701             /* This arrangement of values facilitates
02702              *  calculations within getDisplayPoint()
02703              */
02704             double An,                  /* A = An/Divider */
02705               Bn,                       /* B = Bn/Divider */
02706               Cn,                       /* C = Cn/Divider */
02707               Dn,                       /* D = Dn/Divider */
02708               En,                       /* E = En/Divider */
02709               Fn,                       /* F = Fn/Divider */
02710               Divider;
02711         };
02712 
02713         /* ( 15, 15)  */
02714         /* ( 50, 85)  */
02715         /* ( 85, 10)  */
02716         POINT imaginary[3];
02717         POINT real[3];
02718         MATRIX matrix;
02719 
02720         void init(int xmax, int ymax);
02721         void save_values(void);
02722         void load_values();
02723         int setCalibrationMatrix(POINT * display, POINT * screen, MATRIX * matrix);
02724         int getDisplayPoint(POINT * display, POINT * screen, MATRIX * matrix);
02725         void DoPoint(POINT * display, POINT * screen);
02726     public:
02727         FGInputDevice();
02728         virtual ~FGInputDevice() {}
02729 
02730         virtual bool Attach(void) = 0;
02731         virtual int GetInputEvent(int& type, int& key, int& x, int& y, int& button) = 0;
02732         virtual void Scale(int& x, int& y);
02733 
02734         void Calibration(void);
02735 };
02736 
02737 
02738 #ifdef FG_NAMESPACE
02739 }
02740 #endif
02741 
02742 #ifdef __BORLANDC__
02743 #pragma option pop /* pop -a switch */
02744 #pragma option pop /* pop -b */
02745 #endif
02746 
02747 #ifndef NO_ABSOLETE
02748 #define Pattern     FGPattern
02749 #define Panel       FGPanel
02750 #define Label       FGLabel
02751 #define App         FGApp
02752 #define Window      FGWindow
02753 #define Control     FGControl
02754 #define FontProperty FGFontProperty
02755 #define DrawBuffer  FGDrawBuffer
02756 #define MenuWindow  FGMenuWindow
02757 #define TextEditor  FGTextEditor
02758 #define PushButton  FGPushButton
02759 #define CheckButton FGCheckButton
02760 #define PointButton FGPointButton
02761 #define BaseGui     FGBaseGui
02762 #define GuiEvent    FGEvent
02763 #define FontDialog  FGFontDialog
02764 #define FileDialog  FGFileDialog
02765 #define ColorDialog FGColorDialog
02766 #define Bitmap      FGBitmap
02767 #define EditBox     FGEditBox
02768 #define ButtonGroup FGButtonGroup
02769 #define ProgressBar FGProgressBar
02770 #define Slider      FGSlider
02771 #define SlideBarV   FGSlideBarV
02772 #define SlideBarH   FGSlideBarH
02773 #define RadioGroupV FGRadioGroupVertical
02774 #define RadioGroupH FGRadioGroupHorizontal
02775 #define TwoStateButton FGTwoStateButton
02776 #define ColorScheme FGColorScheme
02777 #endif
02778 
02779 #endif // base_h

Generated on Wed Feb 9 11:31:35 2005 for OpenGUI by  doxygen 1.4.0