mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Windows: IonSimulatorLoadImage can now load any resource. Enable
to use key layouts jpg files in C/C++ code.
This commit is contained in:
committed by
EmilieNumworks
parent
22250b4234
commit
af544a95d1
@@ -17,3 +17,17 @@ ion_src += ion/src/shared/telemetry_console.cpp
|
||||
endif
|
||||
|
||||
LDFLAGS += -lgdiplus
|
||||
|
||||
# The header is refered to as <ion/src/simulator/windows/resources.h> so make sure it's findable this way
|
||||
SFLAGS += -I$(BUILD_DIR)
|
||||
|
||||
$(eval $(call rule_for, \
|
||||
WINDOWS_RESOURCES, \
|
||||
ion/src/simulator/windows/resources.h, \
|
||||
ion/src/simulator/windows/resources.rc, \
|
||||
$$(PYTHON) ion/src/simulator/windows/resources.py --resource $$^ --header $$@, \
|
||||
global \
|
||||
))
|
||||
|
||||
$(BUILD_DIR)/ion/src/simulator/windows/images.o: $(BUILD_DIR)/ion/src/simulator/windows/resources.h
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../shared/platform.h"
|
||||
#include <ion/src/simulator/windows/resources.h>
|
||||
|
||||
#include <SDL.h>
|
||||
#include <windows.h>
|
||||
@@ -40,7 +41,14 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
|
||||
|
||||
LPSTREAM stream;
|
||||
const char * resname = MAKEINTRESOURCE(300);
|
||||
int resourceID = -1;
|
||||
for (size_t i = 0; i < sizeof(resourcesIdentifiers)/sizeof(resourcesIdentifiers[0]); i++) {
|
||||
if (strcmp(identifier, resourcesIdentifiers[i].identifier) == 0) {
|
||||
resourceID = resourcesIdentifiers[i].id;
|
||||
}
|
||||
}
|
||||
assert(resourceID >= 0);
|
||||
const char * resname = MAKEINTRESOURCE(resourceID);
|
||||
CreateStreamOnResource(resname, &stream);
|
||||
|
||||
Gdiplus::Bitmap * image = Gdiplus::Bitmap::FromStream(stream);
|
||||
|
||||
41
ion/src/simulator/windows/resources.py
Normal file
41
ion/src/simulator/windows/resources.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# This script generates a .h file representing available resources to access
|
||||
# them from C code
|
||||
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
import io
|
||||
|
||||
parser = argparse.ArgumentParser(description="Process some jpg files.")
|
||||
parser.add_argument('--resource', help='the resources.rc file')
|
||||
parser.add_argument('--header', help='the .h file to generate')
|
||||
args = parser.parse_args()
|
||||
|
||||
def process_line(f, line):
|
||||
rc_re = re.compile('^(\d{1,4}) RCDATA "\.\./assets/(.*)"')
|
||||
rc_match = rc_re.match(line)
|
||||
if rc_match:
|
||||
f.write('{"' + rc_match.groups()[1] + '", ' + rc_match.groups()[0] + '},\n')
|
||||
return True
|
||||
return False
|
||||
|
||||
def process_resource(resource, path):
|
||||
rc = open(resource, "r")
|
||||
f = open(path, "w")
|
||||
|
||||
f.write("#ifndef ION_SIMULATOR_WINDOWS_RESOURCES_H\n")
|
||||
f.write("#define ION_SIMULATOR_WINDOWS_RESOURCES_H\n\n")
|
||||
f.write("// This file is auto-generated by resources.py\n\n")
|
||||
f.write("constexpr struct {const char * identifier; int id; } resourcesIdentifiers[] = {\n")
|
||||
|
||||
while (process_line(f, rc.readline())):
|
||||
pass
|
||||
|
||||
f.write("};\n\n")
|
||||
f.write("#endif\n")
|
||||
rc.close()
|
||||
f.close()
|
||||
|
||||
process_resource(args.resource, args.header)
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
300 RCDATA "../assets/background.jpg"
|
||||
301 RCDATA "../assets/horizontal_arrow.jpg"
|
||||
302 RCDATA "../assets/large_squircle.jpg"
|
||||
303 RCDATA "../assets/round.jpg"
|
||||
304 RCDATA "../assets/small_squircle.jpg"
|
||||
305 RCDATA "../assets/vertical_arrow.jpg"
|
||||
|
||||
1 VERSIONINFO
|
||||
FILEVERSION 1,0,0,0
|
||||
|
||||
Reference in New Issue
Block a user