Sat, 27 Apr 2013 16:22:35 +0300
Base work regarding constrained cameras
gldraw.cpp | file | annotate | diff | comparison | revisions | |
gldraw.h | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui.h | file | annotate | diff | comparison | revisions | |
gui_actions.cpp | file | annotate | diff | comparison | revisions |
--- a/gldraw.cpp Sat Apr 27 02:52:32 2013 +0300 +++ b/gldraw.cpp Sat Apr 27 16:22:35 2013 +0300 @@ -253,11 +253,31 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::paintGL () { + if (g_CurrentFile == null) + return; + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode (GL_PROJECTION); + + glPushMatrix (); + glLoadIdentity (); + + double x = zoom; + double y = (height * x) / width; + + glOrtho (-x, x, -y, y, -100.0, 100.0); + + glTranslatef (panX, panY, -5.0f); + glRotatef (90.f, 0.0f, 1.0f, 0.0f); + + for (LDObject* obj : g_CurrentFile->objects) + glCallList ((picking == false) ? obj->uGLList : obj->uGLPickList); + glPopMatrix (); glMatrixMode (GL_MODELVIEW); - if (g_CurrentFile == null) - return; +#if 0 + glMatrixMode (GL_MODELVIEW); glPushMatrix (); glLoadIdentity (); @@ -272,6 +292,7 @@ for (LDObject* obj : g_CurrentFile->objects) glCallList ((picking == false) ? obj->uGLList : obj->uGLPickList); glPopMatrix (); +#endif // If we're range-picking, draw a rectangle encompassing the selection area. if (rangepick && !picking) { @@ -513,6 +534,9 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::mouseMoveEvent (QMouseEvent* ev) { + mouseX = pos.x (); + mouseY = pos.y (); + int dx = ev->x () - pos.x (); int dy = ev->y () - pos.y (); totalmove += abs (dx) + abs (dy); @@ -526,8 +550,8 @@ } if (ev->buttons () & Qt::MidButton) { - panX += 0.03f * dx; - panY -= 0.03f * dy; + panX += 0.03f * dx * (zoom / 7.5f); + panY -= 0.03f * dy * (zoom / 7.5f); } pos = ev->pos (); @@ -547,7 +571,10 @@ // ============================================================================= void GLRenderer::wheelEvent (QWheelEvent* ev) { - zoom += (-ev->delta () / 100.0); + printf ("%.5f -> ", zoom); + // zoom += (-ev->delta () / 100.0); + zoom *= (ev->delta () < 0) ? 1.2f : (1.0f / 1.2f); + printf ("%.5f\n", zoom); zoom = clamp (zoom, 0.01, 100.0); ev->accept (); updateGL ();
--- a/gldraw.h Sat Apr 27 02:52:32 2013 +0300 +++ b/gldraw.h Sat Apr 27 16:22:35 2013 +0300 @@ -56,6 +56,7 @@ bool addpick; short width, height; QPoint rangeStart; + ushort mouseX, mouseY; protected: void initializeGL ();
--- a/gui.cpp Sat Apr 27 02:52:32 2013 +0300 +++ b/gui.cpp Sat Apr 27 16:22:35 2013 +0300 @@ -21,6 +21,7 @@ #include <qevent.h> #include <qmenubar.h> #include <qstatusbar.h> +#include <qsplitter.h> #include "common.h" #include "gldraw.h" #include "gui.h" @@ -111,7 +112,6 @@ qObjList = new QTreeWidget; qObjList->setHeaderHidden (true); - qObjList->setMaximumWidth (256); qObjList->setSelectionMode (QTreeWidget::ExtendedSelection); qObjList->setAlternatingRowColors (true); connect (qObjList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selectionChanged ())); @@ -120,15 +120,15 @@ qMessageLog->setReadOnly (true); qMessageLog->setMaximumHeight (96); - QWidget* w = new QWidget; - QGridLayout* layout = new QGridLayout; - layout->setColumnMinimumWidth (0, 192); - layout->setColumnStretch (0, 1); - layout->addWidget (R, 0, 0); - layout->addWidget (qObjList, 0, 1); - layout->addWidget (qMessageLog, 1, 0, 1, 2); - w->setLayout (layout); - setCentralWidget (w); + hsplit = new QSplitter; + hsplit->addWidget (R); + hsplit->addWidget (qObjList); + + vsplit = new QSplitter (Qt::Vertical); + vsplit->addWidget (hsplit); + vsplit->addWidget (qMessageLog); + + setCentralWidget (vsplit); quickColorMeta = parseQuickColorMeta (); @@ -136,10 +136,9 @@ createMenus (); createToolbars (); - setStatusBar (new QStatusBar); - slot_selectionChanged (); + setStatusBar (new QStatusBar); setWindowIcon (QIcon ("icons/ldforge.png")); setTitle (); setMinimumSize (320, 200); @@ -376,6 +375,7 @@ g_CurrentToolBar->addAction (ACTION (gridCoarse)); g_CurrentToolBar->addAction (ACTION (gridMedium)); g_CurrentToolBar->addAction (ACTION (gridFine)); + addToolBarBreak (Qt::TopToolBarArea); // ========================================== // Color toolbar @@ -384,7 +384,7 @@ // ========================================== // Left area toolbars - g_ToolBarArea = Qt::LeftToolBarArea; + //g_ToolBarArea = Qt::LeftToolBarArea; initSingleToolBar ("Objects"); g_CurrentToolBar->addAction (ACTION (setColor)); g_CurrentToolBar->addAction (ACTION (invert));
--- a/gui.h Sat Apr 27 02:52:32 2013 +0300 +++ b/gui.h Sat Apr 27 16:22:35 2013 +0300 @@ -30,6 +30,10 @@ #include "gldraw.h" #include "config.h" +class ForgeWindow; +class color; +class QSplitter; + // Stuff for dialogs #define IMPLEMENT_DIALOG_BUTTONS \ bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \ @@ -67,7 +71,7 @@ #define SHIFT(N) (Qt::SHIFT | Qt::Key_##N) #define CTRL_SHIFT(N) (Qt::CTRL | Qt::SHIFT | Qt::Key_##N) -class color; +// ============================================================================= typedef struct { color* col; QPushButton* btn; @@ -111,6 +115,7 @@ *qHelpMenu, *qControlMenu; QMenu* qRecentFilesMenu; std::vector<QAction*> qaRecentFiles; + QSplitter* hsplit, *vsplit; #ifndef RELEASE QMenu* qDebugMenu;
--- a/gui_actions.cpp Sat Apr 27 02:52:32 2013 +0300 +++ b/gui_actions.cpp Sat Apr 27 16:22:35 2013 +0300 @@ -342,7 +342,14 @@ // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. QImage img = QImage (imagedata, w, h, QImage::Format_ARGB32).rgbSwapped ().mirrored (); - str fname = QFileDialog::getSaveFileName (); + str root = basename (g_CurrentFile->zFileName.chars ()); + if (root.substr (~root - 4, -1) == ".dat") + root -= 4; + + str defaultname = format ("%s.png", root.chars ()); + str fname = QFileDialog::getSaveFileName (g_ForgeWindow, "Save Screencap", defaultname, + "PNG images (*.png);;JPG images (*.jpg);;BMP images (*.bmp);;All Files (*.*)"); + if (~fname > 0 && !img.save (fname)) critical (format ("Couldn't open %s for writing to save screencap: %s", fname.chars(), strerror (errno)));