mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
character: transparently support ImgToWebp scaling factor
This commit is contained in:
parent
7c94d31d66
commit
a4147d2e61
2 changed files with 22 additions and 12 deletions
|
@ -378,20 +378,24 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
else(IMGTOWEBP_LOSSLESS)
|
||||
set(IMGTOWEBP_QUALITY "75" CACHE STRING "Quality of resulting WebP files")
|
||||
endif(IMGTOWEBP_LOSSLESS)
|
||||
set(IMGTOWEBP_RESIZE "" CACHE STRING "Value passed as -resize to ImageMagick (no resizing when empty)")
|
||||
set(IMGTOWEBP_SCALE "100" CACHE STRING "Scaling factor (percentage) used when converting image assets to WebP")
|
||||
set(IMGTOWEBP_PARAMS "" CACHE STRING "Additional ImageMagick parameters")
|
||||
|
||||
if(IMGTOWEBP)
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_img_to_webp
|
||||
DEPENDS ${ASSET_PIPELINE_DEPEND}
|
||||
COMMAND ${CMAKE_COMMAND} -DQUALITY="${IMGTOWEBP_QUALITY}" -DRESIZE="${IMGTOWEBP_RESIZE}" -DPARAMS="${IMGTOWEBP_PARAMS}" -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DLOSSLESS="${IMGTOWEBP_LOSSLESS}" -DDATADIR=${ASSET_PIPELINE_DATADIR} -P ${LIBSUPERDERPY_DIR}/cmake/ImgToWebp.cmake
|
||||
COMMAND ${CMAKE_COMMAND} -DQUALITY="${IMGTOWEBP_QUALITY}" -DRESIZE="${IMGTOWEBP_SCALE}%" -DPARAMS="${IMGTOWEBP_PARAMS}" -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DLOSSLESS="${IMGTOWEBP_LOSSLESS}" -DDATADIR=${ASSET_PIPELINE_DATADIR} -P ${LIBSUPERDERPY_DIR}/cmake/ImgToWebp.cmake
|
||||
USES_TERMINAL)
|
||||
add_definitions(-DLIBSUPERDERPY_IMGTOWEBP)
|
||||
add_definitions("-DLIBSUPERDERPY_IMAGE_SCALE=(${IMGTOWEBP_SCALE} / 100.0)")
|
||||
else(IMGTOWEBP)
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_img_to_webp
|
||||
DEPENDS ${ASSET_PIPELINE_DEPEND})
|
||||
add_definitions(-DLIBSUPERDERPY_IMAGE_SCALE=1)
|
||||
endif(IMGTOWEBP)
|
||||
|
||||
else (ANDROID OR EMSCRIPTEN)
|
||||
add_definitions(-DLIBSUPERDERPY_IMAGE_SCALE=1)
|
||||
endif (ANDROID OR EMSCRIPTEN)
|
||||
|
||||
MACRO(add_libsuperderpy_target EXECUTABLE_SRC_LIST)
|
||||
|
|
|
@ -103,8 +103,8 @@ SYMBOL_EXPORT void LoadSpritesheets(struct Game* game, struct Character* charact
|
|||
}
|
||||
tmp->bitmap = AddBitmap(game, filename);
|
||||
tmp->filepath = strdup(filename);
|
||||
tmp->width = al_get_bitmap_width(tmp->bitmap) / tmp->cols;
|
||||
tmp->height = al_get_bitmap_height(tmp->bitmap) / tmp->rows;
|
||||
tmp->width = (al_get_bitmap_width(tmp->bitmap) / LIBSUPERDERPY_IMAGE_SCALE) / tmp->cols;
|
||||
tmp->height = (al_get_bitmap_height(tmp->bitmap) / LIBSUPERDERPY_IMAGE_SCALE) / tmp->rows;
|
||||
}
|
||||
for (int i = 0; i < tmp->frame_count; i++) {
|
||||
if ((!tmp->frames[i].source) && (tmp->frames[i].file)) {
|
||||
|
@ -120,15 +120,15 @@ SYMBOL_EXPORT void LoadSpritesheets(struct Game* game, struct Character* charact
|
|||
tmp->frames[i].source = AddBitmap(game, filename);
|
||||
tmp->frames[i].filepath = strdup(filename);
|
||||
} else if (!tmp->frames[i].source) {
|
||||
tmp->frames[i].source = al_create_sub_bitmap(tmp->bitmap, tmp->frames[i].col * tmp->width, tmp->frames[i].row * tmp->height, tmp->width, tmp->height);
|
||||
tmp->frames[i].source = al_create_sub_bitmap(tmp->bitmap, tmp->frames[i].col * tmp->width * LIBSUPERDERPY_IMAGE_SCALE, tmp->frames[i].row * tmp->height * LIBSUPERDERPY_IMAGE_SCALE, tmp->width * LIBSUPERDERPY_IMAGE_SCALE, tmp->height * LIBSUPERDERPY_IMAGE_SCALE);
|
||||
}
|
||||
tmp->frames[i].bitmap = al_create_sub_bitmap(tmp->frames[i].source, tmp->frames[i].sx, tmp->frames[i].sy, (tmp->frames[i].sw > 0) ? tmp->frames[i].sw : al_get_bitmap_width(tmp->frames[i].source), (tmp->frames[i].sh > 0) ? tmp->frames[i].sh : al_get_bitmap_height(tmp->frames[i].source));
|
||||
tmp->frames[i].bitmap = al_create_sub_bitmap(tmp->frames[i].source, tmp->frames[i].sx * LIBSUPERDERPY_IMAGE_SCALE, tmp->frames[i].sy * LIBSUPERDERPY_IMAGE_SCALE, (tmp->frames[i].sw > 0) ? (tmp->frames[i].sw * LIBSUPERDERPY_IMAGE_SCALE) : al_get_bitmap_width(tmp->frames[i].source), (tmp->frames[i].sh > 0) ? (tmp->frames[i].sh * LIBSUPERDERPY_IMAGE_SCALE) : al_get_bitmap_height(tmp->frames[i].source));
|
||||
|
||||
int width = al_get_bitmap_width(tmp->frames[i].bitmap) + tmp->frames[i].x;
|
||||
int width = al_get_bitmap_width(tmp->frames[i].bitmap) / LIBSUPERDERPY_IMAGE_SCALE + tmp->frames[i].x;
|
||||
if (width > tmp->width) {
|
||||
tmp->width = width;
|
||||
}
|
||||
int height = al_get_bitmap_height(tmp->frames[i].bitmap) + tmp->frames[i].y;
|
||||
int height = al_get_bitmap_height(tmp->frames[i].bitmap) / LIBSUPERDERPY_IMAGE_SCALE + tmp->frames[i].y;
|
||||
if (height > tmp->height) {
|
||||
tmp->height = height;
|
||||
}
|
||||
|
@ -528,6 +528,7 @@ SYMBOL_EXPORT ALLEGRO_TRANSFORM GetCharacterTransform(struct Game* game, struct
|
|||
al_compose_transform(&transform, &parent);
|
||||
// FIXME: position should be calculated in relation to parents pivot point
|
||||
}
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
|
@ -561,9 +562,14 @@ SYMBOL_EXPORT void DrawCharacter(struct Game* game, struct Character* character)
|
|||
al_compose_transform(&transform, ¤t);
|
||||
al_use_transform(&transform);
|
||||
|
||||
al_draw_tinted_bitmap(character->frame->bitmap, GetCharacterTint(game, character), character->spritesheet->frames[character->pos].x, character->spritesheet->frames[character->pos].y, 0);
|
||||
al_draw_tinted_scaled_bitmap(character->frame->bitmap, GetCharacterTint(game, character),
|
||||
0, 0,
|
||||
al_get_bitmap_width(character->frame->bitmap), al_get_bitmap_height(character->frame->bitmap),
|
||||
character->spritesheet->frames[character->pos].x, character->spritesheet->frames[character->pos].y,
|
||||
al_get_bitmap_width(character->frame->bitmap) / LIBSUPERDERPY_IMAGE_SCALE, al_get_bitmap_height(character->frame->bitmap) / LIBSUPERDERPY_IMAGE_SCALE,
|
||||
0);
|
||||
|
||||
/* al_hold_bitmap_drawing(false);
|
||||
/*al_hold_bitmap_drawing(false);
|
||||
al_draw_filled_rectangle(character->spritesheet->width * character->spritesheet->pivotX - 5,
|
||||
character->spritesheet->height * character->spritesheet->pivotY - 5,
|
||||
character->spritesheet->width * character->spritesheet->pivotX + 5,
|
||||
|
@ -645,10 +651,10 @@ SYMBOL_EXPORT bool IsOnCharacter(struct Game* game, struct Character* character,
|
|||
al_invert_transform(&transform);
|
||||
al_transform_coordinates(&transform, &x, &y);
|
||||
int xpos = (int)x - character->spritesheet->frames[character->pos].x, ypos = (int)y - character->spritesheet->frames[character->pos].y;
|
||||
if (xpos < 0 || ypos < 0 || xpos >= al_get_bitmap_width(character->frame->bitmap) || ypos >= al_get_bitmap_height(character->frame->bitmap)) {
|
||||
if (xpos < 0 || ypos < 0 || xpos >= al_get_bitmap_width(character->frame->bitmap) / LIBSUPERDERPY_IMAGE_SCALE || ypos >= al_get_bitmap_height(character->frame->bitmap) / LIBSUPERDERPY_IMAGE_SCALE) {
|
||||
return false;
|
||||
}
|
||||
ALLEGRO_COLOR color = al_get_pixel(character->frame->bitmap, xpos, ypos);
|
||||
ALLEGRO_COLOR color = al_get_pixel(character->frame->bitmap, xpos * LIBSUPERDERPY_IMAGE_SCALE, ypos * LIBSUPERDERPY_IMAGE_SCALE);
|
||||
return (color.a > 0.0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue