Draw brush using renderer, fixes issue #25

This commit is contained in:
Simon Robertshaw 2012-07-28 13:09:35 +01:00
parent 30b11a7724
commit f9eeebb910
4 changed files with 52 additions and 43 deletions

42
src/game/Brush.cpp Normal file
View File

@ -0,0 +1,42 @@
#include "Brush.h"
#include "graphics/Renderer.h"
void Brush::RenderRect(Renderer * ren, ui::Point position1, ui::Point position2)
{
int width, height, t;
width = position2.X-position1.X;
height = position2.Y-position1.Y;
if(height<0)
{
position1.Y += height;
height *= -1;
}
if(width<0)
{
position1.X += width;
width *= -1;
}
ren->xor_line(position1.X, position1.Y, position1.X+width, position1.Y);
ren->xor_line(position1.X, position1.Y+height, position1.X+width, position1.Y+height);
ren->xor_line(position1.X+width, position1.Y+1, position1.X+width, position1.Y+height-1);
ren->xor_line(position1.X, position1.Y+1, position1.X, position1.Y+height-1);
}
void Brush::RenderLine(Renderer * ren, ui::Point position1, ui::Point position2)
{
ren->xor_line(position1.X, position1.Y, position2.X, position2.Y);
}
void Brush::RenderPoint(Renderer * ren, ui::Point position)
{
if(!outline)
updateOutline();
if(!outline)
return;
ren->xor_bitmap(outline, position.X-radius.X, position.Y-radius.Y, size.X, size.Y);
}
void Brush::RenderFill(Renderer * ren, ui::Point position)
{
}

View File

@ -11,6 +11,7 @@
#include <iostream>
#include "interface/Point.h"
class Renderer;
class Brush
{
protected:
@ -73,43 +74,10 @@ public:
if(outline)
delete[] outline;
}
virtual void RenderRect(Graphics * g, ui::Point position1, ui::Point position2)
{
int width, height, t;
width = position2.X-position1.X;
height = position2.Y-position1.Y;
if(height<0)
{
position1.Y += height;
height *= -1;
}
if(width<0)
{
position1.X += width;
width *= -1;
}
g->xor_line(position1.X, position1.Y, position1.X+width, position1.Y);
g->xor_line(position1.X, position1.Y+height, position1.X+width, position1.Y+height);
g->xor_line(position1.X+width, position1.Y+1, position1.X+width, position1.Y+height-1);
g->xor_line(position1.X, position1.Y+1, position1.X, position1.Y+height-1);
}
virtual void RenderLine(Graphics * g, ui::Point position1, ui::Point position2)
{
g->xor_line(position1.X, position1.Y, position2.X, position2.Y);
}
//Draw the brush outline onto the screen
virtual void RenderPoint(Graphics * g, ui::Point position)
{
if(!outline)
updateOutline();
if(!outline)
return;
g->xor_bitmap(outline, position.X-radius.X, position.Y-radius.Y, size.X, size.Y);
}
virtual void RenderFill(Graphics * g, ui::Point position)
{
//Do nothing for now - possibly draw some sort of flood fill mask
}
virtual void RenderRect(Renderer * ren, ui::Point position1, ui::Point position2);
virtual void RenderLine(Renderer * ren, ui::Point position1, ui::Point position2);
virtual void RenderPoint(Renderer * ren, ui::Point position);
virtual void RenderFill(Renderer * ren, ui::Point position);
virtual void GenerateBitmap()
{
if(bitmap)

View File

@ -1206,7 +1206,7 @@ void GameView::OnDraw()
{
finalCurrentMouse = rectSnapCoords(c->PointTranslate(drawPoint1), finalCurrentMouse);
}
activeBrush->RenderRect(g, c->PointTranslate(drawPoint1), finalCurrentMouse);
activeBrush->RenderRect(ren, c->PointTranslate(drawPoint1), finalCurrentMouse);
}
else if(drawMode==DrawLine && isMouseDown)
{
@ -1214,15 +1214,15 @@ void GameView::OnDraw()
{
finalCurrentMouse = lineSnapCoords(c->PointTranslate(drawPoint1), finalCurrentMouse);
}
activeBrush->RenderLine(g, c->PointTranslate(drawPoint1), finalCurrentMouse);
activeBrush->RenderLine(ren, c->PointTranslate(drawPoint1), finalCurrentMouse);
}
else if(drawMode==DrawFill)
{
activeBrush->RenderFill(g, finalCurrentMouse);
activeBrush->RenderFill(ren, finalCurrentMouse);
}
else
{
activeBrush->RenderPoint(g, finalCurrentMouse);
activeBrush->RenderPoint(ren, finalCurrentMouse);
}
}
ren->RenderEnd();

View File

@ -45,15 +45,14 @@ void Renderer::RenderBegin()
DrawWalls();
DrawSigns();
#ifndef OGLR
RenderZoom();
FinaliseParts();
#endif
}
void Renderer::RenderEnd()
{
#ifdef OGLR
RenderZoom();
#ifdef OGLR
FinaliseParts();
#endif
}