0b7a16b032b34020b31a71127cddad41369fa946
[blender.git] / intern / iksolver / test / ik_glut_test / common / GlutKeyboardManager.cpp
1 /**
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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 Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include "GlutKeyboardManager.h"
29 #include "MT_assert.h"
30
31 MEM_SmartPtr<GlutKeyboardManager> GlutKeyboardManager::m_s_instance = MEM_SmartPtr<GlutKeyboardManager>();
32
33         GlutKeyboardManager *
34 GlutKeyboardManager::
35 Instance(
36 ){
37         if (m_s_instance == NULL) {
38                 m_s_instance = new GlutKeyboardManager();
39         }
40
41         return m_s_instance;
42 }
43
44
45 // this is the function you should pass to glut
46
47         void
48 GlutKeyboardManager::
49 HandleKeyboard(
50         unsigned char key,
51         int x,
52         int y
53 ){
54         GlutKeyboardManager *manager = GlutKeyboardManager::Instance();
55
56         if (manager->m_handler != NULL) {
57                 manager->m_handler->HandleKeyboard(key,x,y);
58         }
59 }
60
61         void
62 GlutKeyboardManager::
63 InstallHandler(
64         GlutKeyboardHandler * handler
65 ){
66
67         MT_assert(m_handler == NULL);
68         m_handler = handler;
69 }
70
71         void
72 GlutKeyboardManager::
73 ReleaseHandler(
74 ){
75         m_handler = NULL;
76 }
77
78
79 GlutKeyboardManager::
80 ~GlutKeyboardManager(
81 ){
82
83         delete(m_handler);
84 }