moving rounded rect and ellipse to path class

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42467 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2006-10-26 19:24:18 +00:00
parent 07c7a3f1fd
commit 59720690df
2 changed files with 43 additions and 35 deletions

View File

@@ -139,9 +139,15 @@ public :
// appends an ellipsis as a new closed subpath fitting the passed rectangle
virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
// draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
// appends a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
// appends an ellipse
virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
// appends a rounded rectangle
virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
// returns the native path
virtual void * GetNativePath() const = 0;

View File

@@ -130,6 +130,38 @@ void wxGraphicsPath::AddCircle( wxDouble x, wxDouble y, wxDouble r )
CloseSubpath();
}
void wxGraphicsPath::AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
{
wxDouble rw = w/2;
wxDouble rh = h/2;
wxDouble xc = x + rw;
wxDouble yc = y + rh;
wxGraphicsMatrix* m = GetRenderer()->CreateMatrix();
m->Translate(xc,yc);
m->Scale(rw/rh,1.0);
wxGraphicsPath* p = GetRenderer()->CreatePath();
p->AddCircle(0,0,rh);
p->Transform(m);
AddPath(p);
delete p;
delete m;
}
void wxGraphicsPath::AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius)
{
if ( radius == 0 )
AddRectangle(x,y,w,h);
else
{
MoveToPoint( x + w, y + h / 2);
AddArcToPoint(x + w, y + h, x + w / 2, y + h, radius);
AddArcToPoint(x, y + h, x, y + h / 2, radius);
AddArcToPoint(x, y , x + w / 2, y, radius);
AddArcToPoint(x + w, y, x + w, y + h / 2, radius);
CloseSubpath();
}
}
// draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r )
{
@@ -273,46 +305,16 @@ void wxGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDou
void wxGraphicsContext::DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
{
wxGraphicsPath* path = CreatePath();
if ( w == h )
{
path->AddCircle( x+w/2,y+w/2,w/2);
DrawPath(path);
}
else
{
PushState();
Translate(x+w/2,y+h/2);
wxDouble factor = ((wxDouble) w) / h;
Scale( factor , 1.0);
path->AddCircle(0,0,h/2);
DrawPath(path);
PopState();
}
path->AddEllipse(x,y,w,h);
DrawPath(path);
delete path;
}
void wxGraphicsContext::DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius)
{
wxGraphicsPath* path = CreatePath();
if ( radius == 0)
{
path->AddRectangle( x , y , w , h );
DrawPath( path );
}
else
{
PushState();
Translate( x , y );
path->MoveToPoint(w, h / 2);
path->AddArcToPoint(w, h, w / 2, h, radius);
path->AddArcToPoint(0, h, 0, h / 2, radius);
path->AddArcToPoint(0, 0, w / 2, 0, radius);
path->AddArcToPoint(w, 0, w, h / 2, radius);
path->CloseSubpath();
DrawPath( path );
PopState();
}
path->AddRoundedRectangle(x,y,w,h,radius);
DrawPath(path);
delete path;
}