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