X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcharwindow.cpp;h=95965d4d60f2f5810d5974c8b6e37fcdde7fd155;hb=32b6adaf700132ab0910d841b43a0ad343029ce0;hp=d9e6ee3ac2182931867b11a4464ee30a77cbe6bb;hpb=29b571499a38273c6c693334512e44f4162171a5;p=ttedit diff --git a/src/charwindow.cpp b/src/charwindow.cpp index d9e6ee3..95965d4 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,103 +48,84 @@ 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... - - 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); - + // If last point is on curve then move to it, otherwise move to first point... + +//NOTE: This is basically doing the below for i=-1. +// Find some way to integrate this crap. +/* +Could do in pairs: get i and i+1, connect them depending on whether the pair +is a line or a curve. +4 cases: on to on (line), + on to off (begin curve), + off to on (end curve), + off to off (begin curve) +*/ +#if 1 for(int i=0; iGetNumPoints(poly); i++) { - if (gp->GetOnCurve(poly, i)) + if (i == 0) + { + IPoint pt = (gp->GetOnCurve(poly, 0) + ? gp->GetPoint(poly, 0) : (gp->GetPrevOnCurve(poly, 0) + ? gp->GetPrevPoint(poly, 0) : gp->GetMidpointToPrev(poly, 0))); + path->moveTo(pt.x, pt.y); + } + + if (gp->GetOnCurve(poly, i) && gp->GetNextOnCurve(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); + // Handle lines... + path->lineTo(gp->GetNextX(poly, i), gp->GetNextY(poly, i)); } 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 + // Skip point if it's on curve (start of curve--it's already + // been plotted so we don't care about it... + if (gp->GetOnCurve(poly, i)) + i++; + + // We may have moved past the end; if not, handle curve + if (i < gp->GetNumPoints(poly)) + { + // Handle curves... + IPoint pt = (gp->GetNextOnCurve(poly, i) + ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i)); + + path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y); + } } } +#else + IPoint pt; - 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); + if (gp->GetPrevOnCurve(poly, 0)) + pt = gp->GetPrevPoint(poly, 0); else - x = (int)pts.GetX(poly, 0), y = (int)pts.GetY(poly, 0); + pt = (gp->GetOnCurve(poly, 0) + ? gp->GetPoint(poly, 0) : gp->GetMidpointToPrev(poly, 0)); + + path->moveTo(pt.x, pt.y); - for(int i=0; iGetNumPoints(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); - } + if (gp->GetOnCurve(poly, i)) + path->lineTo(gp->GetX(poly, i), gp->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; + pt = (gp->GetNextOnCurve(poly, i) + ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i)); - Bezier(p, point(px, py), point(pts.GetX(poly, i), pts.GetY(poly, i)), point(nx, ny)); - x = (int)nx, y = (int)ny; + path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y); - if (pts.GetOnCurve(poly, next)) - i++; // Following point is on curve, so move past it + // If following point is on curve, move past it + if (gp->GetNextOnCurve(poly, i)) + i++; } } +#endif + + path->closeSubpath(); } } -#endif } QSize CharWindow::minimumSizeHint() const @@ -176,44 +145,51 @@ void CharWindow::paintEvent(QPaintEvent * /*event*/) QPainter p(this); + p.setBrush(QColor(122, 163, 39)); // Need to translate as well... -// p.scale(1.0, -1.0); - p.drawPath(*path); -} +// p.scale(2.0, 2.0); +/* +1.0 -> 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 (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(xConvFac, -xConvFac); +//extraY = (rect.width() / (float)paintSize.width()) * (float)paintSize.height(); +//extraY = (extraY - rect.height()) / 2.0f; + extraY = (((float)paintSize.height() / xConvFac) - rect.height()) / 2.0f; + } -// memDC.SelectObject(wxNullBitmap); + p.translate(-rect.x() + extraX, -rect.y() + extraY); + + p.drawPath(*path); } -#endif