예제 #1
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)
예제 #2
0
def imguiX_color_edit3_list(label, v):
    a, b = imgui.color_edit3(
        label,
        *v)  #, imgui.GuiColorEditFlags_Float);// | ImGuiColorEditFlags_HSV);
    return a, list(b)
예제 #3
0
def userInterface(graphicItem, app):
    """ Control graphicItem parameters interactively
    """
    imgui.new_frame()
    expanded, opened = imgui.begin('Controls', closable=True,
            flags=imgui.WINDOW_ALWAYS_AUTO_RESIZE)
    if opened:
        # Field to show
        current = app.ifield
        changed, current = imgui.combo('Field', current, list(CHOICES))
        if changed:
            app.setField(current)

        # Speed Rate
        changed, speed = imgui.drag_float('Speed',
            graphicItem.speedFactor, 0.01, 0.0, 10.0)
        if changed:
            graphicItem.speedFactor = speed

        # Decay
        changed, decay = imgui.drag_float('Decay',
            graphicItem.decay, 0.001, 0.001, 1.0)
        if changed:
            graphicItem.decay = decay

        # Drop Rate Bump
        changed, decayBoost = imgui.drag_float('Decay boost',
            graphicItem.decayBoost, 0.01, 0.001, 1.0)
        if changed:
            graphicItem.decayBoost = decayBoost

        # Unknown const
        changed, opacity = imgui.drag_float('Opacity',
            graphicItem.fadeOpacity, 0.001, 0.900, 0.999, '%.4f')
        if changed:
            graphicItem.fadeOpacity = opacity

        # Palette
        changed, color = imgui.color_edit3('Color', *graphicItem.color)
        if changed:
            graphicItem.color = color
        imgui.same_line()
        changed, palette = imgui.checkbox("Palette", graphicItem.palette)
        if changed:
            graphicItem.palette = palette

        changed, bg_color = imgui.color_edit4('Background color',
                *app.bg_color)
        if changed:
            app.bg_color = bg_color

        # Point size
        changed, pointSize = imgui.input_int("Point size",
            graphicItem.pointSize, 1, 1, 1)
        if changed:
            if pointSize > 5:
                pointSize = 5
            elif pointSize < 1:
                pointSize = 1
            graphicItem.pointSize = pointSize

        # Number of Points
        changed, tracersCount = imgui.drag_int("Number of "
            "Tracers", graphicItem.tracersCount, 1000.0, 4000, 10000000)
        if changed:
            graphicItem.tracersCount = tracersCount

        # Periodic border
        changed, periodic = imgui.checkbox("Periodic", graphicItem.periodic)
        if changed:
            graphicItem.periodic = periodic

        # Draw field
        changed, drawfield = imgui.checkbox("Draw Field",
                graphicItem.drawField)
        if changed:
            graphicItem.drawField = drawfield
    imgui.end()
    imgui.render()
    return opened
예제 #4
0
    def layers(self):
        imgui.begin("Layers")
        if imgui.button("Refresh Screen", 208, 20):
            self.window.clear()
            self.canvas.draw_layers()
        changed, self.delete_index = imgui.input_int("Layer to delete", self.delete_index, 1, 100)
        if imgui.button("Delete", 100, 20):
            self.canvas.delete_object(self.delete_index-1)
        imgui.same_line()
        if imgui.button("Delete All", 100, 20):
            clear_index = self.canvas.get_length() - 1
            try:
                while clear_index >= 0:
                    self.canvas.delete_object(clear_index)
                    clear_index = clear_index - 1
            except clear_index == -1:
                print("No objects found!")
        index = 0

        # --Modification View
        if self.object_is_selected:
            if self.canvas.layers[self.selected].shape == "Circle":
                changed, self.mod_vrad = imgui.input_int("Radius", self.mod_vrad, 1, 100)  # imgui.core.input_int
                changed, self.mod_x_center = imgui.input_int("X-axis center", self.mod_x_center, 1, 800)  # imgui.core.slider_int, set max to window size
                changed, self.mod_y_center = imgui.input_int("Y-axis center", self.mod_y_center, 1, 600)
                changed, self.mod_color = imgui.color_edit3("Set Color", *self.mod_color)  # asterisk used for tuple, I think...
            elif self.canvas.layers[self.selected].shape == "Ellipse":
                changed, self.mod_vrad = imgui.input_int("Vertical Radius", self.mod_vrad, 1, 100)  # imgui.core.input_int
                changed, self.mod_hrad = imgui.input_int("Horizontal Radius", self.mod_hrad, 1, 100)
                changed, self.mod_x_center = imgui.input_int("X-axis center", self.mod_x_center, 1, 800)  # imgui.core.slider_int, set max to window size
                changed, self.mod_y_center = imgui.input_int("Y-axis center", self.mod_y_center, 1, 600)
                changed, self.mod_color = imgui.color_edit3("Set Color", *self.mod_color)  # asterisk used for tuple, I think...
            else:
                pass
            if imgui.button("Apply", 100, 20):
                self.canvas.layers[self.selected].move_to(self.mod_x_center, self.mod_y_center)
                self.canvas.layers[self.selected].set_color(color=Color(self.mod_color[0], self.mod_color[1], self.mod_color[2]))
                if self.canvas.layers[self.selected].shape == "Circle":
                    self.canvas.layers[self.selected].change_length(self.mod_vrad)
                elif self.canvas.layers[self.selected].shape == "Ellipse":
                    self.canvas.layers[self.selected].change_length(self.mod_vrad, self.mod_hrad)
            elif imgui.button("Cancel", 100, 20):
                self.object_is_selected = False

        imgui.new_line()
        imgui.separator()
        # --Layer View--
        for layer in self.canvas.layers:
            layer_str = "Layer: {}, shape: {}"
            imgui.text(layer_str.format(index + 1, layer.shape))
            layer_lbl = "Select Layer {}"
            if len(self.select_index) < (index + 1):
                self.select_index.append(False)
            if imgui.button(layer_lbl.format(index + 1), 125, 20):
                self.selected = index
                self.setCurrentValues(index)
                self.object_is_selected = True
            layer_str = "Layer: {}, shape: {}"
            imgui.same_line()
            imgui.text(layer_str.format(index + 1, layer.shape))
            index = index + 1
        imgui.end()
