Formatting
This commit is contained in:
+9
-7
@@ -100,7 +100,7 @@ SDL_AppEvent (void *appstate, SDL_Event *event)
|
||||
drag_origin_y = gfx_ctx->world_y_offset;
|
||||
}
|
||||
else if (event->type == SDL_EVENT_MOUSE_BUTTON_UP &&
|
||||
event->button.button == SDL_BUTTON_LEFT)
|
||||
event->button.button == SDL_BUTTON_LEFT)
|
||||
{
|
||||
dragging = false;
|
||||
}
|
||||
@@ -114,7 +114,7 @@ SDL_AppEvent (void *appstate, SDL_Event *event)
|
||||
|
||||
if (event->type == SDL_EVENT_MOUSE_WHEEL)
|
||||
{
|
||||
float zoom_factor = 1.0f + (event->wheel.y * 0.1f); /* ±10% per notch */
|
||||
float zoom_factor = 1.0f + (event->wheel.y * 0.1f); /* ±10% per notch */
|
||||
|
||||
/* Zoom around the mouse cursor */
|
||||
int win_w, win_h;
|
||||
@@ -123,16 +123,18 @@ SDL_AppEvent (void *appstate, SDL_Event *event)
|
||||
float mouse_x = event->wheel.mouse_x;
|
||||
float mouse_y = event->wheel.mouse_y;
|
||||
|
||||
float before_x = (mouse_x - gfx_ctx->world_x_offset) / gfx_ctx->world_scale;
|
||||
float before_y = (mouse_y - gfx_ctx->world_y_offset) / gfx_ctx->world_scale;
|
||||
float before_x =
|
||||
(mouse_x - gfx_ctx->world_x_offset) / gfx_ctx->world_scale;
|
||||
float before_y =
|
||||
(mouse_y - gfx_ctx->world_y_offset) / gfx_ctx->world_scale;
|
||||
|
||||
gfx_ctx->world_scale *= zoom_factor;
|
||||
|
||||
if (gfx_ctx->world_scale < 0.1f)
|
||||
{
|
||||
gfx_ctx->world_scale = 0.1f; /* clamp */
|
||||
gfx_ctx->world_scale = 0.1f; /* clamp */
|
||||
}
|
||||
|
||||
|
||||
if (gfx_ctx->world_scale > 10.0f)
|
||||
{
|
||||
gfx_ctx->world_scale = 10.0f;
|
||||
@@ -143,7 +145,7 @@ SDL_AppEvent (void *appstate, SDL_Event *event)
|
||||
|
||||
gfx_ctx->world_x_offset = mouse_x - after_x;
|
||||
gfx_ctx->world_y_offset = mouse_y - after_y;
|
||||
}
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ GfxContext_new ()
|
||||
}
|
||||
|
||||
GfxContext_reset (self);
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -57,12 +57,12 @@ GfxContext_render (GfxContext *self)
|
||||
{
|
||||
float tex_w, tex_h;
|
||||
SDL_GetTextureSize (self->world_texture, &tex_w, &tex_h);
|
||||
|
||||
|
||||
SDL_FRect dst = {
|
||||
.x = self->world_x_offset,
|
||||
.y = self->world_y_offset,
|
||||
.w = tex_w * self->world_scale,
|
||||
.h = tex_h * self->world_scale
|
||||
.x = self->world_x_offset,
|
||||
.y = self->world_y_offset,
|
||||
.w = tex_w * self->world_scale,
|
||||
.h = tex_h * self->world_scale
|
||||
};
|
||||
|
||||
SDL_RenderTexture (self->renderer, self->world_texture, NULL, &dst);
|
||||
|
||||
@@ -43,7 +43,7 @@ typedef struct GfxContext
|
||||
|
||||
GfxContext *GfxContext_new ();
|
||||
void GfxContext_render (GfxContext * self);
|
||||
void GfxContext_reset (GfxContext *self);
|
||||
void GfxContext_reset (GfxContext * self);
|
||||
void GfxContext_free (GfxContext * self);
|
||||
|
||||
void GfxContext_cache_World (GfxContext * self, World * world);
|
||||
|
||||
Reference in New Issue
Block a user