コード例 #1
0
ファイル: frame.c プロジェクト: ogrergo/Projet_C_IG
/*
 * 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);
}
コード例 #2
0
ファイル: ei_draw_tools.c プロジェクト: Benji118/c_ig
// Dessine l'image d'un widget
void ei_draw_widget_img(	ei_surface_t	surface,
							ei_widget_t*	widget,
							ei_surface_t	img,
							ei_rect_t*		img_rect,
							ei_anchor_t		anchor,
							int				button_border_width	)
{	
    // Paramètres du widget
    ei_point_t wtopleft	= ei_point_add( widget->screen_location.top_left,
            ei_point(2*button_border_width, 2*button_border_width) );
    ei_size_t wsize = ei_size_sub( widget->screen_location.size,
            ei_size(4*button_border_width, 4*button_border_width) );

    // Variables à calculer
    ei_rect_t dst_widget_rect;
    ei_rect_t src_image_rect;

    /***********************************************/
    /* ETAPE 1 : CALCUL DE LA TAILLE DE DST ET SRC */
    /***********************************************/	

    ei_size_t img_size;
    if (img_rect != NULL) {
        img_size = img_rect->size;
    } else {
        img_size = hw_surface_get_size(img);
    }

    // Calcul de la largeur de la zone de copie
    if (img_size.width > wsize.width) {
        src_image_rect.size.width = wsize.width;
        dst_widget_rect.size.width = wsize.width;
    } else {
        src_image_rect.size.width = img_size.width;
        dst_widget_rect.size.width = img_size.width;
    }
    // Calcul de la hauteur de la zone de copie
    if (img_size.height > wsize.height) {
        src_image_rect.size.height = wsize.height;
        dst_widget_rect.size.height = wsize.height;
    } else {
        src_image_rect.size.height = img_size.height;
        dst_widget_rect.size.height = img_size.height;
    }

    /*************************************/
    /* ETAPE 2 : CALCUL DES DEUX TOPLEFT */
    /*************************************/	

    // Calcul du topleft de la destination
    ei_switch_anchor(anchor, &(dst_widget_rect.top_left),
            dst_widget_rect.size, wtopleft, wsize);

    // Calcul du topleft de la source
    if (img_rect != NULL) {
        src_image_rect.top_left = img_rect->top_left;
    //    fprintf(stderr, "x %i\n", img_rect->top_left.x);
    //    fprintf(stderr, "y %i\n", img_rect->top_left.y);
    } else {
        // Par défaut je prend le coin en haut à gauche de l'image
        ei_rect_t rect_total = hw_surface_get_rect(img);
        src_image_rect.top_left = rect_total.top_left;
    }

    /*************************************************************/
    /* ETAPE 2bis : RECALCUL SI SORTIE DU CADRE PRINCIPAL (ROOT) */
    /*************************************************************/	

    ei_surface_t display_surface = ei_app_root_surface();
    ei_rect_t display_rect = hw_surface_get_rect(display_surface);

    int cut;

    // Cas 1 : sortie à gauche
    cut = display_rect.top_left.x - dst_widget_rect.top_left.x;
    if	( cut > 0 ) {
        // Changement de DST
        dst_widget_rect.top_left.x = display_rect.top_left.x;
        dst_widget_rect.size.width = dst_widget_rect.size.width - cut;
        // Changement de SRC
        src_image_rect.top_left.x = src_image_rect.top_left.x + cut;
        src_image_rect.size = dst_widget_rect.size;
    }

    // Cas 2 : sortie à droite
    cut = dst_widget_rect.top_left.x + dst_widget_rect.size.width
        - display_rect.top_left.x - display_rect.size.width;
    if	( cut > 0 ) {
        // Changement de DST
        dst_widget_rect.size.width = dst_widget_rect.size.width - cut;
        // Changement de SRC
        src_image_rect.size = dst_widget_rect.size;
    }


    // Cas 3 : sortie en haut
    cut = display_rect.top_left.y - dst_widget_rect.top_left.y;
    if	( cut > 0 ) {
        // Changement de DST
        dst_widget_rect.top_left.y = display_rect.top_left.y;
        dst_widget_rect.size.height = dst_widget_rect.size.height - cut;
        // Changement de SRC
        src_image_rect.top_left.y = src_image_rect.top_left.y + cut;
        src_image_rect.size = dst_widget_rect.size;
    }

    // Cas 4 : sortie en bas
    cut = dst_widget_rect.top_left.y + dst_widget_rect.size.height
        - display_rect.top_left.y - display_rect.size.height;
    if	( cut > 0 ) {
        // Changement de DST
        dst_widget_rect.size.height = dst_widget_rect.size.height - cut;
        // Changement de SRC
        src_image_rect.size = dst_widget_rect.size;
    }

    /*****************************************/
    /* ETAPE 3 : COPIE DE L'IMAGE A AFFICHEE */
    /*****************************************/	

    hw_surface_lock(img);
    ei_copy_surface(surface, &dst_widget_rect, img, &src_image_rect, EI_FALSE);		
    hw_surface_unlock(img);

}