From a36e9d92edce6fedd76a9f8fc17a155753898eb0 Mon Sep 17 00:00:00 2001 From: Rich Date: Thu, 7 Dec 2023 14:59:54 +0000 Subject: [PATCH] . --- app.py | 53 +++++++++++++ gui.py | 233 ++++++++++++++++++--------------------------------------- mfe.py | 67 +---------------- 3 files changed, 128 insertions(+), 225 deletions(-) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..c1c37ca --- /dev/null +++ b/app.py @@ -0,0 +1,53 @@ +import pygame +from config import cfg + +from emu import emu +from gui import gui + + +class application: + def __init__(self): + print(cfg["Engine"]) + self.gfx = gfx_pygame.gfx_pygame() + + self.gfx.setIcon("arcade.png") + + if cfg["FullScreen"]: + self.screen = self.gfx.dispSetMode(cfg["ResolutionX"], cfg["ResolutionY"], True) + else: + self.screen = self.gfx.dispSetMode(cfg["ResolutionX"], cfg["ResolutionY"], False) + + self.font = self.gfx.getFont(cfg["Font"], cfg["FontSize"]) + + self.status = self.gfx.getSurface(cfg["ResolutionX"], cfg["FontSize"]) + + self.listwidth = int(cfg["ResolutionX"] / 2) + + self.emu = emu() + + self.gui = gui(self.gfx, self.screen, self.font) + + self.gui.add_menu( + 0, + 0, + self.listwidth, + cfg["ResolutionY"] - self.font.get_height(), + border=False, + # data=self.roms, + data=["1", "2"], + fg=(255, 255, 255), + bg=(0, 0, 0), + name="MainList", + # startitem=get_emu('CurrentGame'), + # itemattop=get_emu('GameAtTop')) + startitem=0, + itemattop=0, + ) + + self.gui.render() + + def run(self): + pass + while True: + self.gui.render() + self.gfx.tick(60) diff --git a/gui.py b/gui.py index f554177..704034e 100644 --- a/gui.py +++ b/gui.py @@ -1,9 +1,8 @@ import pygame -# pylint: disable=E0611 -from pygame.locals import KEYDOWN -# pylint: enable=E0611 -from configfile import cfg +from pygame.locals import KEYDOWN + +from config import cfg from utils import wrap_multi_line, image_from_data # pylint: disable=E1121,R0902,R0903,R0912,R0913 @@ -13,19 +12,9 @@ BLACK = (0, 0, 0) class baseobject(object): - def __init__(self, - surface, - x, - y, - width, - height, - data, - font, - border=False, - fg=WHITE, - bg=BLACK, - name=None, - title=None): + def __init__( + self, surface, x, y, width, height, data, font, border=False, fg=WHITE, bg=BLACK, name=None, title=None + ): self.surface = surface self.x = x self.y = y @@ -91,22 +80,23 @@ class baseobject(object): class menu(baseobject): - def __init__(self, - surface, - x, - y, - width, - height, - data, - font, - border=False, - fg=WHITE, - bg=BLACK, - name=None, - startitem=0, - itemattop=0): - baseobject.__init__(self, surface, x, y, width, height, data, font, - border, fg, bg, name) + def __init__( + self, + surface, + x, + y, + width, + height, + data, + font, + border=False, + fg=WHITE, + bg=BLACK, + name=None, + startitem=0, + itemattop=0, + ): + baseobject.__init__(self, surface, x, y, width, height, data, font, border, fg, bg, name) self.currentitem = startitem self.itemattop = itemattop self.itemsperpage = int(self.textheight / self.fontheight) @@ -120,8 +110,7 @@ class menu(baseobject): if self.currentitem == self.itemattop: self.itemattop -= 1 self.currentitem -= 1 - if event.key in cfg["KeyDown"] and self.currentitem < len( - self.data) - 1: + if event.key in cfg["KeyDown"] and self.currentitem < len(self.data) - 1: self.currentitem += 1 if self.itemattop + self.itemsperpage <= self.currentitem: self.itemattop += 1 @@ -132,8 +121,7 @@ class menu(baseobject): if self.itemattop < 0: self.itemattop = 0 self.currentitem = 0 - if event.key in cfg["KeyPgDn"] and self.currentitem < len( - self.data) - 1: + if event.key in cfg["KeyPgDn"] and self.currentitem < len(self.data) - 1: self.currentitem += self.itemsperpage - 1 while self.currentitem - self.itemattop >= self.itemsperpage: self.itemattop += 1 @@ -143,28 +131,23 @@ class menu(baseobject): if event.key in cfg["KeyHome"] and self.currentitem > 0: self.currentitem = 0 self.itemattop = 0 - if event.key in cfg["KeyEnd"] and self.currentitem < len( - self.data) - 1: + if event.key in cfg["KeyEnd"] and self.currentitem < len(self.data) - 1: self.currentitem = len(self.data) - 1 self.itemattop = self.currentitem - self.itemsperpage + 1 def render(self): - pygame.Surface.fill( - self.surface, - self.bg, - rect=pygame.Rect(self.x, self.y, self.width, self.height)) + pygame.Surface.fill(self.surface, self.bg, rect=pygame.Rect(self.x, self.y, self.width, self.height)) if self.border: - pygame.draw.rect(self.surface, self.fg, - pygame.Rect(self.x + 1, self.y + 1, - self.width - 2, self.height - 2), 1) + pygame.draw.rect( + self.surface, self.fg, pygame.Rect(self.x + 1, self.y + 1, self.width - 2, self.height - 2), 1 + ) for i in range(0, self.itemsperpage): if i > len(self.data) - 1: t = pygame.Surface((self.textwidth, self.fontheight)) t.fill(self.bg) - self.surface.blit(t, (self.textx, - self.texty + i * self.fontheight)) + self.surface.blit(t, (self.textx, self.texty + i * self.fontheight)) continue if self.isrom: @@ -177,33 +160,20 @@ class menu(baseobject): t = pygame.Surface((self.textwidth, self.fontheight)) t.fill(self.fg) t.blit(s, (0, 0)) - self.surface.blit(t, (self.textx, - self.texty + i * self.fontheight)) + self.surface.blit(t, (self.textx, self.texty + i * self.fontheight)) else: s = self.font.render(item, True, self.fg, self.bg) t = pygame.Surface((self.textwidth, self.fontheight)) t.fill(self.bg) t.blit(s, (0, 0)) - self.surface.blit(t, (self.textx, - self.texty + i * self.fontheight)) + self.surface.blit(t, (self.textx, self.texty + i * self.fontheight)) class notepad(baseobject): - def __init__(self, - surface, - x, - y, - width, - height, - data, - font, - border=False, - fg=WHITE, - bg=BLACK, - name="None", - title=None): - baseobject.__init__(self, surface, x, y, width, height, data, font, - border, fg, bg, name, title) + def __init__( + self, surface, x, y, width, height, data, font, border=False, fg=WHITE, bg=BLACK, name="None", title=None + ): + baseobject.__init__(self, surface, x, y, width, height, data, font, border, fg, bg, name, title) self.data = wrap_multi_line(data, self.font, self.textwidth) self.lineattop = 0 self.linesperpage = int(self.textheight / self.fontheight) @@ -229,52 +199,30 @@ class notepad(baseobject): self.lineattop = self.lasttopline def render(self): - pygame.Surface.fill( - self.surface, - self.bg, - rect=pygame.Rect(self.x, self.y, self.width, self.height)) + pygame.Surface.fill(self.surface, self.bg, rect=pygame.Rect(self.x, self.y, self.width, self.height)) if self.border: - pygame.draw.rect(self.surface, self.fg, - pygame.Rect(self.x + 1, self.y + 1, - self.width - 2, self.height - 2), 1) + pygame.draw.rect( + self.surface, self.fg, pygame.Rect(self.x + 1, self.y + 1, self.width - 2, self.height - 2), 1 + ) if self.title: - x = (self.textwidth / 2) - ( - self.font.size('%s' % self.title)[0] / 2) - title_surface = pygame.Surface((self.textwidth, - self.fontheight)) + x = (self.textwidth / 2) - (self.font.size("%s" % self.title)[0] / 2) + title_surface = pygame.Surface((self.textwidth, self.fontheight)) title_surface.fill(self.fg) - title_surface.blit( - self.font.render('%s' % self.title, True, BLACK, self.fg), - (x, 0)) - self.surface.blit(title_surface, - (self.textx, self.texty - self.fontheight)) + title_surface.blit(self.font.render("%s" % self.title, True, BLACK, self.fg), (x, 0)) + self.surface.blit(title_surface, (self.textx, self.texty - self.fontheight)) for c in range(0, self.linesperpage): try: - itemsurface = self.font.render(self.data[c + self.lineattop], - True, self.fg, self.bg) - self.surface.blit(itemsurface, - (self.textx, - self.texty + c * self.fontheight)) + itemsurface = self.font.render(self.data[c + self.lineattop], True, self.fg, self.bg) + self.surface.blit(itemsurface, (self.textx, self.texty + c * self.fontheight)) except: pass class image_notepad(baseobject): - def __init__(self, - surface, - x, - y, - width, - height, - data, - font, - border=False, - fg=WHITE, - bg=BLACK, - name="None", - title=None): - baseobject.__init__(self, surface, x, y, width, height, data, font, - border, fg, bg, name, title) + def __init__( + self, surface, x, y, width, height, data, font, border=False, fg=WHITE, bg=BLACK, name="None", title=None + ): + baseobject.__init__(self, surface, x, y, width, height, data, font, border, fg, bg, name, title) self.currentitem = 0 self.data = data @@ -288,25 +236,18 @@ class image_notepad(baseobject): self.currentitem -= 1 def render(self): - pygame.Surface.fill( - self.surface, - self.bg, - rect=pygame.Rect(self.x, self.y, self.width, self.height)) + pygame.Surface.fill(self.surface, self.bg, rect=pygame.Rect(self.x, self.y, self.width, self.height)) if self.border: - pygame.draw.rect(self.surface, self.fg, - pygame.Rect(self.x + 1, self.y + 1, - self.width - 2, self.height - 2), 1) - x = (self.textwidth / 2) - (self.font.size('%s' % self.title)[0] / 2) + pygame.draw.rect( + self.surface, self.fg, pygame.Rect(self.x + 1, self.y + 1, self.width - 2, self.height - 2), 1 + ) + x = (self.textwidth / 2) - (self.font.size("%s" % self.title)[0] / 2) title_surface = pygame.Surface((self.textwidth, self.fontheight)) title_surface.fill(self.fg) - title_surface.blit( - self.font.render('%s' % self.data[self.currentitem][0], True, - BLACK, self.fg), (x, 0)) - self.surface.blit(title_surface, (self.textx, - self.texty - self.fontheight)) + title_surface.blit(self.font.render("%s" % self.data[self.currentitem][0], True, BLACK, self.fg), (x, 0)) + self.surface.blit(title_surface, (self.textx, self.texty - self.fontheight)) - image_surface = image_from_data(self.data[self.currentitem][1], - (self.textwidth, self.textheight)) + image_surface = image_from_data(self.data[self.currentitem][1], (self.textwidth, self.textheight)) w, h = image_surface.get_width(), image_surface.get_height() @@ -316,12 +257,11 @@ class image_notepad(baseobject): self.surface.blit(image_surface, (x, y)) -class gui(): +class gui: def __init__(self, surface): self.surface = surface self.objects = [] - self.font = pygame.font.Font( - pygame.font.match_font(cfg["Font"], bold=True), cfg["FontSize"]) + self.font = pygame.font.Font(pygame.font.match_font(cfg["Font"], bold=True), cfg["FontSize"]) # self.fontheight = self.font.get_height() self.currentobject = 0 @@ -333,54 +273,23 @@ class gui(): return event - def add_menu(self, - x, - y, - width, - height, - data, - border=False, - fg=WHITE, - bg=BLACK, - name="None", - startitem=0, - itemattop=0): + def add_menu( + self, x, y, width, height, data, border=False, fg=WHITE, bg=BLACK, name="None", startitem=0, itemattop=0 + ): self.currentobject += 1 self.objects.append( - menu(self.surface, x, y, width, height, data, self.font, border, - fg, bg, name, startitem, itemattop)) + menu(self.surface, x, y, width, height, data, self.font, border, fg, bg, name, startitem, itemattop) + ) - def add_notepad(self, - x, - y, - width, - height, - data, - border=False, - fg=WHITE, - bg=BLACK, - name="None", - title=None): + def add_notepad(self, x, y, width, height, data, border=False, fg=WHITE, bg=BLACK, name="None", title=None): self.currentobject += 1 - self.objects.append( - notepad(self.surface, x, y, width, height, data, self.font, border, - fg, bg, name, title)) + self.objects.append(notepad(self.surface, x, y, width, height, data, self.font, border, fg, bg, name, title)) - def add_image_notepad(self, - x, - y, - width, - height, - data, - border=False, - fg=WHITE, - bg=BLACK, - name="None", - title=None): + def add_image_notepad(self, x, y, width, height, data, border=False, fg=WHITE, bg=BLACK, name="None", title=None): self.currentobject += 1 self.objects.append( - image_notepad(self.surface, x, y, width, height, data, self.font, - border, fg, bg, name, title)) + image_notepad(self.surface, x, y, width, height, data, self.font, border, fg, bg, name, title) + ) def deletelastobject(self): del self.objects[-1] diff --git a/mfe.py b/mfe.py index 2349f36..1eb5c90 100644 --- a/mfe.py +++ b/mfe.py @@ -1,65 +1,6 @@ -import pyglet -from config import cfg +import app -from emu import emu +if __name__ == "__main__": + application = app.application() -from pygletgui import pygletgui - -icon = pyglet.resource.image("arcade.png") - -window = pyglet.window.Window( - cfg["ResolutionX"], - cfg["ResolutionY"], - fullscreen=cfg["FullScreen"], - style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS, -) -pyglet.gl.glClearColor(255, 0, 0, 1.0) # red, green, blue, and alpha(transparency) - -window.set_icon(icon) -# window.set_exclusive_mouse() - -font = pyglet.font.load(cfg["Font"], cfg["FontSize"]) -font_height = font.ascent - font.descent + 1 -print(font_height) - -rom_list_width = int(cfg["ResolutionX"] / 2) - -emu = emu() - -gui = pygletgui(font_height) - -gui.add_menu( - 0, - cfg["ResolutionY"] - 1, - rom_list_width, - cfg["ResolutionY"] - 1, - border=True, - # data=self.roms, - data=["1", "2", "AAAAAaaaaAAAAAAAAaaaaaaaaaaaaasasadsfdsafdsfdsfdsfdsfdsfdsfsadfdsfsdfsdfdsfds"], - fg=(255, 255, 255), - bg=(0, 0, 0), - name="MainList", - # startitem=get_emu('CurrentGame'), - # itemattop=get_emu('GameAtTop')) - startitem=0, - itemattop=0, - font_height=font_height, -) - -# # self.gui.render() - - -@window.event -def on_draw(): - window.clear() - gui.render() - - -@window.event -def on_key_press(symbol, modifiers): - if symbol == pyglet.window.key.ESCAPE: - return - return pyglet.event.EVENT_HANDLED - - -pyglet.app.run() + application.run()