예제 #1
0
    def draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        imgui.begin("Example: item groups")

        imgui.begin_group()
        imgui.text("First group (buttons):")
        imgui.button("Button A")
        imgui.button("Button B")
        imgui.end_group()

        imgui.same_line(spacing=50)

        imgui.begin_group()
        imgui.text("Second group (text and bullet texts):")
        imgui.bullet_text("Bullet A")
        imgui.bullet_text("Bullet B")
        imgui.end_group()

        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
예제 #2
0
def draw_list(id_str, label, items, select_item, delete_callback=None):

    imgui.begin_child(id_str)
    imgui.text(label)

    cur_state.hovered_item = None

    for idx, item in enumerate(items):
        cur_id_str = "##list_{}_{}".format(id_str, idx)
        sel_btn_id = "Select {} {}".format(idx, cur_id_str)
        del_btn_id = "X{}".format(cur_id_str)

        imgui.begin_group()
        if imgui.button(sel_btn_id):
            print("clicked {}".format(idx))
            select_item(idx)
        imgui.same_line()

        imgui.text(str(item))
        if delete_callback is not None:
            imgui.same_line()
            if imgui.button(del_btn_id):
                delete_callback(item)
                print("delete!!")

        imgui.end_group()

        if imgui.is_item_hovered():
            cur_state.hovered_item = item

    imgui.end_child()
예제 #3
0
 def draw_lattice_gui(self):
     imgui.begin("Contact Modes", True)
     imgui.begin_group()
     if imgui.button("prev"):
         self.prev()
     imgui.same_line()
     if self.play_mode == 0:
         if imgui.button("play"):
             self.play_mode += 1
     if self.play_mode == 1:
         if imgui.button("loop"):
             self.play_mode += 1
     if self.play_mode == 2:
         if imgui.button("stop"):
             self.play_mode = 0
     imgui.same_line()
     if imgui.button("next"):
         self.next()
     imgui.same_line()
     if imgui.button("skip"):
         self.skip()
     imgui.end_group()
     
     imgui.text('contacting/separating modes:')
     if self.lattice0.num_faces() > 250:
         self.draw_big_lattice(self.lattice0, 'cs-lattice', self.index0)
     else:
         self.draw_lattice(self.lattice0, 'cs-lattice', self.index0)
     imgui.text('sliding/sticking modes:')
     if self.lattice1 is not None:
         if self.lattice1.num_faces() > 250:
             self.draw_big_lattice(self.lattice1, 'ss-lattice', self.index1)
         else:
             self.draw_lattice(self.lattice1, 'ss-lattice', self.index1)
     imgui.end()
예제 #4
0
def image_explorer(image, width=None, height=None, title="", zoom_key="", hide_buttons=False,
                   image_adjustments=None,
                   always_refresh = False
                   ):
    """
    :param image_adjustments:
    :param hide_buttons:
    :param image: opencv / np image.
    :param width:
    :param height:
    :param title: an optional title
    :param zoom_key: Set the same zoom_key for two image if you want to link their zoom settings
    :return: mouse location in image coordinates (None if the mouse is outside of the image)
    """
    if image_adjustments is None:
        image_adjustments = ImageAdjustments()
    from ._imgui_cv_zoom import image_explorer_autostore_zoominfo
    viewport_size = _image_viewport_size(image, width, height)
    imgui.begin_group()
    mouse_location_original_image = image_explorer_autostore_zoominfo(
        image,
        viewport_size,
        title,
        zoom_key,
        image_adjustments,
        hide_buttons=hide_buttons,
        always_refresh = always_refresh
        )
    imgui.end_group()
    return mouse_location_original_image
예제 #5
0
def drag_drop_target(tag, value, widget):
    """ Drag-and-Drop Target Widget.

    This widget is used in conjunction with `concur.widgets.drag_drop_source`. On widget drop,
    an event is generated which contains the payload from source, and the value from targed,
    and is shaped like this: `(tag, (source_payload, value))`.

    Args:
        tag: Drag-and-Drop event tag. Must match the tag in `drag_drop_source`.
        value: Value added to the event.
        widget: Widget which accepts the drag-and-drop event.
    """
    while True:
        try:
            imgui.begin_group()
            next(widget)
        except StopIteration as e:
            return e.value
        finally:
            imgui.end_group()
        if imgui.begin_drag_drop_target():
            payload = imgui.accept_drag_drop_payload(tag)
            imgui.end_drag_drop_target()
            if payload is not None:
                return tag, (pickle.loads(payload), value)
        yield
예제 #6
0
 def render_row(self, process):
     imgui.begin_group()
     for key in self.attrs:
         imgui.text(str(process.info[key]))
         imgui.next_column()
     imgui.end_group()
     if imgui.is_item_clicked():
         pass
예제 #7
0
def text_tooltip(text, widget):
    """Display a text tooltip on hover"""
    while True:
        try:
            imgui.begin_group()
            next(widget)
        except StopIteration as e:
            return e.value
        finally:
            imgui.end_group()
        if imgui.is_item_hovered():
            imgui.set_tooltip(text)
        yield
예제 #8
0
 def render(self):
     imgui.begin_group()
     imgui.text(self.percentLeft)
     if self.battery.power_plugged:
         imgui.text_colored("I", *theme.color("battery_charging",
                                              "success"))
     imgui.end_group()
     if imgui.is_item_hovered():
         imgui.begin_tooltip()
         if not self.battery.power_plugged:
             imgui.text(f"{self.timeLeft}")
         else:
             imgui.text("Battery is charging")
         imgui.end_tooltip()
예제 #9
0
 def _show_list(self):
     imgui.begin_group()
     # imgui.text("")
     changed, selected_key = imgui_ext.listbox_dict(
         self.images_info,
         self.current_image,
         title_top="Images",
         height_in_items=40,
         item_width=self.listbox_width)
     if changed:
         self._set_selected_image(selected_key)
     if imgui.button(imgui_ext.make_unique_label("Clear all")):
         self.clear_all_images()
     imgui.end_group()
예제 #10
0
def draggable(name, widget, tag=None):
    """Add draggable functionality to a widget. Emits (dx, dy) when dragged. The underlying widget works as usual.

    Returned values are equal to the mouse position difference from the previous frame.
    """
    io = imgui.get_io()
    while True:
        try:
            imgui.begin_group()
            next(widget)
        except StopIteration as e:
            return e.value
        finally:
            imgui.end_group()
        if imgui.is_item_active() and (io.mouse_delta[0] or io.mouse_delta[1]):
            return tag if tag is not None else name, io.mouse_delta
        yield
예제 #11
0
def _image_impl(
    image_and_ajustments,
    width=None, height=None, title="",
    always_refresh = False,
    linked_user_image_address: ImageAddress = 0
    ):

    statics = _image_impl.statics
    statics.last_shown_image = image_and_ajustments
    zoom_key = imgui_ext.make_unique_label(title)
    if zoom_key not in statics.zoomed_status:
        statics.zoom_click_times[zoom_key] = 0
        statics.zoomed_status[zoom_key] = False
    if statics.zoomed_status[zoom_key]:
        viewport_size = SizePixel.from_image(image_and_ajustments.image)
    else:
        viewport_size = _image_viewport_size(image_and_ajustments.image, width, height)

    if zoom_key not in statics.zoomed_status:
        statics.zoomed_status[zoom_key] = False
        statics.zoom_click_times[zoom_key] = timer()

    texture_id = _image_to_texture(
        image_and_ajustments,
        always_refresh = always_refresh,
        linked_user_image_address=linked_user_image_address
        )
    if title == "":
        imgui.image_button(texture_id, viewport_size.width, viewport_size.height, frame_padding=0)
        is_mouse_hovering = imgui.is_item_hovered()
    else:
        imgui.begin_group()
        imgui.image_button(texture_id, viewport_size.width, viewport_size.height, frame_padding=0)
        is_mouse_hovering = imgui.is_item_hovered()
        imgui.text(title)
        imgui.end_group()

    if is_mouse_hovering and imgui.get_io().mouse_down[0]:
        last_time = statics.zoom_click_times[zoom_key]
        now = timer()
        if now - last_time > 0.3:
            statics.zoomed_status[zoom_key] = not statics.zoomed_status[zoom_key]
            statics.zoom_click_times[zoom_key] = now

    return mouse_position_last_image()
