.
This commit is contained in:
53
app.py
Normal file
53
app.py
Normal file
@@ -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)
|
||||||
233
gui.py
233
gui.py
@@ -1,9 +1,8 @@
|
|||||||
import pygame
|
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
|
from utils import wrap_multi_line, image_from_data
|
||||||
|
|
||||||
# pylint: disable=E1121,R0902,R0903,R0912,R0913
|
# pylint: disable=E1121,R0902,R0903,R0912,R0913
|
||||||
@@ -13,19 +12,9 @@ BLACK = (0, 0, 0)
|
|||||||
|
|
||||||
|
|
||||||
class baseobject(object):
|
class baseobject(object):
|
||||||
def __init__(self,
|
def __init__(
|
||||||
surface,
|
self, surface, x, y, width, height, data, font, border=False, fg=WHITE, bg=BLACK, name=None, title=None
|
||||||
x,
|
):
|
||||||
y,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
data,
|
|
||||||
font,
|
|
||||||
border=False,
|
|
||||||
fg=WHITE,
|
|
||||||
bg=BLACK,
|
|
||||||
name=None,
|
|
||||||
title=None):
|
|
||||||
self.surface = surface
|
self.surface = surface
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
@@ -91,22 +80,23 @@ class baseobject(object):
|
|||||||
|
|
||||||
|
|
||||||
class menu(baseobject):
|
class menu(baseobject):
|
||||||
def __init__(self,
|
def __init__(
|
||||||
surface,
|
self,
|
||||||
x,
|
surface,
|
||||||
y,
|
x,
|
||||||
width,
|
y,
|
||||||
height,
|
width,
|
||||||
data,
|
height,
|
||||||
font,
|
data,
|
||||||
border=False,
|
font,
|
||||||
fg=WHITE,
|
border=False,
|
||||||
bg=BLACK,
|
fg=WHITE,
|
||||||
name=None,
|
bg=BLACK,
|
||||||
startitem=0,
|
name=None,
|
||||||
itemattop=0):
|
startitem=0,
|
||||||
baseobject.__init__(self, surface, x, y, width, height, data, font,
|
itemattop=0,
|
||||||
border, fg, bg, name)
|
):
|
||||||
|
baseobject.__init__(self, surface, x, y, width, height, data, font, border, fg, bg, name)
|
||||||
self.currentitem = startitem
|
self.currentitem = startitem
|
||||||
self.itemattop = itemattop
|
self.itemattop = itemattop
|
||||||
self.itemsperpage = int(self.textheight / self.fontheight)
|
self.itemsperpage = int(self.textheight / self.fontheight)
|
||||||
@@ -120,8 +110,7 @@ class menu(baseobject):
|
|||||||
if self.currentitem == self.itemattop:
|
if self.currentitem == self.itemattop:
|
||||||
self.itemattop -= 1
|
self.itemattop -= 1
|
||||||
self.currentitem -= 1
|
self.currentitem -= 1
|
||||||
if event.key in cfg["KeyDown"] and self.currentitem < len(
|
if event.key in cfg["KeyDown"] and self.currentitem < len(self.data) - 1:
|
||||||
self.data) - 1:
|
|
||||||
self.currentitem += 1
|
self.currentitem += 1
|
||||||
if self.itemattop + self.itemsperpage <= self.currentitem:
|
if self.itemattop + self.itemsperpage <= self.currentitem:
|
||||||
self.itemattop += 1
|
self.itemattop += 1
|
||||||
@@ -132,8 +121,7 @@ class menu(baseobject):
|
|||||||
if self.itemattop < 0:
|
if self.itemattop < 0:
|
||||||
self.itemattop = 0
|
self.itemattop = 0
|
||||||
self.currentitem = 0
|
self.currentitem = 0
|
||||||
if event.key in cfg["KeyPgDn"] and self.currentitem < len(
|
if event.key in cfg["KeyPgDn"] and self.currentitem < len(self.data) - 1:
|
||||||
self.data) - 1:
|
|
||||||
self.currentitem += self.itemsperpage - 1
|
self.currentitem += self.itemsperpage - 1
|
||||||
while self.currentitem - self.itemattop >= self.itemsperpage:
|
while self.currentitem - self.itemattop >= self.itemsperpage:
|
||||||
self.itemattop += 1
|
self.itemattop += 1
|
||||||
@@ -143,28 +131,23 @@ class menu(baseobject):
|
|||||||
if event.key in cfg["KeyHome"] and self.currentitem > 0:
|
if event.key in cfg["KeyHome"] and self.currentitem > 0:
|
||||||
self.currentitem = 0
|
self.currentitem = 0
|
||||||
self.itemattop = 0
|
self.itemattop = 0
|
||||||
if event.key in cfg["KeyEnd"] and self.currentitem < len(
|
if event.key in cfg["KeyEnd"] and self.currentitem < len(self.data) - 1:
|
||||||
self.data) - 1:
|
|
||||||
self.currentitem = len(self.data) - 1
|
self.currentitem = len(self.data) - 1
|
||||||
self.itemattop = self.currentitem - self.itemsperpage + 1
|
self.itemattop = self.currentitem - self.itemsperpage + 1
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
pygame.Surface.fill(
|
pygame.Surface.fill(self.surface, self.bg, rect=pygame.Rect(self.x, self.y, self.width, self.height))
|
||||||
self.surface,
|
|
||||||
self.bg,
|
|
||||||
rect=pygame.Rect(self.x, self.y, self.width, self.height))
|
|
||||||
|
|
||||||
if self.border:
|
if self.border:
|
||||||
pygame.draw.rect(self.surface, self.fg,
|
pygame.draw.rect(
|
||||||
pygame.Rect(self.x + 1, self.y + 1,
|
self.surface, self.fg, pygame.Rect(self.x + 1, self.y + 1, self.width - 2, self.height - 2), 1
|
||||||
self.width - 2, self.height - 2), 1)
|
)
|
||||||
|
|
||||||
for i in range(0, self.itemsperpage):
|
for i in range(0, self.itemsperpage):
|
||||||
if i > len(self.data) - 1:
|
if i > len(self.data) - 1:
|
||||||
t = pygame.Surface((self.textwidth, self.fontheight))
|
t = pygame.Surface((self.textwidth, self.fontheight))
|
||||||
t.fill(self.bg)
|
t.fill(self.bg)
|
||||||
self.surface.blit(t, (self.textx,
|
self.surface.blit(t, (self.textx, self.texty + i * self.fontheight))
|
||||||
self.texty + i * self.fontheight))
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self.isrom:
|
if self.isrom:
|
||||||
@@ -177,33 +160,20 @@ class menu(baseobject):
|
|||||||
t = pygame.Surface((self.textwidth, self.fontheight))
|
t = pygame.Surface((self.textwidth, self.fontheight))
|
||||||
t.fill(self.fg)
|
t.fill(self.fg)
|
||||||
t.blit(s, (0, 0))
|
t.blit(s, (0, 0))
|
||||||
self.surface.blit(t, (self.textx,
|
self.surface.blit(t, (self.textx, self.texty + i * self.fontheight))
|
||||||
self.texty + i * self.fontheight))
|
|
||||||
else:
|
else:
|
||||||
s = self.font.render(item, True, self.fg, self.bg)
|
s = self.font.render(item, True, self.fg, self.bg)
|
||||||
t = pygame.Surface((self.textwidth, self.fontheight))
|
t = pygame.Surface((self.textwidth, self.fontheight))
|
||||||
t.fill(self.bg)
|
t.fill(self.bg)
|
||||||
t.blit(s, (0, 0))
|
t.blit(s, (0, 0))
|
||||||
self.surface.blit(t, (self.textx,
|
self.surface.blit(t, (self.textx, self.texty + i * self.fontheight))
|
||||||
self.texty + i * self.fontheight))
|
|
||||||
|
|
||||||
|
|
||||||
class notepad(baseobject):
|
class notepad(baseobject):
|
||||||
def __init__(self,
|
def __init__(
|
||||||
surface,
|
self, surface, x, y, width, height, data, font, border=False, fg=WHITE, bg=BLACK, name="None", title=None
|
||||||
x,
|
):
|
||||||
y,
|
baseobject.__init__(self, surface, x, y, width, height, data, font, border, fg, bg, name, title)
|
||||||
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.data = wrap_multi_line(data, self.font, self.textwidth)
|
||||||
self.lineattop = 0
|
self.lineattop = 0
|
||||||
self.linesperpage = int(self.textheight / self.fontheight)
|
self.linesperpage = int(self.textheight / self.fontheight)
|
||||||
@@ -229,52 +199,30 @@ class notepad(baseobject):
|
|||||||
self.lineattop = self.lasttopline
|
self.lineattop = self.lasttopline
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
pygame.Surface.fill(
|
pygame.Surface.fill(self.surface, self.bg, rect=pygame.Rect(self.x, self.y, self.width, self.height))
|
||||||
self.surface,
|
|
||||||
self.bg,
|
|
||||||
rect=pygame.Rect(self.x, self.y, self.width, self.height))
|
|
||||||
if self.border:
|
if self.border:
|
||||||
pygame.draw.rect(self.surface, self.fg,
|
pygame.draw.rect(
|
||||||
pygame.Rect(self.x + 1, self.y + 1,
|
self.surface, self.fg, pygame.Rect(self.x + 1, self.y + 1, self.width - 2, self.height - 2), 1
|
||||||
self.width - 2, self.height - 2), 1)
|
)
|
||||||
if self.title:
|
if self.title:
|
||||||
x = (self.textwidth / 2) - (
|
x = (self.textwidth / 2) - (self.font.size("%s" % self.title)[0] / 2)
|
||||||
self.font.size('%s' % self.title)[0] / 2)
|
title_surface = pygame.Surface((self.textwidth, self.fontheight))
|
||||||
title_surface = pygame.Surface((self.textwidth,
|
|
||||||
self.fontheight))
|
|
||||||
title_surface.fill(self.fg)
|
title_surface.fill(self.fg)
|
||||||
title_surface.blit(
|
title_surface.blit(self.font.render("%s" % self.title, True, BLACK, self.fg), (x, 0))
|
||||||
self.font.render('%s' % self.title, True, BLACK, self.fg),
|
self.surface.blit(title_surface, (self.textx, self.texty - self.fontheight))
|
||||||
(x, 0))
|
|
||||||
self.surface.blit(title_surface,
|
|
||||||
(self.textx, self.texty - self.fontheight))
|
|
||||||
for c in range(0, self.linesperpage):
|
for c in range(0, self.linesperpage):
|
||||||
try:
|
try:
|
||||||
itemsurface = self.font.render(self.data[c + self.lineattop],
|
itemsurface = self.font.render(self.data[c + self.lineattop], True, self.fg, self.bg)
|
||||||
True, self.fg, self.bg)
|
self.surface.blit(itemsurface, (self.textx, self.texty + c * self.fontheight))
|
||||||
self.surface.blit(itemsurface,
|
|
||||||
(self.textx,
|
|
||||||
self.texty + c * self.fontheight))
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class image_notepad(baseobject):
|
class image_notepad(baseobject):
|
||||||
def __init__(self,
|
def __init__(
|
||||||
surface,
|
self, surface, x, y, width, height, data, font, border=False, fg=WHITE, bg=BLACK, name="None", title=None
|
||||||
x,
|
):
|
||||||
y,
|
baseobject.__init__(self, surface, x, y, width, height, data, font, border, fg, bg, name, title)
|
||||||
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.currentitem = 0
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
@@ -288,25 +236,18 @@ class image_notepad(baseobject):
|
|||||||
self.currentitem -= 1
|
self.currentitem -= 1
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
pygame.Surface.fill(
|
pygame.Surface.fill(self.surface, self.bg, rect=pygame.Rect(self.x, self.y, self.width, self.height))
|
||||||
self.surface,
|
|
||||||
self.bg,
|
|
||||||
rect=pygame.Rect(self.x, self.y, self.width, self.height))
|
|
||||||
if self.border:
|
if self.border:
|
||||||
pygame.draw.rect(self.surface, self.fg,
|
pygame.draw.rect(
|
||||||
pygame.Rect(self.x + 1, self.y + 1,
|
self.surface, self.fg, pygame.Rect(self.x + 1, self.y + 1, self.width - 2, self.height - 2), 1
|
||||||
self.width - 2, self.height - 2), 1)
|
)
|
||||||
x = (self.textwidth / 2) - (self.font.size('%s' % self.title)[0] / 2)
|
x = (self.textwidth / 2) - (self.font.size("%s" % self.title)[0] / 2)
|
||||||
title_surface = pygame.Surface((self.textwidth, self.fontheight))
|
title_surface = pygame.Surface((self.textwidth, self.fontheight))
|
||||||
title_surface.fill(self.fg)
|
title_surface.fill(self.fg)
|
||||||
title_surface.blit(
|
title_surface.blit(self.font.render("%s" % self.data[self.currentitem][0], True, BLACK, self.fg), (x, 0))
|
||||||
self.font.render('%s' % self.data[self.currentitem][0], True,
|
self.surface.blit(title_surface, (self.textx, self.texty - self.fontheight))
|
||||||
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],
|
image_surface = image_from_data(self.data[self.currentitem][1], (self.textwidth, self.textheight))
|
||||||
(self.textwidth, self.textheight))
|
|
||||||
|
|
||||||
w, h = image_surface.get_width(), image_surface.get_height()
|
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))
|
self.surface.blit(image_surface, (x, y))
|
||||||
|
|
||||||
|
|
||||||
class gui():
|
class gui:
|
||||||
def __init__(self, surface):
|
def __init__(self, surface):
|
||||||
self.surface = surface
|
self.surface = surface
|
||||||
self.objects = []
|
self.objects = []
|
||||||
self.font = pygame.font.Font(
|
self.font = pygame.font.Font(pygame.font.match_font(cfg["Font"], bold=True), cfg["FontSize"])
|
||||||
pygame.font.match_font(cfg["Font"], bold=True), cfg["FontSize"])
|
|
||||||
# self.fontheight = self.font.get_height()
|
# self.fontheight = self.font.get_height()
|
||||||
self.currentobject = 0
|
self.currentobject = 0
|
||||||
|
|
||||||
@@ -333,54 +273,23 @@ class gui():
|
|||||||
|
|
||||||
return event
|
return event
|
||||||
|
|
||||||
def add_menu(self,
|
def add_menu(
|
||||||
x,
|
self, x, y, width, height, data, border=False, fg=WHITE, bg=BLACK, name="None", startitem=0, itemattop=0
|
||||||
y,
|
):
|
||||||
width,
|
|
||||||
height,
|
|
||||||
data,
|
|
||||||
border=False,
|
|
||||||
fg=WHITE,
|
|
||||||
bg=BLACK,
|
|
||||||
name="None",
|
|
||||||
startitem=0,
|
|
||||||
itemattop=0):
|
|
||||||
self.currentobject += 1
|
self.currentobject += 1
|
||||||
self.objects.append(
|
self.objects.append(
|
||||||
menu(self.surface, x, y, width, height, data, self.font, border,
|
menu(self.surface, x, y, width, height, data, self.font, border, fg, bg, name, startitem, itemattop)
|
||||||
fg, bg, name, startitem, itemattop))
|
)
|
||||||
|
|
||||||
def add_notepad(self,
|
def add_notepad(self, x, y, width, height, data, border=False, fg=WHITE, bg=BLACK, name="None", title=None):
|
||||||
x,
|
|
||||||
y,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
data,
|
|
||||||
border=False,
|
|
||||||
fg=WHITE,
|
|
||||||
bg=BLACK,
|
|
||||||
name="None",
|
|
||||||
title=None):
|
|
||||||
self.currentobject += 1
|
self.currentobject += 1
|
||||||
self.objects.append(
|
self.objects.append(notepad(self.surface, x, y, width, height, data, self.font, border, fg, bg, name, title))
|
||||||
notepad(self.surface, x, y, width, height, data, self.font, border,
|
|
||||||
fg, bg, name, title))
|
|
||||||
|
|
||||||
def add_image_notepad(self,
|
def add_image_notepad(self, x, y, width, height, data, border=False, fg=WHITE, bg=BLACK, name="None", title=None):
|
||||||
x,
|
|
||||||
y,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
data,
|
|
||||||
border=False,
|
|
||||||
fg=WHITE,
|
|
||||||
bg=BLACK,
|
|
||||||
name="None",
|
|
||||||
title=None):
|
|
||||||
self.currentobject += 1
|
self.currentobject += 1
|
||||||
self.objects.append(
|
self.objects.append(
|
||||||
image_notepad(self.surface, x, y, width, height, data, self.font,
|
image_notepad(self.surface, x, y, width, height, data, self.font, border, fg, bg, name, title)
|
||||||
border, fg, bg, name, title))
|
)
|
||||||
|
|
||||||
def deletelastobject(self):
|
def deletelastobject(self):
|
||||||
del self.objects[-1]
|
del self.objects[-1]
|
||||||
|
|||||||
67
mfe.py
67
mfe.py
@@ -1,65 +1,6 @@
|
|||||||
import pyglet
|
import app
|
||||||
from config import cfg
|
|
||||||
|
|
||||||
from emu import emu
|
if __name__ == "__main__":
|
||||||
|
application = app.application()
|
||||||
|
|
||||||
from pygletgui import pygletgui
|
application.run()
|
||||||
|
|
||||||
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()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user