X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42cfaf8cd4464466398ed888cb2caa5ee360c7ef..77902671753529da1345efb71ff6017cb882bedc:/utils/ogl/src/composit.cpp diff --git a/utils/ogl/src/composit.cpp b/utils/ogl/src/composit.cpp index 2ce5273e41..a6f0ba5aaf 100644 --- a/utils/ogl/src/composit.cpp +++ b/utils/ogl/src/composit.cpp @@ -24,9 +24,7 @@ #include #endif -#ifdef PROLOGIO #include -#endif #include "basic.h" #include "basicp.h" @@ -39,13 +37,11 @@ // construct themselves. wxExprDatabase *GlobalwxExprDatabase = NULL; -// Popup menu for editing divisions -wxMenu *oglPopupDivisionMenu = NULL; /* * Division control point */ - + class wxDivisionControlPoint: public wxControlPoint { DECLARE_DYNAMIC_CLASS(wxDivisionControlPoint) @@ -80,7 +76,7 @@ wxCompositeShape::~wxCompositeShape() wxNode *node = m_constraints.First(); while (node) { - OGLConstraint *constraint = (OGLConstraint *)node->Data(); + wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data(); delete constraint; node = node->Next(); } @@ -103,8 +99,8 @@ void wxCompositeShape::OnDraw(wxDC& dc) if (m_shadowMode != SHADOW_NONE) { if (m_shadowBrush) - dc.SetBrush(m_shadowBrush); - dc.SetPen(g_oglTransparentPen); + dc.SetBrush(* m_shadowBrush); + dc.SetPen(* g_oglTransparentPen); if (m_cornerRadius != 0.0) dc.DrawRoundedRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY), @@ -170,7 +166,7 @@ void wxCompositeShape::OnDragLeft(bool draw, double x, double y, int keys, int a wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); - dc.SetLogicalFunction(wxXOR); + dc.SetLogicalFunction(OGLRBLF); wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT); dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); @@ -189,7 +185,7 @@ void wxCompositeShape::OnBeginDragLeft(double x, double y, int keys, int attachm Erase(dc); - dc.SetLogicalFunction(wxXOR); + dc.SetLogicalFunction(OGLRBLF); wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT); dc.SetPen(dottedPen); @@ -230,7 +226,7 @@ void wxCompositeShape::OnEndDragLeft(double x, double y, int keys, int attachmen double offsetY = yy - objectStartY; Move(dc, GetX() + offsetX, GetY() + offsetY); - + if (m_canvas && !m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc); } @@ -286,7 +282,7 @@ void wxCompositeShape::SetSize(double w, double h, bool recursive) object->Show(FALSE); object->Move(dc, newX, newY); object->Show(TRUE); - + // Now set the scaled size object->GetBoundingBoxMin(&xBound, &yBound); object->SetSize(object->GetFixedWidth() ? xBound : xScale*xBound, @@ -323,7 +319,7 @@ void wxCompositeShape::DeleteConstraintsInvolvingChild(wxShape *child) wxNode *node = m_constraints.First(); while (node) { - OGLConstraint *constraint = (OGLConstraint *)node->Data(); + wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data(); wxNode *nextNode = node->Next(); if ((constraint->m_constrainingObject == child) || @@ -341,7 +337,7 @@ void wxCompositeShape::RemoveChildFromConstraints(wxShape *child) wxNode *node = m_constraints.First(); while (node) { - OGLConstraint *constraint = (OGLConstraint *)node->Data(); + wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data(); wxNode *nextNode = node->Next(); if (constraint->m_constrainedObjects.Member(child)) @@ -379,7 +375,7 @@ void wxCompositeShape::Copy(wxShape& copy) wxShape *newObject = object->CreateNewCopy(FALSE, FALSE); if (newObject->GetId() == 0) newObject->SetId(NewId()); - + newObject->SetParent(&compositeCopy); compositeCopy.m_children.Append(newObject); @@ -396,7 +392,7 @@ void wxCompositeShape::Copy(wxShape& copy) node = m_constraints.First(); while (node) { - OGLConstraint *constraint = (OGLConstraint *)node->Data(); + wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data(); wxShape *newConstraining = (wxShape *)(oglObjectCopyMapping.Find((long)constraint->m_constrainingObject)->Data()); @@ -407,10 +403,10 @@ void wxCompositeShape::Copy(wxShape& copy) wxShape *constrainedObject = (wxShape *)node2->Data(); wxShape *newConstrained = (wxShape *)(oglObjectCopyMapping.Find((long)constrainedObject)->Data()); newConstrainedList.Append(newConstrained); - node2 = node2->Next(); + node2 = node2->Next(); } - OGLConstraint *newConstraint = new OGLConstraint(constraint->m_constraintType, newConstraining, + wxOGLConstraint *newConstraint = new wxOGLConstraint(constraint->m_constraintType, newConstraining, newConstrainedList); newConstraint->m_constraintId = constraint->m_constraintId; if (constraint->m_constraintName) @@ -457,7 +453,7 @@ void wxCompositeShape::Copy(wxShape& copy) } } -OGLConstraint *wxCompositeShape::AddConstraint(OGLConstraint *constraint) +wxOGLConstraint *wxCompositeShape::AddConstraint(wxOGLConstraint *constraint) { m_constraints.Append(constraint); if (constraint->m_constraintId == 0) @@ -465,32 +461,32 @@ OGLConstraint *wxCompositeShape::AddConstraint(OGLConstraint *constraint) return constraint; } -OGLConstraint *wxCompositeShape::AddConstraint(int type, wxShape *constraining, wxList& constrained) +wxOGLConstraint *wxCompositeShape::AddConstraint(int type, wxShape *constraining, wxList& constrained) { - OGLConstraint *constraint = new OGLConstraint(type, constraining, constrained); + wxOGLConstraint *constraint = new wxOGLConstraint(type, constraining, constrained); if (constraint->m_constraintId == 0) constraint->m_constraintId = NewId(); m_constraints.Append(constraint); return constraint; } -OGLConstraint *wxCompositeShape::AddConstraint(int type, wxShape *constraining, wxShape *constrained) +wxOGLConstraint *wxCompositeShape::AddConstraint(int type, wxShape *constraining, wxShape *constrained) { wxList l; l.Append(constrained); - OGLConstraint *constraint = new OGLConstraint(type, constraining, l); + wxOGLConstraint *constraint = new wxOGLConstraint(type, constraining, l); if (constraint->m_constraintId == 0) constraint->m_constraintId = NewId(); m_constraints.Append(constraint); return constraint; } -OGLConstraint *wxCompositeShape::FindConstraint(long cId, wxCompositeShape **actualComposite) +wxOGLConstraint *wxCompositeShape::FindConstraint(long cId, wxCompositeShape **actualComposite) { wxNode *node = m_constraints.First(); while (node) { - OGLConstraint *constraint = (OGLConstraint *)node->Data(); + wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data(); if (constraint->m_constraintId == cId) { if (actualComposite) @@ -506,7 +502,7 @@ OGLConstraint *wxCompositeShape::FindConstraint(long cId, wxCompositeShape **act wxShape *child = (wxShape *)node->Data(); if (child->IsKindOf(CLASSINFO(wxCompositeShape))) { - OGLConstraint *constraint = ((wxCompositeShape *)child)->FindConstraint(cId, actualComposite); + wxOGLConstraint *constraint = ((wxCompositeShape *)child)->FindConstraint(cId, actualComposite); if (constraint) { if (actualComposite) @@ -519,7 +515,7 @@ OGLConstraint *wxCompositeShape::FindConstraint(long cId, wxCompositeShape **act return NULL; } -void wxCompositeShape::DeleteConstraint(OGLConstraint *constraint) +void wxCompositeShape::DeleteConstraint(wxOGLConstraint *constraint) { m_constraints.DeleteObject(constraint); delete constraint; @@ -595,7 +591,7 @@ bool wxCompositeShape::Constrain() node = m_constraints.First(); while (node) { - OGLConstraint *constraint = (OGLConstraint *)node->Data(); + wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data(); if (constraint->Evaluate()) changed = TRUE; node = node->Next(); } @@ -603,9 +599,9 @@ bool wxCompositeShape::Constrain() } #ifdef PROLOGIO -void wxCompositeShape::WritePrologAttributes(wxExpr *clause) +void wxCompositeShape::WriteAttributes(wxExpr *clause) { - wxRectangleShape::WritePrologAttributes(clause); + wxRectangleShape::WriteAttributes(clause); // clause->AddAttributeValue("selectable", (long)selectable); @@ -615,20 +611,20 @@ void wxCompositeShape::WritePrologAttributes(wxExpr *clause) wxNode *node = m_constraints.First(); while (node) { - OGLConstraint *constraint = (OGLConstraint *)node->Data(); + wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data(); sprintf(m_constraintNameBuf, "constraint%d", constraintNo); // Each constraint is stored in the form // (type name id xspacing yspacing m_constrainingObjectId constrainedObjectIdList) - wxExpr *constraintExpr = new wxExpr(PrologList); + wxExpr *constraintExpr = new wxExpr(wxExprList); constraintExpr->Append(new wxExpr((long)constraint->m_constraintType)); - constraintExpr->Append(new wxExpr(PrologString, constraint->m_constraintName)); + constraintExpr->Append(new wxExpr(wxExprString, constraint->m_constraintName)); constraintExpr->Append(new wxExpr(constraint->m_constraintId)); constraintExpr->Append(new wxExpr(constraint->m_xSpacing)); constraintExpr->Append(new wxExpr(constraint->m_ySpacing)); constraintExpr->Append(new wxExpr(constraint->m_constrainingObject->GetId())); - wxExpr *objectList = new wxExpr(PrologList); + wxExpr *objectList = new wxExpr(wxExprList); wxNode *node1 = constraint->m_constrainedObjects.First(); while (node1) { @@ -645,7 +641,7 @@ void wxCompositeShape::WritePrologAttributes(wxExpr *clause) } // Write the ids of all the child images - wxExpr *childrenExpr = new wxExpr(PrologList); + wxExpr *childrenExpr = new wxExpr(wxExprList); node = m_children.First(); while (node) { @@ -658,7 +654,7 @@ void wxCompositeShape::WritePrologAttributes(wxExpr *clause) // Write the ids of all the division images if (m_divisions.Number() > 0) { - wxExpr *divisionsExpr = new wxExpr(PrologList); + wxExpr *divisionsExpr = new wxExpr(wxExprList); node = m_divisions.First(); while (node) { @@ -674,9 +670,9 @@ void wxCompositeShape::WritePrologAttributes(wxExpr *clause) // so as to be able to link up to parent. So we may not be able // to find the constraint participants until we've read everything // in. Need to have another pass for composites. -void wxCompositeShape::ReadPrologAttributes(wxExpr *clause) +void wxCompositeShape::ReadAttributes(wxExpr *clause) { - wxRectangleShape::ReadPrologAttributes(clause); + wxRectangleShape::ReadAttributes(clause); // clause->GetAttributeValue("selectable", selectable); } @@ -728,7 +724,7 @@ void wxCompositeShape::ReadConstraints(wxExpr *clause, wxExprDatabase *database) m_constrainingObject = (wxShape *)objExpr1->GetClientData(); else wxFatalError("Couldn't find constraining image of composite.", "Object graphics error"); - + int i = 0; wxExpr *currentIdExpr = constrainedExpr->Nth(i); while (currentIdExpr) @@ -747,7 +743,7 @@ void wxCompositeShape::ReadConstraints(wxExpr *clause, wxExprDatabase *database) i ++; currentIdExpr = constrainedExpr->Nth(i); } - OGLConstraint *newConstraint = AddConstraint(cType, m_constrainingObject, m_constrainedObjects); + wxOGLConstraint *newConstraint = AddConstraint(cType, m_constrainingObject, m_constrainedObjects); newConstraint->SetSpacing(cXSpacing, cYSpacing); newConstraint->m_constraintId = cId; newConstraint->m_constraintName = (const char*) cName; @@ -843,7 +839,7 @@ wxDivisionShape::~wxDivisionShape() void wxDivisionShape::OnDraw(wxDC& dc) { - dc.SetBrush(wxTRANSPARENT_BRUSH); + dc.SetBrush(* wxTRANSPARENT_BRUSH); dc.SetBackgroundMode(wxTRANSPARENT); double x1 = (double)(GetX() - (GetWidth()/2.0)); @@ -858,18 +854,18 @@ void wxDivisionShape::OnDraw(wxDC& dc) if (m_leftSide) { - dc.SetPen(m_leftSidePen); + dc.SetPen(* m_leftSidePen); dc.DrawLine(WXROUND(x1), WXROUND(y2), WXROUND(x1), WXROUND(y1)); } if (m_topSide) { - dc.SetPen(m_topSidePen); + dc.SetPen(* m_topSidePen); dc.DrawLine(WXROUND(x1), WXROUND(y1), WXROUND(x2), WXROUND(y1)); } // For testing purposes, draw a rectangle so we know // how big the division is. -// SetBrush(wxCYAN_BRUSH); +// SetBrush(* wxCYAN_BRUSH); // wxRectangleShape::OnDraw(dc); } @@ -940,7 +936,7 @@ void wxDivisionShape::OnEndDragLeft(double x, double y, int keys, int attachment } return; } - + wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); @@ -989,9 +985,9 @@ void wxDivisionShape::Copy(wxShape& copy) } #ifdef PROLOGIO -void wxDivisionShape::WritePrologAttributes(wxExpr *clause) +void wxDivisionShape::WriteAttributes(wxExpr *clause) { - wxCompositeShape::WritePrologAttributes(clause); + wxCompositeShape::WriteAttributes(clause); if (m_leftSide) clause->AddAttributeValue("left_side", (long)m_leftSide->GetId()); @@ -1009,9 +1005,9 @@ void wxDivisionShape::WritePrologAttributes(wxExpr *clause) clause->AddAttributeValueString("top_style", m_topSideStyle); } -void wxDivisionShape::ReadPrologAttributes(wxExpr *clause) +void wxDivisionShape::ReadAttributes(wxExpr *clause) { - wxCompositeShape::ReadPrologAttributes(clause); + wxCompositeShape::ReadAttributes(clause); clause->GetAttributeValue("handle_side", m_handleSide); clause->GetAttributeValue("left_colour", m_leftSideColour); @@ -1082,7 +1078,7 @@ bool wxDivisionShape::Divide(int direction) double newYPos2 = (double)(y1 + (3.0*GetHeight()/4.0)); wxDivisionShape *newDivision = compositeParent->OnCreateDivision(); newDivision->Show(TRUE); - + Erase(dc); // Anything adjoining the bottom of this division now adjoins the @@ -1111,7 +1107,7 @@ bool wxDivisionShape::Divide(int direction) // Division is now receiving mouse events _before_ the contained object, // because it was added last (on top of all others) - // Add after the image that visualizes the container + // Add after the image that visualizes the container compositeParent->AddChild(newDivision, compositeParent->FindContainerImage()); m_handleSide = DIVISION_SIDE_BOTTOM; @@ -1133,7 +1129,7 @@ bool wxDivisionShape::Divide(int direction) double newYPos2 = GetY(); wxDivisionShape *newDivision = compositeParent->OnCreateDivision(); newDivision->Show(TRUE); - + Erase(dc); // Anything adjoining the left of this division now adjoins the @@ -1322,7 +1318,7 @@ bool wxDivisionShape::AdjustLeft(double left, bool test) GetCanvas()->PrepareDC(dc); Move(dc, newX, GetY()); - + return TRUE; } @@ -1343,7 +1339,7 @@ bool wxDivisionShape::AdjustTop(double top, bool test) GetCanvas()->PrepareDC(dc); Move(dc, GetX(), newY); - + return TRUE; } @@ -1364,7 +1360,7 @@ bool wxDivisionShape::AdjustRight(double right, bool test) GetCanvas()->PrepareDC(dc); Move(dc, newX, GetY()); - + return TRUE; } @@ -1385,7 +1381,7 @@ bool wxDivisionShape::AdjustBottom(double bottom, bool test) GetCanvas()->PrepareDC(dc); Move(dc, GetX(), newY); - + return TRUE; } @@ -1417,7 +1413,7 @@ void wxDivisionControlPoint::OnBeginDragLeft(double x, double y, int keys, int a originalY = division->GetY(); originalW = division->GetWidth(); originalH = division->GetHeight(); - + wxControlPoint::OnBeginDragLeft(x, y, keys, attachment); } @@ -1455,7 +1451,7 @@ void wxDivisionControlPoint::OnEndDragLeft(double x, double y, int keys, int att success = FALSE; else division->ResizeAdjoining(DIVISION_SIDE_LEFT, x, FALSE); - + break; } case DIVISION_SIDE_TOP: @@ -1466,7 +1462,7 @@ void wxDivisionControlPoint::OnEndDragLeft(double x, double y, int keys, int att success = FALSE; else division->ResizeAdjoining(DIVISION_SIDE_TOP, y, FALSE); - + break; } case DIVISION_SIDE_RIGHT: @@ -1477,7 +1473,7 @@ void wxDivisionControlPoint::OnEndDragLeft(double x, double y, int keys, int att success = FALSE; else division->ResizeAdjoining(DIVISION_SIDE_RIGHT, x, FALSE); - + break; } case DIVISION_SIDE_BOTTOM: @@ -1488,7 +1484,7 @@ void wxDivisionControlPoint::OnEndDragLeft(double x, double y, int keys, int att success = FALSE; else division->ResizeAdjoining(DIVISION_SIDE_BOTTOM, y, FALSE); - + break; } } @@ -1566,7 +1562,7 @@ bool wxDivisionShape::ResizeAdjoining(int side, double newPos, bool test) } node = node->Next(); } - + return TRUE; } @@ -1574,10 +1570,32 @@ bool wxDivisionShape::ResizeAdjoining(int side, double newPos, bool test) * Popup menu for editing divisions * */ - -void oglGraphicsDivisionMenuProc(wxMenu& menu, wxCommandEvent& event) +class OGLPopupDivisionMenu : public wxMenu { +public: + OGLPopupDivisionMenu() : wxMenu() { + Append(DIVISION_MENU_SPLIT_HORIZONTALLY, "Split horizontally"); + Append(DIVISION_MENU_SPLIT_VERTICALLY, "Split vertically"); + AppendSeparator(); + Append(DIVISION_MENU_EDIT_LEFT_EDGE, "Edit left edge"); + Append(DIVISION_MENU_EDIT_TOP_EDGE, "Edit top edge"); + } + + void OnMenu(wxCommandEvent& event); + + DECLARE_EVENT_TABLE(); +}; + +BEGIN_EVENT_TABLE(OGLPopupDivisionMenu, wxMenu) + EVT_CUSTOM_RANGE(wxEVT_COMMAND_MENU_SELECTED, + DIVISION_MENU_SPLIT_HORIZONTALLY, + DIVISION_MENU_EDIT_BOTTOM_EDGE, + OGLPopupDivisionMenu::OnMenu) +END_EVENT_TABLE() + + +void OGLPopupDivisionMenu::OnMenu(wxCommandEvent& event) { - wxDivisionShape *division = (wxDivisionShape *)menu.GetClientData(); + wxDivisionShape *division = (wxDivisionShape *)GetClientData(); switch (event.GetInt()) { case DIVISION_MENU_SPLIT_HORIZONTALLY: @@ -1630,7 +1648,7 @@ void wxDivisionShape::EditEdge(int side) GraphicsForm *form = new GraphicsForm("Containers"); int lineWidth = currentPen->GetWidth(); - + form->Add(wxMakeFormShort("Width", &lineWidth, wxFORM_DEFAULT, NULL, NULL, wxVERTICAL, 150)); form->Add(wxMakeFormString("Colour", pColour, wxFORM_CHOICE, @@ -1698,7 +1716,7 @@ void wxDivisionShape::EditEdge(int side) else if (strcmp(*pStyle, "Dot Dash") == 0) lineStyle = wxDOT_DASH; } - + wxPen *newPen = wxThePenList->FindOrCreatePen(*pColour, lineWidth, lineStyle); if (!pen) pen = wxBLACK_PEN; @@ -1716,7 +1734,9 @@ void wxDivisionShape::EditEdge(int side) // Popup menu void wxDivisionShape::PopupMenu(double x, double y) { - oglPopupDivisionMenu->SetClientData((char *)this); + wxMenu* oglPopupDivisionMenu = new OGLPopupDivisionMenu; + + oglPopupDivisionMenu->SetClientData((void *)this); if (m_leftSide) oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_LEFT_EDGE, TRUE); else @@ -1725,7 +1745,7 @@ void wxDivisionShape::PopupMenu(double x, double y) oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_TOP_EDGE, TRUE); else oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_TOP_EDGE, FALSE); - + int x1, y1; m_canvas->ViewStart(&x1, &y1); @@ -1735,10 +1755,11 @@ void wxDivisionShape::PopupMenu(double x, double y) wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); - int mouse_x = (int)(dc.LogicalToDeviceX(x - x1*unit_x)); - int mouse_y = (int)(dc.LogicalToDeviceY(y - y1*unit_y)); + int mouse_x = (int)(dc.LogicalToDeviceX((long)(x - x1*unit_x))); + int mouse_y = (int)(dc.LogicalToDeviceY((long)(y - y1*unit_y))); m_canvas->PopupMenu(oglPopupDivisionMenu, mouse_x, mouse_y); + delete oglPopupDivisionMenu; } void wxDivisionShape::SetLeftSideColour(const wxString& colour)