예제 #12
0
    def displayInspector(self, obj):
        imgui.set_next_window_position(self.position[0], self.position[1])
        imgui.set_next_window_size(self.width, self.height)

        expanded, opened = imgui.begin("Inspector", True)
        if opened:
            imgui.begin_group()
            imgui.bullet_text(obj.name)

            transform_layer, visible = imgui.collapsing_header(
                "Transform", True)
            if transform_layer:
                HELPER.displayGameObjectTransformSetting(obj, imgui)
            imgui.end_group()

            for component in obj.components:
                HELPER.displayComponentSetting(imgui, component, obj)
        imgui.end()
예제 #13
0
    def draw(self):
        imgui.begin("Example: item groups")

        imgui.begin_group()
        imgui.text("First group (buttons):")
        imgui.button("Button A")
        imgui.button("Button B")
        imgui.end_group()

        imgui.same_line(spacing=50)

        imgui.begin_group()
        imgui.text("Second group (text and bullet texts):")
        imgui.bullet_text("Bullet A")
        imgui.bullet_text("Bullet B")
        imgui.end_group()

        imgui.end()
예제 #14
0
파일: main.py 프로젝트: Delaunay/tide
    def function(self, fun):
        import tide.generators.nodes as nodes
        f: nodes.FunctionDef = fun

        imgui.begin_group()
        imgui.text('def')
        imgui.same_line()
        imgui.input_text('nolavel', f.name)
        imgui.same_line()
        imgui.text('(')
        imgui.same_line()
        imgui.text(')')
        imgui.same_line()
        imgui.text('->')
        imgui.same_line()
        imgui.text(str(f.returns))
        imgui.same_line()
        imgui.text(':')

        imgui.end_group()
예제 #15
0
def tooltip(tooltip_widget, widget):
    """ Display a widget tooltip on hover. May contain arbitrary elements, such as images. """
    while True:
        try:
            imgui.begin_group()
            next(widget)
        except StopIteration as e:
            return e.value
        finally:
            imgui.end_group()

        if imgui.is_item_hovered():
            try:
                imgui.begin_tooltip()
                next(tooltip_widget)
            except StopIteration as e:
                return e.value
            finally:
                imgui.end_tooltip()
        yield
예제 #16
0
def drag_drop_source(tag, payload, widget, dragged_widget=None, flags=0):
    """ Drag-and-Drop Source Widget.

    This widget is used in conjunction with `concur.widgets.drag_drop_target`.

    See the [https://github.com/potocpav/python-concur/blob/master/examples/extra/drag_and_drop.py](examples/extra/drag_and_drop.py)
    for an example.

    Args:
        tag: Drag-and-Drop event tag. Must match the tag in `drag_drop_target`.
        payload: Pickle-able value which is to be returned in the drag-and-drop event.
        widget: Widget which can be dragged.
        dragged_widget: Widget inside the tooltip which is displayed while dragging.
            Defaults to a `widget` copy.
        flags: Flags to modify dragging behavior.
            See [the pyimgui docs](https://pyimgui.readthedocs.io/en/latest/reference/imgui.html?highlight=WINDOW_MENU_BAR#imgui.DRAG_DROP_SOURCE_NO_PREVIEW_TOOLTIP)
            for the flag list.
    """
    while True:
        try:
            imgui.begin_group()
            next(widget)
        except StopIteration as e:
            return e.value
        finally:
            imgui.end_group()
        assert not (
            flags & imgui.DRAG_DROP_SOURCE_ALLOW_NULL_ID
        ), "`SourceAllowNullID` is automatically set - do not set it manually."
        if imgui.begin_drag_drop_source(
                flags | imgui.DRAG_DROP_SOURCE_ALLOW_NULL_ID):
            imgui.set_drag_drop_payload(tag, pickle.dumps(payload))
            try:
                next(dragged_widget if dragged_widget else widget)
            except StopIteration as e:
                assert ValueError(
                    "Drag and drop indicator widget (`dragged_widget`) fired an event. You can use `concur.forever` to supress widget events. If you have a legitimate use-case for this, please file an issue."
                )
            finally:
                imgui.end_drag_drop_source()
        yield
예제 #17
0
    def draw(self):
        width = 20
        height = 100

        imgui.set_next_window_size(160, 160, imgui.ONCE)

        imgui.begin("Sin")
        imgui.begin_group()
        changed, self.value = imgui.v_slider_int(
            "value",
            width, height, self.value,
            min_value=0, max_value=100,
            format="%d"
        )
        imgui.end_group()
        imgui.same_line(spacing=16)
        imgui.begin_group()
        imgui.text('output')
        self.mark_output(self.output)
        imgui.end_group()
        imgui.end()
def MudClientWindow(MudData):
    # mud content
    MudData['World_text_changed'], MudData['World_text'] = imgui.input_text_multiline(
        '\n',
        MudData['World_text'],
        50000,
        1280,
        660,
        imgui.INPUT_TEXT_READ_ONLY
    )
    imgui.begin_group()
    imgui.text("Input:")
    imgui.same_line()
    MudData['Player_text_changed'], MudData['Player_text'] = imgui.input_text(
        '\n\n',
        MudData['Player_text'],
        1920,
        imgui.INPUT_TEXT_ENTER_RETURNS_TRUE
    )
    imgui.end_group()
    if imgui.button("keyboard"):
        imgui.open_popup("select-popup")
예제 #19
0
 def _show_image(self):
     if self.current_image in self.images_info:
         imgui.begin_group()
         if imgui.button("X"):
             self.images_info.pop(self.current_image)
             self.current_image = ""
         else:
             image_info = self.images_info[self.current_image]
             if image_info.additional_legend != "":
                 imgui.same_line()
                 imgui.text(image_info.additional_legend)
             img = image_info.image
             image_size = imgui.Vec2(img.shape[1], img.shape[0])
             image_size = image_size_fit_in_gui(image_size,
                                                self._max_image_size(),
                                                can_make_bigger=True)
             imgui_cv.image_explorer(
                 img,
                 title=self.current_image,
                 width=int(round(image_size.x)),
                 height=int(round(image_size.y)),
                 image_adjustments=image_info.image_adjustments)
         imgui.end_group()
    def create_frames_and_buttons(self):
        # take section one by one
        for key_section in keys:
            # create Sperate Frame For Every Section
            # store_section = Tkinter.Frame(self)
            # store_section.pack(side='left', expand='yes', fill='both', padx=10, pady=10, ipadx=10, ipady=10)
            # imgui.begin_group()
            for layer_name, layer_properties, layer_keys in key_section:
                # store_layer = Tkinter.LabelFrame(store_section)  # , text=layer_name)
                # store_layer.pack(side='top',expand='yes',fill='both')
                # store_layer.pack(layer_properties)
                for key_bunch in layer_keys:
                    # store_key_frame = Tkinter.Frame(store_layer)
                    # store_key_frame.pack(side='top', expand='yes', fill='both')
                    imgui.begin_group()
                    for k in key_bunch:
                        k = k.capitalize()
                        if len(k) <= 3:
                            imgui.push_style_color(imgui.COLOR_BUTTON, *FILE_COLOR)
                            if not self.InnerMudData['Shift_enabled']:
                                k = k.lower()
                            if imgui.button(k):
                                self.button_command(k)
                            imgui.pop_style_color(1)
                        else:
                            imgui.push_style_color(imgui.COLOR_BUTTON, *FILE_COLOR)
                            if imgui.button(k.center(5, ' ')):
                                self.button_command(k)
                            imgui.pop_style_color(1)
                        imgui.same_line()
                        # store_button['relief'] = BUTTON_LOOK
                        # store_button['bg'] = BUTTON_BACKGROUND
                        # store_button['fg'] = FONT_COLOR

                        # store_button['command'] = lambda q=k.lower(): self.button_command(q)
                        # store_button.pack(side='left', fill='both', expand='yes')
                    imgui.end_group()
