Parcourir la source

gbe/display now has a caption as well as a setting to self watch for video resize.

master
Bryan Miller il y a 6 ans
Parent
révision
f536e43ab2
2 fichiers modifiés avec 24 ajouts et 1 suppressions
  1. +3
    -1
      game/__init__.py
  2. +21
    -0
      game/gbe/display.py

+ 3
- 1
game/__init__.py Voir le fichier

@@ -32,7 +32,9 @@ def start():
gbe.events.Events.listen("KEYPRESSED", _OnKeyEvent)
d = gbe.display.Display
d.init()
gbe.events.Events.listen("VIDEORESIZE", _OnVideoResize)
d.caption = "Goldbox 64"
d.watch_for_resize(True)
#gbe.events.Events.listen("VIDEORESIZE", _OnVideoResize)

root = NodeInterface()


+ 21
- 0
game/gbe/display.py Voir le fichier

@@ -6,6 +6,7 @@
'''
import pygame
import weakref
from .events import Events

class Flag:
SWSURFACE = pygame.SWSURFACE
@@ -74,6 +75,15 @@ class _Display:
def opengl(self):
return Flag.isSet(self._display_flags, Flag.OPENGL)

@property
def caption(self):
if pygame.display.get_init():
return pygame.display.get_caption()
@caption.setter
def caption(self, caption):
if pygame.display.get_init():
pygame.display.set_caption(caption)

def toggle_fullscreen(self):
if self._isFlagSet(Flag.FULLSCREEN):
self._display_flags ^= Flag.FULLSCREEN
@@ -81,6 +91,12 @@ class _Display:
self._display_flags |= Flag.FULLSCREEN
self.set_mode(self._resolution, flags)

def watch_for_resize(self, enable):
if enable == True:
Events.listen("VIDEORESIZE", self._OnVideoResize)
elif enable == False:
Events.unlisten("VIDEORESIZE", self._OnVideoResize)

def set_mode(self, resolution, flags):
if (self._init == False):
self._init = True
@@ -104,6 +120,11 @@ class _Display:
def close(self):
pygame.quit()


def _OnVideoResize(self, event, data):
self.set_mode(data["size"], self.flags)
print("Resized to {}".format(self.resolution))

# Creating an instance of the _Display class. Really, this game engine is only going to use ONE display.
Display=_Display()


Chargement…
Annuler
Enregistrer