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

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

        imgui.begin("Circle")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_circle(100,
                             60,
                             30,
                             imgui.get_color_u32_rgba(1, 1, 0, 1),
                             thickness=3)
        imgui.end()

        imgui.set_next_window_position(270, 32, imgui.ONCE)
        imgui.set_next_window_size(256, 256, imgui.ONCE)

        imgui.begin("Filled Circle")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_circle_filled(100, 60, 30,
                                    imgui.get_color_u32_rgba(1, 1, 0, 1))
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
예제 #2
0
def drawMap(linesc,
            east,
            north,
            xbias=1300,
            ybias=100,
            scale=0.5,
            edge_color='#ff0000',
            edge_linewidth=1,
            edge_alpha=1):
    draw_list = imgui.get_window_draw_list()
    pos = imgui.core.get_window_position()
    for p in linesc:
        points = ((p - [east, north]) * [1, -1] /
                  [1.141255544679108e-5, 8.993216192195822e-6] +
                  [xbias, ybias]) * scale + [pos[0], pos[1]]
        if (len(points) > 2):
            draw_list.add_polyline(list(points),
                                   imgui.get_color_u32_rgba(
                                       1, 0, 0, edge_alpha),
                                   closed=False,
                                   thickness=edge_linewidth)
        else:
            draw_list.add_line(points[0][0], points[0][1], points[1][0],
                               points[1][1],
                               imgui.get_color_u32_rgba(1, 0, 0, edge_alpha),
                               edge_linewidth)
예제 #3
0
 def render_turns(self, scale, rectmin):
     turns = self.pts['turn']
     Nturns = len(turns)
     if Nturns < 3:
         return
     t = np.float32(turns).T
     t[1] = -t[1]  # invert y
     tx = tapetrack.trackexport(t)
     N = 100 * Nturns
     s = (tapetrack.tracksubdiv(tx, N) * scale)
     s[:, 0] += rectmin[0]
     s[:, 1] = rectmin[1] - s[:, 1]  # uninvert y
     s[:, 3] = -s[:, 3]
     L = s[:, :2] + s[:, 2:4] * self.lanewidth
     R = s[:, :2] - s[:, 2:4] * self.lanewidth
     dl = imgui.get_window_draw_list()
     cyan = imgui.get_color_u32_rgba(0, 1, 1, 1)
     yellow = imgui.get_color_u32_rgba(1, 1, 0, 1)
     for i in range(1 + N):
         a = i % N
         b = (i + 1) % N
         if i & 1:
             dl.add_line(s[a, 0], s[a, 1], s[b, 0], s[b, 1], yellow)
         dl.add_line(L[a, 0], L[a, 1], L[b, 0], L[b, 1], cyan)
         dl.add_line(R[a, 0], R[a, 1], R[b, 0], R[b, 1], cyan)
     return s
예제 #4
0
def draw_map(cur_state):
    draw_list = imgui.get_window_draw_list()

    vertexes = map_db.get_all_vertexes(cur_state.map_data)

    for idx, vertex in enumerate(vertexes):
        is_selected = cur_state.mode == Mode.VERTEX and idx == cur_state.cur_vertex
        is_hovered = vertex == cur_state.hovered_item and cur_state.hovered_item_type == "Vertex"
        draw_map_vert(draw_list, vertex, highlight=(is_selected or is_hovered))

    # for wall in cur_state.map_data.walls:
    #    draw_map_wall(draw_list, wall, highlight = ((cur_state.mode == Mode.LINE and wall==cur_state.cur_wall) or wall == cur_state.hovered_item))

    for sect in range(cur_state.map_data.num_sectors):
        is_selected = cur_state.mode == Mode.SECTOR and sect == cur_state.cur_sector
        is_hovered = cur_state.hovered_item == sect and cur_state.hovered_item_type == "Sector"

        this_sectors_group = map_db.get_sector_constant(
            cur_state.map_data, sect, map_db.SECT_GROUP_IDX)
        is_group_hovered = cur_state.hovered_item_type == "Sector Group" and cur_state.hovered_item == this_sectors_group

        #is_hovered = cur_state.hovered_item == get_sector
        draw_sector(draw_list,
                    sect,
                    highlight=is_selected or is_hovered or is_group_hovered)

    if (cur_state.mode == Mode.SECTOR and cur_state.cur_sector != -1):
        draw_sector(draw_list, cur_state.cur_sector, highlight=True)
