]> Shamusworld >> Repos - ttedit/commitdiff
Fixed character window to render the main window's points properly,
authorShamus Hammons <jlhamm@acm.org>
Sun, 22 Mar 2009 04:25:41 +0000 (04:25 +0000)
committerShamus Hammons <jlhamm@acm.org>
Sun, 22 Mar 2009 04:25:41 +0000 (04:25 +0000)
added some support functions to GlyphPoints structure.

src/charwindow.cpp
src/glyphpoints.cpp
src/glyphpoints.h

index d9e6ee3ac2182931867b11a4464ee30a77cbe6bb..a6da0f9ca83f8e2312f5028261068dd7d5895421 100755 (executable)
@@ -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; i<gp->GetNumPoints(); 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; i<gp->GetNumPoints(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<pts.GetNumPolys(); poly++)
-       {
-               if (pts.GetNumPoints(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<pts.GetNumPoints(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);
-                               }
-                               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;
-
-                                       Bezier(p, point(px, py), point(pts.GetX(poly, i), pts.GetY(poly, i)), point(nx, ny));
-                                       x = (int)nx, y = (int)ny;
-
-                                       if (pts.GetOnCurve(poly, next))
-                                               i++;                                    // Following point is on curve, so move past it
-                               }
-                       }
-               }
-       }
-#endif
 }
 
 QSize CharWindow::minimumSizeHint() const
@@ -176,44 +111,53 @@ 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 (((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
index d0402f6fe041ddc800a29b03db00a24c53d9439f..d7ce0d5b19d082d629c28aa9f8458142830402e2 100755 (executable)
@@ -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<numPolys; i++)
@@ -579,3 +579,36 @@ void GlyphPoints::AddNewPolyAtEnd(void)
        polyEnd = newPolyEnd;
 }
 
+IPoint GlyphPoints::GetMidpointToPrev(uint16 poly, uint16 pt)
+{
+       uint16 prev = GetPrev(poly, pt);
+
+       int32 x1 = GetX(poly, pt), y1 = GetY(poly, pt);
+       int32 x2 = GetX(poly, prev), y2 = GetY(poly, prev);
+
+       return IPoint((x1 + x2) / 2.0f, (y1 + y2) / 2.0f);
+}
+
+IPoint GlyphPoints::GetMidpointToNext(uint16 poly, uint16 pt)
+{
+       uint16 next = GetNext(poly, pt);
+
+       int32 x1 = GetX(poly, pt), y1 = GetY(poly, pt);
+       int32 x2 = GetX(poly, next), y2 = GetY(poly, next);
+
+       return IPoint((x1 + x2) / 2.0f, (y1 + y2) / 2.0f);
+}
+
+IPoint GlyphPoints::GetPrevPoint(uint16 poly, uint16 pt)
+{
+       uint16 prevPt = GetPrev(poly, pt);
+
+       return IPoint(GetX(poly, prevPt), GetY(poly, prevPt));
+}
+
+IPoint GlyphPoints::GetNextPoint(uint16 poly, uint16 pt)
+{
+       uint16 nextPt = GetNext(poly, pt);
+
+       return IPoint(GetX(poly, nextPt), GetY(poly, nextPt));
+}
index 2384d7cf963a05920e9e16d68269ca7fba1ad652..73195e42d4240c3f048fd9428a4bb27388f1e5a4 100755 (executable)
@@ -70,6 +70,10 @@ class GlyphPoints
                uint16 GetNext(uint16, uint16);
                uint16 GetPoly(uint16);
                void AddNewPolyAtEnd(void);
+               IPoint GetMidpointToPrev(uint16, uint16);
+               IPoint GetMidpointToNext(uint16, uint16);
+               IPoint GetPrevPoint(uint16, uint16);
+               IPoint GetNextPoint(uint16, uint16);
 
        private:
                void AllocateAndCopy(int, int, int *, int *, bool *, uint16 *);