X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0fc1a7137cccc829a34b3527c768db7d7ac83437..d6d1892b8906380cb70c4bd3c88328f1c4851dc6:/utils/ogl/src/constrnt.cpp diff --git a/utils/ogl/src/constrnt.cpp b/utils/ogl/src/constrnt.cpp index 55542d3b94..424939420a 100644 --- a/utils/ogl/src/constrnt.cpp +++ b/utils/ogl/src/constrnt.cpp @@ -32,7 +32,7 @@ #include "constrnt.h" #include "canvas.h" -wxList OGLConstraintTypes(wxKEY_INTEGER); +wxList *OGLConstraintTypes = NULL; /* * Constraint type @@ -54,52 +54,73 @@ OGLConstraintType::~OGLConstraintType() void OGLInitializeConstraintTypes() { - OGLConstraintTypes.Append(gyCONSTRAINT_CENTRED_VERTICALLY, - new OGLConstraintType(gyCONSTRAINT_CENTRED_VERTICALLY, "Centre vertically", "centred vertically w.r.t.")); + if (!OGLConstraintTypes) + return; - OGLConstraintTypes.Append(gyCONSTRAINT_CENTRED_HORIZONTALLY, - new OGLConstraintType(gyCONSTRAINT_CENTRED_HORIZONTALLY, "Centre horizontally", "centred horizontally w.r.t.")); + OGLConstraintTypes = new wxList(wxKEY_INTEGER); - OGLConstraintTypes.Append(gyCONSTRAINT_CENTRED_BOTH, - new OGLConstraintType(gyCONSTRAINT_CENTRED_BOTH, "Centre", "centred w.r.t.")); + OGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_VERTICALLY, + new OGLConstraintType(gyCONSTRAINT_CENTRED_VERTICALLY, "Centre vertically", "centred vertically w.r.t.")); - OGLConstraintTypes.Append(gyCONSTRAINT_LEFT_OF, - new OGLConstraintType(gyCONSTRAINT_LEFT_OF, "Left of", "left of")); + OGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_HORIZONTALLY, + new OGLConstraintType(gyCONSTRAINT_CENTRED_HORIZONTALLY, "Centre horizontally", "centred horizontally w.r.t.")); - OGLConstraintTypes.Append(gyCONSTRAINT_RIGHT_OF, - new OGLConstraintType(gyCONSTRAINT_RIGHT_OF, "Right of", "right of")); + OGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_BOTH, + new OGLConstraintType(gyCONSTRAINT_CENTRED_BOTH, "Centre", "centred w.r.t.")); - OGLConstraintTypes.Append(gyCONSTRAINT_ABOVE, - new OGLConstraintType(gyCONSTRAINT_ABOVE, "Above", "above")); + OGLConstraintTypes->Append(gyCONSTRAINT_LEFT_OF, + new OGLConstraintType(gyCONSTRAINT_LEFT_OF, "Left of", "left of")); - OGLConstraintTypes.Append(gyCONSTRAINT_BELOW, - new OGLConstraintType(gyCONSTRAINT_BELOW, "Below", "below")); + OGLConstraintTypes->Append(gyCONSTRAINT_RIGHT_OF, + new OGLConstraintType(gyCONSTRAINT_RIGHT_OF, "Right of", "right of")); - // Alignment - OGLConstraintTypes.Append(gyCONSTRAINT_ALIGNED_TOP, - new OGLConstraintType(gyCONSTRAINT_ALIGNED_TOP, "Top-aligned", "aligned to the top of")); + OGLConstraintTypes->Append(gyCONSTRAINT_ABOVE, + new OGLConstraintType(gyCONSTRAINT_ABOVE, "Above", "above")); - OGLConstraintTypes.Append(gyCONSTRAINT_ALIGNED_BOTTOM, - new OGLConstraintType(gyCONSTRAINT_ALIGNED_BOTTOM, "Bottom-aligned", "aligned to the bottom of")); + OGLConstraintTypes->Append(gyCONSTRAINT_BELOW, + new OGLConstraintType(gyCONSTRAINT_BELOW, "Below", "below")); - OGLConstraintTypes.Append(gyCONSTRAINT_ALIGNED_LEFT, - new OGLConstraintType(gyCONSTRAINT_ALIGNED_LEFT, "Left-aligned", "aligned to the left of")); + // Alignment + OGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_TOP, + new OGLConstraintType(gyCONSTRAINT_ALIGNED_TOP, "Top-aligned", "aligned to the top of")); - OGLConstraintTypes.Append(gyCONSTRAINT_ALIGNED_RIGHT, - new OGLConstraintType(gyCONSTRAINT_ALIGNED_RIGHT, "Right-aligned", "aligned to the right of")); + OGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_BOTTOM, + new OGLConstraintType(gyCONSTRAINT_ALIGNED_BOTTOM, "Bottom-aligned", "aligned to the bottom of")); - // Mid-alignment - OGLConstraintTypes.Append(gyCONSTRAINT_MIDALIGNED_TOP, - new OGLConstraintType(gyCONSTRAINT_MIDALIGNED_TOP, "Top-midaligned", "centred on the top of")); + OGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_LEFT, + new OGLConstraintType(gyCONSTRAINT_ALIGNED_LEFT, "Left-aligned", "aligned to the left of")); - OGLConstraintTypes.Append(gyCONSTRAINT_MIDALIGNED_BOTTOM, - new OGLConstraintType(gyCONSTRAINT_MIDALIGNED_BOTTOM, "Bottom-midaligned", "centred on the bottom of")); + OGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_RIGHT, + new OGLConstraintType(gyCONSTRAINT_ALIGNED_RIGHT, "Right-aligned", "aligned to the right of")); - OGLConstraintTypes.Append(gyCONSTRAINT_MIDALIGNED_LEFT, - new OGLConstraintType(gyCONSTRAINT_MIDALIGNED_LEFT, "Left-midaligned", "centred on the left of")); + // Mid-alignment + OGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_TOP, + new OGLConstraintType(gyCONSTRAINT_MIDALIGNED_TOP, "Top-midaligned", "centred on the top of")); - OGLConstraintTypes.Append(gyCONSTRAINT_MIDALIGNED_RIGHT, - new OGLConstraintType(gyCONSTRAINT_MIDALIGNED_RIGHT, "Right-midaligned", "centred on the right of")); + OGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_BOTTOM, + new OGLConstraintType(gyCONSTRAINT_MIDALIGNED_BOTTOM, "Bottom-midaligned", "centred on the bottom of")); + + OGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_LEFT, + new OGLConstraintType(gyCONSTRAINT_MIDALIGNED_LEFT, "Left-midaligned", "centred on the left of")); + + OGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_RIGHT, + new OGLConstraintType(gyCONSTRAINT_MIDALIGNED_RIGHT, "Right-midaligned", "centred on the right of")); +} + +void OGLCleanUpConstraintTypes() +{ + if (!OGLConstraintTypes) + return; + + wxNode* node = OGLConstraintTypes->First(); + while (node) + { + OGLConstraintType* ct = (OGLConstraintType*) node->Data(); + delete ct; + node = node->Next(); + } + delete OGLConstraintTypes; + OGLConstraintTypes = NULL; } /* @@ -132,9 +153,9 @@ OGLConstraint::~OGLConstraint() { } -bool OGLConstraint::Equals(float a, float b) +bool OGLConstraint::Equals(double a, double b) { - float marg = 0.5; + double marg = 0.5; bool eq = ((b <= a + marg) && (b >= a - marg)); return eq; @@ -143,7 +164,7 @@ bool OGLConstraint::Equals(float a, float b) // Return TRUE if anything changed bool OGLConstraint::Evaluate() { - float maxWidth, maxHeight, minWidth, minHeight, x, y; + double maxWidth, maxHeight, minWidth, minHeight, x, y; m_constrainingObject->GetBoundingBoxMax(&maxWidth, &maxHeight); m_constrainingObject->GetBoundingBoxMin(&minWidth, &minHeight); x = m_constrainingObject->GetX(); @@ -157,30 +178,30 @@ bool OGLConstraint::Evaluate() case gyCONSTRAINT_CENTRED_VERTICALLY: { int n = m_constrainedObjects.Number(); - float totalObjectHeight = 0.0; + double totalObjectHeight = 0.0; wxNode *node = m_constrainedObjects.First(); while (node) { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); totalObjectHeight += height2; node = node->Next(); } - float startY; - float spacingY; + double startY; + double spacingY; // Check if within the constraining object... if ((totalObjectHeight + (n + 1)*m_ySpacing) <= minHeight) { - spacingY = (float)((minHeight - totalObjectHeight)/(n + 1)); - startY = (float)(y - (minHeight/2.0)); + spacingY = (double)((minHeight - totalObjectHeight)/(n + 1)); + startY = (double)(y - (minHeight/2.0)); } // Otherwise, use default spacing else { spacingY = m_ySpacing; - startY = (float)(y - ((totalObjectHeight + (n+1)*spacingY)/2.0)); + startY = (double)(y - ((totalObjectHeight + (n+1)*spacingY)/2.0)); } // Now position the objects @@ -189,15 +210,15 @@ bool OGLConstraint::Evaluate() while (node) { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - startY += (float)(spacingY + (height2/2.0)); + startY += (double)(spacingY + (height2/2.0)); if (!Equals(startY, constrainedObject->GetY())) { constrainedObject->Move(dc, constrainedObject->GetX(), startY, FALSE); changed = TRUE; } - startY += (float)(height2/2.0); + startY += (double)(height2/2.0); node = node->Next(); } return changed; @@ -205,30 +226,30 @@ bool OGLConstraint::Evaluate() case gyCONSTRAINT_CENTRED_HORIZONTALLY: { int n = m_constrainedObjects.Number(); - float totalObjectWidth = 0.0; + double totalObjectWidth = 0.0; wxNode *node = m_constrainedObjects.First(); while (node) { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); totalObjectWidth += width2; node = node->Next(); } - float startX; - float spacingX; + double startX; + double spacingX; // Check if within the constraining object... if ((totalObjectWidth + (n + 1)*m_xSpacing) <= minWidth) { - spacingX = (float)((minWidth - totalObjectWidth)/(n + 1)); - startX = (float)(x - (minWidth/2.0)); + spacingX = (double)((minWidth - totalObjectWidth)/(n + 1)); + startX = (double)(x - (minWidth/2.0)); } // Otherwise, use default spacing else { spacingX = m_xSpacing; - startX = (float)(x - ((totalObjectWidth + (n+1)*spacingX)/2.0)); + startX = (double)(x - ((totalObjectWidth + (n+1)*spacingX)/2.0)); } // Now position the objects @@ -237,15 +258,15 @@ bool OGLConstraint::Evaluate() while (node) { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - startX += (float)(spacingX + (width2/2.0)); + startX += (double)(spacingX + (width2/2.0)); if (!Equals(startX, constrainedObject->GetX())) { constrainedObject->Move(dc, startX, constrainedObject->GetY(), FALSE); changed = TRUE; } - startX += (float)(width2/2.0); + startX += (double)(width2/2.0); node = node->Next(); } return changed; @@ -253,48 +274,48 @@ bool OGLConstraint::Evaluate() case gyCONSTRAINT_CENTRED_BOTH: { int n = m_constrainedObjects.Number(); - float totalObjectWidth = 0.0; - float totalObjectHeight = 0.0; + double totalObjectWidth = 0.0; + double totalObjectHeight = 0.0; wxNode *node = m_constrainedObjects.First(); while (node) { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); totalObjectWidth += width2; totalObjectHeight += height2; node = node->Next(); } - float startX; - float spacingX; - float startY; - float spacingY; + double startX; + double spacingX; + double startY; + double spacingY; // Check if within the constraining object... if ((totalObjectWidth + (n + 1)*m_xSpacing) <= minWidth) { - spacingX = (float)((minWidth - totalObjectWidth)/(n + 1)); - startX = (float)(x - (minWidth/2.0)); + spacingX = (double)((minWidth - totalObjectWidth)/(n + 1)); + startX = (double)(x - (minWidth/2.0)); } // Otherwise, use default spacing else { spacingX = m_xSpacing; - startX = (float)(x - ((totalObjectWidth + (n+1)*spacingX)/2.0)); + startX = (double)(x - ((totalObjectWidth + (n+1)*spacingX)/2.0)); } // Check if within the constraining object... if ((totalObjectHeight + (n + 1)*m_ySpacing) <= minHeight) { - spacingY = (float)((minHeight - totalObjectHeight)/(n + 1)); - startY = (float)(y - (minHeight/2.0)); + spacingY = (double)((minHeight - totalObjectHeight)/(n + 1)); + startY = (double)(y - (minHeight/2.0)); } // Otherwise, use default spacing else { spacingY = m_ySpacing; - startY = (float)(y - ((totalObjectHeight + (n+1)*spacingY)/2.0)); + startY = (double)(y - ((totalObjectHeight + (n+1)*spacingY)/2.0)); } // Now position the objects @@ -303,10 +324,10 @@ bool OGLConstraint::Evaluate() while (node) { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - startX += (float)(spacingX + (width2/2.0)); - startY += (float)(spacingY + (height2/2.0)); + startX += (double)(spacingX + (width2/2.0)); + startY += (double)(spacingY + (height2/2.0)); if ((!Equals(startX, constrainedObject->GetX())) || (!Equals(startY, constrainedObject->GetY()))) { @@ -314,8 +335,8 @@ bool OGLConstraint::Evaluate() changed = TRUE; } - startX += (float)(width2/2.0); - startY += (float)(height2/2.0); + startX += (double)(width2/2.0); + startY += (double)(height2/2.0); node = node->Next(); } @@ -330,10 +351,10 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - float x3 = (float)(x - (minWidth/2.0) - (width2/2.0) - m_xSpacing); + double x3 = (double)(x - (minWidth/2.0) - (width2/2.0) - m_xSpacing); if (!Equals(x3, constrainedObject->GetX())) { changed = TRUE; @@ -353,10 +374,10 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - float x3 = (float)(x + (minWidth/2.0) + (width2/2.0) + m_xSpacing); + double x3 = (double)(x + (minWidth/2.0) + (width2/2.0) + m_xSpacing); if (!Equals(x3, constrainedObject->GetX())) { changed = TRUE; @@ -378,10 +399,10 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - float y3 = (float)(y - (minHeight/2.0) - (height2/2.0) - m_ySpacing); + double y3 = (double)(y - (minHeight/2.0) - (height2/2.0) - m_ySpacing); if (!Equals(y3, constrainedObject->GetY())) { changed = TRUE; @@ -401,10 +422,10 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - float y3 = (float)(y + (minHeight/2.0) + (height2/2.0) + m_ySpacing); + double y3 = (double)(y + (minHeight/2.0) + (height2/2.0) + m_ySpacing); if (!Equals(y3, constrainedObject->GetY())) { changed = TRUE; @@ -424,10 +445,10 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - float x3 = (float)(x - (minWidth/2.0) + (width2/2.0) + m_xSpacing); + double x3 = (double)(x - (minWidth/2.0) + (width2/2.0) + m_xSpacing); if (!Equals(x3, constrainedObject->GetX())) { changed = TRUE; @@ -447,10 +468,10 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - float x3 = (float)(x + (minWidth/2.0) - (width2/2.0) - m_xSpacing); + double x3 = (double)(x + (minWidth/2.0) - (width2/2.0) - m_xSpacing); if (!Equals(x3, constrainedObject->GetX())) { changed = TRUE; @@ -472,10 +493,10 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - float y3 = (float)(y - (minHeight/2.0) + (height2/2.0) + m_ySpacing); + double y3 = (double)(y - (minHeight/2.0) + (height2/2.0) + m_ySpacing); if (!Equals(y3, constrainedObject->GetY())) { changed = TRUE; @@ -495,10 +516,10 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float width2, height2; + double width2, height2; constrainedObject->GetBoundingBoxMax(&width2, &height2); - float y3 = (float)(y + (minHeight/2.0) - (height2/2.0) - m_ySpacing); + double y3 = (double)(y + (minHeight/2.0) - (height2/2.0) - m_ySpacing); if (!Equals(y3, constrainedObject->GetY())) { changed = TRUE; @@ -518,7 +539,7 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float x3 = (float)(x - (minWidth/2.0)); + double x3 = (double)(x - (minWidth/2.0)); if (!Equals(x3, constrainedObject->GetX())) { changed = TRUE; @@ -538,7 +559,7 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float x3 = (float)(x + (minWidth/2.0)); + double x3 = (double)(x + (minWidth/2.0)); if (!Equals(x3, constrainedObject->GetX())) { changed = TRUE; @@ -560,7 +581,7 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float y3 = (float)(y - (minHeight/2.0)); + double y3 = (double)(y - (minHeight/2.0)); if (!Equals(y3, constrainedObject->GetY())) { changed = TRUE; @@ -580,7 +601,7 @@ bool OGLConstraint::Evaluate() { wxShape *constrainedObject = (wxShape *)node->Data(); - float y3 = (float)(y + (minHeight/2.0)); + double y3 = (double)(y + (minHeight/2.0)); if (!Equals(y3, constrainedObject->GetY())) { changed = TRUE;