/**************************************************************************** Copyright (C) 2002-2006 Gilles Debunne (Gilles.Debunne@imag.fr) This file is part of the QGLViewer library. Version 2.2.4-1, released on December 12, 2006. http://artis.imag.fr/Members/Gilles.Debunne/QGLViewer libQGLViewer is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. libQGLViewer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with libQGLViewer; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ #include "mouseGrabber.h" using namespace qglviewer; using namespace std; void CameraPathPlayer::checkIfGrabsMouse(int x, int y, const Camera* const) { // Rectangular activation array - May have to be tune depending on your default font size setGrabsMouse((x < 80) && (ygrabsMouse()) { glColor3f(1,1,1); if (camera()->keyFrameInterpolator(i)->numberOfKeyFrames() > 1) s = "Play path F" + QString::number(i); else s = "Restore pos F" + QString::number(i); } else { glColor3f(0.6, 0.6, 0.6); if (camera()->keyFrameInterpolator(i)->numberOfKeyFrames() > 1) s = "Path F" + QString::number(i); else s = "Pos F" + QString::number(i); } drawText(10, cpp->yPos()-3, s); } } } void Viewer::updatePlayers() { for (int i=0; ikeyFrameInterpolator(i))) { delete player_[i]; player_[i] = NULL; } // Or add it if needed if ((camera()->keyFrameInterpolator(i)) && (!player_[i])) player_[i] = new CameraPathPlayer(i); } } void Viewer::init() { // Absolutely needed for MouseGrabber setMouseTracking(true); // In order to make the manipulatedFrame displacements clearer setAxisIsDrawn(); // Initialize the CameraPathPlayer MouseGrabber array nbPlayers_ = 12; player_ = new CameraPathPlayer*[nbPlayers_]; for (int i=0; i::const_iterator it=spiral_.begin(), end=spiral_.end(); it != end; ++it) #else for (QList::const_iterator it=spiral_.begin(), end=spiral_.end(); it != end; ++it) #endif (*it).draw(); updatePlayers(); glDisable(GL_LIGHTING); displayPlayers(); glEnable(GL_LIGHTING); } QString Viewer::helpString() const { QString text("

M o u s e G r a b b e r

"); text += "This example illustrates the use of MouseGrabber, which is an abstract "; text += "class for objects that react (usually when the mouse hovers over them).

"; text += "Define new camera paths (or positions) using Alt+[F1-F12]. "; text += "New MouseGrabbers are then created and displayed in the upper left corner. "; text += "Note how they react when the mouse hovers, and click them to play the associated path.

"; text += "ManipulatedFrame, such as the ones which define the spirals' positions, are "; text += "also MouseGrabbers. When the mouse is close to the spiral center, the ManipulatedFrame "; text += "will grab to mouse click (as if the Control key was pressed). This is very convenient "; text += "to intuitively move scene objects (such as lights) without any key or GUI interaction.

"; text += "Note that setMouseTracking() must be enabled to use MouseGrabbers."; return text; } void Spiral::draw() const { glPushMatrix(); glMultMatrixd(mf_.matrix()); // Draw a spiral const float nbSteps = 100.0; glBegin(GL_QUAD_STRIP); for (float i=0; i