preparation for new window code

This commit is contained in:
David Rose 2003-01-09 20:31:14 +00:00
parent 5e58604ada
commit fcd3df851a
6 changed files with 68 additions and 5 deletions

View File

@ -94,12 +94,39 @@ class FFIExternalObject:
# % (downcastFuncName, globmod.__name__)) # % (downcastFuncName, globmod.__name__))
downcastFunctionList.append(func) downcastFunctionList.append(func)
return downcastFunctionList 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): def setPointer(self):
# See what type it really is and downcast to that type (if necessary) # 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 # Look up the TypeHandle in the dict. get() returns None if it is not there
index = self.getTypeIndex() index = self.getTypeIndex()
exactWrapperClass = WrapperClassMap.get(index) 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 # We do not need to downcast if we already have the same class
if (exactWrapperClass and (exactWrapperClass != self.__class__)): if (exactWrapperClass and (exactWrapperClass != self.__class__)):
# Create a new wrapper class instance # Create a new wrapper class instance

View File

@ -9,7 +9,7 @@ class OnscreenGeom(PandaObject, NodePath):
hpr = None, hpr = None,
scale = None, scale = None,
color = None, color = None,
parent = aspect2d, parent = None,
sort = 0): sort = 0):
"""__init__(self, ...) """__init__(self, ...)
@ -40,6 +40,8 @@ class OnscreenGeom(PandaObject, NodePath):
""" """
# We ARE a node path. Initially, we're an empty node path. # We ARE a node path. Initially, we're an empty node path.
NodePath.__init__(self) NodePath.__init__(self)
if parent == None:
parent = aspect2d
self.parent = parent self.parent = parent
# Assign geometry # Assign geometry
self.sort = sort self.sort = sort

View File

@ -9,7 +9,7 @@ class OnscreenImage(PandaObject, NodePath):
hpr = None, hpr = None,
scale = None, scale = None,
color = None, color = None,
parent = aspect2d, parent = None,
sort = 0): sort = 0):
"""__init__(self, ...) """__init__(self, ...)
@ -40,6 +40,8 @@ class OnscreenImage(PandaObject, NodePath):
""" """
# We ARE a node path. Initially, we're an empty node path. # We ARE a node path. Initially, we're an empty node path.
NodePath.__init__(self) NodePath.__init__(self)
if parent == None:
parent = aspect2d
# Assign geometry # Assign geometry
if isinstance(image, NodePath): if isinstance(image, NodePath):
self.assign(image.copyTo(parent, sort)) self.assign(image.copyTo(parent, sort))

View File

@ -29,7 +29,7 @@ class OnscreenText(PandaObject, NodePath):
wordwrap = None, wordwrap = None,
drawOrder = None, drawOrder = None,
font = None, font = None,
parent = aspect2d, parent = None,
sort = 0, sort = 0,
mayChange = 0): mayChange = 0):
"""__init__(self, ...) """__init__(self, ...)
@ -90,6 +90,8 @@ class OnscreenText(PandaObject, NodePath):
created (which leads to better memory optimization). created (which leads to better memory optimization).
""" """
if parent == None:
parent = aspect2d
# make a text node # make a text node
textNode = TextNode('') textNode = TextNode('')

View File

@ -1,6 +1,5 @@
from DirectObject import * from DirectObject import *
from PandaModules import * from PandaModules import *
from ShowBaseGlobal import *
class PandaObject(DirectObject): class PandaObject(DirectObject):
""" """

View File

@ -22,11 +22,15 @@ import Loader
import time import time
import FSM import FSM
import State import State
import DirectObject
__builtins__["FADE_SORT_INDEX"] = 1000 __builtins__["FADE_SORT_INDEX"] = 1000
__builtins__["NO_FADE_SORT_INDEX"] = 2000 __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") notify = directNotify.newCategory("ShowBase")
@ -93,6 +97,7 @@ class ShowBase:
# base.win is the main, or only window; base.winList is a list of # base.win is the main, or only window; base.winList is a list of
# *all* windows. Similarly with base.pipeList and base.camList. # *all* windows. Similarly with base.pipeList and base.camList.
self.win = None self.win = None
self.mainWinMinimized = 0
self.winList = [] self.winList = []
self.pipe = None self.pipe = None
self.pipeList = [] self.pipeList = []
@ -154,6 +159,11 @@ class ShowBase:
__builtins__["globalClock"] = ClockObject.getGlobalClock() __builtins__["globalClock"] = ClockObject.getGlobalClock()
__builtins__["vfs"] = vfs __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) # Transition effects (fade, iris, etc)
import Transitions import Transitions
self.transitions = Transitions.Transitions(self.loader) self.transitions = Transitions.Transitions(self.loader)
@ -967,7 +977,28 @@ class ShowBase:
state.frameIndex += 1 state.frameIndex += 1
return Task.cont 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): def run(self):
self.taskMgr.run() self.taskMgr.run()