示例#1
0
文件: ui.py 项目: DKGL/DKDemo
    def layout(self):
        super().layout()

        bounds = self.bounds()
        if not self.menuBar.isLoaded():
            self.menuBar.load(self.screen())
        menuBarSize = self.menuBar.calculateFrameSize()
        self.menuBar.frame = dk.Rect(0, bounds.height - menuBarSize.height,
                                     bounds.width, menuBarSize.height)

        y = self.menuBar.frame.y - 80
        self.button1.frame = dk.Rect(10, y, 100, 60)
        self.button2.frame = dk.Rect(140, y, 100, 60)

        self.checkbox1.frame = dk.Rect(260, y + 30, 220, 30)
        self.checkbox2.frame = dk.Rect(260, y, 220, 30)

        y -= 10
        for btn in (self.radio1, self.radio2, self.radio3):
            y -= 28
            btn.frame = dk.Rect(20, y, 160, 28)

        y -= 240
        self.treeView.frame = dk.Rect(10, y, 200, 230)

        y = self.checkbox2.frame.y - 80
        self.textField.frame = dk.Rect(240, y, 200, 30)

        y -= 230
        self.progressView.frame = dk.Rect(240, y, 200, 200)
示例#2
0
文件: anim.py 项目: DKGL/DKDemo
    def layout(self):
        super().layout()
        bounds = self.bounds()
        if not self.menuBar.isLoaded():
            self.menuBar.load(self.screen())
        menuBarSize = self.menuBar.calculateFrameSize()
        self.menuBar.frame = dk.Rect(
            0,
            bounds.height - menuBarSize.height,
            # menuBarSize.width,
            bounds.width,
            menuBarSize.height)

        self.infoLabel.frame = dk.Rect(0, 0, bounds.width, 50)

        self.updatePerspective()
示例#3
0
    def onLoaded(self):
        super().onLoaded()
        items = [
            (kine.Frame, 'Kinematic Animation'),
            (sprite.Frame, '2D Sprites, Texture Atlas'),
            (ui.Frame, 'UI Widgets'),
            (vehicle.Frame, 'Vehicle'),
            (shadow.Frame, 'Shadow Mapping'),
            (anim.Frame, 'Character Animation'),
        ]

        btnFontAttr = dk.ui.font.attributes(16, outline=2)

        self.buttons = []
        btnY = 10
        for itemClass, itemText in items:
            btn = dk.ui.Button(itemText, frame=dk.Rect(0, 0, 160, 60))
            btn.demoClass = itemClass
            btn.addTarget(self, self.openDemo)
            btn.fontAttributes = btnFontAttr
            self.addChild(btn)
            self.buttons.append(btn)

        self.demoFrame = None

        self.infoButton = dk.ui.Button('Info', frame=dk.Rect(0, 0, 80, 40))
        self.infoButton.fontAttributes = btnFontAttr
        self.infoButton.setTextColor(dk.Color(1, 1, 1, 1))
        self.infoButton.setOutlineColor(dk.Color(0.25, 0, 0, 1))
        self.infoButton.backgroundColor = dk.Color(1, 0, 0, 0.75)
        self.infoButton.backgroundColorHighlighted = dk.Color(1, 0.5, 0.5)
        self.infoButton.backgroundColorActivated = dk.Color(0.8, 0, 0)
        self.infoButton.addTarget(self, self.showInfoView)
        self.addChild(self.infoButton)

        self.closeButton = dk.ui.Button('Close', frame=dk.Rect(0, 0, 80, 40))
        self.closeButton.fontAttributes = btnFontAttr
        self.closeButton.setTextColor(dk.Color(1, 1, 1, 1))
        self.closeButton.setOutlineColor(dk.Color(0.25, 0, 0, 1))
        self.closeButton.backgroundColor = dk.Color(1, 0, 0, 0.75)
        self.closeButton.backgroundColorHighlighted = dk.Color(1, 0.5, 0.5)
        self.closeButton.backgroundColorActivated = dk.Color(0.8, 0, 0)
        self.closeButton.addTarget(self, self.closeDemo)
        self.addChild(self.closeButton)

        self.screen().postOperation(self.runGC, ())
示例#4
0
    def layout(self):
        super().layout()
        self.updatePerspective()

        if self.infoLabel.font:
            width = self.contentResolution[0]
            height = self.infoLabel.font.lineHeight()
            frame = self.convertPixelToLocal(dk.Rect(0, 0, width, height+15))
            self.infoLabel.frame = frame
示例#5
0
    def showInfoView(self, *args):
        pool = dk.ResourcePool()
        pool.addSearchPath(dk.appInstance().resourceDir)

        class InfoView(dk.ui.TitledView):
            def onLoaded(self):
                super().onLoaded()
                labels = [
                    dk.ui.Label('DK Game Library'),
                    dk.ui.Label('This is DKLib demo sample.'),
                    dk.ui.Label('DK is written with C++.'),
                    dk.ui.Label('You can use python script with PyDK.'),
                    dk.ui.Label('This app content written with python.'),
                    dk.ui.Label('All contents are located in Scripts folder.'),
                    dk.ui.Label('Author: Hongtae Kim, [email protected]'),
                ]
                # font = dk.ui.font.attributes(12, file='SeoulNamsanM.ttf')
                font = dk.ui.font.attributes(12, file='NanumGothic.ttf')
                w, h, y = 300, 24, 260
                for la in labels:
                    y -= h
                    la.fontAttributes = font
                    la.frame = dk.Rect(0, y, w, h)
                    self.addChild(la)

        def dismiss(*a):
            dk.ui.Modal.modalForView(self).dismiss(99)

        def openSiteURL(*a):
            import webbrowser
            webbrowser.open('http://github.com/tiff2766/DKLib')

        infoView = InfoView(caption='About DKDemo',
                            frame=dk.Rect(0, 0, 300, 300))
        btn1 = dk.ui.Button('Dismiss', frame=dk.Rect(10, 10, 100, 40))
        btn1.addTarget(self, dismiss)
        infoView.addChild(btn1)

        btn2 = dk.ui.Button('GitHub', frame=dk.Rect(190, 10, 100, 40))
        btn2.addTarget(self, openSiteURL)
        infoView.addChild(btn2)

        modal = dk.ui.Modal(infoView)
        modal.present(self)
示例#6
0
    def layout(self):
        super().layout()

        if self.demoFrame:
            if isinstance(self.demoFrame, dk.ui.View):
                self.demoFrame.frame = self.contentBounds()
            else:
                t = dk.LinearTransform2()
                t.scale(self.contentScale)
                self.demoFrame.transform = dk.AffineTransform2(t).matrix3()

        btnSize = (100, 50)
        padding = 5
        width, height = self.contentScale
        x = width - btnSize[0] - padding
        self.closeButton.frame = dk.Rect(x, padding, *btnSize)
        x = x - btnSize[0] - padding
        self.infoButton.frame = dk.Rect(x, padding, *btnSize)

        columns = 3
        leftMargin, rightMargin, topMargin, bottomMargin = 40, 40, 80, 140
        padding = 10
        rect = self.bounds()
        rect.origin = dk.Point(rect.origin) + dk.Point(leftMargin,
                                                       bottomMargin)
        rect.size = dk.Size(rect.size) - dk.Size(leftMargin + rightMargin,
                                                 bottomMargin + topMargin)
        from math import ceil
        rows = ceil(len(self.buttons) / columns)

        btnSize = int((rect.width - padding * (columns - 1)) / columns), int(
            (rect.height - padding * (rows - 1)) / rows)
        index = 0
        for btn in self.buttons:
            x = int(index % columns)
            y = int(index / columns)
            rc = dk.Rect()
            rc.origin = dk.Point(x * (btnSize[0] + padding),
                                 y * (btnSize[1] + padding)) + rect.origin
            rc.size = btnSize
            btn.frame = rc
            index += 1
示例#7
0
 def onLoaded(self):
     super().onLoaded()
     labels = [
         dk.ui.Label('DK Game Library'),
         dk.ui.Label('This is DKLib demo sample.'),
         dk.ui.Label('DK is written with C++.'),
         dk.ui.Label('You can use python script with PyDK.'),
         dk.ui.Label('This app content written with python.'),
         dk.ui.Label('All contents are located in Scripts folder.'),
         dk.ui.Label('Author: Hongtae Kim, [email protected]'),
     ]
     # font = dk.ui.font.attributes(12, file='SeoulNamsanM.ttf')
     font = dk.ui.font.attributes(12, file='NanumGothic.ttf')
     w, h, y = 300, 24, 260
     for la in labels:
         y -= h
         la.fontAttributes = font
         la.frame = dk.Rect(0, y, w, h)
         self.addChild(la)
