From 1a11359c42b0d0824eedf4b09a2b5a7865f6ed0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Beno=C3=AEt=20Jacob?= Date: Tue, 25 Jul 2006 14:24:47 +0000 Subject: [PATCH] Change some things in the way OpenGL selection is done It now happens on button press, instead of happening on button release. The clicked atom is highlighted in a separate color (currently some shade of purple, tell me what you think) even if it is not selected. The point of that is that this clicked atom is going to play a very important role in the mouse navigation system I plan to write. Any rotation/move will be done with respect to it. So I thought that this special role of this atom should correspond to a visual highlighting. M kalzium/src/kalziumglwidget.h M kalzium/src/kalziumglwidget.cpp svn path=/trunk/KDE/kdeedu/kalzium/src/kalziumglwidget.h; revision=566143 --- kalzium/kalziumglwidget.cpp | 71 +++++++++++++++++++++++-------------- kalzium/kalziumglwidget.h | 9 ++--- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/kalzium/kalziumglwidget.cpp b/kalzium/kalziumglwidget.cpp index 2c7d3d1..f4466a3 100644 --- a/kalzium/kalziumglwidget.cpp +++ b/kalzium/kalziumglwidget.cpp @@ -35,6 +35,7 @@ KalziumGLWidget::KalziumGLWidget( QWidget * parent ) { m_isLeftButtonPressed = false; m_movedSinceLeftButtonPressed = false; + m_clickedAtom = 0; m_molecule = 0; m_detail = 0; m_displayList = 0; @@ -206,7 +207,7 @@ void KalziumGLWidget::renderScene( GLenum renderMode, glCallList( m_displayList ); #endif - renderSelection(); + renderHighlighting(); if( renderMode == GL_SELECT ) { @@ -243,18 +244,34 @@ void KalziumGLWidget::renderBonds() } } -void KalziumGLWidget::renderSelection() +void KalziumGLWidget::renderHighlighting() { - if( ! m_selectedAtoms.count() ) return; - - Color( 0.2, 0.7, 1.0, 0.7 ).applyAsMaterials(); glEnable( GL_BLEND ); - foreach(OpenBabel::OBAtom* atom, m_selectedAtoms) + + if( m_clickedAtom ) { - glLoadName( atom->GetIdx() ); - m_sphere.draw( atom->GetVector(), - 0.18 + m_molStyle.getAtomRadius( atom ) ); + Color( 0.6, 0.0, 1.0, 0.7 ).applyAsMaterials(); + glLoadName( m_clickedAtom->GetIdx() ); + m_sphere.draw( m_clickedAtom->GetVector(), + 0.18 + m_molStyle.getAtomRadius( m_clickedAtom ) ); } + + if( m_selectedAtoms.count() ) + { + Color( 0.0, 0.7, 1.0, 0.7 ).applyAsMaterials(); + glEnable( GL_BLEND ); + foreach(OpenBabel::OBAtom* atom, m_selectedAtoms) + { + if( atom != m_clickedAtom ) + { + glLoadName( atom->GetIdx() ); + m_sphere.draw( atom->GetVector(), + 0.18 + m_molStyle.getAtomRadius( + atom ) ); + } + } + } + glDisable( GL_BLEND ); } @@ -308,7 +325,10 @@ void KalziumGLWidget::mousePressEvent( QMouseEvent * event ) m_movedSinceLeftButtonPressed = false; m_lastDraggingPosition = event->pos (); m_initialDraggingPosition = event->pos (); - + computeClickedAtom( event->pos () ); + if( m_clickedAtom ) + kDebug()<GetIdx()<pos() ); - if( atomUnderMouse ) + if( m_selectedAtoms.contains( m_clickedAtom ) ) { - if( m_selectedAtoms.contains( atomUnderMouse ) ) - { - m_selectedAtoms.removeAll( - atomUnderMouse ); - } - else m_selectedAtoms.append( atomUnderMouse ); + m_selectedAtoms.removeAll( + m_clickedAtom ); } + else m_selectedAtoms.append( m_clickedAtom ); updateGL(); } + m_clickedAtom = 0; } } @@ -488,6 +504,7 @@ void KalziumGLWidget::slotSetMolecule( OpenBabel::OBMol* molecule ) m_molecule = molecule; m_haveToRecompileDisplayList = true; m_selectedAtoms.clear(); + m_clickedAtom = 0; prepareMoleculeData(); setupObjects(); updateGL(); @@ -569,10 +586,11 @@ void KalziumGLWidget::slotAtomsSelected( QList atoms ) updateGL(); } -OpenBabel::OBAtom * KalziumGLWidget::getAtomUnderMouse( +void KalziumGLWidget::computeClickedAtom( const QPoint & mousePosition ) { - if( ! m_molecule ) return 0; + m_clickedAtom = 0; + if( ! m_molecule ) return; const GLsizei selectionBufferSize = 1024; GLuint selectionBuffer[selectionBufferSize]; @@ -589,7 +607,6 @@ OpenBabel::OBAtom * KalziumGLWidget::getAtomUnderMouse( minZ = 0xffffffff, *ptrNames, numberOfNames = 0; - printf ("hits = %d\n", numberOfHits); for( i = 0; i < numberOfHits; i++ ) { names = *ptr; @@ -604,9 +621,11 @@ OpenBabel::OBAtom * KalziumGLWidget::getAtomUnderMouse( } for( j = 0, ptr = ptrNames; j < numberOfNames; j++, ptr++ ) - if( *ptr ) return m_molecule->GetAtom( *ptr ); - - return 0; + if( *ptr ) + { + m_clickedAtom = m_molecule->GetAtom( *ptr ); + return; + } } #include "kalziumglwidget.moc" diff --git a/kalzium/kalziumglwidget.h b/kalzium/kalziumglwidget.h index f5f04b9..1179a10 100644 --- a/kalzium/kalziumglwidget.h +++ b/kalzium/kalziumglwidget.h @@ -57,6 +57,8 @@ class KalziumGLWidget : public QGLWidget QPoint m_lastDraggingPosition; QPoint m_initialDraggingPosition; + OpenBabel::OBAtom *m_clickedAtom; + /** * Stores the rotation that is applied to the model. */ @@ -65,7 +67,7 @@ class KalziumGLWidget : public QGLWidget /** * The molecule which is displayed */ - OpenBabel::OBMol* m_molecule; + OpenBabel::OBMol *m_molecule; /** * approximate radius of the molecule, @@ -195,7 +197,7 @@ class KalziumGLWidget : public QGLWidget virtual void paintGL(); virtual void renderAtoms(); virtual void renderBonds(); - virtual void renderSelection(); + virtual void renderHighlighting(); virtual void FPSCounter(); /** @@ -241,8 +243,7 @@ class KalziumGLWidget : public QGLWidget */ void setMolStyle( int style ); - OpenBabel::OBAtom * getAtomUnderMouse( - const QPoint & mousePosition ); + void computeClickedAtom( const QPoint & mousePosition ); }; #endif // KALZIUMGLWIDGET_H -- 2.47.3