wip : trying to fix the workspace view bounds detection

This commit is contained in:
Edward R. Gonzalez 2024-06-25 02:38:08 -04:00
parent 1f4d07727e
commit 1fe741034d
9 changed files with 59 additions and 25 deletions

View File

@ -72,7 +72,7 @@ hmap_chained_init :: proc( $HMapChainedType : typeid/HMapChained($Type), lookup_
pool_bucket_cap := pool_bucket_cap
if pool_bucket_cap == 0 {
pool_bucket_cap = cast(uint) int(lookup_capacity) * size_of( HMapChainedSlot(Type)) * 2
pool_bucket_cap = cast(uint) int(lookup_capacity) * size_of( HMapChainedSlot(Type)) //* 2
}
table.header = cast( ^HMapChainedHeader(Type)) raw_mem

View File

@ -325,7 +325,8 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
ui_startup( & workspace.ui, cache_allocator = persistent_slab_allocator() )
}
debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem_Ispsum (197).txt", allocator = persistent_slab_allocator())
debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (197).txt", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (1022).txt", allocator = persistent_slab_allocator())
alloc_error : AllocatorError; success : bool
debug.lorem_content, success = os.read_entire_file( debug.path_lorem, persistent_slab_allocator() )

View File

@ -77,6 +77,7 @@ render_mode_2d_workspace :: proc()
render_set_color(Color_White)
draw_filled_circle(0, 0, 2 * cam_zoom_ratio, 24)
// Blend test
if false
{
gp.set_color( 1.0, 0, 0, 0.25 )
@ -93,10 +94,25 @@ render_mode_2d_workspace :: proc()
render_flush_gp()
}
// Visualize view bounds
when true
{
render_set_view_space(screen_extent)
// render_set_camera(cam)
view_bounds := view_get_bounds()
view_bounds.min *= 0.9
view_bounds.max *= 0.9
draw_rect( view_bounds, { 0, 0, 180, 30 } )
render_flush_gp()
}
render_set_view_space(screen_extent)
render_set_camera(cam)
ui := & project.workspace.ui
ui_context = & project.workspace.ui
when UI_Render_Method == .Layers {
render_list := array_to_slice( ui.render_list )
@ -106,6 +122,8 @@ render_mode_2d_workspace :: proc()
{
render_ui_via_box_tree( ui.root, & cam )
}
ui_context = nil
}
render_mode_screenspace :: proc()
@ -219,6 +237,8 @@ render_mode_screenspace :: proc()
{
ui := & project.workspace.ui
debug_text("Workspace Cam : %v", project.workspace.cam)
debug_text("Box Count (Workspace): %v", ui.built_box_count )
hot_box := ui_box_from_key( ui.curr_cache, ui.hot )
@ -266,6 +286,7 @@ render_screen_ui :: proc()
render_set_view_space(screen_extent)
ui := & screen_ui
state.ui_context = & screen_ui
text_enqueued : b32 = false
shape_enqueued : b32 = false
@ -278,11 +299,13 @@ render_screen_ui :: proc()
{
render_ui_via_box_tree( ui.root )
}
state.ui_context = nil
}
render_text_layer :: proc()
{
// profile("VEFontCache: render text layer")
profile("VEFontCache: render text layer")
Bindings :: gfx.Bindings
Range :: gfx.Range
@ -327,7 +350,7 @@ render_text_layer :: proc()
// 1. Do the glyph rendering pass
// Glyphs are first rendered to an intermediate 2k x 512px R8 texture
case .Glyph:
// profile("VEFontCache: draw call: glyph")
profile("VEFontCache: draw call: glyph")
if num_indices == 0 && ! draw_call.clear_before_draw {
continue
}
@ -363,7 +386,7 @@ render_text_layer :: proc()
// 2. Do the atlas rendering pass
// A simple 16-tap box downsample shader is then used to blit from this intermediate texture to the final atlas location
case .Atlas:
// profile("VEFontCache: draw call: atlas")
profile("VEFontCache: draw call: atlas")
if num_indices == 0 && ! draw_call.clear_before_draw {
continue
}
@ -409,7 +432,7 @@ render_text_layer :: proc()
continue
}
// profile("VEFontCache: draw call: target")
profile("VEFontCache: draw call: target")
width := u32(app_window.extent.x * 2)
height := u32(app_window.extent.y * 2)
@ -467,8 +490,7 @@ render_ui_via_box_tree :: proc( root : ^UI_Box, cam : ^Camera = nil )
default_font := get_state().default_font
cam_zoom_ratio := cam != nil ? 1.0 / cam.zoom : 1.0
circle_radius := cam != nil ? cam_zoom_ratio * 3 : 3
circle_radius := cam != nil ? cam_zoom_ratio * 3 : 3
for box := root.first; box != nil; box = ui_box_tranverse_next_depth_based( box )
{
@ -483,7 +505,7 @@ render_ui_via_box_tree :: proc( root : ^UI_Box, cam : ^Camera = nil )
using computed
// profile("enqueue box")
profile("enqueue box")
GP_Render:
{
@ -719,7 +741,6 @@ draw_text_string_pos_extent_zoomed :: proc( content : string, id : FontID, size
text_scale /= over_sample
color_norm := normalize_rgba8(color)
// logf("zoom_adjust_size: %v", zoom_adjust_size)
ve.set_colour( & font_provider_data.ve_font_cache, color_norm )
ve.draw_text( & font_provider_data.ve_font_cache, ve_id, content, normalized_pos, text_scale )
}

View File

@ -168,7 +168,7 @@ update :: proc( delta_time : f64 ) -> b32
config.cam_min_zoom = 0.10
config.cam_zoom_sensitivity_digital = 0.05
config.cam_zoom_sensitivity_smooth = 2.0
config.cam_zoom_mode = .Smooth
config.cam_zoom_mode = .Digital
switch config.cam_zoom_mode
{
case .Smooth:
@ -247,9 +247,9 @@ update :: proc( delta_time : f64 ) -> b32
config.ui_resize_border_width = 2.5
// test_hover_n_click()
// test_draggable()
// test_text_box()
test_text_box()
// test_parenting( & default_layout, & frame_style_default )
test_whitespace_ast( & default_layout, & frame_style_default )
// test_whitespace_ast( & default_layout, & frame_style_default )
}
//endregion Workspace Imgui Tick

View File

@ -116,6 +116,14 @@ add_range2 :: #force_inline proc "contextless" ( a, b : Range2 ) -> Range2 {
return result
}
// mul_range2 :: #force_inline proc "contextless" ( a, b : Range2 ) -> Range2 {
// result := Range2 { pts = {
// a.p0 + b.p0,
// a.p1 + b.p1,
// }}
// return result
// }
sub_range2 :: #force_inline proc "contextless" ( a, b : Range2 ) -> Range2 {
// result := Range2 { array = a.array - b.array }
result := Range2 { mat = a.mat - b.mat }

View File

@ -168,8 +168,11 @@ view_get_bounds :: #force_inline proc "contextless"() -> Range2 {
cam := & project.workspace.cam
screen_extent := state.app_window.extent
cam_zoom_ratio := 1.0 / cam.zoom
bottom_left := Vec2 { cam.position.x, cam.position.y } + Vec2 { screen_extent.x, screen_extent.y} * cam_zoom_ratio
top_right := Vec2 { cam.position.x, cam.position.y } + Vec2 { screen_extent.x, screen_extent.y} * cam_zoom_ratio
bottom_left := Vec2 { -screen_extent.x, -screen_extent.y}
top_right := Vec2 { screen_extent.x, screen_extent.y}
bottom_left = screen_to_ws_view_pos(bottom_left)
top_right = screen_to_ws_view_pos(top_right)
return range2( bottom_left, top_right )
}
@ -202,7 +205,7 @@ render_to_ws_view_pos :: #force_inline proc "contextless" (pos : Vec2) -> Vec2 {
screen_to_ws_view_pos :: #force_inline proc "contextless" (pos: Vec2) -> Vec2 {
state := get_state(); using state
cam := & project.workspace.cam
result := (Vec2 { cam.position.x, -cam.position.y} + Vec2 { pos.x, pos.y }) * (1 / cam.zoom)
result := pos - cam.position * cam.zoom
return result
}

View File

@ -506,12 +506,13 @@ ui_top_ancestor :: #force_inline proc "contextless" ( box : ^UI_Box ) -> (^UI_Bo
ui_view_bounds :: #force_inline proc "contextless" () -> (range : Range2) {
using state := get_state();
if ui_context == & screen_ui {
return screen_get_bounds()
}
else {
// if ui_context == & screen_ui {
// return screen_get_bounds()
// }
// else {
return view_get_bounds()
}
// }
}
ui_context :: #force_inline proc() -> ^UI_State { return get_state().ui_context }

View File

@ -204,8 +204,8 @@ push-location $path_root
# $build_args += $flag_micro_architecture_native
$build_args += $flag_use_separate_modules
$build_args += $flag_thread_count + $CoreCount_Physical
$build_args += $flag_optimize_none
# $build_args += $flag_optimize_minimal
# $build_args += $flag_optimize_none
$build_args += $flag_optimize_minimal
# $build_args += $flag_optimize_speed
# $build_args += $falg_optimize_aggressive
$build_args += $flag_debug
@ -280,10 +280,10 @@ push-location $path_root
# $build_args += $flag_micro_architecture_native
$build_args += $flag_use_separate_modules
$build_args += $flag_thread_count + $CoreCount_Physical
$build_args += $flag_optimize_none
# $build_args += $flag_optimize_none
# $build_args += $flag_optimize_minimal
# $build_args += $flag_optimize_speed
# $build_args += $falg_optimize_aggressive
$build_args += $falg_optimize_aggressive
$build_args += $flag_debug
$build_args += $flag_pdb_name + $pdb
$build_args += $flag_subsystem + 'windows'