예제 #5
0
def render_layers(view):

    "Layer selector. Currently extremely spare."

    index = view.index
    # changed, new_index = imgui.v_slider_int("##layer_index", 30, 100, index,
    #                                         min_value=0, max_value=n_layers - 1)
    # if changed:
    #     x, y, z = view.direction
    #     delta = new_index - index
    #     view.switch_layer(delta)

    # imgui.same_line()

    draw_list = imgui.get_window_draw_list()
    x, y = imgui.get_cursor_screen_pos()
    draw_list.add_rect_filled(x, y, x + 30, y + 100,
                              imgui.get_color_u32_rgba(0.5, 0.5, 0.5, 1))
    top_layer = view.depth
    h = 100 / top_layer

    for layer in view.hidden_layers:
        dy = 100 - 100 * (view.index_of_layer(layer) + 1) / top_layer
        draw_list.add_rect_filled(x, y + dy, x + 30, y + dy + h,
                                  imgui.get_color_u32_rgba(0.5, 0.1, 0.1, 1))

    dy = 100 - 100 * (index + 1) / top_layer
    draw_list.add_rect_filled(x, y + dy, x + 30, y + dy + h,
                              imgui.get_color_u32_rgba(1, 1, 1, 0.5))

    imgui.set_cursor_screen_pos((x, y))
    imgui.text(str(index))
예제 #6
0
    def _show_custom_ui(self):
        width = 250
        height = 100

        draw_list = imgui.get_window_draw_list()
        plot_start = imgui.get_cursor_screen_pos()
        imgui.push_style_color(imgui.COLOR_PLOT_LINES, 0.8, 0.8, 0.8, 1.0)
        imgui.plot_lines("",
                         self._beat_value_buffer.contents * self.get("gain"),
                         0.0, 1.0, (width, height))
        imgui.pop_style_color()
        plot_size = imgui.get_item_rect_size()

        beat_risings = self._beat_rising_buffer.contents
        count = self._beat_rising_buffer.size
        for i, beat_rising in enumerate(beat_risings):
            if not beat_rising:
                continue
            x = i / (count - 1) * width
            line_start = plot_start[0] + x, plot_start[1]
            line_end = plot_start[0] + x, plot_start[1] + height
            draw_list.add_line(line_start, line_end,
                               imgui.get_color_u32_rgba(0.0, 0.8, 0.0, 0.8))

        threshold = min(1.0, max(0.0, self.get("threshold")))
        threshold_start = plot_start[0], plot_start[1] + (1.0 -
                                                          threshold) * height
        threshold_end = plot_start[0] + width, threshold_start[1]

        draw_list.add_line(threshold_start, threshold_end,
                           imgui.get_color_u32_rgba(0.8, 0.0, 0.0, 0.8))
예제 #7
0
    def draw(self):
        imgui.new_frame()

        pos_x = 10
        pos_y = 10
        sz = 20

        draw_list = imgui.get_window_draw_list()

        for i in range(0, imgui.COLOR_COUNT):
            name = imgui.get_style_color_name(i)
            draw_list.add_rect_filled(pos_x, pos_y, pos_x + sz, pos_y + sz,
                                      imgui.get_color_u32_idx(i))
            imgui.dummy(sz, sz)
            imgui.same_line()

        rgba_color = imgui.get_color_u32_rgba(1, 1, 0, 1)
        draw_list.add_rect_filled(pos_x, pos_y, pos_x + sz, pos_y + sz,
                                  rgba_color)

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
예제 #8
0
 def draw(self):
     imgui.begin("Image example")
     texture_id = imgui.get_io().fonts.texture_id
     draw_list = imgui.get_window_draw_list()
     draw_list.add_image(texture_id, (128, 64), (512, 256),
                         col=imgui.get_color_u32_rgba(0.5, 0.5, 1, 1))
     imgui.end()
예제 #9
0
def render_selection_line(window, p0, p1):
    with invisible_window(window):
        imgui.text("hej")
        x0, y0 = p0
        x1, y1 = p1
        draw_list = imgui.get_window_draw_list()
        draw_list.add_line(x0, y0, x1, y1,
                           imgui.get_color_u32_rgba(1, 1, 0, 1), 2)
예제 #10
0
def render_selection_rectangle(window, p0, p1, color=(1, 1, 0, 1)):
    with invisible_window(window):
        w, h = window.get_size()
        x0, y0 = p0
        x1, y1 = p1
        draw_list = imgui.get_window_draw_list()
        draw_list.add_rect(int(x0), int(h - y0), int(x1), int(h - y1),
                           imgui.get_color_u32_rgba(*color))
예제 #11
0
 def draw(self):
     imgui.begin("Line")
     draw_list = imgui.get_window_draw_list()
     draw_list.add_line(20, 35, 180, 80,
                        imgui.get_color_u32_rgba(1, 1, 0, 1), 3)
     draw_list.add_line(180, 35, 20, 80,
                        imgui.get_color_u32_rgba(1, 0, 0, 1), 3)
     imgui.end()
예제 #12
0
 def draw(self):
     imgui.begin("Circle")
     draw_list = imgui.get_window_draw_list()
     draw_list.add_circle(100,
                          60,
                          30,
                          imgui.get_color_u32_rgba(1, 1, 0, 1),
                          thickness=3)
     imgui.end()
예제 #13
0
def line(x0, y0, x1, y1, color, thickness=1, tf=None):
    """ Line connecting two points. """
    if tf is not None:
        [x0, y0], [x1, y1] = tf.transform(np.array([[x0, y0], [x1, y1]]))
    draw_list = imgui.get_window_draw_list()
    col = color_to_rgba(color)
    while True:
        draw_list.add_line(x0, y0, x1, y1, col, thickness)
        yield
예제 #14
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)} %')    
예제 #15
0
def polygon(points, color, tf=None):
    """ Filled polygon. Points must form a convex area.

    `points` is a list of (x, y) tuples, or a NumPy array of equivalent shape.
    """
    points = prepare_polyline_points(points, tf)
    draw_list = imgui.get_window_draw_list()
    col = color_to_rgba(color)
    while True:
        draw_list.add_convex_poly_filled(points, col)
        yield
예제 #16
0
def polyline(points, color, closed=False, thickness=1, tf=None):
    """ Polygonal line or a closed polygon.

    `points` is a list of (x, y) tuples, or a NumPy array of equivalent shape.
    """
    points = prepare_polyline_points(points, tf)
    draw_list = imgui.get_window_draw_list()
    col = color_to_rgba(color)
    while True:
        draw_list.add_polyline(points, col, closed, thickness)
        yield
예제 #17
0
 def draw(self):
     imgui.begin("Poly Line")
     draw_list = imgui.get_window_draw_list()
     draw_list.add_polyline([(20, 35), (90, 35), (55, 80)],
                            imgui.get_color_u32_rgba(1, 1, 0, 1),
                            closed=False,
                            thickness=3)
     draw_list.add_polyline([(110, 35), (180, 35), (145, 80)],
                            imgui.get_color_u32_rgba(1, 0, 0, 1),
                            closed=True,
                            thickness=3)
     imgui.end()
예제 #18
0
    def draw(self):
        imgui.new_frame()

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

        imgui.begin("Rectangle")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_rect(20,
                           35,
                           90,
                           80,
                           imgui.get_color_u32_rgba(1, 1, 0, 1),
                           thickness=3)
        draw_list.add_rect(110,
                           35,
                           180,
                           80,
                           imgui.get_color_u32_rgba(1, 0, 0, 1),
                           rounding=5,
                           thickness=3)
        imgui.end()

        imgui.set_next_window_position(270, 32, imgui.ONCE)
        imgui.set_next_window_size(256, 256, imgui.ONCE)

        imgui.begin("Filled Rectangle")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_rect_filled(20, 35, 90, 80,
                                  imgui.get_color_u32_rgba(1, 1, 0, 1))
        draw_list.add_rect_filled(110, 35, 180, 80,
                                  imgui.get_color_u32_rgba(1, 0, 0, 1), 5)
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
예제 #19
0
def rect(x0, y0, x1, y1, color, thickness=1, rounding=0, tf=None):
    """ Straight non-filled rectangle specified by its two corners. """
    if tf is not None:
        [x0, y0], [x1, y1] = tf.transform(np.array([[x0, y0], [x1, y1]]))
    # Avoid issues with disappearing lines on very large rectangles
    x0, x1 = np.clip([x0, x1], -8192, 8192)
    y0, y1 = np.clip([y0, y1], -8192, 8192)
    draw_list = imgui.get_window_draw_list()
    col = color_to_rgba(color)
    while True:
        draw_list.add_rect(x0, y0, x1, y1, col, rounding,
                           15 if rounding else 0, thickness)
        yield
