Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
glutrender.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <cgraph/exit.h>
12
13#include "glutrender.h"
14#include "viewport.h"
15#include "arcball.h"
16#include "appmouse.h"
17#include "glexpose.h"
18#include "glcompui.h"
19
20 /*call backs */
21
22static float begin_x = 0.0;
23static float begin_y = 0.0;
24static float dx = 0.0;
25static float dy = 0.0;
26
27/*mouse mode mapping funvtion from glut to glcomp*/
29{
30 switch (n) {
31 case GLUT_LEFT_BUTTON:
32 return glMouseLeftButton;
33 case GLUT_RIGHT_BUTTON:
35 case GLUT_MIDDLE_BUTTON:
36 return glMouseRightButton;
37
38 default:
39 return glMouseLeftButton;
40 }
41}
42
43
44static void cb_reshape(int width, int height)
45{
46 int vPort[4];
47 float aspect;
48 view->w = width;
49 view->h = height;
50 if (view->widgets)
52 glViewport(0, 0, view->w, view->h);
53 /* get current viewport */
54 glGetIntegerv(GL_VIEWPORT, vPort);
55 /* setup various opengl things that we need */
56 glMatrixMode(GL_PROJECTION);
57 glLoadIdentity();
58 init_arcBall(view->arcball, (float)view->w, (float)view->h);
59 if (view->w > view->h) {
60 aspect = (float) view->w / (float) view->h;
61 glOrtho(-aspect * GL_VIEWPORT_FACTOR, aspect * GL_VIEWPORT_FACTOR,
62 GL_VIEWPORT_FACTOR * -1, GL_VIEWPORT_FACTOR, -1500, 1500);
63 } else {
64 aspect = (float) view->h / (float) view->w;
66 -aspect * GL_VIEWPORT_FACTOR, aspect * GL_VIEWPORT_FACTOR,
67 -1500, 1500);
68 }
69
70 glMatrixMode(GL_MODELVIEW);
71 glLoadIdentity();
72 /*** OpenGL END ***/
73
74}
75
76static void cb_display(void)
77{
78 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
79 glLoadIdentity();
80 glexpose_main(view); //draw all stuff
81 glutSwapBuffers();
82 if (view->initFile) {
83 view->initFile = 0;
84 if (view->activeGraph == 0)
87 }
88
89}
90
91static void cb_mouseclick(int button, int state, int x, int y)
92{
93 if (view->g == 0) return;
94 begin_x = (float) x;
95 begin_y = (float) y;
96 if(state==GLUT_DOWN)
97 {
99 if (button == GLUT_LEFT_BUTTON)
101 if (button == GLUT_RIGHT_BUTTON)
103 if (button == GLUT_MIDDLE_BUTTON)
105 }
106 else
107 {
108 view->arcball->isDragging = 0;
109 view->widgets->common.functions.mouseup((glCompObj*)view->widgets, (float)x, (float)y, getGlCompMouseType(button));
110
111 if (button == GLUT_LEFT_BUTTON)
113 if (button == GLUT_LEFT_BUTTON)
115 if (button == GLUT_MIDDLE_BUTTON)
117 dx = 0.0;
118 dy = 0.0;
119 }
120 cb_display();
121
122}
123
124// mouse moving with a button clicked (dragging)
125static void cb_drag(int X, int Y)
126{
127
128 float x = (float) X;
129 float y = (float) Y;
130
131 if (view->widgets)
133
134 dx = x - begin_x;
135 dy = y - begin_y;
136 view->mouse.dragX = dx;
137 view->mouse.dragY = dy;
138 appmouse_move(view,x,y);
139
146 begin_x = x;
147 begin_y = y;
148 cb_display();
149
150}
151
152static void cb_keyboard(unsigned char key, int x, int y)
153{
154 (void)x;
155 (void)y;
156
157 if (key==27) /*ESC*/
158 graphviz_exit(1);
159 if(key=='3')
161 if(key=='c')
163
164 if(key=='+')
166 if(key=='-')
168 if(key=='p')
170
171
173}
174
175static void cb_keyboard_up(unsigned char key, int x, int y)
176{
177 (void)key;
178 (void)x;
179 (void)y;
180
182}
183
184static void cb_special_key(int key, int x, int y)
185{
186 (void)x;
187 (void)y;
188
189 if(key==GLUT_KEY_F1)
190 {
191 printf("Currently help is not available\n");
192 }
194
195}
196
197static void cb_special_key_up(int key, int x, int y)
198{
199 (void)x;
200 (void)y;
201
202 if(key==GLUT_KEY_F1)
203 {
204 printf("Currently help is not available\n");
205 }
207
208}
209
210static void cb_game_mode(char* optArg)
211{
212
213 glutGameModeString(optArg);
214 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
215 {
216 glutEnterGameMode();
217 }
218 else
219 {
220 printf("smyrna cannot initialize requested screen resolution and rate!\n");
221 graphviz_exit(-1);
222
223 }
224}
225
226int cb_glutinit(int w, int h, int *argcp, char *argv[], char *optArg) {
227 /*
228 w,h: width and height of the window in pixels
229 argcp argv: main function's parameters, required for glutinit
230 */
231
232
233
234 glutInit(argcp,argv); //this is required by some OS.
235
236 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
237 // The Type Of Depth Testing To Do
238 glDisable(GL_DEPTH);
239 glClearDepth(1.0f); // Depth Buffer Setup
240 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
241 glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To
242 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
243
244
245 cb_game_mode(optArg);
246
247 /*register callbacks here*/
248 glutDisplayFunc(cb_display);
249 glutReshapeFunc(cb_reshape);
250 glutKeyboardFunc(cb_keyboard);
251 glutKeyboardUpFunc( cb_keyboard_up);
252 glutMouseFunc(cb_mouseclick);
253 glutMotionFunc(cb_drag);
254 glutPassiveMotionFunc(NULL);
255 glutVisibilityFunc(NULL);
256 glutEntryFunc(NULL);
257 glutSpecialFunc(cb_special_key);
258 glutSpecialUpFunc(cb_special_key_up);
259
260 //Attach extra call backs if needed in the future
261/* glutOverlayDisplayFunc
262 glutSpaceballMotionFunc
263 glutSpaceballRotateFunc
264 glutSpaceballButtonFunc
265 glutButtonBoxFunc
266 glutDialsFunc
267 glutTabletMotionFunc
268 glutTabletButtonFunc
269 glutMenuStatusFunc
270 glutIdleFunc
271 glutTimerFunc
272*/
273
274
275 //pass control to glut
276 cb_reshape(w,h);
277 glutMainLoop ();
278
279
280 return 0; //we should never reach here
281
282}
void appmouse_left_click_up(ViewInfo *v, int x, int y)
Definition appmouse.c:112
void appmouse_right_drag(ViewInfo *v, int x, int y)
Definition appmouse.c:135
void appmouse_middle_click_up(ViewInfo *v, int x, int y)
Definition appmouse.c:150
void appmouse_right_click_up(ViewInfo *v, int x, int y)
Definition appmouse.c:130
void appmouse_key_release(ViewInfo *v)
Definition appmouse.c:165
void appmouse_move(ViewInfo *v, int x, int y)
Definition appmouse.c:161
void appmouse_key_press(ViewInfo *v, int key)
Definition appmouse.c:175
void appmouse_middle_drag(ViewInfo *v, int x, int y)
Definition appmouse.c:155
void appmouse_middle_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:143
void appmouse_left_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:105
void appmouse_right_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:123
void appmouse_left_drag(ViewInfo *v, int x, int y)
Definition appmouse.c:116
void init_arcBall(ArcBall_t *a, float NewWidth, float NewHeight)
Definition arcball.c:88
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
disc key
Definition exparse.y:214
#define Y(i)
Definition gdefs.h:3
#define X(prefix, name, str, type, subtype,...)
Definition gdefs.h:14
glMouseButtonType
Definition glcompdefs.h:89
@ glMouseRightButton
Definition glcompdefs.h:89
@ glMouseMiddleButton
Definition glcompdefs.h:90
@ glMouseLeftButton
Definition glcompdefs.h:89
void glcompsetUpdateBorder(glCompSet *s, int w, int h)
Definition glcompset.c:252
void switch2D3D(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:115
void menu_click_zoom_minus(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:46
void menu_click_center(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:98
void menu_click_pan(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:37
void menu_click_zoom_plus(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:57
int glexpose_main(ViewInfo *vi)
Definition glexpose.c:153
static void cb_game_mode(char *optArg)
Definition glutrender.c:210
static float begin_x
Definition glutrender.c:22
static void cb_drag(int X, int Y)
Definition glutrender.c:125
static void cb_special_key(int key, int x, int y)
Definition glutrender.c:184
static void cb_mouseclick(int button, int state, int x, int y)
Definition glutrender.c:91
static void cb_display(void)
Definition glutrender.c:76
static void cb_keyboard(unsigned char key, int x, int y)
Definition glutrender.c:152
static void cb_special_key_up(int key, int x, int y)
Definition glutrender.c:197
static void cb_keyboard_up(unsigned char key, int x, int y)
Definition glutrender.c:175
static float dy
Definition glutrender.c:25
static float begin_y
Definition glutrender.c:23
static float dx
Definition glutrender.c:24
static glMouseButtonType getGlCompMouseType(int n)
Definition glutrender.c:28
static void cb_reshape(int width, int height)
Definition glutrender.c:44
int cb_glutinit(int w, int h, int *argcp, char *argv[], char *optArg)
Definition glutrender.c:226
node NULL
Definition grammar.y:149
static lexstate_t state
Definition htmllex.c:61
ViewInfo * view
Definition viewport.c:38
#define GL_VIEWPORT_FACTOR
Definition smyrnadefs.h:39
int isDragging
Definition arcball.h:554
ArcBall_t * arcball
Definition smyrnadefs.h:365
Agraph_t ** g
Definition smyrnadefs.h:313
glCompSet * widgets
Definition smyrnadefs.h:358
char * initFileName
Definition smyrnadefs.h:359
int activeGraph
Definition smyrnadefs.h:317
glCompMouse mouse
Definition smyrnadefs.h:321
glcompmouseupfunc_t mouseup
Definition glcompdefs.h:197
glcompmousedownfunc_t mousedown
Definition glcompdefs.h:196
glcompmouseoverfunc_t mouseover
Definition glcompdefs.h:193
glCompCallBacks functions
Definition glcompdefs.h:223
glMouseButtonType t
Definition glcompdefs.h:278
glCompCommon common
Definition glcompdefs.h:298
void close_graph(ViewInfo *vi)
Definition viewport.c:74
int add_graph_to_viewport_from_file(char *fileName)
Definition viewport.c:364