]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 774837 ] OGL wxLineShape::HitTest: smaller region
authorJulian Smart <julian@anthemion.co.uk>
Tue, 22 Jul 2003 16:15:49 +0000 (16:15 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 22 Jul 2003 16:15:49 +0000 (16:15 +0000)
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
contrib/samples/ogl/ogledit/doc.h
contrib/src/ogl/OglVC.dsp
contrib/src/ogl/basic.cpp
contrib/src/ogl/basic2.cpp
contrib/src/ogl/lines.cpp
contrib/src/ogl/ogldiag.cpp

index 6f467fc62b621450966c16f966237ab1929326a3..90545046d54978cf4bc37860132ea58e26c8532b 100644 (file)
@@ -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
  */
index 17432e9c37613bf2e11cc9ec97d6035df15632c4..93e98fec6c4e0c8fbf2a35a7a5d38cdaa707fd8c 100644 (file)
 #include <wx/string.h>
 
 #include <wx/deprecated/setup.h>
+
+#if wxUSE_PROLOGIO
 #include <wx/deprecated/wxexpr.h>
+#endif
+
 #include <wx/ogl/ogl.h>
 
 #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
 };
 
 /*
index 1deb8da3a1759e553c8f35691e78e8fc830cf412..e064cb00bc7fe8ac46dd5490570999cce2cad171 100644 (file)
@@ -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
index a145099919c82a24c1313a25253d9fea9d5cd95d..de5d1790c706dc15e010fe6c04aa609037528c12 100644 (file)
@@ -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;
index bf4eb57ca494d44108bc4b15fb868f4236525c92..21aba04dad8febfb49e34b22fc2e0c3d0b3cd757 100644 (file)
@@ -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();
index ebdb997d0711ca8ef3de18ac9263b2b1bf288270..76f10c4aeb6c71d6ef1624d7d24931a3dc196261 100644 (file)
@@ -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;
     }
 
index d9deae4921dd073b82366d5afb827ceb423b27bc..503d4cb809b6f960e7d141b76e716f231c9e6720 100644 (file)
@@ -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());