]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/ogl/src/lines.cpp
"unsigned char" restored in wxColour ctor
[wxWidgets.git] / utils / ogl / src / lines.cpp
index 18d726812039f8c39ac8eb8a0ae256c4b4512126..d03b2f401a8ed2bce3b272411d518e1fbd086988 100644 (file)
@@ -28,7 +28,7 @@
 #include <wx/wxexpr.h>
 #endif
 
-#if USE_IOSTREAMH
+#if wxUSE_IOSTREAMH
 #include <iostream.h>
 #else
 #include <iostream>
@@ -249,7 +249,7 @@ void wxLineShape::FormatText(wxDC& dc, const wxString& s, int i)
       EraseRegion(dc, region, xx, yy);
       if (m_labelObjects[i])
       {
-        m_labelObjects[i]->Select(FALSE);
+        m_labelObjects[i]->Select(FALSE, &dc);
         m_labelObjects[i]->Erase(dc);
         m_labelObjects[i]->SetSize(actualW, actualH);
       }
@@ -391,12 +391,13 @@ void GraphicsStraightenLine(wxRealPoint *point1, wxRealPoint *point2)
   else point2->y = point1->y;
 }
 
-void wxLineShape::Straighten(wxDCdc)
+void wxLineShape::Straighten(wxDC *dc)
 {
   if (!m_lineControlPoints || m_lineControlPoints->Number() < 3)
     return;
 
-  Erase(dc);
+  if (dc)
+    Erase(* dc);
 
   wxNode *first_point_node = m_lineControlPoints->First();
   wxNode *last_point_node = m_lineControlPoints->Last();
@@ -417,7 +418,8 @@ void wxLineShape::Straighten(wxDC& dc)
     node = node->Next();
   }
 
-  Draw(dc);
+  if (dc)
+    Draw(* dc);
 }
 
 
@@ -1063,7 +1065,7 @@ void wxLineShape::OnMoveLink(wxDC& dc, bool moveControlPoints)
 
 //    if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
     // Only move control points if it's a self link. And only works if attachment mode is ON.