예제 #21
0
def frame_commands():
    gl.glClearColor(0.1, 0.1, 0.1, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    io = imgui.get_io()

    if io.key_ctrl and io.keys_down[glfw.KEY_Q]:
        sys.exit(0)

    if imgui.begin_main_menu_bar():
        if imgui.begin_menu("File", True):
            clicked_quit, selected_quit = imgui.menu_item("Quit", "Ctrl+Q", False, True)

            if clicked_quit:
                sys.exit(0)

            imgui.end_menu()
        imgui.end_main_menu_bar()

    # turn windows on/off
    imgui.begin("Active examples")
    for label, enabled in active.copy().items():
        _, enabled = imgui.checkbox(label, enabled)
        active[label] = enabled
    imgui.end()

    if active["window"]:
        imgui.begin("Hello, Imgui!")
        imgui.text("Hello, World!")
        imgui.end()

    if active["child"]:
        imgui.begin("Example: child region")
        imgui.begin_child("region", 150, -50, border=True)
        imgui.text("inside region")
        imgui.end_child()
        imgui.text("outside region")
        imgui.end()

    if active["tooltip"]:
        imgui.begin("Example: tooltip")
        imgui.button("Click me!")
        if imgui.is_item_hovered():
            imgui.begin_tooltip()
            imgui.text("This button is clickable.")
            imgui.end_tooltip()
        imgui.end()

    if active["menu bar"]:
        try:
            flags = imgui.WINDOW_MENU_BAR
            imgui.begin("Child Window - File Browser", flags=flags)
            if imgui.begin_menu_bar():
                if imgui.begin_menu('File'):
                    clicked, state = imgui.menu_item('Close')
                    if clicked:
                        active["menu bar"] = False
                        raise Exception
                    imgui.end_menu()
                imgui.end_menu_bar()
            imgui.end()
        except Exception:
            print("exception caught, but too late!")

    if active["popup"]:
        imgui.begin("Example: simple popup")
        if imgui.button("select"):
            imgui.open_popup("select-popup")
        imgui.same_line()
        if imgui.begin_popup("select-popup"):
            imgui.text("Select one")
            imgui.separator()
            imgui.selectable("One")
            imgui.selectable("Two")
            imgui.selectable("Three")
            imgui.end_popup()
        imgui.end()

    if active["popup modal"]:
        imgui.begin("Example: simple popup modal")
        if imgui.button("Open Modal popup"):
            imgui.open_popup("select-popup-modal")
        imgui.same_line()
        if imgui.begin_popup_modal("select-popup-modal")[0]:
            imgui.text("Select an option:")
            imgui.separator()
            imgui.selectable("One")
            imgui.selectable("Two")
            imgui.selectable("Three")
            imgui.end_popup()
        imgui.end()

    if active["popup context item"]:
        imgui.begin("Example: popup context view")
        imgui.text("Right-click to set value.")
        if imgui.begin_popup_context_item("Item Context Menu"):
            imgui.selectable("Set to Zero")
            imgui.end_popup()
        imgui.end()

    if active["popup context window"]:
        imgui.begin("Example: popup context window")
        if imgui.begin_popup_context_window():
            imgui.selectable("Clear")
            imgui.end_popup()
        imgui.end()

    if active["popup context void"]:
        if imgui.begin_popup_context_void():
            imgui.selectable("Clear")
            imgui.end_popup()

    if active["drag drop"]:
        imgui.begin("Example: drag and drop")
        imgui.button('source')
        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('itemtype', b'payload')
            imgui.button('dragged source')
            imgui.end_drag_drop_source()
        imgui.button('dest')
        if imgui.begin_drag_drop_target():
            payload = imgui.accept_drag_drop_payload('itemtype')
            if payload is not None:
                print('Received:', payload)
            imgui.end_drag_drop_target()
        imgui.end()

    if active["group"]:
        imgui.begin("Example: item groups")
        imgui.begin_group()
        imgui.text("First group (buttons):")
        imgui.button("Button A")
        imgui.button("Button B")
        imgui.end_group()
        imgui.same_line(spacing=50)
        imgui.begin_group()
        imgui.text("Second group (text and bullet texts):")
        imgui.bullet_text("Bullet A")
        imgui.bullet_text("Bullet B")
        imgui.end_group()
        imgui.end()

    if active["tab bar"]:
        imgui.begin("Example Tab Bar")
        if imgui.begin_tab_bar("MyTabBar"):
            if imgui.begin_tab_item("Item 1")[0]:
                imgui.text("Here is the tab content!")
                imgui.end_tab_item()
            if imgui.begin_tab_item("Item 2")[0]:
                imgui.text("Another content...")
                imgui.end_tab_item()
            global opened_state
            selected, opened_state = imgui.begin_tab_item("Item 3", opened=opened_state)
            if selected:
                imgui.text("Hello Saylor!")
                imgui.end_tab_item()
            imgui.end_tab_bar()
        imgui.end()

    if active["list box"]:
        imgui.begin("Example: custom listbox")
        if imgui.begin_list_box("List", 200, 100):
            imgui.selectable("Selected", True)
            imgui.selectable("Not Selected", False)
            imgui.end_list_box()
        imgui.end()

    if active["table"]:
        imgui.begin("Example: table")
        if imgui.begin_table("data", 2):
            imgui.table_next_column()
            imgui.table_header("A")
            imgui.table_next_column()
            imgui.table_header("B")

            imgui.table_next_row()
            imgui.table_next_column()
            imgui.text("123")

            imgui.table_next_column()
            imgui.text("456")

            imgui.table_next_row()
            imgui.table_next_column()
            imgui.text("789")

            imgui.table_next_column()
            imgui.text("111")

            imgui.table_next_row()
            imgui.table_next_column()
            imgui.text("222")

            imgui.table_next_column()
            imgui.text("333")
            imgui.end_table()
        imgui.end()
예제 #22
0
def main():
    import imgui
    import imguihelper
    import _nx
    import runpy
    from imgui.integrations.nx import NXRenderer

    renderer = NXRenderer()
    currentDir = os.getcwd()
    while True:
        renderer.handleinputs()

        imgui.new_frame()

        width, height = renderer.io.display_size
        imgui.set_next_window_size(width, height)
        imgui.set_next_window_position(0, 0)
        imgui.begin("PyLaylist Maker", 
            flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS
        )
        imgui.set_window_font_scale(2.0)
        imgui.begin_group()
        imgui.text("Welcome to Pylaylist Maker for RetroArch!\nTouch is supported\nSettings:")
        imgui.text("RetroArch Path: {}\nRoms Path: {}\nPlaylists Path: {}"
            .format(Settings["retroarchPATH"],Settings["romsPaths"][Settings["indexRomPathUsed"]],Settings["playlistsPath"]))
        imgui.push_style_color(imgui.COLOR_BUTTON, *STRING_COLOR)
        if imgui.button("Toggle Roms Path"):
            Settings["indexRomPathUsed"] = 0 if Settings["indexRomPathUsed"]==1 else 1
            updateSettings()
        imgui.pop_style_color(1)
        imgui.same_line()
        
        if Settings["useAllExtentions"]:
            imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_TRUE_COLOR )
        else:
            imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_FALSE_COLOR )
        if imgui.button("Use All Extentions: "+("True" if Settings["useAllExtentions"] else "False")):
            Settings["useAllExtentions"] = not Settings["useAllExtentions"]
            updateSettings()
        imgui.pop_style_color(1)

        if Settings["useShorthandName"]:
            imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_TRUE_COLOR )
        else:
            imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_FALSE_COLOR )
        if imgui.button("Use Shorthand Name: "+("True" if Settings["useShorthandName"] else "False")):
            Settings["useShorthandName"] = not Settings["useShorthandName"]
            updateSettings()
        imgui.pop_style_color(1)
        imgui.same_line()

        if Settings["makeJsonPlaylists"]:
            imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_TRUE_COLOR )
        else:
            imgui.push_style_color(imgui.COLOR_BUTTON, *BOOL_FALSE_COLOR )
        if imgui.button("Generate Json Playlists: "+("True" if Settings["makeJsonPlaylists"] else "False")):
            Settings["makeJsonPlaylists"] = not Settings["makeJsonPlaylists"]
            updateSettings()
        imgui.pop_style_color(1)
        imgui.end_group()
        imgui.separator()
        imgui.begin_group()
        imgui.text("Commands")
        
        imgui.push_style_color(imgui.COLOR_BUTTON, *STRING_COLOR)
        if imgui.button("Validate/Generate Folders"):
            validateFolders()
            logger.info("Folders Validated")
            
        imgui.pop_style_color(1)
        imgui.text("THIS WILL ADD A BUNCH OF FOLDERS TO YOUR ROM PATH!")

        imgui.push_style_color(imgui.COLOR_BUTTON, *STRING_COLOR)
        if imgui.button("Generate/Update Playlists"):
            generatePlaylist()
            logger.info("Complete")
        imgui.pop_style_color(1)
        imgui.text("THIS WILL MODIFY PLAYLISTS, MAKE BACKUPS FIRST!")
        imgui.text("State: "+state+"\n\n\n")
        quitme = False
        """imgui.push_style_color(imgui.COLOR_BUTTON, *STRING_COLOR)
        if imgui.button("Quit"):
            quitme = True
        imgui.pop_style_color(1)
        """
        imgui.end_group()
        imgui.end()


        imgui.render()
        renderer.render()
        if quitme:
            break
    renderer.shutdown()
    return 0
