From a4763354603a2f8fbaff27a17edab7710ead6c2b Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sun, 22 Mar 2009 04:25:41 +0000 Subject: [PATCH] Fixed character window to render the main window's points properly, added some support functions to GlyphPoints structure. --- src/charwindow.cpp | 182 +++++++++++++++----------------------------- src/glyphpoints.cpp | 35 ++++++++- src/glyphpoints.h | 4 + 3 files changed, 101 insertions(+), 120 deletions(-) diff --git a/src/charwindow.cpp b/src/charwindow.cpp index d9e6ee3..a6da0f9 100755 --- a/src/charwindow.cpp +++ b/src/charwindow.cpp @@ -9,14 +9,16 @@ // --- ---------- ------------------------------------------------------------- // 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 -// - Render of main window points // #include "charwindow.h" @@ -36,22 +38,8 @@ void CharWindow::MakePathFromPoints(GlyphPoints * gp) 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; iGetNumPoints(); i++) - { - } -#endif +// path->setFillRule(Qt::OddEvenFill); + path->setFillRule(Qt::WindingFill); // Draw curve formed by points @@ -60,15 +48,24 @@ void CharWindow::MakePathFromPoints(GlyphPoints * gp) if (gp->GetNumPoints(poly) > 2) { // Initial move... - // If it's not on curve, then move to it, otherwise move to last point... + // If last point is on curve then move to it, otherwise move to first 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); + 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; iGetNumPoints(poly); i++) @@ -81,82 +78,20 @@ void CharWindow::MakePathFromPoints(GlyphPoints * gp) } 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); + IPoint pt = (gp->GetOnCurve(poly, gp->GetNext(poly, i)) ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i)); - if (!gp->GetOnCurve(poly, prev)) - px = (px + gp->GetX(poly, i)) / 2.0f, - py = (py + gp->GetY(poly, i)) / 2.0f; + path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y); + x = pt.x, y = pt.y; - 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 + // If following point is on curve, move past it + if (gp->GetOnCurve(poly, gp->GetNext(poly, i))) + i++; } } path->closeSubpath(); } } - - -#if 0 - // Draw curve formed by points - - for(int poly=0; 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 3.0, height = 400 +r.h / ps.h = 2/400 <-- do it the other way! -#if 0 -BEGIN_EVENT_TABLE(CharWindow, wxMiniFrame) - EVT_PAINT(CharWindow::OnPaint) -// EVT_MOUSE_EVENTS(CharWindow::OnMouseEvent) -END_EVENT_TABLE() +height works, width does not -CharWindow::CharWindow(wxFrame * parent, const wxString &title, const wxPoint &pos, - const wxSize &size, long style): wxMiniFrame(parent, -1, title, pos, size, style) -{ - Show(false); -} +2-step process: +compare aspect ratios -CharWindow::~CharWindow() -{ -} +ps.w - ((r.h / ps.h) * ps.w) -void CharWindow::OnPaint(wxPaintEvent &e) -{ - wxPaintDC dc(this); -//doesnothing dc.SetBackground(*wxWHITE_BRUSH); +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(); -// wxMemoryDC memDC; -// memDC.SelectObject(*bmp); -// dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY); + 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 (prevTool != -1) -// { -// //need ul corner of bitmap, ul corner of dest, width/height -// wxPoint pt(sizeStamp.x * (prevTool & 0x03), sizeStamp.y * (prevTool >> 2)); -// dc.Blit(pt.x, pt.y, sizeStamp.x, sizeStamp.y, &memDC, pt.x, pt.y, wxSRC_INVERT); -// } +// 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); -// memDC.SelectObject(wxNullBitmap); + p.drawPath(*path); } -#endif diff --git a/src/glyphpoints.cpp b/src/glyphpoints.cpp index d0402f6..d7ce0d5 100755 --- a/src/glyphpoints.cpp +++ b/src/glyphpoints.cpp @@ -230,7 +230,7 @@ void GlyphPoints::InsertPoint(uint16 pt, int xx, int yy, bool oc) totX[pt] = xx, totY[pt] = yy, totOnCurve[pt] = oc; -//A way to fix the kludge in GetPoly() would be to put a check here to see if +//A way to fix the kludge in GetPoly() would be to put a check here to see if //we're adding to the end of the structure: [DONE, below] int polyInsert = (pt == numPoints ? numPolys - 1 : GetPoly(pt)); for(int i=polyInsert; i