Esempio n. 1
0
    def _draw_component(self, entity, component_name, component_name_display):
        if not entity.has_component(component_name):
            return
        treeNodeFlags = imgui.TREE_NODE_DEFAULT_OPEN | imgui.TREE_NODE_FRAMED | imgui.TREE_NODE_ALLOW_ITEM_OVERLAP | imgui.TREE_NODE_FRAME_PADDING
        component = entity.get_component(component_name)
        # contentRegionAvailable = imgui.get_content_region_available()
        # lineHeight =
        imgui.push_style_var(imgui.STYLE_FRAME_PADDING, (4, 4))
        imgui.separator()
        open = imgui.tree_node(component_name_display, treeNodeFlags)
        imgui.pop_style_var()
        # TODO imgui.same_line(contentRegionAvailable.x - lin)
        imgui.same_line()
        if imgui.button("+"):
            imgui.open_popup("ComponentSettings")
        removeComponent = False
        if imgui.begin_popup("ComponentSettings"):
            if menu_item_clicked("Remove component"):
                removeComponent = True
            imgui.end_popup()
        if open:
            getattr(self, "_draw_component_%s" % component_name)(component)
            imgui.tree_pop()

        if removeComponent:
            entity.remove_component(component_name)
Esempio n. 2
0
def create_window_dock(glfw_window, menu_bar=False):
    imgui.set_next_window_bg_alpha(0)
    imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, (0, 0))
    begin_maximized_window("Background Window", glfw_window, menu_bar)
    imgui.pop_style_var(1)
    imgui.dock_space("Window Dock Space", 0., 0., 1 << 3)
    imgui.end()
Esempio n. 3
0
    def draw_menu(self):
        imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, (8, 8))
        if imgui.begin_menu_bar():
            # first menu dropdown
            if imgui.begin_menu('菜单', True):
                if utils.is_menu_item_click('导出', 'Ctrl+O+P', False, True):
                    print "暂不支持"
                if utils.is_menu_item_click('设置', 'Ctrl+Alt+S', False, True):
                    print "设置"
                imgui.end_menu()

            if imgui.begin_menu("工具", True):
                if utils.is_menu_item_click("查找", "Ctrl+F", False, True):
                    print "查找"
                if utils.is_menu_item_click("自定义GM", "Ctrl+G", False, True):
                    print "自定义GM"
                imgui.end_menu()

            if imgui.begin_menu("帮助", True):
                if utils.is_menu_item_click("文档", "F1", False, True):
                    print "文档"
                if utils.is_menu_item_click("快捷键", "Ctrl+M", False, True):
                    print "快捷键"
                if utils.is_menu_item_click("关于...", None, False, True):
                    print "关于"
                imgui.end_menu()

            imgui.end_menu_bar()
        imgui.pop_style_var()
Esempio n. 4
0
    def draw_logs(self):
        imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, (6, 6))
        cur_style = imgui.get_style()
        padding = cur_style.window_padding
        cur_cursor_pos = imgui.get_cursor_pos()
        imgui.set_cursor_pos(
            (cur_cursor_pos[0] + padding[0], cur_cursor_pos[1] + padding[1]))
        imgui.begin_child(self.ID_CHILD_CONSOLE,
                          self.width - cur_style.window_padding[0] * 2,
                          self.height - 80, True)

        search_text = self.config.get_string(EConfigKey.CONTENT_SEARCH_TEXT)
        win_width = imgui.get_window_width()
        for idx, record in enumerate(self.log_mgr.log_lst):
            if not self.config.is_has_log_level(record.level):
                continue
            if not utils.filter_search_text(search_text, record):
                continue
            old_color = None
            if record.level == logging.ERROR:
                old_color = utils.set_style_color(imgui.COLOR_TEXT,
                                                  TextColor.ERed)
            elif record.level == logging.WARN or record.level == logging.WARNING:
                old_color = utils.set_style_color(imgui.COLOR_TEXT,
                                                  TextColor.EYellow)
            elif record.level == logging.INFO:
                old_color = utils.set_style_color(imgui.COLOR_TEXT,
                                                  TextColor.EWhite)
            imgui.push_id(str(idx))
            ret = imgui.selectable_wrap(record.msg_with_level,
                                        idx == self.sel_idx,
                                        imgui.SELECTABLE_ALLOW_DOUBLE_CLICK,
                                        win_width * 0.98, 30)
            if ret[1]:
                self.sel_idx = idx
            if imgui.is_item_hovered() and imgui.is_mouse_double_clicked(0):
                self.detail_idx = idx
                imgui.open_popup("detail_log_%d" % self.detail_idx)
            self.draw_log_detail_info_panel(idx, record)
            if old_color:
                utils.set_style_color(imgui.COLOR_TEXT, old_color)
            imgui.pop_id()

        if imgui.is_mouse_dragging() or imgui.get_io().mouse_wheel:
            if imgui.get_scroll_y() >= imgui.get_scroll_max_y():
                self.config.set_bool(EConfigKey.CONTENT_SCROLL_TO_BOTTOM, True)
            else:
                self.config.set_bool(EConfigKey.CONTENT_SCROLL_TO_BOTTOM,
                                     False)

        is_to_bottom = self.config.get_bool(
            EConfigKey.CONTENT_SCROLL_TO_BOTTOM, True)
        if is_to_bottom:
            imgui.set_scroll_y(imgui.get_scroll_max_y())

        imgui.end_child()
        imgui.pop_style_var()
Esempio n. 5
0
def begin_maximized_window(name, glfw_window, menu_bar=False):
    imgui.set_next_window_position(0, 0)
    imgui.set_next_window_size(*glfw.get_window_size(glfw_window))
    imgui.push_style_var(imgui.STYLE_WINDOW_ROUNDING, 0)
    imgui.push_style_var(imgui.STYLE_WINDOW_BORDERSIZE, 0)
    window_flags = imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_COLLAPSE | \
        imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | \
        imgui.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS | imgui.WINDOW_NO_NAV_FOCUS | \
        imgui.WINDOW_NO_DOCKING
    if menu_bar:
        window_flags |= imgui.WINDOW_MENU_BAR
    imgui.begin(name, True, window_flags)
    imgui.pop_style_var(2)
Esempio n. 6
0
def disableable_button(*args, **kwargs):
    disabled = not kwargs.pop('enabled')
    if disabled:
        ig.push_style_var(ig.STYLE_ALPHA, 0.5)
        ig.push_style_color(ig.COLOR_BUTTON_HOVERED,
                            *ig.get_style().colors[ig.COLOR_BUTTON])
        ig.push_style_color(ig.COLOR_BUTTON_ACTIVE,
                            *ig.get_style().colors[ig.COLOR_BUTTON])
    result = ig.button(*args, **kwargs)
    if disabled:
        ig.pop_style_color()
        ig.pop_style_color()
        ig.pop_style_var()
    return result
Esempio n. 7
0
    def update(self):
        imgui.set_next_window_size(self.width, self.height)
        imgui.set_next_window_position(0, 0)

        imgui.push_style_var(imgui.STYLE_WINDOW_ROUNDING, 0)
        imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, (0, 0))
        imgui.begin(
            "main view", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE
            | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_MENU_BAR
            | imgui.WINDOW_NO_TITLE_BAR)

        self.draw_menu()
        self.draw_logs()
        self.draw_btn_bar()
        self.draw_input_bar()

        imgui.end()
        imgui.pop_style_var(2)
