コード例 #1
0
    def __init__(self,function):

        self.function = function
        
        ZNode.__init__(self,geomnode=card(), magnification=.8)        
        self.np.setColor(1,1,1,1)
                
        Draggable.__init__(self)
        Highlightable.__init__(self)

        # Uncomment to apply a texture to the card.
        #tex = loader.loadTexture('card.png')
        #self.np.setTexture(tex)

        # Now to add the DirectGUI widgets onto the card. A StoryCard has two
        # VBoxes containing DirectGUI objects, one that is shown when the card
        # is far from the viewport and displaying itself in low detail, and one
        # that is shown when the viewport is focused on the card and the card is
        # showing itself in high detail.
        self.lowDetailVBox = VBoxList()
        self.highDetailVBox = VBoxList()
        self.lowDetailVBox.reparentTo(self.np)
        self.highDetailVBox.reparentTo(self.np)

        # The title of the function of this card.
        font = 'storymaps/data/TypeWritersSubstitute-Black.ttf'

        title = DirectLabel(text=self.function.name,
                            text_font=loader.loadFont(font),
                            text_bg=(1,1,1,0),
                            frameColor=(1,1,1,1),
                            scale=.7,
                            suppressMouse=0)
        b = Box()
        b.fill(title)                            
        self.lowDetailVBox.append(b)

        title = DirectLabel(text=self.function.name,
                            text_font=loader.loadFont(font),
                            text_bg=(1,1,1,0),
                            frameColor=(1,1,1,1),
                            scale=.7,
                            suppressMouse=0)
        b = Box()
        b.fill(title)                            
        self.highDetailVBox.append(b)

        # The icon of the function of this card. Use Panda's mipmapping
        # to handle scaling the image efficiently.
        tex = loader.loadTexture(function.image)
        tex.setMagfilter(Texture.FTLinearMipmapLinear)
        tex.setMinfilter(Texture.FTLinearMipmapLinear)

        icon = DirectLabel(image=tex)
        icon.setScale(2.5)
        b = Box()
        b.fill(icon)                            
        self.lowDetailVBox.append(b)

        icon = DirectLabel(image=tex)
        b = Box()
        b.fill(icon)                                    
        self.highDetailVBox.append(b)

        # The longer description of the Propp function.
        self.entry  = DirectEntry(initialText=self.function.desc,
                                 text_font=loader.loadFont('storymaps/data/WritersFont.ttf'),
                                 scale=.4,
                                 width=13,
                                 numLines=7,
                                 suppressMouse=0,
                                 frameColor = (1,1,1,1))
        self.entry['state'] = DGG.DISABLED

        b = Box()
        b.setColor(1,1,1,0)
        b.fill(self.entry)                            
        self.highDetailVBox.append(b)

        self.lowDetailVBox.setPos(self.lowDetailVBox.np,-2.6,0,4)
        self.highDetailVBox.setPos(self.lowDetailVBox.getPos())

        self.highDetailVBox.hide()

        # A place for subclasses to put buttons.
        self.buttons = HBoxList()             
        self.buttons.reparentTo(self.np)   
        self.buttons.setScale(.6)
        self.buttons.setPos(-1.8,0,-1.6)
        self.buttons.hide()

        self.disabled = False
コード例 #2
0
ファイル: boxlist_demo.py プロジェクト: PlumpMath/PandaZUI
    cm = CardMaker('cm')
    cm.setFrame(-.1, .1, -.1, .1)

    def __init__(self):

        ZNode.__init__(self, geomnode=DemoItem.cm.generate())
        Draggable.__init__(self)
        self.set_draggable(True)
        Highlightable.__init__(self)
        self.set_highlightable(True)
        # FIXME. zoomable is required to make highlightable work because of the
        # collision mask. It shouldn't be.
        self.set_zoomable(True)


hbox = HBoxList()
hbox.setPos(-.5, 0, .4)
hbox.reparentTo(zcanvas.home)
for i in range(5):
    b = Box(geomnode=DemoItem.cm.generate())
    hbox.append(b)
    i = DemoItem()
    b.fill(i)

vbox = VBoxList()
vbox.setPos(-.5, 0, .25)
vbox.reparentTo(zcanvas.home)
for i in range(5):
    b = Box(geomnode=DemoItem.cm.generate())
    vbox.append(b)
