Fix resizing.

SVN revision: 42967
v-1.6.0
titan 13 years ago committed by titan
parent b05ae06991
commit ded2e589e6
  1. 403
      src/bin/ephoto_table.c

@ -1,28 +1,38 @@
#include "ephoto.h"
static void image_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void move_left(void *data, Evas_Object *obj, const char *emission, const char *source);
static void move_right(void *data, Evas_Object *obj, const char *emission, const char *source);
static void connect_callback(void *data, Ethumb_Client *client, Eina_Bool success);
static void thumb_generated(void *data, Ethumb_Client *client, int id, const char *file, const char *key,
const char *thumb_path, const char *thumb_key,
Eina_Bool success);
typedef struct _Smart_Data Smart_Data;
struct _Smart_Data
{
Evas_Object *obj;
int visiblew;
int visibleh;
int paddingw;
int paddingh;
int tw;
int th;
int x;
int y;
int itemw;
int itemh;
int pagew;
int pageh;
int padw;
int padh;
int w;
int h;
int x;
int y;
int columns;
int rows;
int cur_col;
int cur_row;
int tw;
int th;
int items_per_page;
int current_head;
int current_page;
int item_w, item_h;
int items_per_page;
int total_pages;
int visible_items;
Eina_List *items;
Eina_List *images;
};
@ -42,23 +52,40 @@ static void _table_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
static void _table_smart_clip_set(Evas_Object *obj, Evas_Object *clip);
static void _table_smart_clip_unset(Evas_Object *obj);
static void move_left(void *data, Evas_Object *obj, const char *emission, const char *source);
static void move_right(void *data, Evas_Object *obj, const char *emission, const char *source);
static void connect_callback(void *data, Ethumb_Client *client, Eina_Bool success);
static void thumb_generated(void *data, Ethumb_Client *client, int id, const char *file, const char *key,
const char *thumb_path, const char *thumb_key,
Eina_Bool success);
static void image_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Eina_List *node;
Evas_Event_Mouse_Down *ev;
Smart_Data *sd;
ev = event_info;
sd = evas_object_smart_data_get(em->image_browser);
if (ev->flags == EVAS_BUTTON_DOUBLE_CLICK)
{
edje_object_signal_emit(em->image_browser, "ephoto.browser.hidden", "ephoto");
node = evas_object_data_get(obj, "image");
hide_image_browser();
show_flow_view(node, sd->images);
return;
}
if (obj == em->sel)
return;
if (em->sel)
edje_object_signal_emit(em->sel, "ephoto.thumb.deselected", "ephoto");
edje_object_signal_emit(obj, "ephoto.thumb.selected", "ephoto");
em->sel = obj;
}
static void move_left(void *data, Evas_Object *obj, const char *emission, const char *source)
{
ephoto_table_prev_page(em->image_browser);
printf("Left\n");
}
static void move_right(void *data, Evas_Object *obj, const char *emission, const char *source)
{
ephoto_table_next_page(em->image_browser);
printf("Right\n");
}
static void connect_callback(void *data, Ethumb_Client *client, Eina_Bool success)
@ -125,32 +152,6 @@ static void thumb_generated(void *data, Ethumb_Client *client, int id, const cha
}
}
static void image_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Eina_List *node;
Evas_Event_Mouse_Down *ev;
Smart_Data *sd;
ev = event_info;
sd = evas_object_smart_data_get(em->image_browser);
if (ev->flags == EVAS_BUTTON_DOUBLE_CLICK)
{
edje_object_signal_emit(em->image_browser, "ephoto.browser.hidden", "ephoto");
node = evas_object_data_get(obj, "image");
hide_image_browser();
show_flow_view(node, sd->images);
return;
}
if (obj == em->sel)
return;
if (em->sel)
edje_object_signal_emit(em->sel, "ephoto.thumb.deselected", "ephoto");
edje_object_signal_emit(obj, "ephoto.thumb.selected", "ephoto");
em->sel = obj;
}
Evas_Object *ephoto_table_add(Evas *e)
{
_table_smart_init();
@ -164,11 +165,42 @@ void ephoto_table_padding_set(Evas_Object *obj, int paddingw, int paddingh)
sd = evas_object_smart_data_get(obj);
if (!sd)
return;
sd->paddingw = paddingw;
sd->paddingh = paddingh;
sd->items_per_page = (sd->visiblew / sd->item_w) * (sd->visibleh / sd->item_h);
sd->padw = paddingw;
sd->padh = paddingh;
if (sd->pagew && sd->pageh)
ephoto_table_viewport_set(obj, sd->pagew, sd->pageh);
}
void ephoto_table_viewport_set(Evas_Object *obj, int w, int h)
{
Smart_Data *sd;
char text[PATH_MAX];
int pages, remain;
sd = evas_object_smart_data_get(obj);
if (!sd)
return;
evas_object_resize(sd->obj, w, h);
sd->pagew = w;
sd->pageh = h;
sd->rows = sd->pageh/(sd->padh+sd->itemh);
sd->columns = sd->pagew/(sd->padw+sd->itemw);
sd->items_per_page = sd->rows*sd->columns;
pages = eina_list_count(sd->images)/sd->items_per_page;
remain = eina_list_count(sd->images)%sd->items_per_page;
if (remain > 0)
pages++;
if (pages <= sd->current_page)
sd->total_pages = sd->current_page;
else
sd->total_pages = pages;
snprintf(text, PATH_MAX, "Page: %d of %d", sd->current_page, sd->total_pages);
edje_object_part_text_set(sd->obj, "ephoto.text.object", text);
_table_smart_reconfigure(sd);
}
void ephoto_table_pack(Evas_Object *obj, char *image)
{
Smart_Data *sd;
@ -178,10 +210,12 @@ void ephoto_table_pack(Evas_Object *obj, char *image)
const char *thumb;
sd = evas_object_smart_data_get(obj);
if (!sd)
return;
sd->images = eina_list_append(sd->images, strdup(image));
if (sd->visible_items+1 > sd->items_per_page)
if (sd->cur_row > sd->rows)
{
char text[PATH_MAX];
int pages, remain;
@ -204,10 +238,9 @@ void ephoto_table_pack(Evas_Object *obj, char *image)
edje_object_signal_emit(img, "ephoto.thumb.visible", "ephoto");
evas_object_data_set(img, "image", eina_list_nth_list(sd->images, eina_list_count(sd->images)-1));
evas_object_resize(img, sd->item_w, sd->item_h);
evas_object_size_hint_min_set(img, sd->item_w, sd->item_h);
evas_object_size_hint_max_set(img, sd->item_w, sd->item_h);
sd->visible_items++;
evas_object_resize(img, sd->itemw, sd->itemh);
evas_object_size_hint_min_set(img, sd->itemw, sd->itemh);
evas_object_size_hint_max_set(img, sd->itemw, sd->itemh);
i = evas_imaging_image_load(image, NULL);
evas_imaging_image_size_get(i, &w, &h);
@ -227,45 +260,24 @@ void ephoto_table_pack(Evas_Object *obj, char *image)
evas_imaging_image_free(i);
sd->tw += (sd->item_w + sd->paddingw);
sd->items = eina_list_append(sd->items, img);
if (sd->tw+(sd->item_w + sd->paddingw) >= sd->visiblew)
if (sd->cur_col == sd->columns)
{
sd->th += (sd->item_h + sd->paddingh);
sd->tw = 60;
sd->tw += sd->itemw;
if (sd->cur_row == sd->rows)
sd->th += sd->itemh;
else
sd->th += (sd->itemh + sd->padh);
sd->tw = 60;
sd->cur_row++;
sd->cur_col = 1;
}
}
void ephoto_table_viewport_set(Evas_Object *obj, int w, int h)
{
Smart_Data *sd;
char text[PATH_MAX];
int pages, remain;
sd = evas_object_smart_data_get(obj);
if ((sd->visiblew == w) && (sd->visibleh == h))
return;
sd->visiblew = w;
sd->visibleh = h;
sd->items_per_page = (sd->visiblew / sd->item_w) * (sd->visibleh / sd->item_h);
evas_object_resize(sd->obj, sd->visiblew, sd->visibleh);
if (!eina_list_count(sd->items))
return;
pages = eina_list_count(sd->images)/sd->items_per_page;
remain = eina_list_count(sd->images)%sd->items_per_page;
if (remain > 0)
pages++;
if (pages <= sd->current_page)
sd->total_pages = sd->current_page;
else
sd->total_pages = pages;
snprintf(text, PATH_MAX, "Page: %d of %d", sd->current_page, sd->total_pages);
edje_object_part_text_set(sd->obj, "ephoto.text.object", text);
_table_smart_reconfigure(sd);
{
sd->cur_col++;
sd->tw += (sd->itemw + sd->padw);
}
}
void ephoto_table_next_page(Evas_Object *obj)
@ -381,50 +393,61 @@ static void _table_smart_change_page(Smart_Data *sd, int direction)
sd->tw = 60;
sd->th = 75;
sd->visible_items = 0;
for(j =0; j <= sd->items_per_page && eina_list_data_get(iterator) != NULL; j++)
sd->cur_row = 1;
sd->cur_col = 1;
for(j = 0; (j <= sd->items_per_page) && eina_list_data_get(iterator) != NULL; j++)
{
i = eina_list_data_get(iterator);
evas_object_show(i);
evas_object_move(i, sd->tw, sd->th);
edje_object_signal_emit(i, "ephoto.thumb.visible", "ephoto");
sd->visible_items++;
if (sd->cur_row <= sd->rows)
{
i = eina_list_data_get(iterator);
evas_object_show(i);
evas_object_move(i, sd->tw, sd->th);
edje_object_signal_emit(i, "ephoto.thumb.visible", "ephoto");
sd->tw += (sd->item_w+sd->paddingw);
if (sd->cur_col == sd->columns)
sd->tw += sd->itemw;
else
sd->tw += (sd->itemw + sd->padw);
if (sd->tw+(sd->item_w+sd->paddingw) >= sd->visiblew)
{
sd->th += (sd->item_h+sd->paddingh);
sd->tw = 60;
}
if (sd->cur_col == sd->columns)
{
if (sd->cur_row == sd->rows)
sd->th += sd->itemh;
else
sd->th += (sd->itemh + sd->padh);
sd->tw = 60;
sd->cur_row++;
sd->cur_col = 1;
}
else
sd->cur_col++;
};
iterator = eina_list_next(iterator);
iteratorb = eina_list_next(iteratorb);
}
if (sd->visible_items < sd->items_per_page)
if (sd->cur_row <= sd->rows)
{
for (j=0; j <= sd->items_per_page && eina_list_data_get(iteratorb) != NULL; j++)
for (j = 0; (j <= sd->items_per_page) && eina_list_data_get(iterator) != NULL; j++)
{
if (sd->visible_items+1 > sd->items_per_page)
if (sd->cur_row > sd->rows)
return;
image = eina_list_data_get(iteratorb);
img = edje_object_add(em->e);
edje_object_file_set(img, PACKAGE_DATA_DIR "/themes/default/ephoto.edj", "/ephoto/thumb/shadow");
evas_object_move(img, sd->tw, sd->th);
evas_object_show(img);
evas_object_event_callback_add(img, EVAS_CALLBACK_MOUSE_UP, image_clicked, NULL);
evas_object_move(img, sd->tw, sd->th);
edje_object_signal_emit(img, "ephoto.thumb.visible", "ephoto");
evas_object_data_set(img, "image", iteratorb);
evas_object_data_set(img, "image", eina_list_nth_list(sd->images, eina_list_count(sd->images)-1));
evas_object_resize(img, sd->item_w, sd->item_h);
evas_object_size_hint_min_set(img, sd->item_w, sd->item_h);
evas_object_size_hint_max_set(img, sd->item_w, sd->item_h);
sd->visible_items++;
evas_object_resize(img, sd->itemw, sd->itemh);
evas_object_size_hint_min_set(img, sd->itemw, sd->itemh);
evas_object_size_hint_max_set(img, sd->itemw, sd->itemh);
im = evas_imaging_image_load(image, NULL);
evas_imaging_image_size_get(im, &w, &h);
@ -432,34 +455,43 @@ static void _table_smart_change_page(Smart_Data *sd, int direction)
{
ethumb_client_file_set(em->thumb_cli, image, NULL);
if (!ethumb_client_thumb_exists(em->thumb_cli))
ethumb_client_generate(em->thumb_cli, thumb_generated, img, NULL);
else
{
ethumb_client_thumb_path_get(em->thumb_cli, &thumb, NULL);
thumb_generated(img, em->thumb_cli, 0, image, NULL, thumb, NULL, EINA_TRUE);
}
ethumb_client_generate(em->thumb_cli, thumb_generated, img, NULL);
else
{
ethumb_client_thumb_path_get(em->thumb_cli, &thumb, NULL);
thumb_generated(img, em->thumb_cli, 0, image, NULL, thumb, NULL, EINA_TRUE);
}
}
else
thumb_generated(img, em->thumb_cli, 0, image, NULL, image, NULL, EINA_TRUE);
evas_imaging_image_free(im);
sd->tw += (sd->item_w + sd->paddingw);
sd->items = eina_list_append(sd->items, img);
if (sd->cur_col == sd->columns)
sd->tw += sd->itemw;
else
sd->tw += (sd->itemw + sd->padw);
sd->items = eina_list_append(sd->items, img);
if (sd->tw+(sd->item_w + sd->paddingw) >= sd->visiblew)
if (sd->cur_col == sd->columns)
{
sd->th += (sd->item_h + sd->paddingh);
sd->tw = 60;
if (sd->cur_row == sd->rows)
sd->th += sd->itemh;
else
sd->th += (sd->itemh + sd->padh);
sd->tw = 60;
sd->cur_row++;
sd->cur_col = 1;
}
else
sd->cur_col++;
iteratorb = eina_list_next(iteratorb);
}
}
return;
}
static void _table_smart_reconfigure(Smart_Data *sd)
{
Evas_Imaging_Image *im;
@ -469,6 +501,9 @@ static void _table_smart_reconfigure(Smart_Data *sd)
int w, h, j;
Eina_List *iterator, *iteratorb;
if (!sd->images)
return;
if (sd->current_page == 1)
{
iterator = sd->items;
@ -483,13 +518,14 @@ static void _table_smart_reconfigure(Smart_Data *sd)
sd->tw = 60;
sd->th = 75;
sd->visible_items = 0;
sd->cur_row = 1;
sd->cur_col = 1;
for(j =0; j <= sd->items_per_page && eina_list_data_get(iterator) != NULL; j++)
for(j = 0; (j <= sd->items_per_page) && eina_list_data_get(iterator) != NULL; j++)
{
i = eina_list_data_get(iterator);
if (sd->visible_items+1 > sd->items_per_page)
if (sd->cur_row > sd->rows)
{
while(eina_list_data_get(iterator) != NULL)
{
@ -506,40 +542,46 @@ static void _table_smart_reconfigure(Smart_Data *sd)
evas_object_move(i, sd->tw, sd->th);
edje_object_signal_emit(i, "ephoto.thumb.visible", "ephoto");
sd->visible_items++;
sd->tw += (sd->item_w+sd->paddingw);
if (sd->cur_col == sd->columns)
sd->tw += sd->itemw;
else
sd->tw += (sd->itemw + sd->padw);
if (sd->tw+(sd->item_w+sd->paddingw) >= sd->visiblew)
{
sd->th += (sd->item_h+sd->paddingh);
sd->tw = 60;
}
if (sd->cur_col == sd->columns)
{
if (sd->cur_row == sd->rows)
sd->th += sd->itemh;
else
sd->th += (sd->itemh + sd->padh);
sd->tw = 60;
sd->cur_row++;
sd->cur_col = 1;
}
else
sd->cur_col++;
}
iterator = eina_list_next(iterator);
iteratorb = eina_list_next(iteratorb);
}
if (sd->visible_items < sd->items_per_page)
if (sd->cur_row <= sd->rows)
{
for (j=0; j <= sd->items_per_page && eina_list_data_get(iteratorb) != NULL; j++)
for (j = 0; (j <= sd->items_per_page) && eina_list_data_get(iteratorb) != NULL; j++)
{
if (sd->visible_items+1 > sd->items_per_page)
if (sd->cur_row > sd->rows)
return;
image = eina_list_data_get(iteratorb);
img = edje_object_add(em->e);
edje_object_file_set(img, PACKAGE_DATA_DIR "/themes/default/ephoto.edj", "/ephoto/thumb/shadow");
evas_object_move(img, sd->tw, sd->th);
evas_object_show(img);
evas_object_event_callback_add(img, EVAS_CALLBACK_MOUSE_UP, image_clicked, NULL);
evas_object_move(img, sd->tw, sd->th);
edje_object_signal_emit(img, "ephoto.thumb.visible", "ephoto");
evas_object_data_set(img, "image", iteratorb);
evas_object_data_set(img, "image", eina_list_nth_list(sd->images, eina_list_count(sd->images)-1));
evas_object_resize(img, sd->item_w, sd->item_h);
evas_object_size_hint_min_set(img, sd->item_w, sd->item_h);
evas_object_size_hint_max_set(img, sd->item_w, sd->item_h);
sd->visible_items++;
evas_object_resize(img, sd->itemw, sd->itemh);
evas_object_size_hint_min_set(img, sd->itemw, sd->itemh);
evas_object_size_hint_max_set(img, sd->itemw, sd->itemh);
im = evas_imaging_image_load(image, NULL);
evas_imaging_image_size_get(im, &w, &h);
@ -547,31 +589,40 @@ static void _table_smart_reconfigure(Smart_Data *sd)
{
ethumb_client_file_set(em->thumb_cli, image, NULL);
if (!ethumb_client_thumb_exists(em->thumb_cli))
ethumb_client_generate(em->thumb_cli, thumb_generated, img, NULL);
else
{
ethumb_client_thumb_path_get(em->thumb_cli, &thumb, NULL);
thumb_generated(img, em->thumb_cli, 0, image, NULL, thumb, NULL, EINA_TRUE);
}
ethumb_client_generate(em->thumb_cli, thumb_generated, img, NULL);
else
{
ethumb_client_thumb_path_get(em->thumb_cli, &thumb, NULL);
thumb_generated(img, em->thumb_cli, 0, image, NULL, thumb, NULL, EINA_TRUE);
}
}
else
thumb_generated(img, em->thumb_cli, 0, image, NULL, image, NULL, EINA_TRUE);
evas_imaging_image_free(im);
sd->tw += (sd->item_w + sd->paddingw);
sd->items = eina_list_append(sd->items, img);
if (sd->cur_col == sd->columns)
sd->tw += sd->itemw;
else
sd->tw += (sd->itemw + sd->padw);
sd->items = eina_list_append(sd->items, img);
if (sd->tw+(sd->item_w + sd->paddingw) >= sd->visiblew)
if (sd->cur_col == sd->columns)
{
sd->th += (sd->item_h + sd->paddingh);
sd->tw = 60;
if (sd->cur_row == sd->rows)
sd->th += sd->itemh;
else
sd->th += (sd->itemh + sd->padh);
sd->tw = 60;
sd->cur_row++;
sd->cur_col = 1;
}
else
sd->cur_col++;
iteratorb = eina_list_next(iteratorb);
}
}
return;
}
static void _table_smart_init(void)
@ -611,19 +662,19 @@ static void _table_smart_add(Evas_Object *obj)
edje_object_part_geometry_get(em->bg, "ephoto.swallow.content", 0, 0, &w, &h);
sd->visiblew = w;
sd->visibleh = h;
sd->pagew = w;
sd->pageh = h;
sd->tw = 60;
sd->th = 75;
sd->paddingw = 0;
sd->paddingh = 0;
sd->w = 0;
sd->h = 0;
sd->x = 0;
sd->y = 0;
sd->padw = 0;
sd->padh = 0;
sd->rows = 0;
sd->columns = 0;
sd->cur_row = 1;
sd->cur_col = 1;
sd->items_per_page = 0;
sd->current_head = 0;
sd->current_page = 1;
sd->visible_items = 0;
sd->total_pages = 1;
sd->obj = edje_object_add(em->e);
@ -636,10 +687,12 @@ static void _table_smart_add(Evas_Object *obj)
img = edje_object_add(em->e);
edje_object_file_set(img, PACKAGE_DATA_DIR "/themes/default/ephoto.edj", "/ephoto/thumb/shadow");
edje_object_size_min_get(img, &sd->item_w, &sd->item_h);
edje_object_size_min_get(img, &sd->itemw, &sd->itemh);
evas_object_del(img);
sd->items_per_page = (sd->visiblew / sd->item_w) * (sd->visibleh / sd->item_h);
sd->columns = (sd->pagew / (sd->itemw+sd->padw));
sd->rows = (sd->pageh / (sd->itemh+sd->padh));
sd->items_per_page = sd->columns*sd->rows;
em->thumb_cli = ethumb_client_connect(connect_callback, NULL, NULL);
}
@ -694,10 +747,9 @@ static void _table_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
return;
sd->w = w;
sd->h = h;
evas_object_resize(sd->obj, w, h);
if (!eina_list_count(sd->images))
return;
if ((ibw == sd->visiblew) && (ibh == sd->visibleh))
if ((ibw == sd->pagew) && (ibh == sd->pageh))
return;
else
ephoto_table_viewport_set(obj, w, h);
@ -769,3 +821,4 @@ static void _table_smart_clip_unset(Evas_Object *obj)
return;
}

Loading…
Cancel
Save