Browse Source

Built out and cleaned up the Display class.

master
Bryan Miller 6 years ago
parent
commit
c15de1dfc9
1 changed files with 65 additions and 3 deletions
  1. +65
    -3
      game/gbe/core.py

+ 65
- 3
game/gbe/core.py View File

@@ -52,7 +52,12 @@ class Time:
class Display:
def __init__(self, width=640, height=480):
self._init = False
self._resolution = width, height
self._resolution = (width, height)
self._display_surface = None
self._display_flags = Display.FLAG_RESIZABLE | Display.FLAG_HWSURFACE | Display.FLAG_DOUBLEBUF

def _isFlagSet(self, flag):
return (self._display_flags & flag) == flag

@property
def surface(self):
@@ -60,19 +65,76 @@ class Display:

@property
def width(self):
if self._display_surface is None:
return 0
return self._resolution[0]

@property
def height(self):
if self._display_surface is None:
return 0
return self._resolution[1]

@property
def resolution(self):
if self._display_surface is None:
return (0,0)
return self._display_surface.get_size()

@property
def fullscreen(self):
return self._isFlagSet(Display.FLAG_FULLSCREEN)

@property
def double_buffered(self):
return self._isFlagSet(Display.FLAG_DOUBLEBUF)

@property
def resizable(self):
return self._isFlagSet(Display.FLAG_RESIZABLE)

@property
def no_frame(self):
return self._isFlagSet(Display.FLAG_NOFRAME)

@property
def opengl(self):
return self._isFlagSet(Display.FLAG_OPENGL)

def toggle_fullscreen(self):
if self._isFlagSet(Display.FLAG_FULLSCREEN):
self._display_flags ^= Display.FLAG_FULLSCREEN
else:
self._display_flags |= Display.FLAG_FULLSCREEN
self.set_mode(self._resolution, flags)

def set_mode(self, resolution, flags):
if (self._init == False):
self._init = True
pygame.init()
self._display_surface = pygame.display.set_mode(resolution, flags)
self._display_flags = self._display_surface.get_flags()
self._resolution = self._display_surface.get_size()
return self

def init(self):
if self._init == False:
self._init = True
pygame.init()
self._display_surface = pygame.display.set_mode(self._resolution, pygame.HWSURFACE | pygame.DOUBLEBUF)
self.set_mode(self._resolution, self._display_flags)
return self

def close(self):
pygame.quit()

FLAG_SWSURFACE = pygame.SWSURFACE
FLAG_HWSURFACE = pygame.HWSURFACE
FLAG_HWPALETTE = pygame.HWPALETTE
FLAG_DOUBLEBUF = pygame.DOUBLEBUF
FLAG_FULLSCREEN = pygame.FULLSCREEN
FLAG_OPENGL = pygame.OPENGL
FLAG_RESIZABLE = pygame.RESIZABLE
FLAG_NOFRAME = pygame.NOFRAME



Loading…
Cancel
Save