Character loading without numpy usage

This commit is contained in:
mrkubax10 2024-03-02 13:04:24 +01:00
parent b215b8ad39
commit 0a3be7ef55
2 changed files with 28 additions and 6 deletions

View File

@ -1,3 +1,4 @@
import base64
import tkinter
GRID_COLOR = "#808080"
@ -10,6 +11,7 @@ class EditorCanvas(tkinter.Canvas):
self.grid_size = 32
self.current_char=33
self.current_char_pixels=[]
self.current_char_modified=False
self.width=0
self.height=0
self.bind("<B1-Motion>",self.handle_draw)
@ -27,10 +29,10 @@ class EditorCanvas(tkinter.Canvas):
y = y * self.grid_size
self.create_line((0,y),(self.width,y),width=1,fill=GRID_COLOR)
if self.project.does_char_exist(self.current_char):
if self.project.does_char_exist(self.current_char) or self.current_char_modified:
for i in range(len(self.current_char_pixels)):
x=i%self.project.char_res[0]*self.grid_size
y=i//self.project.char_res[0]*self.grid_size
x=i//self.project.char_res[1]*self.grid_size
y=i%self.project.char_res[1]*self.grid_size
if self.current_char_pixels[i]>0:
self.create_rectangle((x,y),(x+self.grid_size,y+self.grid_size),fill="white")
else:
@ -39,13 +41,34 @@ class EditorCanvas(tkinter.Canvas):
def handle_draw(self,event):
self.current_char_modified=True
pixel_pos=self.cursor_pos_to_pixel((event.x,event.y))
self.current_char_pixels[pixel_pos[1]*self.project.char_res[0]+pixel_pos[0]]=1
self.current_char_pixels[pixel_pos[0]*self.project.char_res[1]+pixel_pos[1]]=1
self.draw()
def load_char(self):
self.current_char_modified=False
if not self.project.does_char_exist(self.current_char):
for x in range(len(self.current_char_pixels)):
self.current_char_pixels[x]=0
return
base64_data=self.project.chars[chr(self.current_char)]
pixels=base64.b64decode(base64_data.encode("ascii"))
pixel_index=0
for pixel in pixels:
if pixel_index>=len(self.current_char_pixels):
break
for x in range(8):
if pixel_index>=len(self.current_char_pixels):
break
self.current_char_pixels[pixel_index]=(pixel>>(7-x))&1
pixel_index+=1
self.draw()
def save_char(self):
pass
def prev_glyph(self):

View File

@ -2,7 +2,6 @@ import os
import numpy as np
import cli_ui
import unicodedata
import base64
from exporter import export
from canvas import *