예제 #5
0
    def drawTools(self):
        imgui.begin("Drawing Tools")
        if imgui.button("Reset", 207, 20):
            self.color = .0, .0, .0
            self.drawMode = ""
            self.vrad = 0
            self.hrad = 0
            self.x_center = 400
            self.y_center = 300
        if imgui.button(
                "Circle", 100, 20
        ):  # imgui.core.button, https://github.com/ocornut/imgui/issues/2481
            self.drawMode = "c"
        imgui.same_line(115)
        if imgui.button("Ellipse", 100, 20):
            self.drawMode = "e"
        imgui.new_line()
        if self.drawMode == "c":
            changed, self.vrad = imgui.input_int("Radius", self.vrad, 1,
                                                 100)  # imgui.core.input_int
            changed, self.x_center = imgui.slider_int(
                "X-axis center", self.x_center, 0,
                800)  # imgui.core.slider_int, set max to window size
            changed, self.y_center = imgui.slider_int("Y-axis center",
                                                      self.y_center, 0, 600)
            changed, self.color = imgui.color_edit3(
                "Set Color",
                *self.color)  # asterisk used for tuple, I think...
        elif self.drawMode == "e":
            changed, self.vrad = imgui.input_int("Vertical Radius", self.vrad,
                                                 1,
                                                 100)  # imgui.core.input_int
            # changed, self.vrad = imgui.slider_int("", self.vrad, 0, 1000)
            changed, self.hrad = imgui.input_int("Horizontal Radius",
                                                 self.hrad, 1, 100)
            # changed, self.hrad = imgui.slider_int("Horizontal Radius", self.hrad, 0, 1000)
            changed, self.x_center = imgui.slider_int(
                "X-axis center", self.x_center, 0,
                800)  # imgui.core.slider_int, set max to window size
            changed, self.y_center = imgui.slider_int("Y-axis center",
                                                      self.y_center, 0, 600)
            changed, self.color = imgui.color_edit3(
                "Set Color",
                *self.color)  # asterisk used for tuple, I think...

        imgui.new_line
        imgui.begin_child("Current Settings",
                          border=True)  # imgui.core.begin_child
        imgui.text("Currently Drawing: ")  # imgui.core.text
        if self.drawMode == "c":
            imgui.same_line(200), imgui.text_colored(
                "Circle", 0, 1,
                0)  # imgui.core.same_line, imgui.core.text_colored
            imgui.text("Radius:"), imgui.same_line(200), imgui.text_colored(
                str(self.vrad), 0, 1, 0)
            imgui.text("X Position:"), imgui.same_line(
                200), imgui.text_colored(str(self.x_center), 0, 1, 0)
            imgui.text("Y Position:"), imgui.same_line(
                200), imgui.text_colored(str(self.y_center), 0, 1, 0)
        elif self.drawMode == "e":
            imgui.same_line(200), imgui.text_colored("Ellipse", 0, 1, 0)
            imgui.text("V. Radius:"), imgui.same_line(200), imgui.text_colored(
                str(self.vrad), 0, 1, 0)
            imgui.text("H. Radius:"), imgui.same_line(200), imgui.text_colored(
                str(self.hrad), 0, 1, 0)
            imgui.text("X Position:"), imgui.same_line(
                200), imgui.text_colored(str(self.x_center), 0, 1, 0)
            imgui.text("Y Position:"), imgui.same_line(
                200), imgui.text_colored(str(self.y_center), 0, 1, 0)
        else:
            imgui.text("Nothing Selected")
        imgui.end_child()
        imgui.end()