00001 00025 #ifndef _render_h_ 00026 #define _render_h_ 00027 00028 #include <SDL.h> 00029 #include "bool.h" 00030 00108 #ifndef BACK_STATES 00109 00118 #define BACK_STATES 2 00119 #endif 00120 00121 #ifndef MAX_LAYERS 00122 00125 #define MAX_LAYERS 6 00126 #endif 00127 00134 struct DisplayInfo_t { 00138 SDL_Surface *display; 00144 Uint16 pw; 00150 Uint16 ph; 00156 Uint16 lw; 00162 Uint16 lh; 00168 Uint16 luw, luh; 00169 union { 00174 Uint8 flags; 00175 struct { 00181 Bool showGame : 1; 00188 Bool showLabels : 1; 00195 Bool scrollField : 1; 00196 }; 00197 }; 00198 }; 00199 00203 extern struct DisplayInfo_t dInfo; 00204 00205 typedef struct RenderItem_t RenderItem; 00206 00207 typedef struct Layer_t Layer; 00208 00214 #define FASTEST_SURFACE ((dInfo.display->flags & SDL_HWACCEL) ? \ 00215 SDL_HWSURFACE : SDL_SWSURFACE) 00216 00229 typedef void (*ItemRenderer)(SDL_Surface *dest, RenderItem *item); 00230 00243 void GenericSurfaceRenderer(SDL_Surface *dest, RenderItem *item); 00244 00255 void SolidFillRenderer(SDL_Surface *dest, RenderItem *item); 00256 00262 struct RenderItem_t { 00266 ItemRenderer renderer; 00270 Layer *parent; 00274 RenderItem *next; 00278 RenderItem *prev; 00282 void *data; 00287 SDL_Rect loc; 00294 SDL_Rect src; 00302 SDL_Rect physDest; 00309 SDL_Rect prevStates[BACK_STATES]; 00310 union { 00314 Uint32 flags; 00315 struct { 00321 Bool dirty : 1; 00328 Bool transparent : 1; 00332 Bool visible : 1; 00339 Bool placed : 1; 00344 Bool enableDraw : 1; 00345 }; 00346 }; 00354 Sint16 physLocX, physLocY; 00360 Sint16 rectIndex[BACK_STATES]; 00361 }; 00362 00373 struct Layer_t { 00377 RenderItem *worldListFirst; 00381 RenderItem *worldListLast; 00388 Sint16 offX; 00395 Sint16 offY; 00396 union { 00400 Uint16 flags; 00401 struct { 00407 Bool dirty : 1; 00408 }; 00409 }; 00410 }; 00411 00416 extern Layer layers[MAX_LAYERS]; 00417 00435 Bool RenderInit(Uint16 numRects, Uint8 numStates); 00436 00450 void RenderClearStates(Uint8 numStates); 00451 00457 void RenderUninit(); 00458 00466 void ForceRenderAll(); 00467 00475 Bool RenderWillRenderAll(); 00476 00485 void ForceDirtyFrame(); 00486 00505 void AddRenderItem(RenderItem *item, int layer); 00506 00518 void RemoveRenderItem(RenderItem *item); 00519 00544 void PlaceRenderItem(RenderItem *item); 00545 00558 void ClearRenderItem(RenderItem *item); 00559 00573 void SetLayerOffset(Layer *layer, Sint16 x, Sint16 y); 00574 00589 void Render(); 00590 00600 Bool ResizeWindow(Uint16 w, Uint16 h); 00601 00610 #define ClipRectToRect(clip, limit) { \ 00611 int t; \ 00612 if ((t = (limit)->x - (clip)->x) > 0) { \ 00613 (clip)->w -= t; \ 00614 (clip)->x = (limit)->x; \ 00615 } \ 00616 if ((t = ((clip)->x + (Sint16)(clip)->w) - ((limit)->x + (limit)->w)) > 0) { \ 00617 (clip)->w -= t; \ 00618 } \ 00619 if ((Sint16)((clip)->w) < 0) { \ 00620 (clip)->w = 0; \ 00621 } \ 00622 if ((t = (limit)->y - (clip)->y) > 0) { \ 00623 (clip)->h -= t; \ 00624 (clip)->y = (limit)->y; \ 00625 } \ 00626 if ((t = ((clip)->y + (Sint16)(clip)->h) - ((limit)->y + (limit)->h)) > 0) { \ 00627 (clip)->h -= t; \ 00628 } \ 00629 if ((Sint16)((clip)->h) < 0) { \ 00630 (clip)->h = 0; \ 00631 } \ 00632 } 00633 00645 #define ClipRectToWH(clip, width, height) { \ 00646 int t; \ 00647 if ((clip)->x < 0) { \ 00648 (clip)->w += (clip)->x; \ 00649 (clip)->x = 0; \ 00650 } \ 00651 if ((t = ((clip)->x + (Sint16)(clip)->w) - (width)) > 0) { \ 00652 (clip)->w -= t; \ 00653 } \ 00654 if ((Sint16)((clip)->w) < 0) { \ 00655 (clip)->w = 0; \ 00656 } \ 00657 if ((clip)->y < 0) { \ 00658 (clip)->h += (clip)->y; \ 00659 (clip)->y = 0; \ 00660 } \ 00661 if ((t = ((clip)->y + (Sint16)(clip)->h) - (height)) > 0) { \ 00662 (clip)->h -= t; \ 00663 } \ 00664 if ((Sint16)((clip)->h) < 0) { \ 00665 (clip)->h = 0; \ 00666 } \ 00667 } 00668 00671 #endif 00672