Newer
Older
#include <stdio.h>
#include <stdlib.h>
#ifdef WIN32
# include "winjunk.h"
#endif
#include <GL/gl.h>
#include "Gview.H"
#include "partiview.H"
#include "geometry.h"
#include "shmem.h"
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <errno.h>
#include "partiviewc.h"
#include "findfile.h"
#include <FL/fl_draw.H>
#include <FL/fl_file_chooser.H>
extern "C" { extern void plugin_init(); }
struct stuff *stuffs[MAXSTUFF];
static int specks_commandstr( struct stuff **stp, const char *str ) {
if(stp == NULL || *stp == NULL || str == NULL)
return 0;
#define MAXARGS 128
char *av[MAXARGS];
int ac;
char *txt = (char *)alloca( strlen(str) + 1 );
char *s = txt;
strcpy(txt, str);
for(ac = 0; ac < MAXARGS-1; ac++) {
av[ac] = strtok(s, " \t\n");
if(av[ac] == NULL) break;
s = NULL;
}
av[ac] = NULL;
return specks_parse_args( stp, ac,av);
}
int specks_commandfmt( struct stuff **stp, const char *fmt, ... ) {
char cmd[1024];
int ok;
va_list args;
va_start(args, fmt);
vsprintf(cmd, fmt, args);
va_end(args);
ok = specks_commandstr( stp, cmd );
if(ok) parti_redraw();
return ok;
}
/* =================================================================== */
void pp_nav_init(Fl_Menu_Button *);
int pp_viewevent_cb( Fl_Gview *, int ev );
void pp_ui_init() {
pp_nav_init(ppui.nav);
/* ppui.cmd->handle_cb = pp_cmd_handle_cb; No, this doesn't work yet */
ppui.view->eventhook = pp_viewevent_cb;
parti_inertia( 1 );
if(getenv("CMDFONT"))
ppui.cmdhist->scaletext( atoi( getenv("CMDFONT") ) );
ppui.freewin = NULL;
ppui.boundwin = ppui.view;
ppui.detached = 0;
#ifdef DEFAULT_ELUMENS
void pp_clk_init() {
ppui.clk = NewN( SClock, 1 );
clock_init( ppui.clk );
clock_set_speed( ppui.clk, 1.0 );
ppui.clk->continuous = 1; // is this used?
ppui.clk->walltimed = 1;
}
void pp_ui_postinit() {
parti_set_timebase( ppui.st, 0.0 );
parti_set_timestep( ppui.st, 0.0 );
parti_set_running( ppui.st, 0 );
parti_set_fwd( ppui.st, 1 );
ppui.stepspeed->logstyle( FL_LOG_LINEAR );
ppui.stepspeed->truebounds( 1.0e-6, 10.0 );
ppui.stepspeed->truevalue( clock_speed( ppui.clk ) );
if(ppui.detached)
parti_detachview("fullscreen");
void pp_cmd_cb( HistInput* inp, void * ) {
if(inp->hist())
inp->hist()->addline( inp->value(), 0 );
specks_commandstr( &ppui.st, inp->value() );
ppui_refresh( ppui.st );
parti_redraw();
}
static enum Gv_Nav codes[] = { GV_FLY, GV_ORBIT, GV_ROTATE, GV_TRANSLATE };
static char *navtitles[] = {"[f]ly","[o]rbit","[r]ot","[t]ran"};
void pp_nav_init(Fl_Menu_Button *m) {
m->add("[f]ly|[o]rbit|[r]ot|[t]ran");
for(int i = m->size(); --i >= 0; )
(((Fl_Menu_Item *)(m->menu()))[i]).labelcolor( m->labelcolor() );
}
void pp_nav_cb(Fl_Menu_Button* m, struct stuff **vst) {
int v = m->value();
if(v >= 0 && v < COUNT(codes))
ppui.view->nav( codes[v] );
}
void pp_obj_cb(Fl_Menu_Button* m, void *) {
parti_object( m->text(), &ppui.st, 0 );
}
void pp_objtog_cb(Fl_Button* b, void *) {
int objno = 1;
sscanf(b->label(), "g%d", &objno);
if(objno<0||objno>=MAXSTUFF||stuffs[objno]==NULL)
return;
parti_object( b->label(), &ppui.st, 0 );
b->value(1);
} else {
stuffs[objno]->useme = !stuffs[objno]->useme;
}
parti_redraw();
}
void pp_slum_cb(Fl_Value_Slider* sl, struct stuff ** ) {
struct stuff *st = ppui.st;
int cd = st->curdata, by = st->sizedby;
if((unsigned int)cd >= MAXFILES) cd = 0;
if((unsigned int)by >= MAXVAL+1) by = 0;
struct valdesc *vd = &st->vdesc[cd][by];
vd->lum = pow(10., sl->value());
ppui.view->redraw();
}
switch(Fl::event_button()) {
case FL_RIGHT_MOUSE: sign *= 10; break;
case FL_MIDDLE_MOUSE: sign *= 0.1; break;
}
clock_step( ppui.st->clk, sign );
parti_redraw();
}
void pp_run_cb( Fl_Button *runbtn, void *stepsign ) {
clock_set_fwd( ppui.st->clk, (int)stepsign );
parti_set_running( ppui.st, runbtn->value() );
parti_set_timestep( ppui.st, v + ppui.timebasetime );
Loading
Loading full blame...