Refactor draw to be separate and handle ortho draw
This commit is contained in:
+115
-25
@@ -1,15 +1,23 @@
|
||||
#+feature dynamic-literals
|
||||
package edit2d
|
||||
import im "shared:odin-imgui"
|
||||
import mu "vendor:microui"
|
||||
import e2_glyph "./glyph"
|
||||
import "core:fmt"
|
||||
import "vendor:glfw"
|
||||
import b2 "vendor:box2d"
|
||||
|
||||
/*
|
||||
This library will only account for box2d's entities editing
|
||||
This library will only account for box2d's entities editing
|
||||
|
||||
It only deals with one world_id, which means typically one level
|
||||
It only deals with one world_id, which means typically one level
|
||||
|
||||
All the interface follows a pattern
|
||||
All the interface follows a pattern
|
||||
i.e. It takes interface_state pointer and returns a boolean indicating weather the world needs to be reloaded
|
||||
i.e. It takes interface_state pointer and returns a boolean indicating weather the world needs to be reloaded
|
||||
|
||||
|
||||
Interface should handle microui
|
||||
|
||||
*/
|
||||
|
||||
EditMode :: enum
|
||||
@@ -41,6 +49,51 @@ interface_state :: struct
|
||||
}
|
||||
|
||||
|
||||
|
||||
key_map : map[i32]mu.Key = {
|
||||
glfw.KEY_LEFT_SHIFT = .SHIFT,
|
||||
glfw.KEY_RIGHT_SHIFT = .SHIFT,
|
||||
glfw.KEY_LEFT_CONTROL = .CTRL,
|
||||
glfw.KEY_RIGHT = .CTRL,
|
||||
glfw.KEY_LEFT_ALT = .ALT,
|
||||
glfw.KEY_RIGHT_ALT = .ALT,
|
||||
glfw.KEY_BACKSPACE = .BACKSPACE,
|
||||
glfw.KEY_DELETE = .DELETE,
|
||||
glfw.KEY_ENTER = .RETURN,
|
||||
glfw.KEY_LEFT = .LEFT,
|
||||
glfw.KEY_RIGHT = .RIGHT,
|
||||
glfw.KEY_HOME = .HOME,
|
||||
glfw.KEY_END = .END,
|
||||
glfw.KEY_A = .A,
|
||||
glfw.KEY_X = .X,
|
||||
glfw.KEY_C = .C,
|
||||
glfw.KEY_V = .V
|
||||
}
|
||||
|
||||
mouse_map : map[i32]mu.Mouse = {
|
||||
glfw.MOUSE_BUTTON_LEFT = .LEFT,
|
||||
glfw.MOUSE_BUTTON_RIGHT = .RIGHT,
|
||||
glfw.MOUSE_BUTTON_MIDDLE= .MIDDLE,
|
||||
}
|
||||
|
||||
|
||||
|
||||
//interface_get_font
|
||||
|
||||
mui_text_width :: proc(font: mu.Font, str: string) -> i32
|
||||
{
|
||||
glyph := cast(^e2_glyph.GlyphState)font
|
||||
return i32(len(str)) * i32(glyph.font_size_pt)
|
||||
}
|
||||
|
||||
mui_text_height :: proc(font: mu.Font) -> i32
|
||||
{
|
||||
glyph := cast(^e2_glyph.GlyphState)font
|
||||
return i32(glyph.font_size_pt)
|
||||
}
|
||||
|
||||
|
||||
interface_get_default :: proc(interface: ^interface_state)
|
||||
{
|
||||
interface.selected_entity = 0
|
||||
interface.vertex_index = new(i32)
|
||||
@@ -50,7 +103,8 @@ interface_get_default :: proc(interface: ^interface_state)
|
||||
}
|
||||
|
||||
interface_draw_options :: proc(state: ^engine_state)
|
||||
interface_draw_options :: proc(state: ^engine_state) {
|
||||
{
|
||||
debug_draw := &state.draw.debug_draw
|
||||
|
||||
im.SliderFloat("Zoom", &state.draw.cam.zoom, 0, 100)
|
||||
im.Checkbox("Shapes", &debug_draw.drawShapes)
|
||||
@@ -70,6 +124,48 @@ interface_draw_options :: proc(state: ^engine_state) {
|
||||
}
|
||||
|
||||
mu_interface_game_mode :: proc(state: ^engine_state, interface: ^interface_state)
|
||||
{
|
||||
if mu.begin_window(&state.mu_ctx, "Edit Mode", {1700, 0, 250, 170})
|
||||
{
|
||||
for type in EditMode
|
||||
{
|
||||
b : bool = interface.edit_mode == type
|
||||
if .CHANGE in mu.checkbox(&state.mu_ctx, fmt.tprint(type), &b) do interface.edit_mode = type
|
||||
}
|
||||
mu.end_window(&state.mu_ctx)
|
||||
}
|
||||
}
|
||||
|
||||
mu_interface_draw_options :: proc(state: ^engine_state)
|
||||
{
|
||||
if mu.begin_window(&state.mu_ctx, "Options", {200, 150, 200, 400}){
|
||||
debug_draw := &state.draw.debug_draw
|
||||
|
||||
mu.label(&state.mu_ctx, "Zoom")
|
||||
mu.slider(&state.mu_ctx, &state.draw.cam.zoom,0, 100)
|
||||
|
||||
mu.checkbox(&state.mu_ctx, "Shapes", &debug_draw.drawShapes)
|
||||
mu.checkbox(&state.mu_ctx, "Joints", &debug_draw.drawJoints)
|
||||
mu.checkbox(&state.mu_ctx, "Joint Extras", &debug_draw.drawJointExtras)
|
||||
mu.checkbox(&state.mu_ctx, "Bounds", &debug_draw.drawBounds)
|
||||
mu.checkbox(&state.mu_ctx, "Contact Points", &debug_draw.drawContacts)
|
||||
mu.checkbox(&state.mu_ctx, "Contact Normals", &debug_draw.drawContactNormals)
|
||||
mu.checkbox(&state.mu_ctx, "Contact Inpulses", &debug_draw.drawContactImpulses)
|
||||
mu.checkbox(&state.mu_ctx, "Contact Features", &debug_draw.drawContactFeatures)
|
||||
mu.checkbox(&state.mu_ctx, "Friction Inpulses", &debug_draw.drawFrictionImpulses)
|
||||
mu.checkbox(&state.mu_ctx, "Mass ", &debug_draw.drawMass)
|
||||
mu.checkbox(&state.mu_ctx, "Body Names", &debug_draw.drawBodyNames)
|
||||
mu.checkbox(&state.mu_ctx, "Graph Colors", &debug_draw.drawGraphColors)
|
||||
mu.checkbox(&state.mu_ctx, "Islands ", &debug_draw.drawIslands)
|
||||
|
||||
mu.label(&state.mu_ctx, "Rotation")
|
||||
mu.slider(&state.mu_ctx, &state.draw.cam.rotation, 0, 360)
|
||||
|
||||
mu.end_window(&state.mu_ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface_all :: proc(interface: ^interface_state) -> bool
|
||||
{
|
||||
ret := false
|
||||
@@ -79,27 +175,26 @@ interface_all :: proc(interface: ^interface_state) -> bool
|
||||
}
|
||||
|
||||
state := interface.state
|
||||
if im.Begin("Edit Mode", nil)
|
||||
{
|
||||
for type in EditMode
|
||||
{
|
||||
if im.RadioButton(fmt.ctprint(type), interface.edit_mode == type)
|
||||
{
|
||||
interface.edit_mode = type
|
||||
}
|
||||
}
|
||||
}
|
||||
im.End()
|
||||
mu.begin(&state.mu_ctx)
|
||||
|
||||
//test_window(&state.mu_ctx)
|
||||
mu_interface_draw_options(interface.state)
|
||||
mu_interface_game_mode(state, interface)
|
||||
|
||||
if im.Begin("Box2d interface")
|
||||
{
|
||||
if im.BeginTabBar("Tabs")
|
||||
{
|
||||
|
||||
if mu.begin_window(&state.mu_ctx, "B2d Interface", {1700, 150, 250, 250})
|
||||
if im.BeginTabItem("Entity", nil, {.Leading})
|
||||
{
|
||||
if .ACTIVE in mu.header(&state.mu_ctx, "Entity", {.AUTO_SIZE})
|
||||
if interface_entity(interface) do ret = true
|
||||
im.EndTabItem()
|
||||
{
|
||||
if interface_entity(interface) do ret = true
|
||||
|
||||
}
|
||||
mu.end_window(&state.mu_ctx)
|
||||
}
|
||||
|
||||
if im.BeginTabItem("Joints", nil, {})
|
||||
{
|
||||
@@ -108,15 +203,10 @@ interface_all :: proc(interface: ^interface_state) -> bool
|
||||
}
|
||||
|
||||
im.EndTabBar()
|
||||
if im.BeginTabItem("Draw Options", nil, {})
|
||||
{
|
||||
interface_draw_options(interface.state)
|
||||
im.EndTabItem()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
mu.end(&state.mu_ctx)
|
||||
im.End()
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user