def finalize(self, dbArgs={}):
        if not self.isDirty():
            return None

        SCObject.finalize(self)
        if hasattr(self, 'button'):
            self.button.destroy()
            del self.button

        halfHeight = self.height / 2.0
        textX = 0
        if dbArgs.has_key('text_align'):
            if dbArgs['text_align'] == TextNode.ACenter:
                textX = self.width / 2.0

        args = {
            'text': self.getDisplayText(),
            'frameColor': (0, 0, 0, 0),
            'rolloverColor': self.getColorScheme().getRolloverColor() + (1, ),
            'pressedColor': self.getColorScheme().getPressedColor() + (1, ),
            'text_font': OTPGlobals.getInterfaceFont(),
            'text_align': TextNode.ALeft,
            'text_fg': self.getColorScheme().getTextColor() + (1, ),
            'text_pos': (textX, -0.25 - halfHeight, 0),
            'relief': DGG.FLAT,
            'pressEffect': 0
        }
        args.update(dbArgs)
        rolloverColor = args['rolloverColor']
        pressedColor = args['pressedColor']
        del args['rolloverColor']
        del args['pressedColor']
        btn = DirectButton(parent=self,
                           frameSize=(0, self.width, -(self.height), 0),
                           **None)
        btn.frameStyle[DGG.BUTTON_ROLLOVER_STATE].setColor(*rolloverColor)
        btn.frameStyle[DGG.BUTTON_DEPRESSED_STATE].setColor(*pressedColor)
        btn.updateFrameStyle()
        btn.bind(DGG.ENTER, self.onMouseEnter)
        btn.bind(DGG.EXIT, self.onMouseLeave)
        btn.bind(DGG.B1PRESS, self.onMouseClick)
        self.button = btn
        self.lastWidth = self.width
        self.lastHeight = self.height
        self.validate()
Exemplo n.º 2
0
 def finalize(self, dbArgs = { }):
     if not self.isDirty():
         return None
     
     SCObject.finalize(self)
     if hasattr(self, 'button'):
         self.button.destroy()
         del self.button
     
     halfHeight = self.height / 2.0
     textX = 0
     if dbArgs.has_key('text_align'):
         if dbArgs['text_align'] == TextNode.ACenter:
             textX = self.width / 2.0
         
     
     args = {
         'text': self.getDisplayText(),
         'frameColor': (0, 0, 0, 0),
         'rolloverColor': self.getColorScheme().getRolloverColor() + (1,),
         'pressedColor': self.getColorScheme().getPressedColor() + (1,),
         'text_font': OTPGlobals.getInterfaceFont(),
         'text_align': TextNode.ALeft,
         'text_fg': self.getColorScheme().getTextColor() + (1,),
         'text_pos': (textX, -0.25 - halfHeight, 0),
         'relief': DGG.FLAT,
         'pressEffect': 0 }
     args.update(dbArgs)
     rolloverColor = args['rolloverColor']
     pressedColor = args['pressedColor']
     del args['rolloverColor']
     del args['pressedColor']
     btn = DirectButton(parent = self, frameSize = (0, self.width, -(self.height), 0), **None)
     btn.frameStyle[DGG.BUTTON_ROLLOVER_STATE].setColor(*rolloverColor)
     btn.frameStyle[DGG.BUTTON_DEPRESSED_STATE].setColor(*pressedColor)
     btn.updateFrameStyle()
     btn.bind(DGG.ENTER, self.onMouseEnter)
     btn.bind(DGG.EXIT, self.onMouseLeave)
     btn.bind(DGG.B1PRESS, self.onMouseClick)
     self.button = btn
     self.lastWidth = self.width
     self.lastHeight = self.height
     self.validate()
