// Who When What
// --- ---------- -------------------------------------------------------------
// JLH 08/28/2008 Created this file
+// JLH 03/19/2009 Converted from wxWidgets to Qt
//
// FIXED:
//
// STILL TO BE DONE:
//
-// - Fix problem with owned window causing main window refresh problems
-// (ironically enough, it doesn't seem to be a problem anymore...)
+// - Fix "window disappears when tool win comes up" problem
+// - Render of main window points
//
#include "charwindow.h"
+#include "debug.h"
+
+CharWindow::CharWindow(QWidget * parent/*= NULL*/): QWidget(parent, Qt::Tool), path(NULL)
+{
+ setWindowTitle("Character: Unknown");
+}
+
+void CharWindow::MakePathFromPoints(GlyphPoints * gp)
+{
+ if (gp == NULL)
+ return;
+
+ if (path != NULL)
+ delete path;
+
+ path = new QPainterPath();
+
+#if 0
+ try
+ {
+ path->moveTo(gp->GetX(0), gp->GetY(0));
+ }
+ catch (int e)
+ {
+ if (e == GP_OUT_OF_RANGE)
+ WriteLogMsg("CharWindow: Caught GP_OUT_OF_RANGE exception.\n");
+ }
+
+ for(int i=1; i<gp->GetNumPoints(); i++)
+ {
+ }
+#endif
+
+ // Draw curve formed by points
+
+ for(int poly=0; poly<gp->GetNumPolys(); poly++)
+ {
+ if (gp->GetNumPoints(poly) > 2)
+ {
+ // Initial move...
+ // If it's not on curve, then move to it, otherwise move to last point...
+
+ int x, y;
+
+ if (gp->GetOnCurve(poly, gp->GetNumPoints(poly) - 1))
+ x = (int)gp->GetX(poly, gp->GetNumPoints(poly) - 1), y = (int)gp->GetY(poly, gp->GetNumPoints(poly) - 1);
+ else
+ x = (int)gp->GetX(poly, 0), y = (int)gp->GetY(poly, 0);
+
+ path->moveTo(x, y);
+
+ for(int i=0; i<gp->GetNumPoints(poly); i++)
+ {
+ if (gp->GetOnCurve(poly, i))
+ {
+// p.drawLine(x, y, gp->GetX(poly, i), gp->GetY(poly, i));
+ x = (int)gp->GetX(poly, i), y = (int)gp->GetY(poly, i);
+ path->lineTo(x, y);
+ }
+ else
+ {
+ uint32 prev = gp->GetPrev(poly, i), next = gp->GetNext(poly, i);
+ float px = gp->GetX(poly, prev), py = gp->GetY(poly, prev),
+ nx = gp->GetX(poly, next), ny = gp->GetY(poly, next);
+
+ if (!gp->GetOnCurve(poly, prev))
+ px = (px + gp->GetX(poly, i)) / 2.0f,
+ py = (py + gp->GetY(poly, i)) / 2.0f;
+
+ if (!gp->GetOnCurve(poly, next))
+ nx = (nx + gp->GetX(poly, i)) / 2.0f,
+ ny = (ny + gp->GetY(poly, i)) / 2.0f;
+
+// Bezier(p, point(px, py), point(gp->GetX(poly, i), gp->GetY(poly, i)), point(nx, ny));
+// path->moveTo(px, py);
+ path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), nx, ny);
+ x = (int)nx, y = (int)ny;
+
+ if (gp->GetOnCurve(poly, next))
+ i++; // Following point is on curve, so move past it
+ }
+ }
+
+ path->closeSubpath();
+ }
+ }
+
+
+#if 0
+ // Draw curve formed by points
+
+ for(int poly=0; poly<pts.GetNumPolys(); poly++)
+ {
+ if (pts.GetNumPoints(poly) > 2)
+ {
+ // Initial move...
+ // If it's not on curve, then move to it, otherwise move to last point...
+
+ int x, y;
+
+ if (pts.GetOnCurve(poly, pts.GetNumPoints(poly) - 1))
+ x = (int)pts.GetX(poly, pts.GetNumPoints(poly) - 1), y = (int)pts.GetY(poly, pts.GetNumPoints(poly) - 1);
+ else
+ x = (int)pts.GetX(poly, 0), y = (int)pts.GetY(poly, 0);
+
+ for(int i=0; i<pts.GetNumPoints(poly); i++)
+ {
+ if (pts.GetOnCurve(poly, i))
+// LineTo(hdc, pts.GetX(poly, i), pts.GetY(poly, i));
+ {
+ p.drawLine(x, y, pts.GetX(poly, i), pts.GetY(poly, i));
+ x = (int)pts.GetX(poly, i), y = (int)pts.GetY(poly, i);
+ }
+ else
+ {
+ uint32 prev = pts.GetPrev(poly, i), next = pts.GetNext(poly, i);
+ float px = pts.GetX(poly, prev), py = pts.GetY(poly, prev),
+ nx = pts.GetX(poly, next), ny = pts.GetY(poly, next);
+
+ if (!pts.GetOnCurve(poly, prev))
+ px = (px + pts.GetX(poly, i)) / 2.0f,
+ py = (py + pts.GetY(poly, i)) / 2.0f;
+
+ if (!pts.GetOnCurve(poly, next))
+ nx = (nx + pts.GetX(poly, i)) / 2.0f,
+ ny = (ny + pts.GetY(poly, i)) / 2.0f;
+
+ Bezier(p, point(px, py), point(pts.GetX(poly, i), pts.GetY(poly, i)), point(nx, ny));
+ x = (int)nx, y = (int)ny;
+
+ if (pts.GetOnCurve(poly, next))
+ i++; // Following point is on curve, so move past it
+ }
+ }
+ }
+ }
+#endif
+}
+
+QSize CharWindow::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+
+QSize CharWindow::sizeHint() const
+{
+ return QSize(200, 200);
+}
+
+void CharWindow::paintEvent(QPaintEvent * /*event*/)
+{
+ if (path == NULL)
+ return;
+
+ QPainter p(this);
+
+// Need to translate as well...
+// p.scale(1.0, -1.0);
+ p.drawPath(*path);
+}
+#if 0
BEGIN_EVENT_TABLE(CharWindow, wxMiniFrame)
EVT_PAINT(CharWindow::OnPaint)
// EVT_MOUSE_EVENTS(CharWindow::OnMouseEvent)
// memDC.SelectObject(wxNullBitmap);
}
+#endif