예제 #23
0
    def srender(self):
        # Create a GUI group
        imgui.begin_group()
        """
        NEW ROW STARTS HERE ROW #1
        """
        for i in range(5):
            self.placeholder()
            imgui.same_line()
        self.placeholder()
        """
        NEW ROW STARTS HERE ROW #2
        """
        for i in range(5):
            self.placeholder()
            imgui.same_line()
        self.placeholder()
        """
        NEW ROW STARTS HERE ROW #3
        """

        for i in range(5):
            self.placeholder()
            imgui.same_line()
        self.placeholder()
        """
        NEW ROW STARTS HERE ROW #4
        """

        for i in range(5):
            self.placeholder()
            imgui.same_line()
        self.placeholder()
        """
        NEW ROW STARTS HERE ROW #5
        """
        # TESTS
        """
        Give code for a long list, test long outputs        
        """
        # Give a style to the button
        imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY)
        # Create a button "Long Output"
        if imgui.button("Long Output",
                        width=self.BTN_WIDTH,
                        height=self.BTN_HEIGHT):
            # Execute code when button is pressed
            self.input = "dpaste:>>070KVYA"
        # push style
        imgui.pop_style_color(1)

        imgui.same_line()
        """
        Test SSL
        """
        # Give a style to the button
        imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY)
        # Create a button "Test SSL"
        if imgui.button("Test SSL",
                        width=self.BTN_WIDTH,
                        height=self.BTN_HEIGHT):
            # Execute code when button is pressed
            self.input = "dpaste:>>0P6AH88"
        # push style
        imgui.pop_style_color(1)

        imgui.same_line()
        """
        import this        
        """
        # Give a style to the button
        imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY)
        # Create a button "Import this"
        if imgui.button("Import this",
                        width=self.BTN_WIDTH,
                        height=self.BTN_HEIGHT):
            # Execute code when button is pressed
            self.input = "dpaste:>>1441C4D"
        # push style
        imgui.pop_style_color(1)

        imgui.same_line()
        """
        for loop      
        """
        # Give a style to the button
        imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_LGRAY)
        # Create a button "For loop this"
        if imgui.button("For loop",
                        width=self.BTN_WIDTH,
                        height=self.BTN_HEIGHT):
            # Execute code when button is pressed
            self.input = "dpaste:>>2BTR5CV"
        # push style
        imgui.pop_style_color(1)

        for i in range(2):
            imgui.same_line()
            self.placeholder()

        imgui.end_group()
예제 #24
0
    def gui_newFrame(self):
        imgui.new_frame()
        imgui.begin("Properties", True)

        changed, self.pause = imgui.checkbox("Paused", self.pause)
        imgui.new_line()

        changed, self.map_type = imgui.combo(
            "Map Type", self.map_type, ["CubeT", "Cube", "Sphere", "SphereT"])

        changed, self.map_size = imgui.drag_int(
            label="Map Size",
            value=self.map_size,
            change_speed=0.1,
            min_value=10,
            max_value=100,
        )

        changed, new_boid_count = imgui.drag_int(label="Boid Count",
                                                 value=self.boid_count,
                                                 change_speed=100,
                                                 min_value=1,
                                                 max_value=self.max_boids)
        if changed:
            self.resize_boids_buffer(new_boid_count)

        imgui.new_line()

        changed, self.speed = imgui.drag_float(label="Speed",
                                               value=self.speed,
                                               change_speed=0.0005,
                                               min_value=0.001,
                                               max_value=0.5,
                                               format="%.3f")

        changed, self.view_distance = imgui.drag_float(
            label="View Distance",
            value=self.view_distance,
            change_speed=0.001,
            min_value=0.0,
            max_value=10.0,
            format="%.2f")

        changed, self.view_angle = imgui.drag_float(label="View Angle",
                                                    value=self.view_angle,
                                                    change_speed=0.001,
                                                    min_value=0.0,
                                                    max_value=pi,
                                                    format="%.2f")

        changed, self.separation_force = imgui.drag_float(
            label="Separation Force",
            value=self.separation_force,
            change_speed=0.002,
            min_value=0.0,
            max_value=10.0,
            format="%.2f")

        changed, self.alignment_force = imgui.drag_float(
            label="Aligment Force",
            value=self.alignment_force,
            change_speed=0.002,
            min_value=0.0,
            max_value=10.0,
            format="%.2f")

        changed, self.cohesion_force = imgui.drag_float(
            label="Cohesion Force",
            value=self.cohesion_force,
            change_speed=0.002,
            min_value=0.0,
            max_value=10.0,
            format="%.2f")

        imgui.new_line()
        imgui.begin_group()
        imgui.text("Custom profiles:")
        if (imgui.button("Profile 1")):
            self.set_custom_profile_1()
        if (imgui.button("Profile 2")):
            self.set_custom_profile_2()
        imgui.end_group()

        imgui.end()
