gxcanvas.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef GXCANVAS_H
  2. #define GXCANVAS_H
  3. #include "ddutil.h"
  4. class gxFont;
  5. class gxGraphics;
  6. typedef IDirectDrawSurface7 ddSurf;
  7. class gxCanvas{
  8. public:
  9. gxCanvas( gxGraphics *graphics,ddSurf *surface,int flags );
  10. ~gxCanvas();
  11. void backup()const;
  12. void restore()const;
  13. ddSurf *getSurface()const;
  14. ddSurf *getTexSurface()const;
  15. void setModify( int n );
  16. int getModify()const;
  17. bool attachZBuffer();
  18. void releaseZBuffer();
  19. bool clip( RECT *d )const;
  20. bool clip( RECT *d,RECT *s )const;
  21. void damage( const RECT &r )const;
  22. private:
  23. int flags,cube_mode;
  24. gxGraphics *graphics;
  25. ddSurf *main_surf,*surf,*z_surf,*cube_surfs[6];
  26. mutable int mod_cnt;
  27. mutable ddSurf *t_surf;
  28. mutable int locked_pitch,locked_cnt,lock_mod_cnt,remip_cnt;
  29. mutable unsigned char *locked_surf;
  30. mutable int cm_pitch;
  31. mutable unsigned *cm_mask;
  32. RECT clip_rect;
  33. PixelFormat format;
  34. gxFont *font;
  35. RECT viewport;
  36. int origin_x,origin_y,handle_x,handle_y;
  37. unsigned mask_surf,color_surf,color_argb,clsColor_surf;
  38. void updateBitMask( const RECT &r )const;
  39. /***** GX INTERFACE *****/
  40. public:
  41. enum{
  42. CANVAS_TEX_RGB= 0x0001,
  43. CANVAS_TEX_ALPHA= 0x0002,
  44. CANVAS_TEX_MASK= 0x0004,
  45. CANVAS_TEX_MIPMAP= 0x0008,
  46. CANVAS_TEX_CLAMPU= 0x0010,
  47. CANVAS_TEX_CLAMPV= 0x0020,
  48. CANVAS_TEX_SPHERE= 0x0040,
  49. CANVAS_TEX_CUBE= 0x0080,
  50. CANVAS_TEX_VIDMEM= 0x0100,
  51. CANVAS_TEX_HICOLOR= 0x0200,
  52. CANVAS_TEXTURE= 0x10000,
  53. CANVAS_NONDISPLAY= 0x20000,
  54. CANVAS_HIGHCOLOR= 0x40000
  55. };
  56. enum{
  57. CUBEMODE_REFLECTION=1,
  58. CUBEMODE_NORMAL=2,
  59. CUBEMODE_POSITION=3,
  60. CUBESPACE_WORLD=0,
  61. CUBESPACE_CAMERA=4
  62. };
  63. //MANIPULATORS
  64. void setFont( gxFont *font );
  65. void setMask( unsigned argb );
  66. void setColor( unsigned argb );
  67. void setClsColor( unsigned argb );
  68. void setOrigin( int x,int y );
  69. void setHandle( int x,int y );
  70. void setViewport( int x,int y,int w,int h );
  71. void cls();
  72. void plot( int x,int y );
  73. void line( int x,int y,int x2,int y2 );
  74. void rect( int x,int y,int w,int h,bool solid );
  75. void oval( int x,int y,int w,int h,bool solid );
  76. void text( int x,int y,const std::string &t );
  77. void blit( int x,int y,gxCanvas *src,int src_x,int src_y,int src_w,int src_h,bool solid );
  78. bool collide( int x,int y,const gxCanvas *src,int src_x,int src_y,bool solid )const;
  79. bool rect_collide( int x,int y,int rect_x,int rect_y,int rect_w,int rect_h,bool solid )const;
  80. bool lock()const;
  81. void setPixel( int x,int y,unsigned argb );
  82. void setPixelFast( int x,int y,unsigned argb ){
  83. format.setPixel( locked_surf+y*locked_pitch+x*format.getPitch(),argb );
  84. ++mod_cnt;
  85. }
  86. void copyPixel( int x,int y,gxCanvas *src,int src_x,int src_y );
  87. void copyPixelFast( int x,int y,gxCanvas *src,int src_x,int src_y );
  88. unsigned getPixel( int x,int y )const;
  89. unsigned getPixelFast( int x,int y )const{
  90. return format.getPixel( locked_surf+y*locked_pitch+x*format.getPitch() );
  91. };
  92. void unlock()const;
  93. void setCubeMode( int mode );
  94. void setCubeFace( int face );
  95. //ACCESSORS
  96. int getWidth()const;
  97. int getHeight()const;
  98. int getDepth()const;
  99. int getFlags()const{ return flags; }
  100. int cubeMode()const{ return cube_mode; }
  101. void getOrigin( int *x,int *y )const;
  102. void getHandle( int *x,int *y )const;
  103. void getViewport( int *x,int *y,int *w,int *h )const;
  104. unsigned getMask()const;
  105. unsigned getColor()const;
  106. unsigned getClsColor()const;
  107. };
  108. #endif