Added UI for color scale property

This commit is contained in:
Gyedo Jeon 2010-01-29 02:44:40 +00:00
parent b4ded0c5fe
commit 4e7076802d
3 changed files with 114 additions and 4 deletions

View File

@ -167,6 +167,7 @@ class ObjectMgr:
return
self.currNodePath = obj[OG.OBJ_NP]
# [gjeon] to connect transform UI with nodepath's transform
self.spawnUpdateObjectUITask()
self.updateObjectPropertyUI(obj)
@ -263,6 +264,13 @@ class ObjectMgr:
np.setSx(float(self.editor.ui.objectPropertyUI.propSX.getValue()))
np.setSy(float(self.editor.ui.objectPropertyUI.propSY.getValue()))
np.setSz(float(self.editor.ui.objectPropertyUI.propSZ.getValue()))
def updateObjectColor(self, r, g, b, a):
if self.currNodePath is None:
return
np = self.currNodePath
np.setColorScale(r, g, b, a)
def updateObjectModel(self, model, obj, fSelectObject=True):
""" replace object's model """
@ -469,6 +477,8 @@ class ObjectMgr:
self.saveData.append(" objects['%s'].setPos(%s)"%(uid, np.getPos()))
self.saveData.append(" objects['%s'].setHpr(%s)"%(uid, np.getHpr()))
self.saveData.append(" objects['%s'].setScale(%s)"%(uid, np.getScale()))
self.saveData.append(" objects['%s'].setTransparency(1)"%uid)
self.saveData.append(" objects['%s'].setColorScale(%s)"%(uid, np.getColorScale()))
self.saveData.append(" objectMgr.updateObjectProperties(objects['%s'], %s)"%(uid,objProp))
self.traverse(child, uid)

View File

