Graphviz 14.1.2~dev.20260118.1035
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 "config.h"
12
13#include "glutrender.h"
14#include "viewport.h"
15#include "arcball.h"
16#include "gui/appmouse.h"
17#include "glexpose.h"
18#include "gui/glcompui.h"
19#include <util/exit.h>
20
21 /*call backs */
22
23static float begin_x = 0.0;
24static float begin_y = 0.0;
25static float dx = 0.0;
26static float dy = 0.0;
27
28/*mouse mode mapping funvtion from glut to glcomp*/
30{
31 switch (n) {
32 case GLUT_LEFT_BUTTON:
33 return glMouseLeftButton;
34 case GLUT_RIGHT_BUTTON:
36 case GLUT_MIDDLE_BUTTON:
37 return glMouseRightButton;
38
39 default:
40 return glMouseLeftButton;
41 }
42}
43
44
45static void cb_reshape(int width, int height)
46{
47 float aspect;
48 view->w = width;
49 view->h = height;
50 if (view->widgets)
52 glViewport(0, 0, view->w, view->h);
53 /* setup various opengl things that we need */
54 glMatrixMode(GL_PROJECTION);
55 glLoadIdentity();
57 if (view->w > view->h) {
58 aspect = (float) view->w / (float) view->h;
59 glOrtho(-aspect * GL_VIEWPORT_FACTOR, aspect * GL_VIEWPORT_FACTOR,
60 GL_VIEWPORT_FACTOR * -1, GL_VIEWPORT_FACTOR, -1500, 1500);
61 } else {
62 aspect = (float) view->h / (float) view->w;
64 -aspect * GL_VIEWPORT_FACTOR, aspect * GL_VIEWPORT_FACTOR,
65 -1500, 1500);
66 }
67
68 glMatrixMode(GL_MODELVIEW);
69 glLoadIdentity();
70 /*** OpenGL END ***/
71
72}
73
74static void cb_display(void)
75{
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
77 glLoadIdentity();
78 glexpose_main(view); //draw all stuff
79 glutSwapBuffers();
80 if (view->initFile) {
81 view->initFile = 0;
82 if (view->activeGraph == 0)
85 }
86
87}
88
89static void cb_mouseclick(int button, int state, int x, int y)
90{
91 if (view->g == 0) return;
92 begin_x = (float) x;
93 begin_y = (float) y;
94 if(state==GLUT_DOWN)
95 {
97 (float)x, (float)y,
98 getGlCompMouseType(button));
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;
110 (float)x, (float)y,
111 getGlCompMouseType(button));
112
113 if (button == GLUT_LEFT_BUTTON || button == GLUT_RIGHT_BUTTON ||
114 button == GLUT_MIDDLE_BUTTON)
115 appmouse_up(view, x, y);
116 dx = 0.0;
117 dy = 0.0;
118 }
119 cb_display();
120
121}
122
123// mouse moving with a button clicked (dragging)
124static void cb_drag(int X, int Y)
125{
126
127 float x = (float) X;
128 float y = (float) Y;
129
130 if (view->widgets)
132
133 dx = x - begin_x;
134 dy = y - begin_y;
135 view->mouse.dragX = dx;
136 view->mouse.dragY = dy;
137 appmouse_move(view,x,y);
138
139 if (view->mouse.down)
140 appmouse_drag(view, x, y);
141 begin_x = x;
142 begin_y = y;
143 cb_display();
144
145}
146
147static void cb_keyboard(unsigned char key, int x, int y)
148{
149 (void)x;
150 (void)y;
151
152 if (key==27) /*ESC*/
153 graphviz_exit(1);
154 if(key=='3')
156 if(key=='c')
158
159 if(key=='+')
161 if(key=='-')
163 if(key=='p')
165
166
168}
169
170static void cb_keyboard_up(unsigned char key, int x, int y)
171{
172 (void)key;
173 (void)x;
174 (void)y;
175
177}
178
179static void cb_special_key(int key, int x, int y)
180{
181 (void)x;
182 (void)y;
183
184 if(key==GLUT_KEY_F1)
185 {
186 printf("Currently help is not available\n");
187 }
189
190}
191
192static void cb_special_key_up(int key, int x, int y)
193{
194 (void)x;
195 (void)y;
196
197 if(key==GLUT_KEY_F1)
198 {
199 printf("Currently help is not available\n");
200 }
202
203}
204
205static void cb_game_mode(char* optArg)
206{
207
208 glutGameModeString(optArg);
209 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
210 {
211 glutEnterGameMode();
212 }
213 else
214 {
215 printf("smyrna cannot initialize requested screen resolution and rate!\n");
216 graphviz_exit(-1);
217
218 }
219}
220
221int cb_glutinit(int w, int h, int *argcp, char *argv[], char *optArg) {
222 /*
223 w,h: width and height of the window in pixels
224 argcp argv: main function's parameters, required for glutinit
225 */
226
227
228
229 glutInit(argcp,argv); //this is required by some OS.
230
231 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
232 // The Type Of Depth Testing To Do
233 glDisable(GL_DEPTH);
234 glClearDepth(1.0f); // Depth Buffer Setup
235 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
236 glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To
237 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
238
239
240 cb_game_mode(optArg);
241
242 /*register callbacks here*/
243 glutDisplayFunc(cb_display);
244 glutReshapeFunc(cb_reshape);
245 glutKeyboardFunc(cb_keyboard);
246 glutKeyboardUpFunc( cb_keyboard_up);
247 glutMouseFunc(cb_mouseclick);
248 glutMotionFunc(cb_drag);
249 glutPassiveMotionFunc(NULL);
250 glutVisibilityFunc(NULL);
251 glutEntryFunc(NULL);
252 glutSpecialFunc(cb_special_key);
253 glutSpecialUpFunc(cb_special_key_up);
254
255 //Attach extra call backs if needed in the future
256/* glutOverlayDisplayFunc
257 glutSpaceballMotionFunc
258 glutSpaceballRotateFunc
259 glutSpaceballButtonFunc
260 glutButtonBoxFunc
261 glutDialsFunc
262 glutTabletMotionFunc
263 glutTabletButtonFunc
264 glutMenuStatusFunc
265 glutIdleFunc
266 glutTimerFunc
267*/
268
269
270 //pass control to glut
271 cb_reshape(w,h);
272 glutMainLoop ();
273
274
275 return 0; //we should never reach here
276
277}
void appmouse_drag(ViewInfo *v, int x, int y)
Definition appmouse.c:101
void appmouse_key_release(ViewInfo *v)
Definition appmouse.c:136
void appmouse_move(ViewInfo *v, int x, int y)
Definition appmouse.c:132
void appmouse_key_press(ViewInfo *v, int key)
Definition appmouse.c:145
void appmouse_middle_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:124
void appmouse_left_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:108
void appmouse_right_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:116
void appmouse_up(ViewInfo *v, int x, int y)
Definition appmouse.c:90
ArcBall_t init_arcBall(float NewWidth, float NewHeight)
Definition arcball.c:84
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
#define Y(i)
Definition gdefs.h:3
#define X(prefix, name, str, type, subtype,...)
Definition gdefs.h:14
glMouseButtonType
Definition glcompdefs.h:67
@ glMouseRightButton
Definition glcompdefs.h:67
@ glMouseMiddleButton
Definition glcompdefs.h:68
@ glMouseLeftButton
Definition glcompdefs.h:67
void glcompsetUpdateBorder(glCompSet *s, int w, int h)
Definition glcompset.c:238
void switch2D3D(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:118
void menu_click_zoom_minus(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:49
void menu_click_center(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:101
void menu_click_pan(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:40
void menu_click_zoom_plus(glCompObj *obj, float x, float y, glMouseButtonType t)
Definition glcompui.c:60
int glexpose_main(ViewInfo *vi)
Definition glexpose.c:147
static void cb_game_mode(char *optArg)
Definition glutrender.c:205
static float begin_x
Definition glutrender.c:23
static void cb_drag(int X, int Y)
Definition glutrender.c:124
static void cb_special_key(int key, int x, int y)
Definition glutrender.c:179
static void cb_mouseclick(int button, int state, int x, int y)
Definition glutrender.c:89
static void cb_display(void)
Definition glutrender.c:74
static void cb_keyboard(unsigned char key, int x, int y)
Definition glutrender.c:147
static void cb_special_key_up(int key, int x, int y)
Definition glutrender.c:192
static void cb_keyboard_up(unsigned char key, int x, int y)
Definition glutrender.c:170
static float dy
Definition glutrender.c:26
static float begin_y
Definition glutrender.c:24
static float dx
Definition glutrender.c:25
static glMouseButtonType getGlCompMouseType(int n)
Definition glutrender.c:29
static void cb_reshape(int width, int height)
Definition glutrender.c:45
int cb_glutinit(int w, int h, int *argcp, char *argv[], char *optArg)
Definition glutrender.c:221
node NULL
Definition grammar.y:181
ViewInfo * view
Definition viewport.c:40
#define GL_VIEWPORT_FACTOR
Definition smyrnadefs.h:37
int isDragging
Definition arcball.h:427
ArcBall_t * arcball
Definition smyrnadefs.h:331
Agraph_t ** g
Definition smyrnadefs.h:288
glCompSet * widgets
Definition smyrnadefs.h:324
char * initFileName
Definition smyrnadefs.h:325
int activeGraph
Definition smyrnadefs.h:292
glCompMouse mouse
Definition smyrnadefs.h:295
glcompmouseupfunc_t mouseup
Definition glcompdefs.h:154
glcompmousedownfunc_t mousedown
Definition glcompdefs.h:153
glcompmouseoverfunc_t mouseover
Definition glcompdefs.h:152
glCompCallBacks functions
Definition glcompdefs.h:179
glCompCommon common
Definition glcompdefs.h:185
glCompObj base
Definition glcompdefs.h:240
void close_graph(ViewInfo *vi)
Definition viewport.c:74
int add_graph_to_viewport_from_file(char *fileName)
Definition viewport.c:347