Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions TextDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import pygame, sys

def wrap(txtBuffer):
def wrap(txtBuffer, w = 80):
lines = []
temp = ""
for c in txtBuffer:
if c == '\n':
for i in range(len(txtBuffer)):
if txtBuffer[i] == '\n' or (i != 0 and i % w == 0):
lines.append(temp)
temp = ""
else:
temp += c
temp += txtBuffer[i]
lines.append(temp)
return lines

Expand Down Expand Up @@ -65,7 +65,7 @@ def drawTxt(screen, lines, y = 0):
else:
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:
if (event.key == 39 or 44 <= event.key <= 57 or event.key == 59 or event.key == 61 or event.key == 96 or 91 <= event.key <= 93) and shift:
txtBuffer.append(caps[chr(event.key)])
elif 97 <= event.key <= 122 and (shift or capsLock):
txtBuffer.append(caps[chr(event.key)])
Expand Down
137 changes: 97 additions & 40 deletions kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@

width, height = 1024, 768

def lineWrap(txt, w):
processed = []
temp = ""
for i in range(txt.__len__()):
if i != 0 and i % w == 0:
processed.append(framework.raster.render(temp, True, (0, 0, 0)))
temp = ""
temp += txt[i]
processed.append(framework.raster.render(temp, True, (0, 0, 0)))
return processed

class Pic(object):
def __init__(self, fileName):
img = pygame.image.load(fileName)
Expand All @@ -38,8 +27,7 @@ def __init__(self):
self.screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Windows 95 Simulated")
self.clock = pygame.time.Clock()
self.font32 = pygame.font.Font("res/segoeui.ttf", 32)
self.raster = pygame.font.Font("res/vga936.fon", 32)
self.raster = pygame.font.Font("res/pkmndp.ttf", 19)
self.speed = 5
self.mousePos = (0, 0)
self.apps = []
Expand All @@ -63,11 +51,10 @@ def addDialog(self, dialog):
dialog.dialogID = len(self.dialogs)
dialog.closeBtn = Secret((dialog.x + 357, dialog.y + 6, 17, 16), dialog.dialogID)
self.dialogs.append(dialog)
# TODO: Add KEYUP/KEYDOWN support
def keyUp(self, key):
return
self.apps[self.appID].keyUp(key)
def keyDown(self, key):
return
self.apps[self.appID].keyDown(key)
def mouseDown(self, pos, button):
self.apps[self.appID].mouseDown(pos, button)
try:
Expand All @@ -86,7 +73,8 @@ def __init__(self, picName):
self.appID = 0
self.btnList = []
self.tooltipList = []
self.txtFieldList = []
self.txtField = TxtField(0, 0, 0, 0)
self.txtFieldEnabled = False
self.secretList = []
def draw(self, screen):
if framework.appID != self.appID:
Expand All @@ -96,11 +84,20 @@ def draw(self, screen):
button.draw(screen)
for tooltip in self.tooltipList:
tooltip.draw(screen)
if self.txtFieldEnabled:
self.txtField.content = self.txtField.wrap(self.txtField.txtBuffer)
self.txtField.content = self.txtField.content[-self.txtField.h:]
self.txtField.draw(screen, self.txtField.content)
def addButton(self, b):
self.btnList.append(b)
def addTooltip(self, txt, font, x, y, c, rect):
t = Txt(txt, font, x, y, c, rect)
self.txtList.append(t)
tt = Tooltip(txt, font, x, y, c, rect)
self.txtList.append(tt)
def enableTxtField(self, x, y, w, h, placeholder = "/# "):
self.txtFieldEnabled = True
self.txtField.x, self.txtField.y = x, y
self.txtField.w, self.txtField.h = w, h
self.txtField.placeholder = placeholder
def mouseDown(self, pos, button):
for btn in self.btnList:
btn.mouseDown(pos, button)
Expand All @@ -113,14 +110,15 @@ def mouseMotion(self, pos):
framework.mousePos = pos
for btn in self.btnList:
btn.mouseMove(pos)
def keyUp(self, button):
framework.keyUp(button)
def keyDown(self, button):
framework.keyDown(button)
def keyUp(self, key):
if self.txtFieldEnabled:
self.txtField.keyUp(key)
def keyDown(self, key):
if self.txtFieldEnabled:
self.txtField.keyDown(key)

class Button:
def __init__(self, name, picFile, x, y, appID, **txt):
self.name = name
def __init__(self, picFile, x, y, appID, **txt):
self.img = pygame.image.load(picFile).convert()
self.w, self.h = self.img.get_width() // 3, self.img.get_height()
self.x, self.y = x, y
Expand All @@ -142,16 +140,8 @@ def mouseUp(self, pos, button):
self.status = 0
if not self.rect.collidepoint(pos):
return
if self.name == 'U':
framework.apps[self.appID].pic.draw(framework.screen, framework.speed)
if self.name == 'D':
framework.apps[self.appID].pic.draw(framework.screen, framework.speed)
if self.name == 'L':
framework.apps[self.appID].pic.draw(framework.screen, framework.speed)
if self.name == 'R':
framework.apps[self.appID].pic.draw(framework.screen, framework.speed)
framework.apps[self.appID].pic.draw(framework.screen, framework.speed)
framework.appID = self.appID

