2024-02-10 00:40:53 -08:00
|
|
|
package sectr
|
|
|
|
|
|
|
|
import "core:fmt"
|
|
|
|
|
|
|
|
import rl "vendor:raylib"
|
|
|
|
|
|
|
|
render :: proc()
|
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
profile(#procedure)
|
2024-02-10 00:40:53 -08:00
|
|
|
state := get_state(); using state
|
2024-02-27 04:50:57 -08:00
|
|
|
replay := & Memory_App.replay
|
2024-02-11 20:00:06 -08:00
|
|
|
cam := & project.workspace.cam
|
|
|
|
win_extent := state.app_window.extent
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
screen_top_left : Vec2 = {
|
|
|
|
-win_extent.x + cam.target.x,
|
|
|
|
-win_extent.y + cam.target.y,
|
|
|
|
}
|
2024-02-10 00:40:53 -08:00
|
|
|
|
|
|
|
rl.BeginDrawing()
|
|
|
|
rl.ClearBackground( Color_BG )
|
2024-02-11 20:00:06 -08:00
|
|
|
render_mode_2d()
|
2024-02-22 18:19:29 -08:00
|
|
|
//region Render Screenspace
|
2024-02-10 00:40:53 -08:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
profile("Render Screenspace")
|
2024-03-08 15:45:08 -08:00
|
|
|
fps_msg := str_fmt_tmp( "FPS: %f", 1 / (frametime_elapsed_ms * MS_To_S) )
|
2024-02-13 14:16:39 -08:00
|
|
|
fps_msg_width := measure_text_size( fps_msg, default_font, 16.0, 0.0 ).x
|
2024-02-11 20:00:06 -08:00
|
|
|
fps_msg_pos := screen_get_corners().top_right - { fps_msg_width, 0 }
|
2024-02-13 14:16:39 -08:00
|
|
|
debug_draw_text( fps_msg, fps_msg_pos, 16.0, color = rl.GREEN )
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
debug_text :: proc( format : string, args : ..any )
|
|
|
|
{
|
|
|
|
@static draw_text_scratch : [Kilobyte * 64]u8
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
state := get_state(); using state
|
|
|
|
if debug.draw_debug_text_y > 800 {
|
|
|
|
debug.draw_debug_text_y = 50
|
|
|
|
}
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
cam := & project.workspace.cam
|
|
|
|
screen_corners := screen_get_corners()
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
position := screen_corners.top_right
|
2024-03-02 07:24:09 -08:00
|
|
|
position.x -= 800
|
2024-02-11 20:00:06 -08:00
|
|
|
position.y += debug.draw_debug_text_y
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
content := str_fmt_buffer( draw_text_scratch[:], format, ..args )
|
2024-03-08 15:45:08 -08:00
|
|
|
debug_draw_text( content, position, 14.0 )
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-03-08 15:45:08 -08:00
|
|
|
debug.draw_debug_text_y += 14
|
2024-02-11 20:00:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Debug Text
|
|
|
|
{
|
2024-03-10 07:31:21 -07:00
|
|
|
// debug_text( "Screen Width : %v", rl.GetScreenWidth () )
|
|
|
|
// debug_text( "Screen Height: %v", rl.GetScreenHeight() )
|
2024-03-08 15:45:08 -08:00
|
|
|
debug_text( "frametime_target_ms : %f ms", frametime_target_ms )
|
|
|
|
debug_text( "frametime : %f ms", frametime_delta_ms )
|
2024-03-10 07:31:21 -07:00
|
|
|
// debug_text( "frametime_last_elapsed_ms : %f ms", frametime_elapsed_ms )
|
2024-02-11 20:00:06 -08:00
|
|
|
if replay.mode == ReplayMode.Record {
|
|
|
|
debug_text( "Recording Input")
|
|
|
|
}
|
|
|
|
if replay.mode == ReplayMode.Playback {
|
|
|
|
debug_text( "Replaying Input")
|
|
|
|
}
|
2024-02-10 00:40:53 -08:00
|
|
|
}
|
2024-02-11 20:00:06 -08:00
|
|
|
|
2024-03-08 00:34:21 -08:00
|
|
|
debug_text("Zoom Target: %v", project.workspace.zoom_target)
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
if debug.mouse_vis {
|
2024-03-08 00:34:21 -08:00
|
|
|
debug_text( "Mouse Vertical Wheel: %v", input.mouse.vertical_wheel )
|
2024-03-02 07:24:09 -08:00
|
|
|
debug_text( "Mouse Position (Screen): %v", input.mouse.pos )
|
|
|
|
debug_text("Mouse Position (World): %v", screen_to_world(input.mouse.pos) )
|
2024-02-11 21:35:22 -08:00
|
|
|
cursor_pos := transmute(Vec2) state.app_window.extent + input.mouse.pos
|
|
|
|
rl.DrawCircleV( cursor_pos, 10, Color_White_A125 )
|
2024-02-10 00:40:53 -08:00
|
|
|
}
|
2024-03-08 00:34:21 -08:00
|
|
|
|
2024-03-09 10:55:47 -08:00
|
|
|
ui := project.workspace.ui
|
|
|
|
|
2024-03-10 17:09:04 -07:00
|
|
|
debug_text("Box Count: %v", ui.built_box_count )
|
|
|
|
|
|
|
|
hot_box := ui_box_from_key( ui.curr_cache, ui.hot )
|
|
|
|
active_box := ui_box_from_key( ui.curr_cache, ui.active )
|
2024-03-09 10:55:47 -08:00
|
|
|
if hot_box != nil {
|
2024-03-10 23:05:30 -07:00
|
|
|
debug_text("Hot Box : %v", hot_box.label.str )
|
|
|
|
debug_text("Hot Range2: %v", hot_box.computed.bounds.pts)
|
2024-03-09 10:55:47 -08:00
|
|
|
}
|
|
|
|
if active_box != nil{
|
|
|
|
debug_text("Active Box: %v", active_box.label.str )
|
|
|
|
}
|
2024-03-10 07:31:21 -07:00
|
|
|
// debug_text("Active Resizing: %v", ui.active_start_signal.resizing)
|
2024-03-09 10:55:47 -08:00
|
|
|
|
2024-03-10 23:05:30 -07:00
|
|
|
view := view_get_bounds()
|
|
|
|
debug_text("View Bounds (World): %v", view.pts )
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
debug.draw_debug_text_y = 50
|
2024-02-10 00:40:53 -08:00
|
|
|
}
|
2024-02-22 18:19:29 -08:00
|
|
|
//endregion Render Screenspace
|
2024-02-11 20:00:06 -08:00
|
|
|
rl.EndDrawing()
|
|
|
|
}
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-02-13 23:29:08 -08:00
|
|
|
render_mode_2d :: proc()
|
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
profile(#procedure)
|
2024-02-11 20:00:06 -08:00
|
|
|
state := get_state(); using state
|
|
|
|
cam := & project.workspace.cam
|
2024-03-02 07:24:09 -08:00
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
win_extent := state.app_window.extent
|
2024-02-10 00:40:53 -08:00
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
rl.BeginMode2D( project.workspace.cam )
|
|
|
|
|
2024-03-10 07:31:21 -07:00
|
|
|
// draw_text( "This is text in world space", { 0, 200 }, 16.0 )
|
2024-03-08 00:34:21 -08:00
|
|
|
|
2024-03-09 11:53:51 -08:00
|
|
|
cam_zoom_ratio := 1.0 / cam.zoom
|
|
|
|
|
2024-03-10 23:05:30 -07:00
|
|
|
view_bounds := view_get_bounds()
|
|
|
|
when false
|
|
|
|
{
|
|
|
|
render_view := Range2 { pts = {
|
|
|
|
world_to_screen_pos(view_bounds.min),
|
|
|
|
world_to_screen_pos(view_bounds.max),
|
|
|
|
}}
|
|
|
|
view_rect := rl.Rectangle {
|
|
|
|
render_view.min.x,
|
|
|
|
render_view.min.y,
|
|
|
|
render_view.max.x - render_view.min.x,
|
|
|
|
render_view.max.y - render_view.min.y,
|
|
|
|
}
|
|
|
|
rl.DrawRectangleRounded( view_rect, 0.3, 9, { 255, 0, 0, 20 } )
|
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
ImguiRender:
|
2024-02-22 18:19:29 -08:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
profile("Imgui Render")
|
2024-03-02 07:24:09 -08:00
|
|
|
ui := & state.project.workspace.ui
|
|
|
|
root := ui.root
|
|
|
|
if root.num_children == 0 {
|
|
|
|
break ImguiRender
|
|
|
|
}
|
|
|
|
|
|
|
|
current := root.first
|
2024-03-10 23:05:30 -07:00
|
|
|
for ; current != nil; current = ui_box_tranverse_next( current )
|
2024-03-10 23:05:18 -07:00
|
|
|
{
|
|
|
|
profile("Box")
|
2024-03-02 07:24:09 -08:00
|
|
|
parent := current.parent
|
|
|
|
|
|
|
|
style := current.style
|
|
|
|
computed := & current.computed
|
|
|
|
|
2024-03-13 21:00:22 -07:00
|
|
|
computed_size := computed.bounds.p1 - computed.bounds.p0
|
|
|
|
|
2024-03-10 23:05:30 -07:00
|
|
|
if ! within_range2( view_bounds, computed.bounds ) {
|
2024-03-14 07:11:04 -07:00
|
|
|
continue
|
2024-03-10 23:05:30 -07:00
|
|
|
}
|
2024-03-08 16:51:46 -08:00
|
|
|
|
2024-03-10 23:05:30 -07:00
|
|
|
// TODO(Ed) : Render Borders
|
2024-02-11 21:35:22 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile_begin("Calculating Raylib rectangles")
|
2024-03-13 23:02:09 -07:00
|
|
|
render_bounds := range2(
|
2024-03-02 07:24:09 -08:00
|
|
|
world_to_screen_pos(computed.bounds.min),
|
|
|
|
world_to_screen_pos(computed.bounds.max),
|
2024-03-13 23:02:09 -07:00
|
|
|
)
|
2024-03-02 07:24:09 -08:00
|
|
|
|
2024-03-09 07:21:48 -08:00
|
|
|
render_padding := range2(
|
|
|
|
world_to_screen_pos(computed.padding.min),
|
|
|
|
world_to_screen_pos(computed.padding.max),
|
|
|
|
)
|
|
|
|
render_content := range2(
|
|
|
|
world_to_screen_pos(computed.content.min),
|
|
|
|
world_to_screen_pos(computed.content.max),
|
|
|
|
)
|
|
|
|
|
|
|
|
rect_bounds := rl.Rectangle {
|
2024-03-02 07:24:09 -08:00
|
|
|
render_bounds.min.x,
|
2024-03-13 23:02:09 -07:00
|
|
|
render_bounds.max.y,
|
|
|
|
abs(render_bounds.max.x - render_bounds.min.x),
|
|
|
|
abs(render_bounds.max.y - render_bounds.min.y),
|
2024-03-02 07:24:09 -08:00
|
|
|
}
|
2024-03-09 07:21:48 -08:00
|
|
|
rect_padding := rl.Rectangle {
|
|
|
|
render_padding.min.x,
|
2024-03-13 23:02:09 -07:00
|
|
|
render_padding.max.y,
|
|
|
|
abs(render_padding.max.x - render_padding.min.x),
|
|
|
|
abs(render_padding.max.y - render_padding.min.y),
|
2024-03-09 07:21:48 -08:00
|
|
|
}
|
|
|
|
rect_content := rl.Rectangle {
|
|
|
|
render_content.min.x,
|
2024-03-13 23:02:09 -07:00
|
|
|
render_content.max.y,
|
|
|
|
abs(render_content.max.x - render_content.min.x),
|
|
|
|
abs(render_content.max.y - render_content.min.y),
|
2024-03-09 07:21:48 -08:00
|
|
|
}
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile_end()
|
|
|
|
|
|
|
|
draw_rectangle :: #force_inline proc "contextless" ( rect : rl.Rectangle, style : UI_Style ) {
|
|
|
|
if style.layout.corner_radii[0] > 0 {
|
|
|
|
rl.DrawRectangleRounded( rect, style.layout.corner_radii[0], 9, style.bg_color )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rl.DrawRectangleRec( rect, style.bg_color )
|
|
|
|
}
|
|
|
|
}
|
2024-03-09 07:21:48 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
draw_rectangle_lines :: #force_inline proc "contextless" ( rect : rl.Rectangle, style : UI_Style, color : Color, thickness : f32 ) {
|
|
|
|
if style.layout.corner_radii[0] > 0 {
|
|
|
|
rl.DrawRectangleRoundedLines( rect, style.layout.corner_radii[0], 9, thickness, color )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rl.DrawRectangleLinesEx( rect, thickness, color )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// profile_begin("rl.DrawRectangleRounded( rect_bounds, style.layout.corner_radii[0], 9, style.bg_color )")
|
|
|
|
if style.bg_color.a != 0
|
|
|
|
{
|
|
|
|
draw_rectangle( rect_bounds, style )
|
|
|
|
}
|
|
|
|
// profile_end()
|
2024-03-09 10:55:47 -08:00
|
|
|
|
2024-03-09 11:53:51 -08:00
|
|
|
line_thickness := 1 * cam_zoom_ratio
|
2024-03-09 10:55:47 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile_begin("rl.DrawRectangleRoundedLines: padding & content")
|
|
|
|
if equal_range2(computed.content, computed.padding) {
|
2024-03-10 23:05:30 -07:00
|
|
|
draw_rectangle_lines( rect_padding, style, Color_Debug_UI_Padding_Bounds, line_thickness )
|
2024-03-10 23:05:18 -07:00
|
|
|
}
|
|
|
|
else {
|
2024-03-13 23:02:09 -07:00
|
|
|
draw_rectangle_lines( rect_content, style, Color_Debug_UI_Content_Bounds, line_thickness )
|
2024-03-10 23:05:18 -07:00
|
|
|
}
|
|
|
|
// profile_end()
|
|
|
|
|
2024-03-10 23:05:30 -07:00
|
|
|
if .Mouse_Resizable in current.flags
|
2024-03-09 11:24:02 -08:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile("Resize Bounds")
|
2024-03-09 11:24:02 -08:00
|
|
|
resize_border_width := cast(f32) get_state().config.ui_resize_border_width
|
2024-03-13 21:00:22 -07:00
|
|
|
resize_percent_width := computed_size * (resize_border_width * 1.0/ 200.0)
|
2024-03-09 10:55:47 -08:00
|
|
|
resize_border_non_range := add(current.computed.bounds, range2(
|
|
|
|
{ resize_percent_width.x, -resize_percent_width.x },
|
|
|
|
{ -resize_percent_width.x, resize_percent_width.x }))
|
|
|
|
|
|
|
|
render_resize := range2(
|
|
|
|
world_to_screen_pos(resize_border_non_range.min),
|
|
|
|
world_to_screen_pos(resize_border_non_range.max),
|
|
|
|
)
|
|
|
|
rect_resize := rl.Rectangle {
|
|
|
|
render_resize.min.x,
|
|
|
|
render_resize.min.y,
|
|
|
|
render_resize.max.x - render_resize.min.x,
|
|
|
|
render_resize.max.y - render_resize.min.y,
|
|
|
|
}
|
2024-03-10 23:05:18 -07:00
|
|
|
draw_rectangle_lines( rect_padding, style, Color_Red, line_thickness )
|
2024-03-09 10:55:47 -08:00
|
|
|
}
|
|
|
|
|
2024-03-10 23:05:30 -07:00
|
|
|
point_radius := 3 * cam_zoom_ratio
|
2024-03-10 23:05:18 -07:00
|
|
|
|
|
|
|
// profile_begin("circles")
|
2024-03-13 21:00:22 -07:00
|
|
|
// center := Vec2 {
|
|
|
|
// render_bounds.p0.x + computed_size.x * 0.5,
|
|
|
|
// render_bounds.p0.y - computed_size.y * 0.5,
|
|
|
|
// }
|
|
|
|
// rl.DrawCircleV( center, point_radius, Color_White )
|
|
|
|
|
|
|
|
rl.DrawCircleV( render_bounds.p0, point_radius, Color_Red )
|
|
|
|
rl.DrawCircleV( render_bounds.p1, point_radius, Color_Blue )
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile_end()
|
2024-03-02 07:24:09 -08:00
|
|
|
|
2024-03-09 07:21:48 -08:00
|
|
|
if len(current.text.str) > 0 {
|
|
|
|
draw_text_string_cached( current.text, world_to_screen_pos(computed.text_pos), style.font_size, style.text_color )
|
|
|
|
}
|
2024-03-02 07:24:09 -08:00
|
|
|
}
|
2024-02-11 21:35:22 -08:00
|
|
|
}
|
2024-02-22 18:19:29 -08:00
|
|
|
//endregion Imgui Render
|
2024-02-11 21:35:22 -08:00
|
|
|
|
2024-02-13 14:16:39 -08:00
|
|
|
|
2024-02-11 21:35:22 -08:00
|
|
|
if debug.mouse_vis {
|
2024-03-02 07:24:09 -08:00
|
|
|
cursor_world_pos := screen_to_world(input.mouse.pos)
|
|
|
|
rl.DrawCircleV( world_to_screen_pos(cursor_world_pos), 5, Color_GreyRed )
|
2024-02-11 21:35:22 -08:00
|
|
|
}
|
2024-02-11 20:00:06 -08:00
|
|
|
|
2024-03-09 11:53:51 -08:00
|
|
|
rl.DrawCircleV( { 0, 0 }, 1 * cam_zoom_ratio, Color_White )
|
2024-03-02 07:24:09 -08:00
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
rl.EndMode2D()
|
|
|
|
}
|