当前位置: 首页>>代码示例>>Python>>正文


Python DirectFrame.bind方法代码示例

本文整理汇总了Python中direct.gui.DirectFrame.DirectFrame.bind方法的典型用法代码示例。如果您正苦于以下问题:Python DirectFrame.bind方法的具体用法?Python DirectFrame.bind怎么用?Python DirectFrame.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在direct.gui.DirectFrame.DirectFrame的用法示例。


在下文中一共展示了DirectFrame.bind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _createComponents

# 需要导入模块: from direct.gui.DirectFrame import DirectFrame [as 别名]
# 或者: from direct.gui.DirectFrame.DirectFrame import bind [as 别名]
    def _createComponents(self):
        self.debug("Creating GUI Components")

        self.categoryMenu = self.parent.attachNewNode("CategoryMenu")
        self.categoryMenu.setPos(-350, 0, -49)

        self.sidebar = self.parent.attachNewNode("EditorSidebar")

        self.sidebarBackground = DirectFrame(
            parent=self.sidebar,
            pos=(0, 0, 0),
            frameSize=(0, 92, 0, -base.win.getYSize()),
            frameColor=(0.05, 0.05, 0.05, 1.0),
        )

        self.logo = BetterOnscreenImage(
            parent=self.sidebar, transparent=False, image="Editor/GUI/logo.png", x=0, y=0, w=92, h=48
        )

        self.categoriesParent = self.sidebar.attachNewNode("Categories")
        self.categoriesParent.setPos(0, 0, -48)

        self.categoryIcons = {}

        self.animations = {"moveMenuArrow": None, "moveCategoryMenu": None}

        for index, category in enumerate(EditorCategories.Categories):
            iconDefault = "Editor/GUI/Icon-" + category.name + ".png"
            iconHover = "Editor/GUI/Icon-" + category.name + "-Hover.png"
            # iconActive = "Editor/GUI/Icon-" + category.name + "-Hover.png"
            self.categoryIcons[category.name] = BetterOnscreenImage(
                parent=self.categoriesParent, transparent=False, image=iconDefault, x=0, y=94 * index, w=92, h=94
            )

            # i hate direct gui
            hoverCatch = DirectFrame(
                parent=self.categoriesParent,
                frameSize=(0, 92, 0, -94),
                pos=(0, 0, -94 * index),
                frameColor=(0, 0, 0, 0),
                state=DGG.NORMAL,
            )

            # Add a hover effect
            hoverCatch.bind(DGG.ENTER, partial(self._showCategoryMenu, category.name))
            hoverCatch.bind(DGG.EXIT, partial(self._hideCategoryMenu, category.name))

        self.currentCategoryMarker = BetterOnscreenImage(
            parent=self.categoriesParent, image="Editor/GUI/Arrow-Right.png", x=92, y=0, w=11, h=21
        )

        self.currentCategoryMarker.hide()

        self.categoryMenuBg = DirectFrame(
            parent=self.categoryMenu, pos=(15, 0, 0), frameSize=(0, 300, 0, -400), frameColor=(0.2, 0.2, 0.2, 1.0)
        )
开发者ID:rasteron,项目名称:RenderPipeline,代码行数:58,代码来源:EditorGUI.py

示例2: renderBuffers

