X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0fc1a7137cccc829a34b3527c768db7d7ac83437..f7ac40d158bbc88f497e29b6efcda20be7da4973:/utils/ogl/src/basic2.cpp?ds=sidebyside diff --git a/utils/ogl/src/basic2.cpp b/utils/ogl/src/basic2.cpp index bff1defda1..ba46cca6fe 100644 --- a/utils/ogl/src/basic2.cpp +++ b/utils/ogl/src/basic2.cpp @@ -10,6 +10,7 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ +#pragma implementation "basicp.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -23,11 +24,9 @@ #include #endif -#ifdef PROLOGIO #include -#endif -#if USE_IOSTREAMH +#if wxUSE_IOSTREAMH #include #else #include @@ -67,6 +66,8 @@ wxPolygonShape::wxPolygonShape() void wxPolygonShape::Create(wxList *the_points) { + ClearPoints(); + m_originalPoints = the_points; // Duplicate the list of points @@ -87,6 +88,11 @@ void wxPolygonShape::Create(wxList *the_points) } wxPolygonShape::~wxPolygonShape() +{ + ClearPoints(); +} + +void wxPolygonShape::ClearPoints() { if (m_points) { @@ -99,6 +105,7 @@ wxPolygonShape::~wxPolygonShape() node = m_points->First(); } delete m_points; + m_points = NULL; } if (m_originalPoints) { @@ -111,12 +118,13 @@ wxPolygonShape::~wxPolygonShape() node = m_originalPoints->First(); } delete m_originalPoints; + m_originalPoints = NULL; } } // Width and height. Centre of object is centre of box. -void wxPolygonShape::GetBoundingBoxMin(float *width, float *height) +void wxPolygonShape::GetBoundingBoxMin(double *width, double *height) { *width = m_boundWidth; *height = m_boundHeight; @@ -125,10 +133,10 @@ void wxPolygonShape::GetBoundingBoxMin(float *width, float *height) void wxPolygonShape::CalculateBoundingBox() { // Calculate bounding box at construction (and presumably resize) time - float left = 10000; - float right = -10000; - float top = 10000; - float bottom = -10000; + double left = 10000; + double right = -10000; + double top = 10000; + double bottom = -10000; wxNode *node = m_points->First(); while (node) @@ -153,10 +161,10 @@ void wxPolygonShape::CalculateBoundingBox() // box. void wxPolygonShape::CalculatePolygonCentre() { - float left = 10000; - float right = -10000; - float top = 10000; - float bottom = -10000; + double left = 10000; + double right = -10000; + double top = 10000; + double bottom = -10000; wxNode *node = m_points->First(); while (node) @@ -170,11 +178,11 @@ void wxPolygonShape::CalculatePolygonCentre() node = node->Next(); } - float bwidth = right - left; - float bheight = bottom - top; - - float newCentreX = (float)(left + (bwidth/2.0)); - float newCentreY = (float)(top + (bheight/2.0)); + double bwidth = right - left; + double bheight = bottom - top; + + double newCentreX = (double)(left + (bwidth/2.0)); + double newCentreY = (double)(top + (bheight/2.0)); node = m_points->First(); while (node) @@ -188,22 +196,22 @@ void wxPolygonShape::CalculatePolygonCentre() m_ypos += newCentreY; } -bool PolylineHitTest(float n, float xvec[], float yvec[], - float x1, float y1, float x2, float y2) +bool PolylineHitTest(double n, double xvec[], double yvec[], + double x1, double y1, double x2, double y2) { bool isAHit = FALSE; int i; - float lastx = xvec[0]; - float lasty = yvec[0]; + double lastx = xvec[0]; + double lasty = yvec[0]; - float min_ratio = 1.0; - float line_ratio; - float other_ratio; + double min_ratio = 1.0; + double line_ratio; + double other_ratio; // char buf[300]; for (i = 1; i < n; i++) { - check_line_intersection(x1, y1, x2, y2, lastx, lasty, xvec[i], yvec[i], + oglCheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[i], yvec[i], &line_ratio, &other_ratio); if (line_ratio != 1.0) isAHit = TRUE; @@ -216,10 +224,10 @@ bool PolylineHitTest(float n, float xvec[], float yvec[], min_ratio = line_ratio; } - // Do last (implicit) line if last and first floats are not identical + // Do last (implicit) line if last and first doubles are not identical if (!(xvec[0] == lastx && yvec[0] == lasty)) { - check_line_intersection(x1, y1, x2, y2, lastx, lasty, xvec[0], yvec[0], + oglCheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[0], yvec[0], &line_ratio, &other_ratio); if (line_ratio != 1.0) isAHit = TRUE; @@ -233,30 +241,30 @@ bool PolylineHitTest(float n, float xvec[], float yvec[], return isAHit; } -bool wxPolygonShape::HitTest(float x, float y, int *attachment, float *distance) +bool wxPolygonShape::HitTest(double x, double y, int *attachment, double *distance) { // Imagine four lines radiating from this point. If all of these lines hit the polygon, // we're inside it, otherwise we're not. Obviously we'd need more radiating lines // to be sure of correct results for very strange (concave) shapes. - float endPointsX[4]; - float endPointsY[4]; + double endPointsX[4]; + double endPointsY[4]; // North endPointsX[0] = x; - endPointsY[0] = (float)(y - 1000.0); + endPointsY[0] = (double)(y - 1000.0); // East - endPointsX[1] = (float)(x + 1000.0); + endPointsX[1] = (double)(x + 1000.0); endPointsY[1] = y; // South endPointsX[2] = x; - endPointsY[2] = (float)(y + 1000.0); + endPointsY[2] = (double)(y + 1000.0); // West - endPointsX[3] = (float)(x - 1000.0); + endPointsX[3] = (double)(x - 1000.0); endPointsY[3] = y; // Store polygon points in an array int np = m_points->Number(); - float *xpoints = new float[np]; - float *ypoints = new float[np]; + double *xpoints = new double[np]; + double *ypoints = new double[np]; wxNode *node = m_points->First(); int i = 0; while (node) @@ -294,14 +302,14 @@ bool wxPolygonShape::HitTest(float x, float y, int *attachment, float *distance) // If a hit, check the attachment points within the object. int n = GetNumberOfAttachments(); - float nearest = 999999.0; + double nearest = 999999.0; for (i = 0; i < n; i++) { - float xp, yp; - if (GetAttachmentPosition(i, &xp, &yp)) + double xp, yp; + if (GetAttachmentPositionEdge(i, &xp, &yp)) { - float l = (float)sqrt(((xp - x) * (xp - x)) + + double l = (double)sqrt(((xp - x) * (xp - x)) + ((yp - y) * (yp - y))); if (l < nearest) { @@ -317,13 +325,13 @@ bool wxPolygonShape::HitTest(float x, float y, int *attachment, float *distance) // Really need to be able to reset the shape! Otherwise, if the // points ever go to zero, we've lost it, and can't resize. -void wxPolygonShape::SetSize(float new_width, float new_height, bool recursive) +void wxPolygonShape::SetSize(double new_width, double new_height, bool recursive) { SetAttachmentSize(new_width, new_height); // Multiply all points by proportion of new size to old size - float x_proportion = (float)(fabs(new_width/m_originalWidth)); - float y_proportion = (float)(fabs(new_height/m_originalHeight)); + double x_proportion = (double)(fabs(new_width/m_originalWidth)); + double y_proportion = (double)(fabs(new_height/m_originalHeight)); wxNode *node = m_points->First(); wxNode *original_node = m_originalPoints->First(); @@ -340,8 +348,8 @@ void wxPolygonShape::SetSize(float new_width, float new_height, bool recursive) } // CalculateBoundingBox(); - m_boundWidth = (float)fabs(new_width); - m_boundHeight = (float)fabs(new_height); + m_boundWidth = (double)fabs(new_width); + m_boundHeight = (double)fabs(new_height); SetDefaultRegionSize(); } @@ -384,8 +392,8 @@ void wxPolygonShape::AddPolygonPoint(int pos) if (!node2) node2 = m_points->First(); wxRealPoint *secondPoint = (wxRealPoint *)node2->Data(); - float x = (float)((secondPoint->x - firstPoint->x)/2.0 + firstPoint->x); - float y = (float)((secondPoint->y - firstPoint->y)/2.0 + firstPoint->y); + double x = (double)((secondPoint->x - firstPoint->x)/2.0 + firstPoint->x); + double y = (double)((secondPoint->y - firstPoint->y)/2.0 + firstPoint->y); wxRealPoint *point = new wxRealPoint(x, y); if (pos >= (m_points->Number() - 1)) @@ -420,17 +428,17 @@ void wxPolygonShape::DeletePolygonPoint(int pos) } // Assume (x1, y1) is centre of box (most generally, line end at box) -bool wxPolygonShape::GetPerimeterPoint(float x1, float y1, - float x2, float y2, - float *x3, float *y3) +bool wxPolygonShape::GetPerimeterPoint(double x1, double y1, + double x2, double y2, + double *x3, double *y3) { int n = m_points->Number(); // First check for situation where the line is vertical, // and we would want to connect to a point on that vertical -- - // find_end_for_polyline can't cope with this (the arrow + // oglFindEndForPolyline can't cope with this (the arrow // gets drawn to the wrong place). - if ((!m_attachmentMode) && (x1 == x2)) + if ((m_attachmentMode == ATTACHMENT_MODE_NONE) && (x1 == x2)) { // Look for the point we'd be connecting to. This is // a heuristic... @@ -457,8 +465,8 @@ bool wxPolygonShape::GetPerimeterPoint(float x1, float y1, } } - float *xpoints = new float[n]; - float *ypoints = new float[n]; + double *xpoints = new double[n]; + double *ypoints = new double[n]; wxNode *node = m_points->First(); int i = 0; @@ -470,17 +478,12 @@ bool wxPolygonShape::GetPerimeterPoint(float x1, float y1, node = node->Next(); i ++; } -/* - wxRealPoint *point = (wxRealPoint *)m_points->First()->Data(); - xpoints[i] = point->x + m_xpos; - ypoints[i] = point->y + m_ypos; -*/ - find_end_for_polyline(n, xpoints, ypoints, + oglFindEndForPolyline(n, xpoints, ypoints, x1, y1, x2, y2, x3, y3); - delete xpoints; - delete ypoints; + delete[] xpoints; + delete[] ypoints; return TRUE; } @@ -493,48 +496,51 @@ void wxPolygonShape::OnDraw(wxDC& dc) for (i = 0; i < n; i++) { wxRealPoint* point = (wxRealPoint*) m_points->Nth(i)->Data(); - intPoints[i].x = (int) point->x; - intPoints[i].y = (int) point->y; + intPoints[i].x = WXROUND(point->x); + intPoints[i].y = WXROUND(point->y); } if (m_shadowMode != SHADOW_NONE) { if (m_shadowBrush) - dc.SetBrush(m_shadowBrush); - dc.SetPen(transparent_pen); + dc.SetBrush(* m_shadowBrush); + dc.SetPen(* g_oglTransparentPen); - dc.DrawPolygon(n, intPoints, m_xpos + m_shadowOffsetX, m_ypos + m_shadowOffsetY); + dc.DrawPolygon(n, intPoints, WXROUND(m_xpos + m_shadowOffsetX), WXROUND(m_ypos + m_shadowOffsetY)); } if (m_pen) { if (m_pen->GetWidth() == 0) - dc.SetPen(transparent_pen); + dc.SetPen(* g_oglTransparentPen); else - dc.SetPen(m_pen); + dc.SetPen(* m_pen); } if (m_brush) - dc.SetBrush(m_brush); - dc.DrawPolygon(n, intPoints, m_xpos, m_ypos); + dc.SetBrush(* m_brush); + dc.DrawPolygon(n, intPoints, WXROUND(m_xpos), WXROUND(m_ypos)); delete[] intPoints; } -void wxPolygonShape::OnDrawOutline(wxDC& dc, float x, float y, float w, float h) +void wxPolygonShape::OnDrawOutline(wxDC& dc, double x, double y, double w, double h) { - dc.SetBrush(wxTRANSPARENT_BRUSH); + dc.SetBrush(* wxTRANSPARENT_BRUSH); + // Multiply all points by proportion of new size to old size + double x_proportion = (double)(fabs(w/m_originalWidth)); + double y_proportion = (double)(fabs(h/m_originalHeight)); - int n = m_points->Number(); + int n = m_originalPoints->Number(); wxPoint *intPoints = new wxPoint[n]; int i; for (i = 0; i < n; i++) { - wxRealPoint* point = (wxRealPoint*) m_points->Nth(i)->Data(); - intPoints[i].x = (int) point->x; - intPoints[i].y = (int) point->y; + wxRealPoint* point = (wxRealPoint*) m_originalPoints->Nth(i)->Data(); + intPoints[i].x = WXROUND(x_proportion * point->x); + intPoints[i].y = WXROUND(y_proportion * point->y); } - dc.DrawPolygon(n, intPoints, x, y); -// wxShape::OnDrawOutline(x, y, w, h); + dc.DrawPolygon(n, intPoints, WXROUND(x), WXROUND(y)); + delete[] intPoints; } // Make as many control points as there are vertices. @@ -550,62 +556,6 @@ void wxPolygonShape::MakeControlPoints() m_controlPoints.Append(control); node = node->Next(); } - -/* - float maxX, maxY, minX, minY; - - GetBoundingBoxMax(&maxX, &maxY); - GetBoundingBoxMin(&minX, &minY); - - float widthMin = (float)(minX + CONTROL_POINT_SIZE + 2); - float heightMin = (float)(minY + CONTROL_POINT_SIZE + 2); - - // Offsets from main object - float top = (float)(- (heightMin / 2.0)); - float bottom = (float)(heightMin / 2.0 + (maxY - minY)); - float left = (float)(- (widthMin / 2.0)); - float right = (float)(widthMin / 2.0 + (maxX - minX)); - - wxControlPoint *control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, left, top, - CONTROL_POINT_DIAGONAL); - m_canvas->AddShape(control); - m_controlPoints.Append(control); - - control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, 0, top, - CONTROL_POINT_VERTICAL); - m_canvas->AddShape(control); - m_controlPoints.Append(control); - - control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, right, top, - CONTROL_POINT_DIAGONAL); - m_canvas->AddShape(control); - m_controlPoints.Append(control); - - control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, right, 0, - CONTROL_POINT_HORIZONTAL); - m_canvas->AddShape(control); - m_controlPoints.Append(control); - - control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, right, bottom, - CONTROL_POINT_DIAGONAL); - m_canvas->AddShape(control); - m_controlPoints.Append(control); - - control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, 0, bottom, - CONTROL_POINT_VERTICAL); - m_canvas->AddShape(control); - m_controlPoints.Append(control); - - control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, left, bottom, - CONTROL_POINT_DIAGONAL); - m_canvas->AddShape(control); - m_controlPoints.Append(control); - - control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, left, 0, - CONTROL_POINT_HORIZONTAL); - m_canvas->AddShape(control); - m_controlPoints.Append(control); -*/ } void wxPolygonShape::ResetControlPoints() @@ -624,70 +574,26 @@ void wxPolygonShape::ResetControlPoints() node = node->Next(); controlPointNode = controlPointNode->Next(); } -/* - - if (m_controlPoints.Number() < 1) - return; - - float maxX, maxY, minX, minY; - - GetBoundingBoxMax(&maxX, &maxY); - GetBoundingBoxMin(&minX, &minY); - - float widthMin = (float)(minX + CONTROL_POINT_SIZE + 2); - float heightMin = (float)(minY + CONTROL_POINT_SIZE + 2); - - // Offsets from main object - float top = (float)(- (heightMin / 2.0)); - float bottom = (float)(heightMin / 2.0 + (maxY - minY)); - float left = (float)(- (widthMin / 2.0)); - float right = (float)(widthMin / 2.0 + (maxX - minX)); - - wxNode *node = m_controlPoints.First(); - wxControlPoint *control = (wxControlPoint *)node->Data(); - control->xoffset = left; control->yoffset = top; - - node = node->Next(); control = (wxControlPoint *)node->Data(); - control->xoffset = 0; control->yoffset = top; - - node = node->Next(); control = (wxControlPoint *)node->Data(); - control->xoffset = right; control->yoffset = top; - - node = node->Next(); control = (wxControlPoint *)node->Data(); - control->xoffset = right; control->yoffset = 0; - - node = node->Next(); control = (wxControlPoint *)node->Data(); - control->xoffset = right; control->yoffset = bottom; - - node = node->Next(); control = (wxControlPoint *)node->Data(); - control->xoffset = 0; control->yoffset = bottom; - - node = node->Next(); control = (wxControlPoint *)node->Data(); - control->xoffset = left; control->yoffset = bottom; - - node = node->Next(); control = (wxControlPoint *)node->Data(); - control->xoffset = left; control->yoffset = 0; -*/ } #ifdef PROLOGIO -void wxPolygonShape::WritePrologAttributes(wxExpr *clause) +void wxPolygonShape::WriteAttributes(wxExpr *clause) { - wxShape::WritePrologAttributes(clause); + wxShape::WriteAttributes(clause); clause->AddAttributeValue("x", m_xpos); clause->AddAttributeValue("y", m_ypos); // Make a list of lists for the coordinates - wxExpr *list = new wxExpr(PrologList); + wxExpr *list = new wxExpr(wxExprList); wxNode *node = m_points->First(); while (node) { wxRealPoint *point = (wxRealPoint *)node->Data(); - wxExpr *point_list = new wxExpr(PrologList); - wxExpr *x_expr = new wxExpr((float)point->x); - wxExpr *y_expr = new wxExpr((float)point->y); + 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); point_list->Append(y_expr); @@ -698,14 +604,14 @@ void wxPolygonShape::WritePrologAttributes(wxExpr *clause) clause->AddAttributeValue("points", list); // Save the original (unscaled) points - list = new wxExpr(PrologList); + list = new wxExpr(wxExprList); node = m_originalPoints->First(); while (node) { wxRealPoint *point = (wxRealPoint *)node->Data(); - wxExpr *point_list = new wxExpr(PrologList); - wxExpr *x_expr = new wxExpr((float) point->x); - wxExpr *y_expr = new wxExpr((float) point->y); + 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); point_list->Append(y_expr); list->Append(point_list); @@ -715,9 +621,9 @@ void wxPolygonShape::WritePrologAttributes(wxExpr *clause) clause->AddAttributeValue("m_originalPoints", list); } -void wxPolygonShape::ReadPrologAttributes(wxExpr *clause) +void wxPolygonShape::ReadAttributes(wxExpr *clause) { - wxShape::ReadPrologAttributes(clause); + wxShape::ReadAttributes(clause); // Read a list of lists m_points = new wxList; @@ -727,8 +633,8 @@ void wxPolygonShape::ReadPrologAttributes(wxExpr *clause) clause->AssignAttributeValue("points", &points_list); // If no points_list, don't crash!! Assume a diamond instead. - float the_height = 100.0; - float the_width = 100.0; + double the_height = 100.0; + double the_width = 100.0; if (!points_list) { wxRealPoint *point = new wxRealPoint(0.0, (-the_height/2)); @@ -758,7 +664,7 @@ void wxPolygonShape::ReadPrologAttributes(wxExpr *clause) wxExpr *yexpr = xexpr->next; long y = yexpr->IntegerValue(); - wxRealPoint *point = new wxRealPoint((float)x, (float)y); + wxRealPoint *point = new wxRealPoint((double)x, (double)y); m_points->Append((wxObject*) point); node = node->next; @@ -792,10 +698,10 @@ void wxPolygonShape::ReadPrologAttributes(wxExpr *clause) else { wxExpr *node = points_list->value.first; - float min_x = 1000; - float min_y = 1000; - float max_x = -1000; - float max_y = -1000; + double min_x = 1000; + double min_y = 1000; + double max_x = -1000; + double max_y = -1000; while (node) { wxExpr *xexpr = node->value.first; @@ -804,17 +710,17 @@ void wxPolygonShape::ReadPrologAttributes(wxExpr *clause) wxExpr *yexpr = xexpr->next; long y = yexpr->IntegerValue(); - wxRealPoint *point = new wxRealPoint((float)x, (float)y); + wxRealPoint *point = new wxRealPoint((double)x, (double)y); m_originalPoints->Append((wxObject*) point); if (x < min_x) - min_x = (float)x; + min_x = (double)x; if (y < min_y) - min_y = (float)y; + min_y = (double)y; if (x > max_x) - max_x = (float)x; + max_x = (double)x; if (y > max_y) - max_y = (float)y; + max_y = (double)y; node = node->next; } @@ -826,26 +732,25 @@ void wxPolygonShape::ReadPrologAttributes(wxExpr *clause) } #endif -void wxPolygonShape::Copy(wxPolygonShape& copy) +void wxPolygonShape::Copy(wxShape& copy) { wxShape::Copy(copy); - if (copy.m_points) - delete copy.m_points; + wxASSERT( copy.IsKindOf(CLASSINFO(wxPolygonShape)) ); - copy.m_points = new wxList; + wxPolygonShape& polyCopy = (wxPolygonShape&) copy; - if (copy.m_originalPoints) - delete copy.m_originalPoints; + polyCopy.ClearPoints(); - copy.m_originalPoints = new wxList; + polyCopy.m_points = new wxList; + polyCopy.m_originalPoints = new wxList; wxNode *node = m_points->First(); while (node) { wxRealPoint *point = (wxRealPoint *)node->Data(); wxRealPoint *new_point = new wxRealPoint(point->x, point->y); - copy.m_points->Append((wxObject*) new_point); + polyCopy.m_points->Append((wxObject*) new_point); node = node->Next(); } node = m_originalPoints->First(); @@ -853,23 +758,16 @@ void wxPolygonShape::Copy(wxPolygonShape& copy) { wxRealPoint *point = (wxRealPoint *)node->Data(); wxRealPoint *new_point = new wxRealPoint(point->x, point->y); - copy.m_originalPoints->Append((wxObject*) new_point); + polyCopy.m_originalPoints->Append((wxObject*) new_point); node = node->Next(); } - copy.m_boundWidth = m_boundWidth; - copy.m_boundHeight = m_boundHeight; - copy.m_originalWidth = m_originalWidth; - copy.m_originalHeight = m_originalHeight; + polyCopy.m_boundWidth = m_boundWidth; + polyCopy.m_boundHeight = m_boundHeight; + polyCopy.m_originalWidth = m_originalWidth; + polyCopy.m_originalHeight = m_originalHeight; } -wxShape *wxPolygonShape::PrivateCopy() -{ - wxPolygonShape *obj = new wxPolygonShape; - Copy(*obj); - return obj; -} - -int wxPolygonShape::GetNumberOfAttachments() +int wxPolygonShape::GetNumberOfAttachments() const { int maxN = (m_points ? (m_points->Number() - 1) : 0); wxNode *node = m_attachmentPoints.First(); @@ -883,10 +781,10 @@ int wxPolygonShape::GetNumberOfAttachments() return maxN+1;; } -bool wxPolygonShape::GetAttachmentPosition(int attachment, float *x, float *y, +bool wxPolygonShape::GetAttachmentPosition(int attachment, double *x, double *y, int nth, int no_arcs, wxLineShape *line) { - if (m_attachmentMode && m_points && attachment < m_points->Number()) + if ((m_attachmentMode == ATTACHMENT_MODE_EDGE) && m_points && attachment < m_points->Number()) { wxRealPoint *point = (wxRealPoint *)m_points->Nth(attachment)->Data(); *x = point->x + m_xpos; @@ -916,11 +814,58 @@ bool wxPolygonShape::AttachmentIsValid(int attachment) return FALSE; } +// Rotate about the given axis by the given amount in radians +void wxPolygonShape::Rotate(double x, double y, double theta) +{ + double actualTheta = theta-m_rotation; + + // Rotate attachment points + double sinTheta = (double)sin(actualTheta); + double cosTheta = (double)cos(actualTheta); + wxNode *node = m_attachmentPoints.First(); + while (node) + { + wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data(); + double x1 = point->m_x; + double y1 = point->m_y; + point->m_x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta; + point->m_y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta; + node = node->Next(); + } + + node = m_points->First(); + while (node) + { + wxRealPoint *point = (wxRealPoint *)node->Data(); + double x1 = point->x; + double y1 = point->y; + point->x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta; + point->y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta; + node = node->Next(); + } + node = m_originalPoints->First(); + while (node) + { + wxRealPoint *point = (wxRealPoint *)node->Data(); + double x1 = point->x; + double y1 = point->y; + point->x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta; + point->y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta; + node = node->Next(); + } + + m_rotation = theta; + + CalculatePolygonCentre(); + CalculateBoundingBox(); + ResetControlPoints(); +} + // Rectangle object IMPLEMENT_DYNAMIC_CLASS(wxRectangleShape, wxShape) -wxRectangleShape::wxRectangleShape(float w, float h) +wxRectangleShape::wxRectangleShape(double w, double h) { m_width = w; m_height = h; m_cornerRadius = 0.0; SetDefaultRegionSize(); @@ -928,73 +873,73 @@ wxRectangleShape::wxRectangleShape(float w, float h) void wxRectangleShape::OnDraw(wxDC& dc) { - float x1 = (float)(m_xpos - m_width/2.0); - float y1 = (float)(m_ypos - m_height/2.0); + double x1 = (double)(m_xpos - m_width/2.0); + double y1 = (double)(m_ypos - m_height/2.0); if (m_shadowMode != SHADOW_NONE) { if (m_shadowBrush) - dc.SetBrush(m_shadowBrush); - dc.SetPen(transparent_pen); + dc.SetBrush(* m_shadowBrush); + dc.SetPen(* g_oglTransparentPen); if (m_cornerRadius != 0.0) - dc.DrawRoundedRectangle(x1 + m_shadowOffsetX, y1 + m_shadowOffsetY, - m_width, m_height, m_cornerRadius); + dc.DrawRoundedRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY), + WXROUND(m_width), WXROUND(m_height), m_cornerRadius); else - dc.DrawRectangle(x1 + m_shadowOffsetX, y1 + m_shadowOffsetY, m_width, m_height); + dc.DrawRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY), WXROUND(m_width), WXROUND(m_height)); } if (m_pen) { if (m_pen->GetWidth() == 0) - dc.SetPen(transparent_pen); + dc.SetPen(* g_oglTransparentPen); else - dc.SetPen(m_pen); + dc.SetPen(* m_pen); } if (m_brush) - dc.SetBrush(m_brush); + dc.SetBrush(* m_brush); if (m_cornerRadius != 0.0) - dc.DrawRoundedRectangle(x1, y1, m_width, m_height, m_cornerRadius); + dc.DrawRoundedRectangle(WXROUND(x1), WXROUND(y1), WXROUND(m_width), WXROUND(m_height), m_cornerRadius); else - dc.DrawRectangle(x1, y1, m_width, m_height); + dc.DrawRectangle(WXROUND(x1), WXROUND(y1), WXROUND(m_width), WXROUND(m_height)); } -void wxRectangleShape::GetBoundingBoxMin(float *the_width, float *the_height) +void wxRectangleShape::GetBoundingBoxMin(double *the_width, double *the_height) { *the_width = m_width; *the_height = m_height; } -void wxRectangleShape::SetSize(float x, float y, bool recursive) +void wxRectangleShape::SetSize(double x, double y, bool recursive) { SetAttachmentSize(x, y); - m_width = (float)wxMax(x, 1.0); - m_height = (float)wxMax(y, 1.0); + m_width = (double)wxMax(x, 1.0); + m_height = (double)wxMax(y, 1.0); SetDefaultRegionSize(); } -void wxRectangleShape::SetCornerRadius(float rad) +void wxRectangleShape::SetCornerRadius(double rad) { m_cornerRadius = rad; } // Assume (x1, y1) is centre of box (most generally, line end at box) -bool wxRectangleShape::GetPerimeterPoint(float x1, float y1, - float x2, float y2, - float *x3, float *y3) +bool wxRectangleShape::GetPerimeterPoint(double x1, double y1, + double x2, double y2, + double *x3, double *y3) { - float bound_x, bound_y; + double bound_x, bound_y; GetBoundingBoxMax(&bound_x, &bound_y); - find_end_for_box(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3); + oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3); return TRUE; } #ifdef PROLOGIO -void wxRectangleShape::WritePrologAttributes(wxExpr *clause) +void wxRectangleShape::WriteAttributes(wxExpr *clause) { - wxShape::WritePrologAttributes(clause); + wxShape::WriteAttributes(clause); clause->AddAttributeValue("x", m_xpos); clause->AddAttributeValue("y", m_ypos); @@ -1004,9 +949,9 @@ void wxRectangleShape::WritePrologAttributes(wxExpr *clause) clause->AddAttributeValue("corner", m_cornerRadius); } -void wxRectangleShape::ReadPrologAttributes(wxExpr *clause) +void wxRectangleShape::ReadAttributes(wxExpr *clause) { - wxShape::ReadPrologAttributes(clause); + wxShape::ReadAttributes(clause); clause->AssignAttributeValue("width", &m_width); clause->AssignAttributeValue("height", &m_height); clause->AssignAttributeValue("corner", &m_cornerRadius); @@ -1020,149 +965,37 @@ void wxRectangleShape::ReadPrologAttributes(wxExpr *clause) } #endif -void wxRectangleShape::Copy(wxRectangleShape& copy) +void wxRectangleShape::Copy(wxShape& copy) { wxShape::Copy(copy); - copy.m_width = m_width; - copy.m_height = m_height; - copy.m_cornerRadius = m_cornerRadius; -} -wxShape *wxRectangleShape::PrivateCopy() -{ - wxRectangleShape *obj = new wxRectangleShape(0.0, 0.0); - Copy(*obj); - return obj; -} + wxASSERT( copy.IsKindOf(CLASSINFO(wxRectangleShape)) ); + wxRectangleShape& rectCopy = (wxRectangleShape&) copy; + rectCopy.m_width = m_width; + rectCopy.m_height = m_height; + rectCopy.m_cornerRadius = m_cornerRadius; +} -int wxRectangleShape::GetNumberOfAttachments() +int wxRectangleShape::GetNumberOfAttachments() const { return wxShape::GetNumberOfAttachments(); } + // There are 4 attachment points on a rectangle - 0 = top, 1 = right, 2 = bottom, // 3 = left. -bool wxRectangleShape::GetAttachmentPosition(int attachment, float *x, float *y, +bool wxRectangleShape::GetAttachmentPosition(int attachment, double *x, double *y, int nth, int no_arcs, wxLineShape *line) { - if (m_attachmentMode) - { - float top = (float)(m_ypos + m_height/2.0); - float bottom = (float)(m_ypos - m_height/2.0); - float left = (float)(m_xpos - m_width/2.0); - float right = (float)(m_xpos + m_width/2.0); - - bool isEnd = (line && line->IsEnd(this)); - - switch (attachment) - { - case 0: - { - if (m_spaceAttachments) - { - if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE)) - { - // Align line according to the next handle along - wxRealPoint *point = line->GetNextControlPoint(this); - if (point->x < left) - *x = left; - else if (point->x > right) - *x = right; - else - *x = point->x; - } - else - *x = left + (nth + 1)*m_width/(no_arcs + 1); - } - else *x = m_xpos; - - *y = bottom; - break; - } - case 1: - { - *x = right; - if (m_spaceAttachments) - { - if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE)) - { - // Align line according to the next handle along - wxRealPoint *point = line->GetNextControlPoint(this); - if (point->y < bottom) - *y = bottom; - else if (point->y > top) - *y = top; - else - *y = point->y; - } - else - *y = bottom + (nth + 1)*m_height/(no_arcs + 1); - } - else *y = m_ypos; - break; - } - case 2: - { - if (m_spaceAttachments) - { - if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE)) - { - // Align line according to the next handle along - wxRealPoint *point = line->GetNextControlPoint(this); - if (point->x < left) - *x = left; - else if (point->x > right) - *x = right; - else - *x = point->x; - } - else - *x = left + (nth + 1)*m_width/(no_arcs + 1); - } - else *x = m_xpos; - *y = top; - break; - } - case 3: - { - *x = left; - if (m_spaceAttachments) - { - if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE)) - { - // Align line according to the next handle along - wxRealPoint *point = line->GetNextControlPoint(this); - if (point->y < bottom) - *y = bottom; - else if (point->y > top) - *y = top; - else - *y = point->y; - } - else - *y = bottom + (nth + 1)*m_height/(no_arcs + 1); - } - else *y = m_ypos; - break; - } - default: - { - return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); - break; - } - } - return TRUE; - } - else - { *x = m_xpos; *y = m_ypos; return TRUE; } + return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); } // Text object (no box) IMPLEMENT_DYNAMIC_CLASS(wxTextShape, wxRectangleShape) -wxTextShape::wxTextShape(float width, float height): +wxTextShape::wxTextShape(double width, double height): wxRectangleShape(width, height) { } @@ -1171,22 +1004,15 @@ void wxTextShape::OnDraw(wxDC& dc) { } -wxShape *wxTextShape::PrivateCopy() -{ - wxTextShape *obj = new wxTextShape(0.0, 0.0); - Copy(*obj); - return obj; -} - -void wxTextShape::Copy(wxTextShape& copy) +void wxTextShape::Copy(wxShape& copy) { wxRectangleShape::Copy(copy); } #ifdef PROLOGIO -void wxTextShape::WritePrologAttributes(wxExpr *clause) +void wxTextShape::WriteAttributes(wxExpr *clause) { - wxRectangleShape::WritePrologAttributes(clause); + wxRectangleShape::WriteAttributes(clause); } #endif @@ -1194,26 +1020,26 @@ void wxTextShape::WritePrologAttributes(wxExpr *clause) IMPLEMENT_DYNAMIC_CLASS(wxEllipseShape, wxShape) -wxEllipseShape::wxEllipseShape(float w, float h) +wxEllipseShape::wxEllipseShape(double w, double h) { m_width = w; m_height = h; SetDefaultRegionSize(); } -void wxEllipseShape::GetBoundingBoxMin(float *w, float *h) +void wxEllipseShape::GetBoundingBoxMin(double *w, double *h) { *w = m_width; *h = m_height; } -bool wxEllipseShape::GetPerimeterPoint(float x1, float y1, - float x2, float y2, - float *x3, float *y3) +bool wxEllipseShape::GetPerimeterPoint(double x1, double y1, + double x2, double y2, + double *x3, double *y3) { - float bound_x, bound_y; + double bound_x, bound_y; GetBoundingBoxMax(&bound_x, &bound_y); -// find_end_for_box(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3); - draw_arc_to_ellipse(m_xpos, m_ypos, bound_x, bound_y, x2, y2, x1, y1, x3, y3); +// oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3); + oglDrawArcToEllipse(m_xpos, m_ypos, bound_x, bound_y, x2, y2, x1, y1, x3, y3); return TRUE; } @@ -1223,26 +1049,26 @@ void wxEllipseShape::OnDraw(wxDC& dc) if (m_shadowMode != SHADOW_NONE) { if (m_shadowBrush) - dc.SetBrush(m_shadowBrush); - dc.SetPen(transparent_pen); - dc.DrawEllipse((m_xpos - GetWidth()/2) + m_shadowOffsetX, - (m_ypos - GetHeight()/2) + m_shadowOffsetY, - GetWidth(), GetHeight()); + dc.SetBrush(* m_shadowBrush); + dc.SetPen(* g_oglTransparentPen); + dc.DrawEllipse((long) ((m_xpos - GetWidth()/2) + m_shadowOffsetX), + (long) ((m_ypos - GetHeight()/2) + m_shadowOffsetY), + (long) GetWidth(), (long) GetHeight()); } if (m_pen) { if (m_pen->GetWidth() == 0) - dc.SetPen(transparent_pen); + dc.SetPen(* g_oglTransparentPen); else - dc.SetPen(m_pen); + dc.SetPen(* m_pen); } if (m_brush) - dc.SetBrush(m_brush); - dc.DrawEllipse((m_xpos - GetWidth()/2), (m_ypos - GetHeight()/2), GetWidth(), GetHeight()); + dc.SetBrush(* m_brush); + dc.DrawEllipse((long) (m_xpos - GetWidth()/2), (long) (m_ypos - GetHeight()/2), (long) GetWidth(), (long) GetHeight()); } -void wxEllipseShape::SetSize(float x, float y, bool recursive) +void wxEllipseShape::SetSize(double x, double y, bool recursive) { SetAttachmentSize(x, y); m_width = x; @@ -1251,9 +1077,9 @@ void wxEllipseShape::SetSize(float x, float y, bool recursive) } #ifdef PROLOGIO -void wxEllipseShape::WritePrologAttributes(wxExpr *clause) +void wxEllipseShape::WriteAttributes(wxExpr *clause) { - wxShape::WritePrologAttributes(clause); + wxShape::WriteAttributes(clause); clause->AddAttributeValue("x", m_xpos); clause->AddAttributeValue("y", m_ypos); @@ -1261,9 +1087,9 @@ void wxEllipseShape::WritePrologAttributes(wxExpr *clause) clause->AddAttributeValue("height", m_height); } -void wxEllipseShape::ReadPrologAttributes(wxExpr *clause) +void wxEllipseShape::ReadAttributes(wxExpr *clause) { - wxShape::ReadPrologAttributes(clause); + wxShape::ReadAttributes(clause); clause->AssignAttributeValue("width", &m_width); clause->AssignAttributeValue("height", &m_height); @@ -1276,38 +1102,41 @@ void wxEllipseShape::ReadPrologAttributes(wxExpr *clause) } #endif -void wxEllipseShape::Copy(wxEllipseShape& copy) +void wxEllipseShape::Copy(wxShape& copy) { wxShape::Copy(copy); - copy.m_width = m_width; - copy.m_height = m_height; -} + wxASSERT( copy.IsKindOf(CLASSINFO(wxEllipseShape)) ); -wxShape *wxEllipseShape::PrivateCopy() -{ - wxEllipseShape *obj = new wxEllipseShape(0.0, 0.0); - Copy(*obj); - return obj; + wxEllipseShape& ellipseCopy = (wxEllipseShape&) copy; + + ellipseCopy.m_width = m_width; + ellipseCopy.m_height = m_height; } -int wxEllipseShape::GetNumberOfAttachments() +int wxEllipseShape::GetNumberOfAttachments() const { return wxShape::GetNumberOfAttachments(); } // There are 4 attachment points on an ellipse - 0 = top, 1 = right, 2 = bottom, // 3 = left. -bool wxEllipseShape::GetAttachmentPosition(int attachment, float *x, float *y, +bool wxEllipseShape::GetAttachmentPosition(int attachment, double *x, double *y, int nth, int no_arcs, wxLineShape *line) { - if (m_attachmentMode) + if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING) + return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); + + if (m_attachmentMode != ATTACHMENT_MODE_NONE) { - float top = (float)(m_ypos + m_height/2.0); - float bottom = (float)(m_ypos - m_height/2.0); - float left = (float)(m_xpos - m_width/2.0); - float right = (float)(m_xpos + m_width/2.0); - switch (attachment) + double top = (double)(m_ypos + m_height/2.0); + double bottom = (double)(m_ypos - m_height/2.0); + double left = (double)(m_xpos - m_width/2.0); + double right = (double)(m_xpos + m_width/2.0); + + int physicalAttachment = LogicalToPhysicalAttachment(attachment); + + switch (physicalAttachment) { case 0: { @@ -1318,7 +1147,7 @@ bool wxEllipseShape::GetAttachmentPosition(int attachment, float *x, float *y, // We now have the point on the bounding box: but get the point on the ellipse // by imagining a vertical line from (*x, m_ypos - m_height- 500) to (*x, m_ypos) intersecting // the ellipse. - draw_arc_to_ellipse(m_xpos, m_ypos, m_width, m_height, *x, (float)(m_ypos-m_height-500), *x, m_ypos, x, y); + oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, *x, (double)(m_ypos-m_height-500), *x, m_ypos, x, y); break; } case 1: @@ -1327,7 +1156,7 @@ bool wxEllipseShape::GetAttachmentPosition(int attachment, float *x, float *y, if (m_spaceAttachments) *y = bottom + (nth + 1)*m_height/(no_arcs + 1); else *y = m_ypos; - draw_arc_to_ellipse(m_xpos, m_ypos, m_width, m_height, (float)(m_xpos+m_width+500), *y, m_xpos, *y, x, y); + oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, (double)(m_xpos+m_width+500), *y, m_xpos, *y, x, y); break; } case 2: @@ -1336,7 +1165,7 @@ bool wxEllipseShape::GetAttachmentPosition(int attachment, float *x, float *y, *x = left + (nth + 1)*m_width/(no_arcs + 1); else *x = m_xpos; *y = bottom; - draw_arc_to_ellipse(m_xpos, m_ypos, m_width, m_height, *x, (float)(m_ypos+m_height+500), *x, m_ypos, x, y); + oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, *x, (double)(m_ypos+m_height+500), *x, m_ypos, x, y); break; } case 3: @@ -1345,7 +1174,7 @@ bool wxEllipseShape::GetAttachmentPosition(int attachment, float *x, float *y, if (m_spaceAttachments) *y = bottom + (nth + 1)*m_height/(no_arcs + 1); else *y = m_ypos; - draw_arc_to_ellipse(m_xpos, m_ypos, m_width, m_height, (float)(m_xpos-m_width-500), *y, m_xpos, *y, x, y); + oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, (double)(m_xpos-m_width-500), *y, m_xpos, *y, x, y); break; } default: @@ -1364,27 +1193,21 @@ bool wxEllipseShape::GetAttachmentPosition(int attachment, float *x, float *y, // Circle object IMPLEMENT_DYNAMIC_CLASS(wxCircleShape, wxEllipseShape) -wxCircleShape::wxCircleShape(float diameter):wxEllipseShape(diameter, diameter) -{ -} - -wxShape *wxCircleShape::PrivateCopy() +wxCircleShape::wxCircleShape(double diameter):wxEllipseShape(diameter, diameter) { - wxCircleShape *obj = new wxCircleShape(0.0); - Copy(*obj); - return obj; + SetMaintainAspectRatio(TRUE); } -void wxCircleShape::Copy(wxCircleShape& copy) +void wxCircleShape::Copy(wxShape& copy) { wxEllipseShape::Copy(copy); } -bool wxCircleShape::GetPerimeterPoint(float x1, float y1, - float x2, float y2, - float *x3, float *y3) +bool wxCircleShape::GetPerimeterPoint(double x1, double y1, + double x2, double y2, + double *x3, double *y3) { - find_end_for_circle(m_width/2, + oglFindEndForCircle(m_width/2, m_xpos, m_ypos, // Centre of circle x2, y2, // Other end of line x3, y3); @@ -1394,16 +1217,25 @@ bool wxCircleShape::GetPerimeterPoint(float x1, float y1, // Control points +double wxControlPoint::sm_controlPointDragStartX = 0.0; +double wxControlPoint::sm_controlPointDragStartY = 0.0; +double wxControlPoint::sm_controlPointDragStartWidth = 0.0; +double wxControlPoint::sm_controlPointDragStartHeight = 0.0; +double wxControlPoint::sm_controlPointDragEndWidth = 0.0; +double wxControlPoint::sm_controlPointDragEndHeight = 0.0; +double wxControlPoint::sm_controlPointDragPosX = 0.0; +double wxControlPoint::sm_controlPointDragPosY = 0.0; + IMPLEMENT_DYNAMIC_CLASS(wxControlPoint, wxRectangleShape) -wxControlPoint::wxControlPoint(wxShapeCanvas *theCanvas, wxShape *object, float size, float the_xoffset, float the_yoffset, int the_type):wxRectangleShape(size, size) +wxControlPoint::wxControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size, double the_xoffset, double the_yoffset, int the_type):wxRectangleShape(size, size) { m_canvas = theCanvas; m_shape = object; m_xoffset = the_xoffset; m_yoffset = the_yoffset; m_type = the_type; - SetPen(black_foreground_pen); + SetPen(g_oglBlackForegroundPen); SetBrush(wxBLACK_BRUSH); m_oldCursor = NULL; m_visible = TRUE; @@ -1431,25 +1263,41 @@ void wxControlPoint::OnErase(wxDC& dc) wxRectangleShape::OnErase(dc); } -/* - * Store original top-left, bottom-right coordinates - * in case we're doing non-vertical resizing. - */ -static float controlPointDragStartX = 0.0; -static float controlPointDragStartY = 0.0; -static float controlPointDragStartWidth = 0.0; -static float controlPointDragStartHeight = 0.0; -static float controlPointDragEndWidth = 0.0; -static float controlPointDragEndHeight = 0.0; -static float controlPointDragPosX = 0.0; -static float controlPointDragPosY = 0.0; - // Implement resizing of canvas object -void wxControlPoint::OnDragLeft(bool draw, float x, float y, int keys, int attachment) +void wxControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment) { - float bound_x; - float bound_y; - m_shape->GetBoundingBoxMin(&bound_x, &bound_y); + m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment); +} + +void wxControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment) +{ + m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment); +} + +void wxControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment) +{ + m_shape->GetEventHandler()->OnSizingEndDragLeft(this, x, y, keys, attachment); +} + +int wxControlPoint::GetNumberOfAttachments() const +{ + return 1; +} + +bool wxControlPoint::GetAttachmentPosition(int attachment, double *x, double *y, + int nth, int no_arcs, wxLineShape *line) +{ + *x = m_xpos; *y = m_ypos; + return TRUE; +} + +// Control points ('handles') redirect control to the actual shape, to make it easier +// to override sizing behaviour. +void wxShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys, int attachment) +{ + double bound_x; + double bound_y; + this->GetBoundingBoxMin(&bound_x, &bound_y); wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); @@ -1460,271 +1308,331 @@ void wxControlPoint::OnDragLeft(bool draw, float x, float y, int keys, int attac dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); - if (m_shape->GetCentreResize()) + if (this->GetCentreResize()) { // Maintain the same centre point. - float new_width = (float)(2.0*fabs(x - m_shape->GetX())); - float new_height = (float)(2.0*fabs(y - m_shape->GetY())); + double new_width = (double)(2.0*fabs(x - this->GetX())); + double new_height = (double)(2.0*fabs(y - this->GetY())); // Constrain sizing according to what control point you're dragging - if (m_type == CONTROL_POINT_HORIZONTAL) - new_height = bound_y; - else if (m_type == CONTROL_POINT_VERTICAL) - new_width = bound_x; - else if (m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT)) + if (pt->m_type == CONTROL_POINT_HORIZONTAL) + { + if (GetMaintainAspectRatio()) + { + new_height = bound_y*(new_width/bound_x); + } + else + new_height = bound_y; + } + else if (pt->m_type == CONTROL_POINT_VERTICAL) + { + if (GetMaintainAspectRatio()) + { + new_width = bound_x*(new_height/bound_y); + } + else + new_width = bound_x; + } + else if (pt->m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT)) new_height = bound_y*(new_width/bound_x); -// m_shape->OnBeginSize(m_shape->m_fixedWidth ? bound_x : new_width, -// m_shape->m_fixedHeight ? bound_y : new_height); - -// m_shape->SetSize(m_shape->m_fixedWidth ? bound_x : new_width, -// m_shape->m_fixedHeight ? bound_y : new_height); - if (m_shape->GetFixedWidth()) + if (this->GetFixedWidth()) new_width = bound_x; - if (m_shape->GetFixedHeight()) + if (this->GetFixedHeight()) new_height = bound_y; - controlPointDragEndWidth = new_width; - controlPointDragEndHeight = new_height; + pt->sm_controlPointDragEndWidth = new_width; + pt->sm_controlPointDragEndHeight = new_height; - m_shape->GetEventHandler()->OnDrawOutline(dc, m_shape->GetX(), m_shape->GetY(), + this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(), new_width, new_height); } else { // Don't maintain the same centre point! - float newX1 = wxMin(controlPointDragStartX, x); - float newY1 = wxMin(controlPointDragStartY, y); - float newX2 = wxMax(controlPointDragStartX, x); - float newY2 = wxMax(controlPointDragStartY, y); - if (m_type == CONTROL_POINT_HORIZONTAL) + double newX1 = wxMin(pt->sm_controlPointDragStartX, x); + double newY1 = wxMin(pt->sm_controlPointDragStartY, y); + double newX2 = wxMax(pt->sm_controlPointDragStartX, x); + double newY2 = wxMax(pt->sm_controlPointDragStartY, y); + if (pt->m_type == CONTROL_POINT_HORIZONTAL) { - newY1 = controlPointDragStartY; - newY2 = newY1 + controlPointDragStartHeight; + newY1 = pt->sm_controlPointDragStartY; + newY2 = newY1 + pt->sm_controlPointDragStartHeight; } - else if (m_type == CONTROL_POINT_VERTICAL) + else if (pt->m_type == CONTROL_POINT_VERTICAL) { - newX1 = controlPointDragStartX; - newX2 = newX1 + controlPointDragStartWidth; + newX1 = pt->sm_controlPointDragStartX; + newX2 = newX1 + pt->sm_controlPointDragStartWidth; } - else if (m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT)) + else if (pt->m_type == CONTROL_POINT_DIAGONAL && ((keys & KEY_SHIFT) || GetMaintainAspectRatio())) { - float newH = (float)((newX2 - newX1)*(controlPointDragStartHeight/controlPointDragStartWidth)); - if (GetY() > controlPointDragStartY) - newY2 = (float)(newY1 + newH); + double newH = (double)((newX2 - newX1)*(pt->sm_controlPointDragStartHeight/pt->sm_controlPointDragStartWidth)); + if (GetY() > pt->sm_controlPointDragStartY) + newY2 = (double)(newY1 + newH); else - newY1 = (float)(newY2 - newH); + newY1 = (double)(newY2 - newH); } - float newWidth = (float)(newX2 - newX1); - float newHeight = (float)(newY2 - newY1); + double newWidth = (double)(newX2 - newX1); + double newHeight = (double)(newY2 - newY1); -// m_shape->OnBeginSize(newWidth, -// newHeight); - -// m_shape->SetSize(newWidth, -// newHeight); - controlPointDragPosX = (float)(newX1 + (newWidth/2.0)); - controlPointDragPosY = (float)(newY1 + (newHeight/2.0)); - if (m_shape->GetFixedWidth()) + if (pt->m_type == CONTROL_POINT_VERTICAL && GetMaintainAspectRatio()) + { + newWidth = bound_x * (newHeight/bound_y) ; + } + + if (pt->m_type == CONTROL_POINT_HORIZONTAL && GetMaintainAspectRatio()) + { + newHeight = bound_y * (newWidth/bound_x) ; + } + + pt->sm_controlPointDragPosX = (double)(newX1 + (newWidth/2.0)); + pt->sm_controlPointDragPosY = (double)(newY1 + (newHeight/2.0)); + if (this->GetFixedWidth()) newWidth = bound_x; - if (m_shape->GetFixedHeight()) + if (this->GetFixedHeight()) newHeight = bound_y; - controlPointDragEndWidth = newWidth; - controlPointDragEndHeight = newHeight; - m_shape->GetEventHandler()->OnDrawOutline(dc, controlPointDragPosX, controlPointDragPosY, newWidth, newHeight); + pt->sm_controlPointDragEndWidth = newWidth; + pt->sm_controlPointDragEndHeight = newHeight; + this->GetEventHandler()->OnDrawOutline(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY, newWidth, newHeight); } } -void wxControlPoint::OnBeginDragLeft(float x, float y, int keys, int attachment) +void wxShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment) { m_canvas->CaptureMouse(); wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); - - if (m_eraseObject) - m_shape->Erase(dc); +/* + if (pt->m_eraseObject) + this->Erase(dc); +*/ dc.SetLogicalFunction(wxXOR); - float bound_x; - float bound_y; - m_shape->GetBoundingBoxMin(&bound_x, &bound_y); + double bound_x; + double bound_y; + this->GetBoundingBoxMin(&bound_x, &bound_y); // Choose the 'opposite corner' of the object as the stationary // point in case this is non-centring resizing. - if (GetX() < m_shape->GetX()) - controlPointDragStartX = (float)(m_shape->GetX() + (bound_x/2.0)); + if (pt->GetX() < this->GetX()) + pt->sm_controlPointDragStartX = (double)(this->GetX() + (bound_x/2.0)); else - controlPointDragStartX = (float)(m_shape->GetX() - (bound_x/2.0)); + pt->sm_controlPointDragStartX = (double)(this->GetX() - (bound_x/2.0)); - if (GetY() < m_shape->GetY()) - controlPointDragStartY = (float)(m_shape->GetY() + (bound_y/2.0)); + if (pt->GetY() < this->GetY()) + pt->sm_controlPointDragStartY = (double)(this->GetY() + (bound_y/2.0)); else - controlPointDragStartY = (float)(m_shape->GetY() - (bound_y/2.0)); + pt->sm_controlPointDragStartY = (double)(this->GetY() - (bound_y/2.0)); - if (m_type == CONTROL_POINT_HORIZONTAL) - controlPointDragStartY = (float)(m_shape->GetY() - (bound_y/2.0)); - else if (m_type == CONTROL_POINT_VERTICAL) - controlPointDragStartX = (float)(m_shape->GetX() - (bound_x/2.0)); + if (pt->m_type == CONTROL_POINT_HORIZONTAL) + pt->sm_controlPointDragStartY = (double)(this->GetY() - (bound_y/2.0)); + else if (pt->m_type == CONTROL_POINT_VERTICAL) + pt->sm_controlPointDragStartX = (double)(this->GetX() - (bound_x/2.0)); // We may require the old width and height. - controlPointDragStartWidth = bound_x; - controlPointDragStartHeight = bound_y; + pt->sm_controlPointDragStartWidth = bound_x; + pt->sm_controlPointDragStartHeight = bound_y; wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT); dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); - if (m_shape->GetCentreResize()) + if (this->GetCentreResize()) { - float new_width = (float)(2.0*fabs(x - m_shape->GetX())); - float new_height = (float)(2.0*fabs(y - m_shape->GetY())); + double new_width = (double)(2.0*fabs(x - this->GetX())); + double new_height = (double)(2.0*fabs(y - this->GetY())); // Constrain sizing according to what control point you're dragging - if (m_type == CONTROL_POINT_HORIZONTAL) - new_height = bound_y; - else if (m_type == CONTROL_POINT_VERTICAL) - new_width = bound_x; - else if (m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT)) + if (pt->m_type == CONTROL_POINT_HORIZONTAL) + { + if (GetMaintainAspectRatio()) + { + new_height = bound_y*(new_width/bound_x); + } + else + new_height = bound_y; + } + else if (pt->m_type == CONTROL_POINT_VERTICAL) + { + if (GetMaintainAspectRatio()) + { + new_width = bound_x*(new_height/bound_y); + } + else + new_width = bound_x; + } + else if (pt->m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT)) new_height = bound_y*(new_width/bound_x); - // Non-recursive SetSize for speed -// m_shape->SetSize(new_width, new_height, FALSE); - - if (m_shape->GetFixedWidth()) + if (this->GetFixedWidth()) new_width = bound_x; - if (m_shape->GetFixedHeight()) + if (this->GetFixedHeight()) new_height = bound_y; - controlPointDragEndWidth = new_width; - controlPointDragEndHeight = new_height; - m_shape->GetEventHandler()->OnDrawOutline(dc, m_shape->GetX(), m_shape->GetY(), + pt->sm_controlPointDragEndWidth = new_width; + pt->sm_controlPointDragEndHeight = new_height; + this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(), new_width, new_height); } else { // Don't maintain the same centre point! - float newX1 = wxMin(controlPointDragStartX, x); - float newY1 = wxMin(controlPointDragStartY, y); - float newX2 = wxMax(controlPointDragStartX, x); - float newY2 = wxMax(controlPointDragStartY, y); - if (m_type == CONTROL_POINT_HORIZONTAL) + double newX1 = wxMin(pt->sm_controlPointDragStartX, x); + double newY1 = wxMin(pt->sm_controlPointDragStartY, y); + double newX2 = wxMax(pt->sm_controlPointDragStartX, x); + double newY2 = wxMax(pt->sm_controlPointDragStartY, y); + if (pt->m_type == CONTROL_POINT_HORIZONTAL) { - newY1 = controlPointDragStartY; - newY2 = newY1 + controlPointDragStartHeight; + newY1 = pt->sm_controlPointDragStartY; + newY2 = newY1 + pt->sm_controlPointDragStartHeight; } - else if (m_type == CONTROL_POINT_VERTICAL) + else if (pt->m_type == CONTROL_POINT_VERTICAL) { - newX1 = controlPointDragStartX; - newX2 = newX1 + controlPointDragStartWidth; + newX1 = pt->sm_controlPointDragStartX; + newX2 = newX1 + pt->sm_controlPointDragStartWidth; } - else if (m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT)) + else if (pt->m_type == CONTROL_POINT_DIAGONAL && ((keys & KEY_SHIFT) || GetMaintainAspectRatio())) { - float newH = (float)((newX2 - newX1)*(controlPointDragStartHeight/controlPointDragStartWidth)); - if (GetY() > controlPointDragStartY) - newY2 = (float)(newY1 + newH); + double newH = (double)((newX2 - newX1)*(pt->sm_controlPointDragStartHeight/pt->sm_controlPointDragStartWidth)); + if (pt->GetY() > pt->sm_controlPointDragStartY) + newY2 = (double)(newY1 + newH); else - newY1 = (float)(newY2 - newH); + newY1 = (double)(newY2 - newH); } - float newWidth = (float)(newX2 - newX1); - float newHeight = (float)(newY2 - newY1); + double newWidth = (double)(newX2 - newX1); + double newHeight = (double)(newY2 - newY1); -// m_shape->OnBeginSize(newWidth, -// newHeight); - -// m_shape->SetSize(newWidth, -// newHeight); - controlPointDragPosX = (float)(newX1 + (newWidth/2.0)); - controlPointDragPosY = (float)(newY1 + (newHeight/2.0)); - if (m_shape->GetFixedWidth()) + if (pt->m_type == CONTROL_POINT_VERTICAL && GetMaintainAspectRatio()) + { + newWidth = bound_x * (newHeight/bound_y) ; + } + + if (pt->m_type == CONTROL_POINT_HORIZONTAL && GetMaintainAspectRatio()) + { + newHeight = bound_y * (newWidth/bound_x) ; + } + + pt->sm_controlPointDragPosX = (double)(newX1 + (newWidth/2.0)); + pt->sm_controlPointDragPosY = (double)(newY1 + (newHeight/2.0)); + if (this->GetFixedWidth()) newWidth = bound_x; - if (m_shape->GetFixedHeight()) + if (this->GetFixedHeight()) newHeight = bound_y; - controlPointDragEndWidth = newWidth; - controlPointDragEndHeight = newHeight; - m_shape->GetEventHandler()->OnDrawOutline(dc, controlPointDragPosX, controlPointDragPosY, newWidth, newHeight); + pt->sm_controlPointDragEndWidth = newWidth; + pt->sm_controlPointDragEndHeight = newHeight; + this->GetEventHandler()->OnDrawOutline(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY, newWidth, newHeight); } } -void wxControlPoint::OnEndDragLeft(float x, float y, int keys, int attachment) +void wxShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment) { wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); m_canvas->ReleaseMouse(); dc.SetLogicalFunction(wxCOPY); - m_shape->Recompute(); - m_shape->ResetControlPoints(); + this->Recompute(); + this->ResetControlPoints(); - if (!m_eraseObject) - m_shape->Show(FALSE); + this->Erase(dc); +/* + if (!pt->m_eraseObject) + this->Show(FALSE); +*/ - m_shape->SetSize(controlPointDragEndWidth, controlPointDragEndHeight); + this->SetSize(pt->sm_controlPointDragEndWidth, pt->sm_controlPointDragEndHeight); // The next operation could destroy this control point (it does for label objects, // via formatting the text), so save all values we're going to use, or // we'll be accessing garbage. - wxShape *theObject = m_shape; + wxShape *theObject = this; wxShapeCanvas *theCanvas = m_canvas; - bool eraseIt = m_eraseObject; + bool eraseIt = pt->m_eraseObject; if (theObject->GetCentreResize()) theObject->Move(dc, theObject->GetX(), theObject->GetY()); else - theObject->Move(dc, controlPointDragPosX, controlPointDragPosY); + theObject->Move(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY); +/* if (!eraseIt) theObject->Show(TRUE); +*/ // Recursively redraw links if we have a composite. if (theObject->GetChildren().Number() > 0) theObject->DrawLinks(dc, -1, TRUE); - float width, height; + double width, height; theObject->GetBoundingBoxMax(&width, &height); theObject->GetEventHandler()->OnEndSize(width, height); if (!theCanvas->GetQuickEditMode() && eraseIt) theCanvas->Redraw(dc); } -int wxControlPoint::GetNumberOfAttachments() -{ - return 1; -} - -bool wxControlPoint::GetAttachmentPosition(int attachment, float *x, float *y, - int nth, int no_arcs, wxLineShape *line) -{ - *x = m_xpos; *y = m_ypos; - return TRUE; -} // Polygon control points IMPLEMENT_DYNAMIC_CLASS(wxPolygonControlPoint, wxControlPoint) -wxPolygonControlPoint::wxPolygonControlPoint(wxShapeCanvas *theCanvas, wxShape *object, float size, - wxRealPoint *vertex, float the_xoffset, float the_yoffset): +wxPolygonControlPoint::wxPolygonControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size, + wxRealPoint *vertex, double the_xoffset, double the_yoffset): wxControlPoint(theCanvas, object, size, the_xoffset, the_yoffset, 0) { m_polygonVertex = vertex; + m_originalDistance = 0.0; } wxPolygonControlPoint::~wxPolygonControlPoint() { } +// Calculate what new size would be, at end of resize +void wxPolygonControlPoint::CalculateNewSize(double x, double y) +{ + double bound_x; + double bound_y; + GetShape()->GetBoundingBoxMin(&bound_x, &bound_y); + + double dist = (double)sqrt((x - m_shape->GetX())*(x - m_shape->GetX()) + + (y - m_shape->GetY())*(y - m_shape->GetY())); + + m_newSize.x = (double)(dist/this->m_originalDistance)*this->m_originalSize.x; + m_newSize.y = (double)(dist/this->m_originalDistance)*this->m_originalSize.y; +} + + // Implement resizing polygon or moving the vertex. -void wxPolygonControlPoint::OnDragLeft(bool draw, float x, float y, int keys, int attachment) +void wxPolygonControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment) +{ + m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment); +} + +void wxPolygonControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment) +{ + m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment); +} + +void wxPolygonControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment) { + m_shape->GetEventHandler()->OnSizingEndDragLeft(this, x, y, keys, attachment); +} + +// Control points ('handles') redirect control to the actual shape, to make it easier +// to override sizing behaviour. +void wxPolygonShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys, int attachment) +{ + wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt; + wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); @@ -1734,97 +1642,87 @@ void wxPolygonControlPoint::OnDragLeft(bool draw, float x, float y, int keys, in dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); - float bound_x; - float bound_y; - m_shape->GetBoundingBoxMin(&bound_x, &bound_y); -/* - float new_width = (float)(2.0*fabs(x - m_shape->GetX())); - float new_height = (float)(2.0*fabs(y - m_shape->GetY())); -*/ - float dist = (float)sqrt((x - m_shape->GetX())*(x - m_shape->GetX()) + - (y - m_shape->GetY())*(y - m_shape->GetY())); - - if (keys & KEY_CTRL) + if (0) // keys & KEY_CTRL) { + // TODO: mend this code. Currently we rely on altering the + // actual points, but we should assume we're not, as per + // the normal sizing case. m_canvas->Snap(&x, &y); // Move point - m_polygonVertex->x = x - m_shape->GetX(); - m_polygonVertex->y = y - m_shape->GetY(); - m_xpos = x; - m_xpos = y; - ((wxPolygonShape *)m_shape)->CalculateBoundingBox(); - ((wxPolygonShape *)m_shape)->CalculatePolygonCentre(); + ppt->m_polygonVertex->x = x - this->GetX(); + ppt->m_polygonVertex->y = y - this->GetY(); + ppt->SetX(x); + ppt->SetY(y); + ((wxPolygonShape *)this)->CalculateBoundingBox(); + ((wxPolygonShape *)this)->CalculatePolygonCentre(); } else { - float new_width = (float)(dist/m_originalDistance)*m_originalSize.x; - float new_height = (float)(dist/m_originalDistance)*m_originalSize.y; - - // Non-recursive SetSize for speed - m_shape->SetSize(new_width, new_height, FALSE); + ppt->CalculateNewSize(x, y); } - float w, h; - m_shape->GetBoundingBoxMax(&w, &h); - m_shape->GetEventHandler()->OnDrawOutline(dc, m_shape->GetX(), m_shape->GetY(), w, h); + + this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(), + ppt->GetNewSize().x, ppt->GetNewSize().y); } -void wxPolygonControlPoint::OnBeginDragLeft(float x, float y, int keys, int attachment) +void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment) { + wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt; + wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); - m_shape->Erase(dc); + this->Erase(dc); dc.SetLogicalFunction(wxXOR); - float bound_x; - float bound_y; - m_shape->GetBoundingBoxMin(&bound_x, &bound_y); - - float dist = (float)sqrt((x - m_shape->GetX())*(x - m_shape->GetX()) + - (y - m_shape->GetY())*(y - m_shape->GetY())); + double bound_x; + double bound_y; + this->GetBoundingBoxMin(&bound_x, &bound_y); - m_originalDistance = dist; - m_originalSize.x = bound_x; - m_originalSize.y = bound_y; + double dist = (double)sqrt((x - this->GetX())*(x - this->GetX()) + + (y - this->GetY())*(y - this->GetY())); + ppt->m_originalDistance = dist; + ppt->m_originalSize.x = bound_x; + ppt->m_originalSize.y = bound_y; - if (m_originalDistance == 0.0) m_originalDistance = (float) 0.0001; + if (ppt->m_originalDistance == 0.0) ppt->m_originalDistance = (double) 0.0001; wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT); dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); - if (keys & KEY_CTRL) + if (0) // keys & KEY_CTRL) { + // TODO: mend this code. Currently we rely on altering the + // actual points, but we should assume we're not, as per + // the normal sizing case. m_canvas->Snap(&x, &y); // Move point - m_polygonVertex->x = x - m_shape->GetX(); - m_polygonVertex->y = y - m_shape->GetY(); - m_xpos = x; - m_xpos = y; - ((wxPolygonShape *)m_shape)->CalculateBoundingBox(); - ((wxPolygonShape *)m_shape)->CalculatePolygonCentre(); + ppt->m_polygonVertex->x = x - this->GetX(); + ppt->m_polygonVertex->y = y - this->GetY(); + ppt->SetX(x); + ppt->SetY(y); + ((wxPolygonShape *)this)->CalculateBoundingBox(); + ((wxPolygonShape *)this)->CalculatePolygonCentre(); } else { - float new_width = (float)(dist/m_originalDistance)*m_originalSize.x; - float new_height = (float)(dist/m_originalDistance)*m_originalSize.y; - - // Non-recursive SetSize for speed - m_shape->SetSize(new_width, new_height, FALSE); + ppt->CalculateNewSize(x, y); } - float w, h; - m_shape->GetBoundingBoxMax(&w, &h); - m_shape->GetEventHandler()->OnDrawOutline(dc, m_shape->GetX(), m_shape->GetY(), w, h); + this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(), + ppt->GetNewSize().x, ppt->GetNewSize().y); m_canvas->CaptureMouse(); } -void wxPolygonControlPoint::OnEndDragLeft(float x, float y, int keys, int attachment) +void wxPolygonShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment) { + wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt; + wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); @@ -1834,20 +1732,23 @@ void wxPolygonControlPoint::OnEndDragLeft(float x, float y, int keys, int attach // If we're changing shape, must reset the original points if (keys & KEY_CTRL) { - ((wxPolygonShape *)m_shape)->CalculateBoundingBox(); - ((wxPolygonShape *)m_shape)->UpdateOriginalPoints(); + ((wxPolygonShape *)this)->CalculateBoundingBox(); + ((wxPolygonShape *)this)->UpdateOriginalPoints(); + } + else + { + SetSize(ppt->GetNewSize().x, ppt->GetNewSize().y); } - ((wxPolygonShape *)m_shape)->CalculateBoundingBox(); - ((wxPolygonShape *)m_shape)->CalculatePolygonCentre(); + ((wxPolygonShape *)this)->CalculateBoundingBox(); + ((wxPolygonShape *)this)->CalculatePolygonCentre(); - m_shape->Recompute(); - m_shape->ResetControlPoints(); - m_shape->Move(dc, m_shape->GetX(), m_shape->GetY()); + this->Recompute(); + this->ResetControlPoints(); + this->Move(dc, this->GetX(), this->GetY()); if (!m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc); } - /* * Object region * @@ -1933,25 +1834,25 @@ void wxShapeRegion::SetFont(wxFont *f) m_font = f; } -void wxShapeRegion::SetMinSize(float w, float h) +void wxShapeRegion::SetMinSize(double w, double h) { m_minWidth = w; m_minHeight = h; } -void wxShapeRegion::SetSize(float w, float h) +void wxShapeRegion::SetSize(double w, double h) { m_width = w; m_height = h; } -void wxShapeRegion::SetPosition(float xp, float yp) +void wxShapeRegion::SetPosition(double xp, double yp) { m_x = xp; m_y = yp; } -void wxShapeRegion::SetProportions(float xp, float yp) +void wxShapeRegion::SetProportions(double xp, double yp) { m_regionProportionX = xp; m_regionProportionY = yp;