浏览代码

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

master
Bryan Miller 6 年前
父节点
当前提交
f536e43ab2
共有 2 个文件被更改,包括 24 次插入1 次删除
  1. +3
    -1
      game/__init__.py
  2. +21
    -0
      game/gbe/display.py

+ 3
- 1
game/__init__.py 查看文件

gbe.events.Events.listen("KEYPRESSED", _OnKeyEvent) gbe.events.Events.listen("KEYPRESSED", _OnKeyEvent)
d = gbe.display.Display d = gbe.display.Display
d.init() 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() root = NodeInterface()



+ 21
- 0
game/gbe/display.py 查看文件

''' '''
import pygame import pygame
import weakref import weakref
from .events import Events


class Flag: class Flag:
SWSURFACE = pygame.SWSURFACE SWSURFACE = pygame.SWSURFACE
def opengl(self): def opengl(self):
return Flag.isSet(self._display_flags, Flag.OPENGL) 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): def toggle_fullscreen(self):
if self._isFlagSet(Flag.FULLSCREEN): if self._isFlagSet(Flag.FULLSCREEN):
self._display_flags ^= Flag.FULLSCREEN self._display_flags ^= Flag.FULLSCREEN
self._display_flags |= Flag.FULLSCREEN self._display_flags |= Flag.FULLSCREEN
self.set_mode(self._resolution, flags) 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): def set_mode(self, resolution, flags):
if (self._init == False): if (self._init == False):
self._init = True self._init = True
def close(self): def close(self):
pygame.quit() 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. # Creating an instance of the _Display class. Really, this game engine is only going to use ONE display.
Display=_Display() Display=_Display()



正在加载...
取消
保存