Exemple #1
0
NeoWindow::NeoWindow( char **args, Neoterics *owner ) : neo( owner ), mainWin( NULL ), options_box( NULL ),
                         nnet_plot( NULL ), chart_wind( NULL ) { //, portal( NULL ) {
#undef int
   int tmp = (int) 1;
   if ( ! neo->dontShowDisplayAtAll ) fl_initialize( &tmp, args, args[0], 0, 0 );
#define int short
   pixmap = NULL;
   display = XOpenDisplay( "" );
   if ( display == NULL ) throw( "cannot connect to server" );
   screen = DefaultScreen( display );
   mainWin = create_form_mainWindow();
   fl_show_form( mainWin->mainWindow, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, neo->programName );
   ::XFlush( display );
   Window window = FL_ObjWin( mainWin->mainCanvas );
   if ( window == (Window) NULL ) throw( "cannot open window" );
   destination = window;
   gc = ::XCreateGC( display, window, 0, 0 );
   changed = true; // Why it has to be here and not at the top, I dont know

   fl_add_canvas_handler( mainWin->mainCanvas, Expose, expose_callback, (void *) this );
   fl_add_canvas_handler( mainWin->mainCanvas, ButtonPress, buttonRelease_callback, (void *) this );
   fl_add_canvas_handler( mainWin->mainCanvas, ButtonRelease, buttonRelease_callback, (void *) this );
   fl_set_scrollbar_return( mainWin->scroll_h, FL_RETURN_CHANGED );
   fl_set_scrollbar_return( mainWin->scroll_v, FL_RETURN_CHANGED );
   fl_set_object_callback( mainWin->scroll_h, scroll_callback, (long) this );
   fl_set_object_callback( mainWin->scroll_v, scroll_callback, (long) this );
   cmap = fl_get_canvas_colormap( mainWin->mainCanvas );

   action_color[moveForward].red = 0x0000; //  Forward color
   action_color[moveForward].green = 0x0000;
   action_color[moveForward].blue = 0xFFFF;
   action_color[turnRight].red = 0x0000; //  Turn Right
   action_color[turnRight].green = 0x0000;
   action_color[turnRight].blue = 0xFFFF;
   action_color[turnLeft].red = 0x0000; //  Turn Left
   action_color[turnLeft].green = 0x0000;
   action_color[turnLeft].blue = 0xFFFF;
   action_color[eat].red = 0x0000; //  Eat
   action_color[eat].green = 0xFFFF;
   action_color[eat].blue = 0xFFFF;
   action_color[breed].red = 0xFFFF; //  Breed
   action_color[breed].green = 0x0000;
   action_color[breed].blue = 0xFFFF;
   action_color[fight].red = 0xFFFF; //  Fight
   action_color[fight].green = 0xFFFF;
   action_color[fight].blue = 0x0000;   

   if ( ! neo->startoffDisplaying ) neo->keepDrawing = false;

#define offscreen
#ifdef offscreen
   pixmap = XCreatePixmap( display, window, mainWin->mainCanvas->w, mainWin->mainCanvas->h,
			   DefaultDepth( display, screen ) );
#endif
}
Exemple #2
0
void NeoWindow::HandleMainWinObject( FL_OBJECT *obj ) { // Handle command from form on main window
   int scale = neo->scale, i;
   if ( obj == mainWin->pause ) { // Pause/un-pause
      if ( ! neo->setup ) return;
      neo->started = true;
      neo->paused = ! neo->paused;
      Refresh( true );
   } else if ( obj == mainWin->step ) { // If paused, update by one timestep
      neo->started = true;
      if ( neo->paused ) neo->nextStep = true;
   } else if ( obj == mainWin->add_food ) { // Add food to world
      neo->borrowed_energy -= neo->food_button_increment;
   } else if ( obj == mainWin->remove_food ) { // Remove food
      neo->borrowed_energy += neo->food_button_increment;
   } else if ( obj == mainWin->file_menu ) {
      const char *choice = fl_get_menu_text( obj );
      if ( ! strcmp( "New", choice ) ) {
	 neo->started = false;
	 neo->paused = true;
	 neo->SetUpRun(); // Set up the run
	 Refresh( true );
	 //portal = new NeoPortal( 1115 );
	 //( portal = new NeoPortal() )->CallServer( "localhost", 1115 );
      } else if ( ! strcmp( "Close", choice ) ) {
	 neo->started = false;
	 neo->paused = true;
	 Refresh( true );
      } else if ( ! strcmp( "Load", choice ) ) {
	 const char *output = NULL;
	 if ( ( output = fl_show_fselector( "Load simulation from file:" , ".", "*",
					    neo->fileName ) ) != NULL ) {
	    strcpy( neo->fileName, output );
	    neo->LoadSimulation();
	    Refresh( true );
	 }
      } else if ( ! strcmp( "Save", choice ) ) {
	 const char *output = NULL;
	 if ( ( output = fl_show_fselector( "Save simulation to file:" , ".", "*",
					    neo->fileName ) ) != NULL ) {
	    strcpy( neo->fileName, output );
	    neo->SaveSimulation();
	 }	
	 Refresh();
      } else if ( ! strcmp( "Print...", choice ) ) {
	 char tmp[50];
	 sprintf( tmp, "%s.%08d.ps", neo->fileName, neo->time_step );
	 const char *output = NULL;
	 if ( ( output = fl_show_fselector( "Print simulation to PostScript file:" , ".", "*",
					    tmp ) ) != NULL ) {
	    fl_object_ps_dump( mainWin->mainCanvas, tmp );
	 }	
      } else if ( ! strcmp( "Quit", choice ) ) {
	 neo->done = true;
	 neo->started = false;
	 neo->keepDrawing = false;
      }
   } else if ( obj == mainWin->other_menu ) {
      const char *choice = fl_get_menu_text( obj );
      if ( ! strcmp( "Update Display", choice ) ) {
	 neo->keepDrawing = ! neo->keepDrawing;
	 Refresh( true ); // Need to update the whole screen
      } else if ( ! strcmp( "NNet Window", choice ) ) {
	 nnet_plot = create_form_neural_net_plot();
	 fl_add_canvas_handler( nnet_plot->mainCanvas, Expose, expose_callback, (void *) this );
	 fl_show_form( nnet_plot->neural_net_plot, FL_PLACE_MOUSE, FL_TRANSIENT, "Neural Net Plot" );
	 RedrawNNetPlot();
      } else if ( ! strcmp( "Chart Window", choice ) ) {
	 chart_wind = create_form_chart_window();
	 fl_show_form( chart_wind->chart_window, FL_PLACE_MOUSE, FL_TRANSIENT, "Population Statistics" );
      } else if ( ! strcmp( "Leave Trails", choice ) ) {
	 neo->leaveTrails = ! neo->leaveTrails;
	 if ( ! neo->leaveTrails ) Refresh( true );
      } else if ( ! strcmp( "Add Bug", choice ) ) {
	 const char *output = NULL;
	 fl_add_fselector_appbutton( "Number", fselector_callback, this );
	 if ( ( output = fl_show_fselector( "Add creature from file:", ".", "*", 
					    neo->creatureFile ) ) != NULL ) {
	    for ( int jj = 0; jj < neo->initialBugSeed; jj ++ ) {
	       strcpy( neo->creatureFile, output );
	       new Creature( Introduced, neo );
	    }
	 }
	 fl_remove_fselector_appbutton( "Number" );
	 Draw( true );
      } else if ( ! strcmp( "Save Bug", choice ) ) {
	 if ( neo->output_creature < 0 ) return;
	 const char *output = NULL;
	 if ( ( output = fl_show_fselector( "Save creature to file:" , ".", "*", 
					    neo->creatureFile ) ) != NULL ) {
	    Creature *creature = neo->ppCreatureList[ neo->output_creature ];
	    if ( creature != NULL ) creature->WriteGenotype( (char *) output );
	 }
      } else if ( ! strcmp( "Options...", choice ) ) {
	 options_box = create_form_options();
	 FD_options *box = options_box;
	 if ( neo->started ) {
	    fl_deactivate_object( box->initial_parameters_group );
	    fl_set_object_label( box->initial_params_frame, "Initial Parameters (currently inactive)" );
	 }
	 fl_set_slider_value( box->initial_pop, neo->initial_creatures );
	 fl_set_slider_value( box->initial_plant, neo->num_initial_food_locs );
	 fl_set_slider_value( box->initial_flesh, neo->num_initial_meat_locs );
	 fl_set_button( box->give_head_start, neo->bGiveHeadStart );
	 fl_set_button( box->allow_sex, neo->bAllowSexual );
	 fl_set_button( box->allow_asex, neo->bAllowAsexual );
	 char tmp[5];
	 sprintf( tmp, "%d", neo->terrain_size );
	 fl_set_choice_text( box->terrain_size, tmp );
	 fl_set_slider_value( box->scale, neo->scale );
	 fl_set_slider_value( box->prob_crossover, neo->prob_crossover );
	 fl_set_slider_value( box->prob_mutation, neo->prob_mutation );
	 fl_set_slider_value( box->max_pop, neo->maximum_creatures );
	 fl_set_slider_value( box->min_pop, neo->nMinimumPopulation );
	 fl_set_slider_value( box->age_factor, neo->age_factor );
	 fl_set_slider_value( box->carcass_decay_rate, neo->nCarcassDecayRate );
	 fl_set_slider_value( box->waste_decay_rate, neo->nWasteDecayRate );
	 fl_set_slider_value( box->poison_decay_rate, neo->nPoisonDecayRate );
	 fl_set_button( box->give_head_start, neo->bGiveHeadStart );
	 fl_set_button( box->maintain_min_pop, neo->bKeepMinimumPopulation );
	 fl_set_button( box->use_survivor, neo->bUseSurvivorForMinimum );
	 fl_set_slider_value( box->save_every, neo->saveEveryNsteps );
	 if ( neo->saveEveryNsteps == -1 ) fl_set_button( box->save_sim, 0 );
	 else fl_set_button( box->save_sim, 1 );
	 fl_set_input( box->file_name, neo->fileName );
	 fl_show_form( box->options, FL_PLACE_MOUSE, FL_TRANSIENT, "Key Commands" );
      }
   }
}
Exemple #3
0
FL_OBJECT *
fl_create_formbrowser( int          type,
                       FL_Coord     x,
                       FL_Coord     y,
                       FL_Coord     w,
                       FL_Coord     h,
                       const char * label )
{
    FL_OBJECT *ob;
    FLI_FORMBROWSER_SPEC *sp;
    int absbw, oldu = fl_get_coordunit( );
    int D;

    ob = fl_make_object( FL_FORMBROWSER, type, x, y, w, h, label,
                         handle_formbrowser );
    fl_set_coordunit( FL_COORD_PIXEL );
    ob->boxtype    = FL_FORMBROWSER_BOXTYPE;
    ob->align      = FL_FORMBROWSER_ALIGN;
    ob->col1       = FL_FORMBROWSER_COL1;
    ob->col2       = FL_BLACK;
    ob->set_return = set_formbrowser_return;
    ob->spec       = sp = fl_calloc( 1, sizeof *sp );

    absbw = FL_abs( ob->bw );

    sp->form   = NULL;
    sp->parent = ob;
    sp->scroll = FL_SMOOTH_SCROLL;
    sp->vw_def = sp->hh_def = D = fli_get_default_scrollbarsize( ob );
    sp->canvas = fl_create_canvas( FL_CANVAS,
                                   ob->x + absbw, ob->y + absbw,
                                   ob->w - 2 * absbw - sp->vw_def,
                                   ob->h - 2 * absbw - sp->hh_def,
                                   label );

    sp->canvas->u_vdata = sp;

    fl_modify_canvas_prop( sp->canvas, NULL, NULL, canvas_cleanup );

    fl_set_object_color( sp->canvas, ob->col1, ob->col2 );
    fl_set_object_bw( sp->canvas, ob->bw );

    fl_set_object_boxtype( sp->canvas,
                           fli_boxtype2frametype( ob->boxtype ) );
    fl_add_canvas_handler( sp->canvas, Expose, canvas_handler, NULL );

    sp->v_pref = sp->h_pref = FL_AUTO;

    sp->hsl = fl_create_scrollbar( FL_HOR_THIN_SCROLLBAR, ob->x,
                                   y + h - D, w - D, D, "" );
    fl_set_scrollbar_value( sp->hsl, sp->old_hval = 0.0 );
    fl_set_object_boxtype( sp->hsl, ob->boxtype );
    sp->hsl->visible = sp->h_pref == FL_ON;
    sp->hsl->resize = FL_RESIZE_X;
    fl_set_object_callback( sp->hsl, hcb, 0 );

    sp->vsl = fl_create_scrollbar( FL_VERT_THIN_SCROLLBAR,
                                   x + w - D, y, D, h - D, "" );
    fl_set_object_boxtype( sp->vsl, ob->boxtype );
    sp->vsl->visible = sp->v_pref == FL_ON;
    fl_set_scrollbar_value( sp->vsl, sp->old_hval = 0.0 );
    sp->vsl->resize = FL_RESIZE_Y;
    fl_set_object_callback( sp->vsl, vcb, 0 );

    fl_add_child( ob, sp->canvas );
    fl_add_child( ob, sp->hsl );
    fl_add_child( ob, sp->vsl );

    fl_set_coordunit( oldu );

    /* Set default return policy for the object */

    fl_set_object_return( ob, FL_RETURN_NONE );

    return ob;
}