📄 view.cpp
字号:
newShape->SetX(x2); break; } case DIAGRAM_TOOLBAR_ALIGNB: { double y2 = (double)(y + (height/2.0) - (height1/2.0)); newShape->SetY(y2); break; } case DIAGRAM_TOOLBAR_ALIGNT: { double y2 = (double)(y - (height/2.0) + (height1/2.0)); newShape->SetY(y2); break; } case DIAGRAM_TOOLBAR_ALIGN_HORIZ: { newShape->SetX(x); break; } case DIAGRAM_TOOLBAR_ALIGN_VERT: { newShape->SetY(y); break; } case DIAGRAM_TOOLBAR_COPY_SIZE: { newShape->SetSize(width, height); break; } } csCommandState* state = new csCommandState(ID_CS_ALIGN, newShape, shape); cmd->AddState(state); } node = node->GetNext(); } doc->GetCommandProcessor()->Submit(cmd);}void csDiagramView::OnAlignUpdate(wxUpdateUIEvent& event){ // This is an approximation, since there may be lines // amongst the selections. event.Enable( (m_selections.GetCount() > 1) ) ;}void csDiagramView::OnNewLinePoint(wxCommandEvent& WXUNUSED(event)){ csDiagramDocument *doc = (csDiagramDocument *)GetDocument(); csDiagramCommand* cmd = new csDiagramCommand(_T("New line point"), doc); wxObjectList::compatibility_iterator node = m_selections.GetFirst(); while (node) { wxShape* shape = (wxShape*) node->GetData(); if (shape->IsKindOf(CLASSINFO(wxLineShape))) { wxShape* newShape = shape->CreateNewCopy(); ((wxLineShape*)newShape)->InsertLineControlPoint(NULL); csCommandState* state = new csCommandState(ID_CS_NEW_POINT, newShape, shape); cmd->AddState(state); } node = node->GetNext(); } doc->GetCommandProcessor()->Submit(cmd);}void csDiagramView::OnCutLinePoint(wxCommandEvent& WXUNUSED(event)){ csDiagramDocument *doc = (csDiagramDocument *)GetDocument(); csDiagramCommand* cmd = new csDiagramCommand(_T("Cut line point"), doc); wxObjectList::compatibility_iterator node = m_selections.GetFirst(); while (node) { wxShape* shape = (wxShape*) node->GetData(); if (shape->IsKindOf(CLASSINFO(wxLineShape))) { wxShape* newShape = shape->CreateNewCopy(); ((wxLineShape*)newShape)->DeleteLineControlPoint(); csCommandState* state = new csCommandState(ID_CS_CUT_POINT, newShape, shape); cmd->AddState(state); } node = node->GetNext(); } doc->GetCommandProcessor()->Submit(cmd);}void csDiagramView::OnStraightenLines(wxCommandEvent& WXUNUSED(event)){ csDiagramDocument *doc = (csDiagramDocument *)GetDocument(); csDiagramCommand* cmd = new csDiagramCommand(_T("Straighten lines"), doc); wxObjectList::compatibility_iterator node = m_selections.GetFirst(); while (node) { wxShape* shape = (wxShape*) node->GetData(); if (shape->IsKindOf(CLASSINFO(wxLineShape))) { wxShape* newShape = shape->CreateNewCopy(); ((wxLineShape*)newShape)->Straighten(); csCommandState* state = new csCommandState(ID_CS_STRAIGHTEN, newShape, shape); cmd->AddState(state); } node = node->GetNext(); } doc->GetCommandProcessor()->Submit(cmd);}void csDiagramView::OnNewLinePointUpdate(wxUpdateUIEvent& event){ wxList selections; FindSelectedShapes(selections, CLASSINFO(wxLineShape)); event.Enable( (selections.GetCount() > 0) );}void csDiagramView::OnCutLinePointUpdate(wxUpdateUIEvent& event){ wxList selections; FindSelectedShapes(selections, CLASSINFO(wxLineShape)); event.Enable( (selections.GetCount() > 0) );}void csDiagramView::OnStraightenLinesUpdate(wxUpdateUIEvent& event){ wxList selections; FindSelectedShapes(selections, CLASSINFO(wxLineShape)); event.Enable( (selections.GetCount() > 0) );}/* * Window implementations */IMPLEMENT_CLASS(csCanvas, wxShapeCanvas)BEGIN_EVENT_TABLE(csCanvas, wxShapeCanvas) EVT_MOUSE_EVENTS(csCanvas::OnMouseEvent) EVT_PAINT(csCanvas::OnPaint)END_EVENT_TABLE()// Define a constructor for my canvascsCanvas::csCanvas(csDiagramView *v, wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style): wxShapeCanvas(parent, id, pos, size, style){ m_view = v;}csCanvas::~csCanvas(void){}void csCanvas::DrawOutline(wxDC& dc, double x1, double y1, double x2, double y2){ wxPen dottedPen(*wxBLACK, 1, wxDOT); dc.SetPen(dottedPen); dc.SetBrush(* wxTRANSPARENT_BRUSH); dc.DrawRectangle((long) x1, (long) y1, (long) (x2 - x1), (long) (y2 - y1));}void csCanvas::OnLeftClick(double x, double y, int WXUNUSED(keys)){ csEditorToolPalette *palette = wxGetApp().GetDiagramPalette(); if (palette->GetSelection() == PALETTE_ARROW) { GetView()->SelectAll(false); wxClientDC dc(this); PrepareDC(dc); Redraw(dc); return; } if (palette->GetSelection() == PALETTE_TEXT_TOOL) { wxString newLabel;#if wxUSE_WX_RESOURCES // Ask for a label and create a new free-floating text region csLabelEditingDialog* dialog = new csLabelEditingDialog(GetParent()); dialog->SetShapeLabel( wxEmptyString ); dialog->SetTitle(_T("New text box")); if (dialog->ShowModal() == wxID_CANCEL) { dialog->Destroy(); return; } newLabel = dialog->GetShapeLabel(); dialog->Destroy();#endif // wxUSE_WX_RESOURCES wxShape* shape = new csTextBoxShape; shape->AssignNewIds(); shape->SetEventHandler(new csEvtHandler(shape, shape, newLabel)); wxComboBox* comboBox = wxGetApp().GetPointSizeComboBox(); wxString str(comboBox->GetValue()); long pointSize; str.ToLong( &pointSize ); wxFont* newFont = wxTheFontList->FindOrCreateFont(pointSize, shape->GetFont()->GetFamily(), shape->GetFont()->GetStyle(), shape->GetFont()->GetWeight(), shape->GetFont()->GetUnderlined(), shape->GetFont()->GetFaceName()); shape->SetFont(newFont); shape->SetX(x); shape->SetY(y); csDiagramCommand* cmd = new csDiagramCommand(_T("Text box"), (csDiagramDocument *)GetView()->GetDocument(), new csCommandState(ID_CS_ADD_SHAPE, shape, NULL)); GetView()->GetDocument()->GetCommandProcessor()->Submit(cmd); palette->SetSelection(PALETTE_ARROW); return; } csSymbol* symbol = wxGetApp().GetSymbolDatabase()->FindSymbol(palette->GetSelection()); if (symbol) { wxShape* theShape = symbol->GetShape()->CreateNewCopy(); wxComboBox* comboBox = wxGetApp().GetPointSizeComboBox(); wxString str(comboBox->GetValue()); long pointSize; str.ToLong( &pointSize ); wxFont* newFont = wxTheFontList->FindOrCreateFont(pointSize, symbol->GetShape()->GetFont()->GetFamily(), symbol->GetShape()->GetFont()->GetStyle(), symbol->GetShape()->GetFont()->GetWeight(), symbol->GetShape()->GetFont()->GetUnderlined(), symbol->GetShape()->GetFont()->GetFaceName()); theShape->SetFont(newFont); theShape->AssignNewIds(); theShape->SetX(x); theShape->SetY(y); csDiagramCommand* cmd = new csDiagramCommand(symbol->GetName(), (csDiagramDocument *)GetView()->GetDocument(), new csCommandState(ID_CS_ADD_SHAPE, theShape, NULL)); GetView()->GetDocument()->GetCommandProcessor()->Submit(cmd); palette->SetSelection(PALETTE_ARROW); }}void csCanvas::OnRightClick(double WXUNUSED(x), double WXUNUSED(y), int WXUNUSED(keys)){}// Initial pointstatic double sg_initialX, sg_initialY;void csCanvas::OnDragLeft(bool WXUNUSED(draw), double x, double y, int WXUNUSED(keys)){ wxClientDC dc(this); PrepareDC(dc); dc.SetLogicalFunction(OGLRBLF); DrawOutline(dc, sg_initialX, sg_initialY, x, y);}void csCanvas::OnBeginDragLeft(double x, double y, int WXUNUSED(keys)){ sg_initialX = x; sg_initialY = y; wxClientDC dc(this); PrepareDC(dc); dc.SetLogicalFunction(OGLRBLF); DrawOutline(dc, sg_initialX, sg_initialY, x, y); CaptureMouse();}void csCanvas::OnEndDragLeft(double x, double y, int WXUNUSED(keys)){ ReleaseMouse(); wxClientDC dc(this); PrepareDC(dc); // Select all images within the rectangle float min_x, max_x, min_y, max_y; min_x = wxMin(x, sg_initialX); max_x = wxMax(x, sg_initialX); min_y = wxMin(y, sg_initialY); max_y = wxMax(y, sg_initialY); wxObjectList::compatibility_iterator node = GetDiagram()->GetShapeList()->GetFirst(); while (node) { wxShape *shape = (wxShape *)node->GetData(); if (shape->GetParent() == NULL && !shape->IsKindOf(CLASSINFO(wxControlPoint))) { float image_x = shape->GetX(); float image_y = shape->GetY(); if (image_x >= min_x && image_x <= max_x && image_y >= min_y && image_y <= max_y) { shape->Select(true, &dc); GetView()->SelectShape(shape, true); } } node = node->GetNext(); }}void csCanvas::OnDragRight(bool WXUNUSED(draw), double WXUNUSED(x), double WXUNUSED(y), int WXUNUSED(keys)){}void csCanvas::OnBeginDragRight(double WXUNUSED(x), double WXUNUSED(y), int WXUNUSED(keys)){}void csCanvas::OnEndDragRight(double WXUNUSED(x), double WXUNUSED(y), int WXUNUSED(keys)){}void csCanvas::OnMouseEvent(wxMouseEvent& event){ wxShapeCanvas::OnMouseEvent(event);}void csCanvas::OnPaint(wxPaintEvent& event){// if (GetDiagram()) wxShapeCanvas::OnPaint(event);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -