Explorar el Código

Merged img_display() into img_render()

master
Bert hace 14 años
padre
commit
629d37376d
Se han modificado 3 ficheros con 32 adiciones y 33 borrados
  1. +28
    -29
      image.c
  2. +1
    -1
      image.h
  3. +3
    -3
      main.c

+ 28
- 29
image.c Ver fichero

@@ -62,40 +62,13 @@ int img_load(img_t *img, const char *filename) {

imlib_context_set_image(im);

img->re = 0;
img->w = imlib_image_get_width();
img->h = imlib_image_get_height();

return 0;
}

void img_display(img_t *img, win_t *win) {
float zw, zh;

if (!img || !win || !imlib_context_get_image())
return;

/* set zoom level to fit image into window */
if (img->scalemode != SCALE_ZOOM) {
zw = (float) win->w / (float) img->w;
zh = (float) win->h / (float) img->h;
img->zoom = MIN(zw, zh);

if (img->zoom < zoom_min)
img->zoom = zoom_min;
else if (img->zoom > zoom_max)
img->zoom = zoom_max;

if (img->scalemode == SCALE_DOWN && img->zoom > 1.0)
img->zoom = 1.0;
}

/* center image in window */
img->x = (win->w - img->w * img->zoom) / 2;
img->y = (win->h - img->h * img->zoom) / 2;

img_render(img, win);
}

void img_check_pan(img_t *img, win_t *win) {
if (!img)
return;
@@ -121,11 +94,37 @@ void img_check_pan(img_t *img, win_t *win) {
void img_render(img_t *img, win_t *win) {
int sx, sy, sw, sh;
int dx, dy, dw, dh;
float zw, zh;

if (!img || !win || !imlib_context_get_image())
return;

img_check_pan(img, win);
if (!img->re) {
/* rendered for the first time */
img->re = 1;

/* set zoom level to fit image into window */
if (img->scalemode != SCALE_ZOOM) {
zw = (float) win->w / (float) img->w;
zh = (float) win->h / (float) img->h;
img->zoom = MIN(zw, zh);

if (img->zoom < zoom_min)
img->zoom = zoom_min;
else if (img->zoom > zoom_max)
img->zoom = zoom_max;

if (img->scalemode == SCALE_DOWN && img->zoom > 1.0)
img->zoom = 1.0;
}

/* center image in window */
img->x = (win->w - img->w * img->zoom) / 2;
img->y = (win->h - img->h * img->zoom) / 2;
} else {
/* typically after zooming and panning */
img_check_pan(img, win);
}

if (img->x < 0) {
sx = -img->x / img->zoom;


+ 1
- 1
image.h Ver fichero

@@ -30,6 +30,7 @@ typedef enum scalemode_e {
typedef struct img_s {
float zoom;
scalemode_t scalemode;
unsigned char re;
int x;
int y;
int w;
@@ -40,7 +41,6 @@ void imlib_init(win_t*);
void imlib_destroy();

int img_load(img_t*, const char*);
void img_display(img_t*, win_t*);
void img_render(img_t*, win_t*);

int img_zoom_in(img_t*);


+ 3
- 3
main.c Ver fichero

@@ -93,7 +93,7 @@ int main(int argc, char **argv) {
imlib_init(&win);

img_load(&img, filenames[fileidx]);
img_display(&img, &win);
img_render(&img, &win);
update_title();

run();
@@ -146,14 +146,14 @@ void on_keypress(XEvent *ev) {
case 'n':
if (fileidx + 1 < filecnt) {
img_load(&img, filenames[++fileidx]);
img_display(&img, &win);
img_render(&img, &win);
update_title();
}
break;
case 'p':
if (fileidx > 0) {
img_load(&img, filenames[--fileidx]);
img_display(&img, &win);
img_render(&img, &win);
update_title();
}
break;


Cargando…
Cancelar
Guardar