コード例 #3
0
ファイル: story.py プロジェクト: PlumpMath/PandaZUI
    def __init__(self):

        # Create two story maps, 'Story Cards' which the user picks story cards
        # from, and 'My Story Map' in which the user constructs her story.
        self.storyCards = StoryMap(storyCardClass=FocusableChoosableStoryCard,
                                   title="Story Cards")
        self.storyCards.reparentTo(zcanvas.home)
        self.storyCards.setScale(0.02)
        self.storyCards.setPos(-.5, 0, .8)
        self.storyCards.fill()
        self.storyCards.added_behaviour = 'disable'

        self.myStoryMap = StoryMap(storyCardClass=FocusableEditableStoryCard,
                                   title="My Story")
        self.myStoryMap.reparentTo(zcanvas.home)
        self.myStoryMap.setScale(0.02)
        self.myStoryMap.setPos(-.5, 0, -.1)
        self.myStoryMap.added_behaviour = 'remove'
        #self.myStoryMap.keep_sorted = True
        #self.myStoryMap.np.showTightBounds()
        self.myStoryMap.auto_grow = True

        # Keyboard controls for saving, loading and exporting.
        #base.accept("f1",self.save)
        #base.accept("f2",self.load)
        #base.accept("f3",self.export)

        # Subscribe to some messages.
        self.acceptOnce('zoom done', zcanvas.message,
                        ["Right-click to zoom back out again."])
        self.accept('add', self.add)
        self.accept('remove', self.remove)

        # Frame along the bottom for Save, Load and Quit buttons.
        self.bottom_np = aspect2d.attachNewNode('bottom frame')
        height = 0.15
        self.bottom_np.setPos(-base.getAspectRatio(), 0, -1 - height)
        cm = CardMaker('bottom frame')
        cm.setFrame(0, 2 * base.getAspectRatio(), 0, height)
        self.bottom_np.attachNewNode(cm.generate())
        self.bottom_np.setTransparency(TransparencyAttrib.MAlpha)
        self.bottom_np.setColor(.1, .1, .1, .7)
        self.bottom_hbox = HBoxList(margin=1)
        self.bottom_hbox.reparentTo(self.bottom_np)
        self.bottom_hbox.setPos(0, 0, height - 0.03)
        self.bottom_hbox.setScale(.1)
        self.save_button = DirectButton(text="Save", command=self.save)
        b = Box()
        b.fill(self.save_button)
        self.bottom_hbox.append(b)
        self.load_button = DirectButton(text="Load", command=self.load)
        b = Box()
        b.fill(self.load_button)
        self.bottom_hbox.append(b)
        # Interval that slides the frame onto the screen.
        self.bottom_interval = LerpPosInterval(
            self.bottom_np,
            duration=1,
            pos=Point3(-base.getAspectRatio(), 0, -1),
            startPos=Point3(-base.getAspectRatio(), 0, -1 - height),
            other=None,
            blendType='easeInOut',
            bakeInStart=1,
            fluid=0,
            name=None)
        self.bottom_reverse_interval = LerpPosInterval(
            self.bottom_np,
            duration=1,
            pos=Point3(-base.getAspectRatio(), 0, -1 - height),
            startPos=Point3(-base.getAspectRatio(), 0, -1),
            other=None,
            blendType='easeInOut',
            bakeInStart=1,
            fluid=0,
            name=None)
        self.bottom_frame_is_active = False

        # Frame along the right for story cards.
        self.right_np = aspect2d.attachNewNode('right frame')
        width = 0.14 * base.getAspectRatio()
        self.right_np.setPos(base.getAspectRatio() + width, 0, 1)
        cm = CardMaker('right frame')
        cm.setFrame(-width, 0, -2, 0)
        self.right_np.attachNewNode(cm.generate())
        self.right_np.setTransparency(TransparencyAttrib.MAlpha)
        self.right_np.setColor(.1, .1, .1, .7)
        self.right_vbox = Stack()
        self.right_vbox.reparentTo(self.right_np)
        self.right_vbox.setPos(-width + 0.035, 0, -0.06)
        self.right_vbox.setScale(.02)
        # Interval that slides the frame onto the screen.
        self.right_interval = LerpPosInterval(
            self.right_np,
            duration=1,
            pos=Point3(base.getAspectRatio(), 0, 1),
            startPos=Point3(base.getAspectRatio() + width, 0, 1),
            other=None,
            blendType='easeInOut',
            bakeInStart=1,
            fluid=0,
            name=None)
        self.right_reverse_interval = LerpPosInterval(
            self.right_np,
            duration=1,
            pos=Point3(base.getAspectRatio() + width, 0, 1),
            startPos=Point3(base.getAspectRatio(), 0, 1),
            other=None,
            blendType='easeInOut',
            bakeInStart=1,
            fluid=0,
            name=None)
        self.right_frame_is_active = False

        # Task that watches for the mouse going to the screen edges and slides
        # the frames onscreen when it does.
        self.prev_x = None
        self.prev_y = None
        taskMgr.add(self.task, 'Mediator mouse watcher task')

        NodePathWrapper.__init__(self)
        FocusObserver.__init__(self)