예제 #25
0
def draw_ui():
    """ Draws the imgui UI """
    global g_cube
    global g_cam
    global g_light_1
    global g_light_color_1
    global g_light_2
    global g_light_color_2
    global g_light_3
    global g_light_color_3
    global g_light_4
    global g_light_color_4
    global g_ambi_color
    global g_spec_color
    global g_fog_color
    global g_fog_density
    global g_fog_height
    global g_fog_max

    global g_move_string

    btn_w = 25
    imgui.set_window_font_scale(1.2)

    _, g_cam = imgui.slider_float3(
        "Camera Position", *g_cam, min_value=-20.0, max_value=150.0)
    g_cam = list(g_cam)

    expanded, _ = imgui.collapsing_header("Controls", True)
    if expanded:
        # Rubiks Cube Moves
        imgui.begin_group()
        imgui.text("Moves:")

        add_move_buttons("F", g_cube.move_f, btn_w)
        imgui.same_line(spacing=20)
        add_move_buttons("B", g_cube.move_b, btn_w)
        add_move_buttons("R", g_cube.move_r, btn_w)
        imgui.same_line(spacing=20)
        add_move_buttons("L", g_cube.move_l, btn_w)
        add_move_buttons("U", g_cube.move_u, btn_w)
        imgui.same_line(spacing=20)
        add_move_buttons("D", g_cube.move_d, btn_w)

        imgui.end_group()

        imgui.same_line(spacing=50)

        # Cube Rotations
        imgui.begin_group()
        imgui.text("Rotations:")
        add_move_buttons("x", g_cube.rotate_x, btn_w)
        add_move_buttons("y", g_cube.rotate_y, btn_w)
        add_move_buttons("z", g_cube.rotate_z, btn_w)
        imgui.end_group()

        _, g_move_string = imgui.core.input_text("", g_move_string, 64)
        imgui.same_line(spacing=10)
        clicked = imgui.button("Perform")
        if clicked:
            parse_moves()

    expanded, _ = imgui.collapsing_header("View Settings", True)
    if expanded:
        # Light 1
        expanded, _ = imgui.collapsing_header("Light 1", True)
        if expanded:
            _, g_light_1 = imgui.slider_float3(
                "Position 1", *g_light_1, min_value=-20.0, max_value=20.0)
            _, g_light_color_1 = imgui.color_edit3("Colour 1", *g_light_color_1)
            g_light_1 = list(g_light_1)
            g_light_color_1 = list(g_light_color_1)
        # Light 2
        expanded, _ = imgui.collapsing_header("Light 2", True)
        if expanded:
            _, g_light_2 = imgui.slider_float3(
                "Position 2", *g_light_2, min_value=-20.0, max_value=20.0)
            _, g_light_color_2 = imgui.color_edit3("Colour 2", *g_light_color_2)
            g_light_2 = list(g_light_2)
            g_light_color_2 = list(g_light_color_2)
        # Light 3
        expanded, _ = imgui.collapsing_header("Light 3", True)
        if expanded:
            _, g_light_3 = imgui.slider_float3(
                "Position 3 ", *g_light_3, min_value=-20.0, max_value=20.0)
            _, g_light_color_3 = imgui.color_edit3("Colour 3", *g_light_color_3)
            g_light_3 = list(g_light_3)
            g_light_color_3 = list(g_light_color_3)
        # Light 4
        expanded, _ = imgui.collapsing_header("Light 4", True)
        if expanded:
            _, g_light_4 = imgui.slider_float3(
                "Position 4", *g_light_4, min_value=-20.0, max_value=20.0)
            _, g_light_color_4 = imgui.color_edit3("Colour 4", *g_light_color_4)
            g_light_4 = list(g_light_4)
            g_light_color_4 = list(g_light_color_4)
        # Other Light constants
        expanded, _ = imgui.collapsing_header("Other Lighting", True)
        if expanded:
            _, g_ambi_color = imgui.color_edit3("Ambient Light Colour",
                                                *g_ambi_color)
            _, g_spec_color = imgui.color_edit3("Specular Light Colour",
                                                *g_spec_color)
            g_ambi_color = list(g_ambi_color)
            g_spec_color = list(g_spec_color)
        expanded, _ = imgui.collapsing_header("Fog Settings", True)
        if expanded:
            _, g_fog_color = imgui.color_edit3("Fog Colour", *g_fog_color)
            g_fog_color = list(g_fog_color)
            _, g_fog_density = imgui.input_float("Fog Density Coefficient",
                                                 g_fog_density)
            _, g_fog_height = imgui.input_float("Fog Height Coefficient",
                                                g_fog_height)
            _, g_fog_max = imgui.input_float("Max Fog", g_fog_max)
예제 #26
0
def main():
    global ERROR
    renderer = NXRenderer()
    currentDir = os.getcwd()

    while True:
        renderer.handleinputs()

        imgui.new_frame()

        width, height = renderer.io.display_size
        imgui.set_next_window_size(width, height)
        imgui.set_next_window_position(0, 0)
        imgui.begin("",
                    flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE
                    | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS)
        imgui.begin_group()

        imgui.text("Welcome to PyNX!")
        imgui.text("Touch is supported")
        imgui.text("Current dir: " + os.getcwd())

        if os.getcwd() != "sdmc:/":
            imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR)
            if imgui.button("../", width=200, height=60):
                os.chdir("..")
            imgui.pop_style_color(1)

        dirs = []
        files = []
        for e in os.listdir():
            if os.path.isdir(e):
                dirs.append(e)
            else:
                files.append(e)

        dirs = sorted(dirs)
        files = sorted(files)

        for e in dirs:
            imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR)
            if imgui.button(e + "/", width=200, height=60):
                os.chdir(e)
            imgui.pop_style_color(1)

        for e in files:
            if e.endswith(".py"):
                imgui.push_style_color(imgui.COLOR_BUTTON, *PYFILE_COLOR)
            else:
                imgui.push_style_color(imgui.COLOR_BUTTON, *FILE_COLOR)

            if imgui.button(e, width=200, height=60) and e.endswith(".py"):
                run_python_module(e)

            imgui.pop_style_color(1)

        imgui.end_group()
        # end of file picker

        imgui.same_line(spacing=50)
        imgui.begin_group()
        imgui.text("Utils:")

        imgui.push_style_color(imgui.COLOR_BUTTON, *APP_COLOR)
        if imgui.button("Interactive Python", width=200, height=60):
            t = Terminal()
            t.main()
        imgui.pop_style_color(1)

        imgui.end_group()

        imgui.end()

        if ERROR:
            imgui.set_next_window_size(width, height)
            imgui.set_next_window_position(0, 0)
            imgui.begin("ERROR",
                        flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE
                        | imgui.WINDOW_NO_SAVED_SETTINGS)
            imgui.text(str(ERROR))
            if imgui.button("OK", width=200, height=60):
                ERROR = ""
            imgui.end()

        imgui.render()
        renderer.render()

    renderer.shutdown()
