consolidate setBackgroundColor() to one function

This commit is contained in:
David Rose 2002-07-11 21:04:19 +00:00
parent a52a3be557
commit 539ca403c3
3 changed files with 42 additions and 13 deletions

View File

@ -31,10 +31,6 @@ def getTkColorString(color):
return "#" + r + g + b return "#" + r + g + b
## Background Color ## ## Background Color ##
def setBackgroundColor(r,g,b):
""" Wrapper function to set background color """
base.win.getGsg().setColorClearValue(VBase4(r, g, b, 1.0))
def lerpBackgroundColor(r,g,b,duration): def lerpBackgroundColor(r,g,b,duration):
""" Function to lerp background color to a new value """ """ Function to lerp background color to a new value """
def lerpColor(state): def lerpColor(state):
@ -42,13 +38,13 @@ def lerpBackgroundColor(r,g,b,duration):
state.time += dt state.time += dt
sf = state.time / state.duration sf = state.time / state.duration
if sf >= 1.0: if sf >= 1.0:
setBackgroundColor(state.ec[0], state.ec[1], state.ec[2]) base.setBackgroundColor(state.ec[0], state.ec[1], state.ec[2])
return Task.done return Task.done
else: else:
r = sf * state.ec[0] + (1 - sf) * state.sc[0] r = sf * state.ec[0] + (1 - sf) * state.sc[0]
g = sf * state.ec[1] + (1 - sf) * state.sc[1] g = sf * state.ec[1] + (1 - sf) * state.sc[1]
b = sf * state.ec[2] + (1 - sf) * state.sc[2] b = sf * state.ec[2] + (1 - sf) * state.sc[2]
setBackgroundColor(r,g,b) base.setBackgroundColor(r,g,b)
return Task.cont return Task.cont
taskMgr.remove('lerpBackgroundColor') taskMgr.remove('lerpBackgroundColor')
t = taskMgr.add(lerpColor, 'lerpBackgroundColor') t = taskMgr.add(lerpColor, 'lerpBackgroundColor')

View File

@ -563,6 +563,41 @@ class ShowBase:
self.taskMgr.remove('dataloop') self.taskMgr.remove('dataloop')
self.eventMgr.shutdown() self.eventMgr.shutdown()
def getBackgroundColor(self):
""" Returns the current window background color. This assumes
the window is set up to clear the color each frame (this is
the normal setting). """
# Temporary try .. except for old Pandas.
try:
return VBase4(self.win.getClearColor())
except:
return VBase4(self.win.getGsg().getColorClearValue())
def setBackgroundColor(self, *args):
""" Sets the window background color to the indicated value.
This assumes the window is set up to clear the color each
frame (this is the normal setting).
The color may be either a VBase3 or a VBase4, or a 3-component
tuple, or the individual r, g, b parameters.
"""
numArgs = len(args)
if numArgs == 3 or numArgs == 4:
color = VBase4(args[0], args[1], args[2], 1.0)
elif numArgs == 1:
arg = args[0]
color = VBase4(arg[0], arg[1], arg[2], 1.0)
else:
raise TypeError, ('Invalid number of arguments: %d, expected 1, 3, or 4.' % numArgs)
# Temporary try .. except for old Pandas.
try:
self.win.setClearColor(color)
except:
self.win.getGsg().setColorClearValue(color)
def toggleBackface(self): def toggleBackface(self):
if self.backfaceCullingEnabled: if self.backfaceCullingEnabled:
self.backfaceCullingOff() self.backfaceCullingOff()

View File

@ -707,13 +707,11 @@ class DirectSessionPanel(AppShell):
## ENVIRONMENT CONTROLS ## ## ENVIRONMENT CONTROLS ##
# Background # # Background #
def setBackgroundColor(self, r, g, b): def setBackgroundColor(self, r, g, b):
self.setBackgroundColor(Vec3(r,g,b)) self.setBackgroundColorVec((r, g, b))
def setBackgroundColorVec(self, color): def setBackgroundColorVec(self, color):
base.win.getGsg().setColorClearValue( base.setBackgroundColor(color[0]/255.0,
VBase4(color[0]/255.0,
color[1]/255.0, color[1]/255.0,
color[2]/255.0, color[2]/255.0)
1.0))
def selectDisplayRegionNamed(self, name): def selectDisplayRegionNamed(self, name):
if (string.find(name, 'Display Region ') >= 0): if (string.find(name, 'Display Region ') >= 0):