示例#8
0
文件: vehicle.py 项目: DKGL/DKDemo
    def layout(self):
        super().layout()
        self.updatePerspective()
        bounds = self.bounds()
        self.brakeButton.frame = dk.Rect(20, 80, 80, 80)
        self.accelButton.frame = dk.Rect(120, 80, 80, 80)
        self.steerSlider.frame = dk.Rect(bounds.width - 240, 80, 240, 80)

        self.cameraButton.frame = dk.Rect(10, bounds.height - 50, 140, 40)

        self.helpText.frame = dk.Rect(160, bounds.height - 50,
                                      bounds.width - 170, 40)

        if self.infoLabel.font:
            width = self.contentResolution[0]
            height = self.infoLabel.font.lineHeight()
            frame = self.convertPixelToLocal(dk.Rect(0, 0, width, height + 15))
            self.infoLabel.frame = frame
示例#9
0
    def onLoaded(self):
        super().onLoaded()

        bounds = self.bounds()

        # slider for light direction
        sliderX = dk.ui.Slider(0, range=(-1.5, 1.5), frame=dk.Rect(0, 100, 200, 40))
        sliderZ = dk.ui.Slider(0, range=(-1.5, 1.5), frame=dk.Rect(0, 150, 40, 200))
        sliderZ.vertical = True
        sliderX.vectorIndex = 0
        sliderZ.vectorIndex = 2
        sliderX.addTarget(self, self.onSliderValueChanged)
        sliderZ.addTarget(self, self.onSliderValueChanged)
        self.addChild(sliderX)
        self.addChild(sliderZ)

        shadowConfigWindow = dk.ui.TitledView('Config')
        origin = shadowConfigWindow.contentBounds().origin

        resWidth = 100
        typeWidth = 120
        itemHeight = 30

        resolutions = (0, 512)
        r = resolutions[-1]
        maxTexSize = dk.texture.maxTextureSize()
        while r < maxTexSize:
            r = r * 2
            resolutions = resolutions + (r,)

        # resolution radio-button rect
        resRect = dk.Rect(origin[0], origin[1], resWidth, len(resolutions) * itemHeight)

        configHeight = max(resRect.height, itemHeight*5)
        resRect.y = origin[1] + configHeight - resRect.height

        # shadow-type radio-button rect
        typeRect = dk.Rect(resRect.x + resRect.width, 0, typeWidth, itemHeight*2)
        typeRect.y = origin[1] + configHeight - typeRect.height

        # shadow-body-vector checkbox rect
        bvRect = dk.Rect(resRect.x + resRect.width, 0, typeWidth, itemHeight)
        bvRect.y = typeRect.y - bvRect.height

        # multi-sample checkbox rect
        msRect = dk.Rect(resRect.x + resRect.width, 0, typeWidth, itemHeight)
        msRect.y = bvRect.y - msRect.height

        # inspect-mode checkbox rect
        imRect = dk.Rect(resRect.x + resRect.width, 0, typeWidth, itemHeight)
        imRect.y = msRect.y - msRect.height

        frame = shadowConfigWindow.frameForContentFrame(dk.Rect(0, 0, resWidth+typeWidth, configHeight ))
        frame.origin = bounds.width - frame.width, bounds.height - frame.height
        shadowConfigWindow.frame = frame

        for btn, val in zip(
                dk.ui.radio.addItems(shadowConfigWindow, resolutions, resRect, columns=1),
                resolutions):
            btn.value = val
            btn.addTarget(self, self.onShadowResolutionChanged)
            btn.backgroundColor = dk.color.clear
            btn.setBlendState(dk.blendstate.defaultAlpha)

        for btn, val in zip(
                dk.ui.radio.addItems(shadowConfigWindow, ('Uniform', 'LiSPSM'), typeRect, columns=1),
                (SHADOW_MAP_UNIFORM, SHADOW_MAP_LISPSM)):
            btn.value = val
            if val == self.shadowMapInfo.type:
                btn.setSelected()
            btn.addTarget(self, self.onShadowTypeChanged)
            btn.backgroundColor = dk.color.clear
            btn.setBlendState(dk.blendstate.defaultAlpha)

        cb = dk.ui.Checkbox('B-Vector', value=True, frame=bvRect)
        cb.addTarget(self, self.onShadowBVectorValueChanged)
        cb.backgroundColor = dk.color.clear
        cb.setBlendState(dk.blendstate.defaultAlpha)
        shadowConfigWindow.addChild(cb)
        cb = dk.ui.Checkbox('Multi-Sample', value=False, frame=msRect)
        cb.addTarget(self, self.onShadowMultiSampleValueChanged)
        cb.backgroundColor = dk.color.clear
        cb.setBlendState(dk.blendstate.defaultAlpha)
        shadowConfigWindow.addChild(cb)
        cb = dk.ui.Checkbox('Inspect', value=False, frame=imRect)
        cb.addTarget(self, self.onShadowInspdeModeValueChanged)
        cb.backgroundColor = dk.color.clear
        cb.setBlendState(dk.blendstate.defaultAlpha)
        shadowConfigWindow.addChild(cb)
        shadowConfigWindow.backgroundColor = dk.Color(1.0, 1.0, 1.0, 0.9)
        shadowConfigWindow.setBlendState(dk.blendstate.defaultAlpha)
        self.addChild(shadowConfigWindow)

        # info labels
        self.infoLabel = dk.ui.Label()
        self.infoLabel.fontAttributes = dk.ui.font.attributes(18)
        self.infoLabel.align = dk.ui.label.ALIGN_LEFT
        self.infoLabel.backgroundColor = dk.Color(0.0, 0.0, 0.0, 0.3)
        self.infoLabel.textColor = dk.Color(1.0, 1.0, 1.0, 1.0)
        self.infoLabel.outlineColor = dk.Color(0.0, 0.0, 0.0, 1.0)
        self.infoLabel.setBlendState(dk.blendstate.defaultAlpha)
        self.infoLabel.enabled = False
        self.addChild(self.infoLabel)

        self.screen().postOperation(self.layout, ())

        # load model
        resourcePool = dk.ResourcePool()
        resourcePool.addSearchPath(dk.appInstance().resourceDir + '/desert')

        self.scene = dk.Scene()
        self.model = resourcePool.loadResource('desert.DKMODEL')
        self.scene.addObject(self.model)
        self.scene.ambientColor = dk.Color(0.1, 0.1, 0.1)
        self.scene.lights.append(dk.light.directional(dk.Vector3(0, -1, 0), dk.Color(1, 1, 1)))
        self.scene.updateLights()

        # calculate aabb
        def calcAABB(model, aabb):
            if isinstance(model, dk.Mesh):
                aabbMin, aabbMax = model.aabb()
                if aabbMin.x < aabb.min.x:  aabb.min.x = aabbMin.x
                if aabbMin.y < aabb.min.y:  aabb.min.y = aabbMin.y
                if aabbMin.z < aabb.min.z:  aabb.min.z = aabbMin.z
                if aabbMax.x > aabb.max.x:  aabb.max.x = aabbMax.x
                if aabbMax.y > aabb.max.y:  aabb.max.y = aabbMax.y
                if aabbMax.z > aabb.max.z:  aabb.max.z = aabbMax.z
            for c in model.children():
                calcAABB(c, aabb)

        aabb = dk.shadow.AABB(dk.Vector3(0, 0, 0), dk.Vector3(0, 0, 0))
        print('calculating scene AABB...')
        calcAABB(self.model, aabb)
        print('AABB: ', aabb)
        self.shadowMapInfo.aabb = aabb

        # generate box polygon mesh
        decl = dk.geometry.VertexBufferDecl()
        decl.add(dk.geometry.STREAM_ID.POSITION, 'position', dk.geometry.STREAM_TYPE.FLOAT3)
        data = array.array('f')
        data.extend(( 1.0,  1.0, -1.0))   # near right top
        data.extend(( 1.0, -1.0, -1.0))   # near right bottom
        data.extend((-1.0, -1.0, -1.0))   # near left bottom
        data.extend((-1.0,  1.0, -1.0))   # near left top
        data.extend(( 1.0,  1.0,  1.0))   # far right top
        data.extend(( 1.0, -1.0,  1.0))   # far right bottom
        data.extend((-1.0, -1.0,  1.0))   # far left bottom
        data.extend((-1.0,  1.0,  1.0))   # far left top

        faceIndices = (2,1,3,0,7,4,6,5,        # 2,1,3 / 3,1,0 / 3,0,7 / 7,0,4 / 7,4,6 / 6,4,5
                   5,4,
                   4,0,5,1,6,2,7,3)        # 4,0,5 / 5,0,1 / 5,1,6 / 6,1,2 / 6,2,7 / 7,2,3

        lineIndices = (0,1,1,2,2,3,3,0,0,4,4,5,5,1,3,7,7,6,6,2,6,5,7,4)

        vb = dk.geometry.createVertexBuffer(decl, data, 8)
        faceIb = dk.geometry.createIndexBuffer(faceIndices, dk.geometry.PRIMITIVE_TRIANGLE_STRIP)
        lineIb = dk.geometry.createIndexBuffer(lineIndices, dk.geometry.PRIMITIVE_LINES)

        inspectMaterial = resourcePool.loadResource('inspect.DKMATERIAL')
        inspectFaceMesh = dk.StaticMesh()
        # inspectFaceMesh.drawFace = dk.mesh.DRAW_FACE_CCW
        inspectFaceMesh.drawFace = dk.mesh.DRAW_FACE_BOTH
        inspectFaceMesh.setMaterial(inspectMaterial)
        inspectFaceMesh.addVertexBuffer(vb)
        inspectFaceMesh.setIndexBuffer(faceIb)

        inspectLineMesh = dk.StaticMesh()
        inspectLineMesh.drawFace = dk.mesh.DRAW_FACE_BOTH
        inspectLineMesh.setMaterial(inspectMaterial)
        inspectLineMesh.addVertexBuffer(vb)
        inspectLineMesh.setIndexBuffer(lineIb)

        # inspect mode items.
        self.inspectScene = dk.Scene()
        self.cameraFrustumFaceMesh = inspectFaceMesh.clone()
        self.shadowFrustumFaceMesh = inspectFaceMesh.clone()
        self.cameraFrustumLineMesh = inspectLineMesh.clone()
        self.shadowFrustumLineMesh = inspectLineMesh.clone()

        self.cameraFrustumFaceMesh.setMaterialProperty('color', floatings=dk.Color(1,0,0,0.1).tuple)
        self.shadowFrustumFaceMesh.setMaterialProperty('color', floatings=dk.Color(0,0,1,0.1).tuple)
        self.cameraFrustumLineMesh.setMaterialProperty('color', floatings=dk.Color(1,1,1).tuple)
        self.shadowFrustumLineMesh.setMaterialProperty('color', floatings=dk.Color(1,1,1).tuple)

        self.inspectScene.addObject(self.cameraFrustumFaceMesh)
        self.inspectScene.addObject(self.shadowFrustumFaceMesh)
        self.inspectScene.addObject(self.cameraFrustumLineMesh)
        self.inspectScene.addObject(self.shadowFrustumLineMesh)