@ -5,6 +5,7 @@ import wx
import os
from wx.lib.scrolledpanel import ScrolledPanel
from wx.lib.agw.cubecolourdialog import *
from direct.wxwidgets.WxSlider import *
from pandac.PandaModules import *
import ObjectGlobals as OG
@ -141,10 +142,26 @@ class ObjectPropUICombo(ObjectPropUI):
def getValue(self):
return self.ui.GetStringSelection()
class ColorPicker(CubeColourDialog):
def __init__(self, parent, colourData=None, style=CCD_SHOW_ALPHA, alpha = 255, callback=None):
self.callback=callback
CubeColourDialog.__init__(self, parent, colourData, style)
self.okButton.Hide()
self.cancelButton.Hide()
self._colour.alpha = alpha
self.alphaSpin.SetValue(self._colour.alpha)
self.DrawAlpha()
def SetPanelColours(self):
self.oldColourPanel.RefreshColour(self._oldColour)
self.newColourPanel.RefreshColour(self._colour)
if self.callback:
self.callback(self._colour.r, self._colour.g, self._colour.b, self._colour.alpha)
class ObjectPropertyUI(ScrolledPanel):
def __init__(self, parent, editor):
self.editor = editor
self.colorPicker = None
ScrolledPanel.__init__(self, parent)
parentSizer = wx.BoxSizer(wx.VERTICAL)
@ -161,10 +178,57 @@ class ObjectPropertyUI(ScrolledPanel):
self.SetSizer(None)
self.Layout()
self.SetupScrolling(self, scroll_y = True, rate_y = 20)
def colorPickerCB(self, rr, gg, bb, aa):
r = rr / 255.0
g = gg / 255.0
b = bb / 255.0
a = aa / 255.0
self.propCR.setValue(r)
self.propCG.setValue(g)
self.propCB.setValue(b)
self.propCA.setValue(a)
self.editor.objectMgr.updateObjectColor(r, g, b, a)
def onColorSlider(self, evt):
r = float(self.editor.ui.objectPropertyUI.propCR.getValue())
g = float(self.editor.ui.objectPropertyUI.propCG.getValue())
b = float(self.editor.ui.objectPropertyUI.propCB.getValue())
a = float(self.editor.ui.objectPropertyUI.propCA.getValue())
if self.colorPicker:
evtObj = evt.GetEventObject()
if evtObj == self.propCR.ui or\
evtObj == self.propCR.ui.textValue:
self.colorPicker.redSpin.SetValue(r * 255)
self.colorPicker.AssignColourValue('r', r * 255, 255, 0)
elif evtObj == self.propCG.ui or\
evtObj == self.propCG.ui.textValue:
self.colorPicker.greenSpin.SetValue(g * 255)
self.colorPicker.AssignColourValue('g', g * 255, 255, 0)
elif evtObj == self.propCB.ui or\
evtObj == self.propCB.ui.textValue:
self.colorPicker.blueSpin.SetValue(b * 255)
self.colorPicker.AssignColourValue('b', b * 255, 255, 0)
else:
self.colorPicker._colour.alpha = a * 255
self.colorPicker.alphaSpin.SetValue(self.colorPicker._colour.alpha)
self.colorPicker.DrawAlpha()
self.editor.objectMgr.updateObjectColor(r, g, b, a)
def openColorPicker(self, evt, colourData, alpha):
if self.colorPicker:
self.colorPicker.Destroy()
self.colorPicker = ColorPicker(self, colourData, alpha=alpha, callback=self.colorPickerCB)
self.colorPicker.GetColourData().SetChooseFull(True)
self.colorPicker.Show()
def updateProps(self, obj):
self.clearPropUI()
self.propPane = wx.Panel(self)
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(self.propPane, 1, wx.EXPAND, 0)
@ -186,14 +250,36 @@ class ObjectPropertyUI(ScrolledPanel):
self.propSX, self.propSY, self.propSZ]
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.AddMany([self.propX, self.propY, self.propZ, self.propH, self.propP, self.propR,
self.propSX, self.propSY, self.propSZ])
sizer.AddMany(transformProps)
for transformProp in transformProps:
transformProp.bindFunc(self.editor.objectMgr.onEnterObjectPropUI,
self.editor.objectMgr.onLeaveObjectPropUI,
self.editor.objectMgr.updateObjectTransform)
objNP = obj[OG.OBJ_NP]
objNP.setTransparency(1)
colorScale = objNP.getColorScale()
self.propCR = ObjectPropUISlider(self.propPane, 'CR', colorScale.getX(), 0, 1)
self.propCG = ObjectPropUISlider(self.propPane, 'CG', colorScale.getY(), 0, 1)
self.propCB = ObjectPropUISlider(self.propPane, 'CB', colorScale.getZ(), 0, 1)
self.propCA = ObjectPropUISlider(self.propPane, 'CA', colorScale.getW(), 0, 1)
colorProps = [self.propCR, self.propCG, self.propCB, self.propCA]
for colorProp in colorProps:
colorProp.ui.bindFunc(self.onColorSlider)
sizer.AddMany(colorProps)
button = wx.Button(self.propPane, -1, 'Color Picker', (0,0), (140, 20))
_colourData = wx.ColourData()
_colourData.SetColour(wx.Colour(colorScale.getX() * 255, colorScale.getY() * 255, colorScale.getZ() * 255))
button.Bind(wx.EVT_BUTTON, lambda p0=None, p1=_colourData, p2=colorScale.getW() * 255: self.openColorPicker(p0, p1, p2))
sizer.Add(button)
if self.colorPicker:
self.openColorPicker(None, _colourData, colorScale.getW() * 255)
objDef = obj[OG.OBJ_DEF]
if objDef.model is not None:

View File

