Esempio n. 1
0
void list_view::init()
{
	init_grid(cast<listbox_definition::resolution>(config()).grid);

	set_single_child(find_widget<grid>(&get_grid(), "_list_grid", false),
					 generator_);

	/*
	 * These items should be managed by the new listbox class.
	 * So make them invisible for now.
	 */
	grid* g = find_widget<grid>(&get_grid(), "_header_grid", false, false);
	if(g)
		g->set_visible(widget::visibility::invisible);

	g = find_widget<grid>(&get_grid(), "_footer_grid", false, false);
	if(g)
		g->set_visible(widget::visibility::invisible);

	g = find_widget<grid>(&get_grid(), "_vertical_scrollbar_grid", false, false);
	if(g)
		g->set_visible(widget::visibility::invisible);

	g = find_widget<grid>(&get_grid(), "_horizontal_scrollbar_grid", false, false);
	if(g)
		g->set_visible(widget::visibility::invisible);
}
Esempio n. 2
0
HIDDEN void
get_cbar(void)
{
    int eid, pid;
    int g1, g2;
    point_t pt1, pt2;
    fastf_t radius;
    vect_t height;
    struct pbar *pb;
    char cbar_name[NAMESIZE+1];

    eid = atoi( curr_rec[1] );

    pid = atoi( curr_rec[2] );
    if ( !pid )
    {
	if ( bar_def_pid )
	    pid = bar_def_pid;
	else
	    pid = eid;
    }

    g1 = atoi( curr_rec[3] );

    g2 = atoi( curr_rec[4] );

    get_grid( g1, pt1 );
    get_grid( g2, pt2 );

    for ( BU_LIST_FOR( pb, pbar, &pbar_head.l ) )
    {
	if ( pb->pid == pid )
	    break;
    }

    if ( BU_LIST_IS_HEAD( &pb->l, &pbar_head.l ) )
    {
	log_line( "Non-existent PID referenced in CBAR" );
	return;
    }

    VSCALE( pt1, pt1, conv[units] );
    VSCALE( pt2, pt2, conv[units] );

    radius = sqrt( pb->area/bn_pi );
    radius = radius * conv[units];

    VSUB2( height, pt2, pt1 );

    sprintf( cbar_name, "cbar.%d", eid );
    mk_rcc( fpout, cbar_name, pt1, height, radius );

    mk_addmember( cbar_name, &pb->head.l, NULL, WMOP_UNION );
}
Esempio n. 3
0
void list_view::layout_children(const bool force)
{
	if(need_layout_ || force) {
		get_grid().place(get_grid().get_origin(), get_grid().get_size());

		/*
				get_grid().set_visible_rectangle(content_visible_area_);
		*/
		need_layout_ = false;
		set_is_dirty(true);
	}
}
Esempio n. 4
0
point listbox::calculate_best_size() const
{
	// Get the size from the base class, then add any extra space for the header and footer.
	point result = scrollbar_container::calculate_best_size();

	if(const grid* header = find_widget<const grid>(&get_grid(), "_header_grid", false, false)) {
		result.y += header->get_best_size().y;
	}

	if(const grid* footer = find_widget<const grid>(&get_grid(), "_footer_grid", false, false)) {
		result.y += footer->get_best_size().y;
	}

	return result;
}
Esempio n. 5
0
ComplementarityRestraint::GridObject *ComplementarityRestraint::get_grid_object(
    core::RigidBody rb, const kernel::ParticlesTemp &a, ObjectKey ok,
    double thickness, double value, double interior_thickness,
    double voxel) const {
  IMP_USAGE_CHECK(!a.empty(), "No particles passed for excluded volume");
  for (unsigned int i = 1; i < a.size(); ++i) {
    IMP_USAGE_CHECK(core::RigidMember(a[0]).get_rigid_body() ==
                        core::RigidMember(a[i]).get_rigid_body(),
                    "Not all particles are from the same rigid body.");
  }
  if (!rb->has_attribute(ok)) {
    IMP_LOG_TERSE("Creating grid for rigid body " << rb->get_name()
                                                  << std::endl);
    IMP::algebra::DenseGrid3D<float> grid =
        get_grid(a, thickness, value, interior_thickness, voxel);
    IMP_LOG_TERSE("Grid has size " << grid.get_number_of_voxels(0) << ", "
                                   << grid.get_number_of_voxels(1) << ", "
                                   << grid.get_number_of_voxels(2)
                                   << std::endl);
    base::Pointer<GridObject> n(new GridObject(
        GridPair(rb.get_reference_frame().get_transformation_to(), grid)));
    rb->add_cache_attribute(ok, n);
  }
  IMP_CHECK_OBJECT(rb->get_value(ok));
  IMP_INTERNAL_CHECK(dynamic_cast<GridObject *>(rb->get_value(ok)),
                     "The saved grid is not a grid.");
  return dynamic_cast<GridObject *>(rb->get_value(ok));
}
Esempio n. 6
0
int	main(int argc, char **argv)
{
	int *grid[9][9];

	get_grid(argc - 1, argv + 1, *grid);
	return (0);
}
Esempio n. 7
0
static int get_data_grid (Isis_Rmf_t *rmf, double **lo, double **hi, unsigned int *n, int *eoeb) /*{{{*/
{
   Client_Data_t *cl = (Client_Data_t *)rmf->client_data;

   *eoeb = 0;
   return get_grid (cl->ebounds, lo, hi, n);
}
Esempio n. 8
0
/*
Sauvegarde d'un grille
@params	p_widget	Elément ayant déclencher la fonction
@params	user_data	Données transmis au callback
*/
void cb_save_file(GtkWidget *p_widget, gpointer user_data){
    GtkWidget *p_dialog_save;
    p_dialog_save = gtk_file_chooser_dialog_new ("Enregistrer un fichier",
                                            GTK_WINDOW(widgetCallback.entry1),
                                            GTK_FILE_CHOOSER_ACTION_SAVE,
                                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                            GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                                            NULL);

    gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(p_dialog_save), TRUE);

   if (gtk_dialog_run(GTK_DIALOG(p_dialog_save)) == GTK_RESPONSE_ACCEPT){ //Nom du fichier a été choisi
        char *filename;
        filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(p_dialog_save));

        int grid[9][9] = {{0}};
        int grid_fixes[9][9] = {{0}};

        //On récupère la grille
        get_grid(grid);
        get_fixed_grid(grid_fixes);

        save_grid_in_file(grid, grid_fixes, filename); //On sauvegarde
    }

    gtk_widget_destroy(p_dialog_save);

    //Parametres inutilises
    (void)p_widget;
}
Esempio n. 9
0
void listbox::finalize(builder_grid_const_ptr header,
		builder_grid_const_ptr footer,
		const std::vector<std::map<std::string, string_map>>& list_data)
{
	// "Inherited."
	scrollbar_container::finalize_setup();

	assert(generator_);

	if(header) {
		swap_grid(&get_grid(), content_grid(), header->build(), "_header_grid");
	}

	grid& p = find_widget<grid>(this, "_header_grid", false);

	for(unsigned i = 0, max = std::max(p.get_cols(), p.get_rows()); i < max; ++i) {
		//
		// TODO: I had to change this to case to a toggle_button in order to use a signal handler.
		// Should probably look into a way to make it more general like it was before (used to be
		// cast to selectable_item).
		//
		// - vultraz, 2017-08-23
		//
		if(toggle_button* selectable = find_widget<toggle_button>(&p, "sort_" + std::to_string(i), false, false)) {
			// Register callback to sort the list.
			connect_signal_notify_modified(*selectable, std::bind(&listbox::order_by_column, this, i, _1));

			if(orders_.size() < max) {
				orders_.resize(max);
			}

			orders_[i].first = selectable;
		}
	}

	if(footer) {
		swap_grid(&get_grid(), content_grid(), footer->build(), "_footer_grid");
	}

	generator_->create_items(-1, list_builder_, list_data, std::bind(&listbox::list_item_clicked, this, _1));
	swap_grid(nullptr, content_grid(), generator_, "_list_grid");
}
Esempio n. 10
0
int main()
{
  int **power = NULL, i;
  
  power = (int**)malloc( 3 * sizeof( int* ) ); // for the rows 
  for ( i = 0; i < 3; i++ ) // for every row, you want get 4 addresses
    power[i] = (int*)malloc(4 * sizeof (int) ); 
  get_grid(power);

  return 0;
}//main()
Esempio n. 11
0
grid
box_rep::find_grid (path bp) {
  box  b= this;
  grid g= get_grid ();
  while (!is_nil (bp)) {
    b  = b->subbox (bp->item);
    bp = bp->next;
    grid g2= b->get_grid ();
    if (!is_nil (g2)) g= g2;
  }
  return g;
}
Esempio n. 12
0
void
stacked_widget::finalize(std::vector<builder_grid_const_ptr> widget_builder)
{
	assert(generator_);
	string_map empty_data;
	for(const auto & builder : widget_builder)
	{
		generator_->create_item(-1, builder, empty_data, nullptr);
	}
	swap_grid(nullptr, &get_grid(), generator_, "_content_grid");

	select_layer(-1);
}
Esempio n. 13
0
int Get_slope_grid(double resolution, double xmin, double xmax, double ymin, double ymax, double* slope)
{
  int status;

  if ( gis_grid.slope == 0 )
    {
      status = calculate_slope();
      if ( status != 0 )
	return status;
    }

  get_grid( resolution, xmin, xmax, ymin, ymax, gis_grid.slope, slope);
  return 0;
}
Esempio n. 14
0
int Get_elevation_grid(double resolution, double xmin, double xmax, double ymin, double ymax, double* elev)
{
  int status;

  if ( gis_grid.elev == 0 )
    {
      status = load_GIS_data();
      if ( status != 0 )
	return status;
    }

  get_grid( resolution, xmin, xmax, ymin, ymax, gis_grid.elev, elev);
  return 0;
}
Esempio n. 15
0
int Get_curvature_grid(double resolution, double xmin, double xmax, double ymin, double ymax, double* xcurv, double* ycurv)
{
  int status;

  if ( gis_grid.slope == 0 )
    {
      status = calculate_slope();
      if ( status != 0 )
	return status;
    }

  if ( gis_grid.xcurv == 0 )
    {
      status = calculate_curvature();
      if ( status != 0 )
	return status;
    }

  get_grid( resolution, xmin, xmax, ymin, ymax, gis_grid.xcurv, xcurv);
  get_grid( resolution, xmin, xmax, ymin, ymax, gis_grid.ycurv, ycurv);

  return 0;
}
Esempio n. 16
0
void
mu_msg_header_view_set_message (MuMsgHeaderView *self, MuMsg *msg)
{
	g_return_if_fail (MU_IS_MSG_HEADER_VIEW(self));

	if (self->_priv->_grid) {
		gtk_container_remove (GTK_CONTAINER(self), self->_priv->_grid);
		self->_priv->_grid = NULL;
	}

	if (msg) {
		self->_priv->_grid = get_grid (msg);
		gtk_box_pack_start (GTK_BOX(self), self->_priv->_grid,
				    TRUE, TRUE, 0);
		gtk_widget_show_all (self->_priv->_grid);
	}
}
Esempio n. 17
0
/* 16Feb07  Phil McDonald */
int	volume_colors (Context data_ctx, int itime, int ivar)
{
    int			ixyz, nxyz;
    float		*data, datmin, datmax, datfac, val, *p_xyz;
    uint_1		*p_ind;
    struct volume	*v;



    if ((data = get_grid (data_ctx, itime, ivar)) == NULL) return 0;

    datmin = data_ctx->Variable[ivar]->MinVal;
    datmax = data_ctx->Variable[ivar]->MaxVal;
    datfac = (datmin == datmax) ? 0.0 : 254.0 / (datmax - datmin);

    v     = data_ctx->Volume;
    nxyz  = v->nx * v->ny * v->nz;
    p_xyz = v->vertex;
    p_ind = v->index;
    for (ixyz = 0; ixyz < nxyz; ixyz++)
    {
        val = volume_interp_val (data_ctx, itime, ivar, data, p_xyz);
        if (IS_MISSING (val))
        {
            *p_ind = 255;
        }
        else if (val <= datmin)
        {
            *p_ind = 0;
        }
        else if (val >= datmax)
        {
            *p_ind = 254;
        }
        else
        {
            *p_ind = (val - datmin) * datfac;
        }
        p_ind++;
        p_xyz += 3;
    }
    release_grid (data_ctx, itime, ivar, data);


    return 1;
}
Esempio n. 18
0
/*
Affichage de la solution de la grille
@params	p_widget	Elément ayant déclencher la fonction
@params	user_data	Données transmis au callback
*/
void cb_resolve(GtkWidget *p_widget, gpointer user_data){
    int i,row,col;

    //On récupère la grille
    int grid[9][9] = {{0}};
    get_grid(grid);
    int grid_fixes[9][9] = {{0}};
    get_fixed_grid(grid_fixes);

    //On vérifit si grid_fixes est vide
    int emptyGridFixes = 1;
    for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        if(grid_fixes[col][row] != 0){emptyGridFixes = 0;break;}
    }

    if(!emptyGridFixes){
        //On récupère la base de la grille
        for(i=0;i<=80;i++){
            row = floor(i/9);
            col = i%9;
            if(grid_fixes[col][row] == 0){grid[col][row] = 0;}
        }
    }
    else{
        //On remplit grid_fixes(grille saisi par user)
        for(i=0;i<=80;i++){
            row = floor(i/9);
            col = i%9;
            if(grid[col][row] != 0){grid_fixes[col][row] = 1;}
        }
    }

    //On résout et on affiche
    if(is_grid_valid(grid)){
        resolve(grid, 0, 0);
        fill_grid(grid, grid_fixes);
    }

    (void)p_widget;
    (void)user_data;
}
Esempio n. 19
0
File: get_grid.c Progetto: plean/CPE
int		my_errors(unsigned char grille[9][9])
{
  static t_bool	e;
  char		*line;
  int		i;
  size_t	len;
  ssize_t	read;

  line = NULL;
  i = -1;
  len = 0;
  while (i < 10 && (read = getline(&line, &len, stdin)) != -1)
      if (get_grid(grille, line, ++i))
	{
	  free(line);
	  return (0);
	}
  if (e == true && i == 10)
    printf("####################\n");
  e = true;
  free(line);
  return (i == 10 || i == -1) ? (1 + (i == 10)) : (0);
}
Esempio n. 20
0
/*!
 * \brief Affichage de la grille
 * \note Pour le mode console
 */
void World::display() {
    for (unsigned i = 0 ; i < len() +2 ; i++) cout << "-";
    cout << endl;
	cout << "x|";
    for (unsigned i = 0 ; i < len() ; i++) cout << i%10 << "|";
    cout << endl;

	for (unsigned i = 0 ; i < hei() ; i++) {
        cout << i%10 << "|";
		for (unsigned j = 0 ; j < len() ; j++) {
            cout << get_grid(j,i)->display();
            cout << "|";
		}
		cout << endl;
	}
	for (unsigned i = 0 ; i < len() + 2 ; i++) cout << "-";
	cout << endl << endl;

	cout << "Stats faction :" << endl;
    for (list<Faction>::iterator it = factions_.begin() ; it!=factions_.end() ; it++) {
        cout << it->toString();
	}
	cout << endl << endl;
}
Esempio n. 21
0
HIDDEN void
get_coord_sys(void)
{
    int form;
    char type;
    char *ptr;
    struct coord_sys *cs;
    int i, gid;
    double tmp[3];
    point_t tmp_pt;

    form = atoi(&curr_rec[0][4]);
    if (form != 1 && form != 2) {
	bu_log("unrecognized form for coordinate system definition (%d):\n", form);
	bu_log("%s\n", line);
	return;
    }
    type = curr_rec[0][5];

    if (type != CORD_CYL && type != CORD_RECT && type != CORD_SPH) {
	bu_log("unrecognized coordinate system type (%c):\n", type);
	bu_log("%s\n", line);
	return;
    }

    (void)strtok(line, delims);
    ptr = strtok((char *)NULL, delims);
    if (!ptr) {
	log_line("Incomplete coordinate system definition");
	return;
    }

    BU_ALLOC(cs, struct coord_sys);

    switch (form) {
	case 1:
	    cs->type = type;
	    cs->cid = atoi(curr_rec[1]);
	    gid = atoi(curr_rec[2]);
	    get_grid(gid, cs->origin);
	    gid = atoi(curr_rec[3]);
	    get_grid(gid, tmp_pt);
	    VSUB2(cs->v3, tmp_pt, cs->origin);
	    VUNITIZE(cs->v3);
	    gid = atoi(curr_rec[4]);
	    get_grid(gid, tmp_pt);
	    VSUB2(cs->v1, tmp_pt, cs->origin);
	    VCROSS(cs->v2, cs->v3, cs->v1);
	    VUNITIZE(cs->v2);
	    VCROSS(cs->v1, cs->v2, cs->v3);
	    BU_LIST_INSERT(&coord_head.l, &cs->l);

	    if (!strlen(curr_rec[5]))
		break;

	    BU_ALLOC(cs, struct coord_sys);
	    cs->type = type;
	    cs->cid = atoi(curr_rec[5]);
	    gid = atoi(curr_rec[6]);
	    get_grid(gid, cs->origin);
	    gid = atoi(curr_rec[7]);
	    get_grid(gid, tmp_pt);
	    VSUB2(cs->v3, tmp_pt, cs->origin);
	    VUNITIZE(cs->v3);
	    gid = atoi(curr_rec[8]);
	    get_grid(gid, tmp_pt);
	    VSUB2(cs->v1, tmp_pt, cs->origin);
	    VCROSS(cs->v2, cs->v3, cs->v1);
	    VUNITIZE(cs->v2);
	    VCROSS(cs->v1, cs->v2, cs->v3);
	    BU_LIST_INSERT(&coord_head.l, &cs->l);

	    break;
	case 2:
	    cs->type = type;
	    cs->cid = atoi(curr_rec[1]);
	    cs->rid = atoi(curr_rec[2]);
	    for (i=0; i<3; i++)
		tmp[i] = atof(curr_rec[3+i]);
	    VMOVE(cs->origin, tmp);
	    for (i=0; i<3; i++)
		tmp[i] = atof(curr_rec[6+i]);
	    VMOVE(cs->v1, tmp);
	    for (i=0; i<3; i++)
		tmp[i] = atof(curr_rec[9+i]);
	    VMOVE(cs->v2, tmp);

	    if (!cs->rid) {
		point_t tmp_pt1, tmp_pt2;

		/* this coordinate system is defined in terms of the default */
		VMOVE(tmp_pt1, cs->v1);
		VMOVE(tmp_pt2, cs->v2);

		VSUB2(cs->v3, tmp_pt1, cs->origin);
		VUNITIZE(cs->v3);
		VSUB2(cs->v1, tmp_pt2, cs->origin);
		VCROSS(cs->v2, cs->v3, cs->v1);
		VUNITIZE(cs->v2);
		VCROSS(cs->v1, cs->v3, cs->v2);
	    }

	    BU_LIST_INSERT(&coord_head.l, &cs->l);
	    break;
    }
}
Esempio n. 22
0
void draw_volume( Context ctx, int it, int ip, unsigned int *ctable )
{
   float *data;
   static int prev_it[VIS5D_MAX_CONTEXTS];
   static int prev_ip[VIS5D_MAX_CONTEXTS];
   static int do_once = 1;
   int dir;
   float x, y, z, ax, ay, az;
   float xyz[3], xy[3][2], xy0[2];
   Display_Context dtx;

   dtx = ctx->dpy_ctx;
   if (do_once){
      int yo;
      for (yo=0; yo<VIS5D_MAX_CONTEXTS; yo++){
         prev_it[yo] = -1;
         prev_ip[yo] = -1;
      }
      do_once = 0;
   }


   xyz[0] = xyz[1] = xyz[2] = 0.0;
   project (xyz, &xy0[0], &xy0[1]);

   xyz[0] = 1.0, xyz[1] = xyz[2] = 0.0;
   project (xyz, &xy[0][0], &xy[0][1]);
   xy[0][0] -= xy0[0], xy[0][1] -= xy0[1];

   xyz[1] = 1.0, xyz[0] = xyz[2] = 0.0;
   project (xyz, &xy[1][0], &xy[1][1]);
   xy[1][0] -= xy0[0], xy[1][1] -= xy0[1];

   xyz[2] = 1.0, xyz[0] = xyz[1] = 0.0;
   project (xyz, &xy[2][0], &xy[2][1]);
   xy[2][0] -= xy0[0], xy[2][1] -= xy0[1];

   ax = (xy[0][0] * xy[0][0]) + (xy[0][1] * xy[0][1]);
   ay = (xy[1][0] * xy[1][0]) + (xy[1][1] * xy[1][1]);
   az = (xy[2][0] * xy[2][0]) + (xy[2][1] * xy[2][1]);

   if ((ax <= ay) && (ax <= az))
   {
      x = (xy[1][1] * xy[2][0]) - (xy[1][0] * xy[2][1]);
      dir = (x > 0.0) ? WEST_TO_EAST : EAST_TO_WEST;
   }
   else if ((ay <= ax) && (ay <= az))
   {
      x = (xy[2][1] * xy[0][0]) - (xy[2][0] * xy[0][1]);
      dir = (x > 0.0) ? SOUTH_TO_NORTH : NORTH_TO_SOUTH;
   }
   else
   {
      x = (xy[0][1] * xy[1][0]) - (xy[0][0] * xy[1][1]);
      dir = (x > 0.0) ? BOTTOM_TO_TOP : TOP_TO_BOTTOM;
   }

   /* If this is a new time step or variable then invalidate old volumes */
   if (it!=prev_it[ctx->context_index] || ip!=prev_ip[ctx->context_index]) {
      ctx->Volume->valid = 0;
      prev_it[ctx->context_index] = it;
      prev_ip[ctx->context_index] = ip;
   }

   /* Determine if we have to compute a set of slices for the direction. */
   if (ctx->Volume->dir!=dir || ctx->Volume->valid==0) {
      data = get_grid( ctx, it, ip );
      if (data) {
         if (ctx->GridSameAsGridPRIME){
            compute_volume( ctx, data, it, ip, ctx->Nr, ctx->Nc, ctx->Nl[ip],
                            ctx->Variable[ip]->LowLev, ctx->Variable[ip]->MinVal, ctx->Variable[ip]->MaxVal,
                            dir, ctx->Volume );
         }
         else{
            compute_volumePRIME( ctx, data, it, ip, dtx->Nr, dtx->Nc, dtx->Nl,
                            dtx->LowLev, ctx->Variable[ip]->MinVal, ctx->Variable[ip]->MaxVal,
                            dir, ctx->Volume );
         }
         release_grid( ctx, it, ip, data );
      }
   }

   render_volume( ctx, ctx->Volume, ctable );
}
Esempio n. 23
0
/*
 * Draw a volumetric rendering of the grid for timestep it and variable ip.
 * Input: it - timestep
 *        ip - variable
 */
void draw_volume( Context ctx, int it, int ip, unsigned int *ctable )
{
   float *data;
   static int prev_it[VIS5D_MAX_CONTEXTS];
   static int prev_ip[VIS5D_MAX_CONTEXTS];
   static int do_once = 1;
   int dir;
   float x, y, z, ax, ay, az;
   MATRIX ctm, proj;
   Display_Context dtx;

   dtx = ctx->dpy_ctx;
   if (do_once){
      int yo;
      for (yo=0; yo<VIS5D_MAX_CONTEXTS; yo++){
         prev_it[yo] = -1;
         prev_ip[yo] = -1;
      }
      do_once = 0;
   }

   /* Get 3rd column values from transformation matrix */
#if defined (HAVE_SGI_GL) || defined (DENALI)
   /* Compute orientation of 3-D box with respect to current matrices */
   /* with no assumptions about the location of the camera.  This was */
   /* done for the CAVE. */
   mmode( MPROJECTION );
   getmatrix( proj );
   mmode( MVIEWING );
   getmatrix( ctm );
#endif
#if defined(HAVE_OPENGL)
   glGetFloatv( GL_PROJECTION_MATRIX, (GLfloat *) proj );
   glGetFloatv( GL_MODELVIEW_MATRIX, (GLfloat *) ctm );
   check_gl_error( "draw_volume" );
#endif

   /* compute third column values in the product of ctm*proj */
   x = ctm[0][0]*proj[0][2] + ctm[0][1]*proj[1][2]
     + ctm[0][2]*proj[2][2] + ctm[0][3]*proj[3][2];
   y = ctm[1][0]*proj[0][2] + ctm[1][1]*proj[1][2]
     + ctm[1][2]*proj[2][2] + ctm[1][3]*proj[3][2];
   z = ctm[2][0]*proj[0][2] + ctm[2][1]*proj[1][2]
     + ctm[2][2]*proj[2][2] + ctm[2][3]*proj[3][2];

   /* examine values to determine how to draw slices */
   ax = ABS(x);
   ay = ABS(y);
   az = ABS(z);
   if (ax>=ay && ax>=az) {
      /* draw x-axis slices */
      dir = (x<0.0) ? WEST_TO_EAST : EAST_TO_WEST;
   }
   else if (ay>=ax && ay>=az) {
      /* draw y-axis slices */
      dir = (y<0.0) ? SOUTH_TO_NORTH : NORTH_TO_SOUTH;
   }
   else {
      /* draw z-axis slices */
      dir = (z<0.0) ? BOTTOM_TO_TOP : TOP_TO_BOTTOM;
   }

   /* If this is a new time step or variable then invalidate old volumes */
   if (it!=prev_it[ctx->context_index] || ip!=prev_ip[ctx->context_index]) {
      ctx->Volume->valid = 0;
      prev_it[ctx->context_index] = it;
      prev_ip[ctx->context_index] = ip;
   }

   /* Determine if we have to compute a set of slices for the direction. */
   if (ctx->Volume->dir!=dir || ctx->Volume->valid==0) {
      data = get_grid( ctx, it, ip );
      if (data) {
         if (ctx->GridSameAsGridPRIME){
            compute_volume( ctx, data, it, ip, ctx->Nr, ctx->Nc, ctx->Nl[ip],
                            ctx->Variable[ip]->LowLev, ctx->Variable[ip]->MinVal, ctx->Variable[ip]->MaxVal,
                            dir, ctx->Volume );
         }
         else{
            compute_volumePRIME( ctx, data, it, ip, dtx->Nr, dtx->Nc, dtx->Nl,
                            dtx->LowLev, ctx->Variable[ip]->MinVal, ctx->Variable[ip]->MaxVal,
                            dir, ctx->Volume );
         }
         release_grid( ctx, it, ip, data );
      }
   }

   render_volume( ctx, ctx->Volume, ctable );
}
Esempio n. 24
0
/*
 * Compute a new variable by evaluating an expression in terms of other
 * variables.  This is called from gui.c after the user has typed in
 * an expression.
 * Input:  expression - the character string expression as type in by
 *                      the user.   Ex: "SPD = SQRT( U*U + V*V + W*W )"
 * Return:  number of variable computed or -1 if error
 */