-    if ((m_from == m_to) && m_from->GetAttachmentMode() && moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
+    if ((m_from == m_to) && (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE) && moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
     {
       wxNode *node = m_lineControlPoints->First();
       while (node)
@@ -1108,7 +1110,7 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
 
   if (m_lineControlPoints->Number() > 2)
   {
-    if (m_from->GetAttachmentMode())
+    if (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
     {
       int nth, no_arcs;
       FindNth(m_from, &nth, &no_arcs, FALSE); // Not incoming
@@ -1119,7 +1121,7 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
                                    (double)second_point->x, (double)second_point->y,
                                     &end_x, &end_y);
 
-    if (m_to->GetAttachmentMode())
+    if (m_to->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
     {
       int nth, no_arcs;
       FindNth(m_to, &nth, &no_arcs, TRUE); // Incoming
@@ -1137,7 +1139,7 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
     double toX = m_to->GetX();
     double toY = m_to->GetY();
 
-    if (m_from->GetAttachmentMode())
+    if (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
     {
       int nth, no_arcs;
       FindNth(m_from, &nth, &no_arcs, FALSE);
@@ -1146,7 +1148,7 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
       fromY = end_y;
     }
 
-    if (m_to->GetAttachmentMode())
+    if (m_to->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
     {
       int nth, no_arcs;
       FindNth(m_to, &nth, &no_arcs, TRUE);
@@ -1155,12 +1157,12 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
       toY = other_end_y;
     }
 
-    if (!m_from->GetAttachmentMode())
+    if (m_from->GetAttachmentMode() == ATTACHMENT_MODE_NONE)
       (void) m_from->GetPerimeterPoint(m_from->GetX(), m_from->GetY(),
                                   toX, toY,
                                   &end_x, &end_y);
 
-    if (!m_to->GetAttachmentMode())
+    if (m_to->GetAttachmentMode() == ATTACHMENT_MODE_NONE)
       (void) m_to->GetPerimeterPoint(m_to->GetX(), m_to->GetY(),
                                 fromX, fromY,
                                 &other_end_x, &other_end_y);
@@ -1294,14 +1296,6 @@ void wxLineShape::OnDrawContents(wxDC& dc)
   }
 }
 
-
-#ifdef PROLOGIO
-char *wxLineShape::GetFunctor()
-{
-  return "arc_image";
-}
-#endif
-
 void wxLineShape::SetTo(wxShape *object)
 {
   m_to = object;
@@ -1375,9 +1369,9 @@ void wxLineShape::ResetControlPoints()
 }
 
 #ifdef PROLOGIO
-void wxLineShape::WritePrologAttributes(wxExpr *clause)
+void wxLineShape::WriteAttributes(wxExpr *clause)
 {
-  wxShape::WritePrologAttributes(clause);
+  wxShape::WriteAttributes(clause);
 
   if (m_from)
     clause->AddAttributeValue("from", m_from->GetId());
@@ -1399,12 +1393,12 @@ void wxLineShape::WritePrologAttributes(wxExpr *clause)
     clause->AddAttributeValue("keep_lines_straight", (long)m_maintainStraightLines);
 
   // Make a list of lists for the (sp)line controls
-  wxExpr *list = new wxExpr(PrologList);
+  wxExpr *list = new wxExpr(wxExprList);
   wxNode *node = m_lineControlPoints->First();
   while (node)
   {
     wxRealPoint *point = (wxRealPoint *)node->Data();
-    wxExpr *point_list = new wxExpr(PrologList);
+    wxExpr *point_list = new wxExpr(wxExprList);
     wxExpr *x_expr = new wxExpr((double) point->x);
     wxExpr *y_expr = new wxExpr((double) point->y);
     point_list->Append(x_expr);
@@ -1420,17 +1414,17 @@ void wxLineShape::WritePrologAttributes(wxExpr *clause)
   // (arrowType arrowEnd xOffset arrowSize)
   if (m_arcArrows.Number() > 0)
   {
-    wxExpr *arrow_list = new wxExpr(PrologList);
+    wxExpr *arrow_list = new wxExpr(wxExprList);
     node = m_arcArrows.First();
     while (node)
     {
       wxArrowHead *head = (wxArrowHead *)node->Data();
-      wxExpr *head_list = new wxExpr(PrologList);
+      wxExpr *head_list = new wxExpr(wxExprList);
       head_list->Append(new wxExpr((long)head->_GetType()));
       head_list->Append(new wxExpr((long)head->GetArrowEnd()));
       head_list->Append(new wxExpr(head->GetXOffset()));
       head_list->Append(new wxExpr(head->GetArrowSize()));
-      head_list->Append(new wxExpr(PrologString, (head->GetName() ? head->GetName() : "")));
+      head_list->Append(new wxExpr(wxExprString, (head->GetName() ? head->GetName() : "")));
       head_list->Append(new wxExpr(head->GetId()));
 
       // New members of wxArrowHead
@@ -1445,9 +1439,9 @@ void wxLineShape::WritePrologAttributes(wxExpr *clause)
   }
 }
 
-void wxLineShape::ReadPrologAttributes(wxExpr *clause)
+void wxLineShape::ReadAttributes(wxExpr *clause)
 {
-  wxShape::ReadPrologAttributes(clause);
+  wxShape::ReadAttributes(clause);
 
   int iVal = (int) m_isSpline;
   clause->AssignAttributeValue("is_spline", &iVal);
@@ -1496,7 +1490,7 @@ void wxLineShape::ReadPrologAttributes(wxExpr *clause)
   m_attachmentFrom = 0;
 
   clause->AssignAttributeValue("attachment_to", &m_attachmentTo);
-  clause->AssignAttributeValue("attachmen_from", &m_attachmentFrom);
+  clause->AssignAttributeValue("attachment_from", &m_attachmentFrom);
 
   wxExpr *line_list = NULL;
 
@@ -1666,12 +1660,12 @@ void wxLineShape::Select(bool select, wxDC* dc)
             m_labelObjects[i]->RemoveFromCanvas(m_canvas);
             delete m_labelObjects[i];
           }
-          m_labelObjects[i] = new wxLabelShape(this, region, w, h);
+          m_labelObjects[i] = OnCreateLabelShape(this, region, w, h);
           m_labelObjects[i]->AddToCanvas(m_canvas);
           m_labelObjects[i]->Show(TRUE);
           if (dc)
             m_labelObjects[i]->Move(*dc, (double)(x + xx), (double)(y + yy));
-          m_labelObjects[i]->Select(TRUE);
+          m_labelObjects[i]->Select(TRUE, dc);
         }
       }
     }
@@ -1683,6 +1677,7 @@ void wxLineShape::Select(bool select, wxDC* dc)
       if (m_labelObjects[i])
       {
         m_labelObjects[i]->Select(FALSE, dc);
+        m_labelObjects[i]->Erase(*dc);
         m_labelObjects[i]->RemoveFromCanvas(m_canvas);
         delete m_labelObjects[i];
         m_labelObjects[i] = NULL;
@@ -1704,6 +1699,7 @@ wxLineControlPoint::wxLineControlPoint(wxShapeCanvas *theCanvas, wxShape *object
   m_xpos = x;
   m_ypos = y;
   m_type = the_type;
+  m_point = NULL;
 }
 
 wxLineControlPoint::~wxLineControlPoint()
@@ -1770,7 +1766,7 @@ void wxLineShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, doub
 
   if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO)
   {
-    lpt->SetX(x); lpt->SetY(y);
+//    lpt->SetX(x); lpt->SetY(y);
   }
 
 }
@@ -1785,6 +1781,7 @@ void wxLineShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y,
   wxLineShape *lineShape = (wxLineShape *)this;
   if (lpt->m_type == CONTROL_POINT_LINE)
   {
+    lpt->m_originalPos = * (lpt->m_point);
     m_canvas->Snap(&x, &y);
 
     this->Erase(dc);
@@ -1817,18 +1814,6 @@ void wxLineShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y,
 
   if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO)
   {
-    lpt->Erase(dc);
-    lineShape->OnDraw(dc);
-    if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM)
-    {
-      lineShape->GetFrom()->OnDraw(dc);
-      lineShape->GetFrom()->OnDrawContents(dc);
-    }
-    else
-    {
-      lineShape->GetTo()->OnDraw(dc);
-      lineShape->GetTo()->OnDrawContents(dc);
-    }
     m_canvas->SetCursor(g_oglBullseyeCursor);
     lpt->m_oldCursor = wxSTANDARD_CURSOR;
   }
@@ -1848,19 +1833,26 @@ void wxLineShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, in
   {
     m_canvas->Snap(&x, &y);
 
-    dc.SetLogicalFunction(wxCOPY);
-    lpt->m_xpos = x; lpt->m_ypos = y;
-    lpt->m_point->x = x; lpt->m_point->y = y;
+    wxRealPoint pt = wxRealPoint(x, y);
+
+    // Move the control point back to where it was;
+    // MoveControlPoint will move it to the new position
+    // if it decides it wants. We only moved the position
+    // during user feedback so we could redraw the line
+    // as it changed shape.
+    lpt->m_xpos = lpt->m_originalPos.x; lpt->m_ypos = lpt->m_originalPos.y;
+    lpt->m_point->x = lpt->m_originalPos.x; lpt->m_point->y = lpt->m_originalPos.y;
 
-    lineShape->GetEventHandler()->OnMoveLink(dc);
+    OnMoveMiddleControlPoint(dc, lpt, pt);
   }
   if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM)
   {
     if (lpt->m_oldCursor)
       m_canvas->SetCursor(lpt->m_oldCursor);
-    this->Erase(dc);
 
-    lpt->m_xpos = x; lpt->m_ypos = y;
+//    this->Erase(dc);
+
+//    lpt->m_xpos = x; lpt->m_ypos = y;
 
     if (lineShape->GetFrom())
     {
@@ -1872,7 +1864,7 @@ void wxLineShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, in
     if (lpt->m_oldCursor)
       m_canvas->SetCursor(lpt->m_oldCursor);
 
-    lpt->m_xpos = x; lpt->m_ypos = y;
+//    lpt->m_xpos = x; lpt->m_ypos = y;
 
     if (lineShape->GetTo())
     {
@@ -1890,13 +1882,22 @@ void wxLineShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, in
   // N.B. in OnMoveControlPoint, an event handler in Hardy could have deselected
   // the line and therefore deleted 'this'. -> GPF, intermittently.
   // So assume at this point that we've been blown away.
-  wxLineShape *lineObj = lineShape;
-  wxShapeCanvas *objCanvas = m_canvas;
 
-  lineObj->OnMoveControlPoint(i+1, x, y);
+  lineShape->OnMoveControlPoint(i+1, x, y);
 #endif
 }
 
+// This is called only when a non-end control point is moved.
+bool wxLineShape::OnMoveMiddleControlPoint(wxDC& dc, wxLineControlPoint* lpt, const wxRealPoint& pt)
+{
+    lpt->m_xpos = pt.x; lpt->m_ypos = pt.y;
+    lpt->m_point->x = pt.x; lpt->m_point->y = pt.y;
+
+    GetEventHandler()->OnMoveLink(dc);
+
+    return TRUE;
+}
+
 // Implement movement of endpoint to a new attachment
 // OBSOLETE: done by dragging with the left button.
 
@@ -2394,6 +2395,12 @@ void wxArrowHead::SetSize(double size)
   }
 }
 
+// Can override this to create a different class of label shape
+wxLabelShape* wxLineShape::OnCreateLabelShape(wxLineShape *parent, wxShapeRegion *region, double w, double h)
+{
+    return new wxLabelShape(parent, region, w, h);
+}
+
 /*
  * Label object
  *
@@ -2456,14 +2463,19 @@ void wxLabelShape::OnEndDragLeft(double x, double y, int keys, int attachment)
 
 bool wxLabelShape::OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display)
 {
-  m_shapeRegion->SetSize(m_width, m_height);
+    return m_lineShape->OnLabelMovePre(dc, this, x, y, old_x, old_y, display);
+}
+
+bool wxLineShape::OnLabelMovePre(wxDC& dc, wxLabelShape* labelShape, double x, double y, double old_x, double old_y, bool display)
+{
+  labelShape->m_shapeRegion->SetSize(labelShape->GetWidth(), labelShape->GetHeight());
 
   // Find position in line's region list
   int i = 0;
-  wxNode *node = m_lineShape->GetRegions().First();
+  wxNode *node = GetRegions().First();
   while (node)
   {
-    if (m_shapeRegion == (wxShapeRegion *)node->Data())
+    if (labelShape->m_shapeRegion == (wxShapeRegion *)node->Data())
       node = NULL;
     else
     {
@@ -2472,18 +2484,21 @@ bool wxLabelShape::OnMovePre(wxDC& dc, double x, double y, double old_x, double
     }
   }
   double xx, yy;
-  m_lineShape->GetLabelPosition(i, &xx, &yy);
+  GetLabelPosition(i, &xx, &yy);
   // Set the region's offset, relative to the default position for
   // each region.
-  m_shapeRegion->SetPosition((double)(x - xx), (double)(y - yy));
+  labelShape->m_shapeRegion->SetPosition((double)(x - xx), (double)(y - yy));
+
+  labelShape->SetX(x);
+  labelShape->SetY(y);
 
   // Need to reformat to fit region.
-  if (m_shapeRegion->GetText())
+  if (labelShape->m_shapeRegion->GetText())
   {
 
-    wxString s(m_shapeRegion->GetText());
-    m_lineShape->FormatText(dc, s, i);
-    m_lineShape->DrawRegion(dc, m_shapeRegion, xx, yy);
+    wxString s(labelShape->m_shapeRegion->GetText());
+    labelShape->FormatText(dc, s, i);
+    DrawRegion(dc, labelShape->m_shapeRegion, xx, yy);
   }
   return TRUE;
 }