]> Shamusworld >> Repos - ttedit/commitdiff
Fix zoom to zoom in/out from the center.
authorShamus Hammons <jlhamm@acm.org>
Fri, 4 Mar 2016 23:17:28 +0000 (17:17 -0600)
committerShamus Hammons <jlhamm@acm.org>
Fri, 4 Mar 2016 23:17:28 +0000 (17:17 -0600)
Also, fixed saving to save without dialog box for loaded/previously saved
files.

22 files changed:
res/ttedit.xpm [changed mode: 0755->0644]
src/charnames.cpp [changed mode: 0755->0644]
src/charnames.h [changed mode: 0755->0644]
src/charwindow.cpp [changed mode: 0755->0644]
src/charwindow.h [changed mode: 0755->0644]
src/debug.cpp [changed mode: 0755->0644]
src/debug.h [changed mode: 0755->0644]
src/editwindow.cpp [changed mode: 0755->0644]
src/editwindow.h [changed mode: 0755->0644]
src/glyphpoints.cpp [changed mode: 0755->0644]
src/glyphpoints.h [changed mode: 0755->0644]
src/list.h [changed mode: 0755->0644]
src/mainwindow.cpp
src/mainwindow.h
src/toolwindow.cpp [changed mode: 0755->0644]
src/toolwindow.h [changed mode: 0755->0644]
src/ttedit.cpp [changed mode: 0755->0644]
src/ttedit.h [changed mode: 0755->0644]
src/ttf.cpp [changed mode: 0755->0644]
src/ttf.h [changed mode: 0755->0644]
src/vector.cpp [changed mode: 0755->0644]
src/vector.h [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 93757ce..4a3d43f
 
 
 EditWindow::EditWindow(QWidget * parent/*= NULL*/): QWidget(parent),
-       scale(1.0), offsetX(-10), offsetY(-10), tool(TOOLSelect),
-       ptHighlight(-1), oldPtHighlight(-1), ptNextHighlight(-1), oldPtNextHighlight(-1),
-       polyFirstPoint(true), showRotationCenter(false), haveZeroPoint(false),
-       selectionInProgress(false)
+       tool(TOOLSelect), ptHighlight(-1), oldPtHighlight(-1), ptNextHighlight(-1),
+       oldPtNextHighlight(-1), polyFirstPoint(true), showRotationCenter(false),
+       haveZeroPoint(false), selectionInProgress(false)
 {
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -81,29 +80,11 @@ void EditWindow::CreateCursors(void)
 
        for(int i=0; i<12; i++)
        {
-               QString s;
-               s.sprintf(":/res/cursor-%s.png", cursorName[i]);
-               QPixmap pmTmp(s);
+               QPixmap pmTmp(QString(":/res/cursor-%1.png").arg(cursorName[i]));
                cur[i] = QCursor(pmTmp, hotx[i], hoty[i]);
        }
 }
 
-#if 0
-QPoint EditWindow::GetAdjustedMousePosition(QMouseEvent * event)
-{
-       // This is undoing the transform, e.g. going from client coords to local
-       // coords. In essence, the height - y is height + (y * -1), the (y * -1)
-       // term doing the conversion of the y-axis from increasing bottom to top.
-       return QPoint(offsetX + event->x(), offsetY + (size().height() - event->y()));
-}
-
-
-QPoint EditWindow::GetAdjustedClientPosition(int x, int y)
-{
-       // VOODOO ALERT (ON Y COMPONENT!!!!)
-       return QPoint(-offsetX + x, (size().height() - (-offsetY + y)) * +1.0);
-}
-#endif
 
 /*
 TODO:
@@ -118,27 +99,12 @@ void EditWindow::paintEvent(QPaintEvent * /*event*/)
        Painter painter(&qtp);
        painter.SetRenderHint(QPainter::Antialiasing);
 
-       Global::zoom = scale;
-       Global::origin = Vector(offsetX, offsetY);
        Global::viewportHeight = size().height();
        Global::screenSize = Vector(size().width(), size().height());