示例#10
0
文件: kine.py 项目: DKGL/DKDemo
    def layout(self):
        super().layout()
        bounds = self.bounds()
        self.infoLabel.frame = dk.Rect(0, 0, bounds.width, 50)

        self.updatePerspective()
示例#11
0
文件: ui.py 项目: DKGL/DKDemo
    def onLoaded(self):
        super().onLoaded()
        self.backgroundColor = dk.Color(1.0, 1.0, 1.0)

        resourcePool = dk.ResourcePool()
        resourcePool.addSearchPath(dk.appInstance().resourceDir)
        image = resourcePool.loadResource('koo.jpg')

        subMenu1 = dk.ui.Menu()
        subMenu1.addItem('Menu Item 1')
        subMenu1.addItem('Menu Item 2')
        subMenu1.addItem('Menu Item 3')
        subMenu1.addSeparator()
        subMenu2 = dk.ui.Menu()
        subMenu2.addItem('Sub Menu Item 1')
        subMenu2.addItem('Sub Menu Item 2')
        subMenu1.addItem('Sub Menu').subMenu = subMenu2
        subMenu3 = dk.ui.Menu()
        subMenu3.addItem('Menu Item 4').checked = True
        subMenu3.addItem('Menu Item 5').checked = True
        subMenu3.addItem('Menu Item 6')
        subMenu4 = dk.ui.Menu()
        subMenu4.addItem('Menu Item 7')
        subMenu4.addItem('Menu Item 8')

        self.menuBar = dk.ui.Menu()
        self.menuBar.addItem('Menu 1').subMenu = subMenu1
        self.menuBar.addItem('Menu 2').subMenu = subMenu3
        self.menuBar.addSeparator()
        self.menuBar.addItem('Menu 3').subMenu = subMenu4
        self.addChild(self.menuBar)

        self.button1 = dk.ui.Button('Button')
        self.button2 = dk.ui.Button('Image Button', image=image)

        self.addChild(self.button1)
        self.addChild(self.button2)

        self.checkbox1 = dk.ui.Checkbox('Check Box 1 - region based',
                                        value=True)
        self.checkbox1.backgroundColor = dk.Color(0.8, 0.8, 0.8)
        self.checkbox1.interactOnlyInsideVisibleContentRect = False
        self.checkbox2 = dk.ui.Checkbox('Check Box 2 - content based',
                                        value=True)
        self.checkbox2.interactOnlyInsideVisibleContentRect = True
        self.addChild(self.checkbox1)
        self.addChild(self.checkbox2)

        self.radio1 = dk.ui.RadioButton('Radio Button 1',
                                        group=1,
                                        frame=dk.Rect(10, 10, 140, 48))
        self.radio2 = dk.ui.RadioButton('Radio Button 2',
                                        group=1,
                                        frame=dk.Rect(10, 10, 140, 48))
        self.radio3 = dk.ui.RadioButton('Radio Button 3',
                                        group=1,
                                        frame=dk.Rect(10, 10, 140, 48))
        self.radio1.setSelected()
        self.addChild(self.radio1)
        self.addChild(self.radio2)
        self.addChild(self.radio3)

        self.treeView = dk.ui.TreeView(frame=dk.Rect(20, 20, 200, 400))
        self.treeView.contentSize = dk.Size(300, 500)

        item1 = self.treeView.addItem('Tree Item 1')
        item11 = self.treeView.addItem('Sub Item 1', parent=item1)
        item12 = self.treeView.addItem('Sub Item 2', parent=item1)
        item11.state = item11.STATE_DISABLED
        self.treeView.addItem('Sub Sub Item 1', parent=item11)
        self.treeView.addItem('Sub Sub Item 2', parent=item12)
        item2 = self.treeView.addItem('Tree Item 2')
        item21 = self.treeView.addItem('Sub Item 1', parent=item2)

        for i in range(3, 10):
            item = self.treeView.addItem('Tree Item {}'.format(i))
            if i < 4:
                for j in range(1, 4):
                    item2 = self.treeView.addItem('Sub Item {}'.format(j),
                                                  parent=item)
                    for k in range(1, 3):
                        self.treeView.addItem('Sub Sub Item {}'.format(k),
                                              parent=item2)

        self.treeView.borderWidth = 1
        self.treeView.scrollBarBorderWidth = 1
        self.treeView.showVerticalScrollBar = True
        self.treeView.showHorizontalScrollBar = True
        self.treeView.showZoomButton = True
        self.treeView.leftScrollBar = True
        self.treeView.expandAllItems()
        self.addChild(self.treeView)

        self.textField = dk.ui.TextField('Text Input Field')
        self.addChild(self.textField)

        self.progressView = dk.ui.View()
        self.progressView.backgroundColor = dk.Color(0.9, 0.9, 0.9)
        self.addChild(self.progressView)

        progressAnim = 20.0
        prog1 = dk.ui.ProgressView(frame=dk.Rect(30, 10, 160, 20))
        prog1.progressAnimation = progressAnim
        prog1.setProgress(1)
        prog2 = dk.ui.ProgressView(frame=dk.Rect(10, 30, 20, 120))
        prog2.backgroundColor = dk.Color(0.4, 0.4, 0.4)
        prog2.progressColor = dk.Color(1.0, 1.0, 0.7)
        prog2.progressAnimation = progressAnim
        prog2.vertical = True
        prog2.setProgress(1)
        prog3 = dk.ui.ProgressView(circularType=True,
                                   frame=dk.Rect(70, 50, 100, 100))
        prog3.progressColor = dk.Color(0.7, 0.7, 1.0)
        prog3.progressAnimation = progressAnim
        prog3.borderWidth = 1
        prog3.innerCircleRadius = 40
        prog3.setProgress(1)
        prog4 = dk.ui.ProgressView(circularType=True,
                                   frame=dk.Rect(40, 40, 30, 30))
        prog4.progressColor = dk.Color(1.0, 0.7, 0.7)
        prog4.progressAnimation = progressAnim
        prog4.borderWidth = 1
        prog4.innerCircleRadius = 0
        prog4.setProgress(1)

        self.progressView.addChild(
            dk.ui.Label('Progress Views', frame=dk.Rect(2, 170, 196, 28)))
        self.progressView.addChild(prog1)
        self.progressView.addChild(prog2)
        self.progressView.addChild(prog3)
        self.progressView.addChild(prog4)

        class MyScrollView(dk.ui.ScrollView, dk.ui.TitledView):
            caption = 'Popup Window (Image scroll)'
            captionHeight = 24
            fontAttributes = dk.ui.font.attributes(14)
            pass

        imageView = dk.ui.ImageView(image=image, frame=dk.Rect(0, 0, 300, 300))
        imageView.enabled = False
        sv = MyScrollView(contentSize=dk.Size(imageView.frame.size),
                          frame=dk.Rect(500, 120, 250, 250))
        sv.addChild(imageView)
        sv.borderWidth = 1
        sv.showHorizontalScrollBar = True
        sv.showVerticalScrollBar = True
        sv.showZoomButton = True
        self.addChild(sv)
