diff --git a/BinEditor.py b/BinEditor.py deleted file mode 100644 index ebb0816..0000000 --- a/BinEditor.py +++ /dev/null @@ -1,102 +0,0 @@ -# BinEditor.py -# Binary editor for pixel art that supports undo & redo -# Might need to use that later on - -import pygame, sys - -width, height = 800, 600 -mx, my = 0, 0 - -def drawGrid(): - for i in range(n + 1): - pygame.draw.line(screen, (170, 170, 170), (50, 50 + 30 * i), (30 * (n + 1.7), 50 + 30 * i), 10) - for i in range(n + 1): - pygame.draw.line(screen, (170, 170, 170), (50 + 30 * i, 50), (50 + 30 * i, 30 * (n + 1.7)), 10) - -def checkBorders(): - try: - for i in range(len(squares)): - if pygame.Rect(squares[i][0], squares[i][1], 30, 30).collidepoint(mx, my): - flagList[i] = 1 - flagList[i] - undo.append(i) - except: - return - -def calc(): - numStr = "" - for i in range(n): - for j in range(n): - numStr += str(flagList[n * j + i]) - strList[i] = hex(int(numStr, 2))[2:] - numStr = "" - -def saveFile(): - fileName = input("File to save to: ") - f = open(fileName, "w") - for s in strList: - f.write(s + ' ') - f.close() - -n = 8 - -squares = [] -for i in range(55, 30 * (n + 1), 30): - for j in range(55, 30 * (n + 1), 30): - squares.append([i, j]) -strList = [""] * n - -print(squares) - -flagList = [0] * n * n -print(flagList) - -pygame.init() -screen = pygame.display.set_mode((width, height)) -pygame.display.set_caption("Binary Color Editor") -clock = pygame.time.Clock() -font = pygame.font.Font(None, 24) -undo = [] -redo = [] -over = False - -while True: - screen.fill((0, 0, 0)) - drawGrid() - checkBorders() - calc() - mx, my = 0, 0 - for i in range(len(flagList)): - if flagList[i]: - pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(squares[i][0] + 1, squares[i][1] + 1, 20, 20), 0) - for i in range(len(strList)): - img = font.render(strList[i], True, (0, 0, 255)) - screen.blit(img, (30 * (n + 1) + 45, 55 + 30.5 * i)) - pygame.display.update() - clock.tick(10) - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - sys.exit() - if event.type == pygame.MOUSEBUTTONDOWN: - if event.button == 1: - if over: - redo = [] - print(event.pos) - mx, my = event.pos - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_s: - saveFile() - elif event.key == pygame.K_z: - if len(undo) != 0: - lastOp = undo.pop() - redo.append(lastOp) - flagList[lastOp] = 1 - flagList[lastOp] - over = True - elif event.key == pygame.K_y: - if len(redo) != 0: - prevOp = redo.pop() - undo.append(prevOp) - flagList[prevOp] = 1 - flagList[prevOp] - over = True - elif event.key == pygame.K_0: - flagList = [0] * n * n \ No newline at end of file diff --git a/TODO b/TODO new file mode 100644 index 0000000..be949ec --- /dev/null +++ b/TODO @@ -0,0 +1,6 @@ +- Integrate TextDraw.py and the buffer provided into kernel.py + Specifications: + - Should contain a variable that controls the availability of the buffer + - Because of this, apps will trigger the buffer by setting the value of that variable + - Should have a button to go back (to the desktop), which means integrating a button too + - Preferably make this into a class and make the buffer sizeable \ No newline at end of file diff --git a/TextDraw.py b/TextDraw.py index c892981..7a05565 100644 --- a/TextDraw.py +++ b/TextDraw.py @@ -3,16 +3,44 @@ import pygame, sys +def wrap(txtBuffer): + lines = [] + temp = "" + for c in txtBuffer: + if c == '\n': + lines.append(temp) + temp = "" + else: + temp += c + lines.append(temp) + return lines + +def drawTxt(screen, lines, y = 0): + for line in lines: + img = raster.render(line, True, (255, 255, 255)) + screen.blit(img, (0, y)) + y += 16 + + width, height = 800, 600 txtBuffer = [] +# ↓ Magic! ↓ +caps = { '`': '~', '1': '!', '2': '@', '3': '#', '4': '$', '5': '%', '6': '^', '7': '&', '8': '*', '9': '(', '0': ')', '-': '_', '=': '+', '[': '{', ']': '}', '\\': '|', ';': ':', '\'': '"', ',': '<', '.': '>', '/': '?', 'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H', 'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L', 'm': 'M', 'n': 'N', 'o': 'O', 'p': 'P', 'q': 'Q', 'r': 'R', 's': 'S', 't': 'T', 'u': 'U', 'v': 'V', 'w': 'W', 'x': 'X', 'y': 'Y', 'z': 'Z' } pygame.init() screen = pygame.display.set_mode((width, height)) pygame.display.set_caption("TextDraw") clock = pygame.time.Clock() +raster = pygame.font.Font("res/vga936.fon", 32) + +shift = False +capsLock = False + while True: + screen.fill((0, 0, 0)) + drawTxt(screen, wrap(txtBuffer)) pygame.display.update() clock.tick(50) for event in pygame.event.get(): @@ -23,21 +51,28 @@ if event.key == pygame.K_BACKSPACE: try: txtBuffer.pop() - for c in txtBuffer: - print(txtBuffer) except: - print(txtBuffer) + pass elif event.key == pygame.K_RETURN: txtBuffer.append('\n') - print(txtBuffer) - elif event.key == pygame.K_LSHIFT or event == pygame.K_RSHIFT: - # TODO: do shift - pass + elif event.key == pygame.K_TAB: + for i in range(4): + txtBuffer.append(' ') + elif event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT: + shift = True elif event.key == pygame.K_CAPSLOCK: - # TODO: always do shift - pass + capsLock = 1 - capsLock else: - if 32 <= event.key <= 126 or event.key == pygame.K_TAB: - txtBuffer.append(chr(event.key)) - for c in txtBuffer: - print(txtBuffer) \ No newline at end of file + if 32 <= event.key <= 126: + # ↓ Also magic! ↓ + if (44 <= event.key <= 57 or event.key == 59 or event.key == 61 or event.key == 96 or 91 <= event.key <= 93 or event.key == 39) and shift: + txtBuffer.append(caps[chr(event.key)]) + elif 97 <= event.key <= 122 and (shift or capsLock): + txtBuffer.append(caps[chr(event.key)]) + else: + txtBuffer.append(chr(event.key)) + elif event.type == pygame.KEYUP: + if event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT: + shift = False + elif event.key == pygame.K_CAPSLOCK: + capsLock = 1 - capsLock \ No newline at end of file diff --git a/backup/files.img b/backup/files.img index 860c876..f458504 100644 Binary files a/backup/files.img and b/backup/files.img differ diff --git a/files.img b/files.img index ead8d81..f458504 100644 --- a/files.img +++ b/files.img @@ -189,8 +189,8 @@ class DlgStatus(Enum): class Dialog: def __init__(self, title, content, status = DlgStatus.INFO): self.img = pygame.image.load("res/dialog/dialog.png") - self.icon = pygame.image.load("res/dialog/" + str(status) + ".bmp") - self.icon.set_colorkey((255, 255, 255)) + self.icon = pygame.transform.scale(pygame.image.load("res/dialog/" + str(status) + ".bmp"), (32, 32)) + self.icon.set_colorkey((255, 0, 255)) self.title = framework.raster.render(title, True, (255, 255, 255)) self.content = lineWrap(content, 35) self.dialogID = 0 @@ -212,8 +212,7 @@ term = App("res/term.jpg") framework.appID = bg.appID framework.addApp(bg) framework.addApp(term) -framework.addDialog(Dialog("Hey there!", "Welcome to our OS emulator! As you can see, line wrap is working perfectly here. Now we just need some art for the icons.")) -framework.addDialog(Dialog("Hi!", "Another one")) +framework.addDialog(Dialog("Hey there!", "Welcome to our OS emulator!")) bg.addButton(Button('U', "res/button/txt_btn.bmp", width // 2 - 35, 20, term.appID, font=framework.raster, content="TERMINAL")) term.addButton(Button('D', "res/button/txt_btn.bmp", width // 2 - 35, 20, bg.appID, font=framework.raster, content="CLOSE")) @@ -238,7 +237,6 @@ while True: !LOC=/bin/ !FNAME=vis.py - # vis.py # Basic CLI text editor diff --git a/kernel.py b/kernel.py index 4b7aac7..397532f 100644 --- a/kernel.py +++ b/kernel.py @@ -85,7 +85,8 @@ def __init__(self, picName): self.pic = Pic(picName) self.appID = 0 self.btnList = [] - self.txtList = [] + self.tooltipList = [] + self.txtFieldList = [] self.secretList = [] def draw(self, screen): if framework.appID != self.appID: @@ -93,11 +94,11 @@ def draw(self, screen): screen.blit(self.pic.img, (0, 0)) for button in self.btnList: button.draw(screen) - for txt in self.txtList: - txt.draw(screen) + for tooltip in self.tooltipList: + tooltip.draw(screen) def addButton(self, b): self.btnList.append(b) - def addTxt(self, txt, font, x, y, c, rect): + def addTooltip(self, txt, font, x, y, c, rect): t = Txt(txt, font, x, y, c, rect) self.txtList.append(t) def mouseDown(self, pos, button): @@ -157,7 +158,7 @@ def mouseMove(self, pos): else: self.status = 0 -class Txt: +class Tooltip: def __init__(self, txt, font, x, y, c, rect): self.txt = txt self.img = font.render(txt, True, c) @@ -174,7 +175,7 @@ def __init__(self, rect, dialogID): self.dialogID = dialogID def mouseDown(self, pos, button): if self.rect.collidepoint(pos): - framework.dialogs.pop(len(framework.dialogs) - 1) + framework.dialogs.pop() print(len(framework.dialogs) - 1) class DlgStatus(Enum): @@ -185,8 +186,8 @@ class DlgStatus(Enum): class Dialog: def __init__(self, title, content, status = DlgStatus.INFO): self.img = pygame.image.load("res/dialog/dialog.png") - self.icon = pygame.image.load("res/dialog/" + str(status) + ".bmp") - self.icon.set_colorkey((255, 255, 255)) + self.icon = pygame.transform.scale(pygame.image.load("res/dialog/" + str(status) + ".bmp"), (32, 32)) + self.icon.set_colorkey((255, 0, 255)) self.title = framework.raster.render(title, True, (255, 255, 255)) self.content = lineWrap(content, 35) self.dialogID = 0 @@ -208,8 +209,7 @@ def mouseDown(self, pos, button): framework.appID = bg.appID framework.addApp(bg) framework.addApp(term) -framework.addDialog(Dialog("Hey there!", "Welcome to our OS emulator! As you can see, line wrap is working perfectly here. Now we just need some art for the icons.")) -framework.addDialog(Dialog("Hi!", "Another one")) +framework.addDialog(Dialog("Hey there!", "Welcome to our OS emulator!")) bg.addButton(Button('U', "res/button/txt_btn.bmp", width // 2 - 35, 20, term.appID, font=framework.raster, content="TERMINAL")) term.addButton(Button('D', "res/button/txt_btn.bmp", width // 2 - 35, 20, bg.appID, font=framework.raster, content="CLOSE")) diff --git a/res/dialog/DlgStatus.ERROR.bmp b/res/dialog/DlgStatus.ERROR.bmp index 1d2e843..7ed0eed 100644 Binary files a/res/dialog/DlgStatus.ERROR.bmp and b/res/dialog/DlgStatus.ERROR.bmp differ diff --git a/res/dialog/DlgStatus.INFO.bmp b/res/dialog/DlgStatus.INFO.bmp index d370957..811f51b 100644 Binary files a/res/dialog/DlgStatus.INFO.bmp and b/res/dialog/DlgStatus.INFO.bmp differ diff --git a/res/dialog/DlgStatus.WARNING.bmp b/res/dialog/DlgStatus.WARNING.bmp index 1715299..c609404 100644 Binary files a/res/dialog/DlgStatus.WARNING.bmp and b/res/dialog/DlgStatus.WARNING.bmp differ diff --git a/stub.py b/stub.py index efb5c62..5d62adc 100644 --- a/stub.py +++ b/stub.py @@ -1,4 +1,3 @@ -# # OS emulator using pygame. # Copyright (C) 2020 The-UltimateGamer & pythonleo # @@ -37,9 +36,10 @@ dsk_spl = img.read().split('\n') kernel = [] for i, line in enumerate(dsk_spl): - if line == '!LOC=/sys/' and dsk_spl[i+1] == '!FNAME=kernel.py': + if line == '!LOC=/sys/' and dsk_spl[i + 1] == '!FNAME=kernel.py': for j in range(i+2, len(dsk_spl)): - if len(dsk_spl[j]) > 0 and dsk_spl[j][0] == '!': break + if len(dsk_spl[j]) > 0 and dsk_spl[j][0] == '!': + break kernel.append(dsk_spl[j]) break