Nice drawing for brush
This commit is contained in:
parent
b2907798f2
commit
84ceea525b
@ -13,12 +13,36 @@
|
|||||||
class Brush
|
class Brush
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
bool * outline;
|
||||||
bool * bitmap;
|
bool * bitmap;
|
||||||
ui::Point size;
|
ui::Point size;
|
||||||
|
void updateOutline()
|
||||||
|
{
|
||||||
|
if(!bitmap)
|
||||||
|
GenerateBitmap();
|
||||||
|
if(!bitmap)
|
||||||
|
return;
|
||||||
|
if(outline)
|
||||||
|
free(outline);
|
||||||
|
int width = size.X*2;
|
||||||
|
int height = size.Y*2;
|
||||||
|
outline = (bool *)malloc(sizeof(bool)*((width+1)*(height+1)));
|
||||||
|
for(int x = 0; x <= width; x++)
|
||||||
|
{
|
||||||
|
for(int y = 0; y <= height; y++)
|
||||||
|
{
|
||||||
|
if(bitmap[y*width+x] && (!y || !x || y == height || x == width || !bitmap[y*width+(x+1)] || !bitmap[y*width+(x-1)] || !bitmap[(y-1)*width+x] || !bitmap[(y+1)*width+x]))
|
||||||
|
outline[y*width+x] = true;
|
||||||
|
else
|
||||||
|
outline[y*width+x] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
Brush(ui::Point size_):
|
Brush(ui::Point size_):
|
||||||
bitmap(NULL),
|
bitmap(NULL),
|
||||||
size(size_)
|
size(size_),
|
||||||
|
outline(NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -30,10 +54,13 @@ public:
|
|||||||
{
|
{
|
||||||
this->size = size;
|
this->size = size;
|
||||||
GenerateBitmap();
|
GenerateBitmap();
|
||||||
|
updateOutline();
|
||||||
}
|
}
|
||||||
virtual ~Brush() {
|
virtual ~Brush() {
|
||||||
if(bitmap)
|
if(bitmap)
|
||||||
delete bitmap;
|
delete bitmap;
|
||||||
|
if(outline)
|
||||||
|
delete outline;
|
||||||
}
|
}
|
||||||
virtual void RenderRect(Graphics * g, ui::Point position1, ui::Point position2)
|
virtual void RenderRect(Graphics * g, ui::Point position1, ui::Point position2)
|
||||||
{
|
{
|
||||||
@ -50,16 +77,30 @@ public:
|
|||||||
position1.X += width;
|
position1.X += width;
|
||||||
width *= -1;
|
width *= -1;
|
||||||
}
|
}
|
||||||
g->fillrect(position1.X-1, position1.Y-1, width+2, height+2, 255, 0, 255, 70);
|
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)
|
virtual void RenderLine(Graphics * g, ui::Point position1, ui::Point position2)
|
||||||
{
|
{
|
||||||
g->blend_line(position1.X, position1.Y, position2.X, position2.Y, 255, 0, 255, 70);
|
g->xor_line(position1.X, position1.Y, position2.X, position2.Y);
|
||||||
}
|
}
|
||||||
//Draw the brush outline onto the screen
|
//Draw the brush outline onto the screen
|
||||||
virtual void RenderPoint(Graphics * g, ui::Point position)
|
virtual void RenderPoint(Graphics * g, ui::Point position)
|
||||||
{
|
{
|
||||||
g->fillrect(position.X-size.X-1, position.Y-size.Y-1, (size.X*2)+2, (size.Y*2)+2, 255, 0, 255, 70);
|
if(!outline)
|
||||||
|
updateOutline();
|
||||||
|
if(!outline)
|
||||||
|
return;
|
||||||
|
for(int x = 0; x <= size.X*2; x++)
|
||||||
|
{
|
||||||
|
for(int y = 0; y <= size.Y*2; y++)
|
||||||
|
{
|
||||||
|
if(outline[y*(size.X*2)+x])
|
||||||
|
g->xor_pixel(position.X-size.X+x, position.Y-size.Y+y);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
virtual void GenerateBitmap()
|
virtual void GenerateBitmap()
|
||||||
{
|
{
|
||||||
@ -81,6 +122,15 @@ public:
|
|||||||
GenerateBitmap();
|
GenerateBitmap();
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool * GetOutline()
|
||||||
|
{
|
||||||
|
if(!outline)
|
||||||
|
updateOutline();
|
||||||
|
if(!outline)
|
||||||
|
return NULL;
|
||||||
|
return outline;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,21 +18,6 @@ public:
|
|||||||
{
|
{
|
||||||
|
|
||||||
};
|
};
|
||||||
//Draw the brush outline onto the screen
|
|
||||||
virtual void RenderPoint(Graphics * g, ui::Point position)
|
|
||||||
{
|
|
||||||
if(!bitmap)
|
|
||||||
GenerateBitmap();
|
|
||||||
//g->fillrect(position.X-size.X-1, position.Y-size.Y-1, (size.X*2)+2, (size.Y*2)+2, 255, 0, 255, 70);
|
|
||||||
for(int x = 0; x <= size.X*2; x++)
|
|
||||||
{
|
|
||||||
for(int y = 0; y <= size.Y*2; y++)
|
|
||||||
{
|
|
||||||
if(bitmap[y*(size.X*2)+x])
|
|
||||||
g->blendpixel(position.X-size.X+x, position.Y-size.Y+y, 255, 0, 255, 70);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void GenerateBitmap()
|
virtual void GenerateBitmap()
|
||||||
{
|
{
|
||||||
if(bitmap)
|
if(bitmap)
|
||||||
|
Loading…
Reference in New Issue
Block a user