Change Naming Convention, add scroll to microui
This commit is contained in:
+30
-36
@@ -12,6 +12,7 @@ import "shared:odin-imgui/imgui_impl_glfw"
|
||||
import "shared:odin-imgui/imgui_impl_opengl3"
|
||||
**/
|
||||
|
||||
import "core:fmt"
|
||||
import gl "vendor:OpenGL"
|
||||
import "vendor:glfw"
|
||||
import e2_draw "shared:Edit2D/draw"
|
||||
@@ -22,12 +23,13 @@ import mu "vendor:microui"
|
||||
//Only to be used inside the libarary
|
||||
__e2d_interal : struct
|
||||
{
|
||||
viewport_changed : bool
|
||||
viewport_changed : bool,
|
||||
mouse_scroll : [2]f64,
|
||||
}
|
||||
|
||||
|
||||
|
||||
engine_state :: struct
|
||||
Engine_State :: struct
|
||||
{
|
||||
window : glfw.WindowHandle,
|
||||
debug_draw : b2.DebugDraw,
|
||||
@@ -43,7 +45,7 @@ engine_state :: struct
|
||||
tex_line : u32,
|
||||
drop_callback : glfw.DropProc,
|
||||
|
||||
input : input_state,
|
||||
input : Input_State,
|
||||
|
||||
mu_ctx : mu.Context,
|
||||
mu_tex : u32,
|
||||
@@ -51,7 +53,7 @@ engine_state :: struct
|
||||
|
||||
MAX_KEYS :: 512
|
||||
|
||||
input_state :: struct
|
||||
Input_State :: struct
|
||||
{
|
||||
mouse_wheel : [2]f64,
|
||||
mouse : [2]f64,
|
||||
@@ -86,7 +88,7 @@ engine_check_types :: proc($Game: typeid)
|
||||
level_engine_type := reflect.struct_field_by_name(level_map_type.value.id, "engine")
|
||||
|
||||
assert(level_engine_type.is_using, "Should be using engine")
|
||||
assert(level_engine_type.type.id == typeid_of(engine_world), "Should be using engine")
|
||||
assert(level_engine_type.type.id == typeid_of(Engine_World), "Should be using engine")
|
||||
|
||||
entities_type := reflect.struct_field_by_name(level_map_type.value.id, "entities")
|
||||
entity_defs_type := reflect.struct_field_by_name(level_map_type.value.id, "entity_defs")
|
||||
@@ -104,7 +106,7 @@ engine_check_types :: proc($Game: typeid)
|
||||
assert(defs_engine.is_using, "Should be using")
|
||||
|
||||
assert(entity_engine.type.id == typeid_of(engine_entity))
|
||||
assert(defs_engine.type.id == typeid_of(engine_entity_def))
|
||||
assert(defs_engine.type.id == typeid_of(Engine_Entity_Def))
|
||||
|
||||
}
|
||||
|
||||
@@ -114,11 +116,16 @@ size_callback :: proc "c" (window: glfw.WindowHandle, width, height : i32)
|
||||
__e2d_interal.viewport_changed = true
|
||||
}
|
||||
|
||||
scroll_callback :: proc "c" (window : glfw.WindowHandle, x, y : f64)
|
||||
{
|
||||
__e2d_interal.mouse_scroll = {x, y}
|
||||
}
|
||||
|
||||
/*
|
||||
This will only be called once to initilize the engine
|
||||
initilize graphics library, glfw, callbacks
|
||||
*/
|
||||
engine_init :: proc($GameType : typeid, state: ^engine_state, font_path : string="")
|
||||
engine_init :: proc($GameType : typeid, state: ^Engine_State, font_path : string="")
|
||||
{
|
||||
|
||||
engine_check_types(GameType)
|
||||
@@ -134,9 +141,6 @@ engine_init :: proc($GameType : typeid, state: ^engine_state, font_path : strin
|
||||
|
||||
state.window = glfw.CreateWindow(state.width, state.height, state.title, nil, nil)
|
||||
|
||||
|
||||
//gl.DebugMessageControl(gl.DONT_CARE, gl.DONT_CARE, gl.DONT_CARE, 0, nil, gl.TRUE);
|
||||
|
||||
assert(state.window != nil)
|
||||
|
||||
glfw.MakeContextCurrent(state.window)
|
||||
@@ -144,6 +148,7 @@ engine_init :: proc($GameType : typeid, state: ^engine_state, font_path : strin
|
||||
gl.load_up_to(4, 5, glfw.gl_set_proc_address)
|
||||
|
||||
glfw.SetWindowSizeCallback(state.window, size_callback)
|
||||
glfw.SetScrollCallback( state.window, scroll_callback)
|
||||
|
||||
state.draw.cam = e2_draw.camera_init()
|
||||
|
||||
@@ -152,7 +157,7 @@ engine_init :: proc($GameType : typeid, state: ^engine_state, font_path : strin
|
||||
state.draw.cam.height = display_h
|
||||
state.draw.cam.zoom = 15
|
||||
state.draw.show_ui = true
|
||||
|
||||
|
||||
e2_draw.draw_create(&state.draw, &state.draw.cam, font_path)
|
||||
draw_configure_box2d(state)
|
||||
|
||||
@@ -201,9 +206,10 @@ normalize_rect :: proc(rect : mu.Rect, size : i32) -> e2_draw.Rect
|
||||
}
|
||||
|
||||
|
||||
update_frame :: proc(state: ^engine_state)
|
||||
update_frame :: proc(state: ^Engine_State)
|
||||
{
|
||||
state.input.mouse_wheel = {}
|
||||
__e2d_interal.mouse_scroll = {}
|
||||
glfw.PollEvents()
|
||||
|
||||
keyboard_update(state)
|
||||
@@ -211,6 +217,9 @@ update_frame :: proc(state: ^engine_state)
|
||||
x, y:= glfw.GetCursorPos(state.window)
|
||||
|
||||
mu.input_mouse_move(&state.mu_ctx, i32(x), i32(y))
|
||||
|
||||
wheel := __e2d_interal.mouse_scroll
|
||||
mu.input_scroll(&state.mu_ctx, i32(wheel.x) * 10, i32(wheel.y) * -20)
|
||||
{
|
||||
for key in key_map
|
||||
{
|
||||
@@ -221,7 +230,7 @@ update_frame :: proc(state: ^engine_state)
|
||||
for key in mouse_map
|
||||
{
|
||||
if is_key_pressed(state, key) do mu.input_mouse_down(&state.mu_ctx, i32(x), i32(y), mouse_map[key])
|
||||
if is_key_released(state, key) do mu.input_mouse_up(&state.mu_ctx,i32(x), i32(y), mouse_map[key])
|
||||
if is_key_released(state, key) do mu.input_mouse_up( &state.mu_ctx,i32(x), i32(y), mouse_map[key])
|
||||
}
|
||||
|
||||
}
|
||||
@@ -236,21 +245,10 @@ update_frame :: proc(state: ^engine_state)
|
||||
state.width , state.height = glfw.GetFramebufferSize(state.window)
|
||||
gl.Viewport(0, 0, state.width, state.height)
|
||||
|
||||
/*
|
||||
imgui_impl_opengl3.NewFrame()
|
||||
imgui_impl_glfw.NewFrame()
|
||||
im.NewFrame()
|
||||
*/
|
||||
}
|
||||
|
||||
end_frame :: proc(state: ^engine_state)
|
||||
end_frame :: proc(state: ^Engine_State)
|
||||
{
|
||||
/*
|
||||
im.Render()
|
||||
imgui_impl_opengl3.RenderDrawData(im.GetDrawData())
|
||||
*/
|
||||
|
||||
|
||||
//Microui
|
||||
|
||||
fb_x, fb_y := glfw.GetFramebufferSize(state.window)
|
||||
@@ -300,27 +298,24 @@ end_frame :: proc(state: ^engine_state)
|
||||
src_rect = normalize_rect(rect, mu.DEFAULT_ATLAS_WIDTH),
|
||||
dst_rect = e2_draw.Rect{f32(c.rect.x), f32(c.rect.y), f32(rect.w), f32(rect.h)},
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cleanup :: proc(state: ^engine_state)
|
||||
cleanup :: proc(state: ^Engine_State)
|
||||
{
|
||||
//imgui_impl_opengl3.Shutdown()
|
||||
//imgui_impl_glfw.Shutdown()
|
||||
}
|
||||
|
||||
engine_should_close :: proc(state : ^engine_state) -> b32
|
||||
engine_should_close :: proc(state : ^Engine_State) -> b32
|
||||
{
|
||||
return glfw.WindowShouldClose(state.window)
|
||||
}
|
||||
|
||||
|
||||
keyboard_update :: proc(state: ^engine_state)
|
||||
keyboard_update :: proc(state: ^Engine_State)
|
||||
{
|
||||
state.input.mouse_prev = state.input.mouse
|
||||
|
||||
@@ -341,20 +336,20 @@ keyboard_update :: proc(state: ^engine_state)
|
||||
}
|
||||
}
|
||||
|
||||
is_key_down :: #force_inline proc(state: ^engine_state, key : i32) -> bool{
|
||||
is_key_down :: #force_inline proc(state: ^Engine_State, key : i32) -> bool{
|
||||
return state.input.curr[key]
|
||||
}
|
||||
|
||||
is_key_pressed :: #force_inline proc(state: ^engine_state, key : i32) -> bool{
|
||||
is_key_pressed :: #force_inline proc(state: ^Engine_State, key : i32) -> bool{
|
||||
return state.input.curr[key] && !state.input.prev[key]
|
||||
}
|
||||
|
||||
is_key_released :: #force_inline proc(state: ^engine_state, key : i32) -> bool{
|
||||
is_key_released :: #force_inline proc(state: ^Engine_State, key : i32) -> bool{
|
||||
return !state.input.curr[key] && state.input.prev[key]
|
||||
}
|
||||
|
||||
|
||||
draw_flush :: proc(state: ^engine_state)
|
||||
draw_flush :: proc(state: ^Engine_State)
|
||||
{
|
||||
d := &state.draw
|
||||
if __e2d_interal.viewport_changed
|
||||
@@ -366,7 +361,6 @@ draw_flush :: proc(state: ^engine_state)
|
||||
d.glyph.height = d.cam.height
|
||||
|
||||
e2_glyph.glyph_init(&d.glyph, d.font_path)
|
||||
|
||||
}
|
||||
e2_draw.draw_flush(d, __e2d_interal.viewport_changed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user