예제 #27
0
def main():
    global width_library
    global width_shematic
    global width_context
    global height_window

    global previous_key_callback
    global selected_link
    global selected_node
    global iggraph
    global node_library
    global debug_is_mouse_dragging
    
    global show_debug_window

    # states -------------------------
    
    scrolling = imgui.Vec2(0, 0)

    iggraph = IGGraph(node_library)

    # iggraph.reset()

    node_hovered_in_scene = -1
    parameter_link_start = None
    selected_parameter = None

    io_hovered = None 
    io_anchors_width_not_hovered = 10
    io_anchors_width_hovered = 15 
    right_splitter_is_active = False
    left_splitter_is_active = False
    
    image_width = 0
    image_height = 0
    image_texture = None

    # states -------------------------

    imgui.create_context()
    window = impl_glfw_init()
    impl = GlfwRenderer(window)
    io = imgui.get_io()
    previous_key_callback = glfw.set_key_callback(window,key_event)
    init_textures()

    assign_parameter_colors(node_library)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        impl.process_inputs()

        imgui.new_frame()
        if imgui.begin_main_menu_bar():
            if imgui.begin_menu("File", True):
                clicked_new, selected_new = imgui.menu_item(
                    "New", 'Cmd+N', False, True
                )
                if clicked_new:
                    iggraph = IGGraph(node_library)
                clicked_load, selected_load = imgui.menu_item(
                    "Load", 'Cmd+L', False, True
                )
                if clicked_load:
                    root = tk.Tk()
                    root.withdraw()
                    filename = filedialog.askopenfilename()
                    if filename :
                        f=open(filename)
                        iggraph.from_json(json.load(f))
                        f.close()
                clicked_save, selected_save = imgui.menu_item(
                    "Save", 'Cmd+S', False, True
                )
                if clicked_save:
                    iggraph.reset()
                    graph_json = iggraph.to_json()
                    text2save = json.dumps(graph_json, indent=4, sort_keys=True)
                    root = tk.Tk()
                    root.withdraw()
                    f = filedialog.asksaveasfile(mode='w', defaultextension=".json")
                    if f is None: # asksaveasfile return `None` if dialog closed with "cancel".
                        return
                    f.write(text2save)
                    f.close()
                clicked_quit, selected_quit = imgui.menu_item(
                    "Quit", 'Cmd+Q', False, True
                )
                if clicked_quit:
                    exit(0)
                imgui.end_menu()
            if imgui.begin_menu("Debug", True):
                show_debug_window_clicked,  show_debug_window_selected = imgui.menu_item(
                    "Show Debug window", 'Cmd+D', show_debug_window, True
                )
                if show_debug_window_clicked:
                    show_debug_window = not show_debug_window
                catch_exceptions_clicked,  catch_exceptions_selected = imgui.menu_item(
                    "Catch Exceptions", '', iggraph.catch_exceptions, True
                )
                if catch_exceptions_clicked:
                    iggraph.catch_exceptions = not iggraph.catch_exceptions
                imgui.separator()
                imgui.menu_item(
                    "Examples", '', False, False
                )
                show_example_mosaic_clicked,  show_example_mosaic_selected = imgui.menu_item(
                    "Mosaic", '', False, True
                )
                if show_example_mosaic_clicked:
                    example_mosaic(iggraph)
                imgui.end_menu()
            imgui.end_main_menu_bar()

        height_window = io.display_size.y - 18  # imgui.get_cursor_pos_y()

        imgui.push_style_var(imgui.STYLE_ITEM_SPACING, imgui.Vec2(0,0))
        imgui.set_next_window_size(io.display_size.x, height_window)
        imgui.set_next_window_position(0, 18)
        imgui.push_style_var(imgui.STYLE_WINDOW_ROUNDING, 0)
        imgui.begin("Splitter test", False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS)
        imgui.pop_style_var()
        imgui.pop_style_var()

        width_shematic = io.display_size.x - separator_width  - width_context - separator_width - width_library

        # ==============================================================================
        # Library
        # ==============================================================================

        imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0)
        imgui.begin_child("Library", width_library, 0, True)
        for node_name in node_library.nodes:
            if imgui.button(node_name, width_library):
                iggraph.create_node(node_name)
        imgui.end_child()
        imgui.pop_style_var()

        imgui.same_line()
        imgui.button("left_splitter", separator_width, height_window - 20)
        left_splitter_is_active = imgui.is_item_active()
        if (left_splitter_is_active):
            width_library += io.mouse_delta.x
            scrolling = imgui.Vec2(scrolling.x - io.mouse_delta.x, scrolling.y)
        if (imgui.is_item_hovered()):
            imgui.set_mouse_cursor(imgui.MOUSE_CURSOR_RESIZE_EW)
        
        imgui.same_line()

        # ==============================================================================
        # Shematic
        # ==============================================================================
        imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0)
        imgui.begin_child("shematic", width_shematic, 0, True)

        if show_inputs_popup(iggraph):
            imgui.open_popup("Outputs")
        show_outputs_popup(iggraph)

        # create our child canvas
        if iggraph.get_state() == iggraph.STATE_IDLE:
            imgui.text("status: edit | ")
        elif iggraph.get_state() == iggraph.STATE_RUNNING:
            imgui.text("status: run  | ")
        imgui.same_line()
        if iggraph.get_state() == iggraph.STATE_IDLE:
            if imgui.button("run"):
                #TODO if not running
                iggraph.set_state(iggraph.STATE_RUNNING)
                iggraph.prepare_to_run()
                imgui.open_popup("User Input")
            imgui.same_line()
            if imgui.button("run one step"):
                iggraph.set_state(iggraph.STATE_RUNNING)
                iggraph.prepare_to_run()
                iggraph.run_one_step()
        elif iggraph.get_state() == iggraph.STATE_RUNNING:
            if imgui.button("stop running"):
                iggraph.reset()
                iggraph.set_state(iggraph.STATE_IDLE)
            imgui.same_line()
            if imgui.button("run one step"):
                iggraph.set_state(iggraph.STATE_RUNNING)
                iggraph.run_one_step()
        # imgui.same_line(imgui.get_window_width() - 100)
        imgui.push_style_var(imgui.STYLE_FRAME_PADDING, imgui.Vec2(1, 1))
        imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, imgui.Vec2(0, 0))
        imgui.begin_child("scrolling_region", 0, 0, True, imgui.WINDOW_NO_SCROLLBAR | imgui.WINDOW_NO_MOVE)
        imgui.pop_style_var()
        imgui.pop_style_var()
        imgui.push_item_width(120.0)

        offset = add(imgui.get_cursor_screen_pos(), scrolling)
        draw_list = imgui.get_window_draw_list()

        # Display links
        draw_list.channels_split(2)
        draw_list.channels_set_current(0)
        for link in iggraph.links:
            draw_link_param_to_param(draw_list, offset, link.output_parameter, link.input_parameter, selected_link == link)

        # Display nodes
        parameter_link_end = None
        one_parameter_hovered = False
        one_node_moving_active = False
        for node in iggraph.nodes:
            imgui.push_id(str(node.id))
            node_rect_min = add(offset, node.pos)
            draw_list.channels_set_current(1) # foreground
            old_any_active = imgui.is_any_item_active()

            #display node content first
            # todo
            test = add(node_rect_min, NODE_WINDOW_PADDING)
            imgui.set_cursor_screen_position(add(node_rect_min, NODE_WINDOW_PADDING))
            imgui.begin_group()
            imgui.text("")
            imgui.text(node.name)
            imgui.text("")
            imgui.end_group()

            # save size
            node_widgets_active = False # (not old_any_active and imgui.is_any_item_active())
            node.size = add( add( imgui.get_item_rect_size(), NODE_WINDOW_PADDING) , NODE_WINDOW_PADDING)
            node_rect_max = add(node.size, node_rect_min) 
            
            #display node box
            draw_list.channels_set_current(0) # background
            imgui.set_cursor_screen_position(node_rect_min)
            imgui.invisible_button(str(node.id), node.size.x, node.size.y)
            if imgui.is_item_hovered():
                node_hovered_in_scene = node.id
            else:
                node_hovered_in_scene = None
            node_moving_active = imgui.is_item_active()
            use_hovered_color = node_hovered_in_scene or selected_node == node
            draw_list.add_rect_filled(node_rect_min.x, node_rect_min.y, node_rect_max.x, node_rect_max.y, get_node_color(node, iggraph, use_hovered_color), 5)
            if node_hovered_in_scene and iggraph.is_error(node):
                imgui.begin_tooltip()
                imgui.text(iggraph.error_nodes[node])
                imgui.end_tooltip()

            # input parameters
            for parameter_name in node.inputs:
                parameter = node.inputs[parameter_name]
                center = node.get_intput_slot_pos(parameter)
                center_with_offset = add(offset, center)
                if io_hovered == parameter:
                    io_anchors_width = io_anchors_width_hovered
                else:
                    io_anchors_width = io_anchors_width_not_hovered
                imgui.set_cursor_pos(imgui.Vec2(center.x-io_anchors_width/2, center.y-io_anchors_width/2))
                imgui.push_id(str(str(node.id) + "input" + parameter.id))
                if (imgui.invisible_button("input", io_anchors_width, io_anchors_width)):
                    selected_parameter = parameter
                # imgui.is_item_hovered() does not work when dragging
                is_hovering = ((io.mouse_pos.x-offset.x>center.x-io_anchors_width/2) and 
                               (io.mouse_pos.x-offset.x<center.x+io_anchors_width/2) and
                               (io.mouse_pos.y-offset.y>center.y-io_anchors_width/2) and
                               (io.mouse_pos.y-offset.y<center.y+io_anchors_width/2))
                if is_hovering:
                    io_hovered = parameter
                    one_parameter_hovered = True
                    imgui.begin_tooltip()
                    imgui.text(parameter_name)
                    imgui.end_tooltip()
                if is_hovering and imgui.is_mouse_released(0):
                    parameter_link_end = parameter
                imgui.pop_id()
                draw_list.add_circle_filled(center_with_offset.x, center_with_offset.y, io_anchors_width/2, get_parameter_color(parameter))

            # output parameters
            for parameter_name in node.outputs:
                parameter = node.outputs[parameter_name]
                center = node.get_output_slot_pos(parameter)
                center_with_offset = add(offset, center)
                if io_hovered == parameter:
                    io_anchors_width = io_anchors_width_hovered
                else:
                    io_anchors_width = io_anchors_width_not_hovered
                imgui.set_cursor_pos(imgui.Vec2(center.x-io_anchors_width/2, center.y-io_anchors_width/2))
                imgui.push_id(str(str(node.id) + "output" + parameter.id))
                if (imgui.invisible_button("output", io_anchors_width, io_anchors_width)):
                    selected_parameter = parameter
                is_hovering = ((io.mouse_pos.x-offset.x>center.x-io_anchors_width/2) and 
                    (io.mouse_pos.x-offset.x<center.x+io_anchors_width/2) and
                    (io.mouse_pos.y-offset.y>center.y-io_anchors_width/2) and
                    (io.mouse_pos.y-offset.y<center.y+io_anchors_width/2))
                if is_hovering:
                    io_hovered = parameter
                    one_parameter_hovered = True
                    imgui.begin_tooltip()
                    imgui.text(parameter_name)
                    imgui.end_tooltip()
                draw_list.add_circle_filled(center_with_offset.x, center_with_offset.y, io_anchors_width/2, get_parameter_color(parameter))
                imgui.pop_id()
                # cannot use imgui.is_item_active, seems buggy with the scroll
                if is_hovering and imgui.is_mouse_down(0):
                    parameter_link_start = parameter

            if node_widgets_active or node_moving_active:
                selected_node = node
                one_node_moving_active = True
            if node_moving_active and imgui.is_mouse_dragging(0) and node.id==selected_node.id:
               node.pos = add(node.pos, io.mouse_delta)

            debug_is_mouse_dragging = imgui.is_mouse_dragging(0)

            imgui.pop_id()
        draw_list.channels_merge()
        if not one_parameter_hovered:
            io_hovered = None

        # scrolling
        mouse_is_in_schematic = (io.mouse_pos.x > width_library) and\
                                (io.mouse_pos.x < (width_library + width_shematic)) and\
                                (io.mouse_pos.y < height_window) and\
                                (io.mouse_pos.y > 18)
        if not one_node_moving_active and\
           not parameter_link_start and\
           imgui.is_mouse_dragging(0) and\
           mouse_is_in_schematic and\
           not left_splitter_is_active and\
           not right_splitter_is_active and\
           imgui.is_window_focused():
            scroll_offset = imgui.Vec2(io.mouse_delta.x, io.mouse_delta.y)
            scrolling = add(scrolling, scroll_offset)
        # link creation
        if parameter_link_start and parameter_link_end:
            iggraph.add_link(parameter_link_start, parameter_link_end)
        # creating link
        elif parameter_link_start and imgui.is_mouse_dragging(0):
            draw_link_param_to_point(draw_list, offset, parameter_link_start, io.mouse_pos.x, io.mouse_pos.y, True)
        # mouse release
        if imgui.is_mouse_released(0):
            parameter_link_start = None

        imgui.pop_item_width()
        imgui.end_child()

        # mouse click on the scene
        if imgui.is_mouse_clicked(0):
            mouse_pos = imgui.get_mouse_pos()
            local_mouse_pos = imgui.Vec2(mouse_pos.x - offset.x, mouse_pos.y - offset.y)
            selected_link = None
            for link in iggraph.links:
                start_node = link.output_parameter.owner
                start_pos = start_node.get_output_slot_pos(link.output_parameter)
                end_node = link.input_parameter.owner
                end_pos = end_node.get_intput_slot_pos(link.input_parameter)
                distance_mouse_start = math.sqrt(((local_mouse_pos.x-start_pos.x)**2) + ((local_mouse_pos.y-start_pos.y)**2))
                distance_mouse_end = math.sqrt(((local_mouse_pos.x-end_pos.x)**2) + ((local_mouse_pos.y-end_pos.y)**2))
                distance_start_end = math.sqrt(((start_pos.x-end_pos.x)**2) + ((start_pos.y-end_pos.y)**2))
                if ((distance_mouse_start + distance_mouse_end) - distance_start_end) < 0.1:
                    selected_link = link
                
        imgui.end_child()
        imgui.pop_style_var()

        imgui.same_line()
        imgui.button("right_splitter", separator_width, height_window - 20)
        right_splitter_is_active = imgui.is_item_active()
        if (right_splitter_is_active):
            width_context -= io.mouse_delta.x
        if (imgui.is_item_hovered()):
            imgui.set_mouse_cursor(imgui.MOUSE_CURSOR_RESIZE_EW)

        # ==============================================================================
        # Context
        # ==============================================================================

        imgui.same_line()
        imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0)
        imgui.begin_child("child3", width_context, 0, True);
        if selected_node:
            if selected_node.handle_dynamic_parameters():
                if imgui.button("add parameter"):
                    selected_node.add_dynamic_parameter()
            if imgui.tree_node("Inputs"):
                for parameter_name in selected_node.inputs:
                    parameter = selected_node.inputs[parameter_name]
                    if imgui.tree_node(parameter.id):
                        display_parameter(parameter, True)
                        imgui.tree_pop()
                imgui.tree_pop()
            if imgui.tree_node("Output"):
                for parameter_name in selected_node.outputs:
                    parameter = selected_node.outputs[parameter_name]
                    if imgui.tree_node(parameter.id):
                        display_parameter(parameter, False)
                        imgui.tree_pop()
                imgui.tree_pop()
        imgui.end_child()
        imgui.pop_style_var()

        # 
        imgui.end()

        # ==============================================================================
        # Debug Window
        # ==============================================================================
        if show_debug_window:
            debug_window_expanded, show_debug_window = imgui.begin("Debug", True)
            if parameter_link_start:
                imgui.text("parameter_link_start: " + parameter_link_start.id)
            else:
                imgui.text("parameter_link_start: " + "None")
            if selected_parameter:
                imgui.text("selected_parameter: " + selected_parameter.id)
            else:
                imgui.text("selected_parameter: " + "None")
            imgui.text("is_mouse_dragging: " + str(debug_is_mouse_dragging))
            imgui.text("mouse: (" + str(io.mouse_pos.x) + ", " + str(io.mouse_pos.y) + ")")
            imgui.end()

        gl.glClearColor(1., 1., 1., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()
        impl.render(imgui.get_draw_data())
        glfw.swap_buffers(window)

    impl.shutdown()
    glfw.terminate()
예제 #28
0
def main():
    pygame.init()

    size = 800, 600

    screen = pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL)

    io = imgui.get_io()
    io.fonts.add_font_default()
    io.display_size = size

    renderer = PygameRenderer()

    clock = pygame.time.Clock()

    ## Test #######
    # Setup OpenGL for 2D rendering
    glEnable(GL_TEXTURE_2D)
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0.0, size[0], size[1], 0.0) # Important
    glMatrixMode(GL_MODELVIEW)
    
    # new pygame.Surface
    test = pygame.Surface((300, 300))
    test_x = 100
    test_y = 100
    test.fill((255, 0, 0))
    tex_id = None

    # pygame surface to OpenGL tex
    ix, iy = test.get_width(), test.get_height()
    image = pygame.image.tostring(test, "RGBA", True)
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
    tex_id = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, tex_id)
    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    ###############

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                sys.exit()

            renderer.process_event(event)

        # Start frame
        imgui.new_frame()

        if imgui.begin_main_menu_bar():
            if imgui.begin_menu("File", True):

                clicked_quit, selected_quit = imgui.menu_item(
                    "Quit", 'Cmd+Q', False, True
                )

                if clicked_quit:
                    exit(1)

                imgui.end_menu()
            imgui.end_main_menu_bar()

        global cb_another, w_closable, dg_val

        if imgui.begin("Main window")[1]:
            imgui.begin_child("aaa", 300 , -10, border=False)
            imgui.begin_group()
            
            imgui.text("Toggle")

            _, cb_another = imgui.checkbox("Another Window", cb_another)
            imgui.text("Another Window state = {}".format(cb_another))

            w_closable = cb_another

            imgui.end_group()

            imgui.begin_group()
            imgui.text("Example: drag float")
            changed, test_x = imgui.drag_float(
                "test_x", test_x,
            )
            changed, test_y = imgui.drag_float(
                "test_y", test_y,
            )

            imgui.text("Changed: {}, x: {:.2f} y: {:.2f}".format(changed, test_x, test_y))
            imgui.end_group()

            imgui.end_child()
            imgui.end()

        # Disable perm
        if w_closable:
            _, w_closable = imgui.begin("Another window", False) # return (collapse, state)
            imgui.text("Bar")
            imgui.text_colored("Eggs", 0.2, 1., 0.)
            imgui.text("AAAA")
            imgui.end()

        # Clean screen
        glClearColor(0.5, 0.5, 0.5, 1)
        glClear(GL_COLOR_BUFFER_BIT)
        
        ## Draw ##########
        x = test_x
        y = test_y
        w = test.get_width()
        h = test.get_height()

        # Prepare the matrix
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glTranslatef(x, y, 0.0) # shift to (x, y)
        glBindTexture(GL_TEXTURE_2D, tex_id)

        # Actual draw
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 0.0,  0.0) # Left top
        glTexCoord2f(1.0, 1.0); glVertex3f(w,  0.0,  0.0)  # Right top
        glTexCoord2f(1.0, 0.0); glVertex3f(w, h,  0.0)     # Right bottom
        glTexCoord2f(0.0, 0.0); glVertex3f(0.0, h,  0.0)   # Left bottom
        glEnd()
        ##################

        imgui.render()

        pygame.display.flip()
        clock.tick(60)
