Simbody  3.4 (development)
Visualizer_InputListener.h
Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_VISUALIZER_INPUT_LISTENER_H_
00002 #define SimTK_SIMBODY_VISUALIZER_INPUT_LISTENER_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                               Simbody(tm)                                  *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK biosimulation toolkit originating from           *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody.  *
00011  *                                                                            *
00012  * Portions copyright (c) 2010-12 Stanford University and the Authors.        *
00013  * Authors: Peter Eastman, Michael Sherman                                    *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
00017  * not use this file except in compliance with the License. You may obtain a  *
00018  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
00019  *                                                                            *
00020  * Unless required by applicable law or agreed to in writing, software        *
00021  * distributed under the License is distributed on an "AS IS" BASIS,          *
00022  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
00023  * See the License for the specific language governing permissions and        *
00024  * limitations under the License.                                             *
00025  * -------------------------------------------------------------------------- */
00026 
00031 #include "simbody/internal/common.h"
00032 #include "simbody/internal/Visualizer.h"
00033 
00034 namespace SimTK {
00035 
00036 //==============================================================================
00037 //                             INPUT LISTENER
00038 //==============================================================================
00047 class SimTK_SIMBODY_EXPORT Visualizer::InputListener {
00048 public:
00054 enum Modifier {
00055     ShiftIsDown   = 0x01, 
00056     ControlIsDown = 0x02, 
00057     AltIsDown     = 0x04, 
00058     IsSpecialKey  = 0xC0  
00059 };
00060 
00061 static const unsigned SpecialKeyOffset = 0x100; // Added to each code
00062 
00065 enum KeyCode {
00066     KeyControlC     = 3,            // some notable ASCII codes
00067     KeyBeep         = 7,
00068     KeyBackspace    = 8,            
00069     KeyTab          = 9,
00070     KeyLF           = 10,
00071     KeyReturn       = 13,
00072     KeyEnter        = KeyReturn,
00073     KeyEsc          = 27,
00074     KeyDelete       = 127,
00075 
00076     KeyF1  = SpecialKeyOffset + 1,  // function keys
00077     KeyF2  = SpecialKeyOffset + 2,
00078     KeyF3  = SpecialKeyOffset + 3,
00079     KeyF4  = SpecialKeyOffset + 4,
00080     KeyF5  = SpecialKeyOffset + 5,
00081     KeyF6  = SpecialKeyOffset + 6,
00082     KeyF7  = SpecialKeyOffset + 7,
00083     KeyF8  = SpecialKeyOffset + 8,
00084     KeyF9  = SpecialKeyOffset + 9,
00085     KeyF10 = SpecialKeyOffset + 10,
00086     KeyF11 = SpecialKeyOffset + 11,
00087     KeyF12 = SpecialKeyOffset + 12,
00088 
00089     KeyLeftArrow    = SpecialKeyOffset + 100,  // directional keys
00090     KeyUpArrow      = SpecialKeyOffset + 101,
00091     KeyRightArrow   = SpecialKeyOffset + 102,
00092     KeyDownArrow    = SpecialKeyOffset + 103,
00093     KeyPageUp       = SpecialKeyOffset + 104,
00094     KeyPageDown     = SpecialKeyOffset + 105,
00095     KeyHome         = SpecialKeyOffset + 106,
00096     KeyEnd          = SpecialKeyOffset + 107,
00097     KeyInsert       = SpecialKeyOffset + 108
00098 };
00099     
00101 virtual ~InputListener() {}
00102 
00117 virtual bool keyPressed(unsigned key, unsigned modifiers) {return false;}
00118 
00125 virtual bool menuSelected(int menu, int item) {return false;}
00126 
00133 virtual bool sliderMoved(int slider, Real value) {return false;}
00134 };
00135 
00136 
00137 
00138 //==============================================================================
00139 //                              INPUT SILO
00140 //==============================================================================
00233 class SimTK_SIMBODY_EXPORT Visualizer::InputSilo
00234 :   public Visualizer::InputListener {
00235 public:
00237 InputSilo();
00239 ~InputSilo();
00240 
00243 bool isAnyUserInput() const;
00244 
00248 void waitForAnyUserInput() const;
00249 
00262 bool takeKeyHit(unsigned& key, unsigned& modifiers);
00263 
00269 void waitForKeyHit(unsigned& key, unsigned& modifiers);
00270 
00283 bool takeMenuPick(int& menu, int& item);
00284 
00290 void waitForMenuPick(int& menu, int& item);
00291 
00305 bool takeSliderMove(int& slider, Real& value);
00306 
00312 void waitForSliderMove(int& slider, Real& value);
00313 
00315 void clear();
00316 
00317 //------------------------------------------------------------------------------
00318                                  private:
00319 // Each of these will return true to the Visualizer's listener thread, meaning 
00320 // that the input will be absorbed and subsequent listeners (if any) will not 
00321 // be called.
00322 virtual bool keyPressed(unsigned key, unsigned modifiers);
00323 virtual bool menuSelected(int menu, int item);
00324 virtual bool sliderMoved(int slider, Real value);
00325 
00326 class Impl;
00327 const Impl& getImpl() const {assert(m_impl); return *m_impl;}
00328 Impl&       updImpl()       {assert(m_impl); return *m_impl;}
00329 
00330 Impl*       m_impl;   // the lone data member in this class
00331 };
00332 
00333 } // namespace SimTK
00334 
00335 #endif // SimTK_SIMBODY_VISUALIZER_INPUT_LISTENER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines