First things for thumbnail mode
This commit is contained in:
parent
e8ed491ba9
commit
7b49740613
2
config.h
2
config.h
@ -19,3 +19,5 @@ static const float zoom_levels[] = {
|
|||||||
12.5, 25.0, 50.0, 75.0,
|
12.5, 25.0, 50.0, 75.0,
|
||||||
100.0, 150.0, 200.0, 400.0, 800.0
|
100.0, 150.0, 200.0, 400.0, 800.0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define THUMB_SIZE 50
|
||||||
|
21
image.c
21
image.c
@ -149,6 +149,27 @@ int img_fit(img_t *img, win_t *win) {
|
|||||||
return oz != img->zoom;
|
return oz != img->zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int img_load_thumb(thumb_t *tn, const char *filename) {
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
|
||||||
|
if (!tn)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!_imlib_load_image(filename))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
w = imlib_image_get_width();
|
||||||
|
h = imlib_image_get_height();
|
||||||
|
|
||||||
|
imlib_context_set_drawable(tn->pm);
|
||||||
|
imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
|
||||||
|
0, 0, THUMB_SIZE, THUMB_SIZE);
|
||||||
|
imlib_free_image();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void img_render(img_t *img, win_t *win) {
|
void img_render(img_t *img, win_t *win) {
|
||||||
int sx, sy, sw, sh;
|
int sx, sy, sw, sh;
|
||||||
int dx, dy, dw, dh;
|
int dx, dy, dw, dh;
|
||||||
|
7
image.h
7
image.h
@ -49,11 +49,18 @@ typedef struct img_s {
|
|||||||
int h;
|
int h;
|
||||||
} img_t;
|
} img_t;
|
||||||
|
|
||||||
|
typedef struct thumb_s {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
Pixmap pm;
|
||||||
|
} thumb_t;
|
||||||
|
|
||||||
void img_init(img_t*, win_t*);
|
void img_init(img_t*, win_t*);
|
||||||
void img_free(img_t*);
|
void img_free(img_t*);
|
||||||
|
|
||||||
int img_check(const char*);
|
int img_check(const char*);
|
||||||
int img_load(img_t*, const char*);
|
int img_load(img_t*, const char*);
|
||||||
|
int img_load_thumb(thumb_t*, const char*);
|
||||||
|
|
||||||
void img_render(img_t*, win_t*);
|
void img_render(img_t*, win_t*);
|
||||||
|
|
||||||
|
8
main.c
8
main.c
@ -46,6 +46,8 @@ const char **filenames;
|
|||||||
int filecnt, fileidx;
|
int filecnt, fileidx;
|
||||||
size_t filesize;
|
size_t filesize;
|
||||||
|
|
||||||
|
thumb_t *thumbs;
|
||||||
|
|
||||||
#define TITLE_LEN 256
|
#define TITLE_LEN 256
|
||||||
char win_title[TITLE_LEN];
|
char win_title[TITLE_LEN];
|
||||||
|
|
||||||
@ -119,6 +121,12 @@ int main(int argc, char **argv) {
|
|||||||
win_open(&win);
|
win_open(&win);
|
||||||
img_init(&img, &win);
|
img_init(&img, &win);
|
||||||
|
|
||||||
|
if (options->thumbnails) {
|
||||||
|
thumbs = (thumb_t*) s_malloc(filecnt * sizeof(thumb_t));
|
||||||
|
for (i = 0; i < filecnt; ++i)
|
||||||
|
img_load_thumb(&thumbs[i], filenames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
load_image();
|
load_image();
|
||||||
img_render(&img, &win);
|
img_render(&img, &win);
|
||||||
update_title();
|
update_title();
|
||||||
|
@ -30,7 +30,7 @@ options_t _options;
|
|||||||
const options_t *options = (const options_t*) &_options;
|
const options_t *options = (const options_t*) &_options;
|
||||||
|
|
||||||
void print_usage() {
|
void print_usage() {
|
||||||
printf("usage: sxiv [-dFfhpqrsvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
|
printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_version() {
|
void print_version() {
|
||||||
@ -45,6 +45,7 @@ void parse_options(int argc, char **argv) {
|
|||||||
_options.scalemode = SCALE_MODE;
|
_options.scalemode = SCALE_MODE;
|
||||||
_options.zoom = 1.0;
|
_options.zoom = 1.0;
|
||||||
_options.aa = 1;
|
_options.aa = 1;
|
||||||
|
_options.thumbnails = 0;
|
||||||
|
|
||||||
_options.fixed = 0;
|
_options.fixed = 0;
|
||||||
_options.fullscreen = 0;
|
_options.fullscreen = 0;
|
||||||
@ -53,7 +54,7 @@ void parse_options(int argc, char **argv) {
|
|||||||
_options.quiet = 0;
|
_options.quiet = 0;
|
||||||
_options.recursive = 0;
|
_options.recursive = 0;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "dFfg:hpqrsvZz:")) != -1) {
|
while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case '?':
|
case '?':
|
||||||
print_usage();
|
print_usage();
|
||||||
@ -85,6 +86,9 @@ void parse_options(int argc, char **argv) {
|
|||||||
case 's':
|
case 's':
|
||||||
_options.scalemode = SCALE_FIT;
|
_options.scalemode = SCALE_FIT;
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
_options.thumbnails = 1;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
print_version();
|
print_version();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -29,6 +29,7 @@ typedef struct options_s {
|
|||||||
scalemode_t scalemode;
|
scalemode_t scalemode;
|
||||||
float zoom;
|
float zoom;
|
||||||
unsigned char aa;
|
unsigned char aa;
|
||||||
|
unsigned char thumbnails;
|
||||||
|
|
||||||
unsigned char fixed;
|
unsigned char fixed;
|
||||||
unsigned char fullscreen;
|
unsigned char fullscreen;
|
||||||
|
8
window.c
8
window.c
@ -211,6 +211,14 @@ void win_toggle_fullscreen(win_t *win) {
|
|||||||
SubstructureNotifyMask, &ev);
|
SubstructureNotifyMask, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pixmap win_create_pixmap(win_t *win) {
|
||||||
|
if (!win)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return XCreatePixmap(win->env.dpy, win->xwin, THUMB_SIZE, THUMB_SIZE,
|
||||||
|
win->env.depth);
|
||||||
|
}
|
||||||
|
|
||||||
void win_clear(win_t *win) {
|
void win_clear(win_t *win) {
|
||||||
win_env_t *e;
|
win_env_t *e;
|
||||||
XGCValues gcval;
|
XGCValues gcval;
|
||||||
|
2
window.h
2
window.h
@ -63,6 +63,8 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
|
|||||||
|
|
||||||
void win_toggle_fullscreen(win_t*);
|
void win_toggle_fullscreen(win_t*);
|
||||||
|
|
||||||
|
Pixmap win_create_pixmap(win_t*);
|
||||||
|
|
||||||
void win_clear(win_t*);
|
void win_clear(win_t*);
|
||||||
void win_draw(win_t*);
|
void win_draw(win_t*);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user