Beispiel #1
0
/*
 * ei_main --
 *
 *	Main function of the application.
 */
int ei_main(int argc, char** argv)
{
	ei_size_t	screen_size		= {600, 600};
	ei_color_t	root_bgcol		= {0x52, 0x7f, 0xb4, 0xff};

	ei_widget_t*	frame;
	ei_size_t	frame_size		= {300,200};
	int		frame_x			= 150;
	int		frame_y			= 200;
	ei_color_t	frame_color		= {0x88, 0x88, 0x88, 0xff};
	ei_relief_t	frame_relief		= ei_relief_raised;
	int		frame_border_width	= 6;

	/* Create the application and change the color of the background. */
	ei_app_create(&screen_size, EI_FALSE);
	ei_frame_configure(ei_app_root_widget(), NULL, &root_bgcol, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

	/* Create, configure and place the frame on screen. */
	frame = ei_widget_create("frame", ei_app_root_widget());
	ei_frame_configure(frame, &frame_size, &frame_color,
			    &frame_border_width, &frame_relief, NULL, NULL, NULL, NULL,
			    NULL, NULL, NULL);
	ei_place(frame, NULL, &frame_x, &frame_y, NULL, NULL, NULL, NULL, NULL, NULL );

	/* Run the application's main loop. */
	ei_app_run();

	/* We just exited from the main loop. Terminate the application (cleanup). */
	ei_app_free();

	return (EXIT_SUCCESS);
}
Beispiel #2
0
int ei_main(int argc, char** argv)
{
	ei_size_t	screen_size	= {800, 800};
        ei_color_t      root_bgcol      = {0x52, 0x7f, 0xb4, 0xff};

        float           button_rel_x    = 0.2;
        float           button_rel_y    = 0.3;        
        float           button_rel_size_x = 0.5;
        float           button_rel_size_y = 0.5;      
        ei_color_t	button_color	= {0x88, 0x88, 0x88, 0xff};
        ei_color_t      text_color      = {0x00, 0x00, 0x00, 0xff};
        ei_relief_t     relief          = ei_relief_raised;
        int             button_border_width    = 2;
        char*           button_title    = "click";
        
        ei_size_t       window_size     = {400,400};
        char*           window_title    = "Hello World";
        ei_color_t      window_color    = {0xA0,0xA0,0xA0, 0xff};
        int             window_border_width    = 2;
        ei_bool_t       closable        = EI_TRUE;
        ei_axis_set_t   window_resizable = ei_axis_both;
        ei_point_t	window_position	 = {30, 10};        

        
        ei_widget_t*    button;
        ei_widget_t*    toplevel;

	ei_app_create(&screen_size, EI_FALSE); 
        ei_frame_configure(ei_app_root_widget(), NULL, &root_bgcol, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);        

        toplevel = ei_widget_create("toplevel", ei_app_root_widget());
        button = ei_widget_create("button", toplevel);
        
        ei_toplevel_configure(toplevel, &window_size, &window_color, &window_border_width, &window_title, &closable, &window_resizable, NULL);
        ei_button_configure(button, NULL, &button_color, 
                            &button_border_width, NULL, &relief, &button_title, NULL, &text_color, NULL,
                            NULL, NULL, NULL, &button_callback, NULL);

        ei_place(toplevel, NULL, &(window_position.x), &(window_position.y), NULL, NULL, NULL, NULL, NULL, NULL);
        ei_place(button, NULL, NULL, NULL, NULL,NULL, &button_rel_x, &button_rel_y, &button_rel_size_x, &button_rel_size_y );

	ei_bind(ei_ev_keydown, 		NULL, "all", process_key, NULL);

        ei_app_run();

	ei_unbind(ei_ev_keydown,	NULL, "all", process_key, NULL);

	ei_app_free();

	return (EXIT_SUCCESS);
}
Beispiel #3
0
/*
 * ei_main --
 *
 *	Main function of the application.
 */
int ei_main(int argc, char** argv)
{
	ei_size_t	screen_size		= {900, 900};
	ei_color_t	root_bgcol		= {0x52, 0x7f, 0xb4, 0xff};

	ei_widget_t*	frame;
	ei_size_t	frame_size		= {300,300};
	int		frame_x			= 0;
	int		frame_y			= 0;
	ei_color_t	frame_color		= {0x88, 0x88, 0x88, 0xff};
	ei_relief_t	frame_relief		= ei_relief_raised;
	int		frame_border_width	= 6;
    char *text = "DALIDA";


	/* Create the application and change the color of the background. */
	ei_app_create(&screen_size, EI_FALSE);
	ei_frame_configure(ei_app_root_widget(), NULL, &root_bgcol, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

	
	const char* filename = "misc/petit_soleil.png";
	ei_surface_t img = hw_image_load(filename,ei_app_root_surface());
        ei_rect_t img_rect = hw_surface_get_rect(img);
	ei_rect_t *img_rect_ptr = &img_rect;

	/* Create, configure and place the frame on screen. */
		for (int i = 1; i < 10; i++) {
    
	frame = ei_widget_create("frame", ei_app_root_widget());
	ei_frame_configure(frame, &frame_size, &frame_color,
			    &frame_border_width, &frame_relief, &text, NULL, NULL, (ei_anchor_t*)&i,
			    &img, &img_rect_ptr, (ei_anchor_t*)&i);
    frame_x = (300 * (i-1)) % 900;
    frame_y = ((i -1) / 3) * 300;
	ei_place(frame, NULL, &frame_x, &frame_y, NULL, NULL, NULL, NULL, NULL, NULL );
    }
	ei_bind(ei_ev_keydown,		NULL, "all", process_key, NULL);
	/* Run the application's main loop. */
	ei_app_run();
    
	ei_unbind(ei_ev_keydown,	NULL, "all", process_key, NULL);
	/* We just exited from the main loop. Terminate the application (cleanup). */
	ei_app_free();

	return (EXIT_SUCCESS);
}
Beispiel #4
0
int ei_main(int argc, char* argv[])
{
	ei_size_t	root_window_size		= { 1024, 768 };
	ei_color_t	root_bgcol			= { 0x52, 0x7f, 0xb4, 0xff };
	ei_bool_t	fullscreen			= EI_FALSE;
    
	ei_app_create(&root_window_size, fullscreen);
	ei_frame_configure(ei_app_root_widget(), NULL, &root_bgcol, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    
	if (argc > 1)
		create_puzzle_window(argv[1]);
	else
		create_puzzle_window(k_default_image_filename);
    
	ei_bind(ei_ev_keydown, NULL, "all", handle_keydown, NULL);
    
	ei_app_run();
	
	ei_app_free();
    
	return (EXIT_SUCCESS);
}
Beispiel #5
0
/*
 * ei_main --
 *
 *	Main function of the application.
 */
int ei_main(int argc, char** argv)
{
	ei_size_t	screen_size		= {400, 400};
	ei_color_t	root_bgcol		= {0x52, 0x7f, 0xb4, 0xff};
    
    ei_widget_t*	frame;
	int		frame_x		= 10;
	int		frame_y		= 10;
	int		frame_width		= 200;
	int		frame_height		= 150;
	ei_color_t	frame_color		= {0x01, 0x88, 0x88, 0xff};
	ei_relief_t	frame_relief		= ei_relief_sunken;
	int		frame_border_width	= 4;
    
	ei_widget_t*	button;
	int		button_x		= 10;
	int		button_y		= 10;
	int		button_width		= 100;
	int		button_height		= 40;
	ei_color_t	button_color		= {0x88, 0x88, 0x88, 0xff};
	char*		button_title		= "click";
	ei_color_t	button_text_color	= {0x00, 0x00, 0x00, 0xff};
	ei_relief_t	button_relief		= ei_relief_raised;
	int		button_border_width	= 2;
	ei_callback_t 	button_callback 	= button_press;
	
	/*ei_widget_t*	window;
	ei_size_t	window_size		= {200,200};
	char*		window_title		= "Hello World";
	ei_color_t	window_color		= {0xA0,0xA0,0xA0, 0xff};
	int		window_border_width	= 2;
	ei_bool_t	window_closable		= EI_TRUE;
	ei_axis_set_t	window_resizable 	= ei_axis_both;
	ei_point_t	window_position	 	= {30, 10};*/
    
	
	/* Create the application and change the color of the background. */
	ei_app_create(&screen_size, EI_FALSE);
	ei_frame_configure(ei_app_root_widget(), NULL, &root_bgcol, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    
	/* Create, configure and place a toplevel window on screen. */
	frame = ei_widget_create("frame", ei_app_root_widget());
	ei_frame_configure(frame, NULL, &frame_color, &frame_border_width,
                          &frame_relief, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	ei_place(frame, NULL, &(frame_x), &(frame_y), &frame_width, &frame_height, NULL, NULL, NULL, NULL);
    
	/* Create, configure and place a button as a descendant of the toplevel window. */
	button = ei_widget_create("button", frame);
	ei_button_configure(button, NULL, &button_color,
                        &button_border_width, NULL, &button_relief, &button_title, NULL, &button_text_color, NULL,
                        NULL, NULL, NULL, &button_callback, NULL);
	ei_place(button, NULL, &button_x, &button_y, &button_width, &button_height, NULL, NULL, NULL, NULL );
    
	/* Hook the keypress callback to the event. */
	ei_bind(ei_ev_keydown,		NULL, "all", process_key, NULL);
    
	/* Run the application's main loop. */
	ei_app_run();
    
	/* We just exited from the main loop. Terminate the application (cleanup). */
	ei_unbind(ei_ev_keydown,	NULL, "all", process_key, NULL);
	ei_app_free();
    
	return (EXIT_SUCCESS);
}
Beispiel #6
0
void create_puzzle_window(char* image_filename)
{
	/*ei_widget_t*		toplevel;
	ei_surface_t		image;
	ei_size_t		image_size;
	int			x, y;
	int			border_width		= 2;
	ei_point_t		place_coords;
	ei_point_t		current_position;
	ei_size_t		n;
	ei_size_t		toplevel_size;
	ei_size_t		image_rect_size;
	ei_size_t		tile_size		= ei_size(k_tile_size, k_tile_size);
	char*			title			= "Puzzle";
	ei_color_t		toplevel_bg		= {0xff, 0xff, 0xff, 0x60};
	ei_axis_set_t		resizable		= ei_axis_none;*/
    
    ei_widget_t*		frame;
	ei_surface_t		image;
	ei_size_t		image_size;
	int			x, y;
	int			border_width		= 2;
	ei_point_t		place_coords;
	ei_point_t		current_position;
	ei_size_t		n;
	ei_size_t		toplevel_size;
	ei_size_t		image_rect_size;
	ei_size_t		tile_size		= ei_size(k_tile_size, k_tile_size);
	ei_color_t		toplevel_bg		= {0xff, 0xff, 0xff, 0x60};
	ei_axis_set_t		resizable		= ei_axis_none;
    
	ei_widget_t*		button;
	ei_color_t		grey			= {0x88, 0x88, 0x88, 0xff};
	int			corner_radius		= 0;
	ei_relief_t		relief			= ei_relief_raised;
	ei_rect_t		img_rect;
	ei_rect_t*		img_rect_ptr		= &img_rect;
	ei_callback_t		callback		= handle_tile_press;
	
	puzzle_t*		puzzle;
	tile_t*			tile;
    
	image		= hw_image_load(image_filename, ei_app_root_surface());
	image_size	= hw_surface_get_size(image);
	n		= ei_size(image_size.width / k_tile_size, image_size.height / k_tile_size);
    
	frame	= ei_widget_create("frame", ei_app_root_widget());
	toplevel_size	= ei_size(n.width*k_tile_size, n.height*k_tile_size);
	border_width	= 0;
	ei_frame_configure(frame, &toplevel_size, &toplevel_bg, &border_width, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	ei_place(frame, NULL, &(g_toplevel_position.x), &(g_toplevel_position.y), NULL, NULL, NULL, NULL, NULL, NULL);
	g_toplevel_position = ei_point_add(g_toplevel_position, ei_point(12, 12));
    
	puzzle		= (puzzle_t*)malloc(sizeof(*puzzle));
	puzzle->n	= n;
	puzzle->tiles	= (tile_t*) malloc(n.width*n.height*sizeof(tile_t));
	puzzle->current	= (tile_t**)malloc(n.width*n.height*sizeof(tile_t*));
    
	border_width	= 2;
	image_rect_size	= ei_size_sub(tile_size, ei_size(2*border_width, 2*border_width));
    
	for (y = 0; y < n.height; y++) {
		for (x = 0; x < n.width; x++) {
			current_position	= ei_point(x, y);
			if ((x == n.width - 1) && (y == n.height - 1)) {
				puzzle->current[index_at(puzzle, current_position)] = NULL;
				continue;
			}
			button			= ei_widget_create("button", frame);
			img_rect		= ei_rect(ei_point(x*k_tile_size+border_width, y*k_tile_size+border_width),
                                      image_rect_size);
			tile			= tile_memory_at(puzzle, ei_point(x, y));
			printf("puzzle.c WIDTH::%i\n",img_rect_ptr->size.width);
			ei_button_configure(button, &tile_size, &grey, &border_width, &corner_radius, &relief, NULL, NULL, NULL,
								NULL, &image, &img_rect_ptr, NULL, &callback, (void*)&tile);
			place_coords		= place_coordinates(current_position);
			ei_place(button, NULL, &(place_coords.x), &(place_coords.y), NULL, NULL, NULL, NULL, NULL, NULL);
            
			tile->puzzle		= puzzle;
			tile->button		= button;
			tile->original_position	= current_position;
			tile->current_position	= current_position;
            
			puzzle->current[index_at(puzzle, current_position)] = tile;
		}
	}
}
Beispiel #7
0
void placerRunfunc(struct ei_widget_t*	widget)
{
    ei_geometry_placer_t* pl;
    ei_rect_t parentRect;
    ei_widget_t* child;
    
    // Il faut que le widget possède un manager de geometrie de type placer
    if(widget->geom_params == NULL)
	return;
    if(widget->geom_params->manager == NULL)
	return;
    if(strcmp(widget->geom_params->manager->name, "placer") != 0)
	return;
    
    pl = (ei_geometry_placer_t*)widget->geom_params->manager;
    
    // Si c'est la fenetre racine ses coordonnées reste toujours à (0,0)
    if(widget == ei_app_root_widget())
	return;
    else
	parentRect = *(widget->parent->content_rect);
	
    // On modifie la taille du widget
    widget->screen_location.size.width = pl->rel_width * parentRect.size.width + pl->width;
    widget->screen_location.size.height = pl->rel_height * parentRect.size.height + pl->height;
    
    // On modifie sa position en fonction de son anchor
    switch(pl->anchor)
    {
	case ei_anc_none:	// Pas d'ancrage -> nord ouest
	case ei_anc_northwest:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y;
	    break;
	case ei_anc_north:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x - (widget->screen_location.size.width)/2;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y;
	    break;
	case ei_anc_northeast:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x - widget->screen_location.size.width;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y;
	    break;
	case ei_anc_east:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x - widget->screen_location.size.width;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y - (widget->screen_location.size.height)/2;
	    break;
	case ei_anc_southeast:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x - widget->screen_location.size.width;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y - widget->screen_location.size.height;
	    break;
	case ei_anc_south:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x - (widget->screen_location.size.width)/2;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y - widget->screen_location.size.height;
	    break;
	case ei_anc_southwest:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y - widget->screen_location.size.height;
	    break;
	case ei_anc_west:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y - (widget->screen_location.size.height)/2;
	    break;
	case ei_anc_center:
	    widget->screen_location.top_left.x = parentRect.top_left.x + pl->rel_x * parentRect.size.width + pl->x - (widget->screen_location.size.width)/2;
	    widget->screen_location.top_left.y = parentRect.top_left.y + pl->rel_y * parentRect.size.height + pl->y - (widget->screen_location.size.height)/2;
	    break;
    }
    
    // On modifie son content_rect en fonction de sa classe
    widget->wclass->geomnotifyfunc(widget, widget->screen_location);
    
    // On deplace les widget enfant
    child = widget->children_head;
    while(child != NULL)
    {
	placerRunfunc(child);
	child = child->next_sibling;
    }
}