void ei_geomnotify_button(ei_widget_t *widget, ei_rect_t rect) { *(widget->content_rect) = ei_rect( ei_point_add( rect.top_left, ei_point( *ei_button(widget)->border_width, *ei_button(widget)->border_width)), ei_size( rect.size.width - 2 * *ei_button(widget)->border_width, rect.size.height - 2 * *ei_button(widget)->border_width)); }
/* Modifie l'Etat du bouton*/ void set_button_press(ei_widget_t * button) { ei_geomnotify_button(button, ei_rect( ei_point_add( button->screen_location.top_left, ei_point( EI_BUTTON_SINK_LENGHT, EI_BUTTON_SINK_LENGHT)), button->screen_location.size)); *ei_button(button)->relief = ei_relief_sunken; ei_app_invalidate_rect(&button->screen_location); if(*ei_button(button)->callback) ei_bind(ei_ev_mouse_buttonup, button, NULL, *ei_button(button)->callback, ei_button(button)->user_param); }
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; } } }
void ei_runfunc_placer(struct ei_widget_t* widget) { // we load the location of the father widget ei_rect_t* container = widget->parent->content_rect; ei_geometrymanager_param_placer_t* prm_placer = (ei_geometrymanager_param_placer_t*)widget->geom_params; float width, height ; assert(prm_placer); assert(prm_placer->rel_width); width = container->size.width * *(prm_placer->rel_width) + *(prm_placer->width); height = container->size.height * *(prm_placer->rel_height) + *(prm_placer->height); ei_point_t pos_rel; switch (*(prm_placer->anchor)) { case ei_anc_none: case ei_anc_northwest: pos_rel = ei_point_zero(); break; case ei_anc_center: pos_rel = ei_point(width / 2, height / 2); break; case ei_anc_north: pos_rel = ei_point(width / 2, 0); break; case ei_anc_northeast: pos_rel = ei_point(width , 0); break; case ei_anc_east: pos_rel = ei_point(width, height / 2); break; case ei_anc_southeast: pos_rel = ei_point(width, height ); break; case ei_anc_south: pos_rel = ei_point(width / 2, height); break; case ei_anc_southwest: pos_rel = ei_point(0 , height ); break; case ei_anc_west: pos_rel = ei_point(0 , height / 2 ); break; } ei_point_t pos_abs = ei_point( container->size.width * *(prm_placer->rel_x) + *(prm_placer->x), container->size.height * *(prm_placer->rel_y) + *(prm_placer->y)); // ei_app_invalidate_rect(&widget->screen_location); widget->screen_location = ei_rect( ei_point_add(ei_point_sub(pos_abs, pos_rel),container->top_left), ei_size(width, height)); ei_app_invalidate_rect(&widget->screen_location); widget->wclass->geomnotifyfunc(widget, widget->screen_location); ei_widget_t * current = widget->children_head; while(current) { if(current->geom_params) { current->geom_params->manager->runfunc(current); } current = current->next_sibling; } }