FreeWRL/FreeX3D  3.0.0
statusbar.c
1 /*
2 
3 */
4 
5 /****************************************************************************
6  This file is part of the FreeWRL/FreeX3D Distribution.
7 
8  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
9 
10  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
22 ****************************************************************************/
23 
24 
25 #include <config.h>
26 #include <system.h>
27 #include <display.h>
28 #include <internal.h>
29 
30 #include <libFreeWRL.h>
31 #include <list.h>
32 #include <io_files.h>
33 
34 #include "../vrml_parser/Structs.h"
35 #include "../opengl/OpenGL_Utils.h"
36 #include "../main/headers.h"
37 #include "../vrml_parser/CParseGeneral.h"
38 #include "../scenegraph/Vector.h"
39 #include "../vrml_parser/CFieldDecls.h"
40 #include "../vrml_parser/CParseParser.h"
41 #include "../vrml_parser/CParseLexer.h"
42 #include "../vrml_parser/CParse.h"
43 
44 #include <float.h>
45 
46 #include "../x3d_parser/Bindable.h"
47 #include "../scenegraph/Collision.h"
48 #include "../scenegraph/quaternion.h"
49 #include "../scenegraph/Viewer.h"
50 
51 #include "../opengl/RasterFont.h"
52 
53 // OLD_IPHONE_AQUA #if !defined(AQUA)
54 
55 #define DJ_KEEP_COMPILER_WARNING 0
56 
57 #define MAX_BUFFER_SIZE 4096
58 static char buffer[MAX_BUFFER_SIZE] = "\0";
59 void render_init(void);
60 
61 #if DJ_KEEP_COMPILER_WARNING
62 #define STATUS_LEN 2000
63 #endif
64 
65 typedef struct pstatusbar{
66  int initDone;
67  int screenWidth, screenHeight;
68  double screenRatio;
69 }* ppstatusbar;
70 
71 void *statusbar_constructor(){
72  void *v = MALLOC(struct pstatusbar *, sizeof(struct pstatusbar));
73  memset(v,0,sizeof(struct pstatusbar));
74  return v;
75 }
76 void statusbar_init(struct tstatusbar *t){
77  //public
78  //private
79  t->prv = statusbar_constructor();
80  {
81  ppstatusbar p = (ppstatusbar)t->prv;
82  p->initDone = FALSE;
83  p->screenHeight = 200;
84  p->screenWidth = 300;
85  p->screenRatio = 1.5;
86 
87  }
88 }
89 //ppstatusbar p = (ppstatusbar)gglobal()->statusbar.prv;
90 
91 #ifdef OLDCODE //statusbar polls Model
92 /* make sure that on a re-load that we re-init */
93 void kill_status (void) {
94  /* hopefully, by this time, rendering has been stopped */
95 }
96 
97 
98 /* trigger a update */
99 void update_status(char* msg)
100 {
101  if (!msg) {
102  buffer[0] = '\0';
103  } else {
104  strncpy(buffer, msg, MAX_BUFFER_SIZE);
105  }
106 }
107 
108 char *get_status(){
109  return buffer;
110 }
111 
112 
113 void hudSetConsoleMessage(char *buffer){}
114 void handleButtonOver(){}
115 void handleOptionPress(){}
116 void handleButtonPress(){}
117 
118 void setMenuButton_collision(int val){}
119 void setMenuButton_texSize(int size){}
120 void setMenuButton_headlight(int val){}
121 void setMenuButton_navModes(int type){}
122 
123 
124 int handleStatusbarHud(int mev, int* clipplane)
125 { return 0; }
126 #endif
127 
128 void statusbar_set_window_size(int width, int height)
129 {
130  ttglobal tg = gglobal();
131  ppstatusbar p = (ppstatusbar)tg->statusbar.prv;
132  p->screenHeight = height;
133  p->screenWidth = width;
134  p->screenRatio = 1.5;
135  if (height != 0)
136  p->screenRatio = (double)width / (double)height;
137  else
138  p->screenRatio = 1.5;
139 
140  fwl_setScreenDim(width, height);
141 }
142 void statusbar_handle_mouse(int mev, int butnum, int mouseX, int mouseY)
143 {
144  //ttglobal tg = gglobal();
145  //ppstatusbar p = (ppstatusbar)tg->statusbar.prv;
146  //if (!handleStatusbarHud(mev, butnum, mouseX, mouseY, &p->clipPlane))
147  fwl_handle_aqua(mev, butnum, mouseX, mouseY); /* ,gcWheelDelta); */
148 }
149 
150 void setup_projection(int pick, int x, int y)
151 {
152  ttglobal tg = gglobal();
153  GLsizei screenwidth2 = tg->display.screenWidth;
154  GLDOUBLE aspect2 = tg->display.screenRatio;
155  //Unused? GLint xvp = 0;
156  if(Viewer()->sidebyside)
157  {
158  screenwidth2 = (int)((screenwidth2 * .5)+.5);
159  aspect2 = aspect2 * .5;
160  // Unused? if(Viewer()->iside == 1) xvp = (GLint)screenwidth2;
161  }
162 
163  FW_GL_MATRIX_MODE(GL_PROJECTION);
164  FW_GL_VIEWPORT(0,0,screenwidth2,tg->display.screenHeight);
165  FW_GL_LOAD_IDENTITY();
166 
167  /* bounds check */
168  if ((Viewer()->fieldofview <= 0.0) || (Viewer()->fieldofview > 180.0)) Viewer()->fieldofview=45.0;
169  /* glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); */
170  FW_GLU_PERSPECTIVE(Viewer()->fieldofview, aspect2, Viewer()->nearPlane, Viewer()->farPlane);
171 
172  FW_GL_MATRIX_MODE(GL_MODELVIEW);
173  PRINT_GL_ERROR_IF_ANY("XEvents::setup_projection");
174 }
175 
180 void drawStatusBar()
181 {
182  // DJ
183  if(1) {
184  if(buffer[0] != '\0') {
185  printf("%s:%d drawStatusBar NON-FUNCTIONAL %s\n",__FILE__,__LINE__,buffer);
186  buffer[0] = '\0';
187  }
188  } else {
189  #if !(defined(_ANDROID))
190  ttglobal tg = gglobal();
191  /* dont do this if we can not display; note that when we start, we can send along
192  invalid data to the OpenGL drivers when doing ortho calcs */
193  if ((tg->display.screenWidth > 5) && (tg->display.screenHeight > 5)) {
194  /* update fps message (maybe extend this with other "text widgets" */
195 
196  rf_xfont_set_color(xf_white);
197  rf_layer2D();
198 
199  rf_printf(15, 15, buffer);
200  rf_leave_layer2D();
201  }
202 #endif
203  }
204 }
205 
206 // OLD_IPHONE_AQUA #endif //AQUA