-//\r
-// TTEDIT.CPP - The TrueType Editor\r
-// by James L. Hammons\r
-// (C) 2004 Underground Software\r
-//\r
-// JLH = James L. Hammons <jlhamm@acm.org>\r
-//\r
-// Who When What\r
-// --- ---------- -------------------------------------------------------------\r
-// JLH 08/28/2008 Created this file\r
-//\r
-\r
-// FIXED:\r
-//\r
-// STILL TO BE DONE:\r
-//\r
-// - Fix problem with owned window causing main window refresh problems\r
-// (ironically enough, it doesn't seem to be a problem anymore...)\r
-//\r
-\r
-#include "charwindow.h"\r
-\r
-\r
-BEGIN_EVENT_TABLE(CharWindow, wxMiniFrame)\r
- EVT_PAINT(CharWindow::OnPaint)\r
-// EVT_MOUSE_EVENTS(CharWindow::OnMouseEvent)\r
-END_EVENT_TABLE()\r
-\r
-CharWindow::CharWindow(wxFrame * parent, const wxString &title, const wxPoint &pos,\r
- const wxSize &size, long style): wxMiniFrame(parent, -1, title, pos, size, style)\r
-{\r
- Show(false);\r
-}\r
-\r
-CharWindow::~CharWindow()\r
-{\r
-}\r
-\r
-void CharWindow::OnPaint(wxPaintEvent &e)\r
-{\r
- wxPaintDC dc(this);\r
-//doesnothing dc.SetBackground(*wxWHITE_BRUSH);\r
-\r
-// wxMemoryDC memDC;\r
-// memDC.SelectObject(*bmp);\r
-// dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY);\r
-\r
-// if (prevTool != -1)\r
-// {\r
-// //need ul corner of bitmap, ul corner of dest, width/height\r
-// wxPoint pt(sizeStamp.x * (prevTool & 0x03), sizeStamp.y * (prevTool >> 2));\r
-// dc.Blit(pt.x, pt.y, sizeStamp.x, sizeStamp.y, &memDC, pt.x, pt.y, wxSRC_INVERT);\r
-// }\r
-\r
-// memDC.SelectObject(wxNullBitmap);\r
-}\r
+//
+// TTEDIT.CPP - The TrueType Editor
+// by James L. Hammons
+// (C) 2004 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who When What
+// --- ---------- -------------------------------------------------------------
+// JLH 08/28/2008 Created this file
+// JLH 03/19/2009 Converted from wxWidgets to Qt
+// JLH 03/21/2009 Fixed main screen points rendering
+//
+
+// FIXED:
+//
+// - Render of main window points [DONE]
+//
+// STILL TO BE DONE:
+//
+// - Fix "window disappears when tool win comes up" problem
+//
+
+#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();
+// path->setFillRule(Qt::OddEvenFill);
+ path->setFillRule(Qt::WindingFill);
+
+ // Draw curve formed by points
+
+ for(int poly=0; poly<gp->GetNumPolys(); poly++)
+ {
+ if (gp->GetNumPoints(poly) > 2)
+ {
+ // Initial move...
+ // If last point is on curve then move to it, otherwise move to first point...
+
+ int x, y;
+
+ if (gp->GetOnCurve(poly, gp->GetPrev(poly, 0)))
+ x = gp->GetX(poly, gp->GetPrev(poly, 0)),
+ y = gp->GetY(poly, gp->GetPrev(poly, 0));
+ else
+ {
+ x = (int)gp->GetX(poly, 0), y = (int)gp->GetY(poly, 0);
+
+ if (!gp->GetOnCurve(poly, 0))
+ {
+ IPoint pt = gp->GetMidpointToPrev(poly, 0);
+ x = pt.x, y = pt.y;
+ }
+ }
+
+ 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
+ {
+ IPoint pt = (gp->GetOnCurve(poly, gp->GetNext(poly, i)) ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i));
+
+ path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y);
+ x = pt.x, y = pt.y;
+
+ // If following point is on curve, move past it
+ if (gp->GetOnCurve(poly, gp->GetNext(poly, i)))
+ i++;
+ }
+ }
+
+ path->closeSubpath();
+ }
+ }
+}
+
+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);
+
+ p.setBrush(QColor(122, 163, 39));
+// Need to translate as well...
+// p.scale(2.0, 2.0);
+
+/*
+1.0 -> 3.0, height = 400
+r.h / ps.h = 2/400 <-- do it the other way!
+
+height works, width does not
+
+2-step process:
+compare aspect ratios
+
+ps.w - ((r.h / ps.h) * ps.w)
+
+0.5 -> where in the 400? -> 100
+0.5/r.h(2.0) = 0.25 * ps.h(400) = 100
+conv.fac. -> (ps.h / r.h)
+*/
+ QRectF rect = path->boundingRect();
+ QSize paintSize = size();
+
+ p.translate(0, paintSize.height());
+float extraX = 0.0f, extraY = 0.0f;
+float xConvFac = (float)paintSize.width() / rect.width();
+float yConvFac = (float)paintSize.height() / rect.height();
+
+// if (((float)paintSize.width() / rect.width()) > ((float)paintSize.height() / rect.height()))
+ if (xConvFac > yConvFac)
+ {
+ // height is limiting factor
+ p.scale(yConvFac, -yConvFac);
+//extraX = (rect.height() / (float)paintSize.height()) * (float)paintSize.width();
+//extraX = (extraX - rect.width()) / 2.0f;
+ extraX = (((float)paintSize.width() / yConvFac) - rect.width()) / 2.0f;
+ }
+ else
+ {
+ // width is limiting factor
+// p.scale((float)paintSize.width() / rect.width(), -(float)paintSize.width() / rect.height());
+ p.scale((float)paintSize.width() / rect.width(), -(float)paintSize.width() / rect.width());
+extraY = (rect.width() / (float)paintSize.width()) * (float)paintSize.height();// / 2.0f;
+extraY = extraY - rect.height();
+extraY /= 2.0f;
+ }
+
+ p.translate(-rect.x() + extraX, -rect.y() + extraY);
+
+ p.drawPath(*path);
+}