-//     p.translate(QPoint(-offsetX, size().height() - (-offsetY)));
-//     p.scale(1.0, -1.0);
-//Nope, a big load of shit. So we'll have to bite the bullet and do it the
-//hard way™.
-//     p.scale(scale, -scale);
-
-// Scrolling can be done by using OffsetViewportOrgEx
-// Scaling can be done by adjusting SetWindowExtEx (it's denominator of txform)
-// you'd use: % = ViewportExt / WindowExt
-// But it makes the window look like crap: fuggetuboutit.
-// Instead, we have to scale EVERYTHING by hand. Crap!
-// It's not *that* bad, but not as convenient either...
-
-       painter.SetPen(QPen(Qt::blue, 1.0, Qt::DotLine));
 
        // Draw coordinate axes
 
+       painter.SetPen(QPen(Qt::blue, 1.0, Qt::DotLine));
        painter.DrawLine(0, -16384, 0, 16384);
        painter.DrawLine(-16384, 0, 16384, 0);
 
@@ -433,7 +399,7 @@ WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumP
                        {
 //                             pt = GetAdjustedClientPosition(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
                                Vector pt = Painter::CartesianToQtCoords(Vector(pts.GetX(ptHighlight), pts.GetY(ptHighlight)));
-//printf("GetAdjustedClientPosition = %i, %i\n", pt.x(), pt.y());
+//printf("GetAdjustedClientPosition = %lf, %lf\n", pt.x, pt.y);
                                QPoint warp(pt.x, pt.y);
                                QCursor::setPos(mapToGlobal(warp));
 
@@ -459,9 +425,9 @@ WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumP
                else if (tool == TOOLRotate)
                {
                        // I think what's needed here is to keep the initial mouse click,
-                       // paint the rotation center, then use the 1st mouse move event to establish
-                       // the rotation "zero line", which becomes the line of reference to all
-                       // subsequent mouse moves.
+                       // paint the rotation center, then use the 1st mouse move event to
+                       // establish the rotation "zero line", which becomes the line of
+                       // reference to all subsequent mouse moves.
 //                     rotationCenter = GetAdjustedMousePosition(event);
                        rotationCenter = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
                        showRotationCenter = true;
@@ -513,14 +479,15 @@ void EditWindow::mouseMoveEvent(QMouseEvent * event)
                // Calc offset from previous point
                Vector pt(event->x(), event->y());
                pt /= Global::zoom;
-               ptOffset = Vector(pt.x - ptPrevious.x, pt.y - ptPrevious.y);
+               ptOffset = Vector(pt.x - ptPrevious.x, -(pt.y - ptPrevious.y));
 
 // Then multiply it by the scaling factor. Whee!
                // This looks wacky because we're using screen coords for the offset...
                // Otherwise, we would subtract both offsets!
-               offsetX -= ptOffset.x, offsetY += ptOffset.y;
-               update();
+//             offsetX -= ptOffset.x, offsetY += ptOffset.y;
+               Global::origin -= ptOffset;
                ptPrevious = pt;
+               update();
        }
        else if (event->buttons() == Qt::LeftButton)
        {
old mode 100755 (executable)
new mode 100644 (file)
index 983a96c..f1518e9
@@ -41,8 +41,6 @@ class EditWindow: public QWidget
        public:
                QImage image;
                Vector pt, ptOffset, ptPrevious;
-               double scale;                                           // Window scaling factor
-               int32_t offsetX, offsetY;                       // Window offsets
                ToolType tool;                                          // Current tool
                GlyphPoints pts;                                        // Glyph point structure
                int32_t ptHighlight, oldPtHighlight, ptNextHighlight, oldPtNextHighlight;
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index ef738e95102f56ae4ec784ecc84b86949b297f2d..2c9b45d1024d27a29540d537771b802ca6afa945 100644 (file)
@@ -38,6 +38,7 @@
 #include "mainwindow.h"
 #include "charwindow.h"
 #include "editwindow.h"
+#include "global.h"
 #include "ttedit.h"
 
 
@@ -163,7 +164,7 @@ void MainWindow::CreateActions(void)
        saveFileAct = CreateAction("&Save File", "Save File", "Save a glyph file", QIcon(), QKeySequence("ctrl+s"));
        quitAct = CreateAction("&Quit", "Quit", "Exits from the TTEdit application", QIcon(), QKeySequence("ctrl+q"));
        zoomInAct = CreateAction("Zoom In", "Zoom In", "Zoom into the canvas", QIcon(), QKeySequence("+"), QKeySequence("="));
-       zoomOutAct = CreateAction("Zoom Out", "Zoom Out", "Zoom out of canvas", QIcon(), QKeySequence("-"));
+       zoomOutAct = CreateAction("Zoom Out", "Zoom Out", "Zoom out of the canvas", QIcon(), QKeySequence("-"));
 
        connect(newGlyphAct, SIGNAL(triggered()), this, SLOT(NewGlyph()));
        connect(openFileAct, SIGNAL(triggered()), this, SLOT(OpenFile()));
@@ -207,6 +208,7 @@ void MainWindow::NewGlyph(void)
        editWnd->pts.Clear();
        ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&(editWnd->pts));
        ((TTEdit *)qApp)->charWnd->update();
+       filename.clear();
 //     editWnd->polyFirstPoint = true;
        editWnd->update();
        setWindowTitle("TTEdit! - Untitled");
@@ -216,7 +218,7 @@ void MainWindow::NewGlyph(void)
 
 void MainWindow::OpenFile(void)
 {
-       QString filename = QFileDialog::getOpenFileName(this, tr("Open Glyph File"),
+       filename = QFileDialog::getOpenFileName(this, tr("Open Glyph File"),
                "./", tr("Glyph files (*.glyph)"));
        FILE * file = fopen(filename.toUtf8().data(), "r");
 
@@ -237,8 +239,10 @@ void MainWindow::OpenFile(void)
 
 void MainWindow::SaveFile(void)
 {
-       QString filename = QFileDialog::getSaveFileName(this, tr("Save Glyph File"),
+       if (filename.isEmpty())
+               filename = QFileDialog::getSaveFileName(this, tr("Save Glyph File"),
                "./", tr("Glyph files (*.glyph)"));
+
        FILE * file = fopen(filename.toUtf8().data(), "w");
 
        //need to pop an error box here...
@@ -248,28 +252,41 @@ void MainWindow::SaveFile(void)
        editWnd->pts.SaveGlyphToFile(file);
        fclose(file);
        setWindowTitle(QString("TTEdit! - %1").arg(filename));
+       statusBar()->showMessage(tr("File saved."));
        editWnd->setFocus();
 }
 
 
 void MainWindow::ZoomIn(void)
 {
-       if (editWnd->scale == 4.0)
+       if (Global::zoom == 4.0)
                return;
 
-       editWnd->scale *= 2.0;
-       scaleIndicator->setText(QString("Scale: %1%").arg(editWnd->scale * 100.0));
+       // Adjust the origin by the width/height by 1/4 (half of the scaled size).
+       // Also, need to adjust for the current zoom level...
+       Vector adjustment = (Global::screenSize / Global::zoom) * 0.25;
+       Global::origin += adjustment;
+
+       Global::zoom *= 2.0;
+
+       scaleIndicator->setText(QString("Scale: %1%").arg(Global::zoom * 100.0));
        editWnd->update();
 }
 
 
 void MainWindow::ZoomOut(void)
 {
-       if (editWnd->scale == 0.25)
+       if (Global::zoom == 0.25)
                return;
 
-       editWnd->scale *= 0.5;
-       scaleIndicator->setText(QString("Scale: %1%").arg(editWnd->scale * 100.0));
+       Global::zoom *= 0.5;
+
+       // Adjust the origin by the width/height by 1/4 (half of the scaled size).
+       // Also, need to adjust for the current zoom level...
+       Vector adjustment = (Global::screenSize / Global::zoom) * 0.25;
+       Global::origin -= adjustment;
+
+       scaleIndicator->setText(QString("Scale: %1%").arg(Global::zoom * 100.0));
        editWnd->update();
 }
 
index bc547de6a3f395b0a22856b3d6612095c946c523..66dfe0ddb330e4ee3bd2650e02d18d5ba8796ee3 100644 (file)
@@ -77,7 +77,7 @@ class MainWindow: public QMainWindow
                QAction * zoomInAct;
                QAction * zoomOutAct;
                QAction * scaleAct;
-//             QString filename;
+               QString filename;
 };
 
 #endif // __MAINWINDOW_H__
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)