diff --git a/direct/src/directtools/DirectUtil.py b/direct/src/directtools/DirectUtil.py index 228ade7810..b4b14374ff 100644 --- a/direct/src/directtools/DirectUtil.py +++ b/direct/src/directtools/DirectUtil.py @@ -31,10 +31,6 @@ def getTkColorString(color): return "#" + r + g + b ## 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): """ Function to lerp background color to a new value """ def lerpColor(state): @@ -42,13 +38,13 @@ def lerpBackgroundColor(r,g,b,duration): state.time += dt sf = state.time / state.duration 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 else: r = sf * state.ec[0] + (1 - sf) * state.sc[0] g = sf * state.ec[1] + (1 - sf) * state.sc[1] b = sf * state.ec[2] + (1 - sf) * state.sc[2] - setBackgroundColor(r,g,b) + base.setBackgroundColor(r,g,b) return Task.cont taskMgr.remove('lerpBackgroundColor') t = taskMgr.add(lerpColor, 'lerpBackgroundColor') diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 0d1a6b0f01..179d9ad375 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -563,6 +563,41 @@ class ShowBase: self.taskMgr.remove('dataloop') 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): if self.backfaceCullingEnabled: self.backfaceCullingOff() diff --git a/direct/src/tkpanels/DirectSessionPanel.py b/direct/src/tkpanels/DirectSessionPanel.py index 05422cecab..57f0a5c1bd 100644 --- a/direct/src/tkpanels/DirectSessionPanel.py +++ b/direct/src/tkpanels/DirectSessionPanel.py @@ -706,14 +706,12 @@ class DirectSessionPanel(AppShell): ## ENVIRONMENT CONTROLS ## # Background # - def setBackgroundColor(self, r,g,b): - self.setBackgroundColor(Vec3(r,g,b)) + def setBackgroundColor(self, r, g, b): + self.setBackgroundColorVec((r, g, b)) def setBackgroundColorVec(self, color): - base.win.getGsg().setColorClearValue( - VBase4(color[0]/255.0, - color[1]/255.0, - color[2]/255.0, - 1.0)) + base.setBackgroundColor(color[0]/255.0, + color[1]/255.0, + color[2]/255.0) def selectDisplayRegionNamed(self, name): if (string.find(name, 'Display Region ') >= 0):