diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-21 17:43:46 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-21 17:43:46 (GMT) |
| commit | f7d8556965832821036c210ffc1f9e73f3ff70cc (patch) | |
| tree | 58e985bdc6e99a2ad8e7382ebaf33553ae93d836 /src/graphics | |
| parent | 5bf0a084ace0e6b673efa4552b40de8b36e0668e (diff) | |
| download | powder-f7d8556965832821036c210ffc1f9e73f3ff70cc.zip powder-f7d8556965832821036c210ffc1f9e73f3ff70cc.tar.gz | |
Icons for menu items
Diffstat (limited to 'src/graphics')
| -rw-r--r-- | src/graphics/Graphics.cpp | 39 | ||||
| -rw-r--r-- | src/graphics/Graphics.h | 8 | ||||
| -rw-r--r-- | src/graphics/Renderer.cpp | 89 | ||||
| -rw-r--r-- | src/graphics/Renderer.h | 2 |
4 files changed, 136 insertions, 2 deletions
diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index 5f84088..23ee092 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -7,6 +7,36 @@ #define INCLUDE_FONTDATA #include "font.h" +VideoBuffer::VideoBuffer(int width, int height): + Width(width), + Height(height) +{ + Buffer = new pixel[width*height]; + std::fill(Buffer, Buffer+(width*height), 0); +}; + +VideoBuffer::VideoBuffer(const VideoBuffer & old): + Width(old.Width), + Height(old.Height) +{ + Buffer = new pixel[old.Width*old.Height]; + std::copy(old.Buffer, old.Buffer+(old.Width*old.Height), Buffer); +}; + +VideoBuffer::VideoBuffer(VideoBuffer * old): + Width(old->Width), + Height(old->Height) +{ + Buffer = new pixel[old->Width*old->Height]; + std::copy(old->Buffer, old->Buffer+(old->Width*old->Height), Buffer); +}; + + +VideoBuffer::~VideoBuffer() +{ + delete[] Buffer; +}; + TPT_INLINE void VideoBuffer::BlendPixel(int x, int y, int r, int g, int b, int a) { #ifdef PIX32OGL @@ -786,4 +816,13 @@ pixel *Graphics::render_packed_rgb(void *image, int width, int height, int cmp_s return res; } +void Graphics::draw_image(const VideoBuffer & vidBuf, int x, int y, int a) +{ + draw_image(vidBuf.Buffer, x, y, vidBuf.Width, vidBuf.Height, a); +} + +void Graphics::draw_image(VideoBuffer * vidBuf, int x, int y, int a) +{ + draw_image(vidBuf->Buffer, x, y, vidBuf->Width, vidBuf->Height, a); +} diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index 1209b86..41c521a 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -90,14 +90,16 @@ public: pixel * Buffer; int Width, Height; - VideoBuffer(int width, int height): Width(width), Height(height), Buffer((pixel*)calloc(width*height, PIXELSIZE)) { }; + VideoBuffer(const VideoBuffer & old); + VideoBuffer(VideoBuffer * old); + VideoBuffer(int width, int height); void BlendPixel(int x, int y, int r, int g, int b, int a); void AddPixel(int x, int y, int r, int g, int b, int a); void SetPixel(int x, int y, int r, int g, int b, int a); int BlendCharacter(int x, int y, int c, int r, int g, int b, int a); int AddCharacter(int x, int y, int c, int r, int g, int b, int a); int SetCharacter(int x, int y, int c, int r, int g, int b, int a); - ~VideoBuffer() { free(Buffer); }; + ~VideoBuffer(); }; class Graphics @@ -158,6 +160,8 @@ public: void 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 draw_image(pixel *img, int x, int y, int w, int h, int a); + void draw_image(const VideoBuffer & vidBuf, int w, int h, int a); + void draw_image(VideoBuffer * vidBuf, int w, int h, int a); Graphics(); ~Graphics(); diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 30f1bfd..d91d30f 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -394,6 +394,95 @@ void Renderer::RenderZoom() #endif } +int Renderer_wtypesCount; +wall_type * Renderer_wtypes = LoadWalls(Renderer_wtypesCount); + + +VideoBuffer * Renderer::WallIcon(int wallID, int width, int height) +{ + int x, y, i, j, cr, cg, cb; + int wt = wallID; + if (wt<0 || wt>=Renderer_wtypesCount) + return 0; + wall_type *wtypes = Renderer_wtypes; + pixel pc = wtypes[wt].colour; + pixel gc = wtypes[wt].eglow; + VideoBuffer * newTexture = new VideoBuffer(width, height); + if (wtypes[wt].drawstyle==1) + { + for (j=0; j<height; j+=2) + for (i=(j>>1)&1; i<width; i+=2) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + } + else if (wtypes[wt].drawstyle==2) + { + for (j=0; j<height; j+=2) + for (i=0; i<width; i+=2) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + } + else if (wtypes[wt].drawstyle==3) + { + for (j=0; j<height; j++) + for (i=0; i<width; i++) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + } + else if (wtypes[wt].drawstyle==4) + { + for (j=0; j<height; j++) + for (i=0; i<width; i++) + if(i%CELL == j%CELL) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + else if (i%CELL == (j%CELL)+1 || (i%CELL == 0 && j%CELL == CELL-1)) + newTexture->SetPixel(i, j, PIXR(gc), PIXG(gc), PIXB(gc), 255); + else + newTexture->SetPixel(i, j, 0x20, 0x20, 0x20, 255); + } + + // special rendering for some walls + if (wt==WL_EWALL) + { + for (j=0; j<height; j++) + for (i=0; i<width; i++) + if(i > width/2) + { + if (i&j&1) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + } + else + { + if (!(i&j&1)) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + } + } + else if (wt==WL_WALLELEC) + { + for (j=0; j<height; j++) + for (i=0; i<width; i++) + { + if (!((y*CELL+j)%2) && !((x*CELL+i)%2)) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + else + newTexture->SetPixel(i, j, 0x80, 0x80, 0x80, 255); + } + } + else if (wt==WL_EHOLE) + { + for (j=0; j<height; j++) + for (i=0; i<width; i++) + if(i < width/2) + { + if (i&j&1) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + } + else + { + if (!(i&j&1)) + newTexture->SetPixel(i, j, PIXR(pc), PIXG(pc), PIXB(pc), 255); + } + } + return newTexture; +} + void Renderer::DrawWalls() { #ifndef OGLR diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h index b2ae640..c292b80 100644 --- a/src/graphics/Renderer.h +++ b/src/graphics/Renderer.h @@ -122,6 +122,8 @@ public: void SetColourMode(unsigned int mode); unsigned int GetColourMode(); + static VideoBuffer * WallIcon(int wallID, int width, int height); + Renderer(Graphics * g, Simulation * sim); ~Renderer(); |
