Skip to content

Commit

Permalink
fix draw functions to work with orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Apr 21, 2024
1 parent 8b298b5 commit 971957f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 11 deletions.
6 changes: 3 additions & 3 deletions include/ccanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ class CCanvas:public CObject
void Spline (wxPoint * points, int npoints);
//void Segments (wxSegment * segs, int nsegs);
void Rectangle (bool filled, float x, float y, float width, float height);
void Arc (bool filled, int x, int y, int x1, int y1, int x2, int y2);
void Arc (bool filled, float x1, float y1, float x2, float y2, float xc, float yc);
void Circle (bool filled, float x, float y, float radius);
void Text (lxString str, float x, float y);
void RotatedText (lxString str, float x, float y, float angle);
void TextOnRect (lxString str, wxRect, unsigned int align );
void Polygon (bool filled, wxPoint * points, int npoints);
void Ellipse(bool filled,int x, int y, int width, int height);
void EllipticArc(bool filled,int x, int y, int width, int height, double start, double end);
void Ellipse(bool filled,float x, float y, float width, float height);
void EllipticArc(bool filled, float x, float y, float width, float height, double start, double end);
void PutBitmap(wxBitmap * bitmap,float x, float y);

void FloodFill(int x, int y,wxColor color, wxFloodFillStyle style);
Expand Down
84 changes: 76 additions & 8 deletions lib/ccanvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,19 @@ CCanvas::Line(float x1_, float y1_, float x2_, float y2_)
void
CCanvas::Lines(wxPoint * points, int npoints)
{
if (DC != NULL) DC->DrawLines (npoints, points);
if (DC != NULL)
{
float x, y;
for(int p = 0; p < npoints; p++)
{
x = points[p].x;
y = points[p].y;
Rotate(&x, &y);
points[p].x = x;
points[p].y = y;
}
DC->DrawLines (npoints, points);
}
}

void
Expand Down Expand Up @@ -518,15 +530,20 @@ CCanvas::Rectangle(bool filled, float x, float y, float width, float height)
}

void
CCanvas::Arc(bool filled, int x, int y, int x1, int y1, int x2, int y2)
CCanvas::Arc(bool filled, float x1, float y1, float x2, float y2, float xc, float yc)
{
if (DC != NULL)
{
if (filled)
DC->SetBrush (*Brush);
else
DC->SetBrush (*wxTRANSPARENT_BRUSH);
DC->DrawArc (x, y, x1, y1, x2, y2);

Rotate (&x1, &y1);
Rotate (&x2, &y2);
Rotate (&xc, &yc);

DC->DrawArc (x1, y1, x2, y2, xc, yc);
}
}

Expand All @@ -539,6 +556,16 @@ CCanvas::Polygon(bool filled, wxPoint * points, int npoints)
DC->SetBrush (*Brush);
else
DC->SetBrush (*wxTRANSPARENT_BRUSH);

float x, y;
for(int p = 0; p < npoints; p++)
{
x = points[p].x;
y = points[p].y;
Rotate(&x, &y);
points[p].x = x;
points[p].y = y;
}

DC->DrawPolygon (npoints, points);
}
Expand Down Expand Up @@ -577,29 +604,70 @@ CCanvas::Circle(bool filled, float x, float y, float radius)
}

void
CCanvas::Ellipse(bool filled, int x, int y, int width, int height)
CCanvas::Ellipse(bool filled, float x, float y, float width, float height)
{
if (DC != NULL)
{
if (filled)
DC->SetBrush (*Brush);
else
DC->SetBrush (*wxTRANSPARENT_BRUSH);
DC->DrawEllipse (x, y, width, height);

float x2, y2;
x2 = x + width;
y2 = y + height;
Rotate (&x, &y);
Rotate (&x2, &y2);

DC->DrawEllipse (x, y, x2 - x, y2 - y);
}
}

void
CCanvas::EllipticArc(bool filled, int x, int y, int width, int height, double start, double end)
CCanvas::EllipticArc(bool filled, float x, float y, float width, float height, double start, double end)
{
if (DC != NULL)
{
if (filled)
DC->SetBrush (*Brush);
else
DC->SetBrush (*wxTRANSPARENT_BRUSH);

DC->DrawEllipticArc (x, y, width, height, start, end);

float x2, y2, w, h;
x2 = x + width;
y2 = y + height;
Rotate (&x, &y);
Rotate (&x2, &y2);
w = x2 - x;
h = y2 - y;

switch (orientation)
{
case 1:
start -= 90;
end -= 90;
x += w;
w = -w;
break;
case 2:
start -= 180;
end -= 180;
x += w;
y += h;
w = -w;
h = -h;
break;
case 3:
start -= 270;
end -= 270;
y += h;
h = -h;
break;
default:
break;
}

DC->DrawEllipticArc (x, y, w, h, start, end);
}
}

Expand Down

0 comments on commit 971957f

Please sign in to comment.