aboutsummaryrefslogtreecommitdiff
path: root/src/gfx/sdl-1.2
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-02-24 21:12:18 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-30 08:20:21 +0200
commitb925e5e156db07494b338e7c130b72f8e3a7725e (patch)
tree771e581beaadb5e1ece158ee40e4251a61b7873b /src/gfx/sdl-1.2
parent669045df00302d7c4df861c4c21cac1efdb54048 (diff)
downloadjancity-b925e5e156db07494b338e7c130b72f8e3a7725e.tar.gz
gfx: separate port-specific interfaces
Diffstat (limited to 'src/gfx/sdl-1.2')
-rw-r--r--src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h7
-rw-r--r--src/gfx/sdl-1.2/src/env.c45
-rw-r--r--src/gfx/sdl-1.2/src/line.c1
-rw-r--r--src/gfx/sdl-1.2/src/quad.c17
-rw-r--r--src/gfx/sdl-1.2/src/rect.c3
-rw-r--r--src/gfx/sdl-1.2/src/sprite.c3
6 files changed, 64 insertions, 12 deletions
diff --git a/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h b/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h
index c067af7..d095cc0 100644
--- a/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h
+++ b/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h
@@ -1,6 +1,9 @@
#ifndef GFX_SDL_12_PRIVATE_H
#define GFX_SDL_12_PRIVATE_H
+#include <gfx.h>
+#include <SDL/SDL.h>
+
#ifdef __cplusplus
extern "C"
{
@@ -12,6 +15,10 @@ enum
SCREEN_H = 240
};
+int sprite_screen_resize_ev(struct sprite *s);
+void gfx_register_sprite(struct sprite *s);
+SDL_Surface *gfx_screen(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gfx/sdl-1.2/src/env.c b/src/gfx/sdl-1.2/src/env.c
index 6589d84..d6d1f33 100644
--- a/src/gfx/sdl-1.2/src/env.c
+++ b/src/gfx/sdl-1.2/src/env.c
@@ -1,4 +1,5 @@
#include <gfx.h>
+#include <gfx_private.h>
#include <sdl-1.2/gfx_private.h>
#include <SDL/SDL.h>
#include <stdbool.h>
@@ -27,34 +28,58 @@ static int resize_screen(const int w, const int h, const bool full_screen)
return -1;
}
+ static bool init;
+
+ if (!init)
+ {
+ display.w = info->current_w;
+ display.h = info->current_h;
+ init = true;
+ }
+
if (fullscreen)
+ {
flags |= SDL_FULLSCREEN;
+ w = display.w;
+ h = display.h;
+ }
-#if 0
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-#endif
-
- const int bpp = info->vfmt->BitsPerPixel;
+ int bpp = info->vfmt->BitsPerPixel;
if (screen)
SDL_FreeSurface(screen);
- if (!(screen = SDL_SetVideoMode(screen_w, screen_h, bpp, flags)))
+ const int max_bpp = SDL_VideoModeOK(w, h, 0, flags);
+
+ if (max_bpp < 0)
+ {
+ fprintf(stderr, "SDL_VideoModeOK: %s\n", SDL_GetError());
+ return -1;
+ }
+ else if (bpp > max_bpp)
+ bpp = max_bpp;
+
+ if (!(screen = SDL_SetVideoMode(w, h, 0, flags)))
{
fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
return -1;
}
+ for (size_t i = 0; i < list_len; i++)
+ if (sprite_screen_resize_ev(list[i]))
+ return -1;
+
screen_w = w;
screen_h = h;
fullscreen = full_screen;
return 0;
}
+SDL_Surface *gfx_screen(void)
+{
+ return screen;
+}
+
int gfx_init(void)
{
if (SDL_InitSubSystem(SDL_INIT_VIDEO))
diff --git a/src/gfx/sdl-1.2/src/line.c b/src/gfx/sdl-1.2/src/line.c
index aeeda7b..3886204 100644
--- a/src/gfx/sdl-1.2/src/line.c
+++ b/src/gfx/sdl-1.2/src/line.c
@@ -1,5 +1,6 @@
#include <gfx.h>
#include <gfx/port.h>
+#include <sdl-1.2/gfx_private.h>
#include <stddef.h>
void stp_4line_init(struct stp_4line *const l)
diff --git a/src/gfx/sdl-1.2/src/quad.c b/src/gfx/sdl-1.2/src/quad.c
index fe1b39f..b680e0c 100644
--- a/src/gfx/sdl-1.2/src/quad.c
+++ b/src/gfx/sdl-1.2/src/quad.c
@@ -1,5 +1,6 @@
#include <gfx.h>
#include <gfx/port.h>
+#include <sdl-1.2/gfx_private.h>
#include <stddef.h>
#include <stdlib.h>
@@ -15,4 +16,20 @@ int quad_from_sprite(const struct sprite *const s, struct quad *const q)
void quad_sort(struct quad *const q)
{
+ SDL_Rect r =
+ {
+ .x = q->x0,
+ .y = q->y0
+ };
+
+ SDL_Rect clip =
+ {
+ .x = q->u0,
+ .y = q->v0,
+ .w = q->u1 - q->u0 + 1,
+ .h= q->v2 - q->v0 + 1
+ };
+
+ if (SDL_BlitSurface(q->s, &clip, gfx_screen(), &r))
+ fprintf(stderr, "SDL_BlitSurface: %s\n", SDL_GetError());
}
diff --git a/src/gfx/sdl-1.2/src/rect.c b/src/gfx/sdl-1.2/src/rect.c
index ee50378..38d9b62 100644
--- a/src/gfx/sdl-1.2/src/rect.c
+++ b/src/gfx/sdl-1.2/src/rect.c
@@ -1,5 +1,6 @@
#include <gfx.h>
#include <gfx/port.h>
+#include <sdl-1.2/gfx_private.h>
#include <SDL/SDL.h>
#include <stddef.h>
#include <stdlib.h>
@@ -14,7 +15,7 @@ void rect_sort(struct rect *const r)
.h = r->h
};
- SDL_Surface *const screen = gfx_port_screen();
+ SDL_Surface *const screen = gfx_screen();
const Uint32 map = SDL_MapRGB(screen->format, r->r, r->g, r->b);
if (SDL_FillRect(screen, &rct, map))
diff --git a/src/gfx/sdl-1.2/src/sprite.c b/src/gfx/sdl-1.2/src/sprite.c
index e20f1c8..f3a2d94 100644
--- a/src/gfx/sdl-1.2/src/sprite.c
+++ b/src/gfx/sdl-1.2/src/sprite.c
@@ -1,6 +1,7 @@
#include <gfx.h>
#include <gfx/port.h>
#include <header.h>
+#include <sdl-1.2/gfx_private.h>
#include <SDL/SDL.h>
#include <errno.h>
#include <stddef.h>
@@ -120,6 +121,6 @@ void sprite_sort(struct sprite *const s)
.h = s->h
};
- if (SDL_BlitSurface(s->s, &clip, gfx_port_screen(), &r))
+ if (SDL_BlitSurface(s->s, &clip, gfx_screen(), &r))
fprintf(stderr, "SDL_BlitSurface: %s\n", SDL_GetError());
}