]> Shamusworld >> Repos - ttedit/blob - src/editwindow.cpp
Added implementation of Polygon Rotate and Flip Winding tools.
[ttedit] / src / editwindow.cpp
1 //
2 // TTEDIT.CPP - The TrueType Editor
3 // by James L. Hammons
4 // (C) 2004 Underground Software
5 //
6 // JLH = James L. Hammons <jlhamm@acm.org>
7 //
8 // Who  When        What
9 // ---  ----------  -------------------------------------------------------------
10 // JLH  08/28/2008  Created this file
11 // JLH  09/02/2008  Separated scrolling from dedicated tool to MMB drag
12 // JLH  03/13/2009  Converted from wxWidgets to Qt
13 //
14
15 // FIXED:
16 //
17 // - Fixed scrolling
18 //
19 // STILL TO BE DONE:
20 //
21 // - Fix bug in Glyphpoints when dragging on an empty canvas or loading a font
22 // - Fix zooming, settings (ini)
23 // - Fix point adding bug 1: should be able to add points to empty canvas
24 // - Fix point adding bug 2: should be able to add point successfully to single
25 //   point on screen
26 // - Add poly multi-select
27 // - Add point multi-select
28 // - Undo system
29 //
30
31 // Uncomment this for debugging...
32 #define DEBUG
33 #define DEBUGFOO            // Various tool debugging...
34 #define DEBUGTP                         // Toolpalette debugging...
35
36 #include "editwindow.h"
37 #include "charwindow.h"
38 #include "debug.h"
39 #include "graphicprimitives.h"
40 #include "mainwindow.h"
41 #include "ttedit.h"
42 #include "vector.h"
43
44
45 EditWindow::EditWindow(QWidget * parent/*= NULL*/): QWidget(parent),
46         scale(1.0), offsetX(-10), offsetY(-10), tool(TOOLSelect),
47         ptHighlight(-1), oldPtHighlight(-1), ptNextHighlight(-1), oldPtNextHighlight(-1),
48         polyFirstPoint(true), showRotationCenter(false), haveZeroPoint(false)
49 {
50         setBackgroundRole(QPalette::Base);
51         setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
52
53         toolPalette = new ToolWindow();
54         CreateCursors();
55         setCursor(cur[TOOLSelect]);
56         setMouseTracking(true);
57 }
58
59
60 QSize EditWindow::minimumSizeHint() const
61 {
62         return QSize(50, 50);
63 }
64
65
66 QSize EditWindow::sizeHint() const
67 {
68         return QSize(400, 400);
69 }
70
71
72 void EditWindow::CreateCursors(void)
73 {
74         int hotx[11] = {  1,  1, 11, 15,  1,  1,  1,  1,  1,  1,  1 };
75         int hoty[11] = {  1,  1, 11, 13,  1,  1,  1,  1,  1,  1,  1 };
76         char cursorName[11][48] = { "select", "select-poly", "scroll", "zoom", "add-point",
77                 "add-poly", "del-point", "del-poly", "rotate", "rotate", "select" };
78
79         for(int i=0; i<11; i++)
80         {
81                 QString s;
82                 s.sprintf(":/res/cursor-%s.png", cursorName[i]);
83                 QPixmap pmTmp(s);
84                 cur[i] = QCursor(pmTmp, hotx[i], hoty[i]);
85         }
86 }
87
88
89 QPoint EditWindow::GetAdjustedMousePosition(QMouseEvent * event)
90 {
91         QSize winSize = size();
92         // This is undoing the transform, e.g. going from client coords to local coords.
93         // In essence, the height - y is height + (y * -1), the (y * -1) term doing the
94         // conversion of the y-axis from increasing bottom to top.
95         return QPoint(offsetX + event->x(), offsetY + (winSize.height() - event->y()));
96 }
97
98
99 QPoint EditWindow::GetAdjustedClientPosition(int x, int y)
100 {
101         QSize winSize = size();
102
103         // VOODOO ALERT (ON Y COMPONENT!!!!)
104         return QPoint(-offsetX + x, (winSize.height() - (-offsetY + y)) * +1.0);
105 }
106
107
108 /*
109 TODO:
110  o  Different colors for polys on selected points
111  o  Different colors for handles on non-selected polys
112  o  Line of sight (dashed, dotted) for off-curve points
113  o  Repaints for press/release of CTRL/SHIFT during point creation
114 */
115 void EditWindow::paintEvent(QPaintEvent * /*event*/)
116 {
117         QPainter p(this);
118 //hm, causes lockup (or does it???)
119         p.setRenderHint(QPainter::Antialiasing);
120 //Doesn't do crap!
121 //dc.SetBackground(*wxWHITE_BRUSH);
122
123 // Due to the screwiness of wxWidgets coord system, the origin is ALWAYS
124 // the upper left corner--regardless of axis orientation, etc...
125 //      int width, height;
126 //      dc.GetSize(&width, &height);
127         QSize winSize = size();
128
129 //      dc.SetDeviceOrigin(-offsetX, height - (-offsetY));
130 //      dc.SetAxisOrientation(true, true);
131         p.translate(QPoint(-offsetX, winSize.height() - (-offsetY)));
132         p.scale(1.0, -1.0);
133
134 // Scrolling can be done by using OffsetViewportOrgEx
135 // Scaling can be done by adjusting SetWindowExtEx (it's denominator of txform)
136 // you'd use: % = ViewportExt / WindowExt
137 // But it makes the window look like crap: fuggetuboutit.
138 // Instead, we have to scale EVERYTHING by hand. Crap!
139 // It's not *that* bad, but not as convenient either...
140
141 //      dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0x00, 0x00, 0xFF), 1, wxDOT)));
142 ////    dc.DrawLine(0, 0, 10, 10);
143         p.setPen(QPen(Qt::blue, 1.0, Qt::DotLine));
144
145         // Draw coordinate axes
146
147 //      dc.CrossHair(0, 0);
148         p.drawLine(0, -16384, 0, 16384);
149         p.drawLine(-16384, 0, 16384, 0);
150
151         // Draw rotation center (if active)
152
153         if (showRotationCenter)
154         {
155                 p.setPen(QPen(Qt::red, 2.0, Qt::SolidLine));
156                 p.drawLine(rotationCenter.x() + 7, rotationCenter.y(), rotationCenter.x() - 7, rotationCenter.y());
157                 p.drawLine(rotationCenter.x(), rotationCenter.y() + 7, rotationCenter.x(), rotationCenter.y() - 7);
158         }
159
160         // Draw points
161
162         for(int i=0; i<pts.GetNumPoints(); i++)
163         {
164                 if (i == ptHighlight)
165                 {
166                         p.setPen(QPen(Qt::red, 1.0, Qt::SolidLine));
167
168                         if (pts.GetOnCurve(i))
169                         {
170                                 DrawSquareDotN(p, pts.GetX(i), pts.GetY(i), 7);
171                                 DrawSquareDotN(p, pts.GetX(i), pts.GetY(i), 9);
172                         }
173                         else
174                         {
175                                 DrawRoundDotN(p, pts.GetX(i), pts.GetY(i), 7);
176                                 DrawRoundDotN(p, pts.GetX(i), pts.GetY(i), 9);
177                         }
178                 }
179                 else if ((i == ptHighlight || i == ptNextHighlight) && tool == TOOLAddPt)
180                 {
181                         p.setPen(QPen(Qt::green, 1.0, Qt::SolidLine));
182
183                         if (pts.GetOnCurve(i))
184                         {
185                                 DrawSquareDotN(p, pts.GetX(i), pts.GetY(i), 7);
186                                 DrawSquareDotN(p, pts.GetX(i), pts.GetY(i), 9);
187                         }
188                         else
189                         {
190                                 DrawRoundDotN(p, pts.GetX(i), pts.GetY(i), 7);
191                                 DrawRoundDotN(p, pts.GetX(i), pts.GetY(i), 9);
192                         }
193                 }
194                 else
195                 {
196                         p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
197
198                         if (pts.GetOnCurve(i))
199                                 DrawSquareDot(p, pts.GetX(i), pts.GetY(i));
200                         else
201                                 DrawRoundDot(p, pts.GetX(i), pts.GetY(i));
202                 }
203
204                 if (tool == TOOLDelPt && i == ptHighlight)
205                 {
206                         p.setPen(QPen(Qt::red, 1.0, Qt::SolidLine));
207                         p.drawLine(pts.GetX(i) - 5, pts.GetY(i) - 5, pts.GetX(i) + 5, pts.GetY(i) + 5);
208                         p.drawLine(pts.GetX(i) + 5, pts.GetY(i) - 5, pts.GetX(i) - 5, pts.GetY(i) + 5);
209                 }
210         }
211
212         // Draw curve formed by points
213
214         p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
215         DrawGlyph(p, pts);
216
217         if (haveZeroPoint)
218         {
219                 // Rotation code
220                 GlyphPoints rotated = pts;
221
222                 if (tool == TOOLRotate)
223                         rotated.RotatePoints(rotationAngle, IPoint(rotationCenter.x(), rotationCenter.y()));
224                 else if (tool == TOOLRotatePoly)
225                 {
226                         uint16 poly = rotated.GetPolyForPointNumber(ptHighlight);
227                         rotated.RotatePolyAroundCentroid(poly, rotationAngle);
228                 }
229
230                 p.setPen(QPen(QColor(255, 0, 255), 1.0, Qt::SolidLine));
231                 DrawGlyph(p, rotated);
232         }
233 }
234
235
236 void EditWindow::DrawGlyph(QPainter & p, GlyphPoints & glyph)
237 {
238         for(int poly=0; poly<glyph.GetNumPolys(); poly++)
239         {
240                 if (glyph.GetNumPoints(poly) > 2)
241                 {
242                         // Initial move...
243                         // If it's not on curve, then move to it, otherwise move to last point...
244
245                         int x, y;
246
247                         if (glyph.GetOnCurve(poly, glyph.GetNumPoints(poly) - 1))
248                                 x = (int)glyph.GetX(poly, glyph.GetNumPoints(poly) - 1), y = (int)glyph.GetY(poly, glyph.GetNumPoints(poly) - 1);
249                         else
250                                 x = (int)glyph.GetX(poly, 0), y = (int)glyph.GetY(poly, 0);
251
252                         for(int i=0; i<glyph.GetNumPoints(poly); i++)
253                         {
254                                 if (glyph.GetOnCurve(poly, i))
255                                 {
256                                         p.drawLine(x, y, glyph.GetX(poly, i), glyph.GetY(poly, i));
257                                         x = (int)glyph.GetX(poly, i), y = (int)glyph.GetY(poly, i);
258                                 }
259                                 else
260                                 {
261                                         uint32 prev = glyph.GetPrev(poly, i), next = glyph.GetNext(poly, i);
262                                         float px = glyph.GetX(poly, prev), py = glyph.GetY(poly, prev),
263                                                 nx = glyph.GetX(poly, next), ny = glyph.GetY(poly, next);
264
265                                         if (!glyph.GetOnCurve(poly, prev))
266                                                 px = (px + glyph.GetX(poly, i)) / 2.0f,
267                                                 py = (py + glyph.GetY(poly, i)) / 2.0f;
268
269                                         if (!glyph.GetOnCurve(poly, next))
270                                                 nx = (nx + glyph.GetX(poly, i)) / 2.0f,
271                                                 ny = (ny + glyph.GetY(poly, i)) / 2.0f;
272
273                                         Bezier(p, point(px, py), point(glyph.GetX(poly, i), glyph.GetY(poly, i)), point(nx, ny));
274                                         x = (int)nx, y = (int)ny;
275
276                                         if (glyph.GetOnCurve(poly, next))
277                                                 i++;                                    // Following point is on curve, so move past it
278                                 }
279                         }
280                 }
281         }
282 }
283
284
285 void EditWindow::mousePressEvent(QMouseEvent * event)
286 {
287         if (event->button() == Qt::RightButton)
288         {
289                 toolPalette->move(event->globalPos());
290                 toolPalette->setVisible(true);
291                 setCursor(cur[TOOLSelect]);
292                 toolPalette->prevTool = TOOLSelect;
293         }
294         else if (event->button() == Qt::MidButton)
295         {
296                 setCursor(cur[2]);                                                      // Scrolling cursor
297         }
298         else if (event->button() == Qt::LeftButton)
299         {
300                 if (tool == TOOLScroll || tool == TOOLZoom)
301 ;//meh                  CaptureMouse();                                         // Make sure we capture the mouse when in scroll/zoom mode
302                 else if (tool == TOOLAddPt)             // "Add Point" tool
303                 {
304                         if (pts.GetNumPoints() > 0)
305                         {
306                                 QPoint pt = GetAdjustedMousePosition(event);
307                                 pts.InsertPoint(pts.GetNext(ptHighlight), pt.x(), pt.y(), ((event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier) ? false : true));
308                                 ptHighlight = ptNextHighlight;
309                                 update();
310                         }
311                 }
312                 else if (tool == TOOLAddPoly)   // "Add Poly" tool
313                 {
314 #ifdef DEBUGFOO
315 WriteLogMsg("Adding point... # polys: %u, # points: %u", pts.GetNumPolys(), pts.GetNumPoints());
316 #endif
317                         if (polyFirstPoint)
318                         {
319                                 polyFirstPoint = false;
320                                 pts.AddNewPolyAtEnd();
321                         }
322
323                         QPoint pt = GetAdjustedMousePosition(event);
324 //printf("GetAdjustedMousePosition = %i, %i\n", pt.x(), pt.y());
325                         // Append a point to the end of the structure
326                         pts += IPoint(pt.x(), pt.y(), ((event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier) ? false : true));
327                         ptHighlight = pts.GetNumPoints() - 1;
328                         update();
329 #ifdef DEBUGFOO
330 WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumPoints());
331 #endif
332                 }
333                 else if (tool == TOOLSelect || tool == TOOLPolySelect)
334                 {
335                         if (pts.GetNumPoints() > 0)
336                         {
337                                 pt = GetAdjustedClientPosition(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
338 //printf("GetAdjustedClientPosition = %i, %i\n", pt.x(), pt.y());
339 //                              WarpPointer(pt.x, pt.y);
340                                 QCursor::setPos(mapToGlobal(pt));
341
342                                 if (event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier)
343                                 {
344                                         pts.SetOnCurve(ptHighlight, !pts.GetOnCurve(ptHighlight));
345                                         update();
346                                 }
347                         }
348                 }
349                 else if (tool == TOOLDelPt)
350                 {
351                         if (pts.GetNumPoints() > 0)
352 //Or could use:
353 //                      if (ptHighlight != -1)
354                         {
355 //This assumes that WM_MOUSEMOVE happens before this!
356 //The above commented out line should take care of this contingency... !!! FIX !!!
357                                 pts.DeletePoint(ptHighlight);
358                                 update();
359                         }
360                 }
361                 else if (tool == TOOLRotate)
362                 {
363                         // I think what's needed here is to keep the initial mouse click,
364                         // paint the rotation center, then use the 1st mouse move event to establish
365                         // the rotation "zero line", which becomes the line of reference to all
366                         // subsequent mouse moves.
367                         rotationCenter = GetAdjustedMousePosition(event);
368                         showRotationCenter = true;
369                         haveZeroPoint = false;
370                         rotationAngle = 0;
371                         update();
372                 }
373                 else if (tool == TOOLRotatePoly)
374                 {
375                         IPoint centroid = pts.GetPolyCentroid(pts.GetPolyForPointNumber(ptHighlight));
376                         rotationCenter = QPoint(centroid.x, centroid.y);
377                         showRotationCenter = true;
378                         pt = GetAdjustedClientPosition(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
379                         QCursor::setPos(mapToGlobal(pt));
380                         rotationZeroPoint = QPoint(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
381                         haveZeroPoint = true;
382                         rotationAngle = 0;
383                         update();
384                 }
385                 else if (tool == TOOLFlipWinding)
386                 {
387 //                      IPoint centroid = pts.GetPolyCentroid(pts.GetPolyForPointNumber(ptHighlight));
388 //                      rotationCenter = QPoint(centroid.x, centroid.y);
389 //                      showRotationCenter = true;
390                         pts.InvertPolyDrawSequence(pts.GetPolyForPointNumber(ptHighlight));
391                         pt = GetAdjustedClientPosition(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
392                         QCursor::setPos(mapToGlobal(pt));
393 //                      rotationZeroPoint = QPoint(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
394 //                      haveZeroPoint = true;
395 //                      rotationAngle = 0;
396                         update();
397 //                      ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&pts);
398 //                      ((TTEdit *)qApp)->charWnd->update();
399                 }
400         }
401
402         event->accept();
403 }
404
405
406 void EditWindow::mouseMoveEvent(QMouseEvent * event)
407 {
408         if (event->buttons() == Qt::RightButton)
409         {
410                 ToolType newTool = toolPalette->FindSelectedTool();
411
412                 if (newTool != toolPalette->prevTool)
413                 {
414                         toolPalette->prevTool = newTool;
415                         toolPalette->repaint();
416                 }
417         }
418         else if (event->buttons() == Qt::MidButton)
419         {
420                 // Calc offset from previous point
421                 pt = event->pos();
422                 ptOffset = QPoint(pt.x() - ptPrevious.x(), pt.y() - ptPrevious.y());
423
424 // Then multiply it by the scaling factor. Whee!
425                 // This looks wacky because we're using screen coords for the offset...
426                 // Otherwise, we would subtract both offsets!
427                 offsetX -= ptOffset.x(), offsetY += ptOffset.y();
428                 update();
429                 ptPrevious = pt;
430         }
431         else if (event->buttons() == Qt::LeftButton)
432         {
433                 if (tool == TOOLAddPt || tool == TOOLAddPoly || tool == TOOLSelect)
434                 {
435                         if (tool != TOOLAddPt || pts.GetNumPoints() > 0)//yecch.
436                         {
437 //temporary, for testing. BTW, Select drag bug is here...!
438 #if 1
439                                 QPoint pt2 = GetAdjustedMousePosition(event);
440                                 pts.SetXY(ptHighlight, pt2.x(), pt2.y());
441                                 update();
442 #endif
443                         }
444                 }
445                 else if (tool == TOOLPolySelect)
446                 {
447                         if (pts.GetNumPoints() > 0)
448                         {
449                                 QPoint pt2 = GetAdjustedMousePosition(event);
450                                 // Should also set onCurve here as well, depending on keystate
451 //Or should we?
452                                 pts.OffsetPoly(pts.GetPoly(ptHighlight), pt2.x() - pts.GetX(ptHighlight), pt2.y() - pts.GetY(ptHighlight));
453                                 update();
454                         }
455                 }
456                 else if (tool == TOOLRotate || tool == TOOLRotatePoly)
457                 {
458                         if (pts.GetNumPoints() > 0)
459                         {
460                                 if (!haveZeroPoint)
461                                 {
462                                         rotationZeroPoint = GetAdjustedMousePosition(event);
463                                         haveZeroPoint = true;
464                                 }
465                                 else
466                                 {
467                                         // Figure out the angle between the "zero" vector and the current one,
468                                         // then rotate all points relative to the "zero" vector (done by paint())
469                                         QPoint currentPoint = GetAdjustedMousePosition(event);
470                                         Vector v1(rotationZeroPoint.x(), rotationZeroPoint.y(), 0,
471                                                 rotationCenter.x(), rotationCenter.y(), 0);
472                                         Vector v2(currentPoint.x(), currentPoint.y(), 0,
473                                                 rotationCenter.x(), rotationCenter.y(), 0);
474 //                                      rotationAngle = v1.Angle(v2);
475                                         rotationAngle = v2.Angle(v1);
476
477                                         QString s;
478                                         s.sprintf("%.3f degrees", rotationAngle * 180.0 / 3.14159265358979323);
479                                         ((TTEdit *)qApp)->mainWindow->statusBar()->showMessage(s);
480                                 }
481
482                                 update();
483                         }
484                 }
485         }
486         else if (event->buttons() == Qt::NoButton)
487         {
488                 // Moving, not dragging...
489                 if (tool == TOOLSelect || tool == TOOLDelPt || tool == TOOLAddPt
490                         || tool == TOOLPolySelect || tool == TOOLRotatePoly || tool == TOOLFlipWinding)
491                 {
492                         QPoint pt2 = GetAdjustedMousePosition(event);
493                         double closest = 1.0e+99;
494
495                         for(int i=0; i<pts.GetNumPoints(); i++)
496                         {
497                                 double dist = ((pt2.x() - pts.GetX(i)) * (pt2.x() - pts.GetX(i)))
498                                         + ((pt2.y() - pts.GetY(i)) * (pt2.y() - pts.GetY(i)));
499
500                                 if (dist < closest)
501                                         closest = dist, ptHighlight = i;
502                         }
503
504                         if (ptHighlight != oldPtHighlight)
505                         {
506                                 oldPtHighlight = ptHighlight;
507                                 update();
508                         }
509
510                         // What follows here looks like voodoo, but is really simple. What we do is
511                         // check to see if the mouse point has a perpendicular intersection with any of
512                         // the line segments. If it does, calculate the length of the perpendicular
513                         // and choose the smallest length. If there is no perpendicular, then choose the
514                         // length of line connecting the closer of either the first endpoint or the
515                         // second and choose the smallest of those.
516
517                         // There is one bit of math that looks like voodoo to me ATM--will explain once
518                         // I understand it better (the calculation of the length of the perpendicular).
519
520                         if (pts.GetNumPoints() > 1 && tool == TOOLAddPt)
521                         {
522                                 double smallest = 1.0e+99;
523
524                                 for(int i=0; i<pts.GetNumPoints(); i++)
525                                 {
526                                         int32 p1x = pts.GetX(i), p1y = pts.GetY(i),
527                                                 p2x = pts.GetX(pts.GetNext(i)), p2y = pts.GetY(pts.GetNext(i));
528
529                                         Vector ls(p2x, p2y, 0, p1x, p1y, 0), v1(pt2.x(), pt2.y(), 0, p1x, p1y, 0),
530                                                 v2(pt2.x(), pt2.y(), 0, p2x, p2y, 0);
531                                         double pp = ls.Dot(v1) / ls.Magnitude(), dist;
532 // Geometric interpretation:
533 // pp is the paremeterized point on the vector ls where the perpendicular intersects ls.
534 // If pp < 0, then the perpendicular lies beyond the 1st endpoint. If pp > length of ls,
535 // then the perpendicular lies beyond the 2nd endpoint.
536
537                                         if (pp < 0.0)
538                                                 dist = v1.Magnitude();
539                                         else if (pp > ls.Magnitude())
540                                                 dist = v2.Magnitude();
541                                         else                                    // distance = ?Det?(ls, v1) / |ls|
542                                                 dist = fabs((ls.x * v1.y - v1.x * ls.y) / ls.Magnitude());
543
544 //The answer to the above looks like it might be found here:
545 //
546 //If the segment endpoints are s and e, and the point is p, then the test for the perpendicular
547 //intercepting the segment is equivalent to insisting that the two dot products {s-e}.{s-p} and
548 //{e-s}.{e-p} are both non-negative.  Perpendicular distance from the point to the segment is
549 //computed by first computing the area of the triangle the three points form, then dividing by the
550 //length of the segment.  Distances are done just by the Pythagorean theorem.  Twice the area of the
551 //triangle formed by three points is the determinant of the following matrix:
552 //
553 //sx sy 1
554 //ex ey 1
555 //px py 1
556 //
557 //By translating the start point to the origin, this can be rewritten as:
558 //By subtracting row 1 from all rows, you get the following:
559 //[because sx = sy = 0. you could leave out the -sx/y terms below. because we subtracted
560 // row 1 from all rows (including row 1) row 1 turns out to be zero. duh!]
561 //
562 //0         0         0
563 //(ex - sx) (ey - sy) 0
564 //(px - sx) (py - sy) 0
565 //
566 //which greatly simplifies the calculation of the determinant.
567
568                                         if (dist < smallest)
569                                                 smallest = dist, ptNextHighlight = pts.GetNext(i), ptHighlight = i;
570                                 }
571
572                                 if (ptNextHighlight != oldPtNextHighlight)
573                                 {
574                                         oldPtNextHighlight = ptNextHighlight;
575                                         update();
576                                 }
577                         }
578                 }
579
580                 ptPrevious = event->pos();
581         }
582
583         event->accept();
584 }
585
586
587 void EditWindow::mouseReleaseEvent(QMouseEvent * event)
588 {
589         if (event->button() == Qt::RightButton)
590         {
591                 ToolType newTool = toolPalette->FindSelectedTool();
592
593                 // We only change the tool if a new one was actually selected. Otherwise, we do nothing.
594                 if (newTool != TOOLNone)
595                 {
596                         tool = newTool;
597
598                         if (tool == TOOLScroll || tool == TOOLZoom || tool == TOOLAddPoly
599                                 || tool == TOOLDelPoly)
600                                 ptHighlight = -1;
601
602                         if (tool == TOOLAddPoly)
603                                 polyFirstPoint = true;
604                 }
605
606                 toolPalette->setVisible(false);
607                 setCursor(cur[tool]);
608                 // Just in case we changed highlighting style with the new tool...
609                 update();
610         }
611         else if (event->button() == Qt::MidButton)
612         {
613                 setCursor(cur[tool]);                                           // Restore previous cursor
614         }
615         else if (event->button() == Qt::LeftButton)
616         {
617                 if (showRotationCenter)
618                 {
619                         showRotationCenter = false;
620                         haveZeroPoint = false;
621
622                         if (tool == TOOLRotate)
623                                 pts.RotatePoints(rotationAngle, IPoint(rotationCenter.x(), rotationCenter.y()));
624                         else
625                         {
626                                 uint16 poly = pts.GetPolyForPointNumber(ptHighlight);
627                                 pts.RotatePolyAroundCentroid(poly, rotationAngle);
628                         }
629
630                         update();
631                         ((TTEdit *)qApp)->mainWindow->statusBar()->showMessage("");
632                 }
633
634 //              if (tool == TOOLScroll || tool == TOOLZoom)
635 //                      ReleaseMouse();
636 //this is prolly too much
637                 ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&pts);
638                 ((TTEdit *)qApp)->charWnd->update();
639
640         }
641
642         event->accept();
643 }