1 /* -*-c++-*-
2 * Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors:
19 *
20 * Cedric Pinson <mornifle@plopbyte.net>
21 *
22 */
23
24 #include "AnimtkViewerKeyHandler"
25
AnimtkKeyEventHandler()26 AnimtkKeyEventHandler::AnimtkKeyEventHandler()
27 {
28 _actionKeys[List] = 'l';
29 _actionKeys[Help] = 'h';
30 _actionKeys[Play] = 'p';
31 _actionKeys[Next] = ']';
32 _actionKeys[Prev] = '[';
33 }
34
printUsage() const35 void AnimtkKeyEventHandler::printUsage() const
36 {
37 std::cout << (char) _actionKeys.find(Help)->second << " for Help" << std::endl;
38 std::cout << (char) _actionKeys.find(List)->second << " for List" << std::endl;
39 std::cout << (char) _actionKeys.find(Play)->second << " for Play" << std::endl;
40 std::cout << (char) _actionKeys.find(Next)->second << " for select Next item" << std::endl;
41 std::cout << (char) _actionKeys.find(Prev)->second << " for select Previous item" << std::endl;
42 }
43
44
handle(const osgGA::GUIEventAdapter & ea,osgGA::GUIActionAdapter &,osg::Object *,osg::NodeVisitor *)45 bool AnimtkKeyEventHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&,
46 osg::Object*, osg::NodeVisitor*)
47 {
48 AnimtkViewerModelController& mc = AnimtkViewerModelController::instance();
49 if(ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN)
50 {
51 if (ea.getKey() == _actionKeys[List]) return mc.list();
52 else if (ea.getKey() == _actionKeys[Play]) return mc.play();
53 else if (ea.getKey() == _actionKeys[Next]) return mc.next();
54 else if (ea.getKey() == _actionKeys[Prev]) return mc.previous();
55 else if (ea.getKey() == _actionKeys[Help])
56 {
57 printUsage();
58 return true;
59 }
60 }
61
62 return false;
63 }
64