diff --git a/ion/src/simulator/windows/Makefile b/ion/src/simulator/windows/Makefile index 0a1913c6f..00cc6c9f9 100644 --- a/ion/src/simulator/windows/Makefile +++ b/ion/src/simulator/windows/Makefile @@ -17,3 +17,17 @@ ion_src += ion/src/shared/telemetry_console.cpp endif LDFLAGS += -lgdiplus + +# The header is refered to as 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 + diff --git a/ion/src/simulator/windows/images.cpp b/ion/src/simulator/windows/images.cpp index 60a6c7cdb..3536c2edc 100644 --- a/ion/src/simulator/windows/images.cpp +++ b/ion/src/simulator/windows/images.cpp @@ -1,4 +1,5 @@ #include "../shared/platform.h" +#include #include #include @@ -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); diff --git a/ion/src/simulator/windows/resources.py b/ion/src/simulator/windows/resources.py new file mode 100644 index 000000000..47298ed20 --- /dev/null +++ b/ion/src/simulator/windows/resources.py @@ -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) + + diff --git a/ion/src/simulator/windows/resources.rc b/ion/src/simulator/windows/resources.rc index 024eb2d13..0dd6b9368 100644 --- a/ion/src/simulator/windows/resources.rc +++ b/ion/src/simulator/windows/resources.rc @@ -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