@ -15,6 +15,8 @@ if objects['1252538687.73gjeon']:
objects['1252538687.73gjeon'].setPos(Point3(8.66381, 0, 7.13246))
objects['1252538687.73gjeon'].setHpr(VBase3(-180, 0, 0))
objects['1252538687.73gjeon'].setScale(VBase3(1, 1, 1))
objects['1252538687.73gjeon'].setTransparency(1)
objects['1252538687.73gjeon'].setColorScale(VBase4(1, 1, 1, 1))
objectMgr.updateObjectProperties(objects['1252538687.73gjeon'], {'123': 1, 'Abc': 'a', 'Number': 1, 'Happy': True})
objects['1252538690.2gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252538690.2gjeon', None, objects['1252538687.73gjeon'])
@ -22,6 +24,8 @@ if objects['1252538690.2gjeon']:
objects['1252538690.2gjeon'].setPos(Point3(0, 0, 2.12046))
objects['1252538690.2gjeon'].setHpr(VBase3(0, 0, 0))
objects['1252538690.2gjeon'].setScale(VBase3(1, 1, 1))
objects['1252538690.2gjeon'].setTransparency(1)
objects['1252538690.2gjeon'].setColorScale(VBase4(1, 1, 1, 1))
objectMgr.updateObjectProperties(objects['1252538690.2gjeon'], {'Distance': 2.0, 'Abc': 'a'})
objects['1252539696.69gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252539696.69gjeon', None, objects['1252538687.73gjeon'])
@ -29,6 +33,8 @@ if objects['1252539696.69gjeon']:
objects['1252539696.69gjeon'].setPos(Point3(-9.53674e-006, 0, 0))
objects['1252539696.69gjeon'].setHpr(VBase3(0, 0, 0))
objects['1252539696.69gjeon'].setScale(VBase3(1, 1, 1))
objects['1252539696.69gjeon'].setTransparency(1)
objects['1252539696.69gjeon'].setColorScale(VBase4(1, 1, 1, 1))
objectMgr.updateObjectProperties(objects['1252539696.69gjeon'], {'Distance': 2.0, 'Abc': 'a'})
objects['1252539897.22gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252539897.22gjeon', None, objects['1252538687.73gjeon'])
@ -36,6 +42,8 @@ if objects['1252539897.22gjeon']:
objects['1252539897.22gjeon'].setPos(Point3(0.06987, 0, -2.12046))
objects['1252539897.22gjeon'].setHpr(VBase3(0, 0, 0))
objects['1252539897.22gjeon'].setScale(VBase3(1, 1, 1))
objects['1252539897.22gjeon'].setTransparency(1)
objects['1252539897.22gjeon'].setColorScale(VBase4(1, 1, 1, 1))
objectMgr.updateObjectProperties(objects['1252539897.22gjeon'], {'Distance': 2.0, 'Abc': 'a'})
objects['1252538689.13gjeon'] = objectMgr.addNewObject('V Double Smiley', '1252538689.13gjeon', None, objects['1252538687.73gjeon'])
@ -43,6 +51,8 @@ if objects['1252538689.13gjeon']:
objects['1252538689.13gjeon'].setPos(Point3(6.07152, 0, -0.863791))
objects['1252538689.13gjeon'].setHpr(VBase3(0, 0, 0))
objects['1252538689.13gjeon'].setScale(VBase3(1, 1, 1))
objects['1252538689.13gjeon'].setTransparency(1)
objects['1252538689.13gjeon'].setColorScale(VBase4(1, 1, 1, 1))
objectMgr.updateObjectProperties(objects['1252538689.13gjeon'], {'Distance': 1.0, 'Abc': 'a'})
objects['1252539974.19gjeon'] = objectMgr.addNewObject('Smiley', '1252539974.19gjeon', 'models/frowney.egg', objects['1252538689.13gjeon'])
@ -50,6 +60,8 @@ if objects['1252539974.19gjeon']:
objects['1252539974.19gjeon'].setPos(Point3(0.06987, 0, 3.09209))
objects['1252539974.19gjeon'].setHpr(VBase3(0, 0, 0))
objects['1252539974.19gjeon'].setScale(VBase3(1, 1, 1))
objects['1252539974.19gjeon'].setTransparency(1)
objects['1252539974.19gjeon'].setColorScale(VBase4(1, 1, 1, 1))
objectMgr.updateObjectProperties(objects['1252539974.19gjeon'], {'123': 1, 'Abc': 'a', 'Number': 1, 'Happy': True})
objects['1252623762.9gjeon'] = objectMgr.addNewObject('Panda', '1252623762.9gjeon', None, None)
@ -57,6 +69,8 @@ if objects['1252623762.9gjeon']:
objects['1252623762.9gjeon'].setPos(Point3(0, 0, 0))
objects['1252623762.9gjeon'].setHpr(VBase3(172.8, 0, 0))
objects['1252623762.9gjeon'].setScale(VBase3(0.005, 0.005, 0.005))
objects['1252623762.9gjeon'].setTransparency(1)
objects['1252623762.9gjeon'].setColorScale(VBase4(1, 0, 0, 0.57))
objectMgr.updateObjectProperties(objects['1252623762.9gjeon'], {})
if hasattr(base, 'le'):