예제 #29
0
def main(collections):

    global ERROR
    renderer = NXRenderer()

    while True:
        renderer.handleinputs()

        imgui.new_frame()

        width, height = renderer.io.display_size
        imgui.set_next_window_size(width, height)
        imgui.set_next_window_position(0, 0)
        imgui.begin("",
                    flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE
                    | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS)

        imgui.push_style_color(imgui.COLOR_TEXT, *TEXT_COLOR)
        imgui.push_style_color(imgui.COLOR_BUTTON_HOVERED, *MENU_BUTTON_COLOR)
        imgui.push_style_color(imgui.COLOR_BUTTON_ACTIVE, *MENU_BUTTON_COLOR)
        imgui.begin_group()

        imgui.text("NX-Rom-Market")

        # Create ROMS folder if it doesn't exist
        directory = "Roms"
        parent_dir = "sdmc:/"
        path = os.path.join(parent_dir, directory)
        try:
            os.makedirs(path, exist_ok=True)
        except OSError as error:
            print("Directory '%s' can not be created" % directory)

        for idx, collectionName in enumerate(sorted([*collections])):

            idx % 3 == 0 and imgui.new_line() or imgui.same_line()

            imgui.push_style_color(imgui.COLOR_BUTTON, *COLLECTION_COLOR)
            if imgui.button(collectionName, width=390, height=150):
                rom_list(collections, collectionName)
            imgui.pop_style_color(1)

        imgui.end_group()

        imgui.end()

        if ERROR:
            imgui.set_next_window_size(width, height)
            imgui.set_next_window_position(0, 0)
            imgui.begin("ERROR",
                        flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE
                        | imgui.WINDOW_NO_SAVED_SETTINGS)
            imgui.text(str(ERROR))
            if imgui.button("OK", width=200, height=60):
                ERROR = ""
            imgui.end()

        imgui.render()
        renderer.render()

    renderer.shutdown()
