mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
🩹 fix: use add_custom_command in cmake, use argparse in png2h
This commit is contained in:
parent
31ea400f9b
commit
a88ceaa1e1
@ -473,6 +473,9 @@ if (ISLE_BUILD_APP)
|
|||||||
ISLE/res/isle.rc
|
ISLE/res/isle.rc
|
||||||
ISLE/isleapp.cpp
|
ISLE/isleapp.cpp
|
||||||
ISLE/islefiles.cpp
|
ISLE/islefiles.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/arrow_bmp.h
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/busy_bmp.h
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/no_bmp.h
|
||||||
)
|
)
|
||||||
list(APPEND isle_targets isle)
|
list(APPEND isle_targets isle)
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
@ -530,13 +533,28 @@ if (ISLE_BUILD_APP)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(Python3_FOUND)
|
if(Python3_FOUND)
|
||||||
|
if(NOT DEFINED PYTHON_PIL_AVAILABLE)
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${Python3_EXECUTABLE} tools/png2h.py ISLE/res/arrow.png ISLE/res/busy.png ISLE/res/no.png
|
COMMAND ${Python3_EXECUTABLE} -c "import PIL"
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
RESULT_VARIABLE PIL_RESULT
|
||||||
RESULT_VARIABLE PNG2H_RESULT
|
|
||||||
OUTPUT_QUIET
|
|
||||||
ERROR_QUIET
|
ERROR_QUIET
|
||||||
)
|
)
|
||||||
|
set(PYTHON_PIL_AVAILABLE ${PIL_RESULT} EQUAL 0 CACHE BOOL "Is Python PIL available?")
|
||||||
|
endif()
|
||||||
|
if(PYTHON_PIL_AVAILABLE)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/arrow_bmp.h
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/busy_bmp.h
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/no_bmp.h
|
||||||
|
COMMAND ${Python3_EXECUTABLE} tools/png2h.py ISLE/res/arrow.png ISLE/res/busy.png ISLE/res/no.png
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
DEPENDS
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/arrow.png
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/busy.png
|
||||||
|
${CMAKE_SOURCE_DIR}/ISLE/res/no.png
|
||||||
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
import argparse
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def encode_cursor(image_path):
|
def encode_cursor(image_path: Path):
|
||||||
img = Image.open(image_path).convert("RGBA")
|
img = Image.open(image_path).convert("RGBA")
|
||||||
width, height = img.size
|
width, height = img.size
|
||||||
pixels = img.load()
|
pixels = img.load()
|
||||||
@ -47,20 +47,19 @@ def to_c_array(name, data):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) == 1:
|
parser = argparse.ArgumentParser(allow_abbrev=False)
|
||||||
print(f"Usage: {sys.argv[0]} [...input.png]")
|
parser.add_argument("inputs", nargs="+", help="PNG images", type=Path)
|
||||||
sys.exit(1)
|
args = parser.parse_args()
|
||||||
|
|
||||||
input_files = sys.argv[1:]
|
input_files: list[Path] = args.inputs
|
||||||
|
|
||||||
for input_file in input_files:
|
for input_file in input_files:
|
||||||
data, mask, width, height = encode_cursor(input_file)
|
data, mask, width, height = encode_cursor(input_file)
|
||||||
|
|
||||||
input_file_path = Path(input_file)
|
input_file_name = input_file.stem
|
||||||
input_file_name = input_file_path.stem
|
output_file = input_file.with_name(f"{input_file_name}_bmp.h")
|
||||||
output_file = input_file_path.with_name(f"{input_file_name}_bmp.h")
|
|
||||||
|
|
||||||
with open(output_file, "w") as f:
|
with output_file.open("w") as f:
|
||||||
f.write(f"// Generated from {input_file}\n")
|
f.write(f"// Generated from {input_file}\n")
|
||||||
f.write(f"// Dimensions: {width}x{height}\n\n")
|
f.write(f"// Dimensions: {width}x{height}\n\n")
|
||||||
f.write(f"#pragma once\n")
|
f.write(f"#pragma once\n")
|
||||||
@ -77,4 +76,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
raise SystemExit(main())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user