TBase.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * Copyright (c) 2010 Nokia Corporation.
  3. */
  4. #ifndef __TENGINE_BASE__
  5. #define __TENGINE_BASE__
  6. #include <string.h>
  7. // type definitions .
  8. //#ifdef __SYMBIAN32__
  9. #define BYTE TBYTE
  10. #define WORD unsigned short
  11. #define DWORD TDWORD
  12. //#else
  13. //#include <windows.h>
  14. //#endif
  15. // 32 - bit architechture
  16. #define TSBYTE char
  17. #define TSWORD short
  18. #define TSDWORD int
  19. #define TBYTE unsigned char
  20. #define TWORD unsigned short
  21. #define TDWORD unsigned int
  22. #define TBOOL TBYTE
  23. #define TTRUE 1
  24. #define TFALSE 0
  25. enum eTKEYCODE {
  26. TKEY_UNKNOWN,
  27. TKEY_LEFT,
  28. TKEY_RIGHT,
  29. TKEY_UP,
  30. TKEY_DOWN,
  31. TKEY_ZOOMIN, // TÄHTI
  32. TKEY_ZOOMOUT, // RISTIKKO
  33. TKEY_MENU,
  34. TKEY_SELECT,
  35. TKEY_BACK,
  36. TKEY_1,
  37. TKEY_2,
  38. TKEY_3,
  39. TKEY_4,
  40. TKEY_5,
  41. TKEY_6,
  42. TKEY_7,
  43. TKEY_8,
  44. TKEY_9,
  45. TKEY_0,
  46. TKEY_CALL // Added by Johannes to make a call.
  47. };
  48. struct STGAHeader {
  49. TSBYTE idlength;
  50. TSBYTE colourmaptype;
  51. TSBYTE datatypecode;
  52. short TSDWORD colourmaporigin;
  53. short TSDWORD colourmaplength;
  54. TSBYTE colourmapdepth;
  55. short TSDWORD x_origin;
  56. short TSDWORD y_origin;
  57. short width;
  58. short height;
  59. TSBYTE bitsperpixel;
  60. TSBYTE imagedescriptor;
  61. TSBYTE idstring[256];
  62. }; // header for TGA, files
  63. enum eTRESOURCETYPE {
  64. eTRESOURCETYPE_IMAGE = 0,
  65. eTRESOURCETYPE_MESH = 1,
  66. eTRESOURCETYPE_FONT = 2,
  67. eTRESOURCETYPE_VFT = 3,
  68. eTRESOURCETYPE_UNDEFINED = 0xFFFFFFFF // force dword
  69. };
  70. class ITResource {
  71. public:
  72. ITResource() {};
  73. virtual ~ITResource() {};
  74. };
  75. class ITStream
  76. {
  77. public:
  78. ITStream() {};
  79. virtual ~ITStream() {};
  80. virtual TSDWORD read( void *target, TSDWORD length ) = 0;
  81. virtual TSDWORD write( void *source, TSDWORD length ) = 0;
  82. virtual TSDWORD cancel() { return 0; } // for blocking streams.
  83. // some helpers here?
  84. TSDWORD writeStream( ITStream *source ); // write stream until its ended
  85. TSDWORD writeString( const TSBYTE *str );
  86. TSDWORD readString( TSBYTE *target, TSDWORD targetSize );
  87. };
  88. class ITBuffer : public ITStream {
  89. public:
  90. ITBuffer() {};
  91. virtual ~ITBuffer() {};
  92. virtual TSDWORD length() = 0;
  93. };
  94. class ITBufferWithPointer : public ITBuffer {
  95. public:
  96. ITBufferWithPointer() {};
  97. virtual ~ITBufferWithPointer() {};
  98. virtual void *getPointer() = 0;
  99. };
  100. class CTMemoryReference : public ITBufferWithPointer {
  101. public:
  102. CTMemoryReference( const TBYTE *data, TSDWORD length ) {
  103. m_data = data; m_length = length; m_readPos = 0;
  104. }
  105. virtual ~CTMemoryReference() {};
  106. void *getPointer() { return (void*)m_data; }
  107. TSDWORD read( void *target, TSDWORD length ) {
  108. if (length+m_readPos>=m_length) length = m_length-m_readPos;
  109. if (length>0) memcpy( target, m_data+m_readPos, length );
  110. m_readPos+=length;
  111. return length;
  112. }
  113. TSDWORD write( void *source, TSDWORD length ) { return 0; }
  114. TSDWORD length() { return m_length; }
  115. protected:
  116. const TBYTE *m_data;
  117. TSDWORD m_length;
  118. TSDWORD m_readPos;
  119. };
  120. enum eTSURFACEFORMAT { eTSURFACEFORMAT_NONE,
  121. eTSURFACEFORMAT_INDEXED8BIT,
  122. eTSURFACEFORMAT_RGBA8888,
  123. eTSURFACEFORMAT_RGBA8888_PREPROCESSED, // PREPROCESSED for fast lighting ,.. (highest 4bit of each component are 0 )
  124. eTSURFACEFORMAT_RGBA4444,
  125. eTSURFACEFORMAT_RGB888,
  126. eTSURFACEFORMAT_RGB565,
  127. eTSURFACEFORMAT_SINGLECOMPONENT8BIT,
  128. eTSURFACEFORMAT_XX88,
  129. eTSURFACEFORMAT_SINGLECOMPONENT16BIT,
  130. eTSURFACEFORMAT_FORCEDWORD=0xFFFFFFFF };
  131. enum eTBLITOPERATION { eTBLITOPERATION_COPY,
  132. eTBLITOPERATION_ALPHA,
  133. eTBLITOPERATION_ADD,
  134. eTBLITOPERATION_FASTALPHA,
  135. eTBLITOPERATION_FASTMULADD,
  136. eTBLITOPERATION_COPY_LEAVEALPHA // leaves alpha-channel untouch. otherwise, just a normal copy
  137. };
  138. #define TSURFACEFLAG_OWNDATA 1
  139. class CTBaseSurface : public ITResource {
  140. public:
  141. CTBaseSurface();
  142. virtual ~CTBaseSurface();
  143. eTRESOURCETYPE getResourceType() { return eTRESOURCETYPE_IMAGE; }
  144. TSDWORD getResourceBytes() { return (m_width*m_height*m_bpp) + sizeof( CTBaseSurface ); }
  145. TSDWORD create( TSDWORD width, TSDWORD height, eTSURFACEFORMAT format );
  146. TSDWORD setAsReference( const void *data, TSDWORD width, TSDWORD height, TSDWORD pitch, eTSURFACEFORMAT format );
  147. CTBaseSurface *changeFormat( eTSURFACEFORMAT copyFormat ); // returns a copy with changed format.
  148. // As "tim" format. ... raw with simple header.
  149. void toStream( ITStream *target );
  150. TBOOL fromStream( ITStream *source );
  151. virtual TSDWORD readTGA( ITStream *source );
  152. virtual TSDWORD writeTGA( ITStream *target );
  153. void release();
  154. inline TSDWORD getWidth() { return m_width; }
  155. inline TSDWORD getHeight() { return m_height; }
  156. inline TSDWORD getPitch() { return m_pitch; }
  157. inline void* getData() { return m_data; }
  158. inline TDWORD getFlags() { return m_flags; }
  159. inline eTSURFACEFORMAT getFormat() { return m_format; }
  160. TSDWORD bltPrepeare(
  161. TSDWORD x, TSDWORD y,
  162. CTBaseSurface &source,
  163. TSDWORD &ibltwidth, TSDWORD &ibltheight,
  164. TSDWORD &ibltsourceoffset );
  165. eTSURFACEFORMAT m_format;
  166. TSDWORD m_bpp;
  167. TSDWORD m_width;
  168. TSDWORD m_height;
  169. TSDWORD m_pitch;
  170. TDWORD m_flags;
  171. TBYTE *m_palette;
  172. void *m_data;
  173. };
  174. #endif