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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 #ifndef DIRTY_RECTANGLE_INCLUDED
00071 #define DIRTY_RECTANGLE_INCLUDED
00072
00073
00074 #include "../engine/krmath.h"
00075 #include "../util/gllist.h"
00076
00077
00078 #ifdef DEBUG
00079 #include "SDL.h"
00080 #include "../util/gldynarray.h"
00081 #endif
00082
00083
00084 class KrDirtyRectangle;
00085 struct SDL_Surface;
00086
00087
00088 struct KrMappedRectInfo
00089 {
00090 int xmin;
00091 int ymin;
00092 int hPixelsPerBit;
00093 int vPixelsPerRow;
00094
00095 void Set( const KrRect& bounds );
00096 };
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 class KrMappedRect : public KrRect
00107 {
00108 public:
00109 KrMappedRect() { xmin = -1; ymin = -1; xmax = -2; ymax = -2; }
00110 KrMappedRect( const KrRect& from, const KrMappedRectInfo& info )
00111 { xmin = from.xmin; ymin = from.ymin; xmax = from.xmax; ymax = from.ymax; CalcMap( info ); }
00112 KrMappedRect( const KrMappedRect& from )
00113 { xmin = from.xmin; ymin = from.ymin; xmax = from.xmax; ymax = from.ymax; map = from.map; }
00114
00115 void Set( const KrRect& from, const KrMappedRectInfo& info )
00116 {
00117 xmin = from.xmin;
00118 ymin = from.ymin;
00119 xmax = from.xmax;
00120 ymax = from.ymax;
00121 CalcMap( info );
00122 }
00123
00124 void operator=( const KrMappedRect& from )
00125 {
00126 xmin = from.xmin;
00127 ymin = from.ymin;
00128 xmax = from.xmax;
00129 ymax = from.ymax;
00130 map = from.map;
00131 }
00132
00133 void CalcMap( const KrMappedRectInfo& );
00134
00135 bool Intersect( const KrMappedRect& rect ) const
00136 {
00137 GLASSERT( rect.map );
00138
00139 if ( ( ( rect.map & map ) == 0 )
00140 || rect.xmax < xmin
00141 || rect.xmin > xmax
00142 || rect.ymax < ymin
00143 || rect.ymin > ymax )
00144 {
00145 return false;
00146 }
00147 return true;
00148 }
00149
00150 U32 Map() const { return map; }
00151 private:
00152 U32 map;
00153 };
00154
00169 class KrDirtyRectangle
00170 {
00171 public:
00172 KrDirtyRectangle();
00173 ~KrDirtyRectangle();
00174
00176 void SetClipping( const KrRect& rect ) { clippingRect = rect; clipping = true; mappedInfo.Set( clippingRect ); }
00178 bool IsClipping() { return clipping; }
00179
00181 void AddRectangle( const KrRect& rect );
00183 void Clear() {
00184 nRect = 0; }
00185 int NumRect() { return nRect; }
00186 const KrMappedRect& Rect( int i ) { GLASSERT( i>=0 && i<nRect );
00187 return rectArray[i]; }
00188
00189
00190
00191
00192
00193
00194 #ifdef DEBUG
00195 void DrawAllRects( SDL_Surface* surface );
00196
00197 void DrawRects( SDL_Surface* surface );
00198 void DrawWindow( int y0, int y1 );
00199
00200 void PrintRects( const char* message );
00201 #endif
00202
00203 enum
00204 {
00205
00206
00207
00208
00209
00210 MAX_DIRTY_RECTANGLES = 128,
00211 };
00212
00213 private:
00214 void Remove( int index );
00215 void HandleOutOfRect( const KrMappedRect& rect );
00216
00217 KrMappedRect rectArray[ MAX_DIRTY_RECTANGLES ];
00218
00219 KrRect clippingRect;
00220 bool clipping;
00221
00222 int nRect;
00223 KrMappedRectInfo mappedInfo;
00224 };
00225
00226
00227
00228 #endif