mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 04:21: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/isleapp.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)
|
||||
if (WIN32)
|
||||
@ -530,13 +533,28 @@ if (ISLE_BUILD_APP)
|
||||
)
|
||||
endif()
|
||||
if(Python3_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${Python3_EXECUTABLE} tools/png2h.py ISLE/res/arrow.png ISLE/res/busy.png ISLE/res/no.png
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE PNG2H_RESULT
|
||||
OUTPUT_QUIET
|
||||
ERROR_QUIET
|
||||
)
|
||||
if(NOT DEFINED PYTHON_PIL_AVAILABLE)
|
||||
execute_process(
|
||||
COMMAND ${Python3_EXECUTABLE} -c "import PIL"
|
||||
RESULT_VARIABLE PIL_RESULT
|
||||
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()
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import argparse
|
||||
from PIL import Image
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def encode_cursor(image_path):
|
||||
def encode_cursor(image_path: Path):
|
||||
img = Image.open(image_path).convert("RGBA")
|
||||
width, height = img.size
|
||||
pixels = img.load()
|
||||
@ -47,20 +47,19 @@ def to_c_array(name, data):
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 1:
|
||||
print(f"Usage: {sys.argv[0]} [...input.png]")
|
||||
sys.exit(1)
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False)
|
||||
parser.add_argument("inputs", nargs="+", help="PNG images", type=Path)
|
||||
args = parser.parse_args()
|
||||
|
||||
input_files = sys.argv[1:]
|
||||
input_files: list[Path] = args.inputs
|
||||
|
||||
for input_file in input_files:
|
||||
data, mask, width, height = encode_cursor(input_file)
|
||||
|
||||
input_file_path = Path(input_file)
|
||||
input_file_name = input_file_path.stem
|
||||
output_file = input_file_path.with_name(f"{input_file_name}_bmp.h")
|
||||
input_file_name = input_file.stem
|
||||
output_file = input_file.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"// Dimensions: {width}x{height}\n\n")
|
||||
f.write(f"#pragma once\n")
|
||||
@ -77,4 +76,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
raise SystemExit(main())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user