summaryrefslogtreecommitdiff
path: root/src/RasterGraphics.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-23 13:59:07 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-23 13:59:07 (GMT)
commitf5547f267b9e73be3d8153df3dd36d7e3b69a2d9 (patch)
treed34603fa1776beac9009c42f77126db434891546 /src/RasterGraphics.cpp
parent4cf42e786bd0e2871a5bc580bed14f4d2c742788 (diff)
downloadpowder-f5547f267b9e73be3d8153df3dd36d7e3b69a2d9.zip
powder-f5547f267b9e73be3d8153df3dd36d7e3b69a2d9.tar.gz
Option to use OpenGL JUST for the interface
Diffstat (limited to 'src/RasterGraphics.cpp')
-rw-r--r--src/RasterGraphics.cpp340
1 files changed, 8 insertions, 332 deletions
diff --git a/src/RasterGraphics.cpp b/src/RasterGraphics.cpp
index b807238..31b1b97 100644
--- a/src/RasterGraphics.cpp
+++ b/src/RasterGraphics.cpp
@@ -1,7 +1,6 @@
#include "Graphics.h"
-#include "font.h"
-#ifndef OGLR
+#ifndef OGLI
Graphics::Graphics():
sdl_scale(1)
@@ -25,335 +24,12 @@ void Graphics::Finalise()
}
-int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
-{
- if(!strlen(s))
- return 0;
- int width, height;
-
- int characterX = x, characterY = y;
- int startX = characterX;
- for (; *s; s++)
- {
- if (*s == '\n')
- {
- characterX = startX;
- characterY += FONT_H+2;
- }
- else if (*s == '\b')
- {
- switch (s[1])
- {
- case 'w':
- r = g = b = 255;
- break;
- case 'g':
- r = g = b = 192;
- break;
- case 'o':
- r = 255;
- g = 216;
- b = 32;
- break;
- case 'r':
- r = 255;
- g = b = 0;
- break;
- case 'l':
- r = 255;
- g = b = 75;
- break;
- case 'b':
- r = g = 0;
- b = 255;
- break;
- case 't':
- b = 255;
- g = 170;
- r = 32;
- break;
- }
- s++;
- }
- else
- {
- characterX = drawchar(characterX, characterY, *(unsigned char *)s, r, g, b, a);
- }
- }
- return x;
-}
-
-int Graphics::drawtext(int x, int y, std::string s, int r, int g, int b, int a)
-{
- return drawtext(x, y, s.c_str(), r, g, b, a);
-}
-
-TPT_INLINE int Graphics::drawchar(int x, int y, int c, int r, int g, int b, int a)
-{
- int i, j, w, bn = 0, ba = 0;
- char *rp = font_data + font_ptrs[c];
- w = *(rp++);
- for (j=0; j<FONT_H; j++)
- for (i=0; i<w; i++)
- {
- if (!bn)
- {
- ba = *(rp++);
- bn = 8;
- }
- blendpixel(x+i, y+j, r, g, b, ((ba&3)*a)/3);
- ba >>= 2;
- bn -= 2;
- }
- return x + w;
-}
-
-TPT_INLINE int Graphics::addchar(int x, int y, int c, int r, int g, int b, int a)
-{
- int i, j, w, bn = 0, ba = 0;
- char *rp = font_data + font_ptrs[c];
- w = *(rp++);
- for (j=0; j<FONT_H; j++)
- for (i=0; i<w; i++)
- {
- if (!bn)
- {
- ba = *(rp++);
- bn = 8;
- }
- {
- addpixel(x+i, y+j, r, g, b, ((ba&3)*a)/3);
- }
- ba >>= 2;
- bn -= 2;
- }
- return x + w;
-}
-
-TPT_INLINE void Graphics::xor_pixel(int x, int y)
-{
- int c;
- if (x<0 || y<0 || x>=XRES || y>=YRES)
- return;
- c = vid[y*(XRES+BARSIZE)+x];
- c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c);
- if (c<512)
- vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0);
- else
- vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040);
-}
-
-TPT_INLINE void Graphics::blendpixel(int x, int y, int r, int g, int b, int a)
-{
- pixel t;
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return;
- if (a!=255)
- {
- t = vid[y*(XRES+BARSIZE)+x];
- r = (a*r + (255-a)*PIXR(t)) >> 8;
- g = (a*g + (255-a)*PIXG(t)) >> 8;
- b = (a*b + (255-a)*PIXB(t)) >> 8;
- }
- vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
-}
-
-TPT_INLINE void Graphics::addpixel(int x, int y, int r, int g, int b, int a)
-{
- pixel t;
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return;
- t = vid[y*(XRES+BARSIZE)+x];
- r = (a*r + 255*PIXR(t)) >> 8;
- g = (a*g + 255*PIXG(t)) >> 8;
- b = (a*b + 255*PIXB(t)) >> 8;
- if (r>255)
- r = 255;
- if (g>255)
- g = 255;
- if (b>255)
- b = 255;
- vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
-}
-
-void Graphics::xor_line(int x1, int y1, int x2, int y2)
-{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
- float e, de;
- if (cp)
- {
- y = x1;
- x1 = y1;
- y1 = y;
- y = x2;
- x2 = y2;
- y2 = y;
- }
- if (x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- dx = x2 - x1;
- dy = abs(y2 - y1);
- e = 0.0f;
- if (dx)
- de = dy/(float)dx;
- else
- de = 0.0f;
- y = y1;
- sy = (y1<y2) ? 1 : -1;
- for (x=x1; x<=x2; x++)
- {
- if (cp)
- xor_pixel(y, x);
- else
- xor_pixel(x, y);
- e += de;
- if (e >= 0.5f)
- {
- y += sy;
- e -= 1.0f;
- }
- }
-}
-
-void Graphics::xor_rect(int x, int y, int w, int h)
-{
- int i;
- for (i=0; i<w; i+=2)
- {
- xor_pixel(x+i, y);
- xor_pixel(x+i, y+h-1);
- }
- for (i=2; i<h; i+=2)
- {
- xor_pixel(x, y+i);
- xor_pixel(x+w-1, y+i);
- }
-}
-
-void Graphics::xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h)
-{
- for(int x1 = 0; x1 < w; x1++)
- {
- for(int y1 = 0; y1 < h; y1++)
- {
- if(bitmap[y1*w+x1])
- xor_pixel(x+x1, y+y1);
- }
- }
-}
-
-void Graphics::draw_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a)
-{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
- float e, de;
- if (cp)
- {
- y = x1;
- x1 = y1;
- y1 = y;
- y = x2;
- x2 = y2;
- y2 = y;
- }
- if (x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- dx = x2 - x1;
- dy = abs(y2 - y1);
- e = 0.0f;
- if (dx)
- de = dy/(float)dx;
- else
- de = 0.0f;
- y = y1;
- sy = (y1<y2) ? 1 : -1;
- for (x=x1; x<=x2; x++)
- {
- if (cp)
- blendpixel(y, x, r, g, b, a);
- else
- blendpixel(x, y, r, g, b, a);
- e += de;
- if (e >= 0.5f)
- {
- y += sy;
- e -= 1.0f;
- }
- }
-}
-
-void Graphics::drawrect(int x, int y, int w, int h, int r, int g, int b, int a)
-{
- int i;
- w--;
- h--;
- for (i=0; i<=w; i++)
- {
- blendpixel(x+i, y, r, g, b, a);
- blendpixel(x+i, y+h, r, g, b, a);
- }
- for (i=1; i<h; i++)
- {
- blendpixel(x, y+i, r, g, b, a);
- blendpixel(x+w, y+i, r, g, b, a);
- }
-}
-
-void Graphics::fillrect(int x, int y, int w, int h, int r, int g, int b, int a)
-{
- int i,j;
- for (j=0; j<h; j++)
- for (i=0; i<w; i++)
- blendpixel(x+i, y+j, r, g, b, a);
-}
-
-void Graphics::gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2)
-{
-
-}
-
-void Graphics::clearrect(int x, int y, int w, int h)
-{
- int i;
- for (i=1; i<h; i++)
- memset(vid+(x+1+(XRES+BARSIZE)*(y+i)), 0, PIXELSIZE*(w-1));
-}
-
-void Graphics::draw_image(pixel *img, int x, int y, int w, int h, int a)
-{
- int i, j, r, g, b;
- if (!img) return;
- if(y + h > YRES+MENUSIZE) h = (YRES+MENUSIZE)-y; //Adjust height to prevent drawing off the bottom
- if(a >= 255)
- for (j=0; j<h; j++)
- for (i=0; i<w; i++)
- {
- vid[(y+j)*(XRES+BARSIZE)+(x+i)] = *img;
- img++;
- }
- else
- for (j=0; j<h; j++)
- for (i=0; i<w; i++)
- {
- r = PIXR(*img);
- g = PIXG(*img);
- b = PIXB(*img);
- blendpixel(x+i, y+j, r, g, b, a);
- img++;
- }
-}
+#define VIDXRES XRES+BARSIZE
+#define VIDYRES YRES+MENUSIZE
+#define PIXELMOETHODS_CLASS Graphics
+#include "PixelMethods.inc"
+#undef VIDYRES
+#undef VIDXRES
+#undef PIXELMETHODS_CLASS
#endif