Move zooming to View menu in menubar and use mouse scroll for changing glyphs
This commit is contained in:
parent
8413f98f4c
commit
d2d28b0782
15
canvas.py
15
canvas.py
@ -1,5 +1,4 @@
|
||||
import base64
|
||||
import platform
|
||||
import tkinter
|
||||
|
||||
GRID_COLOR = "#808080"
|
||||
@ -25,12 +24,6 @@ class EditorCanvas(tkinter.Canvas):
|
||||
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//120))
|
||||
else:
|
||||
# This will probably work only on X11
|
||||
self.bind("<Button-4>",lambda _: self.handle_zoom(1))
|
||||
self.bind("<Button-5>",lambda _: self.handle_zoom(-1))
|
||||
|
||||
|
||||
def draw(self):
|
||||
@ -88,8 +81,12 @@ class EditorCanvas(tkinter.Canvas):
|
||||
self.draw()
|
||||
|
||||
|
||||
def handle_zoom(self,delta):
|
||||
self.grid_size+=delta
|
||||
def zoom_by(self,amount):
|
||||
self.grid_size+=amount
|
||||
if self.grid_size<12:
|
||||
self.grid_size=12
|
||||
elif self.grid_size>102:
|
||||
self.grid_size=102
|
||||
self.width=self.project.char_res[0]*self.grid_size
|
||||
self.height=self.project.char_res[1]*self.grid_size
|
||||
self.draw()
|
||||
|
23
main.py
23
main.py
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import platform
|
||||
import tkinter.filedialog
|
||||
import unicodedata
|
||||
|
||||
@ -211,6 +212,18 @@ def update_glyph_preview():
|
||||
label_glyph_name.config(text=f"{name} U+{canvas_editor.current_char:04x}")
|
||||
|
||||
|
||||
def canvas_editor_handle_scroll(delta):
|
||||
global canvas_editor
|
||||
global project
|
||||
if not project.loaded:
|
||||
return
|
||||
if delta>0:
|
||||
canvas_editor.prev_glyph()
|
||||
else:
|
||||
canvas_editor.next_glyph()
|
||||
update_glyph_preview()
|
||||
|
||||
|
||||
window=tkinter.Tk()
|
||||
window.title("fonteditor")
|
||||
window.geometry(f"{WINDOW_SIZE[0]}x{WINDOW_SIZE[1]}")
|
||||
@ -225,11 +238,21 @@ menu_file.add_command(label="Save project as",command=lambda: save_project(True)
|
||||
menu_export=tkinter.Menu(menubar,tearoff=False)
|
||||
menu_export.add_command(label="Export",command=lambda: export_project(False))
|
||||
menu_export.add_command(label="Export as",command=lambda: export_project(True))
|
||||
menu_view=tkinter.Menu(menubar,tearoff=False)
|
||||
menu_view.add_command(label="Zoom in",command=lambda: canvas_editor.zoom_by(10))
|
||||
menu_view.add_command(label="Zoom out",command=lambda: canvas_editor.zoom_by(-10))
|
||||
menubar.add_cascade(label="File",menu=menu_file)
|
||||
menubar.add_cascade(label="Export",menu=menu_export)
|
||||
menubar.add_cascade(label="View",menu=menu_view)
|
||||
|
||||
canvas_editor=EditorCanvas(project,window,bg="black")
|
||||
canvas_editor.pack(side="left",fill="both",expand=True)
|
||||
if platform.system()=="Windows" or platform.system()=="Darwin":
|
||||
canvas_editor.bind("<MouseWheel>",lambda event: canvas_editor_handle_scroll(event.delta))
|
||||
else:
|
||||
# This will probably work only on X11
|
||||
canvas_editor.bind("<Button-4>",lambda _: canvas_editor_handle_scroll(1))
|
||||
canvas_editor.bind("<Button-5>",lambda _: canvas_editor_handle_scroll(-1))
|
||||
|
||||
frame_controls=tkinter.Frame(window)
|
||||
frame_controls.pack(side="right")
|
||||
|
Loading…
Reference in New Issue
Block a user