Esempio n. 8
0
    def update(self):
        # return done, value
        do_return = False
        recipe = ''
        if self.extra_font:
            imgui.push_font(self.extra_font)
        width = 750
        height = 250
        imgui.set_next_window_size(width, height)
        imgui.set_next_window_position(self.center_x - width // 2,
                                       self.center_y - height // 2)
        imgui.push_style_var(imgui.STYLE_ALPHA, self.alpha)
        imgui.begin('Drop', False, flags=self.flags)
        self.left_label('ID:')
        xx, self.id = imgui.input_text('\n', self.id, 128)
        self.tooltip_help('Participant ID/Name')

        self.add_space(3)
        self.left_label('Español:')
        _, self.spanish = imgui.checkbox('', self.spanish)
        self.tooltip_help('Spanish text for subsequent instructions')
        self.add_space(3)

        self.left_label('Recipe:')
        # current filenames
        recipe_names = []
        recipe_short = []
        for file in glob.glob('recipes/**/*.toml', recursive=True):
            if (os.path.sep + 'defaults' + os.path.sep) not in file:
                recipe_names.append(file)
                recipe_short.append(os.path.relpath(file, 'recipes'))
        changed, self.current_recipe = imgui.combo(' ', self.current_recipe,
                                                   recipe_short)
        self.tooltip_help(
            'Available recipes (TOML files) in the recipe directory')
        imgui.same_line()
        imgui.button('Preview')
        if imgui.is_item_hovered() and recipe_names:
            with open(recipe_names[self.current_recipe], 'r') as f:
                prev = f.read()
            # width in characters, height in number of newlines
            if prev:
                wid = len(
                    max(open(recipe_names[self.current_recipe], 'r'), key=len))
                # TODO: need to be careful of newline char??
                hei = prev.count('\n') + 1
            else:
                wid = 10
                hei = 1
            fac = 0.6
            font_size = imgui.get_font_size() * fac
            wid = int(wid * font_size / 2)  # get something like pix
            hei = int(hei * font_size)
            # if height is >= half the window height, turn to scroll
            val = hei
            if hei >= self.center_y:
                val = self.center_y
            imgui.begin_tooltip()
            imgui.begin_child('region', wid, val)
            imgui.set_scroll_y(imgui.get_scroll_y() -
                               imgui.get_io().mouse_wheel * 30)
            imgui.set_window_font_scale(fac)
            imgui.text(prev)
            imgui.end_child()
            imgui.end_tooltip()
            imgui.set_item_default_focus()

            # imgui.set_tooltip(prev)
        self.add_space(3)

        if imgui.button('Ok'):
            do_return = True
        if imgui.get_io().keys_down[imgui.KEY_ENTER]:
            do_return = True

        imgui.pop_style_var(1)
        imgui.end()
        if self.extra_font:
            imgui.pop_font()

        # disallow depending on current state
        if not self.id:
            do_return = False
        try:
            recipe = recipe_names[self.current_recipe]
        except IndexError:
            do_return = False
        if not os.path.isdir(self.recipe_dir):
            do_return = False
        # no need to validate data dir, we'll create it
        data = {
            'id': self.id,
            'recipe': recipe,
            'spanish': 'es' if self.spanish else 'en'
        }
        return do_return, data
Esempio n. 9
0
def main():

    # Theme Index
    THEME_INDEX = 2

    # window visible params
    bShowInfoPopUp = False
    bShowFiles = True
    bShowParsePdf = True
    bShowParserStatics = True

    bShowImg = False
    bShowTestWindow = True

    #delete cache files
    if os.path.isfile('ParseResult.log'):
        os.remove('ParseResult.log')
    if os.path.isfile('ManualFiles.log'):
        os.remove('ManualFiles.log')
    if os.path.isfile('Cluster.png'):
        os.remove('Cluster.png')

    pygame.init()
    size = 1280, 720  # 720p
    # size = 1920, 1080 # 1080p

    pygame.display.set_mode(
        size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE)
    pygame.display.set_caption("PDF成績單解析器")

    clock = pygame.time.Clock()

    favicon = pygame.image.load('asset\\Logo.png')
    pygame.display.set_icon(favicon)

    imgui.create_context()

    impl = PygameRenderer()

    io = imgui.get_io()
    smallfont = io.fonts.add_font_from_file_ttf(
        "asset\\NotoSansTC-Black.otf", 12,
        io.fonts.get_glyph_ranges_chinese_full())
    normalfont = io.fonts.add_font_from_file_ttf(
        "asset\\NotoSansTC-Black.otf", 16,
        io.fonts.get_glyph_ranges_chinese_full())
    largefont = io.fonts.add_font_from_file_ttf(
        "asset\\NotoSansTC-Black.otf", 28,
        io.fonts.get_glyph_ranges_chinese_full())
    io.fonts.add_font_default()
    impl.refresh_font_texture()
    io.display_size = size

    style = imgui.get_style()
    if THEME_INDEX == 1:
        GF.SetCustomStyle1(style)
    elif THEME_INDEX == 2:
        GF.SetCustomStyle2(style)
    elif THEME_INDEX == 3:
        GF.SetCustomStyle3(style)

    CV = 0
    MV = 200
    while 1:
        clock.tick(30)  # fixed 15 fps

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                # remove cache here
                sys.exit()
            if event.type == pygame.VIDEORESIZE:
                print('resize is triggered!')

            # shortcut bindings
            if event.type == pygame.KEYDOWN:
                if event.mod == pygame.KMOD_LCTRL and event.key == pygame.K_q:
                    sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_F1:
                    GF.OpenHelper()

            impl.process_event(event)
        imgui.push_style_var(imgui.STYLE_FRAME_PADDING, (10, 12.5))
        imgui.new_frame()

        # Main menu region
        if imgui.begin_main_menu_bar():
            with imgui.font(normalfont):
                if imgui.begin_menu("設定", True):
                    if imgui.begin_menu(label="主題", enabled=True):
                        if THEME_INDEX == 1:
                            imgui.menu_item("默認", None, True, True)
                        else:
                            c, _ = imgui.menu_item("默認", None, False, True)
                            if c:
                                GF.SetCustomStyle1(style)
                                THEME_INDEX = 1
                        if THEME_INDEX == 2:
                            imgui.menu_item("CorporateGrey", None, True, True)
                        else:
                            c, _ = imgui.menu_item("CorporateGrey", None,
                                                   False, True)
                            if c:
                                GF.SetCustomStyle2(style)
                                THEME_INDEX = 2
                        if THEME_INDEX == 3:
                            imgui.menu_item("Light", None, True, True)
                        else:
                            c, _ = imgui.menu_item("Light", None, False, True)
                            if c:
                                GF.SetCustomStyle3(style)
                                THEME_INDEX = 3
                        imgui.end_menu()

                    clicked_quit, selected_quit = imgui.menu_item(
                        "Quit", "L-Ctrl + Q", False, True)
                    if clicked_quit:
                        sys.exit()
                    imgui.end_menu()

                if imgui.begin_menu("視窗", True):
                    if not bShowFiles:
                        F, _ = imgui.menu_item(label="選擇目錄",
                                               shortcut=None,
                                               selected=False,
                                               enabled=True)
                    else:
                        F, _ = imgui.menu_item(label="選擇目錄",
                                               shortcut=None,
                                               selected=True,
                                               enabled=True)
                    if F:
                        bShowFiles = not bShowFiles
                    if not bShowParsePdf:
                        o, _ = imgui.menu_item(label="解析成績單",
                                               shortcut=None,
                                               selected=False,
                                               enabled=True)
                    else:
                        o, _ = imgui.menu_item(label="解析成績單",
                                               shortcut=None,
                                               selected=True,
                                               enabled=True)
                    if o:
                        bShowParsePdf = not bShowParsePdf
                    if not bShowParserStatics:
                        r, _ = imgui.menu_item(label="解析結果",
                                               shortcut=None,
                                               selected=False,
                                               enabled=True)
                    else:
                        r, _ = imgui.menu_item(label="解析結果",
                                               shortcut=None,
                                               selected=True,
                                               enabled=True)
                    if r:
                        bShowParserStatics = not bShowParserStatics

                    imgui.end_menu()

                if imgui.begin_menu("資訊", True):
                    I, _ = imgui.menu_item("關於",
                                           None,
                                           selected=False,
                                           enabled=True)
                    h, _ = imgui.menu_item("幫助",
                                           shortcut="F1",
                                           selected=False,
                                           enabled=True)
                    if I:
                        bShowInfoPopUp = True

                    if h:
                        GF.OpenHelper()

                    imgui.end_menu()

            #imgui.pop_style_var(1)
            imgui.end_main_menu_bar()

        # Conditional windows
        if bShowFiles:
            imgui.set_next_window_position(0, 35, imgui.ONCE)
            imgui.set_next_window_size(230, 685, imgui.ONCE)
            with imgui.font(normalfont):
                bFileWindow = imgui.begin("選擇目錄",
                                          True,
                                          flags=imgui.WINDOW_NO_RESIZE
                                          | imgui.WINDOW_NO_MOVE
                                          | imgui.WINDOW_NO_COLLAPSE)
                if not bFileWindow[1]:
                    bShowFiles = False
                GE.FileWindow()
                imgui.end()

        if bShowParsePdf:
            imgui.set_next_window_position(230, 35, imgui.ONCE)
            imgui.set_next_window_size(450, 685, imgui.ONCE)
            with imgui.font(normalfont):
                bParsePdf = imgui.begin("解析成績單", True)
                if not bParsePdf[1]:
                    bShowParsePdf = False
                GE.ParsePdfWidget()
                imgui.end()

        if bShowParserStatics:
            imgui.set_next_window_position(680, 35, imgui.ONCE)
            imgui.set_next_window_size(600, 685, imgui.ONCE)
            with imgui.font(normalfont):
                bParserStats = imgui.begin("解析結果", True)
                if not bParserStats[1]:
                    bShowParserStatics = False
                GE.ParserStaticsWidget()
                if os.path.isfile('Cluster.png'):
                    img_info = GF.loadImage('Cluster.png')
                    imgui.image(img_info[0], img_info[1], img_info[2])
                imgui.end()

        if (bShowInfoPopUp):
            imgui.open_popup("資訊")

        imgui.set_next_window_size(600, 300)
        imgui.font(normalfont)
        if imgui.begin_popup_modal(title="資訊", visible=True, flags=0)[0]:
            GE.ProgramInfoPopup()
            imgui.separator()
            bShowInfoPopUp = False
            imgui.end_popup()

        if THEME_INDEX == 1:
            gl.glClearColor(0.1, 0.1, 0.1, 1)  # for default theme
        elif THEME_INDEX == 2:
            gl.glClearColor(0.45, 0.55, 0.6, 1)  # for light theme
        elif THEME_INDEX == 3:
            gl.glClearColor(0.25, 0.25, 0.25, 1.00)

        imgui.pop_style_var()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()
        impl.render(imgui.get_draw_data())
        pygame.display.flip()

        CV += 1
Esempio n. 10
0
 def __enter__(ims) -> IMGui[None]:
     for (style_var, value) in ims.styles.items():
         imgui.push_style_var(style_var, value)
    def run(self):
        # Loop until the user closes the window
        while not glfw.window_should_close(self.window):
            # Poll for and process events
            glfw.poll_events()

            # build gui.
            self.impl.process_inputs()

            w, h = glfw.get_window_size(self.window)
            glViewport(0, 0, w, h)

            imgui.new_frame()

            timeline_height = 35
            imgui.push_style_var(imgui.STYLE_WINDOW_ROUNDING, 0)
            imgui.push_style_var(imgui.STYLE_FRAME_ROUNDING, 0)

            imgui.set_next_window_position(0, h - timeline_height - 10)
            imgui.set_next_window_size(w, timeline_height)

            imgui.begin(
                "Timeline", False, imgui.WINDOW_NO_TITLE_BAR
                | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_SCROLLBAR)
            imgui.columns(1)
            imgui.same_line(0, 0)
            imgui.push_item_width(-50)
            changed, value = imgui.slider_int("", self.sliderValue, 0,
                                              self.num_scans - 1)
            if changed: self.sliderValue = value
            if self.sliderValue != self.currentTimestep:
                self.currentTimestep = self.sliderValue

            imgui.push_style_var(imgui.STYLE_FRAME_ROUNDING, 3)

            play_delay = 1
            refresh_rate = 0.05

            current_time = time.time()

            imgui.same_line(spacing=5)
            changed = imgui.button("<", 20)
            if self.currentTimestep > 0:
                # just a click
                if changed:
                    self.currentTimestep = self.sliderValue = self.currentTimestep - 1
                    self.lastUpdate = current_time

                # button pressed.
                if imgui.is_item_active() and not self.button_backward_hold:
                    self.hold_start = current_time
                    self.button_backward_hold = True

                if not imgui.is_item_active() and self.button_backward_hold:
                    self.button_backward_hold = False

                # start playback when button pressed long enough
                if self.button_backward_hold and (
                    (current_time - self.hold_start) > play_delay):
                    if (current_time - self.lastUpdate) > refresh_rate:
                        self.currentTimestep = self.sliderValue = self.currentTimestep - 1
                        self.lastUpdate = current_time

            imgui.same_line(spacing=2)
            changed = imgui.button(">", 20)

            if self.currentTimestep < self.num_scans - 1:
                # just a click
                if changed:
                    self.currentTimestep = self.sliderValue = self.currentTimestep + 1
                    self.lastUpdate = current_time

                # button pressed.
                if imgui.is_item_active() and not self.button_forward_hold:
                    self.hold_start = current_time
                    self.button_forward_hold = True

                if not imgui.is_item_active() and self.button_forward_hold:
                    self.button_forward_hold = False

                # start playback when button pressed long enough
                if self.button_forward_hold and (
                    (current_time - self.hold_start) > play_delay):
                    if (current_time - self.lastUpdate) > refresh_rate:
                        self.currentTimestep = self.sliderValue = self.currentTimestep + 1
                        self.lastUpdate = current_time

            imgui.pop_style_var(3)
            imgui.end()

            imgui.set_next_window_position(20, 20, imgui.FIRST_USE_EVER)
            imgui.set_next_window_size(200, 150, imgui.FIRST_USE_EVER)
            imgui.begin("Show Data")

            if len(self.subdirs) > 1:
                for i, subdir in enumerate(self.subdirs):
                    changed, value = imgui.checkbox(subdir,
                                                    self.current_subdir == i)
                    if i < len(self.subdirs) - 1: imgui.same_line()
                    if changed and value: self.current_subdir = i

            subdir = self.subdirs[self.current_subdir]

            data_available = "input" in self.availableData[subdir]
            if data_available:
                imgui.push_style_var(imgui.STYLE_ALPHA, 1.0)
            else:
                imgui.push_style_var(imgui.STYLE_ALPHA, 0.3)

            changed, value = imgui.checkbox("input", self.showInput)
            if changed and value and data_available:
                self.showInput = True
                self.showLabels = False

            imgui.pop_style_var()

            data_available = "labels" in self.availableData[subdir]
            if data_available:
                imgui.push_style_var(imgui.STYLE_ALPHA, 1.0)
            else:
                imgui.push_style_var(imgui.STYLE_ALPHA, 0.3)

            changed, value = imgui.checkbox("labels", self.showLabels)
            if changed and value and data_available:
                self.showInput = False
                self.showLabels = True

            imgui.pop_style_var()

            data_available = "invalid" in self.availableData[subdir]
            if data_available:
                imgui.push_style_var(imgui.STYLE_ALPHA, 1.0)
            else:
                imgui.push_style_var(imgui.STYLE_ALPHA, 0.3)

            changed, value = imgui.checkbox("invalid", self.showInvalid)
            if changed and data_available: self.showInvalid = value

            imgui.pop_style_var()

            data_available = "occluded" in self.availableData[subdir]
            if data_available:
                imgui.push_style_var(imgui.STYLE_ALPHA, 1.0)
            else:
                imgui.push_style_var(imgui.STYLE_ALPHA, 0.3)

            changed, value = imgui.checkbox("occluded", self.showOccluded)
            if changed and data_available: self.showOccluded = value

            imgui.pop_style_var()

            imgui.end()

            # imgui.show_demo_window()

            showData = []
            if self.showInput: showData.append("input")
            if self.showOccluded: showData.append("occluded")
            if self.showInvalid: showData.append("invalid")

            mvp = self.projection_ @ self.cam.matrix @ self.conversion_

            glClearColor(1.0, 1.0, 1.0, 1.0)

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glBindVertexArray(self.vao)

            self.program.bind()
            self.program["mvp"] = mvp.transpose()
            self.program["view_mat"] = (
                self.cam.matrix @ self.conversion_).transpose()
            self.program["lightPos"] = glow.vec3(10, 10, 10)
            self.program["voxel_scale"] = 0.8
            self.program["voxel_alpha"] = 1.0
            self.program["use_label_colors"] = True

            self.label_colors.bind(0)

            if self.showLabels:
                self.setCurrentBufferData("labels", self.currentTimestep)
                glDrawArraysInstanced(GL_TRIANGLES, 0, 36, self.num_instances)

            self.program["use_label_colors"] = False
            self.program["voxel_color"] = glow.vec3(0.3, 0.3, 0.3)

            self.program["voxel_alpha"] = 0.5

            for data_name in showData:
                self.program["voxel_scale"] = 0.5
                if data_name == "input": self.program["voxel_scale"] = 0.8

                self.setCurrentBufferData(data_name, self.currentTimestep)
                glDrawArraysInstanced(GL_TRIANGLES, 0, 36, self.num_instances)

            self.program.release()
            self.label_colors.release(0)

            glBindVertexArray(self.vao_no_points)

            self.prgDrawPose.bind()
            self.prgDrawPose["mvp"] = mvp.transpose()
            self.prgDrawPose["pose"] = np.identity(4, dtype=np.float32)
            self.prgDrawPose["size"] = 1.0

            glDrawArrays(GL_POINTS, 0, 1)
            self.prgDrawPose.release()

            glBindVertexArray(0)

            # draw gui ontop.
            imgui.render()
            self.impl.render(imgui.get_draw_data())

            # Swap front and back buffers
            glfw.swap_buffers(self.window)
Esempio n. 12
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()
Esempio n. 13
0
def render_palette_popup(drawing: Drawing):

    global edit_color
    global color_editor_open

    palette = drawing.palette
    fg = palette.foreground
    bg = palette.background
    fg_color = palette.foreground_color
    bg_color = palette.background_color
    open_color_editor = False

    _, opened = imgui.begin("Color popup", True)

    imgui.begin_child("Colors", height=0)

    imgui.push_style_var(imgui.STYLE_ITEM_SPACING,
                         (0, 0))  # Make layout tighter
    width = int(imgui.get_window_content_region_width()) // 25

    for i, color in enumerate(palette.colors, 0):
        is_foreground = i == fg
        is_background = (i == bg) * 2
        selection = is_foreground | is_background
        if i in palette.overlay:
            color = as_float(palette.overlay[i])
        else:
            color = as_float(color)
        imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND,
                               *SELECTABLE_FRAME_COLORS[selection])
        if imgui.color_button(f"color {i}", *color[:3], 1, 0, 25, 25):
            # io = imgui.get_io()
            # if io.key_shift:
            #     if "spread_start" in temp_vars:
            #         temp_vars["spread_end"] = i
            #     else:
            #         temp_vars["spread_start"] = i
            # else:
            fg = i
        imgui.pop_style_color(1)

        if imgui.core.is_item_clicked(1):
            edit_color = i
            color_editor_open = True
            imgui.open_popup("Edit foreground color")
            # imgui.set_next_window_position(w - 115 - 120, 200)

        if imgui.core.is_item_clicked(2):
            # Detect right button clicks on the button
            bg = i

        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('start_index',
                                        i.to_bytes(1, sys.byteorder))
            imgui.color_button(f"color {i}", *color[:3], 1, 0, 20, 20)
            imgui.end_drag_drop_source()
        if imgui.begin_drag_drop_target():
            start_index = imgui.accept_drag_drop_payload('start_index')
            if start_index is not None:
                start_index = int.from_bytes(start_index, sys.byteorder)
                io = imgui.get_io()
                image_only = io.key_shift
                # drawing.swap_colors(start_index, i, image_only=image_only)
                # palette.clear_overlay()
            imgui.end_drag_drop_target()

        # if imgui.is_item_hovered():
        #     io = imgui.get_io()
        #     delta = int(io.mouse_wheel)

        if i % width != width - 1:
            imgui.same_line()

    imgui.pop_style_var(1)
    #color_editor_open = render_color_editor_popup(drawing, edit_color, color_editor_open)

    imgui.end_child()
    imgui.end()

    palette.foreground = fg
    palette.background = bg

    return opened, open_color_editor
Esempio n. 14
0
def render_palette(drawing: Drawing):

    global color_editor_open  # Need a persistent way to keep track of the popup being closed...
    global current_color_page

    palette = drawing.palette
    fg = palette.foreground
    bg = palette.background
    fg_color = palette.foreground_color
    bg_color = palette.background_color

    imgui.begin_child("Palette", border=False, height=460)
    # Edit foreground color
    if imgui.color_button(f"Foreground (#{fg})", *as_float(fg_color), 0, 30,
                          30):
        io = imgui.get_io()
        w, h = io.display_size
        imgui.open_popup("Edit foreground color")
        imgui.set_next_window_position(w - 115 - 120, 200)
        color_editor_open = True
    if imgui.begin_popup("Edit foreground color",
                         flags=(imgui.WINDOW_NO_MOVE
                                | imgui.WINDOW_NO_SCROLL_WITH_MOUSE)):
        done, cancelled, new_color = render_color_editor(
            palette.colors[fg], fg_color)
        if done and new_color != fg_color:
            drawing.change_colors(fg, new_color)
            palette.clear_overlay()
        elif cancelled:
            palette.clear_overlay()
        else:
            palette.set_overlay(fg, new_color)
        imgui.end_popup()
    elif color_editor_open:
        # The popup was closed by clicking outside, keeping the change (same as OK)
        drawing.change_colors(fg, fg_color)
        palette.clear_overlay()
        color_editor_open = False

    imgui.same_line()

    imgui.color_button(f"Background (#{bg})", *as_float(bg_color), 0, 30, 30)

    max_pages = len(palette.colors) // 64 - 1
    imgui.push_item_width(100)
    _, current_color_page = imgui.slider_int("Page",
                                             current_color_page,
                                             min_value=0,
                                             max_value=max_pages)
    start_color = 64 * current_color_page

    imgui.begin_child("Colors", border=False)
    imgui.push_style_var(imgui.STYLE_ITEM_SPACING,
                         (0, 0))  # Make layout tighter
    width = int(imgui.get_window_content_region_width()) // 20

    imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, 0, 0, 0)

    colors = palette.colors

    # Order the colors by column instead of by row (which is the order we draw them)
    for i, c in enumerate(
            chain.from_iterable(
                zip(range(0, 16), range(16, 32), range(32, 48), range(48,
                                                                      64)))):
        color = colors[start_color + c]
        is_foreground = c == fg
        is_background = (c == bg) * 2
        selection = is_foreground | is_background
        color = as_float(color)

        if color[3] == 0 or selection:
            x, y = imgui.get_cursor_screen_pos()

        if imgui.color_button(f"color {i}", *color[:3], 1, 0, 25, 25):
            # io = imgui.get_io()
            # if io.key_shift:
            #     if "spread_start" in temp_vars:
            #         temp_vars["spread_end"] = i
            #     else:
            #         temp_vars["spread_start"] = i
            # else:
            fg = c

        if i % width != width - 1:
            imgui.same_line()

        draw_list = imgui.get_window_draw_list()
        if color[3] == 0:
            # Mark transparent color
            draw_list.add_line(x + 1, y + 1, x + 24, y + 24,
                               imgui.get_color_u32_rgba(0, 0, 0, 1), 1)
            draw_list.add_line(x + 1, y + 2, x + 23, y + 24,
                               imgui.get_color_u32_rgba(1, 1, 1, 1), 1)

        if is_foreground:
            # Mark foregroupd color
            draw_list.add_rect_filled(x + 2, y + 2, x + 10, y + 10,
                                      imgui.get_color_u32_rgba(1, 1, 1, 1))
            draw_list.add_rect(x + 2, y + 2, x + 10, y + 10,
                               imgui.get_color_u32_rgba(0, 0, 0, 1))
        if is_background:
            # Mark background color
            draw_list.add_rect_filled(x + 15, y + 2, x + 23, y + 10,
                                      imgui.get_color_u32_rgba(0, 0, 0, 1))
            draw_list.add_rect(x + 15, y + 2, x + 23, y + 10,
                               imgui.get_color_u32_rgba(1, 1, 1, 1))

        if imgui.core.is_item_clicked(2):
            # Right button sets background
            bg = c

        # Drag and drop (currently does not accomplish anything though)
        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('start_index',
                                        c.to_bytes(1, sys.byteorder))
            imgui.color_button(f"color {c}", *color[:3], 1, 0, 20, 20)
            imgui.end_drag_drop_source()
        if imgui.begin_drag_drop_target():
            start_index = imgui.accept_drag_drop_payload('start_index')
            if start_index is not None:
                start_index = int.from_bytes(start_index, sys.byteorder)
                io = imgui.get_io()
                image_only = io.key_shift
                drawing.swap_colors(start_index, c, image_only=image_only)
                palette.clear_overlay()
            imgui.end_drag_drop_target()

    imgui.pop_style_color(1)
    imgui.pop_style_var(1)
    imgui.end_child()

    imgui.end_child()

    if imgui.is_item_hovered():
        io = imgui.get_io()
        delta = int(io.mouse_wheel)
        current_color_page = min(max(current_color_page - delta, 0), max_pages)

    palette.foreground = fg
    palette.background = bg
Esempio n. 15
0


def ProgessBar(CV, MV, BarSize = 200):
    if CV >= MV:
        CV = MV
    imgui.dummy(10, 20)
    draw_list = imgui.get_window_draw_list()
    sp = imgui.get_item_rect_min()
    ep = imgui.get_item_rect_max()
    draw_list.add_rect(sp[0]+60,ep[1], sp[0]+60 + BarSize ,sp[1], imgui.get_color_u32_rgba(0.098, 0.098, 0.439, 1))
    draw_list.add_rect_filled(sp[0]+60,ep[1], sp[0]+60 + CV/MV * BarSize ,sp[1], imgui.get_color_u32_rgba(0.098, 0.098, 0.439, 1))
    draw_list.add_text(sp[0]+60 + BarSize + 10, sp[1] + 2, imgui.get_color_u32_rgba(1,0.5,0.5,1), f'{round(CV/MV* 100, 2)} %')    

    
'''

use the following stuff to set size of windows if resize.

https://github.com/ocornut/imgui/issues/933

however, this will disable user resize...

prevent user to resize to very ugly size:

imgui.push_style_var(imgui.STYLE_WINDOW_MIN_SIZE, (x,y,))
imgui.text("Alpha text")
imgui.pop_style_var(1)


##wrap text