26 #include <libFreeWRL.h>
28 #include "../ui/common.h"
29 #include <scenegraph/Vector.h>
32 #if defined (_MSC_VER) || defined(QNX) || defined(_ANDROID) || defined(ANDROIDNDK)
33 #include "../../buildversion.h"
42 #if defined (_MSC_VER) || defined(QNX) || defined(_ANDROID) || defined(ANDROIDNDK)
43 const char *libFreeWRL_get_version(
void) {
return FW_BUILD_VERSION_STR;}
60 int target_frames_per_second;
61 char myMenuStatus[MAXSTAT];
62 char messagebar[MAXSTAT];
65 char window_title[MAXTITLE];
73 int colorSchemeChanged;
83 void *common_constructor(){
84 void *v = MALLOCV(
sizeof(
struct pcommon));
85 memset(v,0,
sizeof(
struct pcommon));
88 void common_init(
struct tcommon *t){
91 t->prv = common_constructor();
94 p->myFps = (
float) 0.0;
95 p->cursorStyle = ACURSE;
96 p->sb_hasString = FALSE;
97 p->colorScheme = NULL;
98 p->colorSchemeChanged = 0;
102 p->want_statusbar = 1;
104 p->showConsoleText = 0;
105 p->target_frames_per_second = 120;
106 p->density_factor = 1.0f;
111 void common_clear(
struct tcommon *t){
118 for(i=0;i<vectorSize(p->keyvals);i++){
123 deleteVector(
keyval,p->keyvals);
132 void setMenuFps(
float fps)
140 void kill_status(
void) {
144 p->sb_hasString = FALSE;
148 void showConsoleText(
int on){
150 p->showConsoleText = on;
152 int getShowConsoleText(){
154 return p->showConsoleText;
157 void update_status(
char* msg) {
161 p->sb_hasString = FALSE;
165 p->sb_hasString = TRUE;
166 strcpy(p->buffer, msg);
173 void setMenuStatus3(
char* status3)
180 snprintf(p->myMenuStatus, MAXSTAT-1,
"%s", pp);
182 void setMenuStatus(
char *stattext)
184 setMenuStatus3(stattext);
186 void setMenuStatusVP(
char *stattext)
188 setMenuStatus3(stattext);
190 char *getMenuStatus()
192 return ((
ppcommon)gglobal()->common.prv)->myMenuStatus;
197 void setWindowTitle0()
201 snprintf(p->window_title,
sizeof(p->window_title),
"FreeWRL");
204 char *getWindowTitle()
207 return p->window_title;
215 snprintf(p->messagebar, MAXSTAT-1,
"%s", p->myMenuStatus);
217 char *getMessageBar()
220 return p->messagebar;
222 double get_viewer_dist();
225 snprintf(p->distbar, 10,
"DIST %4f", (
float)get_viewer_dist());
237 snprintf(p->fpsbar, 10,
"%4d", (
int)(p->myFps + .49999f));
239 static int frontend_using_cursor = 0;
240 void fwl_set_frontend_using_cursor(
int on)
244 frontend_using_cursor = on;
247 void setArrowCursor()
250 p->cursorStyle = ACURSE;
252 void setLookatCursor()
255 p->cursorStyle = SCURSE;
258 void setSensorCursor()
261 p->cursorStyle = SCURSE;
267 if (!frontend_using_cursor)
268 return p->cursorStyle;
273 int fwl_set_sbh_pin_option(
char *optarg){
274 if(optarg && strlen(optarg) > 1){
276 p->pin_statusbar = (optarg[0] ==
'T' || optarg[0] ==
't') ? 1 : 0;
277 p->pin_menubar = (optarg[1] ==
'T' || optarg[1] ==
't') ? 1 : 0;
281 int fwl_set_sbh_want_option(
char *optarg){
282 if(optarg && strlen(optarg) > 1){
284 p->want_statusbar = (optarg[0] ==
'T' || optarg[0] ==
't') ? 1 : 0;
285 p->want_menubar = (optarg[1] ==
'T' || optarg[1] ==
't') ? 1 : 0;
290 void fwl_set_sbh_pin(
int sb,
int mb){
292 p->pin_statusbar = sb;
295 void fwl_get_sbh_pin(
int *sb,
int *mb){
297 *sb = p->pin_statusbar;
298 *mb = p->pin_menubar;
300 void fwl_set_sbh_wantMenubar(
int want){
302 p->want_menubar = want ? 1 : 0;
304 int fwl_get_sbh_wantMenubar(){
306 return p->want_menubar;
308 void fwl_set_sbh_wantStatusbar(
int want){
310 p->want_statusbar = want ? 1 : 0;
312 int fwl_get_sbh_wantStatusbar(){
314 return p->want_statusbar;
317 void fwl_set_target_fps(
int target_fps){
319 p->target_frames_per_second = max(1,target_fps);
321 int fwl_get_target_fps(){
323 return p->target_frames_per_second;
407 {NULL,NULL,NULL,NULL},
410 void color_html2rgb(
char *html,
float *rgb){
417 if(shex[0] ==
'#') shex = &shex[1];
418 ic = strtol(shex,NULL,16);
420 ig = (ic & 0xFF00) >> 8;
421 ir = (ic & 0xFF0000) >> 16;
422 rgb[0] = (float)ir/255.0f;
423 rgb[1] = (float)ig/255.0f;
424 rgb[2] = (float)ib/255.0f;
426 char *hexpermitted =
" #0123456789ABCDEFabcdef";
437 int colorsoption2colorscheme(
const char *optionstring,
colorScheme *cs){
443 char *str, *html, *stok;
444 len = strlen(optionstring);
446 strcpy(str,optionstring);
449 if(!strchr(hexpermitted,str[i])){
457 html = strtok(stok,
" ");
459 if(cs->menuIcon) html = cs->menuIcon;
460 else html =
"#FFFFFF";
463 case 0: cs->panel = strdup(html);
break;
464 case 1: cs->menuIcon = strdup(html);
break;
465 case 2: cs->statusText = strdup(html);
break;
466 case 3: cs->messageText = strdup(html);
break;
476 colorScheme *search_ui_colorscheme(
char *colorschemename){
481 if(!strcmp(colorSchemes[i].name,colorschemename)){
482 cs = &colorSchemes[i];
486 }
while(colorSchemes[i].name);
489 int fwl_set_ui_colorscheme(
char *colorschemename){
492 cs = search_ui_colorscheme(colorschemename);
495 p->colorSchemeChanged++;
503 void fwl_set_ui_colors(
char *fourhtmlcolors){
506 cs = search_ui_colorscheme(
"custom");
507 colorsoption2colorscheme(fourhtmlcolors, cs);
508 p->colorScheme = (
void *)cs;
509 p->colorSchemeChanged++;
511 char *fwl_get_ui_colorschemename(){
517 void fwl_next_ui_colorscheme(){
520 char *colorschemename;
523 colorschemename = fwl_get_ui_colorschemename();
526 if(!strcmp(colorSchemes[i].name,colorschemename)){
527 cs = &colorSchemes[i+1];
529 cs = &colorSchemes[0];
531 if(!strcmp(cs->name,
"custom")){
532 cs = &colorSchemes[0];
534 fwl_set_ui_colorscheme(cs->name);
538 }
while(colorSchemes[i].name);
543 #ifndef UI_COLORSCHEME_DEFAULT
544 #define UI_COLORSCHEME_DEFAULT "neon:lime" //"original" "favicon" "midnight" "aqua" "angry" "neon:cyan" "neon:yellow" "neon:lime" "neon:pink"
546 void fwl_get_ui_color(
char *use,
float *rgb){
550 p->colorScheme = search_ui_colorscheme(UI_COLORSCHEME_DEFAULT);
551 p->colorSchemeChanged++;
554 if(!strcmp(use,
"panel")){
555 color_html2rgb(cs->panel, rgb);
556 }
else if(!strcmp(use,
"menuIcon")){
557 color_html2rgb(cs->menuIcon, rgb);
558 }
else if(!strcmp(use,
"statusText")){
559 color_html2rgb(cs->statusText, rgb);
560 }
else if(!strcmp(use,
"messageText")){
561 color_html2rgb(cs->messageText, rgb);
564 int fwl_get_ui_color_changed(){
566 return p->colorSchemeChanged;
590 #include <scenegraph/Viewer.h>
592 int fwl_setDragChord(
char *chordname);
593 int fwl_setKeyChord(
char *chordname);
595 int fwl_keyval(
char *
key,
char *val);
597 int searchkeyvals(
char *
key){
601 p->keyvals = newVector(
keyval,4);
603 for(i=0;i<vectorSize(p->keyvals);i++){
605 if(!strcmp(k_v.key,key)){
612 int set_key_val(
char *key,
char *val){
617 index = searchkeyvals(key);
620 p->keyvals = newVector(
keyval,4);
621 k_v.key = STRDUP(key);
622 k_v.val = STRDUP(val);
623 vector_pushBack(
keyval,p->keyvals,k_v);
625 k_v = vector_get(
keyval,p->keyvals,index);
627 k_v.val = STRDUP(val);
628 vector_set(
keyval,p->keyvals,index,k_v);
632 int set_keyval(
char *
keyval){
639 p->keyvals = newVector(keyval,4);
648 sep = strchr(kv,
' ');
649 if(!sep) sep = strchr(kv,
',');
655 set_key_val(key,val);
661 char *get_key_val(
char *key){
666 index = searchkeyvals(key);
667 if(index < 0)
return NULL;
668 k_v = vector_get(keyval,p->keyvals,index);
671 int print_keyval(
char *key){
674 index = searchkeyvals(key);
676 ConsoleMessage(
"\n key %s not found\n",key);
679 k_v = vector_get(keyval,p->keyvals,index);
680 ConsoleMessage(
"\n key=%s val=%s\n",key,k_v.val);
684 int fwl_hyper_option(
char *val);
685 int ssr_test(
char *keyval);
689 int (*valfunc)(
char *val);
692 {
"dragchord",NULL,fwl_setDragChord,
"[yawz,yawpitch,roll,xy]"},
693 {
"keychord", NULL,fwl_setKeyChord,
"[yawz,yawpitch,roll,xy]"},
694 {
"navmode",NULL,fwl_setNavMode,
"[walk,fly,examine,explore,spherical,turntable,lookat]"},
695 {
"help",print_help,NULL,NULL},
696 {
"pin",NULL,fwl_set_sbh_pin_option,
"[tf,tt,ft,ff]"},
697 {
"colorscheme",NULL,fwl_set_ui_colorscheme,
"[original,midnight,angry,favicon,aqua,neon:lime,neon:yellow,neon:cyan,neon:pink]"},
698 {
"set_keyval",NULL,set_keyval,
"key,val"},
699 {
"print_keyval",NULL,print_keyval,
"key"},
700 {
"hyper_option",NULL,fwl_hyper_option,
"[0 - 10]"},
702 {
"ssrtest",NULL,ssr_test,
"nav,val"},
704 {
"",print_help,NULL,NULL},
709 ConsoleMessage(
"\n%s\n",
"spacebar commands: spacebar:key[,val]Enter");
711 while(commands[i].key){
712 if(commands[i].helpstring)
713 ConsoleMessage(
" %s,%s\n",commands[i].key,commands[i].helpstring);
715 ConsoleMessage(
" %s\n",commands[i].key);
720 struct command *getCommand(
char *key){
725 while(commands[i].key){
726 if(!strcmp(key,commands[i].key)){
734 int fwl_keyval(
char *key,
char *val){
737 cmd = getCommand(key);
740 ok = cmd->valfunc(val);
744 int fwl_command(
char *key){
747 cmd = getCommand(key);
754 int fwl_commandline(
char *cmdline){
755 char *sep = strchr(cmdline,
' ');
756 if(!sep) sep = strchr(cmdline,
',');
760 val = strdup(&sep[1]);
761 keylen = (int)(sep - cmdline);
763 key = strndup(cmdline,keylen +1);
771 fwl_command(cmdline);
778 void fwl_setDensityFactor(
float density_factor){
785 p->density_factor = density_factor;
787 float fwl_getDensityFactor(){
789 return p->density_factor;
795 void fwl_setPedal(
int pedal){
803 void fwl_setHover(
int hover){