예제 #30
0
def rom_list(collections,
             console_selected,
             prefix='A',
             checkbox_extract=False):
    # clear both buffers
    imguihelper.clear()
    _nx.gfx_set_mode(TILED_DOUBLE)
    clear_terminal()
    imguihelper.initialize()

    renderer = NXRenderer()

    # TODO fetcing indicator
    roms = fetch_roms(collections[console_selected], prefix)

    # create collection rom folder
    directory = "Roms"
    parent_dir = "sdmc:/"
    path = os.path.join(parent_dir, directory, console_selected)
    try:
        os.makedirs(path, exist_ok=True)
    except OSError as error:
        print("Directory '%s' can not be created" % path)

    os.chdir(path)
    dir_content = os.listdir()

    while True:

        renderer.handleinputs()

        imgui.new_frame()

        width, height = renderer.io.display_size
        imgui.set_next_window_size(width, height)
        imgui.set_next_window_position(0, 0)
        imgui.begin("",
                    flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE
                    | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS)

        imgui.begin_group()

        imgui.push_style_color(imgui.COLOR_BUTTON, *MENU_BUTTON_COLOR_SELECTED)
        if imgui.button("< Back", width=70, height=50):
            main(collections)
        imgui.pop_style_color(1)

        imgui.same_line(spacing=50)
        _, checkbox_extract = imgui.checkbox("EXTRACT .ZIP AFTER DOWNLOAD",
                                             checkbox_extract)

        imgui.text("Collection: " + console_selected)

        imgui.new_line()

        for letter in '#' + string.ascii_uppercase:

            button_color = MENU_BUTTON_COLOR_SELECTED if prefix == letter else MENU_BUTTON_COLOR

            imgui.same_line()
            imgui.push_style_color(imgui.COLOR_BUTTON, *button_color)
            if imgui.button(letter, width=28, height=28):
                rom_list(collections, console_selected, letter,
                         checkbox_extract)
            imgui.pop_style_color(1)

        imgui.new_line()
        imgui.begin_child("region", -0, -0, border=True)

        for rom in roms:
            folder_name = os.path.splitext(rom['title'])[0]
            is_downloaded = any(x in dir_content
                                for x in [rom['title'], folder_name])
            button_color = ROM_COLOR_DOWNLOADED if is_downloaded else ROM_COLOR
            imgui.push_style_color(imgui.COLOR_BUTTON, *button_color)
            if imgui.button(rom['title'] + "  " + rom['size'],
                            width=1240,
                            height=30):
                download(rom, console_selected, checkbox_extract)
            imgui.pop_style_color(1)

        imgui.end_child()

        imgui.end_group()

        imgui.end()

        imgui.render()
        renderer.render()

    renderer.shutdown()