# 需要导入模块: from direct.gui.DirectFrame import DirectFrame [as 别名]
# 或者: from direct.gui.DirectFrame.DirectFrame import bind [as 别名]
    def renderBuffers(self):
        self.buffersParent.node().removeAllChildren()

        posX = 0
        posY = 0

        for name in self.bufferOrder:
            target = self.buffers[name]
            for targetType in RenderTargetType.All:
                if not target.hasTarget(targetType):
                    continue
                tex = target.getTexture(targetType)
                sizeStr = str(tex.getXSize()) + " x " + str(tex.getYSize())

                if tex.getZSize() != 1:
                    sizeStr += " x " + str(tex.getZSize())

                sizeStr += " - " + str(self.calculateTexSize(tex)) + " MB"

                node = DirectFrame(parent=self.buffersParent, frameColor=(
                    1, 1, 1, 0.2), frameSize=(-self.innerPadding, self.texWidth + self.innerPadding, -self.texHeight - 30 - self.innerPadding, self.innerPadding + 15),
                    state=DGG.NORMAL)
                node.setPos(
                    20 + posX * (self.texWidth + self.texPadding), 0, -self.paddingTop - 22 - posY * (self.texHeight + self.texPadding + 44))
                node.bind(DGG.ENTER, partial(self.onMouseOver, node))
                node.bind(DGG.EXIT, partial(self.onMouseOut, node))
                node.bind(DGG.B1RELEASE, partial(self.showDetail, tex))

                aspect = tex.getYSize() / float(tex.getXSize())
                computedWidth = self.texWidth
                computedHeight = self.texWidth * aspect

                if computedHeight > self.texHeight:
                    # have to scale tex width instead
                    computedHeight = self.texHeight
                    computedWidth = tex.getXSize() / float(tex.getYSize()) * \
                        self.texHeight

                img = BetterOnscreenImage(
                    image=tex, parent=node, x=0, y=30, w=computedWidth,
                    h=computedHeight, transparent=False, nearFilter=False,
                    anyFilter=False)
                txtName = BetterOnscreenText(
                    text=name, x=0, y=0, size=13, parent=node)
                txtSizeFormat = BetterOnscreenText(
                    text=sizeStr, x=0, y=20, size=13, parent=node,
                    color=Vec3(0.2))
                txtTarget = BetterOnscreenText(
                    text=str(targetType), align="right", x=self.texWidth,
                    y=20, size=13, parent=node, color=Vec3(0.2))

                posX += 1
                if posX > self.pageSize:
                    posY += 1
                    posX = 0
开发者ID:croxis,项目名称:RenderPipeline,代码行数:57,代码来源:BufferViewerGUI.py

示例3: _render_stages

# 需要导入模块: from direct.gui.DirectFrame import DirectFrame [as 别名]
# 或者: from direct.gui.DirectFrame.DirectFrame import bind [as 别名]
    def _render_stages(self):
        """ Renders the stages to the window """

        self._remove_components()
        entries_per_row = 8
        aspect = Globals.base.win.get_y_size() /\
            float(Globals.base.win.get_x_size())
        entry_width = 180
        entry_height = (entry_width - 20) * aspect + 55

        # Store already processed images
        processed = set()
        index = -1
        # Iterate over all stages
        for stage_tex in self._stages:
            if stage_tex in processed:
                continue
            processed.add(stage_tex)
            index += 1
            stage_name = stage_tex.get_name()

            xoffs = index % entries_per_row
            yoffs = index // entries_per_row
            node = self._content_node.attach_new_node("Preview")
            node.set_sz(-1)
            node.set_pos(10 + xoffs * (entry_width - 14), 1, yoffs * (entry_height-14))

            if stage_name.startswith("Image"):
                r, g, b = 0.4, 0.4, 0.4
            else:
                r, g, b = rgb_from_string(stage_name)

            DirectFrame(
                parent=node, frameSize=(7, entry_width - 17, -7, -entry_height + 17),
                frameColor=(r, g, b, 1.0), pos=(0, 0, 0))

            frame_hover = DirectFrame(
                parent=node, frameSize=(0, entry_width - 10, 0, -entry_height + 10),
                frameColor=(0, 0, 0, 0), pos=(0, 0, 0), state=DGG.NORMAL)
            frame_hover.bind(
                DGG.ENTER, partial(self._on_texture_hovered, frame_hover))
            frame_hover.bind(
                DGG.EXIT, partial(self._on_texture_blurred, frame_hover))
            frame_hover.bind(
                DGG.B1PRESS, partial(self._on_texture_clicked, stage_tex))

            BetterOnscreenText(text=stage_name, x=15, y=29, parent=node,
                               size=12, color=Vec3(0.2))

            # Scale image so it always fits
            w, h = stage_tex.get_x_size(), stage_tex.get_y_size()
            scale_x = float(entry_width - 30) / max(1, w)
            scale_y = float(entry_height - 60) / max(1, h)
            scale_factor = min(scale_x, scale_y)

            if stage_tex.get_texture_type() == Texture.TT_buffer_texture:
                scale_factor = 1
                w = entry_width - 30
                h = entry_height - 60

            preview = BetterOnscreenImage(
                image=stage_tex, w=scale_factor * w, h=scale_factor * h,
                any_filter=False, parent=node, x=10, y=40, transparent=False)

            preview.set_shader_input("mipmap", 0)
            preview.set_shader_input("slice", 0)

            preview_shader = DisplayShaderBuilder.build(stage_tex, scale_factor*w, scale_factor*h)
            preview.set_shader(preview_shader)
