Compare commits
5 Commits
e636accfd5
...
f753ede740
Author | SHA1 | Date |
---|---|---|
Xavier Del Campo Romero | f753ede740 | |
Xavier Del Campo Romero | 2d22b88695 | |
Xavier Del Campo Romero | 360ea710e0 | |
Xavier Del Campo Romero | 96dbdea21e | |
Xavier Del Campo Romero | 1ea5a4d4a4 |
|
@ -8,6 +8,7 @@ ExternalProject_Add(tools
|
|||
-D CMAKE_INSTALL_PREFIX=${TOOLS_PREFIX})
|
||||
|
||||
project(rts)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
||||
|
||||
if(CMAKE_TOOLCHAIN_FILE MATCHES "ps1")
|
||||
set(PS1_BUILD 1)
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
FindSDL_gfx
|
||||
-------------
|
||||
|
||||
Locate SDL_gfx library
|
||||
|
||||
This module defines:
|
||||
|
||||
::
|
||||
|
||||
SDL_GFX_LIBRARIES, the name of the library to link against
|
||||
SDL_GFX_INCLUDE_DIRS, where to find the headers
|
||||
SDL_GFX_FOUND, if false, do not try to link against
|
||||
SDL_GFX_VERSION_STRING - human-readable string containing the
|
||||
version of SDL_gfx
|
||||
|
||||
|
||||
|
||||
For backward compatibility the following variables are also set:
|
||||
|
||||
::
|
||||
|
||||
SDLGFX_LIBRARY (same value as SDL_GFX_LIBRARIES)
|
||||
SDLGFX_INCLUDE_DIR (same value as SDL_GFX_INCLUDE_DIRS)
|
||||
SDLGFX_FOUND (same value as SDL_GFX_FOUND)
|
||||
|
||||
|
||||
|
||||
$SDLDIR is an environment variable that would correspond to the
|
||||
./configure --prefix=$SDLDIR used in building SDL.
|
||||
|
||||
Created by Xavier Del Campo, heavily based on the original work by
|
||||
Eric Wing, FindSDL_mixer.cmake.
|
||||
#]=======================================================================]
|
||||
|
||||
if(NOT SDL_GFX_INCLUDE_DIR AND SDLGFX_INCLUDE_DIR)
|
||||
set(SDL_GFX_INCLUDE_DIR ${SDLGFX_INCLUDE_DIR} CACHE PATH "directory cache
|
||||
entry initialized from old variable name")
|
||||
endif()
|
||||
find_path(SDL_GFX_INCLUDE_DIR
|
||||
SDL_framerate.h
|
||||
SDL_gfxBlitFunc.h
|
||||
SDL_gfxPrimitives.h
|
||||
SDL_gfxPrimitives_font.h
|
||||
SDL_imageFilter.h
|
||||
SDL_rotozoom.h
|
||||
HINTS
|
||||
ENV SDLGFXDIR
|
||||
ENV SDLDIR
|
||||
PATH_SUFFIXES SDL
|
||||
# path suffixes to search inside ENV{SDLDIR}
|
||||
include/SDL include/SDL12 include/SDL11 include
|
||||
)
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(VC_LIB_PATH_SUFFIX lib/x64)
|
||||
else()
|
||||
set(VC_LIB_PATH_SUFFIX lib/x86)
|
||||
endif()
|
||||
|
||||
if(NOT SDL_GFX_LIBRARY AND SDLGFX_LIBRARY)
|
||||
set(SDL_GFX_LIBRARY ${SDLGFX_LIBRARY} CACHE FILEPATH "file cache entry
|
||||
initialized from old variable name")
|
||||
endif()
|
||||
find_library(SDL_GFX_LIBRARY
|
||||
NAMES SDL_gfx
|
||||
HINTS
|
||||
ENV SDLGFXDIR
|
||||
ENV SDLDIR
|
||||
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
|
||||
)
|
||||
|
||||
if(SDL_GFX_INCLUDE_DIR AND EXISTS "${SDL_GFX_INCLUDE_DIR}/SDL_gfxPrimitives.h")
|
||||
file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MAJOR[ \t]+[0-9]+$")
|
||||
file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MINOR[ \t]+[0-9]+$")
|
||||
file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MICRO[ \t]+[0-9]+$")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MAJOR[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MAJOR "${SDL_GFX_VERSION_MAJOR_LINE}")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MINOR[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MINOR "${SDL_GFX_VERSION_MINOR_LINE}")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MICRO[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_PATCH "${SDL_GFX_VERSION_PATCH_LINE}")
|
||||
set(SDL_GFX_VERSION_STRING ${SDL_GFX_VERSION_MAJOR}.${SDL_GFX_VERSION_MINOR}.${SDL_GFX_VERSION_PATCH})
|
||||
unset(SDL_GFX_VERSION_MAJOR_LINE)
|
||||
unset(SDL_GFX_VERSION_MINOR_LINE)
|
||||
unset(SDL_GFX_VERSION_PATCH_LINE)
|
||||
unset(SDL_GFX_VERSION_MAJOR)
|
||||
unset(SDL_GFX_VERSION_MINOR)
|
||||
unset(SDL_GFX_VERSION_PATCH)
|
||||
endif()
|
||||
|
||||
set(SDL_GFX_LIBRARIES ${SDL_GFX_LIBRARY})
|
||||
set(SDL_GFX_INCLUDE_DIRS ${SDL_GFX_INCLUDE_DIR})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_gfx
|
||||
REQUIRED_VARS SDL_GFX_LIBRARIES SDL_GFX_INCLUDE_DIRS
|
||||
VERSION_VAR SDL_GFX_VERSION_STRING)
|
||||
|
||||
# for backward compatibility
|
||||
set(SDLGFX_LIBRARY ${SDL_GFX_LIBRARIES})
|
||||
set(SDLGFX_INCLUDE_DIR ${SDL_GFX_INCLUDE_DIRS})
|
||||
set(SDLGFX_FOUND ${SDL_GFX_FOUND})
|
||||
|
||||
mark_as_advanced(SDL_GFX_LIBRARY SDL_GFX_INCLUDE_DIR)
|
|
@ -1,6 +1,7 @@
|
|||
file(MAKE_DIRECTORY ${cdroot})
|
||||
find_package(SDL 1.2 REQUIRED)
|
||||
find_package(SDL_mixer 1.2 REQUIRED)
|
||||
find_package(SDL_gfx 2.0 REQUIRED)
|
||||
set(SDL1_2_BUILD 1)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
|
|
@ -3,6 +3,8 @@ if("$ENV{SDL_PATH}" STREQUAL "")
|
|||
message(FATAL_ERROR "please define env variable SDL_PATH")
|
||||
elseif("$ENV{SDL_MIXER_PATH}" STREQUAL "")
|
||||
message(FATAL_ERROR "please define env variable SDL_MIXER_PATH")
|
||||
elseif("$ENV{SDL_GFX_PATH}" STREQUAL "")
|
||||
message(FATAL_ERROR "please define env variable SDL_GFX_PATH")
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT ${cdroot}/${PROJECT_NAME}
|
||||
|
@ -24,6 +26,12 @@ set_property(TARGET SDL_mixer PROPERTY IMPORTED_LOCATION
|
|||
target_include_directories(SDL_mixer INTERFACE $ENV{SDL_MIXER_PATH}/include)
|
||||
target_link_libraries(SDL_mixer INTERFACE SDL)
|
||||
|
||||
add_library(SDL_gfx STATIC IMPORTED)
|
||||
set_property(TARGET SDL_gfx PROPERTY IMPORTED_LOCATION
|
||||
$ENV{SDL_GFX_PATH}/lib/libSDL_gfx.a)
|
||||
target_include_directories(SDL_gfx INTERFACE $ENV{SDL_GFX_PATH}/include)
|
||||
target_link_libraries(SDL_gfx INTERFACE SDL)
|
||||
|
||||
add_compile_options(-march=i386)
|
||||
set(SDL1_2_BUILD 1)
|
||||
|
||||
|
|
|
@ -125,3 +125,10 @@ WAVE files, support for other audio formats is not required.
|
|||
--disable-music-flac CC=i386-mingw32-gcc --with-sdl-prefix=$HOME/sdl-1.2.15 \
|
||||
CFLAGS='-ffunction-sections -fdata-sections'
|
||||
```
|
||||
|
||||
```sh
|
||||
../SDL_gfx-2.0.26-src/configure --host=i386-mingw32 --enable-shared=no \
|
||||
--prefix=$HOME/SDL_gfx-2.0.26 --with-sdl-prefix=$HOME/sdl-1.2.15 \
|
||||
CFLAGS='-ffunction-sections -fdata-sections' \
|
||||
CC=i386-mingw32-gcc
|
||||
```
|
||||
|
|
|
@ -25,7 +25,7 @@ elseif(SDL1_2_BUILD)
|
|||
"sdl-1.2/src/sprite.c"
|
||||
"sdl-1.2/src/quad.c")
|
||||
set(deps ${deps} SDL)
|
||||
set(privdeps ${privdeps} header)
|
||||
set(privdeps ${privdeps} header SDL_gfx)
|
||||
endif()
|
||||
|
||||
add_library(gfx ${src})
|
||||
|
|
|
@ -11,7 +11,7 @@ extern "C"
|
|||
|
||||
struct sprite
|
||||
{
|
||||
SDL_Surface *s;
|
||||
SDL_Surface *s, *s_x;
|
||||
short x, y, w, h;
|
||||
unsigned char u, v;
|
||||
bool transparent;
|
||||
|
@ -24,8 +24,9 @@ struct quad
|
|||
short y0, y1, y2, y3;
|
||||
unsigned char u0, u1, u2, u3;
|
||||
unsigned char v0, v1, v2, v3;
|
||||
short w, h;
|
||||
bool transparent;
|
||||
SDL_Surface *s;
|
||||
SDL_Surface *s, *s_x;
|
||||
};
|
||||
|
||||
struct rect
|
||||
|
|
|
@ -7,29 +7,38 @@
|
|||
int quad_from_sprite(const struct sprite *const s, struct quad *const q)
|
||||
{
|
||||
q->s = s->s;
|
||||
q->s_x = s->s_x;
|
||||
q->u0 = q->u2 = s->u;
|
||||
q->v0 = q->v1 = s->v;
|
||||
q->u1 = q->u3 = s->u + s->w - 1;
|
||||
q->v2 = q->v3 = s->v + s->h - 1;
|
||||
q->w = s->w;
|
||||
q->h = s->h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void quad_sort(struct quad *const q)
|
||||
{
|
||||
const bool xflip = q->x0 > q->x1;
|
||||
|
||||
SDL_Rect r =
|
||||
{
|
||||
.x = q->x0,
|
||||
.x = xflip ? q->x1 : q->x0,
|
||||
.y = q->y0
|
||||
};
|
||||
|
||||
const short w = q->u1 - q->u0 + 1, h = q->v2 - q->v0 + 1;
|
||||
|
||||
SDL_Rect clip =
|
||||
{
|
||||
.x = q->u0,
|
||||
.x = xflip ? q->w - q->u0 - w: q->u0,
|
||||
.y = q->v0,
|
||||
.w = q->u1 - q->u0 + 1,
|
||||
.h= q->v2 - q->v0 + 1
|
||||
.w = w,
|
||||
.h = h
|
||||
};
|
||||
|
||||
if (SDL_BlitSurface(q->s, &clip, gfx_screen(), &r))
|
||||
SDL_Surface *const s = xflip ? q->s_x : q->s;
|
||||
|
||||
if (SDL_BlitSurface(s, &clip, gfx_screen(), &r))
|
||||
fprintf(stderr, "SDL_BlitSurface: %s\n", SDL_GetError());
|
||||
}
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#include <gfx/port.h>
|
||||
#include <sdl-1.2/gfx_private.h>
|
||||
#include <SDL/SDL.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void rect_sort(struct rect *const r)
|
||||
{
|
||||
|
@ -29,7 +25,7 @@ void rect_sort(struct rect *const r)
|
|||
|
||||
void rect_init(struct rect *const r)
|
||||
{
|
||||
memset(r, 0, sizeof *r);
|
||||
*r = (const struct rect){0};
|
||||
}
|
||||
|
||||
void semitrans_rect_init(struct rect *const r)
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#include <header.h>
|
||||
#include <sdl-1.2/gfx_private.h>
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_rotozoom.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void sprite_free(struct sprite *const s)
|
||||
{
|
||||
|
@ -20,20 +20,32 @@ int sprite_clone(const struct sprite *const src, struct sprite *const dst)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int set_transparent(SDL_Surface *const s)
|
||||
{
|
||||
/* Magenta as transparent. */
|
||||
const Uint32 map = SDL_MapRGB(s->format, 255, 0, 255);
|
||||
const int ret = SDL_SetColorKey(s, SDL_SRCCOLORKEY | SDL_RLEACCEL, map);
|
||||
|
||||
if (ret)
|
||||
fprintf(stderr, "SDL_SetColorKey: %s\n", SDL_GetError());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sprite_screen_resize_ev(struct sprite *const s)
|
||||
{
|
||||
int ret = -1;
|
||||
SDL_Surface *const old = s->s;
|
||||
SDL_Surface *const old = s->s, *const old_x = s->s_x;
|
||||
|
||||
/* Magenta as transparent. */
|
||||
if (s->transparent
|
||||
&& SDL_SetColorKey(old, SDL_SRCCOLORKEY | SDL_RLEACCEL,
|
||||
SDL_MapRGB(old->format, 255, 0, 255)))
|
||||
if (s->transparent && (set_transparent(old) || set_transparent(old_x)))
|
||||
goto end;
|
||||
else if (!(s->s = SDL_DisplayFormat(old)))
|
||||
{
|
||||
fprintf(stderr, "SDL_SetColorKey: %s\n", SDL_GetError());
|
||||
fprintf(stderr, "SDL_DisplayFormat: %s\n", SDL_GetError());
|
||||
goto end;
|
||||
}
|
||||
else if (!(s->s = SDL_DisplayFormat(old)))
|
||||
else if (!(s->s_x = SDL_DisplayFormat(old_x)))
|
||||
{
|
||||
fprintf(stderr, "SDL_DisplayFormat: %s\n", SDL_GetError());
|
||||
goto end;
|
||||
|
@ -43,6 +55,7 @@ int sprite_screen_resize_ev(struct sprite *const s)
|
|||
|
||||
end:
|
||||
SDL_FreeSurface(old);
|
||||
SDL_FreeSurface(old_x);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -58,31 +71,35 @@ static int load_bitmap(struct sprite *const s, FILE *const f)
|
|||
{
|
||||
int ret = -1;
|
||||
SDL_RWops *ops = NULL;
|
||||
SDL_Surface *ts = NULL;
|
||||
SDL_Surface *ts = NULL, *zs = NULL;
|
||||
|
||||
if (!(ops = SDL_RWFromFP(f, 0)))
|
||||
{
|
||||
fprintf(stderr, "SDL_RWFromFP: %s\n", SDL_GetError());
|
||||
goto end;
|
||||
}
|
||||
if (!(ts = SDL_LoadBMP_RW(ops, 0)))
|
||||
else if (!(ts = SDL_LoadBMP_RW(ops, 0)))
|
||||
{
|
||||
fprintf(stderr, "SDL_LoadBMP_RW: %s\n", SDL_GetError());
|
||||
goto end;
|
||||
}
|
||||
/* Magenta as transparent. */
|
||||
else if (s->transparent
|
||||
&& SDL_SetColorKey(ts, SDL_SRCCOLORKEY | SDL_RLEACCEL,
|
||||
SDL_MapRGB(ts->format, 255, 0, 255)))
|
||||
else if (!(zs = zoomSurface(ts, -1, 1, 0)))
|
||||
{
|
||||
fprintf(stderr, "SDL_SetColorKey: %s\n", SDL_GetError());
|
||||
fprintf(stderr, "zoomSurface: %s\n", SDL_GetError());
|
||||
goto end;
|
||||
}
|
||||
else if (s->transparent && (set_transparent(ts) || set_transparent(zs)))
|
||||
goto end;
|
||||
else if (!(s->s = SDL_DisplayFormat(ts)))
|
||||
{
|
||||
fprintf(stderr, "SDL_DisplayFormat: %s\n", SDL_GetError());
|
||||
goto end;
|
||||
}
|
||||
else if (!(s->s_x = SDL_DisplayFormat(zs)))
|
||||
{
|
||||
fprintf(stderr, "SDL_DisplayFormat: %s\n", SDL_GetError());
|
||||
goto end;
|
||||
}
|
||||
|
||||
gfx_register_sprite(s);
|
||||
s->w = ts->w;
|
||||
|
@ -92,12 +109,13 @@ static int load_bitmap(struct sprite *const s, FILE *const f)
|
|||
end:
|
||||
SDL_FreeRW(ops);
|
||||
SDL_FreeSurface(ts);
|
||||
SDL_FreeSurface(zs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sprite_from_fp(struct sprite *const s, FILE *const f)
|
||||
{
|
||||
memset(s, 0, sizeof *s);
|
||||
*s = (const struct sprite){0};
|
||||
|
||||
if (load_header(s, f) || load_bitmap(s, f))
|
||||
return -1;
|
||||
|
|
|
@ -79,10 +79,10 @@ void gui_add_child(struct gui_common *const p,
|
|||
int gui_update(struct gui_common *const g, const union peripheral *const p,
|
||||
const struct camera *const c)
|
||||
{
|
||||
if (g->cb && g->cb->update && g->cb->update(g, p, c))
|
||||
if (g->child && gui_update(g->child, p, c))
|
||||
return -1;
|
||||
|
||||
if (g->child && gui_update(g->child, p, c))
|
||||
if (g->cb && g->cb->update && g->cb->update(g, p, c))
|
||||
return -1;
|
||||
|
||||
for (struct gui_common *s = g->sibling; s; s = s->sibling)
|
||||
|
|
Loading…
Reference in New Issue