source: trunk/src/testing/src/overlayApp.cpp @ 4

Revision 4, 13.2 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/******************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 *
4 * Module: overlayApp.cpp
5 * Author : Ratko Jagodic
6 *
7 * Copyright (C) 2004 Electronic Visualization Laboratory,
8 * University of Illinois at Chicago
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 *  * Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 *  * Redistributions in binary form must reproduce the above
18 *    copyright notice, this list of conditions and the following disclaimer
19 *    in the documentation and/or other materials provided with the distribution.
20 *  * Neither the name of the University of Illinois at Chicago nor
21 *    the names of its contributors may be used to endorse or promote
22 *    products derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or
37 * http://www.evl.uic.edu/cavern/forum/
38 *
39 *****************************************************************************/
40
41#include "overlayApp.h"
42
43
44// custom messages for the appOverlay
45#define RESET  0
46#define DRAG   1
47#define RESIZE 2
48#define Z_CHANGE 3
49#define ON_CORNER 4
50#define ON_APP 5
51#define ROTATE 6
52
53#define SPECIAL_DEVICE 100
54
55
56// STATES for drawing pointers
57#define NORMAL_STATE 10
58#define DRAG_STATE   11
59#define RESIZE_STATE 12
60
61
62// areas
63#define BOTTOM       0
64#define TOP          1
65#define BOTTOM_LEFT  3
66#define TOP_LEFT     4
67#define TOP_RIGHT    5
68#define BOTTOM_RIGHT 6
69
70
71// boundaries
72#define L 0
73#define R 1
74#define T 2
75#define B 3
76
77
78overlayApp::overlayApp()
79{
80   state = NORMAL_STATE;
81   aspectRatio = 1;
82   z = 0;
83   cornerSize = 250;
84
85   for(int i=0; i<7; i++)
86      activeCorners[i] = 0;
87
88   outline[L] = 0.0;
89   outline[R] = 100.0;
90   outline[T] = 100.0;
91   outline[B] = 0.0;
92
93   border_color[0] = 1.0;
94   border_color[1] = 1.0;
95   border_color[2] = 1.0;
96   border_color[3] = 1.0;
97
98   corner_color[0] = 1.0;//0.059;
99   corner_color[1] = 1.0;//0.57;
100   corner_color[2] = 1.0;//0.345;
101   corner_color[3] = 0.3;
102
103   color = border_color;
104
105   specialDevice = false;
106}
107
108
109
110int overlayApp::init(char *name)
111{
112   setName(name);
113   return 0;
114}
115
116
117
118int overlayApp::draw()
119{
120   glDisable(GL_TEXTURE_2D);
121   glEnable(GL_DEPTH_TEST);
122   glEnable(GL_BLEND);
123   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
124   glPushMatrix();
125
126   //fprintf(stderr, "\nDRAWING AT: %f %f %f %f", outline[L], outline[R], outline[T], outline[B]);
127
128   /**********    DRAW THE STUFF   ***********/
129   if (state == NORMAL_STATE)
130   {
131      drawOutline();
132
133      glEnable(GL_LINE_STIPPLE);
134      glLineStipple(8, 21845);
135
136      if (!specialDevice){
137                  drawCorners();
138                  drawTop();
139      }
140
141      glDisable(GL_LINE_STIPPLE);
142   }
143   else if (state == DRAG_STATE || state == RESIZE_STATE)
144   {
145          if (!specialDevice){
146                  glEnable(GL_LINE_STIPPLE);
147                  glLineStipple(8, 21845);
148                  drawOutline();
149                  drawCorners();
150                  drawTop();
151                  glDisable(GL_LINE_STIPPLE);
152          } else {
153                  drawOutline();
154      }
155
156
157   }
158
159   glPopMatrix();
160   glDisable(GL_BLEND);
161   glDisable(GL_DEPTH_TEST);
162   glEnable(GL_TEXTURE_2D);
163
164   return 0;
165}
166
167void overlayApp::drawOutline()
168{
169   // draw the outline of the app we are resizing
170
171   if (specialDevice){
172           glColor4f(0.0,0.0,0.6,color[3] * 3);
173           glLineWidth(10);
174           glBegin(GL_LINE_LOOP);
175                  glVertex3f(outline[L], outline[B], z);
176                  glVertex3f(outline[L], outline[T], z);
177                  glVertex3f(outline[R], outline[T], z);
178                  glVertex3f(outline[R], outline[B], z);
179           glEnd();
180           glColor4f(color[0], color[1], color[2], color[3]);
181           glBegin(GL_QUADS);
182                  glVertex3f(outline[L], outline[B], z);
183                  glVertex3f(outline[L], outline[T], z);
184                  glVertex3f(outline[R], outline[T], z);
185                  glVertex3f(outline[R], outline[B], z);
186           glEnd();
187   } else {
188           glBegin(GL_LINE_LOOP);
189                  glVertex3f(outline[L], outline[B], z);
190                  glVertex3f(outline[L], outline[T], z);
191                  glVertex3f(outline[R], outline[T], z);
192                  glVertex3f(outline[R], outline[B], z);
193           glEnd();
194   }
195}
196
197
198void overlayApp::drawCorners()
199{
200   glLineWidth(2);
201
202
203   // top_left
204   if(activeCorners[TOP_LEFT] == 1)
205   {
206      glBegin(GL_LINE_STRIP);
207         glVertex3f(outline[L], outline[T]-cornerSize, z);
208         glVertex3f(outline[L]+cornerSize, outline[T]-cornerSize, z);
209         glVertex3f(outline[L]+cornerSize, outline[T], z);
210      glEnd();
211
212      glColor4f(corner_color[0], corner_color[1],
213         corner_color[2], corner_color[3]);
214      glBegin(GL_POLYGON);
215         glVertex3f(outline[L], outline[T]-cornerSize, z+0.05);
216         glVertex3f(outline[L]+cornerSize, outline[T]-cornerSize, z+0.05);
217         glVertex3f(outline[L]+cornerSize, outline[T], z+0.05);
218         glVertex3f(outline[L], outline[T], z+0.05);
219         glVertex3f(outline[L], outline[T]-cornerSize, z+0.05);
220      glEnd();
221   }
222
223   // top_right
224   if(activeCorners[TOP_RIGHT] == 1)
225   {
226      glBegin(GL_LINE_STRIP);
227         glVertex3f(outline[R]-cornerSize, outline[T], z);
228         glVertex3f(outline[R]-cornerSize, outline[T]-cornerSize, z);
229         glVertex3f(outline[R], outline[T]-cornerSize, z);
230      glEnd();
231
232      glColor4f(corner_color[0], corner_color[1],
233         corner_color[2], corner_color[3]);
234      glBegin(GL_POLYGON);
235         glVertex3f(outline[R]-cornerSize, outline[T], z+0.05);
236         glVertex3f(outline[R]-cornerSize, outline[T]-cornerSize, z+0.05);
237         glVertex3f(outline[R], outline[T]-cornerSize, z+0.05);
238         glVertex3f(outline[R], outline[T], z+0.05);
239         glVertex3f(outline[R]-cornerSize, outline[T], z+0.05);
240      glEnd();
241   }
242
243   // bottom_right
244   if(activeCorners[BOTTOM_RIGHT] == 1)
245   {
246      glColor4f(color[0], color[1], color[2], 0.5);
247      glBegin(GL_LINE_STRIP);
248         glVertex3f(outline[R]-cornerSize, outline[B], z);
249         glVertex3f(outline[R]-cornerSize, outline[B]+cornerSize, z);
250         glVertex3f(outline[R], outline[B]+cornerSize, z);
251      glEnd();
252
253      glColor4f(corner_color[0], corner_color[1],
254         corner_color[2], corner_color[3]);
255      glBegin(GL_POLYGON);
256         glVertex3f(outline[R]-cornerSize, outline[B], z+0.05);
257         glVertex3f(outline[R]-cornerSize, outline[B]+cornerSize, z+0.05);
258         glVertex3f(outline[R], outline[B]+cornerSize, z+0.05);
259         glVertex3f(outline[R], outline[B], z+0.05);
260         glVertex3f(outline[R]-cornerSize, outline[B], z+0.05);
261      glEnd();
262   }
263
264   // bottom_left
265   if(activeCorners[BOTTOM_LEFT] == 1)
266   {
267      glColor4f(color[0], color[1], color[2], 0.5);
268      glBegin(GL_LINE_STRIP);
269         glVertex3f(outline[L], outline[B]+cornerSize, z);
270         glVertex3f(outline[L]+cornerSize, outline[B]+cornerSize, z);
271         glVertex3f(outline[L]+cornerSize, outline[B], z);
272      glEnd();
273
274      glColor4f(corner_color[0], corner_color[1],
275         corner_color[2], corner_color[3]);
276      glBegin(GL_POLYGON);
277         glVertex3f(outline[L], outline[B]+cornerSize, z+0.05);
278         glVertex3f(outline[L]+cornerSize, outline[B]+cornerSize, z+0.05);
279         glVertex3f(outline[L]+cornerSize, outline[B], z+0.05);
280         glVertex3f(outline[L], outline[B], z+0.05);
281         glVertex3f(outline[L], outline[B]+cornerSize, z+0.05);
282      glEnd();
283   }
284}
285
286
287
288void overlayApp::drawTop()
289{
290   glColor4f(color[0], color[1], color[2], 0.5);
291   glLineWidth(2);
292
293   if(activeCorners[TOP] == 1)
294   {
295      glBegin(GL_LINES);
296         glVertex3f(outline[L]+cornerSize, outline[T], z);
297         glVertex3f(outline[L]+cornerSize, outline[T]-cornerSize, z);
298
299         glVertex3f(outline[L]+cornerSize, outline[T]-cornerSize, z);
300         glVertex3f(outline[R]-cornerSize, outline[T]-cornerSize, z);
301
302         glVertex3f(outline[R]-cornerSize, outline[T], z);
303         glVertex3f(outline[R]-cornerSize, outline[T]-cornerSize, z);
304      glEnd();
305
306
307      glColor4f(corner_color[0], corner_color[1],
308         corner_color[2], corner_color[3]);
309      glBegin(GL_POLYGON);
310         glVertex3f(outline[L]+cornerSize, outline[T], z+0.05);
311         glVertex3f(outline[L]+cornerSize, outline[T]-cornerSize, z+0.05);
312         glVertex3f(outline[R]-cornerSize, outline[T]-cornerSize, z+0.05);
313         glVertex3f(outline[R]-cornerSize, outline[T], z+0.05);
314         glVertex3f(outline[L]+cornerSize, outline[T], z+0.05);
315      glEnd();
316   }
317
318   if(activeCorners[BOTTOM] == 1)
319   {
320      glBegin(GL_LINES);
321         glVertex3f(outline[L]+cornerSize, outline[B], z);
322         glVertex3f(outline[L]+cornerSize, outline[B]+cornerSize, z);
323
324         glVertex3f(outline[L]+cornerSize, outline[B]+cornerSize, z);
325         glVertex3f(outline[R]-cornerSize, outline[B]+cornerSize, z);
326
327         glVertex3f(outline[R]-cornerSize, outline[B]+cornerSize, z);
328         glVertex3f(outline[R]-cornerSize, outline[B], z);
329      glEnd();
330
331
332      glColor4f(corner_color[0], corner_color[1],
333         corner_color[2], corner_color[3]);
334      glBegin(GL_POLYGON);
335         glVertex3f(outline[L]+cornerSize, outline[B], z+0.05);
336         glVertex3f(outline[L]+cornerSize, outline[B]+cornerSize, z+0.05);
337         glVertex3f(outline[R]-cornerSize, outline[B]+cornerSize, z+0.05);
338         glVertex3f(outline[R]-cornerSize, outline[B], z+0.05);
339         glVertex3f(outline[L]+cornerSize, outline[B], z+0.05);
340      glEnd();
341   }
342}
343
344
345
346
347int overlayApp::destroy()
348{
349   return 0;
350}
351
352
353
354int overlayApp::parseMessage(char *msg)
355{
356   int id, code;
357   sscanf(msg, "%d %d", &id, &code);
358
359   switch(code)
360   {
361      case DRAG: {
362         int dx, dy, cId;
363         sscanf(msg, "%d %d %d %d %d", &id, &code, &dx, &dy, &cId);
364         cId += 2;  // the corners in the interaction manager are smaller by 2
365         outline[L] += dx;
366         outline[R] += dx;
367         outline[T] += dy;
368         outline[B] += dy;
369         state = DRAG_STATE;
370         activeCorners[cId] = 1;
371         //fprintf(stderr, "\nDRAG (%d): %.1f %.1f %.1f %.1f", objectID, outline[L], outline[R], outline[T], outline[B]);
372         break;
373      }
374      case RESIZE: {
375         int dx,dy,cId;
376         state = RESIZE_STATE;
377         sscanf(msg, "%d %d %d %d %d", &id, &code, &dx, &dy, &cId);
378         cId += 2;  // the corners in the interaction manager are smaller by 2
379         if (cId == BOTTOM_LEFT)
380         {
381            outline[L] += dx;
382            outline[B] += dx/aspectRatio;
383         }
384         else if(cId == TOP_LEFT)
385         {
386            outline[L] += dx;
387            outline[T] -= dx/aspectRatio;
388         }
389         else if(cId == TOP_RIGHT)
390         {
391            outline[R] += dx;
392            outline[T] += dx/aspectRatio;
393         }
394         else if(cId == BOTTOM_RIGHT)
395         {
396            outline[R] += dx;
397            outline[B] -= dx/aspectRatio;
398         }
399         //fprintf(stderr, "\nRESIZE (%d): %.1f %.1f %.1f %.1f", objectID, outline[L], outline[R], outline[T], outline[B]);
400         activeCorners[cId] = 1;
401         break;
402      }
403      case RESET: {
404         int l,r,t,b,appZ,cs,dispId;
405         state = NORMAL_STATE;
406         sscanf(msg, "%d %d %d %d %d %d %d %d %d", &id, &code, &l, &r, &t, &b, &appZ, &cs, &dispId);
407         outline[L] = l;
408         outline[R] = r;
409         outline[T] = t;
410         outline[B] = b;
411         aspectRatio = (r-l)/float(t-b);
412         cornerSize = cs;
413         displayID = dispId;
414         color = border_color;
415         for(int i=0; i<7; i++)
416            activeCorners[i] = 0;
417         z = -(appZ + 0.1);  // negative cause sage does it this way...
418
419         //fprintf(stderr, "\nRESET (%d): %f %d %d %d %d %f", objectID, aspectRatio, l, r, t, b, z);
420         break;
421      }
422      case Z_CHANGE:{
423         int appZ;
424         sscanf(msg, "%d %d %d", &id, &code, &appZ);
425         z = -(appZ + 0.1);  // negative cause sage does it this way...
426         break;
427      }
428      case ON_CORNER: {
429         int cId, isOn;
430         sscanf(msg, "%d %d %d %d", &id, &code, &cId, &isOn);
431         cId += 2;  // the corners in the interaction manager are smaller by 2
432         activeCorners[cId] = isOn;
433         break;
434      }
435      case ON_APP: {
436                if (specialDevice){
437                        int isOn;
438                        sscanf(msg, "%d %d %d", &id, &code, &isOn);
439                        if (isOn == 0)
440                                border_color[3] = 0.0;
441                        else if (isOn == 1)
442                                border_color[3] = 0.3;
443                        break;
444                }
445      }
446      case SPECIAL_DEVICE: {
447                int isSpecial;
448                sscanf(msg, "%d %d %d", &id, &code, &isSpecial);
449                if (isSpecial == 0){
450                        specialDevice = false;
451                        border_color[3] = 1.0;
452                } else if (isSpecial == 1) {
453                        specialDevice = true;
454                        border_color[0] = 0.5;
455                        border_color[1] = 0.5;
456                        border_color[2] = 1.0;
457                        border_color[3] = 0.0;
458                }
459                break;
460      }
461   }
462
463   return 0;
464
465}
466
467
468
469
470
471
472
473
Note: See TracBrowser for help on using the repository browser.