📄 basic2.cpp
字号:
if (pt->m_type == CONTROL_POINT_HORIZONTAL) pt->sm_controlPointDragStartY = (double)(this->GetY() - (bound_y/2.0)); else if (pt->m_type == CONTROL_POINT_VERTICAL) pt->sm_controlPointDragStartX = (double)(this->GetX() - (bound_x/2.0)); // We may require the old width and height. pt->sm_controlPointDragStartWidth = bound_x; pt->sm_controlPointDragStartHeight = bound_y; wxPen dottedPen(*wxBLACK, 1, wxDOT); dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); if (this->GetCentreResize()) { 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 (pt->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::OnSizingEndDragLeft(wxControlPoint* pt, double WXUNUSED(x), double WXUNUSED(y), int WXUNUSED(keys), int WXUNUSED(attachment)){ wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); m_canvas->ReleaseMouse(); dc.SetLogicalFunction(wxCOPY); this->Recompute(); this->ResetControlPoints(); this->Erase(dc);/* if (!pt->m_eraseObject) this->Show(false);*/ this->SetSize(pt->sm_controlPointDragEndWidth, pt->sm_controlPointDragEndHeight); // The next operation could destroy this control point (it does for label objects, // via formatting the text), so save all values we're going to use, or // we'll be accessing garbage. wxShape *theObject = this; wxShapeCanvas *theCanvas = m_canvas; bool eraseIt = pt->m_eraseObject; if (theObject->GetCentreResize()) theObject->Move(dc, theObject->GetX(), theObject->GetY()); else theObject->Move(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY);/* if (!eraseIt) theObject->Show(true);*/ // Recursively redraw links if we have a composite. if (theObject->GetChildren().GetCount() > 0) theObject->DrawLinks(dc, -1, true); double width, height; theObject->GetBoundingBoxMax(&width, &height); theObject->GetEventHandler()->OnEndSize(width, height); if (!theCanvas->GetQuickEditMode() && eraseIt) theCanvas->Redraw(dc);}// Polygon control pointsIMPLEMENT_DYNAMIC_CLASS(wxPolygonControlPoint, wxControlPoint)wxPolygonControlPoint::wxPolygonControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size, wxRealPoint *vertex, double the_xoffset, double the_yoffset): wxControlPoint(theCanvas, object, size, the_xoffset, the_yoffset, 0){ m_polygonVertex = vertex; m_originalDistance = 0.0;}wxPolygonControlPoint::~wxPolygonControlPoint(){}// Calculate what new size would be, at end of resizevoid wxPolygonControlPoint::CalculateNewSize(double x, double y){ double bound_x; double bound_y; GetShape()->GetBoundingBoxMin(&bound_x, &bound_y); double dist = (double)sqrt((x - m_shape->GetX())*(x - m_shape->GetX()) + (y - m_shape->GetY())*(y - m_shape->GetY())); m_newSize.x = (double)(dist/this->m_originalDistance)*this->m_originalSize.x; m_newSize.y = (double)(dist/this->m_originalDistance)*this->m_originalSize.y;}// Implement resizing polygon or moving the vertex.void wxPolygonControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment){ m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment);}void wxPolygonControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment){ m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment);}void wxPolygonControlPoint::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 wxPolygonShape::OnSizingDragLeft(wxControlPoint* pt, bool WXUNUSED(draw), double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment)){ wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt; wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); dc.SetLogicalFunction(OGLRBLF); wxPen dottedPen(*wxBLACK, 1, wxDOT); dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); #if 0 // keys & KEY_CTRL) { // TODO: mend this code. Currently we rely on altering the // actual points, but we should assume we're not, as per // the normal sizing case. m_canvas->Snap(&x, &y); // Move point ppt->m_polygonVertex->x = x - this->GetX(); ppt->m_polygonVertex->y = y - this->GetY(); ppt->SetX(x); ppt->SetY(y); ((wxPolygonShape *)this)->CalculateBoundingBox(); ((wxPolygonShape *)this)->CalculatePolygonCentre(); } #else { ppt->CalculateNewSize(x, y); } #endif this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(), ppt->GetNewSize().x, ppt->GetNewSize().y);}void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment)){ wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt; wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); this->Erase(dc); dc.SetLogicalFunction(OGLRBLF); double bound_x; double bound_y; this->GetBoundingBoxMin(&bound_x, &bound_y); double dist = (double)sqrt((x - this->GetX())*(x - this->GetX()) + (y - this->GetY())*(y - this->GetY())); ppt->m_originalDistance = dist; ppt->m_originalSize.x = bound_x; ppt->m_originalSize.y = bound_y; if (ppt->m_originalDistance == 0.0) ppt->m_originalDistance = (double) 0.0001; wxPen dottedPen(*wxBLACK, 1, wxDOT); dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); #if 0 // keys & KEY_CTRL) { // TODO: mend this code. Currently we rely on altering the // actual points, but we should assume we're not, as per // the normal sizing case. m_canvas->Snap(&x, &y); // Move point ppt->m_polygonVertex->x = x - this->GetX(); ppt->m_polygonVertex->y = y - this->GetY(); ppt->SetX(x); ppt->SetY(y); ((wxPolygonShape *)this)->CalculateBoundingBox(); ((wxPolygonShape *)this)->CalculatePolygonCentre(); } #else { ppt->CalculateNewSize(x, y); } #endif this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(), ppt->GetNewSize().x, ppt->GetNewSize().y); m_canvas->CaptureMouse();}void wxPolygonShape::OnSizingEndDragLeft(wxControlPoint* pt, double WXUNUSED(x), double WXUNUSED(y), int keys, int WXUNUSED(attachment)){ wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt; wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); m_canvas->ReleaseMouse(); dc.SetLogicalFunction(wxCOPY); // If we're changing shape, must reset the original points if (keys & KEY_CTRL) { ((wxPolygonShape *)this)->CalculateBoundingBox(); ((wxPolygonShape *)this)->UpdateOriginalPoints(); } else { SetSize(ppt->GetNewSize().x, ppt->GetNewSize().y); } ((wxPolygonShape *)this)->CalculateBoundingBox(); ((wxPolygonShape *)this)->CalculatePolygonCentre(); this->Recompute(); this->ResetControlPoints(); this->Move(dc, this->GetX(), this->GetY()); if (!m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc);}/* * Object region * */IMPLEMENT_DYNAMIC_CLASS(wxShapeRegion, wxObject)wxShapeRegion::wxShapeRegion(){ m_regionText = wxEmptyString; m_font = g_oglNormalFont; m_minHeight = 5.0; m_minWidth = 5.0; m_width = 0.0; m_height = 0.0; m_x = 0.0; m_y = 0.0; m_regionProportionX = -1.0; m_regionProportionY = -1.0; m_formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT; m_regionName = wxEmptyString; m_textColour = wxT("BLACK"); m_penColour = wxT("BLACK"); m_penStyle = wxSOLID; m_actualColourObject = wxTheColourDatabase->Find(wxT("BLACK")); m_actualPenObject = NULL;}wxShapeRegion::wxShapeRegion(wxShapeRegion& region):wxObject(){ m_regionText = region.m_regionText; m_regionName = region.m_regionName; m_textColour = region.m_textColour; m_font = region.m_font; m_minHeight = region.m_minHeight; m_minWidth = region.m_minWidth; m_width = region.m_width; m_height = region.m_height; m_x = region.m_x; m_y = region.m_y; m_regionProportionX = region.m_regionProportionX; m_regionProportionY = region.m_regionProportionY; m_formatMode = region.m_formatMode; m_actualColourObject = region.m_actualColourObject; m_actualPenObject = NULL; m_penStyle = region.m_penStyle; m_penColour = region.m_penColour; ClearText(); wxObjectList::compatibility_iterator node = region.m_formattedText.GetFirst(); while (node) { wxShapeTextLine *line = (wxShapeTextLine *)node->GetData(); wxShapeTextLine *new_line = new wxShapeTextLine(line->GetX(), line->GetY(), line->GetText()); m_formattedText.Append(new_line); node = node->GetNext(); }}wxShapeRegion::~wxShapeRegion(){ ClearText();}void wxShapeRegion::ClearText(){ wxObjectList::compatibility_iterator node = m_formattedText.GetFirst(); while (node) { wxShapeTextLine *line = (wxShapeTextLine *)node->GetData(); wxObjectList::compatibility_iterator next = node->GetNext(); delete line; m_formattedText.Erase(node); node = next; }}void wxShapeRegion::SetFont(wxFont *f){ m_font = f;}void wxShapeRegion::SetMinSize(double w, double h){ m_minWidth = w; m_minHeight = h;}void wxShapeRegion::SetSize(double w, double h){ m_width = w; m_height = h;}void wxShapeRegion::SetPosition(double xp, double yp){ m_x = xp; m_y = yp;}void wxShapeRegion::SetProportions(double xp, double yp){ m_regionProportionX = xp; m_regionProportionY = yp;}void wxShapeRegion::SetFormatMode(int mode){ m_formatMode = mode;}void wxShapeRegion::SetColour(const wxString& col){ m_textColour = col; m_actualColourObject = col;}wxColour wxShapeRegion::GetActualColourObject(){ m_actualColourObject = wxTheColourDatabase->Find(GetColour()); return m_actualColourObject;}void wxShapeRegion::SetPenColour(const wxString& col){ m_penColour = col; m_actualPenObject = NULL;}// Returns NULL if the pen is invisible// (different to pen being transparent; indicates that// region boundary should not be drawn.)wxPen *wxShapeRegion::GetActualPen(){ if (m_actualPenObject) return m_actualPenObject; if (!m_penColour) return NULL; if (m_penColour == wxT("Invisible")) return NULL; m_actualPenObject = wxThePenList->FindOrCreatePen(m_penColour, 1, m_penStyle); return m_actualPenObject;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -