Exemplo n.º 1
0
def get_window_rect() -> IMGui[Rect]:
    """ To be used only in imgui code """
    window_top_left = im.get_window_position()
    width, height = im.get_window_size()
    window_bottom_right = Vec2(window_top_left.x + width,
                               window_top_left.y + height)
    return Rect(window_top_left, window_bottom_right)
Exemplo n.º 2
0
 def begin_input(self, pin):
     x, y = imgui.get_cursor_screen_pos()
     wx, wy = imgui.get_window_position()
     x = wx - 8
     pos = (x, y)
     pin.set_position(pos)
     return pos
Exemplo n.º 3
0
def get_window_content_rect() -> IMGui[Rect]:
    TITLE_BAR_HEIGHT = 20
    window_top_left = im.get_window_position()
    content_top_left = Vec2(window_top_left.x,
                            window_top_left.y + TITLE_BAR_HEIGHT)
    width, height = im.get_window_size()
    window_bottom_right = Vec2(window_top_left.x + width,
                               window_top_left.y + height)
    return Rect(content_top_left, window_bottom_right)
Exemplo n.º 4
0
    def begin_output(self, pin):
        x, y = imgui.get_cursor_screen_pos()
        wx, wy = imgui.get_window_position()
        ww, wh = imgui.get_window_size()

        x = wx + ww + 8
        pos = (x, y)
        pin.set_position(pos)
        return pos
Exemplo n.º 5
0
    def draw_big_lattice(self, L, name='lattice', index=None):
        imgui.begin_child(name, 0, self.lattice_height, border=True)

        win_pos = imgui.get_window_position()

        L = L.L

        # Calculate rank and node separation sizes.
        region_min = imgui.get_window_content_region_min()
        region_max = imgui.get_window_content_region_max()
        region_size = (region_max.x - region_min.x, region_max.y - region_min.y)

        n_r = len(L)+1
        n_n = np.max([len(l) for l in L])+1
        rank_sep = region_size[1] / n_r
        node_sep = region_size[0] / n_n
        # radius = np.min([node_sep, rank_sep]) / 8
        radius = 6.0
        off_x = win_pos.x + region_min.x + node_sep
        off_y = win_pos.y + region_min.y + rank_sep

        draw_list = imgui.get_window_draw_list()

        # Create ranks manually
        color = imgui.get_color_u32_rgba(*get_color('safety yellow'))
        offset = np.max([(len(l) - 1) * node_sep for l in L])/2
        extents = []
        for i in range(len(L)):
            n_f = len(L[i])
            l = max(radius, (n_f - 1) * node_sep)
            x0 = round(off_x + offset + -l/2 + 0)
            y0 = round(off_y + rank_sep * i)
            x1 = round(off_x + offset + -l/2 + l)
            y1 = round(off_y + rank_sep * i)
            draw_list.add_line(x0, y0, x1, y1, color, radius)
            extents.append([np.array([x0, y0]), np.array([x1, y1])])

        # Add random lines to simulate a lattice structure.
        thickness = 1
        np.random.seed(0)
        for i in range(1, len(L)):
            for s0, s1 in [(1, 1), (0, 0)]:
                e0 = extents[i-1]
                e1 = extents[i]
                # s0 = np.random.rand()
                # s0 = s
                p0 = s0*e0[0] + (1-s0)*e0[1]
                # s1 = np.random.rand()
                # s1 = 1-s
                p1 = s1*e1[0] + (1-s1)*e1[1]
                draw_list.add_line(p0[0], p0[1], p1[0], p1[1], color, thickness)
        
        # Draw current index in red.
        if index is not None:
            e = extents[index[0]]
            if len(L[index[0]]) > 1:
                s = index[1]/(len(L[index[0]]) - 1)
            else:
                s = 0.5
            p = (1-s)*e[0] + s*e[1]
            red = imgui.get_color_u32_rgba(*get_color('red'))
            draw_list.add_line(p[0]+radius/2, p[1], p[0]-radius/2, p[1], red, radius)

        imgui.end_child()
Exemplo n.º 6
0
    def draw_lattice(self, L, name='lattice', index=None):
        imgui.begin_child(name, 0, self.lattice_height, border=True)

        win_pos = imgui.get_window_position()

        L = L.L

        # Calculate rank and node separation sizes.
        region_min = imgui.get_window_content_region_min()
        region_max = imgui.get_window_content_region_max()
        region_size = (region_max.x - region_min.x, region_max.y - region_min.y)

        n_r = len(L)+1
        n_n = np.max([len(l) for l in L])+1
        rank_sep = region_size[1] / n_r
        node_sep = region_size[0] / n_n
        radius = np.min([node_sep, rank_sep]) / 4
        off_x = win_pos.x + region_min.x + node_sep
        off_y = win_pos.y + region_min.y + rank_sep

        draw_list = imgui.get_window_draw_list()

        # Create ranks manually
        pos = dict()
        rgb = np.array([255, 255, 102], float)/255
        rgb = np.array([238, 210, 2], float)/255
        color = imgui.get_color_u32_rgba(rgb[0], rgb[1], rgb[2], 1.0)
        offset = np.max([(len(l) - 1) * node_sep for l in L])/2
        for i in range(len(L)):
            n_f = len(L[i])
            l = (n_f - 1) * node_sep
            for j in range(len(L[i])):
                F = L[i][j]
                x = off_x + offset + -l/2 + j * node_sep
                y = off_y + rank_sep * i
                pos[F] = (x, y)
                draw_list.add_circle_filled(x, y, radius, color)
        
        # Create lattice
        thickness = 1
        color = imgui.get_color_u32_rgba(rgb[0], rgb[1], rgb[2], 0.5)
        for i in range(len(L)):
            for j in range(len(L[i])):
                F = L[i][j]
                # f_n = names[F]
                # print(f_n)
                fx, fy = pos[F]
                if F.parents is None:
                    continue
                for H in F.parents:
                    # print(i,j)
                    if H in pos:
                        hx, hy = pos[H]
                        draw_list.add_line(hx, hy, fx, fy, color, thickness)

        if index is not None:
            x, y = pos[L[index[0]][index[1]]]
            active = imgui.get_color_u32_rgba(1.0,0.0,0.0,1.0)
            draw_list.add_circle_filled(x, y, radius, active)

        imgui.end_child()