Graphviz 13.0.0~dev.20241220.2304
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 "appmouse.h"
15#include "glexpose.h"
16#include "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 int vPort[4];
46 float aspect;
47 view->w = width;
48 view->h = height;
49 if (view->widgets)
51 glViewport(0, 0, view->w, view->h);
52 /* get current viewport */
53 glGetIntegerv(GL_VIEWPORT, vPort);
54 /* setup various opengl things that we need */
55 glMatrixMode(GL_PROJECTION);
56 glLoadIdentity();
58 if (view->w > view->h) {
59 aspect = (float) view->w / (float) view->h;
60 glOrtho(-aspect * GL_VIEWPORT_FACTOR, aspect * GL_VIEWPORT_FACTOR,
61 GL_VIEWPORT_FACTOR * -1, GL_VIEWPORT_FACTOR, -1500, 1500);
62 } else {
63 aspect = (float) view->h / (float) view->w;
65 -aspect * GL_VIEWPORT_FACTOR, aspect * GL_VIEWPORT_FACTOR,
66 -1500, 1500);
67 }
68
69 glMatrixMode(GL_MODELVIEW);
70 glLoadIdentity();
71 /*** OpenGL END ***/
72
73}
74
75static void cb_display(void)
76{
77 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
78 glLoadIdentity();
79 glexpose_main(view); //draw all stuff
80 glutSwapBuffers();
81 if (view->initFile) {
82 view->initFile = 0;
83 if (view->activeGraph == 0)
86 }
87
88}
89
90static void cb_mouseclick(int button, int state, int x, int y)
91{
92 if (view->g == 0) return;
93 begin_x = (float) x;
94 begin_y = (float) y;
95 if(state==GLUT_DOWN)
96 {
98 (float)x, (float)y,
99 getGlCompMouseType(button));
100 if (button == GLUT_LEFT_BUTTON)
102 if (button == GLUT_RIGHT_BUTTON)
104 if (button == GLUT_MIDDLE_BUTTON)
106 }
107 else
108 {
109 view->arcball->isDragging = 0;
111 (float)x, (float)y,
112 getGlCompMouseType(button));
113
114 if (button == GLUT_LEFT_BUTTON || button == GLUT_RIGHT_BUTTON ||
115 button == GLUT_MIDDLE_BUTTON)
116 appmouse_up(view, x, y);
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
140 if (view->mouse.down)
141 appmouse_drag(view, x, y);
142 begin_x = x;
143 begin_y = y;
144 cb_display();
145
146}
147
148static void cb_keyboard(unsigned char key, int x, int y)
149{
150 (void)x;
151 (void)y;
152
153 if (key==27) /*ESC*/
154 graphviz_exit(1);
155 if(key=='3')
157 if(key=='c')
159
160 if(key=='+')
162 if(key=='-')
164 if(key=='p')
166
167
169}
170
171static void cb_keyboard_up(unsigned char key, int x, int y)
172{
173 (void)key;
174 (void)x;
175 (void)y;
176
178}
179
180static void cb_special_key(int key, int x, int y)
181{
182 (void)x;
183 (void)y;
184
185 if(key==GLUT_KEY_F1)
186 {
187 printf("Currently help is not available\n");
188 }
190
191}
192
193static void cb_special_key_up(int key, int x, int y)
194{
195 (void)x;
196 (void)y;
197
198 if(key==GLUT_KEY_F1)
199 {
200 printf("Currently help is not available\n");
201 }
203
204}
205
206static void cb_game_mode(char* optArg)
207{
208
209 glutGameModeString(optArg);
210 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
211 {
212 glutEnterGameMode();
213 }
214 else
215 {
216 printf("smyrna cannot initialize requested screen resolution and rate!\n");
217 graphviz_exit(-1);
218
219 }
220}
221
222int cb_glutinit(int w, int h, int *argcp, char *argv[], char *optArg) {
223 /*
224 w,h: width and height of the window in pixels
225 argcp argv: main function's parameters, required for glutinit
226 */
227
228
229
230 glutInit(argcp,argv); //this is required by some OS.
231
232 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
233 // The Type Of Depth Testing To Do
234 glDisable(GL_DEPTH);
235 glClearDepth(1.0f); // Depth Buffer Setup
236 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
237 glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To
238 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
239
240
241 cb_game_mode(optArg);
242
243 /*register callbacks here*/
244 glutDisplayFunc(cb_display);
245 glutReshapeFunc(cb_reshape);
246 glutKeyboardFunc(cb_keyboard);
247 glutKeyboardUpFunc( cb_keyboard_up);
248 glutMouseFunc(cb_mouseclick);
249 glutMotionFunc(cb_drag);
250 glutPassiveMotionFunc(NULL);
251 glutVisibilityFunc(NULL);
252 glutEntryFunc(NULL);
253 glutSpecialFunc(cb_special_key);
254 glutSpecialUpFunc(cb_special_key_up);
255
256 //Attach extra call backs if needed in the future
257/* glutOverlayDisplayFunc
258 glutSpaceballMotionFunc
259 glutSpaceballRotateFunc
260 glutSpaceballButtonFunc
261 glutButtonBoxFunc
262 glutDialsFunc
263 glutTabletMotionFunc
264 glutTabletButtonFunc
265 glutMenuStatusFunc
266 glutIdleFunc
267 glutTimerFunc
268*/
269
270
271 //pass control to glut
272 cb_reshape(w,h);
273 glutMainLoop ();
274
275
276 return 0; //we should never reach here
277
278}
void appmouse_drag(ViewInfo *v, int x, int y)
Definition appmouse.c:97
void appmouse_key_release(ViewInfo *v)
Definition appmouse.c:132
void appmouse_move(ViewInfo *v, int x, int y)
Definition appmouse.c:128
void appmouse_key_press(ViewInfo *v, int key)
Definition appmouse.c:141
void appmouse_middle_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:120
void appmouse_left_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:104
void appmouse_right_click_down(ViewInfo *v, int x, int y)
Definition appmouse.c:112
void appmouse_up(ViewInfo *v, int x, int y)
Definition appmouse.c:86
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:247
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:153
static void cb_game_mode(char *optArg)
Definition glutrender.c:206
static float begin_x
Definition glutrender.c:21
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:180
static void cb_mouseclick(int button, int state, int x, int y)
Definition glutrender.c:90
static void cb_display(void)
Definition glutrender.c:75
static void cb_keyboard(unsigned char key, int x, int y)
Definition glutrender.c:148
static void cb_special_key_up(int key, int x, int y)
Definition glutrender.c:193
static void cb_keyboard_up(unsigned char key, int x, int y)
Definition glutrender.c:171
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:222
node NULL
Definition grammar.y:163
ViewInfo * view
Definition viewport.c:37
#define GL_VIEWPORT_FACTOR
Definition smyrnadefs.h:39
int isDragging
Definition arcball.h:554
ArcBall_t * arcball
Definition smyrnadefs.h:343
Agraph_t ** g
Definition smyrnadefs.h:296
glCompSet * widgets
Definition smyrnadefs.h:336
char * initFileName
Definition smyrnadefs.h:337
int activeGraph
Definition smyrnadefs.h:300
glCompMouse mouse
Definition smyrnadefs.h:303
glcompmouseupfunc_t mouseup
Definition glcompdefs.h:167
glcompmousedownfunc_t mousedown
Definition glcompdefs.h:166
glcompmouseoverfunc_t mouseover
Definition glcompdefs.h:163
glCompCallBacks functions
Definition glcompdefs.h:194
glCompCommon common
Definition glcompdefs.h:200
glCompObj base
Definition glcompdefs.h:258
void close_graph(ViewInfo *vi)
Definition viewport.c:71
int add_graph_to_viewport_from_file(char *fileName)
Definition viewport.c:364