⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lines.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    wxExpr *y_expr = new wxExpr((double) point->y);    point_list->Append(x_expr);    point_list->Append(y_expr);    list->Append(point_list);    node = node->GetNext();  }  clause->AddAttributeValue(_T("controls"), list);  // Write arc arrows in new OGL format, if there are any.  // This is a list of lists. Each sublist comprises:  // (arrowType arrowEnd xOffset arrowSize)  if (m_arcArrows.GetCount() > 0)  {    wxExpr *arrow_list = new wxExpr(wxExprList);    node = m_arcArrows.GetFirst();    while (node)    {      wxArrowHead *head = (wxArrowHead *)node->GetData();      wxExpr *head_list = new wxExpr(wxExprList);      head_list->Append(new wxExpr((long)head->_GetType()));      head_list->Append(new wxExpr((long)head->GetArrowEnd()));      head_list->Append(new wxExpr(head->GetXOffset()));      head_list->Append(new wxExpr(head->GetArrowSize()));      head_list->Append(new wxExpr(wxExprString, head->GetName()));      head_list->Append(new wxExpr(head->GetId()));      // New members of wxArrowHead      head_list->Append(new wxExpr(head->GetYOffset()));      head_list->Append(new wxExpr(head->GetSpacing()));      arrow_list->Append(head_list);      node = node->GetNext();    }    clause->AddAttributeValue(_T("arrows"), arrow_list);  }}void wxLineShape::ReadAttributes(wxExpr *clause){  wxShape::ReadAttributes(clause);  int iVal = (int) m_isSpline;  clause->AssignAttributeValue(wxT("is_spline"), &iVal);  m_isSpline = (iVal != 0);  iVal = (int) m_maintainStraightLines;  clause->AssignAttributeValue(wxT("keep_lines_straight"), &iVal);  m_maintainStraightLines = (iVal != 0);  clause->AssignAttributeValue(wxT("align_start"), &m_alignmentStart);  clause->AssignAttributeValue(wxT("align_end"), &m_alignmentEnd);  // Compatibility: check for no regions.  if (m_regions.GetCount() == 0)  {    wxShapeRegion *newRegion = new wxShapeRegion;    newRegion->SetName(_T("Middle"));    newRegion->SetSize(150, 50);    m_regions.Append((wxObject *)newRegion);    if (m_text.GetCount() > 0)    {      newRegion->ClearText();      wxNode *node = m_text.GetFirst();      while (node)      {        wxShapeTextLine *textLine = (wxShapeTextLine *)node->GetData();        wxNode *next = node->GetNext();        newRegion->GetFormattedText().Append((wxObject *)textLine);        delete node;        node = next;      }    }    newRegion = new wxShapeRegion;    newRegion->SetName(wxT("Start"));    newRegion->SetSize(150, 50);    m_regions.Append((wxObject *)newRegion);    newRegion = new wxShapeRegion;    newRegion->SetName(wxT("End"));    newRegion->SetSize(150, 50);    m_regions.Append((wxObject *)newRegion);  }  m_attachmentTo = 0;  m_attachmentFrom = 0;  clause->AssignAttributeValue(wxT("attachment_to"), &m_attachmentTo);  clause->AssignAttributeValue(wxT("attachment_from"), &m_attachmentFrom);  wxExpr *line_list = NULL;  // When image is created, there are default control points. Override  // them if there are some in the file.  clause->AssignAttributeValue(wxT("controls"), &line_list);  if (line_list)  {    // Read a list of lists for the spline controls    if (m_lineControlPoints)    {      ClearPointList(*m_lineControlPoints);    }    else      m_lineControlPoints = new wxList;    wxExpr *node = line_list->value.first;    while (node)    {      wxExpr *xexpr = node->value.first;      double x = xexpr->RealValue();      wxExpr *yexpr = xexpr->next;      double y = yexpr->RealValue();      wxRealPoint *point = new wxRealPoint(x, y);      m_lineControlPoints->Append((wxObject*) point);      node = node->next;    }  }  // Read arrow list, for new OGL code  wxExpr *arrow_list = NULL;  clause->AssignAttributeValue(wxT("arrows"), &arrow_list);  if (arrow_list)  {    wxExpr *node = arrow_list->value.first;    while (node)    {      WXTYPE arrowType = ARROW_ARROW;      int arrowEnd = 0;      double xOffset = 0.0;      double arrowSize = 0.0;      wxString arrowName;      long arrowId = -1;      wxExpr *type_expr = node->Nth(0);      wxExpr *end_expr = node->Nth(1);      wxExpr *dist_expr = node->Nth(2);      wxExpr *size_expr = node->Nth(3);      wxExpr *name_expr = node->Nth(4);      wxExpr *id_expr = node->Nth(5);      // New members of wxArrowHead      wxExpr *yOffsetExpr = node->Nth(6);      wxExpr *spacingExpr = node->Nth(7);      if (type_expr)          arrowType = (WXTYPE)type_expr->IntegerValue();      if (end_expr)        arrowEnd = (int)end_expr->IntegerValue();      if (dist_expr)        xOffset = dist_expr->RealValue();      if (size_expr)        arrowSize = size_expr->RealValue();      if (name_expr)        arrowName = name_expr->StringValue();      if (id_expr)        arrowId = id_expr->IntegerValue();      if (arrowId == -1)        arrowId = wxNewId();      else        wxRegisterId(arrowId);      wxArrowHead *arrowHead = AddArrow(arrowType, arrowEnd, arrowSize, xOffset, arrowName, NULL, arrowId);      if (yOffsetExpr)        arrowHead->SetYOffset(yOffsetExpr->RealValue());      if (spacingExpr)        arrowHead->SetSpacing(spacingExpr->RealValue());      node = node->next;    }  }}#endifvoid wxLineShape::Copy(wxShape& copy){  wxShape::Copy(copy);  wxASSERT( copy.IsKindOf(CLASSINFO(wxLineShape)) );  wxLineShape& lineCopy = (wxLineShape&) copy;  lineCopy.m_to = m_to;  lineCopy.m_from = m_from;  lineCopy.m_attachmentTo = m_attachmentTo;  lineCopy.m_attachmentFrom = m_attachmentFrom;  lineCopy.m_isSpline = m_isSpline;  lineCopy.m_alignmentStart = m_alignmentStart;  lineCopy.m_alignmentEnd = m_alignmentEnd;  lineCopy.m_maintainStraightLines = m_maintainStraightLines;  lineCopy.m_lineOrientations.Clear();  wxNode *node = m_lineOrientations.GetFirst();  while (node)  {    lineCopy.m_lineOrientations.Append(node->GetData());    node = node->GetNext();  }  if (lineCopy.m_lineControlPoints)  {    ClearPointList(*lineCopy.m_lineControlPoints);    delete lineCopy.m_lineControlPoints;  }  lineCopy.m_lineControlPoints = new wxList;  node = m_lineControlPoints->GetFirst();  while (node)  {    wxRealPoint *point = (wxRealPoint *)node->GetData();    wxRealPoint *new_point = new wxRealPoint(point->x, point->y);    lineCopy.m_lineControlPoints->Append((wxObject*) new_point);    node = node->GetNext();  }  // Copy arrows  lineCopy.ClearArrowsAtPosition(-1);  node = m_arcArrows.GetFirst();  while (node)  {    wxArrowHead *arrow = (wxArrowHead *)node->GetData();    lineCopy.m_arcArrows.Append(new wxArrowHead(*arrow));    node = node->GetNext();  }}// Override select, to create/delete temporary label-moving objectsvoid wxLineShape::Select(bool select, wxDC* dc){  wxShape::Select(select, dc);  if (select)  {    for (int i = 0; i < 3; i++)    {      wxNode *node = m_regions.Item(i);      if (node)      {        wxShapeRegion *region = (wxShapeRegion *)node->GetData();        if (region->m_formattedText.GetCount() > 0)        {          double w, h, x, y, xx, yy;          region->GetSize(&w, &h);          region->GetPosition(&x, &y);          GetLabelPosition(i, &xx, &yy);          if (m_labelObjects[i])          {            m_labelObjects[i]->Select(false);            m_labelObjects[i]->RemoveFromCanvas(m_canvas);            delete m_labelObjects[i];          }          m_labelObjects[i] = OnCreateLabelShape(this, region, w, h);          m_labelObjects[i]->AddToCanvas(m_canvas);          m_labelObjects[i]->Show(true);          if (dc)            m_labelObjects[i]->Move(*dc, (double)(x + xx), (double)(y + yy));          m_labelObjects[i]->Select(true, dc);        }      }    }  }  else  {    for (int i = 0; i < 3; i++)    {      if (m_labelObjects[i])      {        m_labelObjects[i]->Select(false, dc);        m_labelObjects[i]->Erase(*dc);        m_labelObjects[i]->RemoveFromCanvas(m_canvas);        delete m_labelObjects[i];        m_labelObjects[i] = NULL;      }    }  }}/* * Line control point * */IMPLEMENT_DYNAMIC_CLASS(wxLineControlPoint, wxControlPoint)wxLineControlPoint::wxLineControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size, double x, double y, int the_type):  wxControlPoint(theCanvas, object, size, x, y, the_type){  m_xpos = x;  m_ypos = y;  m_type = the_type;  m_point = NULL;}wxLineControlPoint::~wxLineControlPoint(){}void wxLineControlPoint::OnDraw(wxDC& dc){  wxRectangleShape::OnDraw(dc);}// Implement movement of Line pointvoid wxLineControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment){    m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment);}void wxLineControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment){    m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment);}void wxLineControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment){    m_shape->GetEventHandler()->OnSizingEndDragLeft(this, x, y, keys, attachment);}// Control points ('handles') redirect control to the actual shape, to make it easier// to override sizing behaviour.void wxLineShape::OnSizingDragLeft(wxControlPoint* pt, bool WXUNUSED(draw), double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment)){  wxLineControlPoint* lpt = (wxLineControlPoint*) pt;  wxClientDC dc(GetCanvas());  GetCanvas()->PrepareDC(dc);  dc.SetLogicalFunction(OGLRBLF);  wxPen dottedPen(*wxBLACK, 1, wxDOT);  dc.SetPen(dottedPen);  dc.SetBrush((* wxTRANSPARENT_BRUSH));  if (lpt->m_type == CONTROL_POINT_LINE)  {    m_canvas->Snap(&x, &y);    lpt->SetX(x); lpt->SetY(y);    lpt->m_point->x = x; lpt->m_point->y = y;    wxLineShape *lineShape = (wxLineShape *)this;    const wxPen *old_pen = lineShape->GetPen();    const wxBrush *old_brush = lineShape->GetBrush();    wxPen dottedPen(*wxBLACK, 1, wxDOT);    lineShape->SetPen(& dottedPen);    lineShape->SetBrush(wxTRANSPARENT_BRUSH);    lineShape->GetEventHandler()->OnMoveLink(dc, false);    lineShape->SetPen(old_pen);    lineShape->SetBrush(old_brush);  }  if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO)  {//    lpt->SetX(x); lpt->SetY(y);  }}void wxLineShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment)){  wxLineControlPoint* lpt = (wxLineControlPoint*) pt;  wxClientDC dc(GetCanvas());  GetCanvas()->PrepareDC(dc);  wxLineShape *lineShape = (wxLineShape *)this;  if (lpt->m_type == CONTROL_POINT_LINE)  {    lpt->m_originalPos = * (lpt->m_point);    m_canvas->Snap(&x, &y);    this->Erase(dc);    // Redraw start and end objects because we've left holes    // when erasing the line    lineShape->GetFrom()->OnDraw(dc);    lineShape->GetFrom()->OnDrawContents(dc);    lineShape->GetTo()->OnDraw(dc);    lineShape->GetTo()->OnDrawContents(dc);    this->SetDisableLabel(true);    dc.SetLogicalFunction(OGLRBLF);    lpt->m_xpos = x; lpt->m_ypos = y;    lpt->m_point->x = x; lpt->m_point->y = y;    const wxPen *old_pen = lineShape->GetPen();    const wxBrush *old_brush = lineShape->GetBrush();    wxPen dottedPen(*wxBLACK, 1, wxDOT);    lineShape->SetPen(& dottedPen);    lineShape->SetBrush(wxTRANSPARENT_BRUSH);    lineShape->GetEventHandler()->OnMoveLink(dc, false);    lineShape->SetPen(old_pen);    lineShape->SetBrush(old_brush);  }  if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO)  {    m_canvas->SetCursor(wxCursor(wxCURSOR_BULLSEYE));    lpt->m_oldCursor = wxSTANDARD_CURSOR;  }}void wxLineShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment)){  wxLineControlPoint* lpt = (wxLineControlPoint*) pt;  wxClientDC dc(GetCanvas());  GetCanvas()->PrepareDC(dc);  this->SetDisableLabel(false);  wxLineShape *lineShape = (wxLineShape *)this;  if (lpt->m_type == CONTROL_POINT_LINE)  {    m_canvas->Snap(&x, &y);    wxRealPoint pt = wxRealPoint(x, y);    // Move the control point back to where it was;    // MoveControlPoint will move it to the new position    // if it decides it wants. We only moved the position    // during user feedback so we could redraw the line    // as it changed shape.    lpt->m_xpos = lpt->m_originalPos.x; lpt->m_ypos = lpt->m_originalPos.y;    lpt->m_point->x = lpt->m_originalPos.x; lpt->m_point->y = lpt->m_originalPos.y;    OnMoveMiddleControlPoint(dc, lpt, pt);  }  if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM)  {    if (lpt->m_oldCursor)      m_canvas->SetCursor(* lpt->m_oldCursor);//    this->Erase(dc);//    lpt->m_xpos = x; lpt->m_ypos = y;    if (lineShape->GetFrom())    {      lineShape->GetFrom()->MoveLineToNewAttachment(dc, lineShape, x, y);    }  }  if (lpt->m_type == CONTROL_POINT_ENDPOINT_TO)  {    if (lpt->m_oldCursor)      m_canvas->SetCursor(* lpt->m_oldCursor);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -