mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 06:11:37 +03:00
Make text tool use selected colors
This is a little weird because the selected background color is analogous to the foreground color in MS Paint, for the other tools, with the foreground color having no equivalent as it's just pixels instead of character cells. So with the default white canvas and black "background color", this now draws a black text box, unlike MS Paint's default behavior for the text tool of drawing a white text box.
This commit is contained in:
parent
fdca36daa1
commit
f8cfcb0f6e
18
paint.py
18
paint.py
@ -1230,10 +1230,24 @@ class PaintApp(App[None]):
|
|||||||
"""Called when selected_bg_color changes."""
|
"""Called when selected_bg_color changes."""
|
||||||
self.query_one("#selected_color_char_input", CharInput).styles.background = selected_bg_color
|
self.query_one("#selected_color_char_input", CharInput).styles.background = selected_bg_color
|
||||||
|
|
||||||
|
if self.image.selection and self.image.selection.textbox_mode:
|
||||||
|
assert self.image.selection.contained_image is not None, "textbox_mode without contained_image"
|
||||||
|
for y in range(self.image.selection.region.height):
|
||||||
|
for x in range(self.image.selection.region.width):
|
||||||
|
self.image.selection.contained_image.bg[y][x] = self.selected_bg_color
|
||||||
|
self.canvas.refresh_scaled_region(self.image.selection.region)
|
||||||
|
|
||||||
def watch_selected_fg_color(self, selected_fg_color: str) -> None:
|
def watch_selected_fg_color(self, selected_fg_color: str) -> None:
|
||||||
"""Called when selected_fg_color changes."""
|
"""Called when selected_fg_color changes."""
|
||||||
self.query_one("#selected_color_char_input", CharInput).styles.color = selected_fg_color
|
self.query_one("#selected_color_char_input", CharInput).styles.color = selected_fg_color
|
||||||
|
|
||||||
|
if self.image.selection and self.image.selection.textbox_mode:
|
||||||
|
assert self.image.selection.contained_image is not None, "textbox_mode without contained_image"
|
||||||
|
for y in range(self.image.selection.region.height):
|
||||||
|
for x in range(self.image.selection.region.width):
|
||||||
|
self.image.selection.contained_image.fg[y][x] = self.selected_fg_color
|
||||||
|
self.canvas.refresh_scaled_region(self.image.selection.region)
|
||||||
|
|
||||||
def watch_selected_char(self, selected_char: str) -> None:
|
def watch_selected_char(self, selected_char: str) -> None:
|
||||||
"""Called when selected_char changes."""
|
"""Called when selected_char changes."""
|
||||||
self.query_one("#selected_color_char_input", CharInput).value = selected_char
|
self.query_one("#selected_color_char_input", CharInput).value = selected_char
|
||||||
@ -2386,6 +2400,10 @@ class PaintApp(App[None]):
|
|||||||
self.image.selection.textbox_mode = self.selected_tool == Tool.text
|
self.image.selection.textbox_mode = self.selected_tool == Tool.text
|
||||||
if self.image.selection.textbox_mode:
|
if self.image.selection.textbox_mode:
|
||||||
self.image.selection.contained_image = AnsiArtDocument(self.image.selection.region.width, self.image.selection.region.height)
|
self.image.selection.contained_image = AnsiArtDocument(self.image.selection.region.width, self.image.selection.region.height)
|
||||||
|
for y in range(self.image.selection.region.height):
|
||||||
|
for x in range(self.image.selection.region.width):
|
||||||
|
self.image.selection.contained_image.fg[y][x] = self.selected_fg_color
|
||||||
|
self.image.selection.contained_image.bg[y][x] = self.selected_bg_color
|
||||||
if self.selected_tool == Tool.free_form_select:
|
if self.selected_tool == Tool.free_form_select:
|
||||||
# Define the mask for the selection using the polygon
|
# Define the mask for the selection using the polygon
|
||||||
self.image.selection.mask = [[is_inside_polygon(x + select_region.x, y + select_region.y, self.tool_points) for x in range(select_region.width)] for y in range(select_region.height)]
|
self.image.selection.mask = [[is_inside_polygon(x + select_region.x, y + select_region.y, self.tool_points) for x in range(select_region.width)] for y in range(select_region.height)]
|
||||||
|
Loading…
Reference in New Issue
Block a user