X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0fc1a7137cccc829a34b3527c768db7d7ac83437..35c9d9582be4ebea40251378e95fdbbfe6b8ce73:/utils/ogl/src/lines.cpp diff --git a/utils/ogl/src/lines.cpp b/utils/ogl/src/lines.cpp index ed7b240715..a44bb7d2c6 100644 --- a/utils/ogl/src/lines.cpp +++ b/utils/ogl/src/lines.cpp @@ -11,6 +11,7 @@ #ifdef __GNUG__ #pragma implementation "lines.h" +#pragma implementation "linesp.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -24,11 +25,9 @@ #include #endif -#ifdef PROLOGIO #include -#endif -#if USE_IOSTREAMH +#if wxUSE_IOSTREAMH #include #else #include @@ -109,6 +108,7 @@ wxLineShape::~wxLineShape() m_labelObjects[i] = NULL; } } + ClearArrowsAtPosition(-1); } void wxLineShape::MakeLineControlPoints(int n) @@ -139,8 +139,8 @@ wxNode *wxLineShape::InsertLineControlPoint(wxDC* dc) wxRealPoint *second_last_point = (wxRealPoint *)second_last->Data(); // Choose a point half way between the last and penultimate points - float line_x = ((last_point->x + second_last_point->x)/2); - float line_y = ((last_point->y + second_last_point->y)/2); + double line_x = ((last_point->x + second_last_point->x)/2); + double line_y = ((last_point->y + second_last_point->y)/2); wxRealPoint *point = new wxRealPoint(line_x, line_y); wxNode *node = m_lineControlPoints->Insert(last, (wxObject*) point); @@ -182,7 +182,7 @@ void wxLineShape::Initialise() wxRealPoint *point = (wxRealPoint *)node->Data(); if (point->x == -999) { - float x1, y1, x2, y2; + double x1, y1, x2, y2; if (first_point->x < last_point->x) { x1 = first_point->x; x2 = last_point->x; } else @@ -205,7 +205,7 @@ void wxLineShape::Initialise() // strings with positions to region text list void wxLineShape::FormatText(wxDC& dc, const wxString& s, int i) { - float w, h; + double w, h; ClearText(i); if (m_regions.Number() < 1) @@ -226,30 +226,29 @@ void wxLineShape::FormatText(wxDC& dc, const wxString& s, int i) region->SetSize(w, h); } - wxList *string_list = ::FormatText(dc, s, (w-5), (h-5), region->GetFormatMode()); + wxStringList *string_list = oglFormatText(dc, s, (w-5), (h-5), region->GetFormatMode()); node = string_list->First(); while (node) { char *s = (char *)node->Data(); wxShapeTextLine *line = new wxShapeTextLine(0.0, 0.0, s); region->GetFormattedText().Append((wxObject *)line); - delete node; - node = string_list->First(); + node = node->Next(); } delete string_list; - float actualW = w; - float actualH = h; + double actualW = w; + double actualH = h; if (region->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS) { - GetCentredTextExtent(dc, &(region->GetFormattedText()), m_xpos, m_ypos, w, h, &actualW, &actualH); + oglGetCentredTextExtent(dc, &(region->GetFormattedText()), m_xpos, m_ypos, w, h, &actualW, &actualH); if ((actualW != w ) || (actualH != h)) { - float xx, yy; + double xx, yy; GetLabelPosition(i, &xx, &yy); EraseRegion(dc, region, xx, yy); if (m_labelObjects[i]) { - m_labelObjects[i]->Select(FALSE); + m_labelObjects[i]->Select(FALSE, &dc); m_labelObjects[i]->Erase(dc); m_labelObjects[i]->SetSize(actualW, actualH); } @@ -263,75 +262,75 @@ void wxLineShape::FormatText(wxDC& dc, const wxString& s, int i) } } } - CentreText(dc, &(region->GetFormattedText()), m_xpos, m_ypos, actualW, actualH, region->GetFormatMode()); + oglCentreText(dc, &(region->GetFormattedText()), m_xpos, m_ypos, actualW, actualH, region->GetFormatMode()); m_formatted = TRUE; } -void wxLineShape::DrawRegion(wxDC& dc, wxShapeRegion *region, float x, float y) +void wxLineShape::DrawRegion(wxDC& dc, wxShapeRegion *region, double x, double y) { if (GetDisableLabel()) return; - float w, h; - float xx, yy; + double w, h; + double xx, yy; region->GetSize(&w, &h); // Get offset from x, y region->GetPosition(&xx, &yy); - float xp = xx + x; - float yp = yy + y; + double xp = xx + x; + double yp = yy + y; // First, clear a rectangle for the text IF there is any if (region->GetFormattedText().Number() > 0) { - dc.SetPen(white_background_pen); - dc.SetBrush(white_background_brush); + dc.SetPen(g_oglWhiteBackgroundPen); + dc.SetBrush(g_oglWhiteBackgroundBrush); // Now draw the text if (region->GetFont()) dc.SetFont(region->GetFont()); - dc.DrawRectangle((float)(xp - w/2.0), (float)(yp - h/2.0), (float)w, (float)h); + dc.DrawRectangle((long)(xp - w/2.0), (long)(yp - h/2.0), (long)w, (long)h); if (m_pen) dc.SetPen(m_pen); dc.SetTextForeground(* region->GetActualColourObject()); #ifdef __WXMSW__ - dc.SetTextBackground(white_background_brush->GetColour()); + dc.SetTextBackground(g_oglWhiteBackgroundBrush->GetColour()); #endif - DrawFormattedText(dc, &(region->GetFormattedText()), xp, yp, w, h, region->GetFormatMode()); + oglDrawFormattedText(dc, &(region->GetFormattedText()), xp, yp, w, h, region->GetFormatMode()); } } -void wxLineShape::EraseRegion(wxDC& dc, wxShapeRegion *region, float x, float y) +void wxLineShape::EraseRegion(wxDC& dc, wxShapeRegion *region, double x, double y) { if (GetDisableLabel()) return; - float w, h; - float xx, yy; + double w, h; + double xx, yy; region->GetSize(&w, &h); // Get offset from x, y region->GetPosition(&xx, &yy); - float xp = xx + x; - float yp = yy + y; + double xp = xx + x; + double yp = yy + y; if (region->GetFormattedText().Number() > 0) { - dc.SetPen(white_background_pen); - dc.SetBrush(white_background_brush); + dc.SetPen(g_oglWhiteBackgroundPen); + dc.SetBrush(g_oglWhiteBackgroundBrush); - dc.DrawRectangle((float)(xp - w/2.0), (float)(yp - h/2.0), (float)w, (float)h); + dc.DrawRectangle((long)(xp - w/2.0), (long)(yp - h/2.0), (long)w, (long)h); } } // Get the reference point for a label. Region x and y // are offsets from this. // position is 0, 1, 2 -void wxLineShape::GetLabelPosition(int position, float *x, float *y) +void wxLineShape::GetLabelPosition(int position, double *x, double *y) { switch (position) { @@ -347,10 +346,10 @@ void wxLineShape::GetLabelPosition(int position, float *x, float *y) wxNode *next_node = node->Next(); wxRealPoint *next_point = (wxRealPoint *)next_node->Data(); - float dx = (next_point->x - point->x); - float dy = (next_point->y - point->y); - *x = (float)(point->x + dx/2.0); - *y = (float)(point->y + dy/2.0); + double dx = (next_point->x - point->x); + double dy = (next_point->y - point->y); + *x = (double)(point->x + dx/2.0); + *y = (double)(point->y + dy/2.0); break; } case 1: @@ -379,8 +378,8 @@ void wxLineShape::GetLabelPosition(int position, float *x, float *y) */ void GraphicsStraightenLine(wxRealPoint *point1, wxRealPoint *point2) { - float dx = point2->x - point1->x; - float dy = point2->y - point1->y; + double dx = point2->x - point1->x; + double dy = point2->y - point1->y; if (dx == 0.0) return; @@ -391,12 +390,13 @@ void GraphicsStraightenLine(wxRealPoint *point1, wxRealPoint *point2) else point2->y = point1->y; } -void wxLineShape::Straighten(wxDC& dc) +void wxLineShape::Straighten(wxDC *dc) { if (!m_lineControlPoints || m_lineControlPoints->Number() < 3) return; - Erase(dc); + if (dc) + Erase(* dc); wxNode *first_point_node = m_lineControlPoints->First(); wxNode *last_point_node = m_lineControlPoints->Last(); @@ -417,7 +417,8 @@ void wxLineShape::Straighten(wxDC& dc) node = node->Next(); } - Draw(dc); + if (dc) + Draw(* dc); } @@ -431,7 +432,7 @@ void wxLineShape::Unlink() m_from = NULL; } -void wxLineShape::SetEnds(float x1, float y1, float x2, float y2) +void wxLineShape::SetEnds(double x1, double y1, double x2, double y2) { // Find centre point wxNode *first_point_node = m_lineControlPoints->First(); @@ -444,12 +445,12 @@ void wxLineShape::SetEnds(float x1, float y1, float x2, float y2) last_point->x = x2; last_point->y = y2; - m_xpos = (float)((x1 + x2)/2.0); - m_ypos = (float)((y1 + y2)/2.0); + m_xpos = (double)((x1 + x2)/2.0); + m_ypos = (double)((y1 + y2)/2.0); } // Get absolute positions of ends -void wxLineShape::GetEnds(float *x1, float *y1, float *x2, float *y2) +void wxLineShape::GetEnds(double *x1, double *y1, double *x2, double *y2) { wxNode *first_point_node = m_lineControlPoints->First(); wxNode *last_point_node = m_lineControlPoints->Last(); @@ -466,7 +467,7 @@ void wxLineShape::SetAttachments(int from_attach, int to_attach) m_attachmentTo = to_attach; } -bool wxLineShape::HitTest(float x, float y, int *attachment, float *distance) +bool wxLineShape::HitTest(double x, double y, int *attachment, double *distance) { if (!m_lineControlPoints) return FALSE; @@ -481,17 +482,17 @@ bool wxLineShape::HitTest(float x, float y, int *attachment, float *distance) wxShapeRegion *region = (wxShapeRegion *)regionNode->Data(); if (region->m_formattedText.Number() > 0) { - float xp, yp, cx, cy, cw, ch; + double xp, yp, cx, cy, cw, ch; GetLabelPosition(i, &xp, &yp); // Offset region from default label position region->GetPosition(&cx, &cy); region->GetSize(&cw, &ch); cx += xp; cy += yp; - float rLeft = (float)(cx - (cw/2.0)); - float rTop = (float)(cy - (ch/2.0)); - float rRight = (float)(cx + (cw/2.0)); - float rBottom = (float)(cy + (ch/2.0)); + double rLeft = (double)(cx - (cw/2.0)); + double rTop = (double)(cy - (ch/2.0)); + double rRight = (double)(cx + (cw/2.0)); + double rBottom = (double)(cy + (ch/2.0)); if (x > rLeft && x < rRight && y > rTop && y < rBottom) { inLabelRegion = TRUE; @@ -510,20 +511,20 @@ bool wxLineShape::HitTest(float x, float y, int *attachment, float *distance) // Allow for inaccurate mousing or vert/horiz lines int extra = 4; - float left = wxMin(point1->x, point2->x) - extra; - float right = wxMax(point1->x, point2->x) + extra; + double left = wxMin(point1->x, point2->x) - extra; + double right = wxMax(point1->x, point2->x) + extra; - float bottom = wxMin(point1->y, point2->y) - extra; - float top = wxMax(point1->y, point2->y) + extra; + double bottom = wxMin(point1->y, point2->y) - extra; + double top = wxMax(point1->y, point2->y) + extra; if ((x > left && x < right && y > bottom && y < top) || inLabelRegion) { // Work out distance from centre of line - float centre_x = (float)(left + (right - left)/2.0); - float centre_y = (float)(bottom + (top - bottom)/2.0); + double centre_x = (double)(left + (right - left)/2.0); + double centre_y = (double)(bottom + (top - bottom)/2.0); *attachment = 0; - *distance = (float)sqrt((centre_x - x)*(centre_x - x) + (centre_y - y)*(centre_y - y)); + *distance = (double)sqrt((centre_x - x)*(centre_x - x) + (centre_y - y)*(centre_y - y)); return TRUE; } @@ -535,10 +536,10 @@ bool wxLineShape::HitTest(float x, float y, int *attachment, float *distance) void wxLineShape::DrawArrows(wxDC& dc) { // Distance along line of each arrow: space them out evenly. - float startArrowPos = 0.0; - float endArrowPos = 0.0; - float middleArrowPos = 0.0; - + double startArrowPos = 0.0; + double endArrowPos = 0.0; + double middleArrowPos = 0.0; + wxNode *node = m_arcArrows.First(); while (node) { @@ -585,7 +586,7 @@ void wxLineShape::DrawArrows(wxDC& dc) } } -void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool proportionalOffset) +void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, double xOffset, bool proportionalOffset) { wxNode *first_line_node = m_lineControlPoints->First(); wxRealPoint *first_line_point = (wxRealPoint *)first_line_node->Data(); @@ -598,10 +599,10 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr wxRealPoint *second_last_line_point = (wxRealPoint *)second_last_line_node->Data(); // Position where we want to start drawing - float positionOnLineX, positionOnLineY; + double positionOnLineX, positionOnLineY; // Position of start point of line, at the end of which we draw the arrow. - float startPositionX, startPositionY; + double startPositionX, startPositionY; switch (arrow->GetPosition()) { @@ -609,13 +610,13 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr { // If we're using a proportional offset, calculate just where this will // be on the line. - float realOffset = xOffset; + double realOffset = xOffset; if (proportionalOffset) { - float totalLength = - (float)sqrt((second_line_point->x - first_line_point->x)*(second_line_point->x - first_line_point->x) + + double totalLength = + (double)sqrt((second_line_point->x - first_line_point->x)*(second_line_point->x - first_line_point->x) + (second_line_point->y - first_line_point->y)*(second_line_point->y - first_line_point->y)); - realOffset = (float)(xOffset * totalLength); + realOffset = (double)(xOffset * totalLength); } GetPointOnLine(second_line_point->x, second_line_point->y, first_line_point->x, first_line_point->y, @@ -628,13 +629,13 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr { // If we're using a proportional offset, calculate just where this will // be on the line. - float realOffset = xOffset; + double realOffset = xOffset; if (proportionalOffset) { - float totalLength = - (float)sqrt((second_last_line_point->x - last_line_point->x)*(second_last_line_point->x - last_line_point->x) + + double totalLength = + (double)sqrt((second_last_line_point->x - last_line_point->x)*(second_last_line_point->x - last_line_point->x) + (second_last_line_point->y - last_line_point->y)*(second_last_line_point->y - last_line_point->y)); - realOffset = (float)(xOffset * totalLength); + realOffset = (double)(xOffset * totalLength); } GetPointOnLine(second_last_line_point->x, second_last_line_point->y, last_line_point->x, last_line_point->y, @@ -646,18 +647,18 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr case ARROW_POSITION_MIDDLE: { // Choose a point half way between the last and penultimate points - float x = ((last_line_point->x + second_last_line_point->x)/2); - float y = ((last_line_point->y + second_last_line_point->y)/2); + double x = ((last_line_point->x + second_last_line_point->x)/2); + double y = ((last_line_point->y + second_last_line_point->y)/2); // If we're using a proportional offset, calculate just where this will // be on the line. - float realOffset = xOffset; + double realOffset = xOffset; if (proportionalOffset) { - float totalLength = - (float)sqrt((second_last_line_point->x - x)*(second_last_line_point->x - x) + + double totalLength = + (double)sqrt((second_last_line_point->x - x)*(second_last_line_point->x - x) + (second_last_line_point->y - y)*(second_last_line_point->y - y)); - realOffset = (float)(xOffset * totalLength); + realOffset = (double)(xOffset * totalLength); } GetPointOnLine(second_last_line_point->x, second_last_line_point->y, @@ -672,10 +673,10 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr * Add yOffset to arrow, if any */ - const float myPi = (float) 3.14159265; + const double myPi = (double) 3.14159265; // The translation that the y offset may give - float deltaX = 0.0; - float deltaY = 0.0; + double deltaX = 0.0; + double deltaY = 0.0; if ((arrow->GetYOffset() != 0.0) && !m_ignoreArrowOffsets) { /* @@ -688,20 +689,20 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr Where theta = tan(-1) of (y3-y1)/(x3-x1) */ - float x1 = startPositionX; - float y1 = startPositionY; - float x3 = positionOnLineX; - float y3 = positionOnLineY; - float d = -arrow->GetYOffset(); // Negate so +offset is above line + double x1 = startPositionX; + double y1 = startPositionY; + double x3 = positionOnLineX; + double y3 = positionOnLineY; + double d = -arrow->GetYOffset(); // Negate so +offset is above line - float theta = 0.0; + double theta = 0.0; if (x3 == x1) - theta = (float)(myPi/2.0); + theta = (double)(myPi/2.0); else - theta = (float)atan((y3-y1)/(x3-x1)); - - float x4 = (float)(x3 - (d*sin(theta))); - float y4 = (float)(y3 + (d*cos(theta))); + theta = (double)atan((y3-y1)/(x3-x1)); + + double x4 = (double)(x3 - (d*sin(theta))); + double y4 = (double)(y3 + (d*cos(theta))); deltaX = x4 - positionOnLineX; deltaY = y4 - positionOnLineY; @@ -711,20 +712,20 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr { case ARROW_ARROW: { - float arrowLength = arrow->GetSize(); - float arrowWidth = (float)(arrowLength/3.0); + double arrowLength = arrow->GetSize(); + double arrowWidth = (double)(arrowLength/3.0); - float tip_x, tip_y, side1_x, side1_y, side2_x, side2_y; - get_arrow_points(startPositionX+deltaX, startPositionY+deltaY, + double tip_x, tip_y, side1_x, side1_y, side2_x, side2_y; + oglGetArrowPoints(startPositionX+deltaX, startPositionY+deltaY, positionOnLineX+deltaX, positionOnLineY+deltaY, arrowLength, arrowWidth, &tip_x, &tip_y, &side1_x, &side1_y, &side2_x, &side2_y); wxPoint points[4]; - points[0].x = tip_x; points[0].y = tip_y; - points[1].x = side1_x; points[1].y = side1_y; - points[2].x = side2_x; points[2].y = side2_y; - points[3].x = tip_x; points[3].y = tip_y; + points[0].x = (int) tip_x; points[0].y = (int) tip_y; + points[1].x = (int) side1_x; points[1].y = (int) side1_y; + points[2].x = (int) side2_x; points[2].y = (int) side2_y; + points[3].x = (int) tip_x; points[3].y = (int) tip_y; dc.SetPen(m_pen); dc.SetBrush(m_brush); @@ -736,24 +737,24 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr { // Find point on line of centre of circle, which is a radius away // from the end position - float diameter = (float)(arrow->GetSize()); - float x, y; + double diameter = (double)(arrow->GetSize()); + double x, y; GetPointOnLine(startPositionX+deltaX, startPositionY+deltaY, positionOnLineX+deltaX, positionOnLineY+deltaY, - (float)(diameter/2.0), + (double)(diameter/2.0), &x, &y); // Convert ellipse centre to top-left coordinates - float x1 = (float)(x - (diameter/2.0)); - float y1 = (float)(y - (diameter/2.0)); + double x1 = (double)(x - (diameter/2.0)); + double y1 = (double)(y - (diameter/2.0)); dc.SetPen(m_pen); if (arrow->_GetType() == ARROW_HOLLOW_CIRCLE) - dc.SetBrush(white_background_brush); + dc.SetBrush(g_oglWhiteBackgroundBrush); else dc.SetBrush(m_brush); - dc.DrawEllipse(x1, y1, diameter, diameter); + dc.DrawEllipse((long) x1, (long) y1, (long) diameter, (long) diameter); break; } case ARROW_SINGLE_OBLIQUE: @@ -773,10 +774,10 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr * --------------| x | <-- e.g. rectangular arrowhead * ----- */ - float x, y; + double x, y; GetPointOnLine(startPositionX, startPositionY, positionOnLineX, positionOnLineY, - (float)(arrow->GetMetaFile()->m_width/2.0), + (double)(arrow->GetMetaFile()->m_width/2.0), &x, &y); // Calculate theta for rotating the metafile. @@ -789,29 +790,29 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr | /(x1, y1) |______________________ */ - float theta = 0.0; - float x1 = startPositionX; - float y1 = startPositionY; - float x2 = positionOnLineX; - float y2 = positionOnLineY; + double theta = 0.0; + double x1 = startPositionX; + double y1 = startPositionY; + double x2 = positionOnLineX; + double y2 = positionOnLineY; if ((x1 == x2) && (y1 == y2)) theta = 0.0; else if ((x1 == x2) && (y1 > y2)) - theta = (float)(3.0*myPi/2.0); + theta = (double)(3.0*myPi/2.0); else if ((x1 == x2) && (y2 > y1)) - theta = (float)(myPi/2.0); + theta = (double)(myPi/2.0); else if ((x2 > x1) && (y2 >= y1)) - theta = (float)atan((y2 - y1)/(x2 - x1)); + theta = (double)atan((y2 - y1)/(x2 - x1)); else if (x2 < x1) - theta = (float)(myPi + atan((y2 - y1)/(x2 - x1))); + theta = (double)(myPi + atan((y2 - y1)/(x2 - x1))); else if ((x2 > x1) && (y2 < y1)) - theta = (float)(2*myPi + atan((y2 - y1)/(x2 - x1))); + theta = (double)(2*myPi + atan((y2 - y1)/(x2 - x1))); else { @@ -826,12 +827,12 @@ void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool pr if (m_erasing) { // If erasing, just draw a rectangle. - float minX, minY, maxX, maxY; + double minX, minY, maxX, maxY; arrow->GetMetaFile()->GetBounds(&minX, &minY, &maxX, &maxY); // Make erasing rectangle slightly bigger or you get droppings. int extraPixels = 4; - dc.DrawRectangle((float)(deltaX + x + minX - (extraPixels/2.0)), (float)(deltaY + y + minY - (extraPixels/2.0)), - (float)(maxX - minX + extraPixels), (float)(maxY - minY + extraPixels)); + dc.DrawRectangle((long)(deltaX + x + minX - (extraPixels/2.0)), (long)(deltaY + y + minY - (extraPixels/2.0)), + (long)(maxX - minX + extraPixels), (long)(maxY - minY + extraPixels)); } else arrow->GetMetaFile()->Draw(dc, x+deltaX, y+deltaY); @@ -848,10 +849,10 @@ void wxLineShape::OnErase(wxDC& dc) { wxPen *old_pen = m_pen; wxBrush *old_brush = m_brush; - SetPen(white_background_pen); - SetBrush(white_background_brush); + SetPen(g_oglWhiteBackgroundPen); + SetBrush(g_oglWhiteBackgroundBrush); - float bound_x, bound_y; + double bound_x, bound_y; GetBoundingBoxMax(&bound_x, &bound_y); if (m_font) dc.SetFont(m_font); @@ -861,7 +862,7 @@ void wxLineShape::OnErase(wxDC& dc) wxNode *node = m_regions.Nth(i); if (node) { - float x, y; + double x, y; wxShapeRegion *region = (wxShapeRegion *)node->Data(); GetLabelPosition(i, &x, &y); EraseRegion(dc, region, x, y); @@ -869,15 +870,15 @@ void wxLineShape::OnErase(wxDC& dc) } // Undraw line - dc.SetPen(white_background_pen); - dc.SetBrush(white_background_brush); + dc.SetPen(g_oglWhiteBackgroundPen); + dc.SetBrush(g_oglWhiteBackgroundBrush); // Drawing over the line only seems to work if the line has a thickness // of 1. if (old_pen && (old_pen->GetWidth() > 1)) { - dc.DrawRectangle((float)(m_xpos - (bound_x/2.0) - 2.0), (float)(m_ypos - (bound_y/2.0) - 2.0), - (float)(bound_x+4.0), (float)(bound_y+4.0)); + dc.DrawRectangle((long)(m_xpos - (bound_x/2.0) - 2.0), (long)(m_ypos - (bound_y/2.0) - 2.0), + (long)(bound_x+4.0), (long)(bound_y+4.0)); } else { @@ -891,12 +892,12 @@ void wxLineShape::OnErase(wxDC& dc) if (old_brush) SetBrush(old_brush); } -void wxLineShape::GetBoundingBoxMin(float *w, float *h) +void wxLineShape::GetBoundingBoxMin(double *w, double *h) { - float x1 = 10000; - float y1 = 10000; - float x2 = -10000; - float y2 = -10000; + double x1 = 10000; + double y1 = 10000; + double x2 = -10000; + double y2 = -10000; wxNode *node = m_lineControlPoints->First(); while (node) @@ -910,8 +911,8 @@ void wxLineShape::GetBoundingBoxMin(float *w, float *h) node = node->Next(); } - *w = (float)(x2 - x1); - *h = (float)(y2 - y1); + *w = (double)(x2 - x1); + *h = (double)(y2 - y1); } /* @@ -963,7 +964,7 @@ void wxLineShape::FindNth(wxShape *image, int *nth, int *no_arcs, bool incoming) *no_arcs = num; } -void wxLineShape::OnDrawOutline(wxDC& dc, float x, float y, float w, float h) +void wxLineShape::OnDrawOutline(wxDC& dc, double x, double y, double w, double h) { wxPen *old_pen = m_pen; wxBrush *old_brush = m_brush; @@ -972,12 +973,6 @@ void wxLineShape::OnDrawOutline(wxDC& dc, float x, float y, float w, float h) SetPen(& dottedPen); SetBrush( wxTRANSPARENT_BRUSH ); -/* - if (m_isSpline) - dc.DrawSpline(m_lineControlPoints); - else - dc.DrawLines(m_lineControlPoints); -*/ GetEventHandler()->OnDraw(dc); if (old_pen) SetPen(old_pen); @@ -986,10 +981,10 @@ void wxLineShape::OnDrawOutline(wxDC& dc, float x, float y, float w, float h) else SetBrush(NULL); } -bool wxLineShape::OnMovePre(wxDC& dc, float x, float y, float old_x, float old_y, bool display) +bool wxLineShape::OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display) { - float x_offset = x - old_x; - float y_offset = y - old_y; + double x_offset = x - old_x; + double y_offset = y - old_y; if (m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0)) { @@ -1010,7 +1005,7 @@ bool wxLineShape::OnMovePre(wxDC& dc, float x, float y, float old_x, float old_y if (m_labelObjects[i]) { m_labelObjects[i]->Erase(dc); - float xp, yp, xr, yr; + double xp, yp, xr, yr; GetLabelPosition(i, &xp, &yp); wxNode *node = m_regions.Nth(i); if (node) @@ -1039,8 +1034,8 @@ void wxLineShape::OnMoveLink(wxDC& dc, bool moveControlPoints) // Do each end - nothing in the middle. User has to move other points // manually if necessary. - float end_x, end_y; - float other_end_x, other_end_y; + double end_x, end_y; + double other_end_x, other_end_y; FindLineEndPoints(&end_x, &end_y, &other_end_x, &other_end_y); @@ -1054,8 +1049,8 @@ void wxLineShape::OnMoveLink(wxDC& dc, bool moveControlPoints) last_point->x = other_end_x; last_point->y = other_end_y; */ - float oldX = m_xpos; - float oldY = m_ypos; + double oldX = m_xpos; + double oldY = m_ypos; SetEnds(end_x, end_y, other_end_x, other_end_y); @@ -1064,12 +1059,12 @@ void wxLineShape::OnMoveLink(wxDC& dc, bool moveControlPoints) SetEnds(end_x, end_y, other_end_x, other_end_y); // Try to move control points with the arc - float x_offset = m_xpos - oldX; - float y_offset = m_ypos - oldY; + double x_offset = m_xpos - oldX; + double y_offset = m_ypos - oldY; // if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0)) // Only move control points if it's a self link. And only works if attachment mode is ON. - if ((m_from == m_to) && m_from->GetAttachmentMode() && moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0)) + if ((m_from == m_to) && (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE) && moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0)) { wxNode *node = m_lineControlPoints->First(); while (node) @@ -1091,15 +1086,15 @@ void wxLineShape::OnMoveLink(wxDC& dc, bool moveControlPoints) // This function can be used by e.g. line-routing routines to // get the actual points on the two node images where the lines will be drawn // to/from. -void wxLineShape::FindLineEndPoints(float *fromX, float *fromY, float *toX, float *toY) +void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, double *toY) { if (!m_from || !m_to) return; // Do each end - nothing in the middle. User has to move other points // manually if necessary. - float end_x, end_y; - float other_end_x, other_end_y; + double end_x, end_y; + double other_end_x, other_end_y; wxNode *first = m_lineControlPoints->First(); wxRealPoint *first_point = (wxRealPoint *)first->Data(); @@ -1114,7 +1109,7 @@ void wxLineShape::FindLineEndPoints(float *fromX, float *fromY, float *toX, floa if (m_lineControlPoints->Number() > 2) { - if (m_from->GetAttachmentMode()) + if (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE) { int nth, no_arcs; FindNth(m_from, &nth, &no_arcs, FALSE); // Not incoming @@ -1122,10 +1117,10 @@ void wxLineShape::FindLineEndPoints(float *fromX, float *fromY, float *toX, floa } else (void) m_from->GetPerimeterPoint(m_from->GetX(), m_from->GetY(), - (float)second_point->x, (float)second_point->y, + (double)second_point->x, (double)second_point->y, &end_x, &end_y); - if (m_to->GetAttachmentMode()) + if (m_to->GetAttachmentMode() != ATTACHMENT_MODE_NONE) { int nth, no_arcs; FindNth(m_to, &nth, &no_arcs, TRUE); // Incoming @@ -1133,17 +1128,17 @@ void wxLineShape::FindLineEndPoints(float *fromX, float *fromY, float *toX, floa } else (void) m_to->GetPerimeterPoint(m_to->GetX(), m_to->GetY(), - (float)second_last_point->x, (float)second_last_point->y, + (double)second_last_point->x, (double)second_last_point->y, &other_end_x, &other_end_y); } else { - float fromX = m_from->GetX(); - float fromY = m_from->GetY(); - float toX = m_to->GetX(); - float toY = m_to->GetY(); + double fromX = m_from->GetX(); + double fromY = m_from->GetY(); + double toX = m_to->GetX(); + double toY = m_to->GetY(); - if (m_from->GetAttachmentMode()) + if (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE) { int nth, no_arcs; FindNth(m_from, &nth, &no_arcs, FALSE); @@ -1152,7 +1147,7 @@ void wxLineShape::FindLineEndPoints(float *fromX, float *fromY, float *toX, floa fromY = end_y; } - if (m_to->GetAttachmentMode()) + if (m_to->GetAttachmentMode() != ATTACHMENT_MODE_NONE) { int nth, no_arcs; FindNth(m_to, &nth, &no_arcs, TRUE); @@ -1161,12 +1156,12 @@ void wxLineShape::FindLineEndPoints(float *fromX, float *fromY, float *toX, floa toY = other_end_y; } - if (!m_from->GetAttachmentMode()) + if (m_from->GetAttachmentMode() == ATTACHMENT_MODE_NONE) (void) m_from->GetPerimeterPoint(m_from->GetX(), m_from->GetY(), toX, toY, &end_x, &end_y); - if (!m_to->GetAttachmentMode()) + if (m_to->GetAttachmentMode() == ATTACHMENT_MODE_NONE) (void) m_to->GetPerimeterPoint(m_to->GetX(), m_to->GetY(), fromX, fromY, &other_end_x, &other_end_y); @@ -1192,8 +1187,8 @@ void wxLineShape::OnDraw(wxDC& dc) for (i = 0; i < n; i++) { wxRealPoint* point = (wxRealPoint*) m_lineControlPoints->Nth(i)->Data(); - points[i].x = (int) point->x; - points[i].y = (int) point->y; + points[i].x = WXROUND(point->x); + points[i].y = WXROUND(point->y); } if (m_isSpline) @@ -1201,8 +1196,14 @@ void wxLineShape::OnDraw(wxDC& dc) else dc.DrawLines(n, points); +#ifdef __WXMSW__ + // For some reason, last point isn't drawn under Windows. + dc.DrawPoint(points[n-1]); +#endif + delete[] points; + // Problem with pen - if not a solid pen, does strange things // to the arrowhead. So make (get) a new pen that's solid. if (m_pen && (m_pen->GetStyle() != wxSOLID)) @@ -1241,20 +1242,20 @@ void wxLineShape::OnEraseControlPoints(wxDC& dc) wxShape::OnEraseControlPoints(dc); } -void wxLineShape::OnDragLeft(bool draw, float x, float y, int keys, int attachment) +void wxLineShape::OnDragLeft(bool draw, double x, double y, int keys, int attachment) { } -void wxLineShape::OnBeginDragLeft(float x, float y, int keys, int attachment) +void wxLineShape::OnBeginDragLeft(double x, double y, int keys, int attachment) { } -void wxLineShape::OnEndDragLeft(float x, float y, int keys, int attachment) +void wxLineShape::OnEndDragLeft(double x, double y, int keys, int attachment) { } /* -void wxLineShape::SetArrowSize(float length, float width) +void wxLineShape::SetArrowSize(double length, double width) { arrow_length = length; arrow_width = width; @@ -1287,21 +1288,13 @@ void wxLineShape::OnDrawContents(wxDC& dc) if (node) { wxShapeRegion *region = (wxShapeRegion *)node->Data(); - float x, y; + double x, y; GetLabelPosition(i, &x, &y); DrawRegion(dc, region, x, y); } } } - -#ifdef PROLOGIO -char *wxLineShape::GetFunctor() -{ - return "arc_image"; -} -#endif - void wxLineShape::SetTo(wxShape *object) { m_to = object; @@ -1375,9 +1368,9 @@ void wxLineShape::ResetControlPoints() } #ifdef PROLOGIO -void wxLineShape::WritePrologAttributes(wxExpr *clause) +void wxLineShape::WriteAttributes(wxExpr *clause) { - wxShape::WritePrologAttributes(clause); + wxShape::WriteAttributes(clause); if (m_from) clause->AddAttributeValue("from", m_from->GetId()); @@ -1399,14 +1392,14 @@ void wxLineShape::WritePrologAttributes(wxExpr *clause) clause->AddAttributeValue("keep_lines_straight", (long)m_maintainStraightLines); // Make a list of lists for the (sp)line controls - wxExpr *list = new wxExpr(PrologList); + wxExpr *list = new wxExpr(wxExprList); wxNode *node = m_lineControlPoints->First(); while (node) { wxRealPoint *point = (wxRealPoint *)node->Data(); - wxExpr *point_list = new wxExpr(PrologList); - wxExpr *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); @@ -1420,17 +1413,17 @@ void wxLineShape::WritePrologAttributes(wxExpr *clause) // (arrowType arrowEnd xOffset arrowSize) if (m_arcArrows.Number() > 0) { - wxExpr *arrow_list = new wxExpr(PrologList); + wxExpr *arrow_list = new wxExpr(wxExprList); node = m_arcArrows.First(); while (node) { wxArrowHead *head = (wxArrowHead *)node->Data(); - wxExpr *head_list = new wxExpr(PrologList); + wxExpr *head_list = new wxExpr(wxExprList); head_list->Append(new wxExpr((long)head->_GetType())); head_list->Append(new wxExpr((long)head->GetArrowEnd())); head_list->Append(new wxExpr(head->GetXOffset())); head_list->Append(new wxExpr(head->GetArrowSize())); - head_list->Append(new wxExpr(PrologString, (head->GetName() ? head->GetName() : ""))); + head_list->Append(new wxExpr(wxExprString, head->GetName())); head_list->Append(new wxExpr(head->GetId())); // New members of wxArrowHead @@ -1445,9 +1438,9 @@ void wxLineShape::WritePrologAttributes(wxExpr *clause) } } -void wxLineShape::ReadPrologAttributes(wxExpr *clause) +void wxLineShape::ReadAttributes(wxExpr *clause) { - wxShape::ReadPrologAttributes(clause); + wxShape::ReadAttributes(clause); int iVal = (int) m_isSpline; clause->AssignAttributeValue("is_spline", &iVal); @@ -1496,7 +1489,7 @@ void wxLineShape::ReadPrologAttributes(wxExpr *clause) m_attachmentFrom = 0; clause->AssignAttributeValue("attachment_to", &m_attachmentTo); - clause->AssignAttributeValue("attachmen_from", &m_attachmentFrom); + clause->AssignAttributeValue("attachment_from", &m_attachmentFrom); wxExpr *line_list = NULL; @@ -1519,10 +1512,10 @@ void wxLineShape::ReadPrologAttributes(wxExpr *clause) while (node) { wxExpr *xexpr = node->value.first; - float x = xexpr->RealValue(); + double x = xexpr->RealValue(); wxExpr *yexpr = xexpr->next; - float y = yexpr->RealValue(); + double y = yexpr->RealValue(); wxRealPoint *point = new wxRealPoint(x, y); m_lineControlPoints->Append((wxObject*) point); @@ -1543,8 +1536,8 @@ void wxLineShape::ReadPrologAttributes(wxExpr *clause) { WXTYPE arrowType = ARROW_ARROW; int arrowEnd = 0; - float xOffset = 0.0; - float arrowSize = 0.0; + double xOffset = 0.0; + double arrowSize = 0.0; wxString arrowName(""); long arrowId = -1; @@ -1589,70 +1582,63 @@ void wxLineShape::ReadPrologAttributes(wxExpr *clause) } #endif -void wxLineShape::Copy(wxLineShape& copy) +void wxLineShape::Copy(wxShape& copy) { wxShape::Copy(copy); - copy.m_isSpline = m_isSpline; - copy.m_alignmentStart = m_alignmentStart; - copy.m_alignmentEnd = m_alignmentEnd; - copy.m_maintainStraightLines = m_maintainStraightLines; - copy.m_lineOrientations.Clear(); + wxASSERT( copy.IsKindOf(CLASSINFO(wxLineShape)) ); + + wxLineShape& lineCopy = (wxLineShape&) copy; + + lineCopy.m_to = m_to; + lineCopy.m_from = m_from; + lineCopy.m_attachmentTo = m_attachmentTo; + lineCopy.m_attachmentFrom = m_attachmentFrom; + lineCopy.m_isSpline = m_isSpline; + lineCopy.m_alignmentStart = m_alignmentStart; + lineCopy.m_alignmentEnd = m_alignmentEnd; + lineCopy.m_maintainStraightLines = m_maintainStraightLines; + lineCopy.m_lineOrientations.Clear(); + wxNode *node = m_lineOrientations.First(); while (node) { - copy.m_lineOrientations.Append(node->Data()); + lineCopy.m_lineOrientations.Append(node->Data()); node = node->Next(); } - if (copy.m_lineControlPoints) + if (lineCopy.m_lineControlPoints) { - ClearPointList(*copy.m_lineControlPoints); - delete copy.m_lineControlPoints; + ClearPointList(*lineCopy.m_lineControlPoints); + delete lineCopy.m_lineControlPoints; } - copy.m_lineControlPoints = new wxList; + lineCopy.m_lineControlPoints = new wxList; node = m_lineControlPoints->First(); while (node) { wxRealPoint *point = (wxRealPoint *)node->Data(); wxRealPoint *new_point = new wxRealPoint(point->x, point->y); - copy.m_lineControlPoints->Append((wxObject*) new_point); + lineCopy.m_lineControlPoints->Append((wxObject*) new_point); node = node->Next(); } -/* - copy.start_style = start_style; - copy.end_style = end_style; - copy.middle_style = middle_style; - - copy.arrow_length = arrow_length; - copy.arrow_width = arrow_width; -*/ - - // Copy new OGL stuff - copy.ClearArrowsAtPosition(-1); + // Copy arrows + lineCopy.ClearArrowsAtPosition(-1); node = m_arcArrows.First(); while (node) { wxArrowHead *arrow = (wxArrowHead *)node->Data(); - copy.m_arcArrows.Append(new wxArrowHead(*arrow)); + lineCopy.m_arcArrows.Append(new wxArrowHead(*arrow)); node = node->Next(); } } -wxShape *wxLineShape::PrivateCopy() -{ - wxLineShape *line = new wxLineShape; - Copy(*line); - return line; -} - // Override select, to create/delete temporary label-moving objects void wxLineShape::Select(bool select, wxDC* dc) { - wxShape::Select(select); + wxShape::Select(select, dc); if (select) { for (int i = 0; i < 3; i++) @@ -1663,7 +1649,7 @@ void wxLineShape::Select(bool select, wxDC* dc) wxShapeRegion *region = (wxShapeRegion *)node->Data(); if (region->m_formattedText.Number() > 0) { - float w, h, x, y, xx, yy; + double w, h, x, y, xx, yy; region->GetSize(&w, &h); region->GetPosition(&x, &y); GetLabelPosition(i, &xx, &yy); @@ -1673,12 +1659,12 @@ void wxLineShape::Select(bool select, wxDC* dc) m_labelObjects[i]->RemoveFromCanvas(m_canvas); delete m_labelObjects[i]; } - m_labelObjects[i] = new wxLabelShape(this, region, w, h); + m_labelObjects[i] = OnCreateLabelShape(this, region, w, h); m_labelObjects[i]->AddToCanvas(m_canvas); m_labelObjects[i]->Show(TRUE); if (dc) - m_labelObjects[i]->Move(*dc, (float)(x + xx), (float)(y + yy)); - m_labelObjects[i]->Select(TRUE); + m_labelObjects[i]->Move(*dc, (double)(x + xx), (double)(y + yy)); + m_labelObjects[i]->Select(TRUE, dc); } } } @@ -1690,6 +1676,7 @@ void wxLineShape::Select(bool select, wxDC* dc) if (m_labelObjects[i]) { m_labelObjects[i]->Select(FALSE, dc); + m_labelObjects[i]->Erase(*dc); m_labelObjects[i]->RemoveFromCanvas(m_canvas); delete m_labelObjects[i]; m_labelObjects[i] = NULL; @@ -1705,12 +1692,13 @@ void wxLineShape::Select(bool select, wxDC* dc) IMPLEMENT_DYNAMIC_CLASS(wxLineControlPoint, wxControlPoint) -wxLineControlPoint::wxLineControlPoint(wxShapeCanvas *theCanvas, wxShape *object, float size, float x, float y, int the_type): +wxLineControlPoint::wxLineControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size, double x, double y, int the_type): wxControlPoint(theCanvas, object, size, x, y, the_type) { m_xpos = x; m_ypos = y; m_type = the_type; + m_point = NULL; } wxLineControlPoint::~wxLineControlPoint() @@ -1723,8 +1711,27 @@ void wxLineControlPoint::OnDraw(wxDC& dc) } // Implement movement of Line point -void wxLineControlPoint::OnDragLeft(bool draw, float x, float y, int keys, int attachment) +void wxLineControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment) +{ + m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment); +} + +void wxLineControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment) +{ + m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment); +} + +void wxLineControlPoint::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 wxLineShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys, int attachment) +{ + wxLineControlPoint* lpt = (wxLineControlPoint*) pt; + wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); @@ -1734,14 +1741,14 @@ void wxLineControlPoint::OnDragLeft(bool draw, float x, float y, int keys, int a dc.SetPen(dottedPen); dc.SetBrush((* wxTRANSPARENT_BRUSH)); - if (m_type == CONTROL_POINT_LINE) + if (lpt->m_type == CONTROL_POINT_LINE) { m_canvas->Snap(&x, &y); - m_xpos = x; m_ypos = y; - m_point->x = x; m_point->y = y; + lpt->SetX(x); lpt->SetY(y); + lpt->m_point->x = x; lpt->m_point->y = y; - wxLineShape *lineShape = (wxLineShape *)m_shape; + wxLineShape *lineShape = (wxLineShape *)this; wxPen *old_pen = lineShape->GetPen(); wxBrush *old_brush = lineShape->GetBrush(); @@ -1756,24 +1763,27 @@ void wxLineControlPoint::OnDragLeft(bool draw, float x, float y, int keys, int a lineShape->SetBrush(old_brush); } - if (m_type == CONTROL_POINT_ENDPOINT_FROM || m_type == CONTROL_POINT_ENDPOINT_TO) + if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO) { - m_xpos = x; m_ypos = y; +// lpt->SetX(x); lpt->SetY(y); } } -void wxLineControlPoint::OnBeginDragLeft(float x, float y, int keys, int attachment) +void wxLineShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment) { + wxLineControlPoint* lpt = (wxLineControlPoint*) pt; + wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); - wxLineShape *lineShape = (wxLineShape *)m_shape; - if (m_type == CONTROL_POINT_LINE) + wxLineShape *lineShape = (wxLineShape *)this; + if (lpt->m_type == CONTROL_POINT_LINE) { + lpt->m_originalPos = * (lpt->m_point); m_canvas->Snap(&x, &y); - m_shape->Erase(dc); + this->Erase(dc); // Redraw start and end objects because we've left holes // when erasing the line @@ -1782,11 +1792,11 @@ void wxLineControlPoint::OnBeginDragLeft(float x, float y, int keys, int attachm lineShape->GetTo()->OnDraw(dc); lineShape->GetTo()->OnDrawContents(dc); - m_shape->SetDisableLabel(TRUE); + this->SetDisableLabel(TRUE); dc.SetLogicalFunction(wxXOR); - m_xpos = x; m_ypos = y; - m_point->x = x; m_point->y = y; + lpt->m_xpos = x; lpt->m_ypos = y; + lpt->m_point->x = x; lpt->m_point->y = y; wxPen *old_pen = lineShape->GetPen(); wxBrush *old_brush = lineShape->GetBrush(); @@ -1801,88 +1811,97 @@ void wxLineControlPoint::OnBeginDragLeft(float x, float y, int keys, int attachm lineShape->SetBrush(old_brush); } - if (m_type == CONTROL_POINT_ENDPOINT_FROM || m_type == CONTROL_POINT_ENDPOINT_TO) + if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO) { - Erase(dc); - lineShape->OnDraw(dc); - if (m_type == CONTROL_POINT_ENDPOINT_FROM) - { - lineShape->GetFrom()->OnDraw(dc); - lineShape->GetFrom()->OnDrawContents(dc); - } - else - { - lineShape->GetTo()->OnDraw(dc); - lineShape->GetTo()->OnDrawContents(dc); - } - m_canvas->SetCursor(GraphicsBullseyeCursor); - m_oldCursor = wxSTANDARD_CURSOR; + m_canvas->SetCursor(g_oglBullseyeCursor); + lpt->m_oldCursor = wxSTANDARD_CURSOR; } } - -void wxLineControlPoint::OnEndDragLeft(float x, float y, int keys, int attachment) + +void wxLineShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment) { + wxLineControlPoint* lpt = (wxLineControlPoint*) pt; + wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); - m_shape->SetDisableLabel(FALSE); - wxLineShape *lineShape = (wxLineShape *)m_shape; + this->SetDisableLabel(FALSE); + wxLineShape *lineShape = (wxLineShape *)this; - if (m_type == CONTROL_POINT_LINE) + if (lpt->m_type == CONTROL_POINT_LINE) { m_canvas->Snap(&x, &y); - dc.SetLogicalFunction(wxCOPY); - m_xpos = x; m_ypos = y; - m_point->x = x; m_point->y = y; + wxRealPoint pt = wxRealPoint(x, y); + + // Move the control point back to where it was; + // MoveControlPoint will move it to the new position + // if it decides it wants. We only moved the position + // during user feedback so we could redraw the line + // as it changed shape. + lpt->m_xpos = lpt->m_originalPos.x; lpt->m_ypos = lpt->m_originalPos.y; + lpt->m_point->x = lpt->m_originalPos.x; lpt->m_point->y = lpt->m_originalPos.y; - lineShape->GetEventHandler()->OnMoveLink(dc); + OnMoveMiddleControlPoint(dc, lpt, pt); } - if (m_type == CONTROL_POINT_ENDPOINT_FROM) + if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM) { - if (m_oldCursor) - m_canvas->SetCursor(m_oldCursor); - m_shape->Erase(dc); + if (lpt->m_oldCursor) + m_canvas->SetCursor(lpt->m_oldCursor); - m_xpos = x; m_ypos = y; +// this->Erase(dc); + +// lpt->m_xpos = x; lpt->m_ypos = y; if (lineShape->GetFrom()) { lineShape->GetFrom()->MoveLineToNewAttachment(dc, lineShape, x, y); - lineShape->GetFrom()->MoveLinks(dc); } } - if (m_type == CONTROL_POINT_ENDPOINT_TO) + if (lpt->m_type == CONTROL_POINT_ENDPOINT_TO) { - if (m_oldCursor) - m_canvas->SetCursor(m_oldCursor); + if (lpt->m_oldCursor) + m_canvas->SetCursor(lpt->m_oldCursor); - m_xpos = x; m_ypos = y; +// lpt->m_xpos = x; lpt->m_ypos = y; if (lineShape->GetTo()) { lineShape->GetTo()->MoveLineToNewAttachment(dc, lineShape, x, y); - lineShape->GetTo()->MoveLinks(dc); } } + + // Needed? +#if 0 int i = 0; for (i = 0; i < lineShape->GetLineControlPoints()->Number(); i++) - if (((wxRealPoint *)(lineShape->GetLineControlPoints()->Nth(i)->Data())) == m_point) + if (((wxRealPoint *)(lineShape->GetLineControlPoints()->Nth(i)->Data())) == lpt->m_point) break; // N.B. in OnMoveControlPoint, an event handler in Hardy could have deselected // the line and therefore deleted 'this'. -> GPF, intermittently. // So assume at this point that we've been blown away. - wxLineShape *lineObj = lineShape; - wxShapeCanvas *objCanvas = m_canvas; - lineObj->OnMoveControlPoint(i+1, x, y); - - if (!objCanvas->GetQuickEditMode()) objCanvas->Redraw(dc); + lineShape->OnMoveControlPoint(i+1, x, y); +#endif +} + +// This is called only when a non-end control point is moved. +bool wxLineShape::OnMoveMiddleControlPoint(wxDC& dc, wxLineControlPoint* lpt, const wxRealPoint& pt) +{ + lpt->m_xpos = pt.x; lpt->m_ypos = pt.y; + lpt->m_point->x = pt.x; lpt->m_point->y = pt.y; + + GetEventHandler()->OnMoveLink(dc); + + return TRUE; } // Implement movement of endpoint to a new attachment -void wxLineControlPoint::OnDragRight(bool draw, float x, float y, int keys, int attachment) +// OBSOLETE: done by dragging with the left button. + +#if 0 +void wxLineControlPoint::OnDragRight(bool draw, double x, double y, int keys, int attachment) { if (m_type == CONTROL_POINT_ENDPOINT_FROM || m_type == CONTROL_POINT_ENDPOINT_TO) { @@ -1890,7 +1909,7 @@ void wxLineControlPoint::OnDragRight(bool draw, float x, float y, int keys, int } } -void wxLineControlPoint::OnBeginDragRight(float x, float y, int keys, int attachment) +void wxLineControlPoint::OnBeginDragRight(double x, double y, int keys, int attachment) { wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); @@ -1910,12 +1929,12 @@ void wxLineControlPoint::OnBeginDragRight(float x, float y, int keys, int attach lineShape->GetTo()->GetEventHandler()->OnDraw(dc); lineShape->GetTo()->GetEventHandler()->OnDrawContents(dc); } - m_canvas->SetCursor(GraphicsBullseyeCursor); + m_canvas->SetCursor(g_oglBullseyeCursor); m_oldCursor = wxSTANDARD_CURSOR; } } -void wxLineControlPoint::OnEndDragRight(float x, float y, int keys, int attachment) +void wxLineControlPoint::OnEndDragRight(double x, double y, int keys, int attachment) { wxClientDC dc(GetCanvas()); GetCanvas()->PrepareDC(dc); @@ -1933,7 +1952,7 @@ void wxLineControlPoint::OnEndDragRight(float x, float y, int keys, int attachme lineShape->GetFrom()->EraseLinks(dc); int new_attachment; - float distance; + double distance; if (lineShape->GetFrom()->HitTest(x, y, &new_attachment, &distance)) lineShape->SetAttachments(new_attachment, lineShape->GetAttachmentTo()); @@ -1954,7 +1973,7 @@ void wxLineControlPoint::OnEndDragRight(float x, float y, int keys, int attachme lineShape->GetTo()->EraseLinks(dc); int new_attachment; - float distance; + double distance; if (lineShape->GetTo()->HitTest(x, y, &new_attachment, &distance)) lineShape->SetAttachments(lineShape->GetAttachmentFrom(), new_attachment); @@ -1968,6 +1987,7 @@ void wxLineControlPoint::OnEndDragRight(float x, float y, int keys, int attachme lineShape->OnMoveControlPoint(i+1, x, y); if (!m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc); } +#endif /* * Get the point on the given line (x1, y1) (x2, y2) @@ -1975,22 +1995,22 @@ void wxLineControlPoint::OnEndDragRight(float x, float y, int keys, int attachme * returned values in x and y */ -void GetPointOnLine(float x1, float y1, float x2, float y2, - float length, float *x, float *y) +void GetPointOnLine(double x1, double y1, double x2, double y2, + double length, double *x, double *y) { - float l = (float)sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)); + double l = (double)sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)); if (l < 0.01) - l = (float) 0.01; + l = (double) 0.01; - float i_bar = (x2 - x1)/l; - float j_bar = (y2 - y1)/l; + double i_bar = (x2 - x1)/l; + double j_bar = (y2 - y1)/l; *x = (- length*i_bar) + x2; *y = (- length*j_bar) + y2; } -wxArrowHead *wxLineShape::AddArrow(WXTYPE type, int end, float size, float xOffset, +wxArrowHead *wxLineShape::AddArrow(WXTYPE type, int end, double size, double xOffset, const wxString& name, wxPseudoMetaFile *mf, long arrowId) { wxArrowHead *arrow = new wxArrowHead(type, end, size, xOffset, name, mf, arrowId); @@ -2191,9 +2211,9 @@ bool wxLineShape::DeleteArrowHead(long id) * */ -float wxLineShape::FindMinimumWidth() +double wxLineShape::FindMinimumWidth() { - float minWidth = 0.0; + double minWidth = 0.0; wxNode *node = m_arcArrows.First(); while (node) { @@ -2208,7 +2228,7 @@ float wxLineShape::FindMinimumWidth() // scale it to give it reasonable aesthetics // when drawing with line. if (minWidth > 0.0) - minWidth = (float)(minWidth * 1.4); + minWidth = (double)(minWidth * 1.4); else minWidth = 20.0; @@ -2220,15 +2240,15 @@ float wxLineShape::FindMinimumWidth() // Find which position we're talking about at this (x, y). // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END -int wxLineShape::FindLinePosition(float x, float y) +int wxLineShape::FindLinePosition(double x, double y) { - float startX, startY, endX, endY; + double startX, startY, endX, endY; GetEnds(&startX, &startY, &endX, &endY); // Find distances from centre, start and end. The smallest wins. - float centreDistance = (float)(sqrt((x - m_xpos)*(x - m_xpos) + (y - m_ypos)*(y - m_ypos))); - float startDistance = (float)(sqrt((x - startX)*(x - startX) + (y - startY)*(y - startY))); - float endDistance = (float)(sqrt((x - endX)*(x - endX) + (y - endY)*(y - endY))); + double centreDistance = (double)(sqrt((x - m_xpos)*(x - m_xpos) + (y - m_ypos)*(y - m_ypos))); + double startDistance = (double)(sqrt((x - startX)*(x - startX) + (y - startY)*(y - startY))); + double endDistance = (double)(sqrt((x - endX)*(x - endX) + (y - endY)*(y - endY))); if (centreDistance < startDistance && centreDistance < endDistance) return ARROW_POSITION_MIDDLE; @@ -2324,7 +2344,7 @@ wxRealPoint *wxLineShape::GetNextControlPoint(wxShape *nodeObject) IMPLEMENT_DYNAMIC_CLASS(wxArrowHead, wxObject) -wxArrowHead::wxArrowHead(WXTYPE type, int end, float size, float dist, const wxString& name, +wxArrowHead::wxArrowHead(WXTYPE type, int end, double size, double dist, const wxString& name, wxPseudoMetaFile *mf, long arrowId) { m_arrowType = type; m_arrowEnd = end; m_arrowSize = size; @@ -2359,21 +2379,27 @@ wxArrowHead::~wxArrowHead() if (m_metaFile) delete m_metaFile; } -void wxArrowHead::SetSize(float size) +void wxArrowHead::SetSize(double size) { m_arrowSize = size; if ((m_arrowType == ARROW_METAFILE) && m_metaFile) { - float oldWidth = m_metaFile->m_width; + double oldWidth = m_metaFile->m_width; if (oldWidth == 0.0) return; - float scale = (float)(size/oldWidth); + double scale = (double)(size/oldWidth); if (scale != 1.0) m_metaFile->Scale(scale, scale); } } +// Can override this to create a different class of label shape +wxLabelShape* wxLineShape::OnCreateLabelShape(wxLineShape *parent, wxShapeRegion *region, double w, double h) +{ + return new wxLabelShape(parent, region, w, h); +} + /* * Label object * @@ -2381,7 +2407,7 @@ void wxArrowHead::SetSize(float size) IMPLEMENT_DYNAMIC_CLASS(wxLabelShape, wxRectangleShape) -wxLabelShape::wxLabelShape(wxLineShape *parent, wxShapeRegion *region, float w, float h):wxRectangleShape(w, h) +wxLabelShape::wxLabelShape(wxLineShape *parent, wxShapeRegion *region, double w, double h):wxRectangleShape(w, h) { m_lineShape = parent; m_shapeRegion = region; @@ -2397,53 +2423,58 @@ void wxLabelShape::OnDraw(wxDC& dc) if (m_lineShape && !m_lineShape->GetDrawHandles()) return; - 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_pen) { if (m_pen->GetWidth() == 0) - dc.SetPen(transparent_pen); + dc.SetPen(g_oglTransparentPen); else dc.SetPen(m_pen); } dc.SetBrush(wxTRANSPARENT_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 wxLabelShape::OnDrawContents(wxDC& dc) { } -void wxLabelShape::OnDragLeft(bool draw, float x, float y, int keys, int attachment) +void wxLabelShape::OnDragLeft(bool draw, double x, double y, int keys, int attachment) { wxRectangleShape::OnDragLeft(draw, x, y, keys, attachment); } -void wxLabelShape::OnBeginDragLeft(float x, float y, int keys, int attachment) +void wxLabelShape::OnBeginDragLeft(double x, double y, int keys, int attachment) { wxRectangleShape::OnBeginDragLeft(x, y, keys, attachment); } -void wxLabelShape::OnEndDragLeft(float x, float y, int keys, int attachment) +void wxLabelShape::OnEndDragLeft(double x, double y, int keys, int attachment) { wxRectangleShape::OnEndDragLeft(x, y, keys, attachment); } -bool wxLabelShape::OnMovePre(wxDC& dc, float x, float y, float old_x, float old_y, bool display) +bool wxLabelShape::OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display) { - m_shapeRegion->SetSize(m_width, m_height); + return m_lineShape->OnLabelMovePre(dc, this, x, y, old_x, old_y, display); +} + +bool wxLineShape::OnLabelMovePre(wxDC& dc, wxLabelShape* labelShape, double x, double y, double old_x, double old_y, bool display) +{ + labelShape->m_shapeRegion->SetSize(labelShape->GetWidth(), labelShape->GetHeight()); // Find position in line's region list int i = 0; - wxNode *node = m_lineShape->GetRegions().First(); + wxNode *node = GetRegions().First(); while (node) { - if (m_shapeRegion == (wxShapeRegion *)node->Data()) + if (labelShape->m_shapeRegion == (wxShapeRegion *)node->Data()) node = NULL; else { @@ -2451,30 +2482,33 @@ bool wxLabelShape::OnMovePre(wxDC& dc, float x, float y, float old_x, float old_ i ++; } } - float xx, yy; - m_lineShape->GetLabelPosition(i, &xx, &yy); + double xx, yy; + GetLabelPosition(i, &xx, &yy); // Set the region's offset, relative to the default position for // each region. - m_shapeRegion->SetPosition((float)(x - xx), (float)(y - yy)); + labelShape->m_shapeRegion->SetPosition((double)(x - xx), (double)(y - yy)); + + labelShape->SetX(x); + labelShape->SetY(y); // Need to reformat to fit region. - if (m_shapeRegion->GetText()) + if (labelShape->m_shapeRegion->GetText()) { - wxString s(m_shapeRegion->GetText()); - m_lineShape->FormatText(dc, s, i); - m_lineShape->DrawRegion(dc, m_shapeRegion, xx, yy); + wxString s(labelShape->m_shapeRegion->GetText()); + labelShape->FormatText(dc, s, i); + DrawRegion(dc, labelShape->m_shapeRegion, xx, yy); } return TRUE; } // Divert left and right clicks to line object -void wxLabelShape::OnLeftClick(float x, float y, int keys, int attachment) +void wxLabelShape::OnLeftClick(double x, double y, int keys, int attachment) { m_lineShape->GetEventHandler()->OnLeftClick(x, y, keys, attachment); } -void wxLabelShape::OnRightClick(float x, float y, int keys, int attachment) +void wxLabelShape::OnRightClick(double x, double y, int keys, int attachment) { m_lineShape->GetEventHandler()->OnRightClick(x, y, keys, attachment); }