Implement erasing

This commit is contained in:
mrkubax10 2024-03-05 18:14:54 +01:00
parent 87a59a5207
commit 0b17893b45

View File

@ -21,10 +21,12 @@ class EditorCanvas(tkinter.Canvas):
self.view_y=0
self.bind("<B1-Motion>",self.handle_draw)
self.bind("<Button-1>",self.handle_draw)
self.bind("<Button-3>",self.handle_move_start)
self.bind("<B3-Motion>",self.handle_move)
self.bind("<Button-2>",self.handle_move_start)
self.bind("<B2-Motion>",self.handle_move)
self.bind("<Button-3>",self.handle_erase)
self.bind("<B3-Motion>",self.handle_erase)
if platform.system()=="Windows" or platform.system()=="Darwin":
self.bind("<MouseWheel>",lambda event: self.handle_zoom(event.delta))
self.bind("<MouseWheel>",lambda event: self.handle_zoom(event.delta/120))
else:
# This will probably work only on X11
self.bind("<Button-4>",lambda _: self.handle_zoom(1))
@ -76,6 +78,16 @@ class EditorCanvas(tkinter.Canvas):
self.draw()
def handle_erase(self,event):
pixel_pos=self.cursor_pos_to_pixel((event.x,event.y))
if not pixel_pos:
return
self.current_char_modified=True
self.project.modified=True
self.current_char_pixels[pixel_pos[0]*self.project.char_res[1]+pixel_pos[1]]=0
self.draw()
def handle_zoom(self,delta):
self.grid_size+=delta
self.width=self.project.char_res[0]*self.grid_size