imgviewer: small improvements
This commit is contained in:
parent
f676ff4295
commit
49da6af715
@ -44,6 +44,8 @@ int top = 40;
|
||||
int width = 300;
|
||||
int height = 300;
|
||||
|
||||
int current_scale = 100;
|
||||
|
||||
sprite_t img = {0};
|
||||
|
||||
#define APPLICATION_TITLE "Image Viewer"
|
||||
@ -60,22 +62,43 @@ void usage(char * argv[]) {
|
||||
}
|
||||
|
||||
static void decors() {
|
||||
if (current_scale != 100) {
|
||||
char tmp[1100];
|
||||
snprintf(tmp, 1100, "%s [%d%%]", window_title, current_scale);
|
||||
render_decorations(window, ctx, tmp);
|
||||
} else {
|
||||
render_decorations(window, ctx, window_title);
|
||||
}
|
||||
}
|
||||
|
||||
void redraw() {
|
||||
static double r = 0.0;
|
||||
uint32_t dark = rgb(107,107,107);
|
||||
uint32_t light = rgb(147,147,147);
|
||||
uint32_t black = rgb(0,0,0);
|
||||
|
||||
int calc_width = img.width * (current_scale / 100.0);
|
||||
int calc_height = img.height * (current_scale / 100.0);
|
||||
|
||||
int image_left = width / 2 - calc_width / 2;
|
||||
int image_right = image_left + calc_width; /* TODO scaling */
|
||||
int image_top = height / 2 - calc_height / 2;
|
||||
int image_bot = image_top + calc_height;
|
||||
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
GFX(ctx,x+decor_left_width,y+decor_top_height) = (((y / 10) % 2 == 0) ^ ((x / 10) % 2 == 0)) ? rgb(107,107,107) : rgb(147,147,147);
|
||||
uint32_t color = (x < image_left || x >= image_right || y < image_top || y >= image_bot) ? black :
|
||||
((((y / 10) % 2 == 0) ^ ((x / 10) % 2 == 0)) ? dark : light);
|
||||
GFX(ctx,x+decor_left_width,y+decor_top_height) = color;
|
||||
}
|
||||
}
|
||||
|
||||
draw_sprite(ctx, &img, decor_left_width + width/2 - img.width/2, decor_top_height + height/2 - img.height/2);
|
||||
if (current_scale != 100) {
|
||||
draw_sprite_scaled(ctx, &img, decor_left_width + image_left, decor_top_height + image_top, calc_width, calc_height);
|
||||
} else {
|
||||
draw_sprite(ctx, &img, decor_left_width + image_left, decor_top_height + image_top);
|
||||
}
|
||||
decors();
|
||||
flip(ctx);
|
||||
r += 0.02;
|
||||
}
|
||||
|
||||
void resize_finish(int w, int h) {
|
||||
@ -101,6 +124,11 @@ void resize_finish(int w, int h) {
|
||||
yutani_flip(yctx, window);
|
||||
}
|
||||
|
||||
static int one_fifth(int scale) {
|
||||
int out = scale * 0.05;
|
||||
if (out) return out;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
|
||||
@ -157,8 +185,8 @@ int main(int argc, char * argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
width = img.width;
|
||||
height = img.height;
|
||||
width = img.width < 300 ? 300 : img.width;
|
||||
height = img.height < 300 ? 300 : img.height;
|
||||
|
||||
window = yutani_window_create(yctx, width + decor_width, height + decor_height);
|
||||
yutani_window_move(yctx, window, left, top);
|
||||
@ -225,6 +253,17 @@ int main(int argc, char * argv[]) {
|
||||
/* Other actions */
|
||||
break;
|
||||
}
|
||||
if (me->wid == window->wid) {
|
||||
if (me->buttons & YUTANI_MOUSE_SCROLL_UP) {
|
||||
current_scale = current_scale + one_fifth(current_scale);
|
||||
redraw();
|
||||
yutani_flip(yctx, window);
|
||||
} else if (me->buttons & YUTANI_MOUSE_SCROLL_DOWN) {
|
||||
current_scale = current_scale - one_fifth(current_scale);
|
||||
redraw();
|
||||
yutani_flip(yctx, window);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case YUTANI_MSG_WINDOW_CLOSE:
|
||||
|
Loading…
Reference in New Issue
Block a user