mirror of
https://github.com/quantum5/win2xcur.git
synced 2025-04-24 10:11:57 -04:00
Merge 88918764b1
into 8e71037f5f
This commit is contained in:
commit
72e04f6d1b
|
@ -16,6 +16,10 @@ class CursorImage:
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f'CursorImage(image={self.image!r}, hotspot={self.hotspot!r}, nominal={self.nominal!r})'
|
return f'CursorImage(image={self.image!r}, hotspot={self.hotspot!r}, nominal={self.nominal!r})'
|
||||||
|
|
||||||
|
def scale(self, width: int, height: int) -> None:
|
||||||
|
self.image.scale(width, height)
|
||||||
|
self.nominal = max(width, height)
|
||||||
|
|
||||||
|
|
||||||
class CursorFrame:
|
class CursorFrame:
|
||||||
images: List[CursorImage]
|
images: List[CursorImage]
|
||||||
|
|
|
@ -7,7 +7,7 @@ from multiprocessing.pool import ThreadPool
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from typing import BinaryIO
|
from typing import BinaryIO
|
||||||
|
|
||||||
from win2xcur import scale, shadow
|
from win2xcur import scale, shadow, multiscale
|
||||||
from win2xcur.parser import open_blob
|
from win2xcur.parser import open_blob
|
||||||
from win2xcur.writer import to_x11
|
from win2xcur.writer import to_x11
|
||||||
|
|
||||||
|
@ -34,6 +34,10 @@ def main() -> None:
|
||||||
help='color of the shadow')
|
help='color of the shadow')
|
||||||
parser.add_argument('--scale', default=None, type=float,
|
parser.add_argument('--scale', default=None, type=float,
|
||||||
help='Scale the cursor by the specified factor.')
|
help='Scale the cursor by the specified factor.')
|
||||||
|
parser.add_argument('--multiscale', action='store_true',
|
||||||
|
help='Generate multiple sizes for each cursor.')
|
||||||
|
parser.add_argument('--multiscale-min', type=int, default=12,
|
||||||
|
help='Minimum size to generate.')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print_lock = Lock()
|
print_lock = Lock()
|
||||||
|
@ -48,7 +52,9 @@ def main() -> None:
|
||||||
print(f'Error occurred while processing {name}:', file=sys.stderr)
|
print(f'Error occurred while processing {name}:', file=sys.stderr)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
if args.scale:
|
if args.multiscale:
|
||||||
|
multiscale.generates_frames(cursor=cursor, min_size=args.multiscale_min)
|
||||||
|
elif args.scale:
|
||||||
scale.apply_to_frames(cursor.frames, scale=args.scale)
|
scale.apply_to_frames(cursor.frames, scale=args.scale)
|
||||||
if args.shadow:
|
if args.shadow:
|
||||||
shadow.apply_to_frames(cursor.frames, color=args.shadow_color, radius=args.shadow_radius,
|
shadow.apply_to_frames(cursor.frames, color=args.shadow_color, radius=args.shadow_radius,
|
||||||
|
|
32
win2xcur/multiscale.py
Normal file
32
win2xcur/multiscale.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
from win2xcur.cursor import CursorFrame, CursorImage
|
||||||
|
|
||||||
|
MULTSCALE = [16, 24, 32, 48, 64, 96, 128, 192, 256]
|
||||||
|
|
||||||
|
def generates_frames(cursor, min_size: int) -> None:
|
||||||
|
"""Generates multiple sizes for each cursor.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
cursor (Cursor): The cursor to generate sizes for.
|
||||||
|
min_size (int): The minimum size to generate.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[Cursor]: The generated cursors.
|
||||||
|
"""
|
||||||
|
frames = cursor.frames
|
||||||
|
new_frames = []
|
||||||
|
image_size = frames[0].images[0].nominal
|
||||||
|
for size in MULTSCALE:
|
||||||
|
if size > image_size:
|
||||||
|
continue
|
||||||
|
if size < min_size:
|
||||||
|
break
|
||||||
|
for frame in frames:
|
||||||
|
new_images = []
|
||||||
|
for cur in frame:
|
||||||
|
new_cur = CursorImage(cur.image.clone(), cur.hotspot, cur.nominal)
|
||||||
|
new_cur.scale(size, size)
|
||||||
|
new_images.append(new_cur)
|
||||||
|
new_frame = CursorFrame(new_images, frame.delay)
|
||||||
|
new_frames.append(new_frame)
|
||||||
|
del cursor.frames[:]
|
||||||
|
cursor.frames.extend(new_frames)
|
|
@ -6,7 +6,7 @@ from win2xcur.cursor import CursorFrame
|
||||||
def apply_to_frames(frames: List[CursorFrame], *, scale: float) -> None:
|
def apply_to_frames(frames: List[CursorFrame], *, scale: float) -> None:
|
||||||
for frame in frames:
|
for frame in frames:
|
||||||
for cursor in frame:
|
for cursor in frame:
|
||||||
cursor.image.scale(
|
cursor.scale(
|
||||||
int(round(cursor.image.width * scale)),
|
int(round(cursor.image.width * scale)),
|
||||||
int(round(cursor.image.height) * scale),
|
int(round(cursor.image.height) * scale),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue