Skip to content

Commit

Permalink
GUI: Add drawCircle()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkachov authored and sev- committed Jul 3, 2016
1 parent f22d119 commit 2231de0
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 5 deletions.
9 changes: 5 additions & 4 deletions graphics/VectorRenderer.h
Expand Up @@ -151,6 +151,7 @@ class VectorRenderer {
* @param r Radius of the circle.
*/
virtual void drawCircle(int x, int y, int r) = 0;
virtual void drawCircleClip(int x, int y, int r, Common::Rect clipping) = 0;

/**
* Draws a square starting at (x,y) with the given width and height.
Expand Down Expand Up @@ -358,16 +359,16 @@ class VectorRenderer {
/**
* DrawStep callback functions for each drawing feature
*/
void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) { //TODO
void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
uint16 x, y, w, h, radius;

radius = stepGetRadius(step, area);
stepGetPositions(step, area, x, y, w, h);

drawCircle(x + radius, y + radius, radius);
drawCircleClip(x + radius, y + radius, radius, clip);
}

void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) { //TODO
void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawSquareClip(x, y, w, h, clip);
Expand All @@ -389,7 +390,7 @@ class VectorRenderer {
fillSurface();
}

void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) { //TODO
void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawTriangleClip(x, y, w, h, (TriangleOrientation)step.extraData, clip);
Expand Down
103 changes: 103 additions & 0 deletions graphics/VectorRendererSpec.cpp
Expand Up @@ -1069,6 +1069,69 @@ drawCircle(int x, int y, int r) {
}
}

template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawCircleClip(int x, int y, int r, Common::Rect clipping) {
if (x + r > Base::_activeSurface->w || y + r > Base::_activeSurface->h ||
x - r < 0 || y - r < 0 || x == 0 || y == 0 || r <= 0)
return;

Common::Rect backup = _clippingArea;
_clippingArea = clipping;
bool useClippingVersions = !(_clippingArea.isEmpty() || _clippingArea.contains(Common::Rect(x - r, y - r, x + r, y + r)));

if (Base::_fillMode != kFillDisabled && Base::_shadowOffset
&& x + r + Base::_shadowOffset < Base::_activeSurface->w
&& y + r + Base::_shadowOffset < Base::_activeSurface->h) {
if (useClippingVersions)
drawCircleAlgClip(x + Base::_shadowOffset + 1, y + Base::_shadowOffset + 1, r, 0, kFillForeground);
else
drawCircleAlg(x + Base::_shadowOffset + 1, y + Base::_shadowOffset + 1, r, 0, kFillForeground);
}

switch (Base::_fillMode) {
case kFillDisabled:
if (Base::_strokeWidth)
if (useClippingVersions)
drawCircleAlgClip(x, y, r, _fgColor, kFillDisabled);
else
drawCircleAlg(x, y, r, _fgColor, kFillDisabled);
break;

case kFillForeground:
if (useClippingVersions)
drawCircleAlgClip(x, y, r, _fgColor, kFillForeground);
else
drawCircleAlg(x, y, r, _fgColor, kFillForeground);
break;

case kFillBackground:
if (Base::_strokeWidth > 1) {
if (useClippingVersions) {
drawCircleAlgClip(x, y, r, _fgColor, kFillForeground);
drawCircleAlgClip(x, y, r - Base::_strokeWidth, _bgColor, kFillBackground);
} else {
drawCircleAlg(x, y, r, _fgColor, kFillForeground);
drawCircleAlg(x, y, r - Base::_strokeWidth, _bgColor, kFillBackground);
}
} else {
if (useClippingVersions) {
drawCircleAlgClip(x, y, r, _bgColor, kFillBackground);
drawCircleAlgClip(x, y, r, _fgColor, kFillDisabled);
} else {
drawCircleAlg(x, y, r, _bgColor, kFillBackground);
drawCircleAlg(x, y, r, _fgColor, kFillDisabled);
}
}
break;

case kFillGradient:
break;
}

_clippingArea = backup;
}

/** SQUARES **/
template<typename PixelType>
void VectorRendererSpec<PixelType>::
Expand Down Expand Up @@ -2677,7 +2740,47 @@ drawCircleAlg(int x1, int y1, int r, PixelType color, VectorRenderer::FillMode f
}


template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawCircleAlgClip(int x1, int y1, int r, PixelType color, VectorRenderer::FillMode fill_m) {
int f, ddF_x, ddF_y;
int x, y, px, py, sw = 0;
int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
PixelType *ptr = (PixelType *)Base::_activeSurface->getBasePtr(x1, y1);

if (fill_m == kFillDisabled) {
while (sw++ < Base::_strokeWidth) {
BE_RESET();
r--;

if (IS_IN_CLIP(x1 + y, y1)) *(ptr + y) = color;
if (IS_IN_CLIP(x1 - y, y1)) *(ptr - y) = color;
if (IS_IN_CLIP(x1, y1 + y)) *(ptr + py) = color;
if (IS_IN_CLIP(x1, y1 - y)) *(ptr - py) = color;

while (x++ < y) {
BE_ALGORITHM();
BE_DRAWCIRCLE_CLIP(ptr, ptr, ptr, ptr, x, y, px, py, x1, y1, x1, y1, x1, y1, x1, y1);

if (Base::_strokeWidth > 1) {
BE_DRAWCIRCLE_CLIP(ptr, ptr, ptr, ptr, x - 1, y, px, py, x1, y1, x1, y1, x1, y1, x1, y1);
BE_DRAWCIRCLE_CLIP(ptr, ptr, ptr, ptr, x, y, px - pitch, py, x1, y1, x1, y1, x1, y1, x1, y1);
}
}
}
} else {
colorFillClip<PixelType>(ptr - r, ptr + r, color, x1 - r, y1 + r, _clippingArea);
BE_RESET();

while (x++ < y) {
BE_ALGORITHM();
colorFillClip<PixelType>(ptr - x + py, ptr + x + py, color, x1 - x, y1 + y, _clippingArea);
colorFillClip<PixelType>(ptr - x - py, ptr + x - py, color, x1 - x, y1 - y, _clippingArea);
colorFillClip<PixelType>(ptr - y + px, ptr + y + px, color, x1 - y, y1 + x, _clippingArea);
colorFillClip<PixelType>(ptr - y - px, ptr + y - px, color, x1 - y, y1 - x, _clippingArea);
}
}
}


/********************************************************************
Expand Down
6 changes: 5 additions & 1 deletion graphics/VectorRendererSpec.h
Expand Up @@ -51,7 +51,8 @@ class VectorRendererSpec : public VectorRenderer {
VectorRendererSpec(PixelFormat format);

void drawLine(int x1, int y1, int x2, int y2); //TODO
void drawCircle(int x, int y, int r); //TODO
void drawCircle(int x, int y, int r);
void drawCircleClip(int x, int y, int r, Common::Rect clipping);
void drawSquare(int x, int y, int w, int h);
void drawSquareClip(int x, int y, int w, int h, Common::Rect clipping);
void drawRoundedSquare(int x, int y, int r, int w, int h);
Expand Down Expand Up @@ -161,6 +162,9 @@ class VectorRendererSpec : public VectorRenderer {
virtual void drawCircleAlg(int x, int y, int r,
PixelType color, FillMode fill_m);

virtual void drawCircleAlgClip(int x, int y, int r,
PixelType color, FillMode fill_m);

virtual void drawRoundedSquareAlg(int x1, int y1, int r, int w, int h,
PixelType color, FillMode fill_m);

Expand Down

0 comments on commit 2231de0

Please sign in to comment.