aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-04-14 16:56:06 +0100
committerHarry Jeffery <harry@exec64.co.uk>2017-04-14 16:56:06 +0100
commitb9dd2cbc01bdd071fc44db771187d12860191d13 (patch)
tree971571ab6f5277d6aeccad9715e83b7d49fb3ace
parent5a8932cb21f63af86dffa419ec5da5f4a5d29d70 (diff)
downloadimv-b9dd2cbc01bdd071fc44db771187d12860191d13.tar.gz
Refactor texture to new style
-rw-r--r--src/main.c29
-rw-r--r--src/texture.c7
-rw-r--r--src/texture.h8
3 files changed, 23 insertions, 21 deletions
diff --git a/src/main.c b/src/main.c
index e2c0654..2f13b33 100644
--- a/src/main.c
+++ b/src/main.c
@@ -175,7 +175,7 @@ static void parse_args(int argc, char** argv)
struct {
struct imv_navigator nav;
struct imv_loader *ldr;
- struct imv_texture tex;
+ struct imv_texture *tex;
struct imv_viewport view;
struct imv_commands *cmds;
SDL_Window *window;
@@ -356,8 +356,7 @@ int main(int argc, char** argv)
/* create our main classes */
g_state.ldr = imv_loader_create();
-
- imv_init_texture(&g_state.tex, g_state.renderer);
+ g_state.tex = imv_texture_create(g_state.renderer);
imv_init_viewport(&g_state.view, g_state.window);
@@ -453,12 +452,12 @@ int main(int argc, char** argv)
case SDLK_PLUS:
case SDLK_i:
case SDLK_UP:
- imv_viewport_zoom(&g_state.view, &g_state.tex, IMV_ZOOM_KEYBOARD, 1);
+ imv_viewport_zoom(&g_state.view, g_state.tex, IMV_ZOOM_KEYBOARD, 1);
break;
case SDLK_MINUS:
case SDLK_o:
case SDLK_DOWN:
- imv_viewport_zoom(&g_state.view, &g_state.tex, IMV_ZOOM_KEYBOARD, -1);
+ imv_viewport_zoom(&g_state.view, g_state.tex, IMV_ZOOM_KEYBOARD, -1);
break;
case SDLK_s:
if(!e.key.repeat) {
@@ -475,12 +474,12 @@ int main(int argc, char** argv)
break;
case SDLK_a:
if(!e.key.repeat) {
- imv_viewport_scale_to_actual(&g_state.view, &g_state.tex);
+ imv_viewport_scale_to_actual(&g_state.view, g_state.tex);
}
break;
case SDLK_c:
if(!e.key.repeat) {
- imv_viewport_center(&g_state.view, &g_state.tex);
+ imv_viewport_center(&g_state.view, g_state.tex);
}
break;
case SDLK_j:
@@ -536,7 +535,7 @@ int main(int argc, char** argv)
}
break;
case SDL_MOUSEWHEEL:
- imv_viewport_zoom(&g_state.view, &g_state.tex, IMV_ZOOM_MOUSE, e.wheel.y);
+ imv_viewport_zoom(&g_state.view, g_state.tex, IMV_ZOOM_MOUSE, e.wheel.y);
SDL_ShowCursor(SDL_ENABLE);
break;
case SDL_MOUSEMOTION:
@@ -546,7 +545,7 @@ int main(int argc, char** argv)
SDL_ShowCursor(SDL_ENABLE);
break;
case SDL_WINDOWEVENT:
- imv_viewport_update(&g_state.view, &g_state.tex);
+ imv_viewport_update(&g_state.view, g_state.tex);
break;
}
}
@@ -605,7 +604,7 @@ int main(int argc, char** argv)
FIBITMAP *bmp;
int is_new_image;
if(imv_loader_get_image(g_state.ldr, &bmp, &is_new_image)) {
- imv_texture_set_image(&g_state.tex, bmp);
+ imv_texture_set_image(g_state.tex, bmp);
iw = FreeImage_GetWidth(bmp);
ih = FreeImage_GetHeight(bmp);
FreeImage_Unload(bmp);
@@ -617,9 +616,9 @@ int main(int argc, char** argv)
g_state.need_rescale = 0;
if(g_options.scaling == NONE ||
(g_options.scaling == DOWN && ww > iw && wh > ih)) {
- imv_viewport_scale_to_actual(&g_state.view, &g_state.tex);
+ imv_viewport_scale_to_actual(&g_state.view, g_state.tex);
} else {
- imv_viewport_scale_to_window(&g_state.view, &g_state.tex);
+ imv_viewport_scale_to_window(&g_state.view, g_state.tex);
}
}
@@ -663,7 +662,7 @@ int main(int argc, char** argv)
int len;
const char *current_path = imv_navigator_selection(&g_state.nav);
len = snprintf(title, sizeof(title), "imv - [%i/%i] [%ix%i] [%.2f%%] %s [%s]",
- g_state.nav.cur_path + 1, g_state.nav.num_paths, g_state.tex.width, g_state.tex.height,
+ g_state.nav.cur_path + 1, g_state.nav.num_paths, g_state.tex->width, g_state.tex->height,
100.0 * g_state.view.scale,
current_path, scaling_label[g_options.scaling]);
if(g_options.delay >= 1000) {
@@ -692,7 +691,7 @@ int main(int argc, char** argv)
}
/* draw our actual texture */
- imv_texture_draw(&g_state.tex, g_state.view.x, g_state.view.y, g_state.view.scale);
+ imv_texture_draw(g_state.tex, g_state.view.x, g_state.view.y, g_state.view.scale);
/* if the overlay needs to be drawn, draw that too */
if(g_options.overlay && font) {
@@ -771,7 +770,7 @@ int main(int argc, char** argv)
}
imv_loader_free(g_state.ldr);
- imv_destroy_texture(&g_state.tex);
+ imv_texture_free(g_state.tex);
imv_navigator_destroy(&g_state.nav);
imv_destroy_viewport(&g_state.view);
imv_commands_free(g_state.cmds);
diff --git a/src/texture.c b/src/texture.c
index 52ec521..bdfe91f 100644
--- a/src/texture.c
+++ b/src/texture.c
@@ -17,8 +17,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "texture.h"
-void imv_init_texture(struct imv_texture *tex, SDL_Renderer *r)
+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;
@@ -26,9 +27,10 @@ void imv_init_texture(struct imv_texture *tex, SDL_Renderer *r)
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_destroy_texture(struct imv_texture *tex)
+void imv_texture_free(struct imv_texture *tex)
{
if(tex->num_chunks > 0) {
for(int i = 0; i < tex->num_chunks; ++i) {
@@ -39,6 +41,7 @@ void imv_destroy_texture(struct imv_texture *tex)
tex->chunks = NULL;
tex->renderer = NULL;
}
+ free(tex);
}
int imv_texture_set_image(struct imv_texture *tex, FIBITMAP *image)
diff --git a/src/texture.h b/src/texture.h
index 4d2aea9..2931525 100644
--- a/src/texture.h
+++ b/src/texture.h
@@ -36,11 +36,11 @@ struct imv_texture {
};
-/* Initialises an instance of imv_texture */
-void imv_init_texture(struct imv_texture *tex, SDL_Renderer *r);
+/* Creates an instance of imv_texture */
+struct imv_texture *imv_texture_create(SDL_Renderer *r);
-/* Cleans up all resources owned by a imv_texture instance */
-void imv_destroy_texture(struct imv_texture *tex);
+/* 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);