From 3ceb0eac655e04da262b8148b35ee37a8ae3402a Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Sun, 26 Nov 2017 12:06:41 +0000 Subject: Rename imv_texture -> imv_image --- src/image.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/image.h | 37 ++++++++++++++++ src/imv.c | 50 +++++++++++----------- src/loader.c | 3 +- src/texture.c | 132 --------------------------------------------------------- src/texture.h | 37 ---------------- src/viewport.c | 44 +++++++++---------- src/viewport.h | 18 ++++---- 8 files changed, 227 insertions(+), 226 deletions(-) create mode 100644 src/image.c create mode 100644 src/image.h delete mode 100644 src/texture.c delete mode 100644 src/texture.h (limited to 'src') diff --git a/src/image.c b/src/image.c new file mode 100644 index 0000000..5c9d9b5 --- /dev/null +++ b/src/image.c @@ -0,0 +1,132 @@ +#include "image.h" + +struct imv_image *imv_image_create(SDL_Renderer *r) +{ + struct imv_image *image = malloc(sizeof(struct imv_image)); + memset(image, 0, sizeof(struct imv_image)); + image->renderer = r; + + SDL_RendererInfo ri; + SDL_GetRendererInfo(r, &ri); + image->chunk_width = ri.max_texture_width != 0 ? ri.max_texture_width : 4096; + image->chunk_height = ri.max_texture_height != 0 ? ri.max_texture_height : 4096; + return image; +} + +void imv_image_free(struct imv_image *image) +{ + if(image->num_chunks > 0) { + for(int i = 0; i < image->num_chunks; ++i) { + SDL_DestroyTexture(image->chunks[i]); + } + free(image->chunks); + image->num_chunks = 0; + image->chunks = NULL; + image->renderer = NULL; + } + free(image); +} + +int imv_image_set_bitmap(struct imv_image *image, FIBITMAP *bmp) +{ + image->width = FreeImage_GetWidth(bmp); + image->height = FreeImage_GetHeight(bmp); + + /* figure out how many chunks are needed, and create them */ + if(image->num_chunks > 0) { + for(int i = 0; i < image->num_chunks; ++i) { + SDL_DestroyTexture(image->chunks[i]); + } + free(image->chunks); + } + + image->num_chunks_wide = 1 + image->width / image->chunk_width; + image->num_chunks_tall = 1 + image->height / image->chunk_height; + + image->last_chunk_width = image->width % image->chunk_width; + image->last_chunk_height = image->height % image->chunk_height; + + if(image->last_chunk_width == 0) { + image->last_chunk_width = image->chunk_width; + } + if(image->last_chunk_height == 0) { + image->last_chunk_height = image->chunk_height; + } + + image->num_chunks = image->num_chunks_wide * image->num_chunks_tall; + image->chunks = malloc(sizeof(SDL_Texture*) * image->num_chunks); + + int failed_at = -1; + for(int y = 0; y < image->num_chunks_tall; ++y) { + for(int x = 0; x < image->num_chunks_wide; ++x) { + const int is_last_h_chunk = (x == image->num_chunks_wide - 1); + const int is_last_v_chunk = (y == image->num_chunks_tall - 1); + image->chunks[x + y * image->num_chunks_wide] = + SDL_CreateTexture(image->renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STATIC, + is_last_h_chunk ? image->last_chunk_width : image->chunk_width, + is_last_v_chunk ? image->last_chunk_height : image->chunk_height); + SDL_SetTextureBlendMode(image->chunks[x + y * image->num_chunks_wide], + SDL_BLENDMODE_BLEND); + if(image->chunks[x + y * image->num_chunks_wide] == NULL) { + failed_at = x + y * image->num_chunks_wide; + break; + } + } + } + + if(failed_at != -1) { + for(int i = 0; i <= failed_at; ++i) { + SDL_DestroyTexture(image->chunks[i]); + } + free(image->chunks); + image->num_chunks = 0; + image->chunks = NULL; + return 1; + } + + BYTE* pixels = malloc(4 * image->width * image->height); + FreeImage_ConvertToRawBits(pixels, bmp, 4 * image->width, 32, + FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, TRUE); + + for(int y = 0; y < image->num_chunks_tall; ++y) { + for(int x = 0; x < image->num_chunks_wide; ++x) { + ptrdiff_t offset = 4 * x * image->chunk_width + + y * 4 * image->width * image->chunk_height; + BYTE* addr = pixels + offset; + SDL_UpdateTexture(image->chunks[x + y * image->num_chunks_wide], + NULL, addr, 4 * image->width); + } + } + + free(pixels); + return 0; +} + +void imv_image_draw(struct imv_image *image, int bx, int by, double scale) +{ + int offset_x = 0; + int offset_y = 0; + for(int y = 0; y < image->num_chunks_tall; ++y) { + for(int x = 0; x < image->num_chunks_wide; ++x) { + int img_w, img_h; + SDL_QueryTexture(image->chunks[x + y * image->num_chunks_wide], NULL, NULL, + &img_w, &img_h); + SDL_Rect view_area = { + bx + offset_x, + by + offset_y, + img_w * scale, + img_h * scale + }; + SDL_RenderCopy(image->renderer, + image->chunks[x + y * image->num_chunks_wide], NULL, &view_area); + offset_x += image->chunk_width * scale; + } + offset_x = 0; + offset_y += image->chunk_height * scale; + } +} + + +/* vim:set ts=2 sts=2 sw=2 et: */ diff --git a/src/image.h b/src/image.h new file mode 100644 index 0000000..5b17fff --- /dev/null +++ b/src/image.h @@ -0,0 +1,37 @@ +#ifndef IMV_TEXTURE_H +#define IMV_TEXTURE_H + +#include +#include + +struct imv_image { + int width; /* width of the image overall */ + int height; /* height of the image overall */ + int num_chunks; /* number of chunks allocated */ + SDL_Texture **chunks; /* array of chunks */ + int num_chunks_wide; /* number of chunks per row of the image */ + int num_chunks_tall; /* number of chunks per column of the image */ + int chunk_width; /* chunk width */ + int chunk_height; /* chunk height */ + int last_chunk_width; /* width of rightmost chunk */ + int last_chunk_height; /* height of bottommost chunk */ + SDL_Renderer *renderer; /* SDL renderer to draw to */ +}; + + +/* Creates an instance of imv_image */ +struct imv_image *imv_image_create(SDL_Renderer *r); + +/* Cleans up an imv_image instance */ +void imv_image_free(struct imv_image *image); + +/* Updates the image to contain the data in the bitmap parameter */ +int imv_image_set_bitmap(struct imv_image *image, FIBITMAP *bmp); + +/* Draw the image at the given position with the given scale */ +void imv_image_draw(struct imv_image *image, int x, int y, double scale); + +#endif + + +/* vim:set ts=2 sts=2 sw=2 et: */ diff --git a/src/imv.c b/src/imv.c index 1152305..34a352f 100644 --- a/src/imv.c +++ b/src/imv.c @@ -17,7 +17,7 @@ #include "ini.h" #include "list.h" #include "loader.h" -#include "texture.h" +#include "image.h" #include "navigator.h" #include "viewport.h" #include "util.h" @@ -62,7 +62,7 @@ struct imv { struct imv_navigator *navigator; struct imv_loader *loader; struct imv_commands *commands; - struct imv_texture *texture; + struct imv_image *image; struct imv_viewport *view; void *stdin_image_data; size_t stdin_image_data_len; @@ -72,7 +72,7 @@ struct imv { SDL_Window *window; SDL_Renderer *renderer; TTF_Font *font; - SDL_Texture *background_texture; + SDL_Texture *background_image; bool sdl_init; bool ttf_init; struct { @@ -150,7 +150,7 @@ struct imv *imv_create(void) imv->window = NULL; imv->renderer = NULL; imv->font = NULL; - imv->background_texture = NULL; + imv->background_image = NULL; imv->sdl_init = false; imv->ttf_init = false; @@ -229,8 +229,8 @@ void imv_free(struct imv *imv) if(imv->window) { SDL_DestroyWindow(imv->window); } - if(imv->background_texture) { - SDL_DestroyTexture(imv->background_texture); + if(imv->background_image) { + SDL_DestroyTexture(imv->background_image); } if(imv->font) { TTF_CloseFont(imv->font); @@ -494,9 +494,9 @@ int imv_run(struct imv *imv) (imv->scaling_mode == SCALING_DOWN && ww > imv->current_image.width && wh > imv->current_image.height)) { - imv_viewport_scale_to_actual(imv->view, imv->texture); + imv_viewport_scale_to_actual(imv->view, imv->image); } else { - imv_viewport_scale_to_window(imv->view, imv->texture); + imv_viewport_scale_to_window(imv->view, imv->image); } } @@ -610,9 +610,9 @@ static bool setup_window(struct imv *imv) SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, imv->nearest_neighbour ? "0" : "1"); - /* construct a chequered background texture */ + /* construct a chequered background image */ if(imv->background_type == BACKGROUND_CHEQUERED) { - imv->background_texture = create_chequered(imv->renderer); + imv->background_image = create_chequered(imv->renderer); } /* set up the required fonts and surfaces for displaying the overlay */ @@ -624,7 +624,7 @@ static bool setup_window(struct imv *imv) return false; } - imv->texture = imv_texture_create(imv->renderer); + imv->image = imv_image_create(imv->renderer); imv->view = imv_viewport_create(imv->window); /* put us in fullscren mode to begin with if requested */ @@ -645,7 +645,7 @@ static void handle_event(struct imv *imv, SDL_Event *event) if(event->type == imv->events.NEW_IMAGE) { /* new image to display */ FIBITMAP *bmp = event->user.data1; - imv_texture_set_image(imv->texture, bmp); + imv_image_set_bitmap(imv->image, bmp); imv->current_image.width = FreeImage_GetWidth(bmp); imv->current_image.height = FreeImage_GetHeight(bmp); FreeImage_Unload(bmp); @@ -728,12 +728,12 @@ static void handle_event(struct imv *imv, SDL_Event *event) } break; case SDL_MOUSEWHEEL: - imv_viewport_zoom(imv->view, imv->texture, IMV_ZOOM_MOUSE, event->wheel.y); + imv_viewport_zoom(imv->view, imv->image, IMV_ZOOM_MOUSE, event->wheel.y); SDL_ShowCursor(SDL_ENABLE); break; case SDL_MOUSEMOTION: if(event->motion.state & SDL_BUTTON_LMASK) { - imv_viewport_move(imv->view, event->motion.xrel, event->motion.yrel, imv->texture); + imv_viewport_move(imv->view, event->motion.xrel, event->motion.yrel, imv->image); } SDL_ShowCursor(SDL_ENABLE); break; @@ -749,7 +749,7 @@ static void handle_event(struct imv *imv, SDL_Event *event) SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); } - imv_viewport_update(imv->view, imv->texture); + imv_viewport_update(imv->view, imv->image); break; } } @@ -765,7 +765,7 @@ static void render_window(struct imv *imv) const size_t index_cur = imv_navigator_index(imv->navigator); const size_t index_len = imv_navigator_length(imv->navigator); int len = snprintf(title, sizeof(title), "imv - [%zu/%zu] [%ix%i] [%.2f%%] %s [%s]", - index_cur + 1, index_len, imv->texture->width, imv->texture->height, + index_cur + 1, index_len, imv->image->width, imv->image->height, 100.0 * imv->view->scale, current_path, scaling_label[imv->scaling_mode]); if(imv->slideshow_image_duration >= 1000) { @@ -786,18 +786,18 @@ static void render_window(struct imv *imv) } else { /* chequered background */ int img_w, img_h; - SDL_QueryTexture(imv->background_texture, NULL, NULL, &img_w, &img_h); - /* tile the texture so it fills the window */ + SDL_QueryTexture(imv->background_image, NULL, NULL, &img_w, &img_h); + /* tile the image so it fills the window */ for(int y = 0; y < wh; y += img_h) { for(int x = 0; x < ww; x += img_w) { SDL_Rect dst_rect = {x,y,img_w,img_h}; - SDL_RenderCopy(imv->renderer, imv->background_texture, NULL, &dst_rect); + SDL_RenderCopy(imv->renderer, imv->background_image, NULL, &dst_rect); } } } - /* draw our actual texture */ - imv_texture_draw(imv->texture, imv->view->x, imv->view->y, imv->view->scale); + /* draw our actual image */ + imv_image_draw(imv->image, imv->view->x, imv->view->y, imv->view->scale); /* if the overlay needs to be drawn, draw that too */ if(imv->overlay_enabled && imv->font) { @@ -955,7 +955,7 @@ void command_pan(struct list *args, const char *argstr, void *data) long int x = strtol(args->items[1], NULL, 10); long int y = strtol(args->items[2], NULL, 10); - imv_viewport_move(imv->view, x, y, imv->texture); + imv_viewport_move(imv->view, x, y, imv->image); } void command_select_rel(struct list *args, const char *argstr, void *data) @@ -993,10 +993,10 @@ void command_zoom(struct list *args, const char *argstr, void *data) if(args->len == 2) { const char *str = args->items[1]; if(!strcmp(str, "actual")) { - imv_viewport_scale_to_actual(imv->view, imv->texture); + imv_viewport_scale_to_actual(imv->view, imv->image); } else { long int amount = strtol(args->items[1], NULL, 10); - imv_viewport_zoom(imv->view, imv->texture, IMV_ZOOM_KEYBOARD, amount); + imv_viewport_zoom(imv->view, imv->image, IMV_ZOOM_KEYBOARD, amount); } } } @@ -1043,7 +1043,7 @@ void command_center(struct list *args, const char *argstr, void *data) (void)args; (void)argstr; struct imv *imv = data; - imv_viewport_center(imv->view, imv->texture); + imv_viewport_center(imv->view, imv->image); } void command_reset(struct list *args, const char *argstr, void *data) diff --git a/src/loader.c b/src/loader.c index 3f46f1a..3090c4d 100644 --- a/src/loader.c +++ b/src/loader.c @@ -1,10 +1,11 @@ #include "loader.h" -#include "texture.h" #include #include #include #include #include +#include +#include static void block_usr1_signal(void); static int is_thread_cancelled(void); diff --git a/src/texture.c b/src/texture.c deleted file mode 100644 index f641207..0000000 --- a/src/texture.c +++ /dev/null @@ -1,132 +0,0 @@ -#include "texture.h" - -struct imv_texture *imv_texture_create(SDL_Renderer *r) -{ - struct imv_texture *tex = malloc(sizeof(struct imv_texture)); - memset(tex, 0, sizeof(struct imv_texture)); - tex->renderer = r; - - SDL_RendererInfo ri; - SDL_GetRendererInfo(r, &ri); - tex->chunk_width = ri.max_texture_width != 0 ? ri.max_texture_width : 4096; - tex->chunk_height = ri.max_texture_height != 0 ? ri.max_texture_height : 4096; - return tex; -} - -void imv_texture_free(struct imv_texture *tex) -{ - if(tex->num_chunks > 0) { - for(int i = 0; i < tex->num_chunks; ++i) { - SDL_DestroyTexture(tex->chunks[i]); - } - free(tex->chunks); - tex->num_chunks = 0; - tex->chunks = NULL; - tex->renderer = NULL; - } - free(tex); -} - -int imv_texture_set_image(struct imv_texture *tex, FIBITMAP *image) -{ - tex->width = FreeImage_GetWidth(image); - tex->height = FreeImage_GetHeight(image); - - /* figure out how many chunks are needed, and create them */ - if(tex->num_chunks > 0) { - for(int i = 0; i < tex->num_chunks; ++i) { - SDL_DestroyTexture(tex->chunks[i]); - } - free(tex->chunks); - } - - tex->num_chunks_wide = 1 + tex->width / tex->chunk_width; - tex->num_chunks_tall = 1 + tex->height / tex->chunk_height; - - tex->last_chunk_width = tex->width % tex->chunk_width; - tex->last_chunk_height = tex->height % tex->chunk_height; - - if(tex->last_chunk_width == 0) { - tex->last_chunk_width = tex->chunk_width; - } - if(tex->last_chunk_height == 0) { - tex->last_chunk_height = tex->chunk_height; - } - - tex->num_chunks = tex->num_chunks_wide * tex->num_chunks_tall; - tex->chunks = malloc(sizeof(SDL_Texture*) * tex->num_chunks); - - int failed_at = -1; - for(int y = 0; y < tex->num_chunks_tall; ++y) { - for(int x = 0; x < tex->num_chunks_wide; ++x) { - const int is_last_h_chunk = (x == tex->num_chunks_wide - 1); - const int is_last_v_chunk = (y == tex->num_chunks_tall - 1); - tex->chunks[x + y * tex->num_chunks_wide] = - SDL_CreateTexture(tex->renderer, - SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STATIC, - is_last_h_chunk ? tex->last_chunk_width : tex->chunk_width, - is_last_v_chunk ? tex->last_chunk_height : tex->chunk_height); - SDL_SetTextureBlendMode(tex->chunks[x + y * tex->num_chunks_wide], - SDL_BLENDMODE_BLEND); - if(tex->chunks[x + y * tex->num_chunks_wide] == NULL) { - failed_at = x + y * tex->num_chunks_wide; - break; - } - } - } - - if(failed_at != -1) { - for(int i = 0; i <= failed_at; ++i) { - SDL_DestroyTexture(tex->chunks[i]); - } - free(tex->chunks); - tex->num_chunks = 0; - tex->chunks = NULL; - return 1; - } - - BYTE* pixels = malloc(4 * tex->width * tex->height); - FreeImage_ConvertToRawBits(pixels, image, 4 * tex->width, 32, - FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, TRUE); - - for(int y = 0; y < tex->num_chunks_tall; ++y) { - for(int x = 0; x < tex->num_chunks_wide; ++x) { - ptrdiff_t offset = 4 * x * tex->chunk_width + - y * 4 * tex->width * tex->chunk_height; - BYTE* addr = pixels + offset; - SDL_UpdateTexture(tex->chunks[x + y * tex->num_chunks_wide], - NULL, addr, 4 * tex->width); - } - } - - free(pixels); - return 0; -} - -void imv_texture_draw(struct imv_texture *tex, int bx, int by, double scale) -{ - int offset_x = 0; - int offset_y = 0; - for(int y = 0; y < tex->num_chunks_tall; ++y) { - for(int x = 0; x < tex->num_chunks_wide; ++x) { - int img_w, img_h; - SDL_QueryTexture(tex->chunks[x + y * tex->num_chunks_wide], NULL, NULL, - &img_w, &img_h); - SDL_Rect view_area = { - bx + offset_x, - by + offset_y, - img_w * scale, - img_h * scale - }; - SDL_RenderCopy(tex->renderer, - tex->chunks[x + y * tex->num_chunks_wide], NULL, &view_area); - offset_x += tex->chunk_width * scale; - } - offset_x = 0; - offset_y += tex->chunk_height * scale; - } -} - - -/* vim:set ts=2 sts=2 sw=2 et: */ diff --git a/src/texture.h b/src/texture.h deleted file mode 100644 index 873811c..0000000 --- a/src/texture.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef IMV_TEXTURE_H -#define IMV_TEXTURE_H - -#include -#include - -struct imv_texture { - int width; /* width of the texture overall */ - int height; /* height of the texture overall */ - int num_chunks; /* number of chunks allocated */ - SDL_Texture **chunks; /* array of chunks */ - int num_chunks_wide; /* number of chunks per row of the image */ - int num_chunks_tall; /* number of chunks per column of the image */ - int chunk_width; /* chunk width */ - int chunk_height; /* chunk height */ - int last_chunk_width; /* width of rightmost chunk */ - int last_chunk_height; /* height of bottommost chunk */ - SDL_Renderer *renderer; /* SDL renderer to draw to */ -}; - - -/* Creates an instance of imv_texture */ -struct imv_texture *imv_texture_create(SDL_Renderer *r); - -/* Cleans up an imv_texture instance */ -void imv_texture_free(struct imv_texture *tex); - -/* Updates the texture to contain the data in the image parameter */ -int imv_texture_set_image(struct imv_texture *tex, FIBITMAP *image); - -/* Draw the texture at the given position with the given scale */ -void imv_texture_draw(struct imv_texture *tex, int x, int y, double scale); - -#endif - - -/* vim:set ts=2 sts=2 sw=2 et: */ diff --git a/src/viewport.c b/src/viewport.c index aad717c..ffefbcd 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -32,23 +32,23 @@ void imv_viewport_toggle_playing(struct imv_viewport *view) view->playing = !view->playing; } -void imv_viewport_scale_to_actual(struct imv_viewport *view, const struct imv_texture *tex) +void imv_viewport_scale_to_actual(struct imv_viewport *view, const struct imv_image *image) { view->scale = 1; view->redraw = 1; view->locked = 1; - imv_viewport_center(view, tex); + imv_viewport_center(view, image); } void imv_viewport_move(struct imv_viewport *view, int x, int y, - const struct imv_texture *tex) + const struct imv_image *image) { view->x += x; view->y += y; view->redraw = 1; view->locked = 1; - int w = (int)((double)tex->width * view->scale); - int h = (int)((double)tex->height * view->scale); + int w = (int)((double)image->width * view->scale); + int h = (int)((double)image->height * view->scale); int ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); if (view->x < -w) { @@ -65,7 +65,7 @@ void imv_viewport_move(struct imv_viewport *view, int x, int y, } } -void imv_viewport_zoom(struct imv_viewport *view, const struct imv_texture *tex, enum imv_zoom_source src, int amount) +void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *image, enum imv_zoom_source src, int amount) { double prev_scale = view->scale; int x, y, ww, wh; @@ -77,18 +77,18 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_texture *tex, x -= view->x; y -= view->y; } else { - x = view->scale * tex->width / 2; - y = view->scale * tex->height / 2; + x = view->scale * image->width / 2; + y = view->scale * image->height / 2; } - const int scaled_width = tex->width * view->scale; - const int scaled_height = tex->height * view->scale; + const int scaled_width = image->width * view->scale; + const int scaled_height = image->height * view->scale; const int ic_x = view->x + scaled_width/2; const int ic_y = view->y + scaled_height/2; const int wc_x = ww/2; const int wc_y = wh/2; - double delta_scale = 0.04 * ww * amount / tex->width; + double delta_scale = 0.04 * ww * amount / image->width; view->scale += delta_scale; const double min_scale = 0.1; @@ -125,35 +125,35 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_texture *tex, view->locked = 1; } -void imv_viewport_center(struct imv_viewport *view, const struct imv_texture *tex) +void imv_viewport_center(struct imv_viewport *view, const struct imv_image *image) { int ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); - view->x = (ww - tex->width * view->scale) / 2; - view->y = (wh - tex->height * view->scale) / 2; + view->x = (ww - image->width * view->scale) / 2; + view->y = (wh - image->height * view->scale) / 2; view->locked = 1; view->redraw = 1; } -void imv_viewport_scale_to_window(struct imv_viewport *view, const struct imv_texture *tex) +void imv_viewport_scale_to_window(struct imv_viewport *view, const struct imv_image *image) { int ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); double window_aspect = (double)ww / (double)wh; - double image_aspect = (double)tex->width / (double)tex->height; + double image_aspect = (double)image->width / (double)image->height; if(window_aspect > image_aspect) { /* Image will become too tall before it becomes too wide */ - view->scale = (double)wh / (double)tex->height; + view->scale = (double)wh / (double)image->height; } else { /* Image will become too wide before it becomes too tall */ - view->scale = (double)ww / (double)tex->width; + view->scale = (double)ww / (double)image->width; } - imv_viewport_center(view, tex); + imv_viewport_center(view, image); view->locked = 0; } @@ -167,15 +167,15 @@ void imv_viewport_set_title(struct imv_viewport *view, char* title) SDL_SetWindowTitle(view->window, title); } -void imv_viewport_update(struct imv_viewport *view, struct imv_texture *tex) +void imv_viewport_update(struct imv_viewport *view, struct imv_image *image) { view->redraw = 1; if(view->locked) { return; } - imv_viewport_center(view, tex); - imv_viewport_scale_to_window(view, tex); + imv_viewport_center(view, image); + imv_viewport_scale_to_window(view, image); } int imv_viewport_needs_redraw(struct imv_viewport *view) diff --git a/src/viewport.h b/src/viewport.h index b1d8bf7..bda55f1 100644 --- a/src/viewport.h +++ b/src/viewport.h @@ -2,7 +2,7 @@ #define IMV_VIEWPORT_H #include -#include "texture.h" +#include "image.h" struct imv_viewport { SDL_Window *window; @@ -35,27 +35,27 @@ void imv_viewport_toggle_playing(struct imv_viewport *view); /* Reset the viewport to its initial settings */ void imv_viewport_reset(struct imv_viewport *view); -/* Pan the view by the given amounts without letting the texture get too far +/* Pan the view by the given amounts without letting the image get too far * off-screen */ void imv_viewport_move(struct imv_viewport *view, int x, int y, - const struct imv_texture *tex); + const struct imv_image *image); -/* Zoom the view by the given amount. imv_texture* is used to get the image +/* Zoom the view by the given amount. imv_image* is used to get the image * dimensions */ -void imv_viewport_zoom(struct imv_viewport *view, const struct imv_texture *tex, +void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *image, enum imv_zoom_source, int amount); /* Recenter the view to be in the middle of the image */ void imv_viewport_center(struct imv_viewport *view, - const struct imv_texture *tex); + const struct imv_image *image); /* Scale the view so that the image appears at its actual resolution */ void imv_viewport_scale_to_actual(struct imv_viewport *view, - const struct imv_texture *tex); + const struct imv_image *image); /* Scale the view so that the image fills the window */ void imv_viewport_scale_to_window(struct imv_viewport *view, - const struct imv_texture *tex); + const struct imv_image *image); /* Tell the viewport that it needs to be redrawn */ void imv_viewport_set_redraw(struct imv_viewport *view); @@ -64,7 +64,7 @@ void imv_viewport_set_redraw(struct imv_viewport *view); void imv_viewport_set_title(struct imv_viewport *view, char *title); /* Tell the viewport the window or image has changed */ -void imv_viewport_update(struct imv_viewport *view, struct imv_texture *tex); +void imv_viewport_update(struct imv_viewport *view, struct imv_image *image); /* Poll whether we need to redraw */ int imv_viewport_needs_redraw(struct imv_viewport *view); -- cgit v1.2.3