Skip to content

Commit

Permalink
Allow applying a transform (rotate/flip) to UI images
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Oct 23, 2024
1 parent d094fb6 commit 939ac31
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/app/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@
type DefaultExt = Literal['png', 'vtf']


TRANSPOSES: dict[str, Image.Transpose | None] = {
'': None,
'none': None,
'90': ROTATE_CW,
'180': FLIP_ROTATE,
'270': ROTATE_CCW,
'cw': ROTATE_CW,
'ccw': ROTATE_CCW,
'flip_vert': FLIP_TOP_BOTTOM,
'flip_horiz': FLIP_LEFT_RIGHT,
}


def _load_special(path: str, theme: Theme) -> Image.Image:
"""Various special images we have to load."""
img: Image.Image
Expand Down Expand Up @@ -345,9 +358,26 @@ def parse(
width, height,
subfolder=subfolder,
))
elif child.name == 'transform':
try:
orient = TRANSPOSES[child['orient'].casefold()]
except KeyError:
raise ValueError(f'Invalid transform type "{child['orient']}"') from None
orig = cls.parse(
child,
pack, width, height, subkey='child',
subfolder=subfolder,
)
children.append(orig.transform(transpose=orient))
else:
raise ValueError(f'Unknown compound type "{child.real_name}"!')
return cls.composite(children, width, height)
match children:
case []:
return cls.blank(width, height)
case [single]:
return single
case _:
return cls.composite(children, width, height)

return cls.parse_uri(utils.PackagePath.parse(kv.value, pack), width, height, subfolder=subfolder)

Expand Down

0 comments on commit 939ac31

Please sign in to comment.