mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
preparation for new window code
This commit is contained in:
parent
5e58604ada
commit
fcd3df851a
@ -95,11 +95,38 @@ class FFIExternalObject:
|
||||
downcastFunctionList.append(func)
|
||||
return downcastFunctionList
|
||||
|
||||
def lookUpNewType(self, typeHandle, rootType):
|
||||
# We tried to downcast to an unknown type. Try to figure out
|
||||
# the lowest type we *do* know, so we can downcast to that
|
||||
# type instead.
|
||||
if typeHandle.getNumParentClasses() == 0:
|
||||
# This type has no parents! That shouldn't happen.
|
||||
FFIConstants.notify.warning("Unknown class type: %s has no parents!" % (typeHandle.getName()))
|
||||
return None
|
||||
|
||||
parentType = typeHandle.getParentTowards(rootType, self)
|
||||
parentIndex = parentType.getIndex()
|
||||
parentWrapperClass = WrapperClassMap.get(parentIndex)
|
||||
if parentWrapperClass == None:
|
||||
parentWrapperClass = self.lookUpNewType(parentType, rootType)
|
||||
|
||||
if parentWrapperClass != None:
|
||||
# If the parent class is known, then record that this
|
||||
# class is a derivation of that parent class.
|
||||
WrapperClassMap[typeHandle.getIndex()] = parentWrapperClass
|
||||
|
||||
return parentWrapperClass
|
||||
|
||||
def setPointer(self):
|
||||
# See what type it really is and downcast to that type (if necessary)
|
||||
# Look up the TypeHandle in the dict. get() returns None if it is not there
|
||||
index = self.getTypeIndex()
|
||||
exactWrapperClass = WrapperClassMap.get(index)
|
||||
if exactWrapperClass == None:
|
||||
# This is an unknown class type. Perhaps it derives from
|
||||
# a class type we know.
|
||||
exactWrapperClass = self.lookUpNewType(self.getType(), self.getClassType())
|
||||
|
||||
# We do not need to downcast if we already have the same class
|
||||
if (exactWrapperClass and (exactWrapperClass != self.__class__)):
|
||||
# Create a new wrapper class instance
|
||||
|
@ -9,7 +9,7 @@ class OnscreenGeom(PandaObject, NodePath):
|
||||
hpr = None,
|
||||
scale = None,
|
||||
color = None,
|
||||
parent = aspect2d,
|
||||
parent = None,
|
||||
sort = 0):
|
||||
"""__init__(self, ...)
|
||||
|
||||
@ -40,6 +40,8 @@ class OnscreenGeom(PandaObject, NodePath):
|
||||
"""
|
||||
# We ARE a node path. Initially, we're an empty node path.
|
||||
NodePath.__init__(self)
|
||||
if parent == None:
|
||||
parent = aspect2d
|
||||
self.parent = parent
|
||||
# Assign geometry
|
||||
self.sort = sort
|
||||
|
@ -9,7 +9,7 @@ class OnscreenImage(PandaObject, NodePath):
|
||||
hpr = None,
|
||||
scale = None,
|
||||
color = None,
|
||||
parent = aspect2d,
|
||||
parent = None,
|
||||
sort = 0):
|
||||
"""__init__(self, ...)
|
||||
|
||||
@ -40,6 +40,8 @@ class OnscreenImage(PandaObject, NodePath):
|
||||
"""
|
||||
# We ARE a node path. Initially, we're an empty node path.
|
||||
NodePath.__init__(self)
|
||||
if parent == None:
|
||||
parent = aspect2d
|
||||
# Assign geometry
|
||||
if isinstance(image, NodePath):
|
||||
self.assign(image.copyTo(parent, sort))
|
||||
|
@ -29,7 +29,7 @@ class OnscreenText(PandaObject, NodePath):
|
||||
wordwrap = None,
|
||||
drawOrder = None,
|
||||
font = None,
|
||||
parent = aspect2d,
|
||||
parent = None,
|
||||
sort = 0,
|
||||
mayChange = 0):
|
||||
"""__init__(self, ...)
|
||||
@ -90,6 +90,8 @@ class OnscreenText(PandaObject, NodePath):
|
||||
created (which leads to better memory optimization).
|
||||
|
||||
"""
|
||||
if parent == None:
|
||||
parent = aspect2d
|
||||
|
||||
# make a text node
|
||||
textNode = TextNode('')
|
||||
|
@ -1,6 +1,5 @@
|
||||
from DirectObject import *
|
||||
from PandaModules import *
|
||||
from ShowBaseGlobal import *
|
||||
|
||||
class PandaObject(DirectObject):
|
||||
"""
|
||||
|
@ -22,11 +22,15 @@ import Loader
|
||||
import time
|
||||
import FSM
|
||||
import State
|
||||
import DirectObject
|
||||
|
||||
__builtins__["FADE_SORT_INDEX"] = 1000
|
||||
__builtins__["NO_FADE_SORT_INDEX"] = 2000
|
||||
|
||||
class ShowBase:
|
||||
# Now ShowBase is a DirectObject. We need this so ShowBase can hang
|
||||
# hooks on messages, particularly on window-event. This doesn't
|
||||
# *seem* to cause anyone any problems.
|
||||
class ShowBase(DirectObject.DirectObject):
|
||||
|
||||
notify = directNotify.newCategory("ShowBase")
|
||||
|
||||
@ -93,6 +97,7 @@ class ShowBase:
|
||||
# base.win is the main, or only window; base.winList is a list of
|
||||
# *all* windows. Similarly with base.pipeList and base.camList.
|
||||
self.win = None
|
||||
self.mainWinMinimized = 0
|
||||
self.winList = []
|
||||
self.pipe = None
|
||||
self.pipeList = []
|
||||
@ -154,6 +159,11 @@ class ShowBase:
|
||||
__builtins__["globalClock"] = ClockObject.getGlobalClock()
|
||||
__builtins__["vfs"] = vfs
|
||||
|
||||
# Now hang a hook on the window-event from Panda. This allows
|
||||
# us to detect when the user resizes, minimizes, or closes the
|
||||
# main window.
|
||||
self.accept('window-event', self.__windowEvent)
|
||||
|
||||
# Transition effects (fade, iris, etc)
|
||||
import Transitions
|
||||
self.transitions = Transitions.Transitions(self.loader)
|
||||
@ -967,7 +977,28 @@ class ShowBase:
|
||||
state.frameIndex += 1
|
||||
return Task.cont
|
||||
|
||||
def __windowEvent(self, win):
|
||||
properties = win.getProperties()
|
||||
if win == self.win:
|
||||
if not properties.getOpen():
|
||||
# If the user closes the main window, we should exit.
|
||||
self.notify.info("User closed main window, exiting.")
|
||||
sys.exit()
|
||||
|
||||
if properties.getMinimized() and not self.mainWinMinimized:
|
||||
# If the main window is minimized, throw an event to
|
||||
# stop the music.
|
||||
self.mainWinMinimized = 1
|
||||
messenger.send('PandaPaused')
|
||||
|
||||
elif not properties.getMinimized() and self.mainWinMinimized:
|
||||
# If the main window is restored, throw an event to
|
||||
# restart the music.
|
||||
self.mainWinMinimized = 0
|
||||
messenger.send('PandaRestarted')
|
||||
|
||||
|
||||
def run(self):
|
||||
self.taskMgr.run()
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user