From: Julian Smart Date: Sun, 6 Sep 1998 14:32:25 +0000 (+0000) Subject: OGL improvements X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2e5ed787e9f0f4eac35b9a55e97ea4a177e2fdda?hp=868a28262c40a7428d3991ca8a034674814bdb0a OGL improvements git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@677 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/utils/ogl/distrib/ogl.rsp b/utils/ogl/distrib/ogl.rsp index f7eaa1967c..74c26f53df 100644 --- a/utils/ogl/distrib/ogl.rsp +++ b/utils/ogl/distrib/ogl.rsp @@ -1,21 +1,20 @@ src/*.cpp -src/*.c src/*.h src/*.rc src/*.def src/*.xbm -src/make*.* +src/*.xpm +src/makefile* src/*.txt src/*.ico src/*.bmp samples/ogledit/*.cpp -samples/ogledit/*.c samples/ogledit/*.h samples/ogledit/*.rc samples/ogledit/*.def samples/ogledit/*.xbm -samples/ogledit/make*.* +samples/ogledit/makefile* samples/ogledit/*.txt samples/ogledit/*.ico @@ -23,6 +22,7 @@ samples/ogledit/*.bmp samples/ogledit/bitmaps/*.bmp samples/ogledit/bitmaps/*.gif samples/ogledit/bitmaps/*.xbm +samples/ogledit/bitmaps/*.xpm distrib/*.rsp distrib/*.bat diff --git a/utils/ogl/src/basic.cpp b/utils/ogl/src/basic.cpp index 240dfc58ea..ce0ed54a71 100644 --- a/utils/ogl/src/basic.cpp +++ b/utils/ogl/src/basic.cpp @@ -1056,11 +1056,11 @@ bool wxShape::AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, co return FALSE; } -void wxShape::MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move, +bool wxShape::MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move, double x, double y) { if (!GetAttachmentMode()) - return; + return FALSE; int newAttachment, oldAttachment; double distance; @@ -1069,7 +1069,7 @@ void wxShape::MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move, // the user has moved the point to bool hit = HitTest(x, y, &newAttachment, &distance); if (!hit) - return; + return FALSE; EraseLinks(dc); @@ -1138,6 +1138,8 @@ void wxShape::MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move, newOrdering.Append(to_move); GetEventHandler()->OnChangeAttachment(newAttachment, to_move, newOrdering); + + return TRUE; } void wxShape::OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering) @@ -1467,15 +1469,15 @@ void wxShape::Move(wxDC& dc, double x, double y, bool display) double old_x = m_xpos; double old_y = m_ypos; - m_xpos = x; m_ypos = y; - if (!GetEventHandler()->OnMovePre(dc, x, y, old_x, old_y, display)) { - m_xpos = old_x; - m_ypos = old_y; +// m_xpos = old_x; +// m_ypos = old_y; return; } + m_xpos = x; m_ypos = y; + ResetControlPoints(); if (display) diff --git a/utils/ogl/src/basic.h b/utils/ogl/src/basic.h index bc3bb5f356..a134d73e79 100644 --- a/utils/ogl/src/basic.h +++ b/utils/ogl/src/basic.h @@ -394,7 +394,7 @@ class wxShape: public wxShapeEvtHandler virtual void EraseLinks(wxDC& dc, int attachment = -1, bool recurse = FALSE); virtual void DrawLinks(wxDC& dc, int attachment = -1, bool recurse = FALSE); - virtual void MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move, + virtual bool MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move, double x, double y); // Reorders the lines coming into the node image at this attachment @@ -638,6 +638,9 @@ class wxEllipseShape: public wxShape inline double GetWidth() const { return m_width; } inline double GetHeight() const { return m_height; } + inline void SetWidth(double w) { m_width = w; } + inline void SetHeight(double h) { m_height = h; } + protected: double m_width; double m_height; diff --git a/utils/ogl/src/basic2.cpp b/utils/ogl/src/basic2.cpp index 2c9c7c9b2c..46e1723c6a 100644 --- a/utils/ogl/src/basic2.cpp +++ b/utils/ogl/src/basic2.cpp @@ -1583,9 +1583,10 @@ void wxShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); - +/* if (pt->m_eraseObject) this->Erase(dc); +*/ dc.SetLogicalFunction(wxXOR); @@ -1694,8 +1695,11 @@ void wxShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int ke this->Recompute(); this->ResetControlPoints(); + this->Erase(dc); +/* if (!pt->m_eraseObject) this->Show(FALSE); +*/ this->SetSize(pt->controlPointDragEndWidth, pt->controlPointDragEndHeight); @@ -1711,8 +1715,10 @@ void wxShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int ke else theObject->Move(dc, pt->controlPointDragPosX, pt->controlPointDragPosY); +/* if (!eraseIt) theObject->Show(TRUE); +*/ // Recursively redraw links if we have a composite. if (theObject->GetChildren().Number() > 0) diff --git a/utils/ogl/src/lines.cpp b/utils/ogl/src/lines.cpp index 18d7268120..b321ba3854 100644 --- a/utils/ogl/src/lines.cpp +++ b/utils/ogl/src/lines.cpp @@ -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(wxDC& dc) +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); } @@ -1496,7 +1498,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 +1668,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 +1685,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 +1707,7 @@ wxLineControlPoint::wxLineControlPoint(wxShapeCanvas *theCanvas, wxShape *object m_xpos = x; m_ypos = y; m_type = the_type; + m_point = NULL; } wxLineControlPoint::~wxLineControlPoint() @@ -1770,7 +1774,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 +1789,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 +1822,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 +1841,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 +1872,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 +1890,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 +2403,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 +2471,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 +2492,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; } diff --git a/utils/ogl/src/lines.h b/utils/ogl/src/lines.h index e15a64b93d..4b94a9c95b 100644 --- a/utils/ogl/src/lines.h +++ b/utils/ogl/src/lines.h @@ -88,6 +88,7 @@ class wxArrowHead: public wxObject }; // Line object +class wxLabelShape; class wxLineShape: public wxShape { DECLARE_DYNAMIC_CLASS(wxLineShape) @@ -107,7 +108,9 @@ class wxLineShape: public wxShape void OnDrawControlPoints(wxDC& dc); void OnEraseControlPoints(wxDC& dc); void OnErase(wxDC& dc); - virtual inline void OnMoveControlPoint(int WXUNUSED(which), double WXUNUSED(x), double WXUNUSED(y)) {} + virtual bool OnMoveControlPoint(int WXUNUSED(which), double WXUNUSED(x), double WXUNUSED(y)) { return FALSE; } + virtual bool OnMoveMiddleControlPoint(wxDC& dc, wxLineControlPoint* lpt, const wxRealPoint& pt); + virtual bool OnLabelMovePre(wxDC& dc, wxLabelShape* labelShape, double x, double y, double old_x, double old_y, bool display); void OnDrawOutline(wxDC& dc, double x, double y, double w, double h); void GetBoundingBoxMin(double *w, double *h); void FormatText(wxDC& dc, const wxString& s, int regionId = 0); @@ -139,8 +142,11 @@ class wxLineShape: public wxShape // position is 0 (middle), 1 (start), 2 (end) void GetLabelPosition(int position, double *x, double *y); + // Can override this to create a different class of label shape + virtual wxLabelShape* OnCreateLabelShape(wxLineShape *parent = NULL, wxShapeRegion *region = NULL, double w = 0.0, double h = 0.0); + // Straighten verticals and horizontals - virtual void Straighten(wxDC& dc); + virtual void Straighten(wxDC* dc = NULL); // Not implemented inline void SetMaintainStraightLines(bool flag) { m_maintainStraightLines = flag; } diff --git a/utils/ogl/src/linesp.h b/utils/ogl/src/linesp.h index 70b7026d74..383fe7f554 100644 --- a/utils/ogl/src/linesp.h +++ b/utils/ogl/src/linesp.h @@ -44,6 +44,7 @@ public: int m_type; wxRealPoint* m_point; // Line point + wxRealPoint m_originalPos; }; diff --git a/utils/ogl/src/makefile.b32 b/utils/ogl/src/makefile.b32 index 7945902454..c9acc471b1 100644 --- a/utils/ogl/src/makefile.b32 +++ b/utils/ogl/src/makefile.b32 @@ -51,7 +51,7 @@ CPPFLAGS=$(DEBUG_FLAGS) $(OPT) @$(CFG) CFLAGS=$(DEBUG_FLAGS) $(OPT) @$(CFG) OBJECTS = basic.obj basic2.obj canvas.obj ogldiag.obj lines.obj misc.obj divided.obj constrnt.obj\ - composit.obj drawn.obj bitmap.obj mfutils.obj + composit.obj drawn.obj bmpshape.obj mfutils.obj all: $(OGLLIB) diff --git a/utils/ogl/src/makefile.nt b/utils/ogl/src/makefile.nt index dfd5a0b159..9a16cb5919 100644 --- a/utils/ogl/src/makefile.nt +++ b/utils/ogl/src/makefile.nt @@ -26,7 +26,7 @@ LOCALDOCDIR=$(WXDIR)\utils\ogl\docs PROGRAM=test OBJECTS = basic.obj basic2.obj canvas.obj ogldiag.obj lines.obj misc.obj divided.obj constrnt.obj\ - composit.obj drawn.obj bitmap.obj mfutils.obj + composit.obj drawn.obj bmpshape.obj mfutils.obj LIBTARGET=$(WXDIR)\lib\ogl.lib @@ -104,7 +104,7 @@ drawn.obj: drawn.$(SRCSUFF) basic.h misc.h canvas.h drawn.h drawnp.h basicp $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) << -bitmap.obj: bitmap.$(SRCSUFF) basic.h misc.h canvas.h bitmap.h +bmpshape.obj: bmpshape.$(SRCSUFF) basic.h misc.h canvas.h bmpshape.h cl @<< $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) << diff --git a/utils/ogl/src/ogldiag.cpp b/utils/ogl/src/ogldiag.cpp index 60efe27a7d..915c289e10 100644 --- a/utils/ogl/src/ogldiag.cpp +++ b/utils/ogl/src/ogldiag.cpp @@ -400,6 +400,7 @@ void wxDiagram::ReadLines(wxExprDatabase& database) shape->Show(TRUE); OnShapeLoad(database, *shape, *clause); + shape->SetCanvas(GetCanvas()); long image_to = -1; long image_from = -1; clause->GetAttributeValue("to", image_to);