예제 #20
0
def text(string, x, y, color, tf=None):
    """ Text, using the default font and font size.

    This is a raw drawing function. Use `concur.widgets.text` instead if you want a text widget.
    """
    if tf is not None:
        x, y = np.matmul(tf.c2s, [x, y, 1])
    col = color_to_rgba(color)
    while True:
        # Text was hanging the application if too far away
        if -8192 < x < 8192 and -8192 < y < 8192:
            draw_list = imgui.get_window_draw_list()
            draw_list.add_text(x, y, col, string)
        yield
예제 #21
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("Line")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_line(20, 35, 180, 80, imgui.get_color_u32_rgba(1,1,0,1), 3)
        draw_list.add_line(180, 35, 20, 80, imgui.get_color_u32_rgba(1,0,0,1), 3)
        imgui.end()

        imgui.begin("Poly Line")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_polyline([(20, 35), (90, 35), (55, 80)], imgui.get_color_u32_rgba(1,1,0,1), closed=False, thickness=3)
        draw_list.add_polyline([(110, 35), (180, 35), (145, 80)], imgui.get_color_u32_rgba(1,0,0,1), closed=True, thickness=3)
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
예제 #22
0
def image(tex_id, x, y, width, height, uv_a=(0, 0), uv_b=(1, 1), tf=None):
    """ Draw an image with the given origin (x, y), width and height.

    This is a raw drawing function. Use `concur.extra_widgets.image.image` instead
    if you want an image widget. Note that OpenGL textures may be rendered incorrectly
    if width or height isn't divisible by 4.
    """
    p1, p2 = [x, y], [x + width, y + height]
    if tf is not None:
        p1, p2 = tf.transform(np.array([p1, p2]))

    draw_list = imgui.get_window_draw_list()
    while True:
        draw_list.add_image(tex_id, tuple(p1), tuple(p2), uv_a, uv_b)
        yield
예제 #23
0
def polygons(points, color, tf=None):
    """ Multiple filled polygons with the same length and color.

    Calling this function is more efficient than calling `polygon` multiple times, because all the data is given
    to the C++ back-end in one Python call, and because transformation is vectorized.

    `points` is a NumPy array with shape `(n, m, 2)`, where `n` is the number of polygons, and `m` is the number of points
    in each polyline.
    """
    if tf is not None:
        points = tf.transform(points.reshape(-1, 2)).reshape(points.shape)
    draw_list = imgui.get_window_draw_list()
    col = color_to_rgba(color)
    while True:
        draw_list.add_convex_polys_filled(points, col)
        yield
예제 #24
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("Text")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_text(20, 35, imgui.get_color_u32_rgba(1, 1, 0, 1),
                           "Hello!")
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
예제 #25
0
def circle(cx, cy, radius, color, thickness=1, num_segments=16, tf=None):
    """ Circle specified by its center and radius. """
    if tf is not None:
        assert np.allclose(np.abs(tf.c2s[0, 0]), np.abs(tf.c2s[1, 1])), \
            "`tf` must be aspect ratio preserving to draw circles. Use `ellipse` instead, if it isn't the case."
        [cx, cy], radius = np.matmul(tf.c2s,
                                     [cx, cy, 1]), radius * tf.c2s[0, 0]
    draw_list = imgui.get_window_draw_list()
    col = color_to_rgba(color)
    while True:
        draw_list.add_circle(cx,
                             cy,
                             radius,
                             col,
                             num_segments=num_segments,
                             thickness=thickness)
        yield