示例#12
0
文件: vehicle.py 项目: DKGL/DKDemo
    def onLoaded(self):
        super().onLoaded()

        resourceDir = dk.appInstance().resourceDir
        self.resourcePool = dk.ResourcePool()

        # self.resourcePool.addSearchPath(resourceDir)
        self.resourcePool.addSearchPath(resourceDir)

        # create simulator scene
        self.scene = dk.DynamicsScene()
        self.scene.setAmbientColor(dk.color.white)
        self.scene.lights = [
            dk.light.directional(dk.Vector3(-1, -1, -1), dk.Color(1, 1, 1))
        ]
        self.scene.updateLights()
        # self.scene.setDrawMode(dk.scene.DRAW_MESHES, dk.scene.DRAW_COLLISION_SHAPES)
        self.scene.drawMode = dk.scene.DRAW_COLLISION_SHAPES
        self.scene.lights.append(dk.Light())

        # ground object
        groundShape = dk.BoxShape(500, 100, 500)
        self.groundObject = createRigidBody(0, groundShape,
                                            dk.Vector3(0, -100, 0),
                                            'groundObject')

        self.scene.addObject(self.groundObject)

        # vehicle chassis
        chassisShape = dk.CompoundShape()
        chassisShape.addChild(dk.BoxShape(1, 0.5, 2), dk.Vector3(0, 1, 0))
        chassisShape.addChild(dk.BoxShape(0.85, 0.3, 0.9),
                              dk.Vector3(0, 1.8, -0.3))

        self.carChassis = createRigidBody(800,
                                          chassisShape,
                                          name='car chassis')
        #self.carChassis.setWorldTransform(dk.NSTransform(dk.Quaternion(dk.Vector3(0,0,1), math.pi * 0.3), dk.Vector3(0,10,0)))

        self.scene.addObject(self.carChassis)

        self.resetScene()

        # vehicle object
        self.vehicle = dk.controller.Vehicle(self.carChassis)
        self.carChassis.keepActivating(True)

        # add vehicle into scene
        self.scene.addObject(self.vehicle)

        WHEEL_WIDTH = 0.4
        WHEEL_RADIUS = 0.5

        # wheel shape
        wheelShape = dk.CylinderShape(WHEEL_WIDTH, WHEEL_RADIUS, WHEEL_RADIUS,
                                      dk.collisionshape.UP_AXIS_LEFT)
        self.wheelShape = wheelShape
        self.wheelTrans = []

        CONNECTION_HEIGHT = 1.2
        CUBE_HALF_EXTENTS = 1.0

        suspensionResetLength = 0.6
        wheelDirectionCS0 = dk.Vector3(0, -1, 0)
        wheelAxleCS = dk.Vector3(-1, 0, 0)

        tunning = {
            'suspensionStiffness': 20.0,
            'suspensionDamping': 2.3,
            'suspensionCompression': 4.4,
            'frictionSlip': 1000.0,
            'rollInfluence': 0.1
        }

        xvalues = (CUBE_HALF_EXTENTS - (0.3 * WHEEL_WIDTH),
                   -CUBE_HALF_EXTENTS + (0.3 * WHEEL_WIDTH),
                   -CUBE_HALF_EXTENTS + (0.3 * WHEEL_WIDTH),
                   CUBE_HALF_EXTENTS - (0.3 * WHEEL_WIDTH))
        zvalues = (2 * CUBE_HALF_EXTENTS - WHEEL_RADIUS,
                   2 * CUBE_HALF_EXTENTS - WHEEL_RADIUS,
                   -2 * CUBE_HALF_EXTENTS + WHEEL_RADIUS,
                   -2 * CUBE_HALF_EXTENTS + WHEEL_RADIUS)

        for x, z in zip(xvalues, zvalues):
            connectionPointCS0 = dk.Vector3(x, CONNECTION_HEIGHT, z)
            print('connectionPointCS0: ', connectionPointCS0)
            self.vehicle.addWheel(connectionPointCS0, wheelDirectionCS0,
                                  wheelAxleCS, suspensionResetLength,
                                  WHEEL_RADIUS, **tunning)

        self.vehicle.resetSuspension()
        for wheel in self.vehicle.wheels:
            self.vehicle.updateWheelTransform(wheel)

        # shooting box!
        self.shootingShapes = (dk.BoxShape(0.5, 0.5,
                                           0.5), dk.BoxShape(1.0, 0.5, 1.0),
                               dk.BoxShape(2.0, 0.5, 1.0),
                               dk.CylinderShape(1.0, 1.0, 1.0),
                               dk.CylinderShape(1.5, 0.5,
                                                1.5), dk.ConeShape(1.0, 1.5),
                               dk.ConeShape(2.5, 1.5), dk.SphereShape(1.0))

        # ui buttons
        self.accelButton = SimpleButton('Acc', frame=dk.Rect(100, 100, 80, 80))
        self.accelButton.backgroundColor = dk.color.blue
        self.brakeButton = SimpleButton('Brake',
                                        frame=dk.Rect(10, 100, 80, 80))
        self.brakeButton.backgroundColor = dk.color.red
        self.cameraButton = dk.ui.Button(text='Reset Camera',
                                         frame=dk.Rect(10, 10, 80, 50))
        self.cameraButton.addTarget(self, self.resetCamera)

        self.addChild(self.accelButton)
        self.addChild(self.brakeButton)
        self.addChild(self.cameraButton)

        self.steerSlider = dk.ui.Slider(frame=dk.Rect(200, 100, 200, 50))
        self.steerSlider.thumbRadius = 20
        self.addChild(self.steerSlider)
        self.steerSlider.minimumValue = -0.3
        self.steerSlider.maximumValue = 0.3
        self.steerSlider.value = 0.0
        self.steerSlider.addTarget(self, self.onSteerChanged)

        # info labels
        self.infoLabel = dk.ui.Label()
        self.infoLabel.align = dk.ui.label.ALIGN_LEFT
        self.infoLabel.backgroundColor = dk.Color(0, 0, 0, 0.2)
        self.infoLabel.textColor = dk.Color(1, 1, 1, 1)
        self.infoLabel.outlineColor = dk.Color(0, 0, 0, 0.85)
        self.infoLabel.drawTextOutline = True
        self.addChild(self.infoLabel)

        # help labels
        self.helpText = dk.ui.Label(
            'Arrow Keys: move, left-click: move camera, right-click: shoot obstacle'
        )
        self.helpText.fontAttributes = dk.ui.font.attributes(14)
        self.helpText.backgroundColor = dk.color.clear
        self.helpText.outlineColor = dk.Color(0.2, 0.2, 0.2)
        self.helpText.textColor = dk.color.white
        self.helpText.setBlendState(dk.blendstate.defaultAlpha)
        self.addChild(self.helpText)

        self.captureKeyboard(0)
        #self.resetCamera()
        self.screen().postOperation(self.layout, ())
        self.autoShootingCount = 0
        self.autoShooting = self.screen().scheduleOperation(
            self.shootBoxFromAbove, (), interval=self.shootingInterval)