X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8552e6f031ded8ae61b4a5b489fbf06962365da7..780fb83cb0d665baec66e651d58d91f6c0af66b0:/contrib/src/ogl/basic2.cpp?ds=sidebyside diff --git a/contrib/src/ogl/basic2.cpp b/contrib/src/ogl/basic2.cpp index b79a6c7545..0526495e72 100644 --- a/contrib/src/ogl/basic2.cpp +++ b/contrib/src/ogl/basic2.cpp @@ -6,7 +6,7 @@ // Created: 12/07/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -63,23 +63,31 @@ void wxPolygonShape::Create(wxList *the_points) { ClearPoints(); - m_originalPoints = the_points; - - // Duplicate the list of points - m_points = new wxList; - - wxNode *node = the_points->GetFirst(); - while (node) + if (!the_points) { - wxRealPoint *point = (wxRealPoint *)node->GetData(); - wxRealPoint *new_point = new wxRealPoint(point->x, point->y); - m_points->Append((wxObject*) new_point); - node = node->GetNext(); + m_originalPoints = new wxList; + m_points = new wxList; + } + else + { + m_originalPoints = the_points; + + // Duplicate the list of points + m_points = new wxList; + + wxObjectList::compatibility_iterator node = the_points->GetFirst(); + while (node) + { + wxRealPoint *point = (wxRealPoint *)node->GetData(); + wxRealPoint *new_point = new wxRealPoint(point->x, point->y); + m_points->Append((wxObject*) new_point); + node = node->GetNext(); + } + CalculateBoundingBox(); + m_originalWidth = m_boundWidth; + m_originalHeight = m_boundHeight; + SetDefaultRegionSize(); } - CalculateBoundingBox(); - m_originalWidth = m_boundWidth; - m_originalHeight = m_boundHeight; - SetDefaultRegionSize(); } wxPolygonShape::~wxPolygonShape() @@ -91,12 +99,12 @@ void wxPolygonShape::ClearPoints() { if (m_points) { - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); delete point; - delete node; + m_points->Erase(node); node = m_points->GetFirst(); } delete m_points; @@ -104,12 +112,12 @@ void wxPolygonShape::ClearPoints() } if (m_originalPoints) { - wxNode *node = m_originalPoints->GetFirst(); + wxObjectList::compatibility_iterator node = m_originalPoints->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); delete point; - delete node; + m_originalPoints->Erase(node); node = m_originalPoints->GetFirst(); } delete m_originalPoints; @@ -133,7 +141,7 @@ void wxPolygonShape::CalculateBoundingBox() double top = 10000; double bottom = -10000; - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -161,7 +169,7 @@ void wxPolygonShape::CalculatePolygonCentre() double top = 10000; double bottom = -10000; - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -194,7 +202,7 @@ void wxPolygonShape::CalculatePolygonCentre() bool PolylineHitTest(double n, double xvec[], double yvec[], double x1, double y1, double x2, double y2) { - bool isAHit = FALSE; + bool isAHit = false; int i; double lastx = xvec[0]; double lasty = yvec[0]; @@ -208,7 +216,7 @@ bool PolylineHitTest(double n, double xvec[], double yvec[], oglCheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[i], yvec[i], &line_ratio, &other_ratio); if (line_ratio != 1.0) - isAHit = TRUE; + isAHit = true; lastx = xvec[i]; lasty = yvec[i]; @@ -222,7 +230,7 @@ bool PolylineHitTest(double n, double xvec[], double yvec[], oglCheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[0], yvec[0], &line_ratio, &other_ratio); if (line_ratio != 1.0) - isAHit = TRUE; + isAHit = true; } return isAHit; @@ -252,7 +260,7 @@ bool wxPolygonShape::HitTest(double x, double y, int *attachment, double *distan int np = m_points->GetCount(); double *xpoints = new double[np]; double *ypoints = new double[np]; - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); int i = 0; while (node) { @@ -265,13 +273,13 @@ bool wxPolygonShape::HitTest(double x, double y, int *attachment, double *distan // We assume it's inside the polygon UNLESS one or more // lines don't hit the outline. - bool isContained = TRUE; + bool isContained = true; int noPoints = 4; for (i = 0; i < noPoints; i++) { if (!PolylineHitTest(np, xpoints, ypoints, x, y, endPointsX[i], endPointsY[i])) - isContained = FALSE; + isContained = false; } /* if (isContained) @@ -283,7 +291,7 @@ bool wxPolygonShape::HitTest(double x, double y, int *attachment, double *distan delete[] ypoints; if (!isContained) - return FALSE; + return false; int nearest_attachment = 0; @@ -307,7 +315,7 @@ bool wxPolygonShape::HitTest(double x, double y, int *attachment, double *distan } *attachment = nearest_attachment; *distance = nearest; - return TRUE; + return true; } // Really need to be able to reset the shape! Otherwise, if the @@ -320,8 +328,8 @@ void wxPolygonShape::SetSize(double new_width, double new_height, bool WXUNUSED( double x_proportion = (double)(fabs(new_width/m_originalWidth)); double y_proportion = (double)(fabs(new_height/m_originalHeight)); - wxNode *node = m_points->GetFirst(); - wxNode *original_node = m_originalPoints->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); + wxObjectList::compatibility_iterator original_node = m_originalPoints->GetFirst(); while (node && original_node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -344,18 +352,18 @@ void wxPolygonShape::SetSize(double new_width, double new_height, bool WXUNUSED( void wxPolygonShape::UpdateOriginalPoints() { if (!m_originalPoints) m_originalPoints = new wxList; - wxNode *original_node = m_originalPoints->GetFirst(); + wxObjectList::compatibility_iterator original_node = m_originalPoints->GetFirst(); while (original_node) { - wxNode *next_node = original_node->GetNext(); + wxObjectList::compatibility_iterator next_node = original_node->GetNext(); wxRealPoint *original_point = (wxRealPoint *)original_node->GetData(); delete original_point; - delete original_node; + m_originalPoints->Erase(original_node); original_node = next_node; } - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -371,11 +379,11 @@ void wxPolygonShape::UpdateOriginalPoints() void wxPolygonShape::AddPolygonPoint(int pos) { - wxNode *node = m_points->Item(pos); + wxObjectList::compatibility_iterator node = m_points->Item(pos); if (!node) node = m_points->GetFirst(); wxRealPoint *firstPoint = (wxRealPoint *)node->GetData(); - wxNode *node2 = m_points->Item(pos + 1); + wxObjectList::compatibility_iterator node2 = m_points->Item(pos + 1); if (!node2) node2 = m_points->GetFirst(); wxRealPoint *secondPoint = (wxRealPoint *)node2->GetData(); @@ -399,12 +407,12 @@ void wxPolygonShape::AddPolygonPoint(int pos) void wxPolygonShape::DeletePolygonPoint(int pos) { - wxNode *node = m_points->Item(pos); + wxObjectList::compatibility_iterator node = m_points->Item(pos); if (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); delete point; - delete node; + m_points->Erase(node); UpdateOriginalPoints(); if (m_selected) { @@ -429,7 +437,7 @@ bool wxPolygonShape::GetPerimeterPoint(double x1, double y1, { // Look for the point we'd be connecting to. This is // a heuristic... - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -439,13 +447,13 @@ bool wxPolygonShape::GetPerimeterPoint(double x1, double y1, { *x3 = point->x + m_xpos; *y3 = point->y + m_ypos; - return TRUE; + return true; } else if ((y2 < y1) && (point->y < 0.0)) { *x3 = point->x + m_xpos; *y3 = point->y + m_ypos; - return TRUE; + return true; } } node = node->GetNext(); @@ -455,7 +463,7 @@ bool wxPolygonShape::GetPerimeterPoint(double x1, double y1, double *xpoints = new double[n]; double *ypoints = new double[n]; - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); int i = 0; while (node) { @@ -472,7 +480,7 @@ bool wxPolygonShape::GetPerimeterPoint(double x1, double y1, delete[] xpoints; delete[] ypoints; - return TRUE; + return true; } void wxPolygonShape::OnDraw(wxDC& dc) @@ -533,7 +541,7 @@ void wxPolygonShape::OnDrawOutline(wxDC& dc, double x, double y, double w, doubl // Make as many control points as there are vertices. void wxPolygonShape::MakeControlPoints() { - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -547,8 +555,8 @@ void wxPolygonShape::MakeControlPoints() void wxPolygonShape::ResetControlPoints() { - wxNode *node = m_points->GetFirst(); - wxNode *controlPointNode = m_controlPoints.GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); + wxObjectList::compatibility_iterator controlPointNode = m_controlPoints.GetFirst(); while (node && controlPointNode) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -574,7 +582,7 @@ void wxPolygonShape::WriteAttributes(wxExpr *clause) // Make a list of lists for the coordinates wxExpr *list = new wxExpr(wxExprList); - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -732,7 +740,7 @@ void wxPolygonShape::Copy(wxShape& copy) polyCopy.m_points = new wxList; polyCopy.m_originalPoints = new wxList; - wxNode *node = m_points->GetFirst(); + wxObjectList::compatibility_iterator node = m_points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -757,7 +765,7 @@ void wxPolygonShape::Copy(wxShape& copy) int wxPolygonShape::GetNumberOfAttachments() const { int maxN = (m_points ? (m_points->GetCount() - 1) : 0); - wxNode *node = m_attachmentPoints.GetFirst(); + wxObjectList::compatibility_iterator node = m_attachmentPoints.GetFirst(); while (node) { wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData(); @@ -776,7 +784,7 @@ bool wxPolygonShape::GetAttachmentPosition(int attachment, double *x, double *y, wxRealPoint *point = (wxRealPoint *)m_points->Item(attachment)->GetData(); *x = point->x + m_xpos; *y = point->y + m_ypos; - return TRUE; + return true; } else { return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); } @@ -785,20 +793,20 @@ bool wxPolygonShape::GetAttachmentPosition(int attachment, double *x, double *y, bool wxPolygonShape::AttachmentIsValid(int attachment) const { if (!m_points) - return FALSE; + return false; if ((attachment >= 0) && (attachment < (int) m_points->GetCount())) - return TRUE; + return true; - wxNode *node = m_attachmentPoints.GetFirst(); + wxObjectList::compatibility_iterator node = m_attachmentPoints.GetFirst(); while (node) { wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData(); if (point->m_id == attachment) - return TRUE; + return true; node = node->GetNext(); } - return FALSE; + return false; } // Rotate about the given axis by the given amount in radians @@ -809,7 +817,7 @@ void wxPolygonShape::Rotate(double x, double y, double theta) // Rotate attachment points double sinTheta = (double)sin(actualTheta); double cosTheta = (double)cos(actualTheta); - wxNode *node = m_attachmentPoints.GetFirst(); + wxObjectList::compatibility_iterator node = m_attachmentPoints.GetFirst(); while (node) { wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData(); @@ -920,7 +928,7 @@ bool wxRectangleShape::GetPerimeterPoint(double WXUNUSED(x1), double WXUNUSED(y1 GetBoundingBoxMax(&bound_x, &bound_y); oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3); - return TRUE; + return true; } #if wxUSE_PROLOGIO @@ -1028,7 +1036,7 @@ bool wxEllipseShape::GetPerimeterPoint(double x1, double y1, // oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3); oglDrawArcToEllipse(m_xpos, m_ypos, bound_x, bound_y, x2, y2, x1, y1, x3, y3); - return TRUE; + return true; } void wxEllipseShape::OnDraw(wxDC& dc) @@ -1169,10 +1177,10 @@ bool wxEllipseShape::GetAttachmentPosition(int attachment, double *x, double *y, return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); } } - return TRUE; + return true; } else - { *x = m_xpos; *y = m_ypos; return TRUE; } + { *x = m_xpos; *y = m_ypos; return true; } } @@ -1181,7 +1189,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxCircleShape, wxEllipseShape) wxCircleShape::wxCircleShape(double diameter):wxEllipseShape(diameter, diameter) { - SetMaintainAspectRatio(TRUE); + SetMaintainAspectRatio(true); } void wxCircleShape::Copy(wxShape& copy) @@ -1198,7 +1206,7 @@ bool wxCircleShape::GetPerimeterPoint(double WXUNUSED(x1), double WXUNUSED(y1), x2, y2, // Other end of line x3, y3); - return TRUE; + return true; } // Control points @@ -1224,8 +1232,8 @@ wxControlPoint::wxControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double SetPen(g_oglBlackForegroundPen); SetBrush(wxBLACK_BRUSH); m_oldCursor = NULL; - m_visible = TRUE; - m_eraseObject = TRUE; + m_visible = true; + m_eraseObject = true; } wxControlPoint::~wxControlPoint() @@ -1274,7 +1282,7 @@ bool wxControlPoint::GetAttachmentPosition(int WXUNUSED(attachment), double *x, int WXUNUSED(nth), int WXUNUSED(no_arcs), wxLineShape *WXUNUSED(line)) { *x = m_xpos; *y = m_ypos; - return TRUE; + return true; } // Control points ('handles') redirect control to the actual shape, to make it easier @@ -1402,6 +1410,7 @@ void wxShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int double bound_x; double bound_y; this->GetBoundingBoxMin(&bound_x, &bound_y); + this->GetEventHandler()->OnBeginSize(bound_x, bound_y); // Choose the 'opposite corner' of the object as the stationary // point in case this is non-centring resizing. @@ -1531,7 +1540,7 @@ void wxShape::OnSizingEndDragLeft(wxControlPoint* pt, double WXUNUSED(x), double this->Erase(dc); /* if (!pt->m_eraseObject) - this->Show(FALSE); + this->Show(false); */ this->SetSize(pt->sm_controlPointDragEndWidth, pt->sm_controlPointDragEndHeight); @@ -1550,12 +1559,12 @@ void wxShape::OnSizingEndDragLeft(wxControlPoint* pt, double WXUNUSED(x), double /* if (!eraseIt) - theObject->Show(TRUE); + theObject->Show(true); */ // Recursively redraw links if we have a composite. if (theObject->GetChildren().GetCount() > 0) - theObject->DrawLinks(dc, -1, TRUE); + theObject->DrawLinks(dc, -1, true); double width, height; theObject->GetBoundingBoxMax(&width, &height); @@ -1761,7 +1770,7 @@ wxShapeRegion::wxShapeRegion() m_textColour = wxT("BLACK"); m_penColour = wxT("BLACK"); m_penStyle = wxSOLID; - m_actualColourObject = NULL; + m_actualColourObject = wxTheColourDatabase->Find(wxT("BLACK")); m_actualPenObject = NULL; } @@ -1782,13 +1791,13 @@ wxShapeRegion::wxShapeRegion(wxShapeRegion& region) m_regionProportionX = region.m_regionProportionX; m_regionProportionY = region.m_regionProportionY; m_formatMode = region.m_formatMode; - m_actualColourObject = NULL; + m_actualColourObject = region.m_actualColourObject; m_actualPenObject = NULL; m_penStyle = region.m_penStyle; m_penColour = region.m_penColour; ClearText(); - wxNode *node = region.m_formattedText.GetFirst(); + wxObjectList::compatibility_iterator node = region.m_formattedText.GetFirst(); while (node) { wxShapeTextLine *line = (wxShapeTextLine *)node->GetData(); @@ -1806,13 +1815,13 @@ wxShapeRegion::~wxShapeRegion() void wxShapeRegion::ClearText() { - wxNode *node = m_formattedText.GetFirst(); + wxObjectList::compatibility_iterator node = m_formattedText.GetFirst(); while (node) { wxShapeTextLine *line = (wxShapeTextLine *)node->GetData(); - wxNode *next = node->GetNext(); + wxObjectList::compatibility_iterator next = node->GetNext(); delete line; - delete node; + m_formattedText.Erase(node); node = next; } } @@ -1854,15 +1863,12 @@ void wxShapeRegion::SetFormatMode(int mode) void wxShapeRegion::SetColour(const wxString& col) { m_textColour = col; - m_actualColourObject = NULL; + m_actualColourObject = col; } -wxColour *wxShapeRegion::GetActualColourObject() +wxColour wxShapeRegion::GetActualColourObject() { - if (!m_actualColourObject) - m_actualColourObject = wxTheColourDatabase->FindColour(GetColour()); - if (!m_actualColourObject) - m_actualColourObject = wxBLACK; + m_actualColourObject = wxTheColourDatabase->Find(GetColour()); return m_actualColourObject; }