int compute_var( Display_Context dtx, const char *expression, int *expressionowner,
                 char name[100], char mess[100], int *recompute )
{
  int time, var, nl, lowlev, toplev, length, layer, offset, i;
  float *g, *a, *b, *f[MAXOPS];
  int numops;
  int ftype, arg_count;
  Context ctx;

  struct compute_state fixed_state, *state;
  state = &fixed_state;

  strcpy(mess, "");

  /* parse the expression to build a tree, return -1 if error */
  if (parse(dtx, state, expression, name, expressionowner, &var, recompute, mess) < 0){
    return -1;
  }
  {
     int ahh;
     for (ahh=0; ahh< dtx->numofctxs; ahh++){
        if (*expressionowner == dtx->ctxpointerarray[ahh]->context_index){
           ctx = dtx->ctxpointerarray[ahh];
           ahh = dtx->numofctxs;
        }
     }
  }

  numops = state->curop; /* length of "program" to compute new variable */

  /* Determine how many levels in output grid (nl) */
  toplev = ctx->MaxNl;
  lowlev = 0;
  /* just look at the var that belong to that data ctx though */
  for (i=0; i<state->numvars; i++) {
    if (state->varlist[i] == USETIME){
       toplev = ctx->MaxNl;
       lowlev = 0;
    }
    else if (state->varownerlist[i] == ctx->context_index){
      if (ctx->Nl[state->varlist[i]] + ctx->Variable[state->varlist[i]]->LowLev < toplev) {
        toplev = ctx->Nl[state->varlist[i]] + ctx->Variable[state->varlist[i]]->LowLev;
      }
      if (ctx->Variable[state->varlist[i]]->LowLev > lowlev) {
        lowlev = ctx->Variable[state->varlist[i]]->LowLev;
      }
    }
  }
  nl = toplev - lowlev;
  if (nl < 1) {
    strcpy(mess, "Error:  grids don't overlap in the vertical");
    return -1;
  }
  layer = ctx->Nr * ctx->Nc;
  length = layer * nl;

  /* Evaluate the tree for each timestep */
  for (time=0;time<ctx->NumTimes;time++) {
    printf(" Creating Variable %s for Time %d\n", name, time); 
    /* run program for one time step */
    state->stop = 0;
    for (state->curop=0; state->curop<numops; state->curop++) {
      switch (state->ops[state->curop]) {
        case PUSH_VAR_OP:
          if (state->args2[state->curop] != ctx->context_index){
            int dd1, tt1;
            int ahh, time2;
            Context tctx;
            for (ahh=0; ahh< ctx->dpy_ctx->numofctxs; ahh++){
              if (state->args2[state->curop] ==
                 ctx->dpy_ctx->ctxpointerarray[ahh]->context_index){
                 tctx = ctx->dpy_ctx->ctxpointerarray[ahh];
                 ahh = ctx->dpy_ctx->numofctxs;
              }
            }
            vis5d_get_ctx_time_stamp( ctx->context_index, time, &dd1, &tt1);
            time2 = return_closes_timestep( tctx, dd1, tt1);
            if (time2 < 0){
              a = (float *) allocate(ctx, length * sizeof(float));
              for (i=0; i<length; i++){
                 a[i] = MISSING;
              }
            }
            else{      
              g = get_grid2( ctx, tctx, time2, state->args[state->curop], nl);
              a = (float *) allocate(ctx, length * sizeof(float));
              for (i=0; i<length; i++){
                 a[i] = g[i];
              }
              release_grid2(ctx, time2, state->args[state->curop], nl, g);
            }
            state->sgrid[state->stop] = a;
            state->stop++;
          }
          else{
            if (state->args3[state->curop] != 0){
               if (time+state->args3[state->curop] < ctx->NumTimes &&
                   time+state->args3[state->curop] >= 0){
                  if (state->args[state->curop] == USETIME){
                     int jj, daze, minz;
                     a = (float *) allocate(ctx, length * sizeof(float));
                     /* get time in seconds since first time step*/
                     if (time+state->args3[state->curop] == 0){
                        jj = 0;
                     }
                     else{
                        daze = ctx->DayStamp[time+state->args3[state->curop]] -
                                     ctx->DayStamp[0];
                        minz = ctx->TimeStamp[time+state->args3[state->curop]] -
                                     ctx->TimeStamp[0];
                        jj = (86400*daze)+minz;
                     }
                     for (i=0; i<length; i++){
                        a[i] = (float) jj;
                     }
                     state->sgrid[state->stop] = a;
                     state->stop++;
                  }
                  else{
                     g = get_grid(ctx, time+state->args3[state->curop],
                                  state->args[state->curop]);
                     a = (float *) allocate(ctx, length * sizeof(float));
                     /* adjust to align lowest levels of grids */
                     offset = (lowlev - ctx->Variable[state->args[state->curop]]->LowLev) * layer;
                     for (i=0; i<length; i++) a[i] = g[i + offset];
                     release_grid(ctx, time+state->args3[state->curop],
                                  state->args[state->curop], g);
                     state->sgrid[state->stop] = a;
                     state->stop++;
                  }
               }
               else{
                  a = (float *) allocate(ctx, length * sizeof(float));
                  for (i=0; i<length; i++){
                     a[i] = MISSING;
                  }
                  state->sgrid[state->stop] = a;
                  state->stop++;
               }
            }
            else{
               if (state->args[state->curop] == USETIME){
                  int jj, daze, minz;
                  /* get time in seconds since first time step*/
                  a = (float *) allocate(ctx, length * sizeof(float));
                  if (time+state->args3[state->curop] == 0){
                     jj = 0;
                  }
                  else{
                     daze = ctx->DayStamp[time+state->args3[state->curop]] -
                            ctx->DayStamp[0];
                     minz = ctx->TimeStamp[time+state->args3[state->curop]] -
                            ctx->TimeStamp[0];
                     jj = (86400*daze)+minz;
                  }
                  for (i=0; i<length; i++){
                     a[i] = (float) jj;
                  }
                  state->sgrid[state->stop] = a;
                  state->stop++;
               }
               else{
                  g = get_grid(ctx, time, state->args[state->curop]);
                  a = (float *) allocate(ctx, length * sizeof(float));
                  /* adjust to align lowest levels of grids */
                  offset = (lowlev - ctx->Variable[state->args[state->curop]]->LowLev) * layer;
                  for (i=0; i<length; i++) a[i] = g[i + offset];
                  release_grid(ctx, time, state->args[state->curop], g);
                  state->sgrid[state->stop] = a;
                  state->stop++;
               }
            }
          }
          break;
        case PUSH_NUM_OP:
          a = (float *) allocate(ctx,length * sizeof(float));
          for (i=0; i<length; i++) a[i] = state->nums[state->curop];
          state->sgrid[state->stop] = a;
          state->stop++;
          break;
        case ADD_OP:
          a = state->sgrid[state->stop - 1];
          b = state->sgrid[state->stop - 2];
          for (i=0; i<length; i++) {
            if (IS_MISSING(a[i]) || IS_MISSING(b[i])) a[i] = MISSING;
            else a[i] = a[i] + b[i];
          }
          deallocate(ctx,b, length * sizeof(float));
          state->sgrid[state->stop - 2] = a;
          state->stop--;
          break;
        case SUB_OP:
          a = state->sgrid[state->stop - 1];
          b = state->sgrid[state->stop - 2];
          for (i=0; i<length; i++) {
            if (IS_MISSING(a[i]) || IS_MISSING(b[i])) a[i] = MISSING;
            else a[i] = b[i] - a[i];
          }
          deallocate(ctx,b, length * sizeof(float));
          state->sgrid[state->stop - 2] = a;
          state->stop--;
          break;
        case MUL_OP:
          a = state->sgrid[state->stop - 1];
          b = state->sgrid[state->stop - 2];
          for (i=0; i<length; i++) {
            if (IS_MISSING(a[i]) || IS_MISSING(b[i])) a[i] = MISSING;
            else a[i] = a[i] * b[i];
          }
          deallocate(ctx,b, length * sizeof(float));
          state->sgrid[state->stop - 2] = a;
          state->stop--;
          break;
        case DIV_OP:
          a = state->sgrid[state->stop - 1];
          b = state->sgrid[state->stop - 2];
          for (i=0; i<length; i++) {
            if (IS_MISSING(a[i]) || IS_MISSING(b[i])) a[i] = MISSING;
            else a[i] = b[i] / a[i];
          }
          deallocate(ctx,b, length * sizeof(float));
          state->sgrid[state->stop - 2] = a;
          state->stop--;
          break;
        case POWER_OP:
          a = state->sgrid[state->stop - 1];
          b = state->sgrid[state->stop - 2];
          for (i=0; i<length; i++) {
            if (IS_MISSING(a[i]) || IS_MISSING(b[i])) a[i] = MISSING;
            else a[i] = pow(b[i], a[i]);
          }
          deallocate(ctx,b, length * sizeof(float));
          state->sgrid[state->stop - 2] = a;
          state->stop--;
          break;
        case NEGATE_OP:
          a = state->sgrid[state->stop - 1];
          for (i=0; i<length; i++) {
            if (IS_MISSING(a[i])) a[i] = MISSING;
            else a[i] = -a[i];
          }
          state->sgrid[state->stop - 1] = a;
          break;
        case FUNC_OP:
          ftype = state->args[state->curop];
          arg_count = numargs[ftype];
          for (i=0; i<arg_count; i++) {
            state->stop--;
            f[arg_count - 1 - i] = state->sgrid[state->stop];
          }
          a = f[0];
          switch (ftype) {
            case SQRT_FUNC:
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i])) a[i] = MISSING;
                else a[i] = sqrt(a[i]);
              }
              break;
            case EXP_FUNC:
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i])) a[i] = MISSING;
                else a[i] = exp(a[i]);
              }
              break;
            case LOG_FUNC:
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i])) a[i] = MISSING;
                else a[i] = log(a[i]);
              }
              break;
            case SIN_FUNC:
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i])) a[i] = MISSING;
                else a[i] = sin(a[i]);
              }
              break;
            case COS_FUNC:
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i])) a[i] = MISSING;
                else a[i] = cos(a[i]);
              }
              break;
            case TAN_FUNC:
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i])) a[i] = MISSING;
                else a[i] = tan(a[i]);
              }
              break;
            case ATAN_FUNC:
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i])) a[i] = MISSING;
                else a[i] = atan(a[i]);
              }
              break;
            case ABS_FUNC:
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i])) a[i] = MISSING;
                else a[i] = fabs(a[i]);
              }
              break;
            case MIN_FUNC:
              b = f[1];
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i]) || IS_MISSING(b[i])) a[i] = MISSING;
                else a[i] = a[i] < b[i] ? a[i] : b[i];
              }
              break;
            case MAX_FUNC:
              b = f[1];
              for (i=0; i<length; i++) {
                if (IS_MISSING(a[i]) || IS_MISSING(b[i])) a[i] = MISSING;
                else a[i] = a[i] > b[i] ? a[i] : b[i];
              }
              break;
            default:
              strcpy(mess, "Error:  illegal program step");
              return -1;
          }

          for (i=1; i<arg_count; i++) {
            deallocate(ctx,f[i], length * sizeof(float));
          }
          state->sgrid[state->stop] = a;
          state->stop++;
          break;
        default:
          strcpy(mess, "Error:  illegal program step");
          return -1;
      }
    }
    if (state->stop != 1) return -1;

    /* save/compress the result grid */
    install_new_grid( ctx, time, var, state->sgrid[0], nl, lowlev );
    deallocate(ctx,state->sgrid[0], length * sizeof(float));
  }
  return var;
}
Esempio n. 25
0
void Editor::calc_self()
{
    // Aendert die Mauskoordinaten ggf., also frueh aufrufen!
    map.calc_scrolling();

    // Wo ist die Maus auf dem Land?
    mx = map.get_mouse_x();
    my = map.get_mouse_y();

    const bool mouse_on_panel = hardware.get_my() > map.get_screen_yl();

    const int grid    = get_grid();
    const int mx_grid = (mx + grid/2) - Help::mod(mx, grid);
    const int my_grid = (my + grid/2) - Help::mod(my, grid);

    // Maus wird erst beim Zeichnen positioniert, damit auch die Unterfenster
    // davon profitieren, denn bei ihnen wird dieser main_loop uebersprungen.
    mouse_cursor.set_x_frame(0);
    mouse_cursor.set_y_frame(0);
    if (map.get_scrollable()
     && ((useR->scroll_right  && hardware.get_mrh())
      || (useR->scroll_middle && hardware.get_mmh())))
     mouse_cursor.set_x_frame(3);

    hover.clear();












    // Hotkey ohne Button: Cycle around all the buttons, and every button off
    if (hardware.key_once(useR->key_ed_grid)) {
        if (!panel[GRID_2 ].get_on()
         && !panel[GRID_CUSTOM].get_on()
         && !panel[GRID_16].get_on()) panel[GRID_2].set_on();
        else if (panel[GRID_2].get_on()) {
            panel[GRID_2 ].set_off();
            panel[GRID_CUSTOM].set_on();
        }
        else if (panel[GRID_CUSTOM].get_on()) {
            panel[GRID_CUSTOM].set_off();
            panel[GRID_16].set_on();
        }
        else panel[GRID_16].set_off();
    }

    // Moving objects with the arrow keys. This doesn't have an OSD button.
    // Testing for key_hold is good for this: If the drawing of the level is
    // slow, lots of keypresses get stuck in the buffer and the object(s) will
    // move on despite you've let got. Only moving the object(s) when you
    // first press the key (one could write a new function in Hardware for
    // this, of course) is also bad if the drawing is quick, because
    // you'd have to repeatedly tap the key to move it a distance.
    if (hardware.key_once(useR->key_ed_up)
     && hardware.key_hold(useR->key_ed_up)) {
        for (SelIt i = selection.begin(); i != selection.end(); ++i)
         i->o->set_y(i->o->get_y() - grid);
        if (!selection.empty()) draw_required = true;
    }
    else if (hardware.key_once(useR->key_ed_right)
     &&      hardware.key_hold(useR->key_ed_right)) {
        for (SelIt i = selection.begin(); i != selection.end(); ++i)
         i->o->set_x(i->o->get_x() + grid);
        if (!selection.empty()) draw_required = true;
    }
    else if (hardware.key_once(useR->key_ed_down)
     &&      hardware.key_hold(useR->key_ed_down)) {
        for (SelIt i = selection.begin(); i != selection.end(); ++i)
         i->o->set_y(i->o->get_y() + grid);
        if (!selection.empty()) draw_required = true;
    }
    else if (hardware.key_once(useR->key_ed_left)
     &&      hardware.key_hold(useR->key_ed_left)) {
        for (SelIt i = selection.begin(); i != selection.end(); ++i)
         i->o->set_x(i->o->get_x() - grid);
        if (!selection.empty()) draw_required = true;
    }

    // Buttons mit Hotkeys, die aber nicht auf normale Weise damit
    // assoziiert sind, werden jetzt speziell behandelt.
    // Es gibt bloede Ueberschneidungen mit dem Druecken und Loslassen von
    // Shift waehrend einer Mauszieh-Aktion, daher beheben wir das hier
    // von vornherein und nicht unten im Maus-Code.
    if (hardware.key_hold(useR->key_ed_sel_frame) && ! hardware.get_mlh())
     panel[SELECT_FRAME].set_on();
    if (hardware.key_release(useR->key_ed_sel_frame) && ! hardware.get_mlh())
     panel[SELECT_FRAME].set_off();

    if (hardware.key_hold(useR->key_ed_sel_add))
     panel[SELECT_ADD].set_on();
    if (hardware.key_release(useR->key_ed_sel_add))
     panel[SELECT_ADD].set_off();

    // Das Eindruecken von Buttons sperren, solange etwas umhergezogen wird:
    // Ansonsten wird die For-Schleife durchlaufen.
    if ((!hardware.get_mlh() && !hardware.get_mlr())
     || !mouse_hold_started_outside_panel || !mouse_on_panel)
     // Steuerleisten-Buttons abfragen
     for (unsigned int i = 0; i < panel.size(); ++i) {
        Api::BitmapButton& b = panel[i];
        if (b.get_clicked()) switch (i) {
        case FILE_NEW:
        case FILE_EXIT:
            save_lists();
            if (Level(useR->single_last_level) != level) {
                box_unsaved_data = new_box_unsaved_data(level);
                Api::Manager::add_focus(box_unsaved_data);
                b.set_on();
            }
            else if (i == FILE_NEW) delete_everything();
            else                    exit = true;
            break;

        case FILE_SAVE:
            if (useR->single_last_level.get_file().empty()) {
                // same as FILE_SAVE_AS
                b.set_on();
                browser_save = new Api::SaveBrowser(gloB->dir_levels,
                               gloB->ext_level,
                               useR->single_last_level,
                               Api::SaveBrowser::search_criterion_level,
                               Api::SaveBrowser::new_box_overwrite_level);
                browser_save->set_info_level_name(level.get_name());
                browser_save->set_info_filename(useR->single_last_level);
                Api::Manager::add_focus(browser_save);
            }
            else save_lists_and_level();
            break;

        case FILE_SAVE_AS:
            b.set_on();
            browser_save = new Api::SaveBrowser(gloB->dir_levels,
                               gloB->ext_level,
                               useR->single_last_level,
                               Api::SaveBrowser::search_criterion_level,
                               Api::SaveBrowser::new_box_overwrite_level);
            browser_save->set_info_level_name(level.get_name());
            browser_save->set_info_filename(useR->single_last_level);
            Api::Manager::add_focus(browser_save);
            break;

        case GRID_2:
        case GRID_CUSTOM:
        case GRID_16:
            {
                bool was_on = b.get_on();
                panel[GRID_2 ].set_off();
                panel[GRID_CUSTOM].set_off();
                panel[GRID_16].set_off();
                panel[i].set_on(!was_on);
            }
            break;

        case SELECT_ALL:
            selection.clear();
            for  (int type = Object::TERRAIN; type != Object::MAX; ++type)
             for (GraIt i = object[type].begin(); i != object[type].end(); ++i)
             selection.push_back(Selection(&object[type], i));
            break;

        case SELECT_FRAME:
        case SELECT_ADD:
            b.set_on(!b.get_on()); // Der Maus-Code kontrolliert, ob diese
            break;                 // Buttons eingeschaltet sind

        case SELECT_COPY:
            for (SelIt i = selection.begin(); i != selection.end(); ++i) {
                int offset = grid;
                while (offset < 8) offset *= 2;
                i->l->push_back(*i->o); // An einem Listenende anhaengen
                i->o = --i->l->end();   // Neue Position fuer den Auswahliter.
                i->o->set_x(i->o->get_x() + offset);
                i->o->set_y(i->o->get_y() + offset);
            }
            if (!selection.empty()) draw_required = true;
            break;

        case SELECT_DELETE:
            for (SelIt i = selection.begin(); i != selection.end(); ++i) {
                i->l->erase(i->o);
            }
            if (!selection.empty()) draw_required = true;
            selection.clear();
            break;

        case SELECT_MINUS: selection_fore_background(true,  false); break;
        case SELECT_PLUS:  selection_fore_background(false, false); break;
        case SELECT_BACK:  selection_fore_background(true,  true ); break;
        case SELECT_FRONT: selection_fore_background(false, true ); break;

        case SELECT_FLIP:
            flip_selection();
            if (!selection.empty()) draw_required = true;
            break;

        case SELECT_ROTATE:
            rotate_selection();
            if (!selection.empty()) draw_required = true;
            break;

        case SELECT_DARK:
            for (SelIt i = selection.begin(); i != selection.end(); ++i)
             if (i->l == &object[Object::TERRAIN])
             i->o->set_mode(i->o->get_mode() == Cutbit::DARK_EDITOR
              ? Cutbit::NORMAL : Cutbit::DARK_EDITOR);
            if (!selection.empty()) draw_required = true;
            break;

        case SELECT_NOOW:
            for (SelIt i = selection.begin(); i != selection.end(); ++i)
             if (i->l == &object[Object::TERRAIN])
             i->o->set_mode(i->o->get_mode() == Cutbit::NOOW_EDITOR
              ? Cutbit::NORMAL : Cutbit::NOOW_EDITOR);
            if (!selection.empty()) draw_required = true;
            break;

        case VIEW_ZOOM:
            b.set_on(!b.get_on());
            map.set_zoom(b.get_on());
            break;

        case MENU_SIZE:
            b.set_on();
            window_size     = new Api::WindowSize(level, map);
            Api::Manager::add_focus(window_size);
            break;

        case MENU_SCROLL:
            b.set_on();
            window_scroll   = new Api::WindowScroll(level, map);
            Api::Manager::add_focus(window_scroll);
            break;

        case MENU_VARS:
            b.set_on();
            window_variable = new Api::WindowVariables(level);
            Api::Manager::add_focus(window_variable);
            break;

        case MENU_SKILL:
            b.set_on();
            window_skill    = new Api::WindowSkill(level);
            Api::Manager::add_focus(window_skill);
            break;

        case HELP:
            b.set_on(!b.get_on());
            break;

        case ADD_TERRAIN:
            b.set_on();
            browser_bitmap = new Api::BitmapBrowser(
                             search_criterion_terrain,
                             useR->editor_last_dir_terrain,
                             Language::add_terrain,
                             browser_terrain_last_page);
            Api::Manager::add_focus(browser_bitmap);
            break;

        case ADD_STEEL:
            b.set_on();
            browser_bitmap = new Api::BitmapBrowser(
                             search_criterion_steel,
                             useR->editor_last_dir_steel,
                             Language::add_steel);
            Api::Manager::add_focus(browser_bitmap);
            break;

        case ADD_HATCH:
            b.set_on();
            browser_bitmap = new Api::BitmapBrowser(
                             search_criterion_hatch,
                             useR->editor_last_dir_hatch,
                             Language::add_hatch);
            Api::Manager::add_focus(browser_bitmap);
            break;

        case ADD_GOAL:
            b.set_on();
            browser_bitmap = new Api::BitmapBrowser(
                             search_criterion_goal,
                             useR->editor_last_dir_goal,
                             Language::add_goal);
            Api::Manager::add_focus(browser_bitmap);
            break;

        case ADD_DECO:
            b.set_on();
            browser_bitmap = new Api::BitmapBrowser(
                             search_criterion_deco,
                             useR->editor_last_dir_deco,
                             Language::add_deco);
            Api::Manager::add_focus(browser_bitmap);
            break;

        case ADD_HAZARD:
            b.set_on();
            browser_bitmap = new Api::BitmapBrowser(
                             search_criterion_hazard,
                             useR->editor_last_dir_hazard,
                             Language::add_hazard);
            Api::Manager::add_focus(browser_bitmap);
            break;

        default:
            break;
        }
    }













    // Dies verhindert Umherziehen und dergleichen, wenn das Maushalten
    // nicht im Spielfeld mit Objektwahl o. Ae. begann
    if (hardware.get_ml() && mouse_on_panel) {
        mouse_hold_started_outside_panel = false;
    }

    // Determine hover objects.
    // (Allerdings Hoverobjekt nicht beim Umherziehen waehlen.)
    // If no hover object found, then ignore transparency and go just by
    // the objects' selection boxes' sizes.
    if (! mouse_on_panel && hardware.get_mlh() < 2
     && ! panel[SELECT_FRAME].get_on()) {
        Selection s = find_under_mouse_cursor(FIND_BY_TRANSP);
        if (! s.is_valid()) s = find_under_mouse_cursor(FIND_BY_SELBOX);
        if (s.is_valid()) hover.push_back(s);
    }

    // Vielleicht doch klicken und Rahmen ziehen? Wenn man ins Nirvana
    // klickt, dann noch schnell den Button aktivieren
    if (!mouse_on_panel && !panel[SELECT_FRAME].get_on()
     && hardware.get_ml() && hover.empty()) {
        panel[SELECT_FRAME].set_on();
    }

    // Mehrere grosse Moeglichkeiten zur Auswahl
    // Moeglichkeit: Rahmen ziehen
    if (panel[SELECT_FRAME].get_on()) {
        // Rahmenziehen beginnt
        if (hardware.get_ml() && !mouse_on_panel) {
            mouse_hold_started_outside_panel = true;
            frame_start_x  = mx;
            frame_start_y  = my;
        }
        // Beim Rahmenziehen Objekte markieren, auch beim Loslassen diesen
        // Code nutzen, denn beim Loslassen wird einfach alles aus der
        // Hover-Liste in die Auswahl uebernommen!
        if ((hardware.get_mlh() || hardware.get_mlr())
         && mouse_hold_started_outside_panel) {
            int x1 = (frame_start_x < mx) ? frame_start_x : mx;
            int y1 = (frame_start_y < my) ? frame_start_y : my;
            int x2 = (frame_start_x > mx) ? frame_start_x : mx;
            int y2 = (frame_start_y > my) ? frame_start_y : my;
//            // Rahmen ueber dem Panel lassen, gaebe beim Torus sonst Kaese
//            if (hardware.is_mouse_over_panel()) {
//                y1 = frame_start_y;
//                y2 = map.get_screen_y()
//                   + (map.get_zoom() ? Level::min_y*3/4 : Level::min_y) - 2;
//                if (level.torus_y) y2 = Help::mod(y2, map.get_yl());
//                if (y1 < y2) std::swap(y1, y2);
//            }
            // Bei Toruskarten sollte der Rahmen so gezogen werden, dass er
            // nur im sichtbaren Bereich verlaeuft. Dieser Test funktioniert
            // auch, wenn der Zoom an ist!
            if (level.torus_x && x1 < map.get_screen_x()
                              && x2 > map.get_screen_x()) frame_torus_x=true;
            else                                           frame_torus_x=false;
            if (level.torus_y && y1 < map.get_screen_y()
                              && y2 > map.get_screen_y()) frame_torus_y=true;
            else                                           frame_torus_y=false;
            // Stopfe Gefundenes in die Hoverliste
            for (int type = Object::TERRAIN; type != Object::MAX; ++type)
             find_check_frame(object[Object::perm(type)], x1, y1, x2, y2);
            frame_draw_x1 = x1;
            frame_draw_y1 = y1;
            frame_draw_x2 = x2;
            frame_draw_y2 = y2;
            // Beim Loslassen alles aus der Hover-Liste in die Auswahl setzen
            if (hardware.get_mlr()) {
                if (!hardware.get_shift()) panel[SELECT_FRAME].set_off();
                // Kein CTRL gedrueckt - genau alles im Hover wird zur Auswahl
                if (!panel[SELECT_ADD].get_on()) selection.clear();
                for (SelIt i = hover.begin(); i != hover.end(); ++i) {
                    selection.push_back(*i);
                }
                // Radikal auf Dubletten ueberpruefen - zuvor hatte ich hier
                // etwas schlankeren Code stehen fuer CTRL-Auswahl, mit Ein-
                // fuehrung der Toruskarten kommen wir glaube ich nicht mehr
                // unter der O(n^2)-Loesung weg.
                // Kommen wir doch, die CTRL-Loesung von damals sollte reichen.
                // Mache ich aber (noch) nicht, kostet bisher noch nix.
                delete_dublicates_from_selection();
            }
            // Fertig mit dem Uebertragen in die Auswahl
        }
        // Rahmen fertig gezogen
    }



    // Weitere grosse Moeglichkeit:
    // Keinen Rahmen ziehen
    else {
        // Neuauswahl der Grafikobjekte
        if (hardware.get_ml() && !mouse_on_panel) {
            mouse_hold_started_outside_panel = true;
            // Wir haben hier garantiert etwas angeklickt, denn sonst
            // haette eine Abfrage oben bereits den SELECT_FRAME-Button
            // aktiviert.
            // Soll zur Auswahl hinzugefuegt werden (CTRL/entspr. Button)?
            // Falls das Element bereits in der Auswahl ist, wird es
            // wieder hieraus entfernt.
            if (panel[SELECT_ADD].get_on()) {
                bool is_already_in_selection = false;
                for (SelIt i = selection.begin(); i!=selection.end(); ++i){
                    if (*i == *hover.begin()) {
                        selection.erase(i);
                        is_already_in_selection = true;
                        hover.clear(); // Verhindert dunklen Rahmen, weil im
                                       // naechsten Tick umhergezogen wird
                        break;
                    }
                }
                if (!is_already_in_selection) {
                    selection.push_back(*hover.begin());
                }
            }
            // Nicht CTRL gedrueckt:
            // - Wenn in eine Auswahl geklickt, passiert nichts, denn man
            //   will ja moeglicherweise umherziehen
            // - Wenn noch nicht ausgewaehlt, dies als neue Auswahl nehmen
            else {
                bool is_already_in_selection = false;
                for (SelIt i = selection.begin(); i!=selection.end(); ++i){
                    if (*i == *hover.begin()) {
                        is_already_in_selection = true;
                        break;
                    }
                }
                if (!is_already_in_selection) {
                    selection.clear();
                    selection.push_back(*hover.begin());
                }
            }
            // Andere Dinge bei Mausklick
            mx_grid_last = mx_grid;
            my_grid_last = my_grid;
        }







        // Umherziehen von Objekten mit der Maus
        else if (hardware.get_mlh() && mouse_hold_started_outside_panel) {
            if (mx_grid != mx_grid_last || my_grid != my_grid_last) {
                for (SelIt i = selection.begin(); i != selection.end(); ++i) {
                    const int iox = i->o->get_x() + grid/2;
                    const int ioy = i->o->get_y() + grid/2;
                    i->o->set_x(
                        iox - Help::mod(iox, grid) - mx_grid_last + mx_grid
                    );
                    i->o->set_y(
                        ioy - Help::mod(ioy, grid) - my_grid_last + my_grid
                    );
                }
                if (!selection.empty()) draw_required = true;
            }
            mx_grid_last = mx_grid;
            my_grid_last = my_grid;

            if (selection.size() > 0 && mouse_on_panel) {
                mouse_cursor.set_y_frame(2);
            }
        }

        // Loslassen von umhergezogenen Objekten - nur wichtig fuer's
        // Wegschmeissen in das ewige Nirwana am unteren Bildschirmrand :-D
        else if (hardware.get_mlr() && mouse_hold_started_outside_panel) {
            if (mouse_on_panel) {
                // Komplette Auswahl loeschen
                for (SelIt i = selection.begin(); i != selection.end(); ++i) {
                    i->l->erase(i->o);
                }
                if (!selection.empty()) draw_required = true;
                selection.clear();
            }
        }
        // Ende Loslassen

    }
    // Ende der grossen Moeglichkeit fuer "Keinen Rahmen ziehen"


}
Esempio n. 26
0
/*
Evènement lors du changement d'une case de la grille
@params	p_widget	Elément ayant déclencher la fonction
@params	user_data	Données transmis au callback
*/
void cb_entry_modified(GtkWidget *p_widget, gpointer user_data){
    int i,row,col, value, incorrect = 0;
    char entry_value = *gtk_entry_get_text(GTK_ENTRY(p_widget));

    if(!isdigit(entry_value)){ //On empêche l'user de saisir autre chose que des chiffres
        gtk_entry_set_text(GTK_ENTRY(p_widget), "");
    }

    int grid[9][9] = {{0}};
    get_grid(grid);
    int grid_fixes[9][9] = {{0}};
    get_fixed_grid(grid_fixes);

    //On vérifit si grid_fixes est vide
    int emptyGridFixes = 1;
    for(i=0;i<=80;i++){
        row = floor(i/9);
        col = i%9;
        if(grid_fixes[col][row] != 0){emptyGridFixes = 0;break;}
    }

    for(i=0;i<81;i++){
        value = *gtk_entry_get_text(GTK_ENTRY(widgetCallback.entry3[i])) - '0'; //On récupère le char de la case
        if(value == -48) value = 0; //" " => 0

        row = floor(i/9);
        col = i%9;

        grid[col][row] = 0;

        if((!absentDeBloc(value, grid, col, row) || !absentDeColonne(value, grid, row) || !absentDeLigne(value, grid, col)) && grid_fixes[col][row] != 1 && value != 0){
            //La valeur n'est pas valide => on change le style de la case
            GdkColor red;
            gdk_color_parse("#d34836", &red);

            gtk_widget_modify_text(GTK_WIDGET(widgetCallback.entry3[i]), GTK_STATE_NORMAL, &red);
            incorrect++;
        }
        else if(grid_fixes[col][row] == 1 || emptyGridFixes){
            //Base de la grille => style noir
            GdkColor black;
            gdk_color_parse ("#000000", &black);
            gtk_widget_modify_text(GTK_WIDGET(widgetCallback.entry3[i]), GTK_STATE_NORMAL, &black);
        }
        else{
            //Case valide => style bleu
            GdkColor blue;
            gdk_color_parse ("#335D6A", &blue);
            gtk_widget_modify_text(GTK_WIDGET(widgetCallback.entry3[i]), GTK_STATE_NORMAL, &blue);
        }

        grid[col][row] = value;
    }

    if(incorrect == 0){ //Pas d'erreur
        //On vérifit si la grille est remplie
        int filledGrid = 1;
        for(i=0;i<=80;i++){
            row = floor(i/9);
            col = i%9;
            if(grid[col][row] == 0){filledGrid = 0;break;}
        }

        if(filledGrid){ //Rempli + pas d'erreur => grille résolue
            GtkWidget *p_dialog = gtk_message_dialog_new(GTK_WINDOW(widgetCallback.entry1),
                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
                                                        GTK_MESSAGE_INFO,
                                                        GTK_BUTTONS_CLOSE,
                                                        g_locale_to_utf8("Bravo la grille est résolue !", -1, NULL, NULL, NULL),
                                                        NULL);

            gtk_dialog_run (GTK_DIALOG (p_dialog));
            gtk_widget_destroy (p_dialog);
        }
    }

    //Parametres inutilises
    (void)p_widget;
    (void)user_data;
}
Esempio n. 27
0
static int get_arf_grid (Isis_Rmf_t *rmf, double **lo, double **hi, unsigned int *n) /*{{{*/
{
   Client_Data_t *cl = (Client_Data_t *)rmf->client_data;

   return get_grid (cl->arf, lo, hi, n);
}