📄 composit.cpp
字号:
return true;}bool wxDivisionShape::AdjustRight(double right, bool test){ double x1 = (double)(GetX() - (GetWidth()/2.0)); if (right <= x1) return false; if (test) return true; double newW = right - x1; double newX = (double)(x1 + newW/2.0); SetSize(newW, GetHeight()); wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); Move(dc, newX, GetY()); return true;}bool wxDivisionShape::AdjustBottom(double bottom, bool test){ double y1 = (double)(GetY() - (GetHeight()/2.0)); if (bottom <= y1) return false; if (test) return true; double newH = bottom - y1; double newY = (double)(y1 + newH/2.0); SetSize(GetWidth(), newH); wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); Move(dc, GetX(), newY); return true;}wxDivisionControlPoint::wxDivisionControlPoint(wxShapeCanvas *the_canvas, wxShape *object, double size, double the_xoffset, double the_yoffset, int the_type): wxControlPoint(the_canvas, object, size, the_xoffset, the_yoffset, the_type){ SetEraseObject(false);}wxDivisionControlPoint::~wxDivisionControlPoint(){}static double originalX = 0.0;static double originalY = 0.0;static double originalW = 0.0;static double originalH = 0.0;// Implement resizing of canvas objectvoid wxDivisionControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment){ wxControlPoint::OnDragLeft(draw, x, y, keys, attachment);}void wxDivisionControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment){ wxDivisionShape *division = (wxDivisionShape *)m_shape; originalX = division->GetX(); originalY = division->GetY(); originalW = division->GetWidth(); originalH = division->GetHeight(); wxControlPoint::OnBeginDragLeft(x, y, keys, attachment);}void wxDivisionControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment){ wxControlPoint::OnEndDragLeft(x, y, keys, attachment); wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); wxDivisionShape *division = (wxDivisionShape *)m_shape; wxCompositeShape *divisionParent = (wxCompositeShape *)division->GetParent(); // Need to check it's within the bounds of the parent composite. double x1 = (double)(divisionParent->GetX() - (divisionParent->GetWidth()/2.0)); double y1 = (double)(divisionParent->GetY() - (divisionParent->GetHeight()/2.0)); double x2 = (double)(divisionParent->GetX() + (divisionParent->GetWidth()/2.0)); double y2 = (double)(divisionParent->GetY() + (divisionParent->GetHeight()/2.0)); // Need to check it has not made the division zero or negative width/height double dx1 = (double)(division->GetX() - (division->GetWidth()/2.0)); double dy1 = (double)(division->GetY() - (division->GetHeight()/2.0)); double dx2 = (double)(division->GetX() + (division->GetWidth()/2.0)); double dy2 = (double)(division->GetY() + (division->GetHeight()/2.0)); bool success = true; switch (division->GetHandleSide()) { case DIVISION_SIDE_LEFT: { if ((x <= x1) || (x >= x2) || (x >= dx2)) success = false; // Try it out first... else if (!division->ResizeAdjoining(DIVISION_SIDE_LEFT, x, true)) success = false; else division->ResizeAdjoining(DIVISION_SIDE_LEFT, x, false); break; } case DIVISION_SIDE_TOP: { if ((y <= y1) || (y >= y2) || (y >= dy2)) success = false; else if (!division->ResizeAdjoining(DIVISION_SIDE_TOP, y, true)) success = false; else division->ResizeAdjoining(DIVISION_SIDE_TOP, y, false); break; } case DIVISION_SIDE_RIGHT: { if ((x <= x1) || (x >= x2) || (x <= dx1)) success = false; else if (!division->ResizeAdjoining(DIVISION_SIDE_RIGHT, x, true)) success = false; else division->ResizeAdjoining(DIVISION_SIDE_RIGHT, x, false); break; } case DIVISION_SIDE_BOTTOM: { if ((y <= y1) || (y >= y2) || (y <= dy1)) success = false; else if (!division->ResizeAdjoining(DIVISION_SIDE_BOTTOM, y, true)) success = false; else division->ResizeAdjoining(DIVISION_SIDE_BOTTOM, y, false); break; } } if (!success) { division->SetSize(originalW, originalH); division->Move(dc, originalX, originalY); } divisionParent->Draw(dc); division->GetEventHandler()->OnDrawControlPoints(dc);}/* Resize adjoining divisions. * Behaviour should be as follows: If right edge moves, find all objects whose left edge adjoins this object, and move left edge accordingly. If left..., move ... right. If top..., move ... bottom. If bottom..., move top. If size goes to zero or end position is other side of start position, resize to original size and return. */bool wxDivisionShape::ResizeAdjoining(int side, double newPos, bool test){ wxCompositeShape *divisionParent = (wxCompositeShape *)GetParent(); wxNode *node = divisionParent->GetDivisions().GetFirst(); while (node) { wxDivisionShape *division = (wxDivisionShape *)node->GetData(); switch (side) { case DIVISION_SIDE_LEFT: { if (division->m_rightSide == this) { bool success = division->AdjustRight(newPos, test); if (!success && test) return false; } break; } case DIVISION_SIDE_TOP: { if (division->m_bottomSide == this) { bool success = division->AdjustBottom(newPos, test); if (!success && test) return false; } break; } case DIVISION_SIDE_RIGHT: { if (division->m_leftSide == this) { bool success = division->AdjustLeft(newPos, test); if (!success && test) return false; } break; } case DIVISION_SIDE_BOTTOM: { if (division->m_topSide == this) { bool success = division->AdjustTop(newPos, test); if (!success && test) return false; } break; } default: break; } node = node->GetNext(); } return true;}/* * Popup menu for editing divisions * */class OGLPopupDivisionMenu : public wxMenu {public: OGLPopupDivisionMenu() : wxMenu() { Append(DIVISION_MENU_SPLIT_HORIZONTALLY, wxT("Split horizontally")); Append(DIVISION_MENU_SPLIT_VERTICALLY, wxT("Split vertically")); AppendSeparator(); Append(DIVISION_MENU_EDIT_LEFT_EDGE, wxT("Edit left edge")); Append(DIVISION_MENU_EDIT_TOP_EDGE, wxT("Edit top edge")); } void OnMenu(wxCommandEvent& event); DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(OGLPopupDivisionMenu, wxMenu) EVT_MENU_RANGE(DIVISION_MENU_SPLIT_HORIZONTALLY, DIVISION_MENU_EDIT_BOTTOM_EDGE, OGLPopupDivisionMenu::OnMenu)END_EVENT_TABLE()void OGLPopupDivisionMenu::OnMenu(wxCommandEvent& event){ wxDivisionShape *division = (wxDivisionShape *)GetClientData(); switch (event.GetInt()) { case DIVISION_MENU_SPLIT_HORIZONTALLY: { division->Divide(wxHORIZONTAL); break; } case DIVISION_MENU_SPLIT_VERTICALLY: { division->Divide(wxVERTICAL); break; } case DIVISION_MENU_EDIT_LEFT_EDGE: { division->EditEdge(DIVISION_SIDE_LEFT); break; } case DIVISION_MENU_EDIT_TOP_EDGE: { division->EditEdge(DIVISION_SIDE_TOP); break; } default: break; }}void wxDivisionShape::EditEdge(int WXUNUSED(side)){ wxMessageBox(wxT("EditEdge() not implemented"), wxT("OGL"), wxOK);#if 0 wxBeginBusyCursor(); wxPen *currentPen = NULL; char **pColour = NULL; char **pStyle = NULL; if (side == DIVISION_SIDE_LEFT) { currentPen = m_leftSidePen; pColour = &m_leftSideColour; pStyle = &m_leftSideStyle; } else { currentPen = m_topSidePen; pColour = &m_topSideColour; pStyle = &m_topSideStyle; } GraphicsForm *form = new GraphicsForm("Containers"); int lineWidth = currentPen->GetWidth(); form->Add(wxMakeFormShort("Width", &lineWidth, wxFORM_DEFAULT, NULL, NULL, wxVERTICAL, 150)); form->Add(wxMakeFormString("Colour", pColour, wxFORM_CHOICE, new wxList(wxMakeConstraintStrings( "BLACK" , "BLUE" , "BROWN" , "CORAL" , "CYAN" , "DARK GREY" , "DARK GREEN" , "DIM GREY" , "GREY" , "GREEN" , "LIGHT BLUE" , "LIGHT GREY" , "MAGENTA" , "MAROON" , "NAVY" , "ORANGE" , "PURPLE" , "RED" , "TURQUOISE" , "VIOLET" , "WHITE" , "YELLOW" , NULL), NULL), NULL, wxVERTICAL, 150)); form->Add(wxMakeFormString("Style", pStyle, wxFORM_CHOICE, new wxList(wxMakeConstraintStrings( "Solid" , "Short Dash" , "Long Dash" , "Dot" , "Dot Dash" , NULL), NULL), NULL, wxVERTICAL, 100)); wxDialogBox *dialog = new wxDialogBox(m_canvas->GetParent(), "Division properties", 10, 10, 500, 500); if (GraphicsLabelFont) dialog->SetLabelFont(GraphicsLabelFont); if (GraphicsButtonFont) dialog->SetButtonFont(GraphicsButtonFont); form->AssociatePanel(dialog); form->dialog = dialog; dialog->Fit(); dialog->Centre(wxBOTH); wxEndBusyCursor(); dialog->Show(true); int lineStyle = wxSOLID; if (*pStyle) { if (strcmp(*pStyle, "Solid") == 0) lineStyle = wxSOLID; else if (strcmp(*pStyle, "Dot") == 0) lineStyle = wxDOT; else if (strcmp(*pStyle, "Short Dash") == 0) lineStyle = wxSHORT_DASH; else if (strcmp(*pStyle, "Long Dash") == 0) lineStyle = wxLONG_DASH; else if (strcmp(*pStyle, "Dot Dash") == 0) lineStyle = wxDOT_DASH; } wxPen *newPen = wxThePenList->FindOrCreatePen(*pColour, lineWidth, lineStyle); if (!pen) pen = wxBLACK_PEN; if (side == DIVISION_SIDE_LEFT) m_leftSidePen = newPen; else m_topSidePen = newPen; // Need to draw whole image again wxCompositeShape *compositeParent = (wxCompositeShape *)GetParent(); compositeParent->Draw(dc);#endif}// Popup menuvoid wxDivisionShape::PopupMenu(double x, double y){ wxMenu* oglPopupDivisionMenu = new OGLPopupDivisionMenu; oglPopupDivisionMenu->SetClientData((void *)this); if (m_leftSide) oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_LEFT_EDGE, true); else oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_LEFT_EDGE, false); if (m_topSide) oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_TOP_EDGE, true); else oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_TOP_EDGE, false); int x1, y1; m_canvas->GetViewStart(&x1, &y1); int unit_x, unit_y; m_canvas->GetScrollPixelsPerUnit(&unit_x, &unit_y); wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); int mouse_x = (int)(dc.LogicalToDeviceX((long)(x - x1*unit_x))); int mouse_y = (int)(dc.LogicalToDeviceY((long)(y - y1*unit_y))); m_canvas->PopupMenu(oglPopupDivisionMenu, mouse_x, mouse_y); delete oglPopupDivisionMenu;}void wxDivisionShape::SetLeftSideColour(const wxString& colour){ m_leftSideColour = colour;}void wxDivisionShape::SetTopSideColour(const wxString& colour){ m_topSideColour = colour;}void wxDivisionShape::SetLeftSideStyle(const wxString& style){ m_leftSideStyle = style;}void wxDivisionShape::SetTopSideStyle(const wxString& style){ m_topSideStyle = style;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -