vsandbox.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * The sandbox-playground
  3. * Copyright (c) 2010 Nokia Corporation.
  4. *
  5. */
  6. #ifndef __VSANDBOX__
  7. #define __VSANDBOX__
  8. #include "TSurface_RGBA8888.h"
  9. #include "vsand_grid.h"
  10. #include "T2DMath.h"
  11. // tools defined here for compatibility
  12. enum eSANDTOOL { eSANDTOOL_NONE,
  13. eSANDTOOL_SCRATCH_TO_TARGET,
  14. eSANDTOOL_CURVE,
  15. eSANDTOOL_ADD,
  16. eSANDTOOL_PUSH,
  17. eSANDTOOL_PUSH_TOWARDS,
  18. eSANDTOOL_PULL,
  19. eSANDTOOL_GRAVITY,
  20. eSANDTOOL_LIGHT };
  21. #define SANDGRID_DIV 8
  22. #define SANDGRID_DIV_BITS 3
  23. #define SANDGRID_LIGHT_SHR 22 // with size 8, 22 in "sqr" space,.. 2 bits per 1 change
  24. #define SANDGRID_SAND_SHR 12
  25. #define BG_SIZE 256
  26. class CVSandBox {
  27. public:
  28. CVSandBox( int simw, int simh );
  29. ~CVSandBox();
  30. int run( int fixedFrameTime );
  31. int render( CTSurface_RGBA8888 &target, int *bound_rect = 0 );
  32. // getters/setters
  33. inline CT2DVector &gravity() { return m_vGravity; }
  34. inline CT2DVector &light() { return m_vLight; } // note, use only as get.
  35. inline CVSand_Grid *getGrid() { return m_sandGrid; }
  36. void setLight( int x, int y );
  37. void relightBg( int mul );
  38. void autoPaintTo( CTSurface_RGBA8888 &target, int type=-1, int power = 35 );
  39. void autoPaintToResetTarget( int index, int type=-1 );
  40. bool isScratching() { if (m_autoPaintType==4) return true; else return false; }
  41. TDWORD* getAutoPaintTargetMem() { return (TDWORD*)m_autoPaintTarget.getData(); }
  42. void shake( int dirx, int diry );
  43. void markAllChanged();
  44. protected:
  45. void autoPaintStep();
  46. void drawGridItem( TDWORD *target,int pitch, SVSandNode *node, int u, int v );
  47. CVSand_Grid *m_sandGrid;
  48. CT2DVector m_vGravity;
  49. CT2DVector m_vLight;
  50. int m_bgLight;
  51. TDWORD *m_litBackground;
  52. // autopaint
  53. TSDWORD m_autoPaintStatus;
  54. TSDWORD m_autoPaintType;
  55. CTSurface_RGBA8888 m_autoPaintTarget;
  56. };
  57. #endif