def mouseMove(self, pos):
if self.rect.collidepoint(pos):
self.status = 1
Expand All @@ -169,14 +159,72 @@ def draw(self, screen):
if self.rect.collidepoint(framework.mousePos):
screen.blit(self.img, (self.x, self.y))

class TxtField:
def __init__(self, x, y, w, h, placeholder = ""):
self.x, self.y = x, y
self.w, self.h = w, h
self.placeholder = placeholder
self.txtBuffer = []
self.content = []
self.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' }
self.shift, self.capsLock = False, False
self.raster = pygame.font.Font("res/pkmndp.ttf", 28)
def wrap(self, txtBuffer):
lines = []
temp = self.placeholder
for i in range(len(txtBuffer)):
if txtBuffer[i] == '\n':
lines.append(temp)
temp = self.placeholder
elif (i != 0 and i % self.w == 0):
lines.append(temp)
temp = ""
else:
temp += txtBuffer[i]
lines.append(temp)
return lines
def draw(self, screen, lines, c = (255, 255, 255), y = 0):
for line in lines:
img = self.raster.render(line, True, c)
screen.blit(img, (0, y))
y += 30
def keyUp(self, key):
if key == pygame.K_LSHIFT or key == pygame.K_RSHIFT:
self.shift = False
elif key == pygame.K_CAPSLOCK:
self.capsLock = 1 - self.capsLock
def keyDown(self, key):
if key == pygame.K_BACKSPACE:
try:
self.txtBuffer.pop()
except:
pass
elif key == pygame.K_RETURN:
self.txtBuffer.append('\n')
elif key == pygame.K_TAB:
for i in range(4):
self.txtBuffer.append(' ')
elif key == pygame.K_LSHIFT or key == pygame.K_RSHIFT:
self.shift = True
elif key == pygame.K_CAPSLOCK:
self.capsLock = 1 - self.capsLock
else:
if 32 <= key <= 126:
# ↓ Also magic! ↓
if (key == 39 or 44 <= key <= 57 or key == 59 or key == 61 or key == 96 or 91 <= key <= 93) and self.shift:
self.txtBuffer.append(self.caps[chr(key)])
elif 97 <= event.key <= 122 and (self.shift or self.capsLock):
self.txtBuffer.append(self.caps[chr(key)])
else:
self.txtBuffer.append(chr(key))

class Secret:
def __init__(self, rect, dialogID):
self.rect = pygame.Rect(rect)
self.dialogID = dialogID
def mouseDown(self, pos, button):
if self.rect.collidepoint(pos):
framework.dialogs.pop()
print(len(framework.dialogs) - 1)

class DlgStatus(Enum):
INFO = 0
Expand All @@ -189,11 +237,21 @@ def __init__(self, title, content, status = DlgStatus.INFO):
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.content = self.wrap(content, 35)
self.dialogID = 0
self.w, self.h = self.img.get_size()
self.x, self.y = 322, 284
self.closeBtn = None
def wrap(self, txt, w):
processed = []
temp = ""
for i in range(txt.__len__()):
if i != 0 and i % w == 0:
processed.append(framework.raster.render(temp, True, (0, 0, 0)))
temp = ""
temp += txt[i]
processed.append(framework.raster.render(temp, True, (0, 0, 0)))
return processed
def draw(self, screen):
screen.blit(self.img, (self.x, self.y))
screen.blit(self.title, (self.x + 10, self.y + 6))
Expand All @@ -210,8 +268,9 @@ def mouseDown(self, pos, button):
framework.addApp(bg)
framework.addApp(term)
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"))
bg.addButton(Button("res/button/txt_btn.bmp", width // 2 - 35, 20, term.appID, font=framework.raster, content="TERMINAL"))
term.addButton(Button("res/button/txt_btn.bmp", width // 2 - 35, 20, bg.appID, font=framework.raster, content="CLOSE"))
term.enableTxtField(0, 0, 80, 20)

while True:
for event in pygame.event.get():
Expand All @@ -220,10 +279,8 @@ def mouseDown(self, pos, button):
sys.exit()
if event.type == pygame.KEYDOWN:
framework.keyDown(event.key)
print(event.key)
elif event.type == pygame.KEYUP:
framework.keyUp(event.key)
print(event.key)
if event.type == pygame.MOUSEBUTTONDOWN:
framework.mouseDown(event.pos, event.button)
elif event.type == pygame.MOUSEBUTTONUP:
Expand Down
File renamed without changes.
Binary file removed res/segoeui.ttf
Binary file not shown.
Binary file removed res/vga936.fon
Binary file not shown.