26#include <libFreeWRL.h>
28#include "../ui/common.h"
29#include <scenegraph/Vector.h>
32#if defined (_MSC_VER) || defined (AQUA) || defined(QNX) || defined(_ANDROID) || defined(ANDROIDNDK)
33#include "../../buildversion.h"
42#if defined (_MSC_VER) || defined (AQUA) || defined(QNX) || defined(_ANDROID) || defined(ANDROIDNDK)
43const char *libFreeWRL_get_version(
void) {
return FW_BUILD_VERSION_STR;}
61 int target_frames_per_second;
62 char myMenuStatus[MAXSTAT];
63 char messagebar[MAXSTAT];
66 char window_title[MAXTITLE];
74 int colorSchemeChanged;
85 int draw_bounding_boxes;
87void *common_constructor(){
88 void *v = MALLOCV(
sizeof(
struct pcommon));
89 memset(v,0,
sizeof(
struct pcommon));
92void common_init(
struct tcommon *t){
95 t->prv = common_constructor();
99 p->myFps = (float) 0.0;
100 p->cursorStyle = ACURSE;
101 p->sb_hasString = FALSE;
102 p->colorScheme = NULL;
103 p->colorSchemeChanged = 0;
104 p->pin_statusbar = 1;
107 p->want_statusbar = 1;
109 p->showConsoleText = 0;
110 p->target_frames_per_second = 120;
111 p->density_factor = 1.0f;
114 p->jsengine = JSENGINE_STUB;
116 p->jsengine = JSENGINE_DUK;
119 p->jsengine = JSENGINE_SM;
120 p->jsengine_variant = 2;
121#ifdef JAVASCRIPT_ENGINE_VARIANT
122 p->jsengine_variant = JAVASCRIPT_ENGINE_VARIANT;
124 p->draw_bounding_boxes = FALSE;
128void common_clear(
struct tcommon *t){
135 for(i=0;i<vectorSize(p->keyvals);i++){
140 deleteVector(
keyval,p->keyvals);
147void fwl_setTrap(
int k){
156void fwl_setJsEngine(
char *optarg){
158 int engine, engine_variant, ivalid;
164 if(strlen(optarg) >= 2 && (!strncmp(optarg,
"SM",2) || !strncmp(optarg,
"sm",2))){
167 engine = JSENGINE_SM;
168 if(strlen(optarg) >= 3){
169 if(optarg[2] ==
'2') engine_variant = 2;
170 if(optarg[2] ==
'1') engine_variant = 1;
173 ConsoleMessage(
"not built with spidermonkey js engine\n");
176 if(!strcmp(optarg,
"DUK") || !strcmp(optarg,
"duk")){
178 #ifdef JAVASCRIPT_DUK
179 engine = JSENGINE_DUK;
181 ConsoleMessage(
"not built with duktape js engine\n");
184 if(!strcmp(optarg,
"NONE") || !strcmp(optarg,
"none")){
186 engine = JSENGINE_STUB;
189 static char *engine_names [] = {
"NONE",
"DUK",
"SM"};
190 ConsoleMessage(
"could not do js preference %s, trying %s\n",optarg,engine_names[p->jsengine]);
193 ConsoleMessage(
"invalid --javascript / -J otpion, should be SM, DUK or NONE\n");
195 if(ivalid && engine > -1){
196 p->jsengine = engine;
197 if(engine_variant > -1) p->jsengine_variant = engine_variant;
204int getJsEngineVariant(){
206 return p->jsengine_variant;
210void setMenuFps(
float fps)
218void kill_status(
void) {
222 p->sb_hasString = FALSE;
226void showConsoleText(
int on){
228 p->showConsoleText = on;
230int getShowConsoleText(){
232 return p->showConsoleText;
235void update_status(
char* msg) {
239 p->sb_hasString = FALSE;
243 p->sb_hasString = TRUE;
244 strcpy(p->buffer, msg);
251void setMenuStatus3(
char* status3)
258 snprintf(p->myMenuStatus, MAXSTAT-1,
"%s", pp);
260void setMenuStatus(
char *stattext)
262 setMenuStatus3(stattext);
264void setMenuStatusVP(
char *stattext)
266 setMenuStatus3(stattext);
270 return ((
ppcommon)gglobal()->common.prv)->myMenuStatus;
275void setWindowTitle0()
279 snprintf(p->window_title,
sizeof(p->window_title),
"FreeWRL");
282char *getWindowTitle()
285 return p->window_title;
293 snprintf(p->messagebar, MAXSTAT-1,
"%s", p->myMenuStatus);
298 return p->messagebar;
300double get_viewer_dist();
303 snprintf(p->distbar, 10,
"D%8f", (
float)get_viewer_dist());
315 snprintf(p->fpsbar, 10,
"%4d", (
int)(p->myFps + .49999f));
317static int frontend_using_cursor = 0;
318void fwl_set_frontend_using_cursor(
int on)
322 frontend_using_cursor = on;
328 p->cursorStyle = ACURSE;
330void setLookatCursor()
333 p->cursorStyle = SCURSE;
336void setSensorCursor()
339 p->cursorStyle = SCURSE;
345 if (!frontend_using_cursor)
346 return p->cursorStyle;
351int fwl_set_sbh_pin_option(
char *optarg){
352 if(optarg && strlen(optarg) > 1){
354 p->pin_statusbar = (optarg[0] ==
'T' || optarg[0] ==
't') ? 1 : 0;
355 p->pin_menubar = (optarg[1] ==
'T' || optarg[1] ==
't') ? 1 : 0;
359int fwl_set_sbh_want_option(
char *optarg){
360 if(optarg && strlen(optarg) > 1){
362 p->want_statusbar = (optarg[0] ==
'T' || optarg[0] ==
't') ? 1 : 0;
363 p->want_menubar = (optarg[1] ==
'T' || optarg[1] ==
't') ? 1 : 0;
368void fwl_set_sbh_pin(
int sb,
int mb){
370 p->pin_statusbar = sb;
373void fwl_get_sbh_pin(
int *sb,
int *mb){
375 *sb = p->pin_statusbar;
376 *mb = p->pin_menubar;
378void fwl_set_sbh_wantMenubar(
int want){
380 p->want_menubar = want ? 1 : 0;
382int fwl_get_sbh_wantMenubar(){
384 return p->want_menubar;
386void fwl_set_sbh_wantStatusbar(
int want){
388 p->want_statusbar = want ? 1 : 0;
390int fwl_get_sbh_wantStatusbar(){
392 return p->want_statusbar;
395void fwl_set_target_fps(
int target_fps){
397 p->target_frames_per_second = max(1,target_fps);
399int fwl_get_target_fps(){
401 return p->target_frames_per_second;
485{NULL,NULL,NULL,NULL},
488void color_html2rgb(
char *html,
float *rgb){
495 if(shex[0] ==
'#') shex = &shex[1];
496 ic = strtol(shex,NULL,16);
498 ig = (ic & 0xFF00) >> 8;
499 ir = (ic & 0xFF0000) >> 16;
500 rgb[0] = (float)ir/255.0f;
501 rgb[1] = (float)ig/255.0f;
502 rgb[2] = (float)ib/255.0f;
504char *hexpermitted =
" #0123456789ABCDEFabcdef";
515int colorsoption2colorscheme(
const char *optionstring,
colorScheme *cs){
521 char *str, *html, *stok;
522 len = strlen(optionstring);
524 strcpy(str,optionstring);
527 if(!strchr(hexpermitted,str[i])){
535 html = strtok(stok,
" ");
537 if(cs->menuIcon) html = cs->menuIcon;
538 else html =
"#FFFFFF";
541 case 0: cs->panel = strdup(html);
break;
542 case 1: cs->menuIcon = strdup(html);
break;
543 case 2: cs->statusText = strdup(html);
break;
544 case 3: cs->messageText = strdup(html);
break;
554colorScheme *search_ui_colorscheme(
char *colorschemename){
559 if(!strcmp(colorSchemes[i].name,colorschemename)){
560 cs = &colorSchemes[i];
564 }
while(colorSchemes[i].name);
567int fwl_set_ui_colorscheme(
char *colorschemename){
570 cs = search_ui_colorscheme(colorschemename);
573 p->colorSchemeChanged++;
581void fwl_set_ui_colors(
char *fourhtmlcolors){
584 cs = search_ui_colorscheme(
"custom");
585 colorsoption2colorscheme(fourhtmlcolors, cs);
586 p->colorScheme = (
void *)cs;
587 p->colorSchemeChanged++;
589char *fwl_get_ui_colorschemename(){
595void fwl_next_ui_colorscheme(){
598 char *colorschemename;
601 colorschemename = fwl_get_ui_colorschemename();
604 if(!strcmp(colorSchemes[i].name,colorschemename)){
605 cs = &colorSchemes[i+1];
607 cs = &colorSchemes[0];
609 if(!strcmp(cs->name,
"custom")){
610 cs = &colorSchemes[0];
612 fwl_set_ui_colorscheme(cs->name);
616 }
while(colorSchemes[i].name);
621#ifndef UI_COLORSCHEME_DEFAULT
622#define UI_COLORSCHEME_DEFAULT "neon:lime"
624void fwl_get_ui_color(
char *use,
float *rgb){
628 p->colorScheme = search_ui_colorscheme(UI_COLORSCHEME_DEFAULT);
629 p->colorSchemeChanged++;
632 if(!strcmp(use,
"panel")){
633 color_html2rgb(cs->panel, rgb);
634 }
else if(!strcmp(use,
"menuIcon")){
635 color_html2rgb(cs->menuIcon, rgb);
636 }
else if(!strcmp(use,
"statusText")){
637 color_html2rgb(cs->statusText, rgb);
638 }
else if(!strcmp(use,
"messageText")){
639 color_html2rgb(cs->messageText, rgb);
642int fwl_get_ui_color_changed(){
644 return p->colorSchemeChanged;
668#include <scenegraph/Viewer.h>
670int fwl_setDragChord(
char *chordname);
671int fwl_setKeyChord(
char *chordname);
673int fwl_keyval(
char *
key,
char *val);
675int searchkeyvals(
char *
key){
679 p->keyvals = newVector(
keyval,4);
681 for(i=0;i<vectorSize(p->keyvals);i++){
683 if(!strcmp(k_v.key,
key)){
690int set_key_val(
char *
key,
char *val){
695 index = searchkeyvals(
key);
698 p->keyvals = newVector(
keyval,4);
699 k_v.key = STRDUP(
key);
700 k_v.val = STRDUP(val);
701 vector_pushBack(
keyval,p->keyvals,k_v);
703 k_v = vector_get(
keyval,p->keyvals,index);
705 k_v.val = STRDUP(val);
706 vector_set(
keyval,p->keyvals,index,k_v);
710int set_keyval(
char *
keyval){
717 p->keyvals = newVector(
keyval,4);
726 sep = strchr(kv,
' ');
727 if(!sep) sep = strchr(kv,
',');
733 set_key_val(
key,val);
739char *get_key_val(
char *
key){
744 index = searchkeyvals(
key);
745 if(index < 0)
return NULL;
746 k_v = vector_get(
keyval,p->keyvals,index);
749int print_keyval(
char *
key){
752 index = searchkeyvals(
key);
754 ConsoleMessage(
"\n key %s not found\n",
key);
757 k_v = vector_get(
keyval,p->keyvals,index);
758 ConsoleMessage(
"\n key=%s val=%s\n",
key,k_v.val);
762int fwl_hyper_option(
char *val);
763int ssr_test(
char *
keyval);
767 int (*valfunc)(
char *val);
770 {
"dragchord",NULL,fwl_setDragChord,
"[yawz,yawpitch,roll,xy]"},
771 {
"keychord", NULL,fwl_setKeyChord,
"[yawz,yawpitch,roll,xy]"},
772 {
"navmode",NULL,fwl_setNavMode,
"[walk,fly,examine,explore,spherical,turntable,lookat]"},
773 {
"help",print_help,NULL,NULL},
774 {
"pin",NULL,fwl_set_sbh_pin_option,
"[tf,tt,ft,ff]"},
775 {
"colorscheme",NULL,fwl_set_ui_colorscheme,
"[original,midnight,angry,favicon,aqua,neon:lime,neon:yellow,neon:cyan,neon:pink]"},
776 {
"set_keyval",NULL,set_keyval,
"key,val"},
777 {
"print_keyval",NULL,print_keyval,
"key"},
778 {
"hyper_option",NULL,fwl_hyper_option,
"[0 - 10]"},
780 {
"ssrtest",NULL,ssr_test,
"nav,val"},
782 {
"",print_help,NULL,NULL},
787 ConsoleMessage(
"\n%s\n",
"spacebar commands: spacebar:key[,val]Enter");
789 while(commands[i].
key){
790 if(commands[i].helpstring)
791 ConsoleMessage(
" %s,%s\n",commands[i].
key,commands[i].helpstring);
793 ConsoleMessage(
" %s\n",commands[i].
key);
803 while(commands[i].
key){
804 if(!strcmp(
key,commands[i].
key)){
812int fwl_keyval(
char *
key,
char *val){
815 cmd = getCommand(
key);
818 ok = cmd->valfunc(val);
822int fwl_command(
char *
key){
825 cmd = getCommand(
key);
832int fwl_commandline(
char *cmdline){
833 char *sep = strchr(cmdline,
' ');
834 if(!sep) sep = strchr(cmdline,
',');
838 val = strdup(&sep[1]);
839 keylen = (int)(sep - cmdline);
841 key = strndup(cmdline,keylen +1);
849 fwl_command(cmdline);
856void fwl_setDensityFactor(
float density_factor){
863 p->density_factor = density_factor;
865float fwl_getDensityFactor(){
867 return p->density_factor;
873void fwl_setPedal(
int pedal){
881void fwl_setHover(
int hover){
885void fwl_setDrawBoundingBoxes(
int drawbb){
887 p->draw_bounding_boxes = drawbb;
889int fwl_getDrawBoundingBoxes(){
891 return p->draw_bounding_boxes;