graphicsProvider.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #include <fxcg/display.h>
  2. #include <fxcg/file.h>
  3. #include <fxcg/keyboard.h>
  4. #include <fxcg/system.h>
  5. #include <fxcg/misc.h>
  6. #include <fxcg/app.h>
  7. #include <fxcg/serial.h>
  8. #include <fxcg/rtc.h>
  9. #include <fxcg/heap.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <math.h>
  14. #include "graphicsProvider.hpp"
  15. const short empty[18] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  16. int PrintMiniFix( int x, int y, const char*Msg, const int flags, const short color, const short bcolor )
  17. {
  18. int i = 0, dx;
  19. unsigned short width;
  20. void*p;
  21. while ( Msg[ i ] )
  22. {
  23. if( Msg[i] == 9) {
  24. drawLine(x, y+24+7, x+11, y+24+7, color);
  25. drawLine(x, y+24+8, x+11, y+24+8, color);
  26. x+=12;
  27. i++;
  28. continue;
  29. } else if( Msg[i] == 31) {
  30. // small dot for multiply
  31. int tx = x+2, ty=y;
  32. PrintMini(&tx, &ty, (unsigned char*)"\xe6\xaa", 0, 0xFFFFFFFF, 0, 0, color, bcolor, 1, 0);
  33. x+=12;
  34. i++;
  35. continue;
  36. } else p = GetMiniGlyphPtr( Msg[ i ], &width );
  37. dx = ( 12 - width ) / 2;
  38. if ( dx > 0 )
  39. {
  40. PrintMiniGlyph( x, y, (void*)empty, flags, dx, 0, 0, 0, 0, color, bcolor, 0 );
  41. }
  42. else dx = 0;
  43. PrintMiniGlyph( x + dx, y, p, flags, width, 0, 0, 0, 0, color, bcolor, 0 );
  44. if ( width + dx < 12 )
  45. {
  46. PrintMiniGlyph( x + width + dx, y, (void*)empty, flags, 12 - width - dx, 0, 0, 0, 0, color, bcolor, 0 );
  47. }
  48. x += 12;
  49. i++;
  50. }
  51. return x;
  52. }
  53. //draws a point of color color at (x0, y0)
  54. void plot(int x0, int y0,unsigned short color) {
  55. unsigned short* VRAM = (unsigned short*)0xA8000000;
  56. VRAM += (y0*LCD_WIDTH_PX + x0);
  57. *VRAM=color;
  58. }
  59. void drawRectangle(int x, int y, int width, int height, unsigned short color){
  60. unsigned short*VRAM = (unsigned short*)0xA8000000;
  61. VRAM+=(y*384)+x;
  62. while(height--){
  63. int i=width;
  64. while(i--){
  65. *VRAM++ = color;
  66. }
  67. VRAM+=384-width;
  68. }
  69. }
  70. //Uses the Bresenham line algorithm
  71. void drawLine(int x1, int y1, int x2, int y2, int color) {
  72. signed char ix;
  73. signed char iy;
  74. // if x1 == x2 or y1 == y2, then it does not matter what we set here
  75. int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1;
  76. int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1;
  77. plot(x1, y1, color);
  78. if (delta_x >= delta_y) {
  79. int error = delta_y - (delta_x >> 1); // error may go below zero
  80. while (x1 != x2) {
  81. if (error >= 0) {
  82. if (error || (ix > 0)) {
  83. y1 += iy;
  84. error -= delta_x;
  85. } // else do nothing
  86. } // else do nothing
  87. x1 += ix;
  88. error += delta_y;
  89. plot(x1, y1, color);
  90. }
  91. } else {
  92. int error = delta_x - (delta_y >> 1); // error may go below zero
  93. while (y1 != y2) {
  94. if (error >= 0) {
  95. if (error || (iy > 0)) {
  96. x1 += ix;
  97. error -= delta_y;
  98. } // else do nothing
  99. } // else do nothing
  100. y1 += iy;
  101. error += delta_x;
  102. plot(x1, y1, color);
  103. }
  104. }
  105. }
  106. //ReplaceColor By Kerm:
  107. /*void VRAMReplaceColorInRect(int x, int y, int width, int height, color_t color_old, color_t color_new) {
  108. //color_t* VRAM = GetVRAMAddress();
  109. color_t* VRAM = (color_t*)0xA8000000;
  110. VRAM += (y*LCD_WIDTH_PX)+x;
  111. for(int j=0; j<height; VRAM += (LCD_WIDTH_PX-width), j++) {
  112. for(int i=0; i<width; VRAM++, i++) {
  113. if (*VRAM == color_old) *VRAM = color_new;
  114. }
  115. }
  116. } */
  117. /*void CopySprite(const void* datar, int x, int y, int width, int height) {
  118. color_t*data = (color_t*) datar;
  119. color_t* VRAM = (color_t*)0xA8000000;
  120. VRAM += LCD_WIDTH_PX*y + x;
  121. for(int j=y; j<y+height; j++) {
  122. for(int i=x; i<x+width; i++) {
  123. *(VRAM++) = *(data++);
  124. }
  125. VRAM += LCD_WIDTH_PX-width;
  126. }
  127. }*/
  128. void CopySpriteMasked(unsigned short* data, int x, int y, int width, int height, unsigned short maskcolor) {
  129. unsigned short* VRAM = (unsigned short*)0xA8000000;
  130. VRAM += (LCD_WIDTH_PX*y + x);
  131. while(height--) {
  132. int i=width;
  133. while(i--){
  134. if(*data!=maskcolor) {
  135. *(VRAM++) = *(data++);
  136. } else {
  137. ++VRAM;
  138. ++data;
  139. }
  140. }
  141. VRAM += (LCD_WIDTH_PX-width);
  142. }
  143. }
  144. /*void CopySpriteNbit(const unsigned char* data, int x, int y, int width, int height, const color_t* palette, unsigned int bitwidth) {
  145. color_t* VRAM = (color_t*)0xA8000000;
  146. VRAM += (LCD_WIDTH_PX*y + x);
  147. int offset = 0;
  148. unsigned char buf = 0;
  149. for(int j=y; j<y+height; j++) {
  150. int availbits = 0;
  151. for(int i=x; i<x+width; i++) {
  152. if (!availbits) {
  153. buf = data[offset++];
  154. availbits = 8;
  155. }
  156. color_t thisthis = ((color_t)buf>>(8-bitwidth));
  157. *VRAM = palette[(color_t)thisthis];
  158. VRAM++;
  159. buf<<=bitwidth;
  160. availbits-=bitwidth;
  161. }
  162. VRAM += (LCD_WIDTH_PX-width);
  163. }
  164. }*/
  165. //the following does not update the screen automatically; it will draw the tny.im logo starting at screen coordinates x,y
  166. //the tny.im logo is great enough not to require any sprites! yay!
  167. //w:138
  168. //h:42
  169. static const unsigned char logoB[]={
  170. //draw t
  171. 0, 6, 6, 24,
  172. 6, 12, 6, 6,
  173. 6, 30, 6, 6,
  174. //draw n
  175. 18, 12, 6, 24,
  176. 24, 12, 12, 6,
  177. 36, 18, 6, 18,
  178. //draw y
  179. 48, 12, 6, 18,
  180. 60, 12, 6, 18,
  181. 54, 30, 6, 6,
  182. 48, 36, 6, 6,
  183. //draw dot
  184. 72, 30, 6, 6 };
  185. static const unsigned char logoO[]={
  186. //draw i (orange)
  187. 84, 0, 6, 6,
  188. 84, 12, 6, 24,
  189. //draw m (orange)
  190. 96, 12, 6, 24,
  191. 102, 12, 12, 6,
  192. 114, 18, 6, 18,
  193. 120, 12, 12, 6,
  194. 132, 18, 6, 18 };
  195. void drawtnyimLogo(int x, int y) {
  196. int i;
  197. for(i=0;i<11*4;i+=4)
  198. drawRectangle(x+logoB[i], y+logoB[i+1], logoB[i+2], logoB[i+3], COLOR_BLACK);
  199. for(i=0;i<7*4;i+=4)
  200. drawRectangle(x+logoO[i], y+logoO[i+1], logoO[i+2], logoO[i+3], TNYIM_ORANGE);
  201. }
  202. /*int textColorToFullColor(int textcolor) {
  203. switch(textcolor) {
  204. case TEXT_COLOR_BLACK: return COLOR_BLACK;
  205. case TEXT_COLOR_BLUE: return COLOR_BLUE;
  206. case TEXT_COLOR_GREEN: return COLOR_GREEN;
  207. case TEXT_COLOR_CYAN: return COLOR_CYAN;
  208. case TEXT_COLOR_RED: return COLOR_RED;
  209. case TEXT_COLOR_PURPLE: return COLOR_PURPLE;
  210. case TEXT_COLOR_YELLOW: return COLOR_YELLOW;
  211. case TEXT_COLOR_WHITE: return COLOR_LIGHTGRAY;
  212. default: return COLOR_BLACK;
  213. }
  214. }
  215. void progressMessage(char* message, int cur, int total) {
  216. char buffer[30] = "";
  217. char buffer2[5] = "";
  218. strcpy(buffer, " ");
  219. strcat(buffer, message);
  220. strcat(buffer, " (");
  221. itoa(cur, (unsigned char*)buffer2);
  222. strcat(buffer, buffer2);
  223. strcat(buffer, "/");
  224. itoa(total, (unsigned char*)buffer2);
  225. strcat(buffer, buffer2);
  226. strcat(buffer, ")");
  227. PrintXY(1,8,(char*)" ", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
  228. PrintXY(1,8,(char*)buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
  229. Bdisp_PutDisp_DD();
  230. }*/
  231. void printCentered(unsigned char* text, int y, int FGC, int BGC) {
  232. int len = strlen((char*)text);
  233. int x = LCD_WIDTH_PX/2-(len*18)/2;
  234. int cur = 0;
  235. while(cur<len) {
  236. PrintCXY(x, y, &text[cur], 0x40, -1, FGC, BGC, 1, 0 );
  237. x=x+18;
  238. cur++;
  239. }
  240. }