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

Annotation of /trunk/cusplibrary/cusp/opengl/spy/glut_2d_canvas.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_2d_canvas.h
File MIME type: text/plain
File size: 2838 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 "glut_window.h"
20    
21     namespace cusp
22     {
23     namespace opengl
24     {
25     namespace spy
26     {
27    
28     /**
29     * @file glut_2d_canvas.h
30     *
31     * The main glut_2d_canvas window handler. This
32     * class provides some slightly higher-level functions
33     * above a GLUT window.
34     */
35    
36     class glut_2d_canvas
37     : public glut_window<glut_2d_canvas>
38     {
39     public:
40     glut_2d_canvas(int w, int h, const char* title);
41    
42     // derived classes should override draw, not display
43     virtual void draw();
44    
45     virtual void display();
46     virtual void reshape(int w, int h);
47     virtual void key(unsigned char key, int x, int y);
48     virtual void special_key(int key, int x, int y);
49     virtual void motion(int x, int y);
50     virtual void mouse_click(int button, int state, int x, int y);
51     virtual void menu(int value) {};
52    
53     public:
54    
55     // window properties
56     int width;
57     int height;
58    
59     float natural_width;
60     float natural_height;
61    
62     float zoom;
63    
64     float trans_x;
65     float trans_y;
66    
67     float center_x;
68     float center_y;
69    
70     float aspect;
71    
72     void set_natural_size(float w, float h)
73     {
74     natural_width = w;
75     natural_height = h;
76     glutPostRedisplay();
77     }
78    
79     void set_center(float x, float y)
80     {
81     center_x = x;
82     center_y = y;
83     glutPostRedisplay();
84     }
85    
86     void set_window_size(int w, int h)
87     {
88     glutSetWindow(glut_id);
89     glutReshapeWindow(w,h);
90     }
91    
92     void set_zoom(float z)
93     {
94     zoom = z;
95     glutPostRedisplay();
96     }
97    
98     void set_aspect(float a)
99     {
100     aspect = a;
101     }
102    
103     void set_background_color(float r, float g, float b)
104     { background_color[0]=r; background_color[1]=g; background_color[2]=b; }
105    
106    
107    
108     protected:
109     enum {
110     STATE_NONE = 100,
111     STATE_MOVE,
112     STATE_ZOOM
113     } mouse_state;
114    
115     // used by the mouse handler
116     int mouse_begin_x;
117     int mouse_begin_y;
118    
119     float virtual_width;
120     float virtual_height;
121    
122     void begin_mouse_click(int x, int y)
123     {
124     mouse_begin_x = x;
125     mouse_begin_y = y;
126     }
127    
128     float background_color[3];
129    
130     bool display_finished;
131     int frame;
132     };
133    
134     } // end spy
135     } // end opengl
136     } // end cusp
137    
138     #include <cusp/opengl/spy/detail/glut_2d_canvas.inl>
139    

  ViewVC Help
Powered by ViewVC 1.1.26