📄 basic.cpp
字号:
void wxShape::OnBeginDragRight(double x, double y, int keys, int attachment)
{
if ((m_sensitivity & OP_DRAG_RIGHT) != OP_DRAG_RIGHT)
{
attachment = 0;
double dist;
if (m_parent)
{
m_parent->HitTest(x, y, &attachment, &dist);
m_parent->GetEventHandler()->OnBeginDragRight(x, y, keys, attachment);
}
return;
}
}
void wxShape::OnEndDragRight(double x, double y, int keys, int attachment)
{
if ((m_sensitivity & OP_DRAG_RIGHT) != OP_DRAG_RIGHT)
{
attachment = 0;
double dist;
if (m_parent)
{
m_parent->HitTest(x, y, &attachment, &dist);
m_parent->GetEventHandler()->OnEndDragRight(x, y, keys, attachment);
}
return;
}
}
void wxShape::OnDrawOutline(wxDC& dc, double x, double y, double w, double h)
{
double top_left_x = (double)(x - w/2.0);
double top_left_y = (double)(y - h/2.0);
double top_right_x = (double)(top_left_x + w);
double top_right_y = (double)top_left_y;
double bottom_left_x = (double)top_left_x;
double bottom_left_y = (double)(top_left_y + h);
double bottom_right_x = (double)top_right_x;
double bottom_right_y = (double)bottom_left_y;
wxPoint points[5];
points[0].x = WXROUND(top_left_x); points[0].y = WXROUND(top_left_y);
points[1].x = WXROUND(top_right_x); points[1].y = WXROUND(top_right_y);
points[2].x = WXROUND(bottom_right_x); points[2].y = WXROUND(bottom_right_y);
points[3].x = WXROUND(bottom_left_x); points[3].y = WXROUND(bottom_left_y);
points[4].x = WXROUND(top_left_x); points[4].y = WXROUND(top_left_y);
dc.DrawLines(5, points);
}
void wxShape::Attach(wxShapeCanvas *can)
{
m_canvas = can;
}
void wxShape::Detach()
{
m_canvas = NULL;
}
void wxShape::Move(wxDC& dc, double x, double y, bool display)
{
double old_x = m_xpos;
double old_y = m_ypos;
if (!GetEventHandler()->OnMovePre(dc, x, y, old_x, old_y, display))
{
// m_xpos = old_x;
// m_ypos = old_y;
return;
}
m_xpos = x; m_ypos = y;
ResetControlPoints();
if (display)
Draw(dc);
MoveLinks(dc);
GetEventHandler()->OnMovePost(dc, x, y, old_x, old_y, display);
}
void wxShape::MoveLinks(wxDC& dc)
{
GetEventHandler()->OnMoveLinks(dc);
}
void wxShape::Draw(wxDC& dc)
{
if (m_visible)
{
GetEventHandler()->OnDraw(dc);
GetEventHandler()->OnDrawContents(dc);
GetEventHandler()->OnDrawControlPoints(dc);
GetEventHandler()->OnDrawBranches(dc);
}
}
void wxShape::Flash()
{
if (GetCanvas())
{
wxClientDC dc(GetCanvas());
GetCanvas()->PrepareDC(dc);
dc.SetLogicalFunction(OGLRBLF);
Draw(dc);
dc.SetLogicalFunction(wxCOPY);
Draw(dc);
}
}
void wxShape::Show(bool show)
{
m_visible = show;
wxNode *node = m_children.GetFirst();
while (node)
{
wxShape *image = (wxShape *)node->GetData();
image->Show(show);
node = node->GetNext();
}
}
void wxShape::Erase(wxDC& dc)
{
GetEventHandler()->OnErase(dc);
GetEventHandler()->OnEraseControlPoints(dc);
GetEventHandler()->OnDrawBranches(dc, true);
}
void wxShape::EraseContents(wxDC& dc)
{
GetEventHandler()->OnEraseContents(dc);
}
void wxShape::AddText(const wxString& string)
{
wxNode *node = m_regions.GetFirst();
if (!node)
return;
wxShapeRegion *region = (wxShapeRegion *)node->GetData();
region->ClearText();
wxShapeTextLine *new_line =
new wxShapeTextLine(0.0, 0.0, string);
region->GetFormattedText().Append(new_line);
m_formatted = false;
}
void wxShape::SetSize(double x, double y, bool WXUNUSED(recursive))
{
SetAttachmentSize(x, y);
SetDefaultRegionSize();
}
void wxShape::SetAttachmentSize(double w, double h)
{
double scaleX;
double scaleY;
double width, height;
GetBoundingBoxMin(&width, &height);
if (width == 0.0)
scaleX = 1.0;
else scaleX = w/width;
if (height == 0.0)
scaleY = 1.0;
else scaleY = h/height;
wxNode *node = m_attachmentPoints.GetFirst();
while (node)
{
wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData();
point->m_x = (double)(point->m_x * scaleX);
point->m_y = (double)(point->m_y * scaleY);
node = node->GetNext();
}
}
// Add line FROM this object
void wxShape::AddLine(wxLineShape *line, wxShape *other,
int attachFrom, int attachTo,
// The line ordering
int positionFrom, int positionTo)
{
if (positionFrom == -1)
{
if (!m_lines.Member(line))
m_lines.Append(line);
}
else
{
// Don't preserve old ordering if we have new ordering instructions
m_lines.DeleteObject(line);
if (positionFrom < (int) m_lines.GetCount())
{
wxNode* node = m_lines.Item(positionFrom);
m_lines.Insert(node, line);
}
else
m_lines.Append(line);
}
if (positionTo == -1)
{
if (!other->m_lines.Member(line))
other->m_lines.Append(line);
}
else
{
// Don't preserve old ordering if we have new ordering instructions
other->m_lines.DeleteObject(line);
if (positionTo < (int) other->m_lines.GetCount())
{
wxNode* node = other->m_lines.Item(positionTo);
other->m_lines.Insert(node, line);
}
else
other->m_lines.Append(line);
}
#if 0
// Wrong: doesn't preserve ordering of shape already linked
m_lines.DeleteObject(line);
other->m_lines.DeleteObject(line);
if (positionFrom == -1)
m_lines.Append(line);
else
{
if (positionFrom < m_lines.GetCount())
{
wxNode* node = m_lines.Item(positionFrom);
m_lines.Insert(node, line);
}
else
m_lines.Append(line);
}
if (positionTo == -1)
other->m_lines.Append(line);
else
{
if (positionTo < other->m_lines.GetCount())
{
wxNode* node = other->m_lines.Item(positionTo);
other->m_lines.Insert(node, line);
}
else
other->m_lines.Append(line);
}
#endif
line->SetFrom(this);
line->SetTo(other);
line->SetAttachments(attachFrom, attachTo);
}
void wxShape::RemoveLine(wxLineShape *line)
{
if (line->GetFrom() == this)
line->GetTo()->m_lines.DeleteObject(line);
else
line->GetFrom()->m_lines.DeleteObject(line);
m_lines.DeleteObject(line);
}
#if wxUSE_PROLOGIO
void wxShape::WriteAttributes(wxExpr *clause)
{
clause->AddAttributeValueString(_T("type"), GetClassInfo()->GetClassName());
clause->AddAttributeValue(_T("id"), m_id);
if (m_pen)
{
int penWidth = m_pen->GetWidth();
int penStyle = m_pen->GetStyle();
if (penWidth != 1)
clause->AddAttributeValue(_T("pen_width"), (long)penWidth);
if (penStyle != wxSOLID)
clause->AddAttributeValue(_T("pen_style"), (long)penStyle);
wxString penColour = wxTheColourDatabase->FindName(m_pen->GetColour());
if (penColour == wxEmptyString)
{
wxString hex(oglColourToHex(m_pen->GetColour()));
hex = wxString(_T("#")) + hex;
clause->AddAttributeValueString(_T("pen_colour"), hex);
}
else if (penColour != _T("BLACK"))
clause->AddAttributeValueString(_T("pen_colour"), penColour);
}
if (m_brush)
{
wxString brushColour = wxTheColourDatabase->FindName(m_brush->GetColour());
if (brushColour == wxEmptyString)
{
wxString hex(oglColourToHex(m_brush->GetColour()));
hex = wxString(_T("#")) + hex;
clause->AddAttributeValueString(_T("brush_colour"), hex);
}
else if (brushColour != _T("WHITE"))
clause->AddAttributeValueString(_T("brush_colour"), brushColour);
if (m_brush->GetStyle() != wxSOLID)
clause->AddAttributeValue(_T("brush_style"), (long)m_brush->GetStyle());
}
// Output line ids
int n_lines = m_lines.GetCount();
if (n_lines > 0)
{
wxExpr *list = new wxExpr(wxExprList);
wxNode *node = m_lines.GetFirst();
while (node)
{
wxShape *line = (wxShape *)node->GetData();
wxExpr *id_expr = new wxExpr(line->GetId());
list->Append(id_expr);
node = node->GetNext();
}
clause->AddAttributeValue(_T("arcs"), list);
}
// Miscellaneous members
if (m_attachmentMode != 0)
clause->AddAttributeValue(_T("use_attachments"), (long)m_attachmentMode);
if (m_sensitivity != OP_ALL)
clause->AddAttributeValue(_T("sensitivity"), (long)m_sensitivity);
if (!m_spaceAttachments)
clause->AddAttributeValue(_T("space_attachments"), (long)m_spaceAttachments);
if (m_fixedWidth)
clause->AddAttributeValue(_T("fixed_width"), (long)m_fixedWidth);
if (m_fixedHeight)
clause->AddAttributeValue(_T("fixed_height"), (long)m_fixedHeight);
if (m_shadowMode != SHADOW_NONE)
clause->AddAttributeValue(_T("shadow_mode"), (long)m_shadowMode);
if (m_centreResize != true)
clause->AddAttributeValue(_T("centre_resize"), (long)0);
clause->AddAttributeValue(_T("maintain_aspect_ratio"), (long) m_maintainAspectRatio);
if (m_highlighted != false)
clause->AddAttributeValue(_T("hilite"), (long)m_highlighted);
if (m_parent) // For composite objects
clause->AddAttributeValue(_T("parent"), (long)m_parent->GetId());
if (m_rotation != 0.0)
clause->AddAttributeValue(_T("rotation"), m_rotation);
if (!this->IsKindOf(CLASSINFO(wxLineShape)))
{
clause->AddAttributeValue(_T("neck_length"), (long) m_branchNeckLength);
clause->AddAttributeValue(_T("stem_length"), (long) m_branchStemLength);
clause->AddAttributeValue(_T("branch_spacing"), (long) m_branchSpacing);
clause->AddAttributeValue(_T("branch_style"), (long) m_branchStyle);
}
// Write user-defined attachment points, if any
if (m_attachmentPoints.GetCount() > 0)
{
wxExpr *attachmentList = new wxExpr(wxExprList);
wxNode *node = m_attachmentPoints.GetFirst();
while (node)
{
wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData();
wxExpr *pointExpr = new wxExpr(wxExprList);
pointExpr->Append(new wxExpr((long)point->m_id));
pointExpr->Append(new wxExpr(point->m_x));
pointExpr->Append(new wxExpr(point->m_y));
attachmentList->Append(pointExpr);
node = node->GetNext();
}
clause->AddAttributeValue(_T("user_attachments"), attachmentList);
}
// Write text regions
WriteRegions(clause);
}
void wxShape::WriteRegions(wxExpr *clause)
{
// Output regions as region1 = (...), region2 = (...), etc
// and formatted text as text1 = (...), text2 = (...) etc.
int regionNo = 1;
wxChar regionNameBuf[20];
wxChar textNameBuf[20];
wxNode *node = m_regions.GetFirst();
while (node)
{
wxShapeRegion *region = (wxShapeRegion *)node->GetData();
wxSprintf(regionNameBuf, _T("region%d"), regionNo);
wxSprintf(textNameBuf, _T("text%d"), regionNo);
// Original text and region attributes:
// region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
// formatMode fontSize fontFamily fontStyle fontWeight textColour)
wxExpr *regionExpr = new wxExpr(wxExprList);
regionExpr->Append(new wxExpr(wxExprString, region->m_regionName));
regionExpr->Append(new wxExpr(wxExprString, region->m_regionText));
regionExpr->Append(new wxExpr(region->m_x));
regionExpr->Append(new wxExpr(region->m_y));
regionExpr->Append(new wxExpr(region->GetWidth()));
regionExpr->Append(new wxExpr(region->GetHeight()));
regionExpr->Append(new wxExpr(region->m_minWidth));
regionExpr->Append(new wxExpr(region->m_minHeight));
regionExpr->Append(new wxExpr(region->m_regionProportionX));
regionExpr->Append(new wxExpr(region->m_regionProportionY));
regionExpr->Append(new wxExpr((long)region->m_formatMode));
regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetPointSize() : 10)));
regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetFamily() : wxDEFAULT)));
regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetStyle() : wxDEFAULT)));
regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetWeight() : wxNORMAL)));
regionExpr->Append(new wxExpr(wxExprString, region->m_textColour));
// New members for pen colour/style
regionExpr->Append(new wxExpr(wxExprString, region->m_penColour));
regionExpr->Append(new wxExpr((long)region->m_penStyle));
// Formatted text:
// text1 = ((x y string) (x y string) ...)
wxExpr *textExpr = new wxExpr(wxExprList);
wxNode *textNode = region->m_formattedText.GetFirst();
while (textNode)
{
wxShapeTextLine *line = (wxShapeTextLine *)textNode->GetData();
wxExpr *list2 = new wxExpr(wxExprList);
list2->Append(new wxExpr(line->GetX()));
list2->Append(new wxExpr(line->GetY()));
list2->Append(new wxExpr(wxExprString, line->GetText()));
textExpr->Append(list2);
textNode = textNode->GetNext();
}
// Now add both attributes to the clause
clause->AddAttributeValue(regionNameBuf, regionExpr);
clause->AddAttributeValue(textNameBuf, textExpr);
node = node->GetNext();
regionNo ++;
}
}
void wxShape::ReadAttributes(wxExpr *clause)
{
clause->GetAttributeValue(_T("id"), m_id);
wxRegisterId(m_id);
clause->GetAttributeValue(_T("x"), m_xpos);
clause->GetAttributeValue(_T("y"), m_ypos);
// Input text strings (FOR COMPATIBILITY WITH OLD FILES ONLY. SEE REGION CODE BELOW.)
ClearText();
wxExpr *strings = clause->AttributeValue(_T("text"));
if (strings && strings->Type() == wxExprList)
{
m_formatted = true; // Assume text is formatted unless we prove otherwise
wxExpr *node = strings->value.first;
while (node)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -