[ion] Simulator: key layouts assets are PNG instead of JPG I (fix macos)

This commit is contained in:
Émilie Feral
2020-09-17 11:53:27 +02:00
committed by EmilieNumworks
parent 11236c67cb
commit d4b7b6baf0
14 changed files with 32 additions and 29 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -3,7 +3,7 @@
#include <SDL.h>
#include <AppKit/AppKit.h>
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha) {
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) {
NSImage * nsImage = [NSImage imageNamed:[NSString stringWithUTF8String:identifier]];
CGImageRef cgImage = [nsImage CGImageForProposedRect:NULL
context:NULL
@@ -15,11 +15,12 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
size_t height = CGImageGetHeight(cgImage);
size_t bytesPerPixel = 4;
size_t bitsPerPixel = bytesPerPixel*8;
size_t bytesPerRow = bytesPerPixel * width;
size_t bitsPerComponent = 8;
void * bitmapData = malloc(height * width * bytesPerPixel);
size_t size = height * width * bytesPerPixel;
void * bitmapData = malloc(size);
memset(bitmapData, 0, size);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(
@@ -33,21 +34,24 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
SDL_Surface * surface = SDL_CreateRGBSurfaceWithFormatFrom(
bitmapData,
width,
height,
bitsPerPixel,
bytesPerRow,
SDL_PIXELFORMAT_ABGR8888);
SDL_Texture * texture = SDL_CreateTexture(
renderer,
SDL_PIXELFORMAT_ABGR8888,
SDL_TEXTUREACCESS_STATIC,
width,
height
);
SDL_SetColorKey(surface, withTransparency, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
SDL_SetSurfaceAlphaMod(surface, alpha);
SDL_UpdateTexture(
texture,
NULL,
bitmapData,
bytesPerPixel * width
);
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
free(bitmapData);
SDL_FreeSurface(surface);
return texture;
}

View File

@@ -16,15 +16,15 @@ $(simulator_app_binary): $(foreach arch,$(ARCHS),$(BUILD_DIR)/$(arch)/%.bin) | $
# Background & Keys images
define rule_for_jpg_asset
simulator_app_deps += $(call simulator_app_resource,$(1).jpg)
$(call simulator_app_resource,$(1).jpg): ion/src/simulator/assets/$(1).jpg | $$$$(@D)/.
define rule_for_asset
simulator_app_deps += $(call simulator_app_resource,$(1))
$(call simulator_app_resource,$(1)): ion/src/simulator/assets/$(1) | $$$$(@D)/.
$(call rule_label,COPY)
$(Q) cp $$^ $$@
endef
JPG_ASSETS = background horizontal_arrow large_squircle round small_squircle vertical_arrow
$(foreach ASSET,$(JPG_ASSETS),$(eval $(call rule_for_jpg_asset,$(ASSET))))
ASSETS = background.jpg horizontal_arrow.png large_squircle.png round.png small_squircle.png vertical_arrow.png
$(foreach ASSET,$(ASSETS),$(eval $(call rule_for_asset,$(ASSET))))
# Process icons
@@ -45,4 +45,4 @@ $(addprefix $(SIMULATOR_ICONSET)/,icon_%.png): ion/src/simulator/assets/logo.svg
# Export simulator app dependencies
simulator_app_deps += $(simulator_app_binary)
simulator_app_deps += $(call simulator_app_plist,Info.plist)
simulator_app_deps += $(call simulator_app_plist,Info.plist)

View File

@@ -103,11 +103,11 @@ public:
};
static constexpr size_t NumberOfShapes = (size_t)Shape::NumberOfShapes;
static constexpr const char * imagePathForKey[KeyLayout::NumberOfShapes] = {
"horizontal_arrow.jpg",
"vertical_arrow.jpg",
"round.jpg",
"small_squircle.jpg",
"large_squircle.jpg"
"horizontal_arrow.png",
"vertical_arrow.png",
"round.png",
"small_squircle.png",
"large_squircle.png"
};
constexpr KeyLayout(float x, float y, Shape shape) :
@@ -198,14 +198,13 @@ static void getKeyRectangle(int validKeyIndex, SDL_Texture * texture, SDL_Rect *
makeAbsolute(fRect, rect);
}
static constexpr uint8_t k_blendingRatio = 0x44;
static SDL_Texture * sBackgroundTexture = nullptr;
static SDL_Texture * sKeyLayoutTextures[KeyLayout::NumberOfShapes];
void init(SDL_Renderer * renderer) {
sBackgroundTexture = IonSimulatorLoadImage(renderer, "background.jpg", false, 0xFF);
sBackgroundTexture = IonSimulatorLoadImage(renderer, "background.jpg");
for (size_t i = 0; i < KeyLayout::NumberOfShapes; i++) {
sKeyLayoutTextures[i] = IonSimulatorLoadImage(renderer, KeyLayout::imagePathForKey[i], true, k_blendingRatio);
sKeyLayoutTextures[i] = IonSimulatorLoadImage(renderer, KeyLayout::imagePathForKey[i]);
}
}

View File

@@ -11,7 +11,7 @@ extern "C" {
/* Those functions should be implemented per-platform.
* They are defined as C function for easier interop. */
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha);
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier);
char * IonSimulatorGetLanguageCode();
#if EPSILON_SDL_SCREEN_ONLY