开发者ID:MYheavyGo,项目名称:RenderPipeline,代码行数:71,代码来源:BufferViewer.py

示例4: _render_stages

# 需要导入模块: from direct.gui.DirectFrame import DirectFrame [as 别名]
# 或者: from direct.gui.DirectFrame.DirectFrame import bind [as 别名]
    def _render_stages(self):
        """ Renders the stages to the window """

        self._remove_components()
        entries_per_row = 6
        aspect = Globals.native_resolution.y / Globals.native_resolution.x
        entry_width = 235
        entry_height = (entry_width - 20) * aspect + 55

        # Store already processed images
        processed = set()
        index = -1
        # Iterate over all stages
        for stage_tex in self._stages:
            if stage_tex in processed:
                continue
            processed.add(stage_tex)
            index += 1
            stage_name = stage_tex.get_name()

            xoffs = index % entries_per_row
            yoffs = index // entries_per_row
            node = self._content_node.attach_new_node("Preview")
            node.set_sz(-1)
            node.set_pos(10 + xoffs * (entry_width - 14), 1, yoffs * (entry_height - 14 + 10))

            r, g, b = 0.2, 0.2, 0.2
            if isinstance(stage_tex, Image):
                r, g, b = 0.2, 0.4, 0.6

            stage_name = stage_name.replace("render_pipeline_internal:", "")
            parts = stage_name.split(":")
            stage_name = parts[-1]
            DirectFrame(
                parent=node, frameSize=(7, entry_width - 17, -7, -entry_height + 17),
                frameColor=(r, g, b, 1.0), pos=(0, 0, 0))

            frame_hover = DirectFrame(
                parent=node, frameSize=(0, entry_width - 10, 0, -entry_height + 10),
                frameColor=(0, 0, 0, 0), pos=(0, 0, 0), state=DGG.NORMAL)
            frame_hover.bind(
                DGG.ENTER, partial(self._on_texture_hovered, frame_hover))
            frame_hover.bind(
                DGG.EXIT, partial(self._on_texture_blurred, frame_hover))
            frame_hover.bind(
                DGG.B1PRESS, partial(self._on_texture_clicked, stage_tex))

            Text(text=stage_name, x=15, y=29, parent=node, size=12, color=Vec3(0.8))

            # Scale image so it always fits
            w, h = stage_tex.get_x_size(), stage_tex.get_y_size()
            padd_x, padd_y = 24, 57
            scale_x = (entry_width - padd_x) / max(1, w)
            scale_y = (entry_height - padd_y) / max(1, h)
            scale_factor = min(scale_x, scale_y)

            if stage_tex.get_texture_type() == Image.TT_buffer_texture:
                scale_factor = 1
                w = entry_width - padd_x
                h = entry_height - padd_y

            preview = Sprite(
                image=stage_tex, w=scale_factor * w, h=scale_factor * h,
                any_filter=False, parent=node, x=7, y=40, transparent=False)

            preview.set_shader_input("mipmap", 0)
            preview.set_shader_input("slice", 0)
            preview.set_shader_input("brightness", 1)
            preview.set_shader_input("tonemap", False)

            preview_shader = DisplayShaderBuilder.build(
                stage_tex, scale_factor * w, scale_factor * h)
            preview.set_shader(preview_shader)

        num_rows = (index + entries_per_row) // entries_per_row

        self._set_scroll_height(50 + (entry_height - 14 + 10) * num_rows)
开发者ID:ELMERzark,项目名称:RenderPipeline,代码行数:79,代码来源:buffer_viewer.py

示例5: DraggableWindow

