Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <GL/glut.h>
#include "flhack.H"
#include "Gview.H"
#include "partiview.H"
#include "geometry.h"
#include "shmem.h"
#include "pview_funcs.h"
extern "C" {
#include "findfile.h"
};
int wwidth = 640;
int wheight = 480;
int wposx = 100;
int wposy = 100;
int isFullScreen = false;
extern char partiview_version[];
void display()
{
ppui.view->redraw(true);
glutSwapBuffers();
}
void reshape (int _w,int _h)
{
if (!isFullScreen) {
wwidth = _w;
wheight = _h;
}
ppui.view->size(_w,_h);
}
void mouseFunc(int _button,int _state,int _x,int _y)
{
#ifdef MACINTOSH
if (_button == GLUT_LEFT_BUTTON && glutGetModifiers())
_button = GLUT_RIGHT_BUTTON;
#endif
Fl::state = 0;
if (_button == GLUT_LEFT_BUTTON) {
Fl::state = FL_BUTTON1;
Fl::button = FL_LEFT_MOUSE;
}
if (_button == GLUT_MIDDLE_BUTTON) {
Fl::state = FL_BUTTON2;
Fl::button = FL_MIDDLE_MOUSE;
}
if (_button == GLUT_RIGHT_BUTTON) {
Fl::state = FL_BUTTON3;
Fl::button = FL_RIGHT_MOUSE;
}
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT)
Fl::state += FL_SHIFT;
if (glutGetModifiers() == GLUT_ACTIVE_CTRL)
Fl::state += FL_CTRL;
Fl::x = _x;
Fl::y = _y;
if (_state == GLUT_DOWN)
ppui.view->handle(FL_PUSH);
else {
Fl::state = 0;
ppui.view->handle(FL_RELEASE);
Fl::button = 0;
}
}
void mouseMotion(int _x,int _y)
{
Fl::x = _x;
Fl::y = _y;
ppui.view->handle(FL_DRAG);
}
void special(int _key,int _x,int _y)
{
Fl::keys[0] = _key;
Fl::keys[1] = '\0';
Fl::x = _x;
Fl::y = _y;
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT)
Fl::state += FL_SHIFT;
if (glutGetModifiers() == GLUT_ACTIVE_CTRL)
Fl::state += FL_CTRL;
ppui.view->handle(FL_KEYBOARD);
if (_key == GLUT_KEY_F1) {
fprintf(stdout, "> ");
char line[1024];
gets(line);
pviewEval(line);
}
if (_key == GLUT_KEY_F11) {
if (isFullScreen) {
isFullScreen = false;
glutPositionWindow(wposx, wposy);
glutReshapeWindow(wwidth, wheight);
} else {
isFullScreen = true;
glutFullScreen();
}
}
glutPostRedisplay();
}
void keyboard(unsigned char _key,int _x,int _y)
{
Fl::keys[0] = _key;
Fl::keys[1] = '\0';
Fl::x = _x;
Fl::y = _y;
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT)
Fl::state += FL_SHIFT;
if (glutGetModifiers() == GLUT_ACTIVE_CTRL)
Fl::state += FL_CTRL;
ppui.view->handle(FL_KEYBOARD);
glutPostRedisplay();
}
void idle(void)
{
Fl::idle();
if (pviewPicked()) {
fprintf(stdout, "%s\n", _pickmsg);
strcpy(_pickmsg, "");
}
glutPostRedisplay();
}
int main(int _argc,char **_argv)
{
glutInit(&_argc,_argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(wwidth, wheight);
glutInitWindowPosition(wposx, wposy);
glutCreateWindow(_argv[0]);
fprintf(stdout, "Welcome to Partiview ver.%s : glut version.\n", partiview_version);
fprintf(stdout, "Hit [F1] key to enter a command.\n\n");
// initialize partiview
char* initarg = NULL;
if (_argc>1)
initarg = _argv[1];
pviewInit(initarg);
pviewEval("inertia on");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouseFunc);
glutMotionFunc(mouseMotion);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}