mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 14:21:33 +03:00
Start defining an enlarged view for certain characters
This commit is contained in:
parent
e48c9cc632
commit
7cdb35a4ae
35
paint.py
35
paint.py
@ -774,6 +774,8 @@ class Canvas(Widget):
|
|||||||
bg = self.image.bg[y // self.magnification][x // self.magnification]
|
bg = self.image.bg[y // self.magnification][x // self.magnification]
|
||||||
fg = self.image.fg[y // self.magnification][x // self.magnification]
|
fg = self.image.fg[y // self.magnification][x // self.magnification]
|
||||||
ch = self.image.ch[y // self.magnification][x // self.magnification]
|
ch = self.image.ch[y // self.magnification][x // self.magnification]
|
||||||
|
if self.magnification > 1:
|
||||||
|
ch = self.big_ch(ch, x % self.magnification, y % self.magnification)
|
||||||
style = Style.parse(fg+" on "+bg)
|
style = Style.parse(fg+" on "+bg)
|
||||||
if self.magnifier_preview_region and self.magnifier_preview_region.contains(x, y) and not inner_magnifier_preview_region.contains(x, y):
|
if self.magnifier_preview_region and self.magnifier_preview_region.contains(x, y) and not inner_magnifier_preview_region.contains(x, y):
|
||||||
# invert the colors
|
# invert the colors
|
||||||
@ -794,6 +796,39 @@ class Canvas(Widget):
|
|||||||
(region.height + 2) * self.magnification,
|
(region.height + 2) * self.magnification,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def big_ch(self, ch: str, x: int, y: int) -> str:
|
||||||
|
"""Return a character part of a meta-glyph."""
|
||||||
|
if ch == " ":
|
||||||
|
return " "
|
||||||
|
if ch == "█":
|
||||||
|
return "█"
|
||||||
|
if ch == "▄":
|
||||||
|
if y < self.magnification // 2:
|
||||||
|
return " "
|
||||||
|
else:
|
||||||
|
return "█"
|
||||||
|
if ch == "▀":
|
||||||
|
if y < self.magnification // 2:
|
||||||
|
return "█"
|
||||||
|
else:
|
||||||
|
return " "
|
||||||
|
if ch == "▌":
|
||||||
|
if x < self.magnification // 2:
|
||||||
|
return "█"
|
||||||
|
else:
|
||||||
|
return " "
|
||||||
|
if ch == "▐":
|
||||||
|
if x < self.magnification // 2:
|
||||||
|
return " "
|
||||||
|
else:
|
||||||
|
return "█"
|
||||||
|
# Fall back to showing the character for a single cell.
|
||||||
|
# if x == 0 and y == 0:
|
||||||
|
if x == self.magnification // 2 and y == self.magnification // 2:
|
||||||
|
return ch
|
||||||
|
else:
|
||||||
|
return " "
|
||||||
|
|
||||||
|
|
||||||
class PaintApp(App):
|
class PaintApp(App):
|
||||||
"""MS Paint like image editor in the terminal."""
|
"""MS Paint like image editor in the terminal."""
|
||||||
|
Loading…
Reference in New Issue
Block a user