static void display_forms( FLI_FORMBROWSER_SPEC * sp ) { int f; int y_pos; FL_OBJECT *canvas = sp->canvas; FL_FORM **form = sp->form; int nforms = sp->nforms; int top_form = sp->top_form; int left_edge = - sp->left_edge; int height = canvas->h; /* - (2 * absbw); */ if ( ! FL_ObjWin( sp->canvas ) ) return; fli_inherit_attributes( sp->parent, sp->canvas ); for ( f = 0; f < top_form; f++ ) if ( form[ f ]->visible ) fl_hide_form( form[ f ] ); fli_inherit_attributes( sp->parent, sp->vsl ); fli_inherit_attributes( sp->parent, sp->hsl ); /* I prefer to keep scrollbar unresizable */ sp->vsl->resize = sp->hsl->resize = FL_RESIZE_NONE; y_pos = sp->scroll == FL_JUMP_SCROLL ? 0 : -sp->top_edge; for ( f = top_form; y_pos < height && f < nforms; f++ ) { if ( form[ f ]->visible ) set_form_position( form[ f ], left_edge, y_pos ); else { fl_prepare_form_window( form[ f ], 0, FL_NOBORDER, "Formbrowser" ); form[ f ]->parent_obj = sp->parent; XReparentWindow( fl_get_display( ), form[ f ]->window, FL_ObjWin( sp->canvas ), left_edge, y_pos ); fl_show_form_window( form[ f ] ); } y_pos += form[ f ]->h; } for ( ; f < nforms; f++ ) if ( form[ f ]->visible ) fl_hide_form( form[ f ] ); }
void NeoWindow::HandleScrollbars( FL_OBJECT *obj ) { // Scroll bars moved int scale = neo->scale; int size = (int) neo->terrain_size; int oldx = xoffset, oldy = yoffset; int w = (int) mainWin->mainCanvas->w; int h = (int) mainWin->mainCanvas->h; if ( obj == NULL || obj == mainWin->scroll_h ) { xoffset = fl_get_scrollbar_value( mainWin->scroll_h ) * ( scale * size - w ); fl_set_scrollbar_size( mainWin->scroll_h, (double) w / (double) ( scale * size ) ); //fl_set_scrollbar_step( mainWin->scroll_h, (double) w / (double) ( scale * size ) ); } if ( obj == NULL || obj == mainWin->scroll_v ) { yoffset = fl_get_scrollbar_value( mainWin->scroll_v ) * ( scale * size - h ); fl_set_scrollbar_size( mainWin->scroll_v, (double) h / (double) ( scale * size ) ); //fl_set_scrollbar_step( mainWin->scroll_v, (double) h / (double) ( scale * size ) ); //fl_set_scrollbar_increment( mainWin->scroll_v, (double) h / (double) ( scale * size ) ); } if ( obj != NULL ) { Window window = FL_ObjWin( mainWin->mainCanvas ); if ( pixmap != (Pixmap) NULL ) { XCopyArea( display, pixmap, window, gc, 0, 0, w, h, -(xoffset-oldx), -(yoffset-oldy) ); ::XFlush( display ); } Refresh( true ); } }
void NeoWindow::HandleButtonPress( FL_OBJECT *obj, XEvent *ev ) { // Deal with mouse button press Window rootWin, childWin, window = FL_ObjWin( mainWin->mainCanvas ); int scale = neo->scale; Creature *old_creature = NULL, *new_creature = NULL; #undef int int x, y, root_x, root_y; unsigned int buttons; #define int short ::XQueryPointer( display, window, &rootWin, &childWin, &root_x, &root_y, &x, &y, &buttons ); if ( buttons == 0 ) { // No shift/alt/ctrl pressed if ( neo->output_creature >= 0 ) old_creature = neo->ppCreatureList[ neo->output_creature ]; int creature = neo->FindCreatureAtLoc( -1, (x+xoffset)/scale, (y+yoffset)/scale ); if ( creature >= 0 ) new_creature = neo->ppCreatureList[ creature ]; neo->output_creature = creature; if ( old_creature != NULL ) DrawAt( old_creature->xcoord, old_creature->ycoord, true ); if ( new_creature != NULL ) DrawAt( new_creature->xcoord, new_creature->ycoord, true ); if ( nnet_plot != NULL ) RedrawNNetPlot(); } else if ( buttons & ( 1 | 4 | 8 ) ) { // shift or alt or ctrl pressed (1 or 4 or 8) while( buttons & ( 1 | 4 | 8 ) ) { ::XQueryPointer( display, window, &rootWin, &childWin, &root_x, &root_y, &x, &y, &buttons ); long loc = ((y+yoffset)/scale << neo->location_shift) + (x+xoffset)/scale; neo->pcBarrierField[loc] = 255; DrawAt( (x+xoffset)/scale, (y+yoffset)/scale, true ); } } }
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 }
void NeoWindow::Refresh( Boolean forceRedraw ) { // Blit the pixmap to the window, optionally after if ( changed || forceRedraw ) Draw( true ); // forcing a redraw onto the pixmap Window window = FL_ObjWin( mainWin->mainCanvas ); destination = window; if ( pixmap != (Pixmap) NULL ) destination = pixmap; if ( destination == pixmap ) { int w = (int) mainWin->mainCanvas->w; int h = (int) mainWin->mainCanvas->h; XCopyArea( display, pixmap, window, gc, 0, 0, w, h, 0, 0 ); destination = window; ::XFlush( display ); } }
void NeoWindow::RedrawNNetPlot() { if ( nnet_plot == NULL ) return; Window window = FL_ObjWin( nnet_plot->mainCanvas ); int index = neo->output_creature; if ( index >= 0 ) { // Only need to redraw network structure if we're looking at a new bug if ( index != nnet_plot->mainCanvas->u_ldata ) DrawNetworkStructure(); UpdateInformation(); } else { ::XSetForeground( display, gc, fl_get_pixel( FL_COL1 ) ); // Clear the whole damn thing ::XFillRectangle( display, window, gc, 0, 0, 450, 300 ); } nnet_plot->mainCanvas->u_ldata = index; ::XFlush( display ); }
void NeoWindow::Draw( Boolean draw_creatures ) { HandleScrollbars( NULL ); Window window = FL_ObjWin( mainWin->mainCanvas ); destination = window; if ( pixmap != (Pixmap) NULL ) destination = pixmap; XSetForeground( display, gc, BlackPixel( display, screen ) ); ::XFillRectangle( display, destination, gc, 0, 0, mainWin->mainCanvas->w, mainWin->mainCanvas->h ); if ( neo->setup && neo->keepDrawing ) { for ( long y = 0; y < neo->terrain_size; y ++ ) { for ( long x = 0; x < neo->terrain_size; x ++ ) { DrawAt( x, y, false ); } } if ( draw_creatures ) { Creature **ptr = &( neo->ppCreatureList[0] ); for ( int i = 0; i < neo->max_index; i ++ ) { Creature *creature = *ptr++; if ( creature != (Creature *) NULL ) RedrawCreature( i ); } } } changed = false; }
int image_displaysetup() /* Inicializa las ventanas, la paleta de colores y memoria compartida para visualizacion*/ { XGCValues gc_values; XWindowAttributes win_attributes; XColor nuevocolor; int pixelNum, numCols; int allocated_colors=0, non_allocated_colors=0; image_win= FL_ObjWin(fd_guixforms->ventana0); XGetWindowAttributes(display, image_win, &win_attributes); screen = DefaultScreen(display); XMapWindow(display, image_win); /*XSelectInput(display, image_win, ButtonPress|StructureNotifyMask);*/ gc_values.graphics_exposures = False; image_gc = XCreateGC(display, image_win, GCGraphicsExposures, &gc_values); /* Utilizan el Visual (=estructura de color) y el colormap con que este operando el programa principal con su Xforms. No crea un nuevo colormap, sino que modifica el que se estaba usando a traves de funciones de Xforms*/ vmode= fl_get_vclass(); if ((vmode==TrueColor)&&(fl_state[vmode].depth==16)) {printf("display: truecolor 16 bpp\n"); imagenA_buf = (char *) malloc(SIFNTSC_COLUMNS*SIFNTSC_ROWS*2); imagenA = XCreateImage(display,DefaultVisual(display,screen),win_attributes.depth, ZPixmap,0,imagenA_buf,SIFNTSC_COLUMNS, SIFNTSC_ROWS,8,0); imagenB_buf = (char *) malloc(SIFNTSC_COLUMNS*SIFNTSC_ROWS*2); imagenB = XCreateImage(display,DefaultVisual(display,screen),win_attributes.depth, ZPixmap,0,imagenB_buf,SIFNTSC_COLUMNS, SIFNTSC_ROWS,8,0); return win_attributes.depth; } else if ((vmode==TrueColor)&&(fl_state[vmode].depth==24)) { printf("display: truecolor 24 bpp\n"); imagenA_buf = (char *) malloc(SIFNTSC_COLUMNS*SIFNTSC_ROWS*4); imagenA = XCreateImage(display,DefaultVisual(display,screen),24, ZPixmap,0,imagenA_buf,SIFNTSC_COLUMNS, SIFNTSC_ROWS,8,0); imagenB_buf = (char *) malloc(SIFNTSC_COLUMNS*SIFNTSC_ROWS*4); imagenB = XCreateImage(display,DefaultVisual(display,screen),24, ZPixmap,0,imagenB_buf,SIFNTSC_COLUMNS, SIFNTSC_ROWS,8,0); return win_attributes.depth; } else if ((vmode==PseudoColor)&&(fl_state[vmode].depth==8)) { numCols = 256; for (pixelNum=0; pixelNum<numCols; pixelNum++) { nuevocolor.pixel=0; nuevocolor.red=pixelNum<<8; nuevocolor.green=pixelNum<<8; nuevocolor.blue=pixelNum<<8; nuevocolor.flags=DoRed|DoGreen|DoBlue; /*if (XAllocColor(display,DefaultColormap(display,screen),&nuevocolor)==False) tabla[pixelNum]=tabla[pixelNum-1];*/ if (XAllocColor(display,fl_state[vmode].colormap,&nuevocolor)==False) {tabla[pixelNum]=tabla[pixelNum-1]; non_allocated_colors++;} else {tabla[pixelNum]=nuevocolor.pixel;allocated_colors++;} } printf("display: depth= %d\n", fl_state[vmode].depth); printf("display: colormap got %d colors, %d non_allocated colors\n",allocated_colors,non_allocated_colors); imagenA_buf = (char *) malloc(SIFNTSC_COLUMNS*SIFNTSC_ROWS); imagenA = XCreateImage(display,DefaultVisual(display,screen),8, ZPixmap,0,imagenA_buf,SIFNTSC_COLUMNS, SIFNTSC_ROWS,8,0); imagenB_buf = (char *) malloc(SIFNTSC_COLUMNS*SIFNTSC_ROWS); imagenB = XCreateImage(display,DefaultVisual(display,screen),8, ZPixmap,0,imagenB_buf,SIFNTSC_COLUMNS, SIFNTSC_ROWS,8,0); pixel8bpp_rojo = fl_get_pixel(FL_RED); pixel8bpp_blanco = fl_get_pixel(FL_WHITE); pixel8bpp_amarillo = fl_get_pixel(FL_YELLOW); return win_attributes.depth; } else { perror("Unsupported color mode in X server");exit(1); } return win_attributes.depth; }