# HG changeset patch # User Santeri Piippo # Date 1398821132 -10800 # Node ID 038985b4a154136c4f20fa2bbe6fe5f68f2f83bd # Parent bb897dfef387ad16af262a975da8aa0046958c2f - added a selection hover effect to the renderer. selecting objects just became a lot more convenient... diff -r bb897dfef387 -r 038985b4a154 src/glCompiler.cc --- a/src/glCompiler.cc Wed Apr 30 03:41:23 2014 +0300 +++ b/src/glCompiler.cc Wed Apr 30 04:25:32 2014 +0300 @@ -79,7 +79,8 @@ // ============================================================================= // -GLCompiler::GLCompiler() +GLCompiler::GLCompiler (GLRenderer* renderer) : + m_renderer (renderer) { needMerge(); memset (m_vboSizes, 0, sizeof m_vboSizes); @@ -194,13 +195,20 @@ return qcol; } + double blendAlpha = 0.0; + if (topobj->isSelected()) + blendAlpha = 1.0; + elif (topobj == m_renderer->objectAtCursor()) + blendAlpha = 0.5; + + if (blendAlpha != 0.0) { - // Brighten it up for the select list. QColor selcolor (cfg::selectColorBlend); - qcol.setRed ((qcol.red() + selcolor.red()) / 2); - qcol.setGreen ((qcol.green() + selcolor.green()) / 2); - qcol.setBlue ((qcol.blue() + selcolor.blue()) / 2); + double denom = blendAlpha + 1.0; + qcol.setRed ((qcol.red() + (selcolor.red() * blendAlpha)) / denom); + qcol.setGreen ((qcol.green() + (selcolor.green() * blendAlpha)) / denom); + qcol.setBlue ((qcol.blue() + (selcolor.blue() * blendAlpha)) / denom); } return qcol; diff -r bb897dfef387 -r 038985b4a154 src/glCompiler.h --- a/src/glCompiler.h Wed Apr 30 03:41:23 2014 +0300 +++ b/src/glCompiler.h Wed Apr 30 04:25:32 2014 +0300 @@ -33,7 +33,7 @@ bool isChanged; }; - GLCompiler(); + GLCompiler (GLRenderer* renderer); ~GLCompiler(); void compileDocument (LDDocument* doc); void dropObject (LDObject* obj); @@ -73,6 +73,7 @@ GLuint m_vbo[g_numVBOs]; bool m_vboChanged[g_numVBOs]; int m_vboSizes[g_numVBOs]; + GLRenderer* const m_renderer; }; #define checkGLError() { checkGLError_private (__FILE__, __LINE__); } diff -r bb897dfef387 -r 038985b4a154 src/glRenderer.cc --- a/src/glRenderer.cc Wed Apr 30 03:41:23 2014 +0300 +++ b/src/glRenderer.cc Wed Apr 30 04:25:32 2014 +0300 @@ -128,15 +128,15 @@ m_editMode = ESelectMode; m_rectdraw = false; m_panning = false; - m_compiler = new GLCompiler; + m_compiler = new GLCompiler (this); setDocument (null); setDrawOnly (false); setMessageLog (null); m_width = m_height = -1; m_hoverpos = g_origin; - m_compiler = new GLCompiler; m_toolTipTimer = new QTimer (this); m_toolTipTimer->setSingleShot (true); + m_objectAtCursor = 0; connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); m_thickBorderPen = QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); @@ -319,6 +319,12 @@ // void GLRenderer::setBackground() { + if (isPicking()) + { + glClearColor (0.0f, 0.0f, 0.0f, 1.0f); + return; + } + QColor col (cfg::backgroundColor); if (not col.isValid()) @@ -578,14 +584,11 @@ // ============================================================================= // -void GLRenderer::paintEvent (QPaintEvent* ev) +void GLRenderer::paintEvent (QPaintEvent*) { - Q_UNUSED (ev) - makeCurrent(); m_virtWidth = zoom(); m_virtHeight = (m_height * m_virtWidth) / m_width; - initGLData(); drawGLScene(); @@ -1158,6 +1161,9 @@ // Update rect vertices since m_hoverpos may have changed updateRectVerts(); + // + highlightCursorObject(); + update(); } @@ -1233,11 +1239,8 @@ compileObject (obj); } + // Paint the picking scene setPicking (true); - - // Paint the picking scene - glDisable (GL_DITHER); - glClearColor (0.0f, 0.0f, 0.0f, 1.0f); drawGLScene(); int x0 = mouseX, @@ -1336,9 +1339,6 @@ setPicking (false); m_rangepick = false; - glEnable (GL_DITHER); - - setBackground(); repaint(); } @@ -1408,6 +1408,19 @@ // ============================================================================= // +void GLRenderer::setPicking (const bool& a) +{ + m_isPicking = a; + setBackground(); + + if (a) + glDisable (GL_DITHER); + else + glEnable (GL_DITHER); +} + +// ============================================================================= +// Matrix GLRenderer::getCircleDrawMatrix (double scale) { Matrix transform = g_circleDrawMatrixTemplates[camera() % 3]; @@ -2128,3 +2141,35 @@ if (g_win->R() == this) g_win->refresh(); } + +// ============================================================================= +// +void GLRenderer::highlightCursorObject() +{ + setPicking (true); + drawGLScene(); + setPicking (false); + + unsigned char pixel[4]; + glReadPixels (m_pos.x(), m_height - m_pos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]); + LDObject* newObject = null; + LDObject* oldObject = objectAtCursor(); + qint32 newIndex = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2]; + + if (newIndex != (oldObject != null ? oldObject->id() : 0)) + { + if (newIndex != 0) + newObject = LDObject::fromID (newIndex); + + if (oldObject != null) + compileObject (oldObject); + + setObjectAtCursor (newObject); + + if (newObject != null) + compileObject (newObject); + } + + update(); +} + diff -r bb897dfef387 -r 038985b4a154 src/glRenderer.h --- a/src/glRenderer.h Wed Apr 30 03:41:23 2014 +0300 +++ b/src/glRenderer.h Wed Apr 30 04:25:32 2014 +0300 @@ -143,12 +143,13 @@ }; Q_OBJECT - PROPERTY (public, bool, isDrawOnly, setDrawOnly, STOCK_WRITE) - PROPERTY (public, MessageManager*, messageLog, setMessageLog, STOCK_WRITE) - PROPERTY (private, bool, isPicking, setPicking, STOCK_WRITE) - PROPERTY (public, LDDocument*, document, setDocument, CUSTOM_WRITE) - PROPERTY (public, EditMode, editMode, setEditMode, CUSTOM_WRITE) - PROPERTY (private, GLCompiler*, compiler, setCompiler, STOCK_WRITE) + PROPERTY (public, bool, isDrawOnly, setDrawOnly, STOCK_WRITE) + PROPERTY (public, MessageManager*, messageLog, setMessageLog, STOCK_WRITE) + PROPERTY (private, bool, isPicking, setPicking, CUSTOM_WRITE) + PROPERTY (public, LDDocument*, document, setDocument, CUSTOM_WRITE) + PROPERTY (public, EditMode, editMode, setEditMode, CUSTOM_WRITE) + PROPERTY (private, GLCompiler*, compiler, setCompiler, STOCK_WRITE) + PROPERTY (private, LDObject*, objectAtCursor, setObjectAtCursor, STOCK_WRITE) public: GLRenderer (QWidget* parent = null); @@ -184,6 +185,7 @@ void zoomNotch (bool inward); static QColor getMainColor(); + void highlightCursorObject(); protected: void contextMenuEvent (QContextMenuEvent* ev);