From 1dde66dda68a3d712d2f4de0388c4bb3a3375b36 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 22 Jul 2003 16:15:49 +0000 Subject: [PATCH] Applied patch [ 774837 ] OGL wxLineShape::HitTest: smaller region Also fixed .dsp file to reflect oglmisc.cpp name Fixed some warnings Added test for wxUSE_PROLOGIO git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22237 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/samples/ogl/ogledit/doc.cpp | 12 ++++++++++-- contrib/samples/ogl/ogledit/doc.h | 6 ++++++ contrib/src/ogl/OglVC.dsp | 4 ++-- contrib/src/ogl/basic.cpp | 6 +++--- contrib/src/ogl/basic2.cpp | 6 +++--- contrib/src/ogl/lines.cpp | 25 +++++++++++++------------ contrib/src/ogl/ogldiag.cpp | 4 ++-- 7 files changed, 39 insertions(+), 24 deletions(-) diff --git a/contrib/samples/ogl/ogledit/doc.cpp b/contrib/samples/ogl/ogledit/doc.cpp index 6f467fc62b..90545046d5 100644 --- a/contrib/samples/ogl/ogledit/doc.cpp +++ b/contrib/samples/ogl/ogledit/doc.cpp @@ -87,6 +87,8 @@ wxSTD istream& DiagramDocument::LoadObject(wxSTD istream& stream) wxOutputStream& DiagramDocument::SaveObject(wxOutputStream& stream) { +#if wxUSE_PROLOGIO + wxDocument::SaveObject(stream); char buf[400]; (void) wxGetTempFileName("diag", buf); @@ -96,16 +98,17 @@ wxOutputStream& DiagramDocument::SaveObject(wxOutputStream& stream) wxTransferFileToStream(buf, stream); wxRemoveFile(buf); - + +#endif return stream; } wxInputStream& DiagramDocument::LoadObject(wxInputStream& stream) { +#if wxUSE_PROLOGIO wxDocument::LoadObject(stream); - char buf[400]; (void) wxGetTempFileName("diag", buf); @@ -114,6 +117,7 @@ wxInputStream& DiagramDocument::LoadObject(wxInputStream& stream) diagram.DeleteAllShapes(); diagram.LoadFile(buf); wxRemoveFile(buf); +#endif return stream; } @@ -546,6 +550,8 @@ void MyEvtHandler::OnEndSize(double x, double y) /* * Diagram */ + +#if wxUSE_PROLOGIO bool MyDiagram::OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr) { @@ -568,6 +574,8 @@ bool MyDiagram::OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr) return TRUE; } +#endif + /* * New shapes */ diff --git a/contrib/samples/ogl/ogledit/doc.h b/contrib/samples/ogl/ogledit/doc.h index 17432e9c37..93e98fec6c 100644 --- a/contrib/samples/ogl/ogledit/doc.h +++ b/contrib/samples/ogl/ogledit/doc.h @@ -21,7 +21,11 @@ #include #include + +#if wxUSE_PROLOGIO #include +#endif + #include #if wxUSE_STD_IOSTREAM @@ -36,8 +40,10 @@ class MyDiagram: public wxDiagram { public: MyDiagram(void) {} +#if wxUSE_PROLOGIO bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr); bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr); +#endif }; /* diff --git a/contrib/src/ogl/OglVC.dsp b/contrib/src/ogl/OglVC.dsp index 1deb8da3a1..e064cb00bc 100644 --- a/contrib/src/ogl/OglVC.dsp +++ b/contrib/src/ogl/OglVC.dsp @@ -124,11 +124,11 @@ SOURCE=.\mfutils.cpp # End Source File # Begin Source File -SOURCE=.\misc.cpp +SOURCE=.\ogldiag.cpp # End Source File # Begin Source File -SOURCE=.\ogldiag.cpp +SOURCE=.\oglmisc.cpp # End Source File # End Target # End Project diff --git a/contrib/src/ogl/basic.cpp b/contrib/src/ogl/basic.cpp index a145099919..de5d1790c7 100644 --- a/contrib/src/ogl/basic.cpp +++ b/contrib/src/ogl/basic.cpp @@ -1621,7 +1621,7 @@ void wxShape::AddLine(wxLineShape *line, wxShape *other, { // Don't preserve old ordering if we have new ordering instructions m_lines.DeleteObject(line); - if (positionFrom < m_lines.GetCount()) + if (positionFrom < (int) m_lines.GetCount()) { wxNode* node = m_lines.Item(positionFrom); m_lines.Insert(node, line); @@ -1639,7 +1639,7 @@ void wxShape::AddLine(wxLineShape *line, wxShape *other, { // Don't preserve old ordering if we have new ordering instructions other->m_lines.DeleteObject(line); - if (positionTo < other->m_lines.GetCount()) + if (positionTo < (int) other->m_lines.GetCount()) { wxNode* node = other->m_lines.Item(positionTo); other->m_lines.Insert(node, line); @@ -2904,7 +2904,7 @@ wxRealPoint wxShape::CalcSimpleAttachment(const wxRealPoint& pt1, const wxRealPo // Return the zero-based position in m_lines of line. int wxShape::GetLinePosition(wxLineShape* line) { - int i = 0; + size_t i = 0; for (i = 0; i < m_lines.GetCount(); i++) if ((wxLineShape*) (m_lines.Item(i)->GetData()) == line) return i; diff --git a/contrib/src/ogl/basic2.cpp b/contrib/src/ogl/basic2.cpp index bf4eb57ca4..21aba04dad 100644 --- a/contrib/src/ogl/basic2.cpp +++ b/contrib/src/ogl/basic2.cpp @@ -396,7 +396,7 @@ void wxPolygonShape::AddPolygonPoint(int pos) double y = (double)((secondPoint->y - firstPoint->y)/2.0 + firstPoint->y); wxRealPoint *point = new wxRealPoint(x, y); - if (pos >= (m_points->GetCount() - 1)) + if (pos >= (int) (m_points->GetCount() - 1)) m_points->Append((wxObject*) point); else m_points->Insert(node2, (wxObject*) point); @@ -784,7 +784,7 @@ int wxPolygonShape::GetNumberOfAttachments() const bool wxPolygonShape::GetAttachmentPosition(int attachment, double *x, double *y, int nth, int no_arcs, wxLineShape *line) { - if ((m_attachmentMode == ATTACHMENT_MODE_EDGE) && m_points && attachment < m_points->GetCount()) + if ((m_attachmentMode == ATTACHMENT_MODE_EDGE) && m_points && attachment < (int) m_points->GetCount()) { wxRealPoint *point = (wxRealPoint *)m_points->Item(attachment)->GetData(); *x = point->x + m_xpos; @@ -800,7 +800,7 @@ bool wxPolygonShape::AttachmentIsValid(int attachment) const if (!m_points) return FALSE; - if ((attachment >= 0) && (attachment < m_points->GetCount())) + if ((attachment >= 0) && (attachment < (int) m_points->GetCount())) return TRUE; wxNode *node = m_attachmentPoints.GetFirst(); diff --git a/contrib/src/ogl/lines.cpp b/contrib/src/ogl/lines.cpp index ebdb997d07..76f10c4aeb 100644 --- a/contrib/src/ogl/lines.cpp +++ b/contrib/src/ogl/lines.cpp @@ -509,22 +509,23 @@ bool wxLineShape::HitTest(double x, double y, int *attachment, double *distance) wxRealPoint *point1 = (wxRealPoint *)node->GetData(); wxRealPoint *point2 = (wxRealPoint *)node->GetNext()->GetData(); - // Allow for inaccurate mousing or vert/horiz lines + // For inaccurate mousing allow 8 pixel corridor int extra = 4; - double left = wxMin(point1->x, point2->x) - extra; - double right = wxMax(point1->x, point2->x) + extra; - double bottom = wxMin(point1->y, point2->y) - extra; - double top = wxMax(point1->y, point2->y) + extra; - - if ((x > left && x < right && y > bottom && y < top) || inLabelRegion) + double dx = point2->x - point1->x; + double dy = point2->y - point1->y; + double seg_len = sqrt(dx*dx+dy*dy); + double distance_from_seg = + seg_len*((x-point1->x)*dy-(y-point1->y)*dx)/(dy*dy+dx*dx); + double distance_from_prev = + seg_len*((y-point1->y)*dy+(x-point1->x)*dx)/(dy*dy+dx*dx); + + if ((fabs(distance_from_seg) < extra && + distance_from_prev >= 0 && distance_from_prev <= seg_len) + || inLabelRegion) { - // Work out distance from centre of line - double centre_x = (double)(left + (right - left)/2.0); - double centre_y = (double)(bottom + (top - bottom)/2.0); - *attachment = 0; - *distance = (double)sqrt((centre_x - x)*(centre_x - x) + (centre_y - y)*(centre_y - y)); + *distance = distance_from_seg; return TRUE; } diff --git a/contrib/src/ogl/ogldiag.cpp b/contrib/src/ogl/ogldiag.cpp index d9deae4921..503d4cb809 100644 --- a/contrib/src/ogl/ogldiag.cpp +++ b/contrib/src/ogl/ogldiag.cpp @@ -613,7 +613,7 @@ void wxLineCrossings::FindCrossings(wxDiagram& diagram) wxLineShape* lineShape1 = (wxLineShape*) shape1; // Iterate through the segments wxList* pts1 = lineShape1->GetLineControlPoints(); - int i; + size_t i; for (i = 0; i < (pts1->GetCount() - 1); i++) { wxRealPoint* pt1_a = (wxRealPoint*) (pts1->Item(i)->GetData()); @@ -633,7 +633,7 @@ void wxLineCrossings::FindCrossings(wxDiagram& diagram) // Iterate through the segments wxList* pts2 = lineShape2->GetLineControlPoints(); int j; - for (j = 0; j < (pts2->GetCount() - 1); j++) + for (j = 0; j < (int) (pts2->GetCount() - 1); j++) { wxRealPoint* pt2_a = (wxRealPoint*) (pts2->Item(j)->GetData()); wxRealPoint* pt2_b = (wxRealPoint*) (pts2->Item(j+1)->GetData());