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