mutter/clutter/cltr-photo-grid.c

856 lines
20 KiB
C
Raw Normal View History

2005-03-24 11:46:49 -05:00
#include "cltr-photo-grid.h"
2005-04-03 12:13:08 -04:00
#include "cltr-private.h"
struct CltrPhotoGridCell
{
Pixbuf *pixb;
float angle;
CltrTexture *texture;
gint anim_step;
CltrPhotoGridCellState state;
};
struct CltrPhotoGrid
{
CltrWidget widget;
gchar *img_path;
int n_rows;
int n_cols;
2005-04-07 18:46:43 -04:00
int row_offset; /* where is the first visible row. */
2005-04-03 12:13:08 -04:00
int cell_width;
int cell_height;
GList *cells_tail;
GList *cell_active;
2005-04-22 14:03:55 -04:00
gboolean is_populated;
2005-04-03 12:13:08 -04:00
/* animation / zoom etc stuff */
2005-04-07 18:46:43 -04:00
/* current anim frame position */
2005-04-22 14:03:55 -04:00
int anim_fps, anim_n_steps, anim_step;
2005-04-03 12:13:08 -04:00
2005-04-07 18:46:43 -04:00
/* start / end points for animations */
float zoom_min, zoom_max, zoom_step;
float view_min_x, view_max_x, view_min_y, view_max_y;
float scroll_dist;
2005-04-03 12:13:08 -04:00
2005-04-07 18:46:43 -04:00
/* Values calucated from above for setting up the GL tranforms and 'view' */
float paint_trans_x, paint_trans_y, paint_zoom;
int paint_start_y;
2005-04-03 12:13:08 -04:00
2005-04-22 14:03:55 -04:00
GList *paint_cell_item;
2005-04-03 12:13:08 -04:00
2005-04-22 14:03:55 -04:00
GMutex *mutex;
2005-04-03 12:13:08 -04:00
2005-04-07 18:46:43 -04:00
CltrPhotoGridState state;
2005-04-03 12:13:08 -04:00
};
static void
cltr_photo_grid_paint(CltrWidget *widget);
static gboolean
cltr_photo_grid_handle_xevent (CltrWidget *widget, XEvent *xev);
static void
cltr_photo_grid_show(CltrWidget *widget);
2005-04-07 18:46:43 -04:00
static void
cltr_photo_grid_update_visual_state(CltrPhotoGrid *grid);
2005-03-24 11:46:49 -05:00
2005-04-22 14:03:55 -04:00
GMutex*
cltr_photo_grid_mutex(CltrPhotoGrid *grid)
{
return grid->mutex;
}
2005-03-27 15:12:19 -05:00
2005-04-22 14:03:55 -04:00
void
cltr_photo_grid_set_populated(CltrPhotoGrid *grid, gboolean populated)
{
grid->is_populated = populated;
}
2005-04-03 12:13:08 -04:00
static void
cltr_photo_grid_handle_xkeyevent(CltrPhotoGrid *grid, XKeyEvent *xkeyev)
2005-03-24 11:46:49 -05:00
{
2005-04-03 12:13:08 -04:00
KeySym kc;
kc = XKeycodeToKeysym(xkeyev->display, xkeyev->keycode, 0);
switch (kc)
{
case XK_Left:
case XK_KP_Left:
cltr_photo_grid_navigate(grid, CLTR_WEST);
break;
case XK_Up:
case XK_KP_Up:
cltr_photo_grid_navigate(grid, CLTR_NORTH);
break;
case XK_Right:
case XK_KP_Right:
cltr_photo_grid_navigate(grid, CLTR_EAST);
break;
case XK_Down:
case XK_KP_Down:
cltr_photo_grid_navigate(grid, CLTR_SOUTH);
break;
case XK_Return:
cltr_photo_grid_activate_cell(grid);
break;
default:
CLTR_DBG("unhandled keysym");
}
}
static gboolean
cltr_photo_grid_handle_xevent (CltrWidget *widget, XEvent *xev)
{
CltrPhotoGrid* grid = CLTR_PHOTO_GRID(widget);
switch (xev->type)
{
case KeyPress:
CLTR_DBG("KeyPress");
cltr_photo_grid_handle_xkeyevent(grid, &xev->xkey);
break;
}
return TRUE;
}
CltrPhotoGridCell*
cltr_photo_grid_cell_new(CltrPhotoGrid *grid,
2005-04-22 14:03:55 -04:00
Pixbuf *pixb)
2005-04-03 12:13:08 -04:00
{
CltrPhotoGridCell *cell = NULL;
int maxw = grid->widget.width, maxh = grid->widget.height;
2005-03-24 11:46:49 -05:00
int neww = 0, newh = 0;
2005-04-03 12:13:08 -04:00
cell = g_malloc0(sizeof(CltrPhotoGridCell));
2005-03-24 11:46:49 -05:00
if (pixb->width > pixb->height) /* landscape */
{
if (pixb->width > maxw)
{
neww = maxw;
newh = (neww * pixb->height) / pixb->width;
}
}
else /* portrait */
{
if (pixb->height > maxh)
{
newh = maxh;
neww = (newh * pixb->width) / pixb->height;
}
}
if (neww || newh)
{
cell->pixb = pixbuf_scale_down(pixb, neww, newh);
pixbuf_unref(pixb);
}
else cell->pixb = pixb;
2005-04-22 14:03:55 -04:00
cell->texture = cltr_texture_new(cell->pixb);
2005-03-24 11:46:49 -05:00
2005-03-25 12:22:10 -05:00
cell->angle = 6.0 - (rand()%12);
2005-03-27 15:12:19 -05:00
cell->anim_step = 15;
cell->state = CLTR_PHOTO_GRID_CELL_STATE_APPEARING;
2005-03-24 11:46:49 -05:00
return cell;
}
2005-04-22 14:03:55 -04:00
Pixbuf*
cltr_photo_grid_cell_pixbuf(CltrPhotoGridCell *cell)
{
return cell->pixb;
}
CltrPhotoGridCell*
cltr_photo_grid_get_active_cell(CltrPhotoGrid *grid)
{
if (grid->cell_active)
return grid->cell_active->data;
else
return NULL;
}
void
cltr_photo_grid_set_active_cell(CltrPhotoGrid *grid, CltrPhotoGridCell *cell)
{
GList *cell_item = NULL;
cell_item = g_list_find(g_list_first(grid->cells_tail), (gconstpointer)cell);
if (cell_item)
grid->cell_active = cell_item;
}
CltrPhotoGridCell*
cltr_photo_grid_get_first_cell(CltrPhotoGrid *grid)
{
GList *cell_item = NULL;
cell_item = g_list_first(grid->cells_tail);
if (cell_item)
return cell_item->data;
return NULL;
}
2005-03-24 11:46:49 -05:00
void
2005-04-03 12:13:08 -04:00
cltr_photo_grid_append_cell(CltrPhotoGrid *grid,
CltrPhotoGridCell *cell)
2005-03-24 11:46:49 -05:00
{
grid->cells_tail = g_list_append(grid->cells_tail, cell);
}
2005-03-31 13:19:25 -05:00
/* relative */
2005-03-24 11:46:49 -05:00
static void
2005-04-03 12:13:08 -04:00
ctrl_photo_grid_cell_to_coords(CltrPhotoGrid *grid,
2005-03-24 11:46:49 -05:00
GList *cell,
int *x,
int *y)
{
int idx;
2005-03-31 13:19:25 -05:00
idx = g_list_position(grid->cells_tail, cell);
2005-03-24 11:46:49 -05:00
*y = idx / grid->n_cols;
*x = idx % grid->n_cols;
CLTR_DBG("idx: %i x: %i, y: %i", idx, *x , *y);
}
static void
2005-04-03 12:13:08 -04:00
ctrl_photo_grid_get_zoomed_coords(CltrPhotoGrid *grid,
2005-03-24 11:46:49 -05:00
int x,
int y,
float *tx,
float *ty)
{
/*
2005-03-25 12:22:10 -05:00
* figure out translate co-ords for the cell at x,y to get translated
* so its centered for glScale to zoom in on it.
2005-03-24 11:46:49 -05:00
*/
2005-03-25 12:22:10 -05:00
*tx = (float)grid->cell_width * (grid->zoom_max) * x * -1.0;
*ty = (float)grid->cell_height * (grid->zoom_max) * y * -1.0;
2005-03-31 13:19:25 -05:00
}
static gboolean
2005-04-03 12:13:08 -04:00
cell_is_offscreen(CltrPhotoGrid *grid,
2005-03-31 13:19:25 -05:00
GList *cell,
CltrDirection *where)
{
int idx;
idx = g_list_position(grid->cells_tail, cell);
CLTR_DBG("idx %i, rows*cols %i", idx, grid->n_cols * grid->n_rows);
if (idx < (grid->row_offset * grid->n_cols))
{
if (where) *where = CLTR_NORTH;
return TRUE; /* scroll up */
}
if (idx >= ((grid->row_offset * grid->n_cols)+(grid->n_cols * grid->n_rows)))
{
if (where) *where = CLTR_SOUTH;
return TRUE; /* scroll down */
}
return FALSE;
2005-03-24 11:46:49 -05:00
}
2005-03-27 15:12:19 -05:00
gboolean
cltr_photo_grid_idle_cb(gpointer data)
{
2005-04-03 12:13:08 -04:00
CltrPhotoGrid *grid = (CltrPhotoGrid *)data;
2005-03-27 15:12:19 -05:00
2005-04-07 18:46:43 -04:00
cltr_photo_grid_update_visual_state(grid);
2005-04-03 12:13:08 -04:00
cltr_widget_queue_paint(CLTR_WIDGET(grid));
2005-03-27 15:12:19 -05:00
2005-04-22 14:03:55 -04:00
if (!grid->is_populated)
return TRUE;
2005-03-27 15:12:19 -05:00
switch(grid->state)
{
case CLTR_PHOTO_GRID_STATE_ZOOM_IN:
case CLTR_PHOTO_GRID_STATE_ZOOM_OUT:
case CLTR_PHOTO_GRID_STATE_ZOOMED_MOVE:
2005-03-31 13:19:25 -05:00
case CLTR_PHOTO_GRID_STATE_SCROLLED_MOVE:
2005-03-27 15:12:19 -05:00
return TRUE;
case CLTR_PHOTO_GRID_STATE_ZOOMED:
case CLTR_PHOTO_GRID_STATE_BROWSE:
default:
return FALSE; /* no need for rapid updates now */
}
}
2005-03-24 11:46:49 -05:00
void
2005-04-03 12:13:08 -04:00
cltr_photo_grid_navigate(CltrPhotoGrid *grid,
2005-03-24 11:46:49 -05:00
CltrDirection direction)
{
GList *cell_orig = grid->cell_active;
switch (direction)
{
case CLTR_SOUTH:
if (g_list_nth(grid->cell_active, grid->n_cols))
grid->cell_active = g_list_nth(grid->cell_active, grid->n_cols);
break;
case CLTR_NORTH:
if (g_list_nth_prev(grid->cell_active, grid->n_cols))
grid->cell_active = g_list_nth_prev(grid->cell_active, grid->n_cols);
break;
case CLTR_EAST:
if (g_list_next(grid->cell_active))
grid->cell_active = g_list_next(grid->cell_active);
break;
case CLTR_WEST:
if (g_list_previous(grid->cell_active))
grid->cell_active = g_list_previous(grid->cell_active);
break;
}
if (cell_orig != grid->cell_active) /* we've moved */
{
2005-03-31 13:19:25 -05:00
int x, y;
float zoom = grid->zoom_min;
CltrDirection where;
if (cell_is_offscreen(grid, grid->cell_active, &where))
{
GList *cell_item = NULL;
cell_item = g_list_nth(grid->cells_tail,
grid->n_cols * grid->row_offset);
if (grid->state != CLTR_PHOTO_GRID_STATE_ZOOMED)
grid->state = CLTR_PHOTO_GRID_STATE_SCROLLED_MOVE;
/* scroll */
if (where == CLTR_NORTH)
{ /* up */
grid->scroll_dist = grid->cell_height;
grid->row_offset--;
}
else
{
grid->scroll_dist = - grid->cell_height;
grid->row_offset++;
}
if (grid->state != CLTR_PHOTO_GRID_STATE_ZOOMED)
2005-04-22 14:03:55 -04:00
g_timeout_add(FPS_TO_TIMEOUT(grid->anim_fps),
2005-04-03 12:13:08 -04:00
cltr_photo_grid_idle_cb, grid);
2005-03-31 13:19:25 -05:00
}
2005-03-24 11:46:49 -05:00
if (grid->state == CLTR_PHOTO_GRID_STATE_ZOOMED)
{
grid->state = CLTR_PHOTO_GRID_STATE_ZOOMED_MOVE;
2005-03-31 13:19:25 -05:00
2005-03-24 11:46:49 -05:00
grid->view_min_x = grid->view_max_x;
grid->view_min_y = grid->view_max_y ;
grid->anim_step = 0;
zoom = grid->zoom_max;
2005-03-27 15:12:19 -05:00
2005-04-22 14:03:55 -04:00
g_timeout_add(FPS_TO_TIMEOUT(grid->anim_fps),
2005-04-03 12:13:08 -04:00
cltr_photo_grid_idle_cb, grid);
2005-03-24 11:46:49 -05:00
}
ctrl_photo_grid_cell_to_coords(grid, grid->cell_active, &x, &y);
2005-03-25 12:22:10 -05:00
ctrl_photo_grid_get_zoomed_coords(grid, x, y,
2005-03-24 11:46:49 -05:00
&grid->view_max_x,
&grid->view_max_y);
CLTR_DBG("x: %f, y: %f", grid->view_max_x , grid->view_max_y);
2005-03-27 15:12:19 -05:00
2005-04-03 12:13:08 -04:00
cltr_widget_queue_paint(CLTR_WIDGET(grid));
2005-03-24 11:46:49 -05:00
}
}
void /* bleh badly named */
2005-04-03 12:13:08 -04:00
cltr_photo_grid_activate_cell(CltrPhotoGrid *grid)
2005-03-24 11:46:49 -05:00
{
if (grid->state == CLTR_PHOTO_GRID_STATE_BROWSE)
{
grid->state = CLTR_PHOTO_GRID_STATE_ZOOM_IN;
2005-03-27 15:12:19 -05:00
2005-03-31 13:19:25 -05:00
2005-04-22 14:03:55 -04:00
g_timeout_add(FPS_TO_TIMEOUT(grid->anim_fps),
2005-04-03 12:13:08 -04:00
cltr_photo_grid_idle_cb, grid);
2005-03-24 11:46:49 -05:00
}
else if (grid->state == CLTR_PHOTO_GRID_STATE_ZOOMED)
{
grid->state = CLTR_PHOTO_GRID_STATE_ZOOM_OUT;
/* reset - zoomed moving will have reset */
2005-03-31 13:19:25 -05:00
2005-03-24 11:46:49 -05:00
grid->view_min_x = 0.0;
2005-03-31 13:19:25 -05:00
grid->view_min_y = 0.0; /*- (grid->row_offset * grid->cell_height);*/
2005-03-27 15:12:19 -05:00
2005-04-22 14:03:55 -04:00
g_timeout_add(FPS_TO_TIMEOUT(grid->anim_fps),
2005-04-03 12:13:08 -04:00
cltr_photo_grid_idle_cb, grid);
2005-03-24 11:46:49 -05:00
}
}
2005-04-03 12:13:08 -04:00
static void
2005-04-07 18:46:43 -04:00
cltr_photo_grid_update_visual_state(CltrPhotoGrid *grid)
2005-03-24 11:46:49 -05:00
{
2005-04-07 18:46:43 -04:00
int view_x_diff = grid->view_max_x - grid->view_min_x;
int view_y_diff = grid->view_max_y - grid->view_min_y;
int zoom_diff = grid->zoom_max - grid->zoom_min;
int row_offset_h = grid->row_offset * grid->cell_height;
/* Default states ( zoomed out ) */
grid->paint_zoom = grid->zoom_min;
grid->paint_trans_x = grid->view_min_x;
grid->paint_trans_y = grid->view_min_y - row_offset_h;
grid->paint_start_y = row_offset_h;
grid->paint_cell_item = g_list_nth(grid->cells_tail,
grid->n_cols * grid->row_offset);
2005-03-24 11:46:49 -05:00
2005-04-22 14:03:55 -04:00
if (grid->state != CLTR_PHOTO_GRID_STATE_BROWSE)
2005-03-24 11:46:49 -05:00
{
2005-04-07 18:46:43 -04:00
float scroll_min_y_offset = (float)(row_offset_h);
2005-03-24 11:46:49 -05:00
/* Assume zoomed in */
2005-04-07 18:46:43 -04:00
grid->paint_zoom = grid->zoom_max;
grid->paint_trans_x = grid->view_max_x;
grid->paint_trans_y = grid->view_max_y;
2005-03-24 11:46:49 -05:00
if (grid->state == CLTR_PHOTO_GRID_STATE_ZOOM_IN)
{
grid->anim_step++;
/* Are we zoomed all the way in > */
if (grid->anim_step >= grid->anim_n_steps)
{
grid->state = CLTR_PHOTO_GRID_STATE_ZOOMED;
grid->anim_step = 0;
}
else
{
float f = (float)grid->anim_step/grid->anim_n_steps;
2005-03-31 13:19:25 -05:00
scroll_min_y_offset *= grid->zoom_max;
2005-04-07 18:46:43 -04:00
grid->paint_zoom = grid->zoom_min + (zoom_diff * f);
grid->paint_trans_x = view_x_diff * f;
grid->paint_trans_y = (view_y_diff + scroll_min_y_offset) * f;
2005-03-31 13:19:25 -05:00
2005-04-07 18:46:43 -04:00
grid->paint_start_y = 0;
2005-03-24 11:46:49 -05:00
}
}
else if (grid->state == CLTR_PHOTO_GRID_STATE_ZOOM_OUT)
{
grid->anim_step++;
if (grid->anim_step >= grid->anim_n_steps)
{
2005-04-07 18:46:43 -04:00
grid->paint_zoom = grid->zoom_min;
grid->anim_step = 0;
grid->paint_trans_x = grid->view_min_x;
grid->paint_trans_y = grid->view_min_y - scroll_min_y_offset;
grid->state = CLTR_PHOTO_GRID_STATE_BROWSE;
2005-03-24 11:46:49 -05:00
}
else
{
float f = (float)(grid->anim_n_steps - grid->anim_step )
/ grid->anim_n_steps;
2005-03-31 13:19:25 -05:00
scroll_min_y_offset *= grid->zoom_max;
2005-04-07 18:46:43 -04:00
grid->paint_zoom = grid->zoom_min + (zoom_diff * f);
grid->paint_trans_x = view_x_diff * f;
grid->paint_trans_y = (view_y_diff + scroll_min_y_offset) * f;
grid->paint_start_y = 0;
2005-03-31 13:19:25 -05:00
2005-03-24 11:46:49 -05:00
}
}
else if (grid->state == CLTR_PHOTO_GRID_STATE_ZOOMED_MOVE)
{
grid->anim_step++;
if (grid->anim_step >= grid->anim_n_steps)
{
grid->state = CLTR_PHOTO_GRID_STATE_ZOOMED;
grid->anim_step = 0;
}
else
{
float f = (float)grid->anim_step/grid->anim_n_steps;
2005-04-07 18:46:43 -04:00
grid->paint_trans_x = grid->view_min_x + (view_x_diff * f);
grid->paint_trans_y = grid->view_min_y + (view_y_diff * f);
2005-03-24 11:46:49 -05:00
}
}
2005-03-31 13:19:25 -05:00
else if (grid->state == CLTR_PHOTO_GRID_STATE_SCROLLED_MOVE)
{
2005-04-07 18:46:43 -04:00
grid->paint_zoom = grid->zoom_min;
grid->paint_trans_x = grid->view_min_x;
grid->paint_trans_y = grid->view_min_y - row_offset_h;
2005-03-31 13:19:25 -05:00
grid->anim_step++;
2005-03-24 11:46:49 -05:00
2005-04-03 12:13:08 -04:00
if (grid->anim_step >= (grid->anim_n_steps/4))
2005-03-31 13:19:25 -05:00
{
2005-04-07 18:46:43 -04:00
grid->state = CLTR_PHOTO_GRID_STATE_BROWSE;
grid->anim_step = 0;
grid->paint_zoom = grid->zoom_min;
2005-03-31 13:19:25 -05:00
}
else
{
2005-04-03 12:13:08 -04:00
float f = (float)grid->anim_step / (grid->anim_n_steps/4);
2005-04-07 18:46:43 -04:00
grid->paint_trans_y += (grid->scroll_dist * f);
2005-03-24 11:46:49 -05:00
2005-03-31 13:19:25 -05:00
if (grid->scroll_dist > 0) /* up */
{
2005-04-07 18:46:43 -04:00
grid->paint_start_y = (grid->row_offset-1) * grid->cell_height;
2005-03-31 13:19:25 -05:00
}
else /* down */
{
2005-04-07 18:46:43 -04:00
grid->paint_cell_item = g_list_nth(grid->cells_tail,
grid->n_cols * (grid->row_offset-1));
2005-03-31 13:19:25 -05:00
}
}
}
2005-03-24 11:46:49 -05:00
}
2005-04-07 18:46:43 -04:00
}
static void
cltr_photo_grid_paint(CltrWidget *widget)
{
int x = 0, y = 0, rows = 0, cols = 0, i =0;
GList *cell_item;
CltrPhotoGrid *grid = (CltrPhotoGrid *)widget;
rows = grid->n_rows+1;
CLTR_MARK();
glPushMatrix();
if (grid->cells_tail == NULL)
{
2005-05-06 13:41:15 -04:00
glColor3ub(0xc2, 0xc3, 0xc1);
2005-04-07 18:46:43 -04:00
glRecti(0, 0, widget->width, widget->height);
glPopMatrix();
return;
}
/*
* Using GL_POLYGON_SMOOTH with 'regular' alpha blends causes ugly seems
* in the textures and texture tile borders. We therefore do this 'saturate'
* trick painting front -> back.
*
* see http://blog.metawrap.com/blog/PermaLink.aspx?guid=db82f92e-9fc8-4635-b3e5-e37a1ca6ee0a
* for more info
*
* Note bg must be glClearColor( 0.0, 0.0, 0.0, 0.0 ) to work.
* Is there a better way.?
* - multisample ?
*/
2005-04-27 18:17:45 -04:00
if (!grid->paint_cell_item)
cltr_photo_grid_update_visual_state(grid);
2005-04-07 18:46:43 -04:00
glEnable(GL_BLEND);
2005-03-24 11:46:49 -05:00
2005-04-07 18:46:43 -04:00
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); /* needed */
glEnable(GL_POLYGON_SMOOTH);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE);
glColor4f(1.0, 1.0, 1.0, 1.0);
/* values from cltr_photo_grid_update_visual_state() */
cell_item = grid->paint_cell_item;
y = grid->paint_start_y;
glTranslatef (grid->paint_trans_x, grid->paint_trans_y, 0.0);
glScalef (grid->paint_zoom, grid->paint_zoom, 0.0);
2005-03-24 11:46:49 -05:00
while (rows--)
{
cols = grid->n_cols;
x = 0;
while (cols--)
{
2005-04-03 12:13:08 -04:00
CltrPhotoGridCell *cell = (CltrPhotoGridCell *)cell_item->data;
2005-04-07 18:46:43 -04:00
Pixbuf *pixb = NULL;
int x1, x2, y1, y2, thumb_w, thumb_h;
2005-05-06 13:41:15 -04:00
int ns_border, ew_border, selected_offset = 0;
2005-03-24 11:46:49 -05:00
pixb = cell->pixb;
thumb_w = (pixb->width / grid->n_cols);
thumb_h = (pixb->height / grid->n_rows);
2005-03-27 15:12:19 -05:00
if (cell->state == CLTR_PHOTO_GRID_CELL_STATE_APPEARING)
{
cell->anim_step -= 4;
if (cell->anim_step <= 0)
{
cell->state = CLTR_PHOTO_GRID_CELL_STATE_STATIC;
}
else
{
thumb_w = thumb_w + cell->anim_step;
thumb_h = thumb_h + cell->anim_step;
}
2005-04-07 18:46:43 -04:00
/* set color here for developing effect
* only fully develop when all picts loaded ?
* blur texture too ?
*/
/* glColor4f(1.0, 1.0, 1.0, 0.5); */
2005-03-27 15:12:19 -05:00
cell->anim_step = 0;
}
2005-05-06 13:41:15 -04:00
if (cell_item == grid->cell_active
&& grid->state == CLTR_PHOTO_GRID_STATE_BROWSE)
selected_offset = 2;
2005-03-24 11:46:49 -05:00
ew_border = thumb_w/8;
2005-05-06 13:41:15 -04:00
ns_border = (thumb_h/8) + 4;
2005-03-24 11:46:49 -05:00
thumb_w -= (2 * ew_border);
thumb_h -= (2 * ns_border);
2005-03-25 12:22:10 -05:00
x1 = x + ((grid->cell_width - thumb_w)/2);
y1 = y + ((grid->cell_height - thumb_h)/2);
2005-03-24 11:46:49 -05:00
2005-03-25 12:22:10 -05:00
x2 = x1 + thumb_w;
2005-03-24 11:46:49 -05:00
y2 = y1 + thumb_h;
glPushMatrix();
2005-03-25 12:22:10 -05:00
/* Translate origin to rotation point ( photo center ) */
glTranslatef( x1 + ((x2-x1)/2), y1 + ((y2-y1)/2), 0.0);
2005-03-27 15:12:19 -05:00
if (cell->state != CLTR_PHOTO_GRID_CELL_STATE_APPEARING)
/* Rotate around Z axis */
glRotatef ( cell->angle, 0.0, 0.0, 1.0);
2005-03-25 12:22:10 -05:00
2005-03-29 18:26:36 -05:00
glEnable(GL_TEXTURE_2D);
2005-04-22 14:03:55 -04:00
g_mutex_lock(grid->mutex);
2005-03-29 18:26:36 -05:00
2005-03-30 11:52:02 -05:00
cltr_texture_render_to_gl_quad(cell->texture,
2005-05-06 13:41:15 -04:00
-(thumb_w/2) - selected_offset,
-(thumb_h/2) - selected_offset,
(thumb_w/2) - selected_offset,
(thumb_h/2) - selected_offset);
2005-03-29 18:26:36 -05:00
2005-04-22 14:03:55 -04:00
g_mutex_unlock(grid->mutex);
2005-03-29 18:26:36 -05:00
2005-03-24 11:46:49 -05:00
glDisable(GL_TEXTURE_2D);
2005-03-29 18:26:36 -05:00
2005-03-24 11:46:49 -05:00
if (cell_item == grid->cell_active
&& grid->state == CLTR_PHOTO_GRID_STATE_BROWSE)
glColor4f(1.0, 1.0, 1.0, 1.0);
else
2005-03-25 12:22:10 -05:00
glColor4f(0.9, 0.95, 0.95, 1.0);
2005-05-06 13:41:15 -04:00
glColor4f(1.0, 1.0, 1.0, 1.0);
2005-03-25 12:22:10 -05:00
/* Draw with origin in center of photo */
2005-05-06 13:41:15 -04:00
glRecti(-(thumb_w/2)-6 - selected_offset,
-(thumb_h/2)-6 - selected_offset,
(thumb_w/2)+6 - selected_offset,
(thumb_h/2)+ns_border - selected_offset);
/*
cltr_glu_rounded_rect(-(thumb_w/2)-4, -(thumb_h/2)-4,
(thumb_w/2)+4, (thumb_h/2)+ns_border,
2005-04-22 14:03:55 -04:00
thumb_w/30,
NULL);
2005-05-06 13:41:15 -04:00
*/
/* Nice colors */
/* glColor4ub(0x3c, 0xbb, 0x15, 0xff); */
/* glColor4ub(0x99, 0x99, 0xff, 0xff); */
/* glColor4ub(0x99, 0x99, 0x99, 0xff); */
2005-04-22 14:03:55 -04:00
/* shadow */
2005-05-06 13:41:15 -04:00
glColor4ub(0x99, 0x99, 0x99, 0xff);
glRecti(-(thumb_w/2)-6+2, -(thumb_h/2)-6+2,
(thumb_w/2)+6+2, (thumb_h/2)+ns_border+2);
/*
2005-04-22 14:03:55 -04:00
glColor4f(0.1, 0.1, 0.1, 0.3);
2005-05-06 13:41:15 -04:00
2005-04-22 14:03:55 -04:00
cltr_glu_rounded_rect(-(thumb_w/2)-4 + 1, -(thumb_h/2)-4 + 1,
(thumb_w/2)+4 + 1, (thumb_h/2)+ns_border +1,
thumb_w/30,
NULL);
2005-05-06 13:41:15 -04:00
*/
2005-04-22 14:03:55 -04:00
glColor4f(1.0, 1.0, 1.0, 1.0);
2005-03-25 12:22:10 -05:00
2005-03-24 11:46:49 -05:00
glEnable(GL_TEXTURE_2D);
2005-03-27 15:12:19 -05:00
2005-04-07 18:46:43 -04:00
glPopMatrix();
2005-03-24 11:46:49 -05:00
cell_item = g_list_next(cell_item);
if (!cell_item)
goto finish;
x += grid->cell_width;
i++;
}
2005-04-07 18:46:43 -04:00
2005-03-24 11:46:49 -05:00
y += grid->cell_height;
}
finish:
glPopMatrix();
2005-03-29 18:26:36 -05:00
/* finally paint background */
2005-04-07 18:46:43 -04:00
2005-03-24 11:46:49 -05:00
glDisable(GL_TEXTURE_2D);
2005-05-06 13:41:15 -04:00
glColor3ub(0xc2, 0xc3, 0xc1);
2005-04-03 12:13:08 -04:00
glRecti(0, 0, widget->width, widget->height);
2005-03-24 11:46:49 -05:00
2005-04-07 18:46:43 -04:00
/* reset */
glDisable(GL_POLYGON_SMOOTH);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
2005-03-24 11:46:49 -05:00
}
2005-04-03 12:13:08 -04:00
static void
cltr_photo_grid_show(CltrWidget *widget)
{
2005-04-07 18:46:43 -04:00
CltrPhotoGrid *grid = CLTR_PHOTO_GRID(widget);
2005-04-22 14:03:55 -04:00
/*
GThread *loader_thread;
2005-04-07 18:46:43 -04:00
loader_thread = g_thread_create (cltr_photo_grid_populate,
(gpointer)grid,
TRUE,
NULL);
2005-04-22 14:03:55 -04:00
*/
2005-04-07 18:46:43 -04:00
2005-04-22 14:03:55 -04:00
grid->state = CLTR_PHOTO_GRID_STATE_BROWSE;
if (!grid->is_populated)
g_timeout_add(FPS_TO_TIMEOUT(20),
cltr_photo_grid_idle_cb, grid);
2005-04-03 12:13:08 -04:00
cltr_widget_queue_paint(widget);
}
2005-04-22 14:03:55 -04:00
void
cltr_photo_grid_set_fps(CltrPhotoGrid *grid, int fps)
{
grid->anim_fps = fps;
}
int
cltr_photo_grid_get_fps(CltrPhotoGrid *grid)
{
return grid->anim_fps;
}
void
cltr_photo_grid_set_anim_steps(CltrPhotoGrid *grid, int steps)
{
grid->anim_n_steps = steps;
}
int
cltr_photo_grid_get_anim_steps(CltrPhotoGrid *grid)
{
return grid->anim_n_steps;
}
2005-04-03 12:13:08 -04:00
CltrWidget*
cltr_photo_grid_new(int width,
int height,
2005-03-24 11:46:49 -05:00
int n_cols,
int n_rows,
2005-03-27 15:12:19 -05:00
const gchar *img_path)
2005-03-24 11:46:49 -05:00
{
2005-04-03 12:13:08 -04:00
CltrPhotoGrid *grid = NULL;
2005-03-24 11:46:49 -05:00
2005-04-03 12:13:08 -04:00
grid = g_malloc0(sizeof(CltrPhotoGrid));
2005-03-24 11:46:49 -05:00
2005-04-03 12:13:08 -04:00
grid->widget.width = width;
grid->widget.height = height;
grid->widget.show = cltr_photo_grid_show;
grid->widget.paint = cltr_photo_grid_paint;
grid->widget.xevent_handler = cltr_photo_grid_handle_xevent;
2005-03-27 15:12:19 -05:00
2005-04-03 12:13:08 -04:00
grid->img_path = strdup(img_path);
2005-03-24 11:46:49 -05:00
grid->n_cols = n_cols;
grid->n_rows = n_rows;
2005-04-03 12:13:08 -04:00
grid->cell_width = grid->widget.width / n_cols;
grid->cell_height = grid->widget.height / n_rows;
2005-03-24 11:46:49 -05:00
2005-04-22 14:03:55 -04:00
grid->state = CLTR_PHOTO_GRID_STATE_BROWSE;
grid->is_populated = FALSE;
grid->anim_fps = 50;
2005-03-24 11:46:49 -05:00
2005-04-22 14:03:55 -04:00
grid->anim_n_steps = 10; /* value needs to be calced dep on rows */
2005-03-24 11:46:49 -05:00
grid->anim_step = 0;
2005-04-07 18:46:43 -04:00
/* Default 'browse view' */
2005-03-25 12:22:10 -05:00
grid->zoom_min = 1.0;
2005-04-03 12:13:08 -04:00
grid->view_min_x = (grid->widget.width - (grid->zoom_min * grid->widget.width))/2.0;
2005-03-24 11:46:49 -05:00
grid->view_min_y = 0.0;
/* Assmes cols == rows */
2005-05-06 13:41:15 -04:00
grid->zoom_max = (float) (n_rows * 1.0);
2005-03-31 13:19:25 -05:00
grid->row_offset = 0;
2005-03-24 11:46:49 -05:00
2005-04-22 14:03:55 -04:00
grid->mutex = g_mutex_new();
2005-03-27 15:12:19 -05:00
2005-04-03 12:13:08 -04:00
return CLTR_WIDGET(grid);
2005-03-24 11:46:49 -05:00
}