Exemplo n.º 3
0
Arquivo: SCMenu.py Projeto: nate97/src
    def finalize(self):
        if not self.isDirty():
            return
        self.inFinalize = 1
        SCObject.finalize(self)
        visibleMembers = []
        for member in self:
            if member.isViewable():
                visibleMembers.append(member)
                member.reparentTo(self)
            else:
                member.reparentTo(hidden)
                if self.activeMember is member:
                    self.__setActiveMember(None)

        maxWidth = 0.0
        maxHeight = 0.0
        for member in visibleMembers:
            width, height = member.getMinDimensions()
            maxWidth = max(maxWidth, width)
            maxHeight = max(maxHeight, height)

        holder = self.getHolder()
        if holder is not None:
            widthToCover = holder.getMinSubmenuWidth()
            maxWidth = max(maxWidth, widthToCover)
        memberWidth, memberHeight = maxWidth, maxHeight
        self.width = maxWidth
        for i in xrange(len(visibleMembers)):
            member = visibleMembers[i]
            member.setPos(0, 0, -i * maxHeight)
            member.setDimensions(memberWidth, memberHeight)
            member.finalize()

        if len(visibleMembers) > 0:
            z1 = visibleMembers[0].getZ(aspect2d)
            visibleMembers[0].setZ(-maxHeight)
            z2 = visibleMembers[0].getZ(aspect2d)
            visibleMembers[0].setZ(0)
            actualHeight = (z2 - z1) * len(visibleMembers)
            bottomZ = self.getZ(aspect2d) + actualHeight
            if bottomZ < -1.0:
                overlap = bottomZ - -1.0
                self.setZ(aspect2d, self.getZ(aspect2d) - overlap)
            if self.getZ(aspect2d) > 1.0:
                self.setZ(aspect2d, 1.0)
        sX = memberWidth
        sZ = memberHeight * len(visibleMembers)
        self.bgMiddle.setScale(sX, 1, sZ)
        self.bgTop.setScale(sX, 1, 1)
        self.bgBottom.setScale(sX, 1, 1)
        self.bgLeft.setScale(1, 1, sZ)
        self.bgRight.setScale(1, 1, sZ)
        self.bgBottomLeft.setZ(-sZ)
        self.bgBottom.setZ(-sZ)
        self.bgTopRight.setX(sX)
        self.bgRight.setX(sX)
        self.bgBottomRight.setX(sX)
        self.bgBottomRight.setZ(-sZ)
        sB = 0.15
        self.bgTopLeft.setSx(aspect2d, sB)
        self.bgTopLeft.setSz(aspect2d, sB)
        self.bgBottomRight.setSx(aspect2d, sB)
        self.bgBottomRight.setSz(aspect2d, sB)
        self.bgBottomLeft.setSx(aspect2d, sB)
        self.bgBottomLeft.setSz(aspect2d, sB)
        self.bgTopRight.setSx(aspect2d, sB)
        self.bgTopRight.setSz(aspect2d, sB)
        self.bgTop.setSz(aspect2d, sB)
        self.bgBottom.setSz(aspect2d, sB)
        self.bgLeft.setSx(aspect2d, sB)
        self.bgRight.setSx(aspect2d, sB)
        r, g, b = self.getColorScheme().getFrameColor()
        a = self.getColorScheme().getAlpha()
        self.bg.setColorScale(r, g, b, a)
        if self.activeMember is not None:
            self.activeMember.reparentTo(self)
        self.validate()
        self.inFinalize = 0
        return
Exemplo n.º 4
0
    def finalize(self):
        if not self.isDirty():
            return
        self.inFinalize = 1
        SCObject.finalize(self)
        visibleMembers = []
        for member in self:
            if member.isViewable():
                visibleMembers.append(member)
                member.reparentTo(self)
            else:
                member.reparentTo(hidden)
                if self.activeMember is member:
                    self.__setActiveMember(None)

        maxWidth = 0.0
        maxHeight = 0.0
        for member in visibleMembers:
            width, height = member.getMinDimensions()
            maxWidth = max(maxWidth, width)
            maxHeight = max(maxHeight, height)

        holder = self.getHolder()
        if holder is not None:
            widthToCover = holder.getMinSubmenuWidth()
            maxWidth = max(maxWidth, widthToCover)
        memberWidth, memberHeight = maxWidth, maxHeight
        self.width = maxWidth
        for i in xrange(len(visibleMembers)):
            member = visibleMembers[i]
            member.setPos(0, 0, -i * maxHeight)
            member.setDimensions(memberWidth, memberHeight)
            member.finalize()

        if len(visibleMembers) > 0:
            z1 = visibleMembers[0].getZ(aspect2d)
            visibleMembers[0].setZ(-maxHeight)
            z2 = visibleMembers[0].getZ(aspect2d)
            visibleMembers[0].setZ(0)
            actualHeight = (z2 - z1) * len(visibleMembers)
            bottomZ = self.getZ(aspect2d) + actualHeight
            if bottomZ < -1.0:
                overlap = bottomZ - -1.0
                self.setZ(aspect2d, self.getZ(aspect2d) - overlap)
            if self.getZ(aspect2d) > 1.0:
                self.setZ(aspect2d, 1.0)
        sX = memberWidth
        sZ = memberHeight * len(visibleMembers)
        self.bgMiddle.setScale(sX, 1, sZ)
        self.bgTop.setScale(sX, 1, 1)
        self.bgBottom.setScale(sX, 1, 1)
        self.bgLeft.setScale(1, 1, sZ)
        self.bgRight.setScale(1, 1, sZ)
        self.bgBottomLeft.setZ(-sZ)
        self.bgBottom.setZ(-sZ)
        self.bgTopRight.setX(sX)
        self.bgRight.setX(sX)
        self.bgBottomRight.setX(sX)
        self.bgBottomRight.setZ(-sZ)
        sB = 0.15
        self.bgTopLeft.setSx(aspect2d, sB)
        self.bgTopLeft.setSz(aspect2d, sB)
        self.bgBottomRight.setSx(aspect2d, sB)
        self.bgBottomRight.setSz(aspect2d, sB)
        self.bgBottomLeft.setSx(aspect2d, sB)
        self.bgBottomLeft.setSz(aspect2d, sB)
        self.bgTopRight.setSx(aspect2d, sB)
        self.bgTopRight.setSz(aspect2d, sB)
        self.bgTop.setSz(aspect2d, sB)
        self.bgBottom.setSz(aspect2d, sB)
        self.bgLeft.setSx(aspect2d, sB)
        self.bgRight.setSx(aspect2d, sB)
        r, g, b = self.getColorScheme().getFrameColor()
        a = self.getColorScheme().getAlpha()
        self.bg.setColorScale(r, g, b, a)
        if self.activeMember is not None:
            self.activeMember.reparentTo(self)
        self.validate()
        self.inFinalize = 0
        return
Exemplo n.º 5
0
    def finalize(self, dbArgs={}):
        """ 'dbArgs' can contain parameters (and parameter overrides) for
        the DirectButton.
        """
        if not self.isDirty():
            return
        
        SCObject.finalize(self)
        
        if hasattr(self, 'button'):
            self.button.destroy()
            del self.button

        halfHeight = self.height/2.

        # if we're given a 'center' value for the text alignment,
        # calculate the appropriate text X position
        textX = 0
        if dbArgs.has_key('text_align'):
            if dbArgs['text_align'] == TextNode.ACenter:
                textX = self.width/2.

        args = {
            'text': self.getDisplayText(),
            'frameColor': (0,0,0,0),
            'rolloverColor': self.getColorScheme().getRolloverColor()+(1,),
            'pressedColor': self.getColorScheme().getPressedColor()+(1,),
            'text_font': OTPGlobals.getInterfaceFont(),
            'text_align': TextNode.ALeft,
            'text_fg': self.getColorScheme().getTextColor()+(1,),
            'text_pos': (textX,-.25-halfHeight,0),
            'relief': DGG.FLAT,
            # disable the 'press effect' (slight scale-down)
            'pressEffect': 0,
            }
        # add external parameters and apply any overrides
        args.update(dbArgs)

        # these can't be passed directly to DirectButton
        rolloverColor = args['rolloverColor']
        pressedColor = args['pressedColor']
        del args['rolloverColor']
        del args['pressedColor']

        """
        from direct.gui.DirectGui import *;import OTPGlobals;
        btn.destroy();w=3;h=2;btn = DirectButton(parent=aspect2d,frameSize=(0,w,-h,0),text='TEST',frameColor=(.8,.8,1,1),text_font=OTPGlobals.getInterfaceFont(),text_align=TextNode.ALeft,text_fg=(0,0,0,1),text_pos=(0,-.25-(h/2.),0),image=('phase_3/models/props/page-arrow', 'poly'),image_pos=(w*.9,0,-h/2.),state=DGG.NORMAL,relief=DGG.RAISED);btn.setPos(-.5,0,0);btn.setScale(.5)"""

        btn = DirectButton(
            parent = self,
            frameSize = (0,self.width,
                         -self.height,0),
            # this doesn't trigger until mouse-up. We want to trigger
            # on mouse-down; see the 'bind' calls below
            #command = self.onMouseClick,
            **args
            )

        # Set frame color for rollover and pressed states
        btn.frameStyle[DGG.BUTTON_ROLLOVER_STATE].setColor(*rolloverColor)
        btn.frameStyle[DGG.BUTTON_DEPRESSED_STATE].setColor(*pressedColor)
        btn.updateFrameStyle()

        # listen for input events
        btn.bind(DGG.ENTER,   self.onMouseEnter)
        btn.bind(DGG.EXIT,    self.onMouseLeave)
        btn.bind(DGG.B1PRESS, self.onMouseClick)
        self.button = btn

        # store the new display params
        self.lastWidth  = self.width
        self.lastHeight = self.height

        self.validate()
Exemplo n.º 6
0
    def finalize(self):
        if not self.isDirty():
            return

        self.inFinalize = 1

        SCObject.finalize(self)

        if __debug__:
            # make sure all of our members know that we are their parent menu
            # (who's yo daddy?)
            for member in self:
                assert member.getParentMenu() is self

        # we aren't interested in members that aren't viewable.
        # build a list of viewable members. Also parent viewable
        # members to us, parent non-viewable members to hidden.
        visibleMembers = []
        for member in self:
            if member.isViewable():
                visibleMembers.append(member)
                member.reparentTo(self)
            else:
                member.reparentTo(hidden)
                # if this is the active member, deactivate it
                if self.activeMember is member:
                    self.__setActiveMember(None)

        # survey the members to find out their ideal dimensions, and
        # determine the maximum dimensions
        maxWidth = 0.
        maxHeight = 0.
        for member in visibleMembers:
            width,height = member.getMinDimensions()
            maxWidth = max(maxWidth, width)
            maxHeight = max(maxHeight, height)

        # make sure that we cover our parent menu all the way out past its
        # right edge
        holder = self.getHolder()
        if holder is not None:
            # how wide do we need to be to cover our parent menu?
            widthToCover = holder.getMinSubmenuWidth()
            maxWidth = max(maxWidth, widthToCover)

        # all of the menu members will be at least as big as the biggest
        # member, in each dimension
        memberWidth, memberHeight = maxWidth, maxHeight
        # Store this so that we can do horizonal centering
        self.width = maxWidth

        # put the members in the right place, and tell them what size
        # they should be
        for i in xrange(len(visibleMembers)):
            member = visibleMembers[i]
            member.setPos(0,0,-i * maxHeight)
            member.setDimensions(memberWidth, memberHeight)
            member.finalize()

        if len(visibleMembers) > 0:
            z1 = visibleMembers[0].getZ(aspect2d)
            visibleMembers[0].setZ(-maxHeight)
            z2 = visibleMembers[0].getZ(aspect2d)
            visibleMembers[0].setZ(0)

            actualHeight = (z2-z1) * len(visibleMembers)

            # keep the menu from going off the bottom of the screen
            bottomZ = self.getZ(aspect2d) + actualHeight
            if bottomZ < -1.:
                overlap = bottomZ - (-1.)
                self.setZ(aspect2d, self.getZ(aspect2d) - overlap)
            # keep the menu from going off the top of the screen
            if self.getZ(aspect2d) > 1.:
                self.setZ(aspect2d, 1.)
        
        # set up the background frame
        sX = memberWidth
        sZ = memberHeight * len(visibleMembers)
        self.bgMiddle.setScale(sX,1,sZ)
        self.bgTop.setScale(sX,1,1)
        self.bgBottom.setScale(sX,1,1)
        self.bgLeft.setScale(1,1,sZ)
        self.bgRight.setScale(1,1,sZ)
        self.bgBottomLeft.setZ(-sZ)
        self.bgBottom.setZ(-sZ)
        self.bgTopRight.setX(sX)
        self.bgRight.setX(sX)
        self.bgBottomRight.setX(sX)
        self.bgBottomRight.setZ(-sZ)
        # scale the border wrt aspect2d
        # note: changing the Y-scale from literal '1' wrt parent
        # is not necessary and was causing visibility problems
        sB = .15
        self.bgTopLeft.setSx(aspect2d, sB)
        self.bgTopLeft.setSz(aspect2d, sB)
        self.bgBottomRight.setSx(aspect2d, sB)
        self.bgBottomRight.setSz(aspect2d, sB)
        self.bgBottomLeft.setSx(aspect2d, sB)
        self.bgBottomLeft.setSz(aspect2d, sB)
        self.bgTopRight.setSx(aspect2d, sB)
        self.bgTopRight.setSz(aspect2d, sB)
        self.bgTop.setSz(aspect2d, sB)
        self.bgBottom.setSz(aspect2d, sB)
        self.bgLeft.setSx(aspect2d, sB)
        self.bgRight.setSx(aspect2d, sB)

        r,g,b = self.getColorScheme().getFrameColor()
        a = self.getColorScheme().getAlpha()
        self.bg.setColorScale(r,g,b,a)

        # if we have an active member, reparent it to us, so that
        # it and its children show up over the rest of the menu elements
        if self.activeMember is not None:
            self.activeMember.reparentTo(self)

        self.validate()

        self.inFinalize = 0