X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcharwindow.cpp;h=06b273dc79dee5aec307d0288a709d6820007807;hb=HEAD;hp=4c601c8392e27ae21dc27fca89ba784fa5d884ce;hpb=c84263bb8b0d16e4c6da49aa0b7d0bc904ae02b1;p=ttedit diff --git a/src/charwindow.cpp b/src/charwindow.cpp old mode 100755 new mode 100644 index 4c601c8..06b273d --- a/src/charwindow.cpp +++ b/src/charwindow.cpp @@ -6,51 +6,183 @@ // JLH = James L. Hammons // // 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 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 // #include "charwindow.h" +#include "debug.h" -BEGIN_EVENT_TABLE(CharWindow, wxMiniFrame) - EVT_PAINT(CharWindow::OnPaint) -// EVT_MOUSE_EVENTS(CharWindow::OnMouseEvent) -END_EVENT_TABLE() +CharWindow::CharWindow(QWidget * parent/*= NULL*/): QWidget(parent, Qt::Window), path(NULL) +{ + setWindowTitle("Character: Unknown"); +} -CharWindow::CharWindow(wxFrame * parent, const wxString &title, const wxPoint &pos, - const wxSize &size, long style): wxMiniFrame(parent, -1, title, pos, size, style) + +QPainterPath * CharWindow::MakePathFromPoints(GlyphPoints * gp) { - Show(false); + if (gp == NULL) + return NULL; + + 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; polyGetNumPolys(); poly++) + { + if (gp->GetNumPoints(poly) < 3) + continue; + + // Initial move: If our start point is on curve, then go to it. + // Otherwise, check previous point. If it's on curve, go to it + // otherwise go the midpoint between start point and previous (since + // it's between two curve control points). + 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); + + for(int i=0; iGetNumPoints(poly); i++) + { + // If this point and then next are both on curve, we have a line... + if (gp->GetOnCurve(poly, i) && gp->GetNextOnCurve(poly, i)) + path->lineTo(gp->GetNextX(poly, i), gp->GetNextY(poly, i)); + else + { + // Skip point if it's on curve (start of curve--it's already + // been plotted so we don't need to handle it...) + if (gp->GetOnCurve(poly, i)) + continue; + + // We are now guaranteed that we are sitting on a curve control + // point (off curve). Figure the extent of the curve: If the + // following is a curve control point, then use the midpoint to + // it otherwise go to the next point since it's on curve. + 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); + } + } + + path->closeSubpath(); + } + + return path; } -CharWindow::~CharWindow() + +void CharWindow::RenderPathInImage(QPainterPath * path, QImage * img) { + if ((path == NULL) || (img == NULL)) + return; + + QPainter p(img); + + p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine)); + p.setBrush(Qt::black); + + QRectF rect = path->boundingRect(); + QSize paintSize = img->size(); + +#if 0 + // For some reason, this code cuts off two pixels when rendering the path. + // Not sure why, but we compensate for that here. + paintSize.rwidth() -= 2; + paintSize.rheight() -= 2; +#endif + + 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 (xConvFac > yConvFac) + { + // height is limiting factor (smaller than width) + p.scale(yConvFac, -yConvFac); + extraX = (((float)paintSize.width() / yConvFac) - rect.width()) / 2.0f; + } + else + { + // width is limiting factor (smaller than height) + p.scale(xConvFac, -xConvFac); + extraY = (((float)paintSize.height() / xConvFac) - rect.height()) / 2.0f; + } + + p.translate(-rect.x() + extraX, -rect.y() + extraY); + p.drawPath(*path); +} + + +QSize CharWindow::minimumSizeHint() const +{ + return QSize(50, 50); +} + + +QSize CharWindow::sizeHint() const +{ + return QSize(200, 200); } -void CharWindow::OnPaint(wxPaintEvent &e) + +void CharWindow::paintEvent(QPaintEvent * /*event*/) { - wxPaintDC dc(this); -//doesnothing dc.SetBackground(*wxWHITE_BRUSH); + if (path == NULL) + return; + + QPainter p(this); + +// p.setBrush(QColor(0, 163, 200)); // Nice, aqua color... + p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine)); + p.setBrush(Qt::black); -// wxMemoryDC memDC; -// memDC.SelectObject(*bmp); -// dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY); + QRectF rect = path->boundingRect(); + QSize paintSize = size(); -// 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); -// } + // For some reason, this code cuts off two pixels when rendering the path. + // Not sure why, but we compensate for that here. + paintSize.rwidth() -= 2; + paintSize.rheight() -= 2; -// memDC.SelectObject(wxNullBitmap); + 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 (xConvFac > yConvFac) + { + // height is limiting factor (smaller than width) + p.scale(yConvFac, -yConvFac); + extraX = (((float)paintSize.width() / yConvFac) - rect.width()) / 2.0f; + } + else + { + // width is limiting factor (smaller than height) + p.scale(xConvFac, -xConvFac); + extraY = (((float)paintSize.height() / xConvFac) - rect.height()) / 2.0f; + } + + p.translate(-rect.x() + extraX, -rect.y() + extraY); + + p.drawPath(*path); } +