📄 basic2.cpp
字号:
// In case we're reading an old file, set the region's size
if (m_regions.GetCount() == 1)
{
wxShapeRegion *region = (wxShapeRegion *)m_regions.GetFirst()->GetData();
region->SetSize(m_width, m_height);
}
}
#endif
void wxRectangleShape::Copy(wxShape& copy)
{
wxShape::Copy(copy);
wxASSERT( copy.IsKindOf(CLASSINFO(wxRectangleShape)) );
wxRectangleShape& rectCopy = (wxRectangleShape&) copy;
rectCopy.m_width = m_width;
rectCopy.m_height = m_height;
rectCopy.m_cornerRadius = m_cornerRadius;
}
int wxRectangleShape::GetNumberOfAttachments() const
{
return wxShape::GetNumberOfAttachments();
}
// There are 4 attachment points on a rectangle - 0 = top, 1 = right, 2 = bottom,
// 3 = left.
bool wxRectangleShape::GetAttachmentPosition(int attachment, double *x, double *y,
int nth, int no_arcs, wxLineShape *line)
{
return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
}
// Text object (no box)
IMPLEMENT_DYNAMIC_CLASS(wxTextShape, wxRectangleShape)
wxTextShape::wxTextShape(double width, double height):
wxRectangleShape(width, height)
{
}
void wxTextShape::OnDraw(wxDC& WXUNUSED(dc))
{
}
void wxTextShape::Copy(wxShape& copy)
{
wxRectangleShape::Copy(copy);
}
#if wxUSE_PROLOGIO
void wxTextShape::WriteAttributes(wxExpr *clause)
{
wxRectangleShape::WriteAttributes(clause);
}
#endif
// Ellipse object
IMPLEMENT_DYNAMIC_CLASS(wxEllipseShape, wxShape)
wxEllipseShape::wxEllipseShape(double w, double h)
{
m_width = w; m_height = h;
SetDefaultRegionSize();
}
void wxEllipseShape::GetBoundingBoxMin(double *w, double *h)
{
*w = m_width; *h = m_height;
}
bool wxEllipseShape::GetPerimeterPoint(double x1, double y1,
double x2, double y2,
double *x3, double *y3)
{
double bound_x, bound_y;
GetBoundingBoxMax(&bound_x, &bound_y);
// oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3);
oglDrawArcToEllipse(m_xpos, m_ypos, bound_x, bound_y, x2, y2, x1, y1, x3, y3);
return true;
}
void wxEllipseShape::OnDraw(wxDC& dc)
{
if (m_shadowMode != SHADOW_NONE)
{
if (m_shadowBrush)
dc.SetBrush(* m_shadowBrush);
dc.SetPen(* g_oglTransparentPen);
dc.DrawEllipse((long) ((m_xpos - GetWidth()/2) + m_shadowOffsetX),
(long) ((m_ypos - GetHeight()/2) + m_shadowOffsetY),
(long) GetWidth(), (long) GetHeight());
}
if (m_pen)
{
if (m_pen->GetWidth() == 0)
dc.SetPen(* g_oglTransparentPen);
else
dc.SetPen(* m_pen);
}
if (m_brush)
dc.SetBrush(* m_brush);
dc.DrawEllipse((long) (m_xpos - GetWidth()/2), (long) (m_ypos - GetHeight()/2), (long) GetWidth(), (long) GetHeight());
}
void wxEllipseShape::SetSize(double x, double y, bool WXUNUSED(recursive))
{
SetAttachmentSize(x, y);
m_width = x;
m_height = y;
SetDefaultRegionSize();
}
#if wxUSE_PROLOGIO
void wxEllipseShape::WriteAttributes(wxExpr *clause)
{
wxShape::WriteAttributes(clause);
clause->AddAttributeValue(wxT("x"), m_xpos);
clause->AddAttributeValue(wxT("y"), m_ypos);
clause->AddAttributeValue(wxT("width"), m_width);
clause->AddAttributeValue(wxT("height"), m_height);
}
void wxEllipseShape::ReadAttributes(wxExpr *clause)
{
wxShape::ReadAttributes(clause);
clause->AssignAttributeValue(wxT("width"), &m_width);
clause->AssignAttributeValue(wxT("height"), &m_height);
// In case we're reading an old file, set the region's size
if (m_regions.GetCount() == 1)
{
wxShapeRegion *region = (wxShapeRegion *)m_regions.GetFirst()->GetData();
region->SetSize(m_width, m_height);
}
}
#endif
void wxEllipseShape::Copy(wxShape& copy)
{
wxShape::Copy(copy);
wxASSERT( copy.IsKindOf(CLASSINFO(wxEllipseShape)) );
wxEllipseShape& ellipseCopy = (wxEllipseShape&) copy;
ellipseCopy.m_width = m_width;
ellipseCopy.m_height = m_height;
}
int wxEllipseShape::GetNumberOfAttachments() const
{
return wxShape::GetNumberOfAttachments();
}
// There are 4 attachment points on an ellipse - 0 = top, 1 = right, 2 = bottom,
// 3 = left.
bool wxEllipseShape::GetAttachmentPosition(int attachment, double *x, double *y,
int nth, int no_arcs, wxLineShape *line)
{
if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
if (m_attachmentMode != ATTACHMENT_MODE_NONE)
{
double top = (double)(m_ypos + m_height/2.0);
double bottom = (double)(m_ypos - m_height/2.0);
double left = (double)(m_xpos - m_width/2.0);
double right = (double)(m_xpos + m_width/2.0);
int physicalAttachment = LogicalToPhysicalAttachment(attachment);
switch (physicalAttachment)
{
case 0:
{
if (m_spaceAttachments)
*x = left + (nth + 1)*m_width/(no_arcs + 1);
else *x = m_xpos;
*y = top;
// We now have the point on the bounding box: but get the point on the ellipse
// by imagining a vertical line from (*x, m_ypos - m_height- 500) to (*x, m_ypos) intersecting
// the ellipse.
oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, *x, (double)(m_ypos-m_height-500), *x, m_ypos, x, y);
break;
}
case 1:
{
*x = right;
if (m_spaceAttachments)
*y = bottom + (nth + 1)*m_height/(no_arcs + 1);
else *y = m_ypos;
oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, (double)(m_xpos+m_width+500), *y, m_xpos, *y, x, y);
break;
}
case 2:
{
if (m_spaceAttachments)
*x = left + (nth + 1)*m_width/(no_arcs + 1);
else *x = m_xpos;
*y = bottom;
oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, *x, (double)(m_ypos+m_height+500), *x, m_ypos, x, y);
break;
}
case 3:
{
*x = left;
if (m_spaceAttachments)
*y = bottom + (nth + 1)*m_height/(no_arcs + 1);
else *y = m_ypos;
oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, (double)(m_xpos-m_width-500), *y, m_xpos, *y, x, y);
break;
}
default:
{
return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
}
}
return true;
}
else
{ *x = m_xpos; *y = m_ypos; return true; }
}
// Circle object
IMPLEMENT_DYNAMIC_CLASS(wxCircleShape, wxEllipseShape)
wxCircleShape::wxCircleShape(double diameter):wxEllipseShape(diameter, diameter)
{
SetMaintainAspectRatio(true);
}
void wxCircleShape::Copy(wxShape& copy)
{
wxEllipseShape::Copy(copy);
}
bool wxCircleShape::GetPerimeterPoint(double WXUNUSED(x1), double WXUNUSED(y1),
double x2, double y2,
double *x3, double *y3)
{
oglFindEndForCircle(m_width/2,
m_xpos, m_ypos, // Centre of circle
x2, y2, // Other end of line
x3, y3);
return true;
}
// Control points
double wxControlPoint::sm_controlPointDragStartX = 0.0;
double wxControlPoint::sm_controlPointDragStartY = 0.0;
double wxControlPoint::sm_controlPointDragStartWidth = 0.0;
double wxControlPoint::sm_controlPointDragStartHeight = 0.0;
double wxControlPoint::sm_controlPointDragEndWidth = 0.0;
double wxControlPoint::sm_controlPointDragEndHeight = 0.0;
double wxControlPoint::sm_controlPointDragPosX = 0.0;
double wxControlPoint::sm_controlPointDragPosY = 0.0;
IMPLEMENT_DYNAMIC_CLASS(wxControlPoint, wxRectangleShape)
wxControlPoint::wxControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size, double the_xoffset, double the_yoffset, int the_type):wxRectangleShape(size, size)
{
m_canvas = theCanvas;
m_shape = object;
m_xoffset = the_xoffset;
m_yoffset = the_yoffset;
m_type = the_type;
SetPen(g_oglBlackForegroundPen);
SetBrush(wxBLACK_BRUSH);
m_oldCursor = NULL;
m_visible = true;
m_eraseObject = true;
}
wxControlPoint::~wxControlPoint()
{
}
// Don't even attempt to draw any text - waste of time!
void wxControlPoint::OnDrawContents(wxDC& WXUNUSED(dc))
{
}
void wxControlPoint::OnDraw(wxDC& dc)
{
m_xpos = m_shape->GetX() + m_xoffset;
m_ypos = m_shape->GetY() + m_yoffset;
wxRectangleShape::OnDraw(dc);
}
void wxControlPoint::OnErase(wxDC& dc)
{
wxRectangleShape::OnErase(dc);
}
// Implement resizing of canvas object
void wxControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
{
m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment);
}
void wxControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment)
{
m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment);
}
void wxControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment)
{
m_shape->GetEventHandler()->OnSizingEndDragLeft(this, x, y, keys, attachment);
}
int wxControlPoint::GetNumberOfAttachments() const
{
return 1;
}
bool wxControlPoint::GetAttachmentPosition(int WXUNUSED(attachment), double *x, double *y,
int WXUNUSED(nth), int WXUNUSED(no_arcs), wxLineShape *WXUNUSED(line))
{
*x = m_xpos; *y = m_ypos;
return true;
}
// Control points ('handles') redirect control to the actual shape, to make it easier
// to override sizing behaviour.
void wxShape::OnSizingDragLeft(wxControlPoint* pt, bool WXUNUSED(draw), double x, double y, int keys, int WXUNUSED(attachment))
{
double bound_x;
double bound_y;
this->GetBoundingBoxMin(&bound_x, &bound_y);
wxClientDC dc(GetCanvas());
GetCanvas()->PrepareDC(dc);
dc.SetLogicalFunction(OGLRBLF);
wxPen dottedPen(*wxBLACK, 1, wxDOT);
dc.SetPen(dottedPen);
dc.SetBrush((* wxTRANSPARENT_BRUSH));
if (this->GetCentreResize())
{
// Maintain the same centre point.
double new_width = (double)(2.0*fabs(x - this->GetX()));
double new_height = (double)(2.0*fabs(y - this->GetY()));
// Constrain sizing according to what control point you're dragging
if (pt->m_type == CONTROL_POINT_HORIZONTAL)
{
if (GetMaintainAspectRatio())
{
new_height = bound_y*(new_width/bound_x);
}
else
new_height = bound_y;
}
else if (pt->m_type == CONTROL_POINT_VERTICAL)
{
if (GetMaintainAspectRatio())
{
new_width = bound_x*(new_height/bound_y);
}
else
new_width = bound_x;
}
else if (pt->m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT))
new_height = bound_y*(new_width/bound_x);
if (this->GetFixedWidth())
new_width = bound_x;
if (this->GetFixedHeight())
new_height = bound_y;
pt->sm_controlPointDragEndWidth = new_width;
pt->sm_controlPointDragEndHeight = new_height;
this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
new_width, new_height);
}
else
{
// Don't maintain the same centre point!
double newX1 = wxMin(pt->sm_controlPointDragStartX, x);
double newY1 = wxMin(pt->sm_controlPointDragStartY, y);
double newX2 = wxMax(pt->sm_controlPointDragStartX, x);
double newY2 = wxMax(pt->sm_controlPointDragStartY, y);
if (pt->m_type == CONTROL_POINT_HORIZONTAL)
{
newY1 = pt->sm_controlPointDragStartY;
newY2 = newY1 + pt->sm_controlPointDragStartHeight;
}
else if (pt->m_type == CONTROL_POINT_VERTICAL)
{
newX1 = pt->sm_controlPointDragStartX;
newX2 = newX1 + pt->sm_controlPointDragStartWidth;
}
else if (pt->m_type == CONTROL_POINT_DIAGONAL && ((keys & KEY_SHIFT) || GetMaintainAspectRatio()))
{
double newH = (double)((newX2 - newX1)*(pt->sm_controlPointDragStartHeight/pt->sm_controlPointDragStartWidth));
if (GetY() > pt->sm_controlPointDragStartY)
newY2 = (double)(newY1 + newH);
else
newY1 = (double)(newY2 - newH);
}
double newWidth = (double)(newX2 - newX1);
double newHeight = (double)(newY2 - newY1);
if (pt->m_type == CONTROL_POINT_VERTICAL && GetMaintainAspectRatio())
{
newWidth = bound_x * (newHeight/bound_y) ;
}
if (pt->m_type == CONTROL_POINT_HORIZONTAL && GetMaintainAspectRatio())
{
newHeight = bound_y * (newWidth/bound_x) ;
}
pt->sm_controlPointDragPosX = (double)(newX1 + (newWidth/2.0));
pt->sm_controlPointDragPosY = (double)(newY1 + (newHeight/2.0));
if (this->GetFixedWidth())
newWidth = bound_x;
if (this->GetFixedHeight())
newHeight = bound_y;
pt->sm_controlPointDragEndWidth = newWidth;
pt->sm_controlPointDragEndHeight = newHeight;
this->GetEventHandler()->OnDrawOutline(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY, newWidth, newHeight);
}
}
void wxShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys, int WXUNUSED(attachment))
{
m_canvas->CaptureMouse();
wxClientDC dc(GetCanvas());
GetCanvas()->PrepareDC(dc);
/*
if (pt->m_eraseObject)
this->Erase(dc);
*/
dc.SetLogicalFunction(OGLRBLF);
double bound_x;
double bound_y;
this->GetBoundingBoxMin(&bound_x, &bound_y);
this->GetEventHandler()->OnBeginSize(bound_x, bound_y);
// Choose the 'opposite corner' of the object as the stationary
// point in case this is non-centring resizing.
if (pt->GetX() < this->GetX())
pt->sm_controlPointDragStartX = (double)(this->GetX() + (bound_x/2.0));
else
pt->sm_controlPointDragStartX = (double)(this->GetX() - (bound_x/2.0));
if (pt->GetY() < this->GetY())
pt->sm_controlPointDragStartY = (double)(this->GetY() + (bound_y/2.0));
else
pt->sm_controlPointDragStartY = (double)(this->GetY() - (bound_y/2.0));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -