diff options
| author | jacob1 <jfu614@gmail.com> | 2013-05-17 16:44:25 (GMT) |
|---|---|---|
| committer | jacob1 <jfu614@gmail.com> | 2013-05-17 16:44:25 (GMT) |
| commit | 981f6984c2c0f87d54a9c90f4518c69c9ef02ae0 (patch) | |
| tree | 757bd699a23c1fad61e60700265a25feb1a3042c /src/graphics | |
| parent | cbd402d8cb6aa699ffde83a1b5b3c2f4fc51baaf (diff) | |
| parent | 77bf649fb4482c86ac1fd9b3233f062b53226007 (diff) | |
| download | powder-981f6984c2c0f87d54a9c90f4518c69c9ef02ae0.zip powder-981f6984c2c0f87d54a9c90f4518c69c9ef02ae0.tar.gz | |
Merge branch 'HEAD' of git@github.com:FacialTurd/The-Powder-Toy.git
Diffstat (limited to 'src/graphics')
| -rw-r--r-- | src/graphics/Graphics.cpp | 2 | ||||
| -rw-r--r-- | src/graphics/Graphics.h | 2 | ||||
| -rw-r--r-- | src/graphics/OpenGLDrawMethods.inl | 56 | ||||
| -rw-r--r-- | src/graphics/RasterDrawMethods.inl | 54 | ||||
| -rw-r--r-- | src/graphics/Renderer.cpp | 4 | ||||
| -rw-r--r-- | src/graphics/Renderer.h | 2 |
6 files changed, 117 insertions, 3 deletions
diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index bacb421..09da936 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -47,7 +47,7 @@ void VideoBuffer::Resize(float factor, bool resample) { int newWidth = ((float)Width)*factor; int newHeight = ((float)Height)*factor; - Resize(newWidth, newHeight); + Resize(newWidth, newHeight, resample); } void VideoBuffer::Resize(int width, int height, bool resample, bool fixedRatio) diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index 3a87bb6..2cbdd87 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -239,6 +239,8 @@ public: void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a); void drawrect(int x, int y, int width, int height, int r, int g, int b, int a); void fillrect(int x, int y, int width, int height, int r, int g, int b, int a); + void drawcircle(int x, int y, int rx, int ry, int r, int g, int b, int a); + void fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a); void clearrect(int x, int y, int width, int height); 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); diff --git a/src/graphics/OpenGLDrawMethods.inl b/src/graphics/OpenGLDrawMethods.inl index bfc338a..52d09da 100644 --- a/src/graphics/OpenGLDrawMethods.inl +++ b/src/graphics/OpenGLDrawMethods.inl @@ -1,4 +1,5 @@ -#include "../data/font.h" +#include "../data/font.h" +#include <math.h> int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a) { @@ -314,6 +315,59 @@ void PIXELMETHODS_CLASS::fillrect(int x, int y, int width, int height, int r, in glEnd(); } +void PIXELMETHODS_CLASS::drawcircle(int x, int y, int rx, int ry, int r, int g, int b, int a) +{ + int yTop = ry, yBottom, i, j; + if (!rx) + { + for (j = -ry; j <= ry; j++) + blendpixel(x, y+j, r, g, b, a); + return; + } + for (i = 0; i <= rx; i++) { + yBottom = yTop; + while (pow(i-rx,2.0)*pow(ry,2.0) + pow(yTop-ry,2.0)*pow(rx,2.0) <= pow(rx,2.0)*pow(ry,2.0)) + yTop++; + if (yBottom != yTop) + yTop--; + for (int j = yBottom; j <= yTop; j++) + { + blendpixel(x+i-rx, y+j-ry, r, g, b, a); + if (i != rx) + blendpixel(x-i+rx, y+j-ry, r, g, b, a); + if (j != ry) + { + blendpixel(x+i-rx, y-j+ry, r, g, b, a); + if (i != rx) + blendpixel(x-i+rx, y-j+ry, r, g, b, a); + } + } + } +} + +void PIXELMETHODS_CLASS::fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a) +{ + int yTop = ry+1, yBottom, i, j; + if (!rx) + { + for (j = -ry; j <= ry; j++) + blendpixel(x, y+j, r, g, b, a); + return; + } + for (i = 0; i <= rx; i++) + { + while (pow(i-rx,2.0)*pow(ry,2.0) + pow(yTop-ry,2.0)*pow(rx,2.0) <= pow(rx,2.0)*pow(ry,2.0)) + yTop++; + yBottom = 2*ry - yTop; + for (int j = yBottom+1; j < yTop; j++) + { + blendpixel(x+i-rx, y+j-ry, r, g, b, a); + if (i != rx) + blendpixel(x-i+rx, y+j-ry, r, g, b, a); + } + } +} + void PIXELMETHODS_CLASS::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) { glBegin(GL_QUADS); diff --git a/src/graphics/RasterDrawMethods.inl b/src/graphics/RasterDrawMethods.inl index b4de875..5ac22cb 100644 --- a/src/graphics/RasterDrawMethods.inl +++ b/src/graphics/RasterDrawMethods.inl @@ -1,4 +1,5 @@ #include "font.h" +#include <math.h> int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a) { @@ -356,6 +357,59 @@ void PIXELMETHODS_CLASS::fillrect(int x, int y, int w, int h, int r, int g, int blendpixel(x+i, y+j, r, g, b, a); } +void PIXELMETHODS_CLASS::drawcircle(int x, int y, int rx, int ry, int r, int g, int b, int a) +{ + int yTop = ry, yBottom, i, j; + if (!rx) + { + for (j = -ry; j <= ry; j++) + blendpixel(x, y+j, r, g, b, a); + return; + } + for (i = 0; i <= rx; i++) { + yBottom = yTop; + while (pow(i-rx,2.0)*pow(ry,2.0) + pow(yTop-ry,2.0)*pow(rx,2.0) <= pow(rx,2.0)*pow(ry,2.0)) + yTop++; + if (yBottom != yTop) + yTop--; + for (int j = yBottom; j <= yTop; j++) + { + blendpixel(x+i-rx, y+j-ry, r, g, b, a); + if (i != rx) + blendpixel(x-i+rx, y+j-ry, r, g, b, a); + if (j != ry) + { + blendpixel(x+i-rx, y-j+ry, r, g, b, a); + if (i != rx) + blendpixel(x-i+rx, y-j+ry, r, g, b, a); + } + } + } +} + +void PIXELMETHODS_CLASS::fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a) +{ + int yTop = ry+1, yBottom, i, j; + if (!rx) + { + for (j = -ry; j <= ry; j++) + blendpixel(x, y+j, r, g, b, a); + return; + } + for (i = 0; i <= rx; i++) + { + while (pow(i-rx,2.0)*pow(ry,2.0) + pow(yTop-ry,2.0)*pow(rx,2.0) <= pow(rx,2.0)*pow(ry,2.0)) + yTop++; + yBottom = 2*ry - yTop; + for (int j = yBottom+1; j < yTop; j++) + { + blendpixel(x+i-rx, y+j-ry, r, g, b, a); + if (i != rx) + blendpixel(x-i+rx, y+j-ry, r, g, b, a); + } + } +} + void PIXELMETHODS_CLASS::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) { diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index a3ea66d..dfdd307 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -9,8 +9,10 @@ #include "simulation/Elements.h" #include "simulation/ElementGraphics.h" #include "simulation/Air.h" +#ifdef LUACONSOLE #include "cat/LuaScriptInterface.h" #include "cat/LuaScriptHelper.h" +#endif extern "C" { #include "hmap.h" @@ -1212,7 +1214,7 @@ void Renderer::render_parts() { if (elements[t].Graphics) { -#ifndef RENDERER +#if !defined(RENDERER) && defined(LUACONSOLE) if (lua_gr_func[t]) { luacon_graphicsReplacement(this, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb, i); diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h index 9251006..8a7120f 100644 --- a/src/graphics/Renderer.h +++ b/src/graphics/Renderer.h @@ -126,6 +126,8 @@ public: void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a); void drawrect(int x, int y, int width, int height, int r, int g, int b, int a); void fillrect(int x, int y, int width, int height, int r, int g, int b, int a); + void drawcircle(int x, int y, int rx, int ry, int r, int g, int b, int a); + void fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a); void clearrect(int x, int y, int width, int height); 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); |
