added glyph text copy button, single button draw, configurable guide lines, initial dark theme
This commit is contained in:
56
canvas.py
56
canvas.py
@@ -1,14 +1,15 @@
|
||||
import base64
|
||||
import tkinter
|
||||
import clipboard
|
||||
|
||||
GRID_COLOR = "#808080"
|
||||
GRID_GUIDE_COLOR = (128, 128, 255)
|
||||
GRID_GUIDE_COLOR = "#51bbfe"
|
||||
|
||||
class EditorCanvas(tkinter.Canvas):
|
||||
def __init__(self,project,*args,**kwargs):
|
||||
super().__init__(*args,**kwargs)
|
||||
self.project=project
|
||||
self.grid_size = 32
|
||||
self.grid_size = 64
|
||||
self.current_char=33
|
||||
self.current_char_pixels=[]
|
||||
self.current_char_modified=False
|
||||
@@ -18,24 +19,32 @@ class EditorCanvas(tkinter.Canvas):
|
||||
self.prev_mouse_y=0
|
||||
self.view_x=0
|
||||
self.view_y=0
|
||||
self.draw_color = 0
|
||||
self.guide_pos = ()
|
||||
|
||||
self.bind("<Button-1>",self.handle_draw_start)
|
||||
self.bind("<B1-Motion>",self.handle_draw)
|
||||
self.bind("<Button-1>",self.handle_draw)
|
||||
|
||||
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)
|
||||
|
||||
def set_guide_pos(self, pos):
|
||||
self.guide_pos = pos
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
self.delete("all")
|
||||
|
||||
# draw grid
|
||||
for x in range(self.project.char_res[0] + 1):
|
||||
x = x * self.grid_size+self.view_x
|
||||
x = x * self.grid_size + self.view_x
|
||||
self.create_line((x,self.view_y),(x,self.view_y+self.height),width=1,fill=GRID_COLOR)
|
||||
|
||||
for y in range(self.project.char_res[1] + 1):
|
||||
y = y * self.grid_size+self.view_y
|
||||
self.create_line((self.view_x,y),(self.view_x+self.width,y),width=1,fill=GRID_COLOR)
|
||||
temp_color = GRID_GUIDE_COLOR if y in self.guide_pos else GRID_COLOR
|
||||
|
||||
y = y * self.grid_size + self.view_y
|
||||
self.create_line((self.view_x,y),(self.view_x+self.width,y),width=1,fill=temp_color)
|
||||
|
||||
if self.project.does_char_exist(self.current_char) or self.current_char_modified:
|
||||
for i in range(len(self.current_char_pixels)):
|
||||
@@ -48,13 +57,22 @@ class EditorCanvas(tkinter.Canvas):
|
||||
self.create_line((self.view_x+self.width,self.view_y),(self.view_x,self.view_y+self.height),width=3,fill="red")
|
||||
|
||||
|
||||
def handle_draw(self,event):
|
||||
pixel_pos=self.cursor_pos_to_pixel((event.x,event.y))
|
||||
def handle_draw_start(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]]=1
|
||||
self.draw_color = 1 - self.current_char_pixels[pixel_pos[0]*self.project.char_res[1]+pixel_pos[1]]
|
||||
|
||||
self.handle_draw(event)
|
||||
|
||||
|
||||
def handle_draw(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]] = self.draw_color
|
||||
self.draw()
|
||||
|
||||
|
||||
@@ -71,16 +89,6 @@ 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 zoom_by(self,amount):
|
||||
self.grid_size+=amount
|
||||
if self.grid_size<12:
|
||||
@@ -171,3 +179,5 @@ class EditorCanvas(tkinter.Canvas):
|
||||
self.current_char_pixels=[0 for _ in range(self.project.char_res[0]*self.project.char_res[1])]
|
||||
self.load_char()
|
||||
|
||||
def copy_char(self):
|
||||
clipboard.copy(chr(self.current_char))
|
||||
|
||||
Reference in New Issue
Block a user