00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef DIRTY_RECTANGLE_INCLUDED
00034 #define DIRTY_RECTANGLE_INCLUDED
00035
00036
00037 #include "../engine/krmath.h"
00038 #include "../util/gllist.h"
00039
00040
00041 #ifdef DEBUG
00042 #include "SDL.h"
00043 #endif
00044
00045
00046 class KrDirtyRectangle;
00047 struct SDL_Surface;
00048
00049
00050 struct KrMappedRectInfo
00051 {
00052 int xmin;
00053 int ymin;
00054 int hPixelsPerBit;
00055 int vPixelsPerRow;
00056
00057 void Set( const grinliz::Rectangle2I& bounds );
00058 };
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 class KrMappedRect : public grinliz::Rectangle2I
00069 {
00070 public:
00071 KrMappedRect() { min.x = -1; min.y = -1; max.x = -2; max.y = -2; }
00072 KrMappedRect( const grinliz::Rectangle2I& from, const KrMappedRectInfo& info )
00073 { min.x = from.min.x; min.y = from.min.y; max.x = from.max.x; max.y = from.max.y; CalcMap( info ); }
00074 KrMappedRect( const KrMappedRect& from )
00075 { min.x = from.min.x; min.y = from.min.y; max.x = from.max.x; max.y = from.max.y; map = from.map; }
00076
00077 void Set( const grinliz::Rectangle2I& from, const KrMappedRectInfo& info )
00078 {
00079 min.x = from.min.x;
00080 min.y = from.min.y;
00081 max.x = from.max.x;
00082 max.y = from.max.y;
00083 CalcMap( info );
00084 }
00085
00086 void operator=( const KrMappedRect& from )
00087 {
00088 min.x = from.min.x;
00089 min.y = from.min.y;
00090 max.x = from.max.x;
00091 max.y = from.max.y;
00092 map = from.map;
00093 }
00094
00095 void CalcMap( const KrMappedRectInfo& );
00096
00097 bool Intersect( const KrMappedRect& rect ) const
00098 {
00099 GLASSERT( rect.map );
00100
00101 if ( ( ( rect.map & map ) == 0 )
00102 || rect.max.x < min.x
00103 || rect.min.x > max.x
00104 || rect.max.y < min.y
00105 || rect.min.y > max.y )
00106 {
00107 return false;
00108 }
00109 return true;
00110 }
00111
00112 U32 Map() const { return map; }
00113 private:
00114 U32 map;
00115 };
00116
00131 class KrDirtyRectangle
00132 {
00133 public:
00134 KrDirtyRectangle();
00135 ~KrDirtyRectangle();
00136
00138 void SetClipping( const grinliz::Rectangle2I& rect )
00139 { clippingRect = rect; clipping = true; mappedInfo.Set( clippingRect ); }
00141 bool IsClipping() { return clipping; }
00142
00144 void AddRectangle( const grinliz::Rectangle2I& rect );
00146 void Clear() {
00147 nRect = 0; }
00148 int NumRect() { return nRect; }
00149 const KrMappedRect& Rect( int i ) { GLASSERT( i>=0 && i<nRect );
00150 return rectArray[i]; }
00151
00152
00153
00154
00155
00156
00157 #ifdef DEBUG
00158 void DrawAllRects( SDL_Surface* surface );
00159
00160 void DrawRects( SDL_Surface* surface );
00161 void DrawWindow( int y0, int y1 );
00162
00163 void PrintRects( const char* message );
00164 #endif
00165
00166 enum
00167 {
00168
00169
00170
00171
00172
00173 MAX_DIRTY_RECTANGLES = 128,
00174 };
00175
00176 private:
00177 void Remove( int index );
00178 void HandleOutOfRect( const KrMappedRect& rect );
00179
00180 KrMappedRect rectArray[ MAX_DIRTY_RECTANGLES ];
00181
00182 grinliz::Rectangle2I clippingRect;
00183 bool clipping;
00184
00185 int nRect;
00186 KrMappedRectInfo mappedInfo;
00187 };
00188
00189
00190
00191 #endif