From 0a3be7ef556a037c5eee840182c4b89a2218c2a1 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Sat, 2 Mar 2024 13:04:24 +0100 Subject: [PATCH] Character loading without numpy usage --- canvas.py | 33 ++++++++++++++++++++++++++++----- main.py | 1 - 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/canvas.py b/canvas.py index a681ade..f1380e5 100644 --- a/canvas.py +++ b/canvas.py @@ -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("",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): diff --git a/main.py b/main.py index 5527148..184476d 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,6 @@ import os import numpy as np import cli_ui import unicodedata -import base64 from exporter import export from canvas import *