2 // TTEDIT.CPP - The TrueType Editor
4 // (C) 2004 Underground Software
6 // JLH = James L. Hammons <jlhamm@acm.org>
9 // --- ---------- -------------------------------------------------------------
10 // JLH 08/28/2008 Created this file
11 // JLH 03/19/2009 Converted from wxWidgets to Qt
18 // - Fix "window disappears when tool win comes up" problem
19 // - Render of main window points
22 #include "charwindow.h"
25 CharWindow::CharWindow(QWidget * parent/*= NULL*/): QWidget(parent, Qt::Tool), path(NULL)
27 setWindowTitle("Character: Unknown");
30 void CharWindow::MakePathFromPoints(GlyphPoints * gp)
38 path = new QPainterPath();
43 path->moveTo(gp->GetX(0), gp->GetY(0));
47 if (e == GP_OUT_OF_RANGE)
48 WriteLogMsg("CharWindow: Caught GP_OUT_OF_RANGE exception.\n");
51 for(int i=1; i<gp->GetNumPoints(); i++)
56 // Draw curve formed by points
58 for(int poly=0; poly<gp->GetNumPolys(); poly++)
60 if (gp->GetNumPoints(poly) > 2)
63 // If it's not on curve, then move to it, otherwise move to last point...
67 if (gp->GetOnCurve(poly, gp->GetNumPoints(poly) - 1))
68 x = (int)gp->GetX(poly, gp->GetNumPoints(poly) - 1), y = (int)gp->GetY(poly, gp->GetNumPoints(poly) - 1);
70 x = (int)gp->GetX(poly, 0), y = (int)gp->GetY(poly, 0);
74 for(int i=0; i<gp->GetNumPoints(poly); i++)
76 if (gp->GetOnCurve(poly, i))
78 // p.drawLine(x, y, gp->GetX(poly, i), gp->GetY(poly, i));
79 x = (int)gp->GetX(poly, i), y = (int)gp->GetY(poly, i);
84 uint32 prev = gp->GetPrev(poly, i), next = gp->GetNext(poly, i);
85 float px = gp->GetX(poly, prev), py = gp->GetY(poly, prev),
86 nx = gp->GetX(poly, next), ny = gp->GetY(poly, next);
88 if (!gp->GetOnCurve(poly, prev))
89 px = (px + gp->GetX(poly, i)) / 2.0f,
90 py = (py + gp->GetY(poly, i)) / 2.0f;
92 if (!gp->GetOnCurve(poly, next))
93 nx = (nx + gp->GetX(poly, i)) / 2.0f,
94 ny = (ny + gp->GetY(poly, i)) / 2.0f;
96 // Bezier(p, point(px, py), point(gp->GetX(poly, i), gp->GetY(poly, i)), point(nx, ny));
97 // path->moveTo(px, py);
98 path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), nx, ny);
99 x = (int)nx, y = (int)ny;
101 if (gp->GetOnCurve(poly, next))
102 i++; // Following point is on curve, so move past it
106 path->closeSubpath();
112 // Draw curve formed by points
114 for(int poly=0; poly<pts.GetNumPolys(); poly++)
116 if (pts.GetNumPoints(poly) > 2)
119 // If it's not on curve, then move to it, otherwise move to last point...
123 if (pts.GetOnCurve(poly, pts.GetNumPoints(poly) - 1))
124 x = (int)pts.GetX(poly, pts.GetNumPoints(poly) - 1), y = (int)pts.GetY(poly, pts.GetNumPoints(poly) - 1);
126 x = (int)pts.GetX(poly, 0), y = (int)pts.GetY(poly, 0);
128 for(int i=0; i<pts.GetNumPoints(poly); i++)
130 if (pts.GetOnCurve(poly, i))
131 // LineTo(hdc, pts.GetX(poly, i), pts.GetY(poly, i));
133 p.drawLine(x, y, pts.GetX(poly, i), pts.GetY(poly, i));
134 x = (int)pts.GetX(poly, i), y = (int)pts.GetY(poly, i);
138 uint32 prev = pts.GetPrev(poly, i), next = pts.GetNext(poly, i);
139 float px = pts.GetX(poly, prev), py = pts.GetY(poly, prev),
140 nx = pts.GetX(poly, next), ny = pts.GetY(poly, next);
142 if (!pts.GetOnCurve(poly, prev))
143 px = (px + pts.GetX(poly, i)) / 2.0f,
144 py = (py + pts.GetY(poly, i)) / 2.0f;
146 if (!pts.GetOnCurve(poly, next))
147 nx = (nx + pts.GetX(poly, i)) / 2.0f,
148 ny = (ny + pts.GetY(poly, i)) / 2.0f;
150 Bezier(p, point(px, py), point(pts.GetX(poly, i), pts.GetY(poly, i)), point(nx, ny));
151 x = (int)nx, y = (int)ny;
153 if (pts.GetOnCurve(poly, next))
154 i++; // Following point is on curve, so move past it
162 QSize CharWindow::minimumSizeHint() const
164 return QSize(50, 50);
167 QSize CharWindow::sizeHint() const
169 return QSize(200, 200);
172 void CharWindow::paintEvent(QPaintEvent * /*event*/)
179 // Need to translate as well...
180 // p.scale(1.0, -1.0);
186 BEGIN_EVENT_TABLE(CharWindow, wxMiniFrame)
187 EVT_PAINT(CharWindow::OnPaint)
188 // EVT_MOUSE_EVENTS(CharWindow::OnMouseEvent)
191 CharWindow::CharWindow(wxFrame * parent, const wxString &title, const wxPoint &pos,
192 const wxSize &size, long style): wxMiniFrame(parent, -1, title, pos, size, style)
197 CharWindow::~CharWindow()
201 void CharWindow::OnPaint(wxPaintEvent &e)
204 //doesnothing dc.SetBackground(*wxWHITE_BRUSH);
207 // memDC.SelectObject(*bmp);
208 // dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY);
210 // if (prevTool != -1)
212 // //need ul corner of bitmap, ul corner of dest, width/height
213 // wxPoint pt(sizeStamp.x * (prevTool & 0x03), sizeStamp.y * (prevTool >> 2));
214 // dc.Blit(pt.x, pt.y, sizeStamp.x, sizeStamp.y, &memDC, pt.x, pt.y, wxSRC_INVERT);
217 // memDC.SelectObject(wxNullBitmap);