/[escript]/trunk/cusplibrary/cusp/opengl/spy/glut_window.h
ViewVC logotype

Annotation of /trunk/cusplibrary/cusp/opengl/spy/glut_window.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4955 - (hide annotations)
Tue May 20 04:33:15 2014 UTC (6 years, 4 months ago) by caltinay
Original Path: branches/diaplayground/cusplibrary/cusp/opengl/spy/glut_window.h
File MIME type: text/plain
File size: 3098 byte(s)
added pristine copy of cusplibrary (apache license) to be used by ripley.

1 caltinay 4955 /*
2     * Copyright 2008-2010 NVIDIA Corporation
3     *
4     * Licensed under the Apache License, Version 2.0 (the "License");
5     * you may not use this file except in compliance with the License.
6     * You may obtain a copy of the License at
7     *
8     * http://www.apache.org/licenses/LICENSE-2.0
9     *
10     * Unless required by applicable law or agreed to in writing, software
11     * distributed under the License is distributed on an "AS IS" BASIS,
12     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     * See the License for the specific language governing permissions and
14     * limitations under the License.
15     */
16    
17     #pragma once
18    
19     #include <cusp/opengl/spy/gl_util.h>
20    
21     namespace cusp
22     {
23     namespace opengl
24     {
25     namespace spy
26     {
27    
28     template <class Derived>
29     class glut_window
30     {
31     public:
32     void register_with_glut()
33     {
34     set_window_data(glut_id, this);
35    
36     glutSetWindow(glut_id);
37     glutDisplayFunc(Derived::glut_display);
38     glutReshapeFunc(Derived::glut_reshape);
39     glutKeyboardFunc(Derived::glut_key);
40     glutSpecialFunc(Derived::glut_special_key);
41     glutMotionFunc(Derived::glut_motion);
42     glutMouseFunc(Derived::glut_mouse_click);
43     }
44    
45     int get_glut_window_id()
46     {
47     return (glut_id);
48     }
49    
50     protected:
51     int glut_id;
52    
53     /**
54     * Empty prototypes...
55     */
56     void display()
57     {
58     }
59    
60     void reshape(int w, int h)
61     {
62     }
63    
64     void key(unsigned char key, int x, int y)
65     {
66     }
67    
68     void special_key(int key, int x, int y)
69     {
70     }
71    
72     void motion(int x, int y)
73     {
74     }
75    
76     void mouse_click(int button, int state, int x, int y)
77     {
78     }
79    
80     void menu(int value)
81     {
82     }
83    
84     public:
85     static void glut_display()
86     {
87     Derived* gw = get_class_pointer();
88     if (gw)
89     gw->display();
90     }
91    
92     static void glut_reshape(int w, int h)
93     {
94     Derived* gw = get_class_pointer();
95     if (gw)
96     gw->reshape(w,h);
97     }
98    
99     static void glut_key(unsigned char key, int x, int y)
100     {
101     Derived* gw = get_class_pointer();
102     if (gw)
103     gw->key(key,x,y);
104     }
105     static void glut_special_key(int key, int x, int y)
106     {
107     Derived* gw = get_class_pointer();
108     if (gw)
109     gw->special_key(key,x,y);
110     }
111     static void glut_motion(int x, int y)
112     {
113     Derived* gw = get_class_pointer();
114     if (gw)
115     gw->motion(x,y);
116     }
117     static void glut_mouse_click(int button, int state, int x, int y)
118     {
119     Derived* gw = get_class_pointer();
120     if (gw)
121     gw->mouse_click(button,state,x,y);
122     }
123    
124     static void glut_menu(int value)
125     {
126     Derived* gw = get_class_pointer();
127     if (gw)
128     gw->menu(value);
129     }
130    
131    
132     private:
133     static Derived* get_class_pointer()
134     {
135     int w_id = glutGetWindow();
136     void* d = get_window_data(w_id);
137     glut_window<Derived>* gw = (glut_window<Derived>*)d;
138     if (gw && gw->glut_id==w_id)
139     return ((Derived*)gw);
140     else
141     return (0);
142     }
143     };
144    
145     } // end spy
146     } // end opengl
147     } // end cusp
148    

  ViewVC Help
Powered by ViewVC 1.1.26