예제 #26
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("Image example")
        draw_list = imgui.get_window_draw_list()
        #imgui.image(self.texture.glo, *self.texture.size)
        #draw_list.add_image(self.texture_id, (0, 0), (self.width, self.height))
        draw_list.add_image(self.texture.glo, (0, 0), self.texture.size)
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
예제 #27
0
def zoomtip(imtex, imdim, mag=1.0):
    if imgui.is_item_hovered():
        w, h = imgui.get_window_size()
        h = imdim[0] * w / imdim[1]
        rectmin = imgui.get_item_rect_min()
        mousepos = imgui.get_mouse_pos()
        u = float(mousepos[0] - rectmin[0]) / w
        v = float(mousepos[1] - rectmin[1]) / h
        imgui.begin_tooltip()
        tw = 32. / imdim[1] / mag
        th = 32. / imdim[0] / mag
        imgui.image(imtex, 64, 64, uv0=(u - tw, v - th), uv1=(u + tw, v + th))
        dl = imgui.get_window_draw_list()
        rm = imgui.get_item_rect_min()
        col = imgui.get_color_u32_rgba(1, 1, 0, 1)
        dl.add_line(rm[0], rm[1] + 32, rm[0] + 64, rm[1] + 32, col)
        dl.add_line(rm[0] + 32, rm[1], rm[0] + 32, rm[1] + 64, col)
        imgui.end()
예제 #28
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("Font image example")
        texture_id = imgui.get_io().fonts.texture_id
        draw_list = imgui.get_window_draw_list()
        draw_list.add_image(texture_id, (20, 35), (180, 80),
                            col=imgui.get_color_u32_rgba(0.5, 0.5, 1, 1))
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
예제 #29
0
    def render_map(self):
        imgui.begin("map")
        imgui.slider_float("x (m)",
                           self.track[self.i, 0] * ceiltrack.CEIL_HEIGHT, -80,
                           80)
        imgui.slider_float("y (m)",
                           self.track[self.i, 1] * ceiltrack.CEIL_HEIGHT, -80,
                           80)
        imgui.slider_float("theta", self.track[self.i, 2] % (np.pi * 2), -7, 7)
        imgui.slider_float("x (grid)",
                           self.track[self.i, 0] / ceiltrack.X_GRID, -10, 10)
        imgui.slider_float("y (grid)",
                           self.track[self.i, 1] / ceiltrack.X_GRID, -10, 10)

        changed, self.ceilheight = imgui.slider_float("ceiling height (m)",
                                                      self.ceilheight, 2, 4)
        if changed:
            self.loadframe(self.i)

        dl = imgui.get_window_draw_list()
        pos = imgui.get_cursor_screen_pos()
        siz = imgui.get_content_region_available()
        if siz[1] == 0:
            siz = [400, 300]
        # just use a fixed size
        w = siz[0]
        imgui.image_button(self.floortex, w, w / 2, frame_padding=0)
        # imgui.image_button(self.floortex, siz[0], siz[0])
        origin = [pos[0], pos[1]]
        scale = 50 * ceiltrack.CEIL_HEIGHT * w / 1000
        trackcolor = imgui.get_color_u32_rgba(0.3, 0.5, 0.3, 1)
        for i in range(1, self.i):
            dl.add_line(origin[0] + scale * self.track[i - 1, 0],
                        origin[1] + scale * self.track[i - 1, 1],
                        origin[0] + scale * self.track[i, 0],
                        origin[1] + scale * self.track[i, 1], trackcolor, 1.5)

        carcolor = imgui.get_color_u32_rgba(0, 1, 0.6, 1)
        B = self.track[self.i]
        dl.add_line(origin[0] + scale * B[0], origin[1] + scale * B[1],
                    origin[0] + scale * (B[0] + np.cos(B[2])),
                    origin[1] + scale * (B[1] - np.sin(B[2])), carcolor, 1.5)

        imgui.end()
예제 #30
0
def polylines(points, color, closed=False, thickness=1, tf=None):
    """ Multiple polygonal lines with the same length and parameters.

    Calling this function is more efficient than calling `polyline` multiple times, because all the data is given
    to the C++ back-end in one Python call, and because transformation is vectorized.

    `points` is a NumPy array with shape `(n, m, 2)`, where `n` is the number of polylines, and `m` is the number of points
    in each polyline.
    """
    if len(points) == 0:
        while True:
            yield
    if tf is not None:
        points = tf.transform(points.reshape(-1, 2)).reshape(points.shape)
    draw_list = imgui.get_window_draw_list()
    col = color_to_rgba(color)
    while True:
        draw_list.add_polylines(points, col, closed, thickness)
        yield