# 需要导入模块: from direct.gui.DirectFrame import DirectFrame [as 别名]
# 或者: from direct.gui.DirectFrame.DirectFrame import bind [as 别名]
class DraggableWindow(DebugObject):

    """ This is a simple draggable but not resizeable window """

    def __init__(self, width=800, height=500, title="Window", parent=None):
        DebugObject.__init__(self, "Window-" + title)
        self._width = width
        self._height = height
        self._title = title
        self._visible = True
        self._parent = parent if parent else Globals.base.pixel2d
        self._context_scale = 1.0 / parent.get_sx()
        self._context_width = Globals.base.win.get_x_size() * self._context_scale
        self._context_height = Globals.base.win.get_y_size() * self._context_scale
        self._pos = Vec2((self._context_width - self._width) / 2, (self._context_height - self._height) / 2)
        self._dragging = False
        self._drag_offset = Vec2(0)

    def set_title(self, title):
        """ Sets the window title """
        self._title = title
        self._window_title.set_text(title)

    def show(self):
        """ Shows the window """
        self._visible = True
        self._node.show()

    def hide(self):
        """ Hides the window """
        self._visible = False
        self._stop_drag()
        self._node.hide()

    def remove(self):
        """ Removes the window from the scene graph. You should still delete the
        instance """
        self._stop_drag()
        self._node.remove_node()

    def _create_components(self):
        """ Creates the window components """
        self._node = self._parent.attach_new_node("Window")
        self._node.set_pos(self._pos.x, 1, -self._pos.y)
        border_px = 1
        self._border_frame = DirectFrame(
            pos=(0, 1, 0),
            frameSize=(-border_px, self._width + border_px, border_px, -self._height - border_px),
            frameColor=(0.0, 0.0, 0.0, 1),
            parent=self._node,
            state=DGG.NORMAL,
        )
        # self._border_frame.hide()
        self._background = DirectFrame(
            pos=(0, 1, 0),
            frameSize=(0, self._width, 0, -self._height),
            frameColor=(0.098, 0.098, 0.098, 1),
            parent=self._node,
        )
        self._title_bar = DirectFrame(
            pos=(0, 1, 0),
            frameSize=(0, self._width, 0, -45),
            frameColor=(0.058, 0.058, 0.058, 1),
            parent=self._node,
            state=DGG.NORMAL,
        )
        self._window_title = BetterOnscreenText(
            parent=self._node, x=12, y=29, text=self._title, size=19, color=Vec3(0.7), may_change=True
        )
        self._btn_close = DirectButton(
            relief=DGG.FLAT,
            pressEffect=1,
            pos=(self._width - 22, 1, -22),
            frameColor=(0, 0, 0, 0),
            scale=(20, 1, 20),
            parent=self._node,
            image="Data/GUI/CloseWindow.png",
        )

        # Init bindings
        self._btn_close.set_transparency(TransparencyAttrib.M_alpha)
        self._btn_close.bind(DGG.B1CLICK, self._request_close)
        self._btn_close.bind(DGG.WITHIN, self._on_close_btn_hover)
        self._btn_close.bind(DGG.WITHOUT, self._on_close_btn_out)
        self._title_bar.bind(DGG.B1PRESS, self._start_drag)
        self._title_bar.bind(DGG.B1RELEASE, self._stop_drag)

    def _start_drag(self, evt=None):
        """ Gets called when the user starts dragging the window """
        self._dragging = True
        self._node.detach_node()
        self._node.reparent_to(self._parent)
        Globals.base.taskMgr.add(self._on_tick, "UIWindowDrag", uponDeath=self._stop_drag)
        self._drag_offset = self._pos - self._get_mouse_pos()

    def _on_close_btn_hover(self, evt=None):
        """ Internal method when the close button got hovered """
        self._btn_close["frameColor"] = (1.0, 0.2, 0.2, 1.0)

    def _on_close_btn_out(self, evt=None):
#.........这里部分代码省略.........
开发者ID:MYheavyGo,项目名称:RenderPipeline,代码行数:103,代码来源:DraggableWindow.py


注:本文中的direct.gui.DirectFrame.DirectFrame.bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。