diff --git a/code/alias_raylib.odin b/code/alias_raylib.odin new file mode 100644 index 0000000..22e2f69 --- /dev/null +++ b/code/alias_raylib.odin @@ -0,0 +1,4 @@ +package sectr + +import rl "vendor:raylib" + diff --git a/code/colors.odin b/code/colors.odin new file mode 100644 index 0000000..d13bec6 --- /dev/null +++ b/code/colors.odin @@ -0,0 +1,8 @@ +package sectr + +import rl "vendor:raylib" + +Color_BG :: rl.Color { 41, 41, 45, 255 } +Color_BG_TextBox :: rl.Color { 32, 32, 32, 255 } +Color_Frame_Hover :: rl.Color { 122, 122, 125, 255 } +Color_Frame_Select :: rl.Color { 188, 188, 188, 255 } diff --git a/code/engine_loop.odin b/code/engine_loop.odin new file mode 100644 index 0000000..a07a29c --- /dev/null +++ b/code/engine_loop.odin @@ -0,0 +1,51 @@ +package sectr + +import "core:fmt" + +import rl "vendor:raylib" + +draw_text_y : f32 = 50 + +run_cycle :: proc( running : ^b32 ) +{ + for ; running^ ; + { + if rl.WindowShouldClose() { + running^ = false; + } + + // Logic Update + { + + } + + // Rendering + { + rl.BeginDrawing() + rl.ClearBackground( Color_BG ) + defer { + rl.DrawFPS( 0, 0 ) + rl.EndDrawing() + // Note(Ed) : Polls input as well. + } + + draw_text :: proc( format : string, args : ..any ) + { + @static draw_text_scratch : [65536]u8 + if ( draw_text_y > 500 ) { + draw_text_y = 50 + } + content := fmt.bprintf( draw_text_scratch[:], format, ..args ) + debug_text( content, 25, draw_text_y ) + draw_text_y += 16 + } + + draw_text( "Monitor : %v", rl.GetMonitorName(0) ) + draw_text( "Screen Width : %v", rl.GetScreenWidth() ) + draw_text( "Screen Height: %v", rl.GetScreenHeight() ) + + + draw_text_y = 50 + } + } +} diff --git a/code/launch.odin b/code/launch.odin index 39a9ff5..7999de9 100644 --- a/code/launch.odin +++ b/code/launch.odin @@ -1,49 +1,16 @@ package sectr -import "core:io" -import "core:fmt" -import "core:mem" -import "core:mem/virtual" -import "core:strings" -import "core:unicode/utf8" -import rl "vendor:raylib" +import "core:strings" -kilobytes :: proc ( kb : $integer_type ) -> integer_type { - return kb * 1024 -} -megabytes :: proc ( kb : $integer_type ) -> integer_type { - return kb * 1024 * 1024 -} - -Frame :: struct { - bounds : rl.Rectangle - // collision_bounds : rl.Rectangle, // Interaction space - // nav_bounds : rl.Rectangle // Navigation space -} - -TextLine :: [dynamic]u8 -TextBox :: struct { - using frame : Frame, - text : strings.Builder, - - // TODO(Ed) : Make use of the lines view, this will tell use when a line begins or ends - lines : [dynamic]TextLine, - cursor_pos : i32 -} - -// TextBlob :: struct { -// buffer : string -// } - -Null_Rune : rune = 0 - -Color_BG :: rl.Color { 41, 41, 45, 255 } -Color_BG_TextBox :: rl.Color { 32, 32, 32, 255 } -Color_Frame_Hover :: rl.Color { 122, 122, 125, 255 } -Color_Frame_Select :: rl.Color { 188, 188, 188, 255 } +import rl "vendor:raylib" Path_Assets :: "../assets/" + +WindowState :: struct { + +} + main :: proc() { // Rough setup of window with rl stuff @@ -59,96 +26,17 @@ main :: proc() monitor_refresh_rate := rl.GetMonitorRefreshRate( monitor_id ) rl.SetTargetFPS( monitor_refresh_rate ) - font_rec_mono_semicasual_reg : rl.Font; { + // Basic Font Setup + { path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" } ) cstr := strings.clone_to_cstring(path_rec_mono_semicasual_reg) font_rec_mono_semicasual_reg = rl.LoadFontEx( cstr, 24, nil, 0 ) delete( cstr ) + + rl.GuiSetFont( font_rec_mono_semicasual_reg ) // TODO(Ed) : Does this do anything? + default_font = font_rec_mono_semicasual_reg } - hovered_frame : ^Frame = nil - focused_frame : ^Frame = nil - text_box : TextBox - { - builder, err := strings.builder_make_len_cap( 0, megabytes( cast(int) 1 ) / 4 ) - if err != mem.Allocator_Error.None { - fmt.println( "Failed to allocate text arena!" ) - return - } - text_box.text = builder - } - - for ; ! rl.WindowShouldClose() ; - { - mouse_pos := rl.GetMousePosition() - - // Logic Update - { - rect := &text_box.bounds - rect.width = 900 - rect.height = 400 - rect.x = cast(f32) (screen_width / 2) - rect.width / 2.0 - rect.y = cast(f32) (screen_height / 2) - rect.height - - if rl.CheckCollisionPointRec( mouse_pos, rect^ ) { - hovered_frame = & text_box - } - else { - hovered_frame = nil - } - - if rl.IsMouseButtonPressed( rl.MouseButton.LEFT ) - { - if hovered_frame != nil { - focused_frame = hovered_frame - } - else { - focused_frame = nil - } - } - - if focused_frame != nil { - for code_point := rl.GetCharPressed(); - code_point != Null_Rune; - { - strings.write_rune( & text_box.text, code_point ); - code_point = rl.GetCharPressed() - } - } - } - - // Rendering - { - rl.BeginDrawing() - rl.ClearBackground( Color_BG ) - - // Text Box - { - rl.DrawRectangleRec( text_box.bounds, Color_BG_TextBox ) - - if focused_frame != nil { - rl.DrawRectangleLinesEx( focused_frame.bounds, 2, Color_Frame_Select ) - } - else if hovered_frame != nil { - rl.DrawRectangleLinesEx( hovered_frame.bounds, 2, Color_Frame_Hover ) - } - - txt_str := strings.to_string( text_box.text ) - runes := utf8.string_to_runes(txt_str) - - rl.GuiSetFont( font_rec_mono_semicasual_reg ) - if len(txt_str) > 0 { - rl.DrawTextCodepoints( font_rec_mono_semicasual_reg, raw_data( runes ), - cast(i32) len(runes), - rl.Vector2 { text_box.bounds.x + 10, text_box.bounds.y + 10 }, - 24.0, // font size - 0.0, // font spacing - rl.WHITE - ) - } - } - - rl.EndDrawing() - } - } + running : b32 = true + run_cycle( & running ) } diff --git a/code/memory.odin b/code/memory.odin new file mode 100644 index 0000000..850d736 --- /dev/null +++ b/code/memory.odin @@ -0,0 +1,8 @@ +package sectr + +kilobytes :: proc ( kb : $integer_type ) -> integer_type { + return kb * 1024 +} +megabytes :: proc ( kb : $integer_type ) -> integer_type { + return kb * 1024 * 1024 +} diff --git a/code/sectr.odin b/code/sectr.odin deleted file mode 100644 index 7ba6dc6..0000000 --- a/code/sectr.odin +++ /dev/null @@ -1,3 +0,0 @@ -package sectr - - diff --git a/code/text.odin b/code/text.odin new file mode 100644 index 0000000..b4fc5a9 --- /dev/null +++ b/code/text.odin @@ -0,0 +1,23 @@ +package sectr + +import "core:unicode/utf8" + +import rl "vendor:raylib" + +font_rec_mono_semicasual_reg : rl.Font; +default_font : rl.Font + +debug_text :: proc( content : string, x, y : f32, size : f32 = 16.0, color : rl.Color = rl.WHITE, font : rl.Font = default_font ) +{ + if len( content ) == 0 { + return + } + runes := utf8.string_to_runes( content ) + + rl.DrawTextCodepoints( font, + raw_data(runes), cast(i32) len(runes), + position = rl.Vector2 { x, y }, + fontSize = size, + spacing = 0.0, + tint = color ); +} diff --git a/launch.odin_old b/launch.odin_old new file mode 100644 index 0000000..949d97c --- /dev/null +++ b/launch.odin_old @@ -0,0 +1,154 @@ +package sectr_old + +import "core:io" +import "core:fmt" +import "core:mem" +import "core:mem/virtual" +import "core:strings" +import "core:unicode/utf8" +import rl "vendor:raylib" + +kilobytes :: proc ( kb : $integer_type ) -> integer_type { + return kb * 1024 +} +megabytes :: proc ( kb : $integer_type ) -> integer_type { + return kb * 1024 * 1024 +} + +Frame :: struct { + bounds : rl.Rectangle + // collision_bounds : rl.Rectangle, // Interaction space + // nav_bounds : rl.Rectangle // Navigation space +} + +TextLine :: [dynamic]u8 +TextBox :: struct { + using frame : Frame, + text : strings.Builder, + + // TODO(Ed) : Make use of the lines view, this will tell use when a line begins or ends + lines : [dynamic]TextLine, + cursor_pos : i32 +} + +// TextBlob :: struct { +// buffer : string +// } + +Null_Rune : rune = 0 + +Color_BG :: rl.Color { 41, 41, 45, 255 } +Color_BG_TextBox :: rl.Color { 32, 32, 32, 255 } +Color_Frame_Hover :: rl.Color { 122, 122, 125, 255 } +Color_Frame_Select :: rl.Color { 188, 188, 188, 255 } + +Path_Assets :: "../assets/" + +main :: proc() +{ + // Rough setup of window with rl stuff + screen_width : i32 = 1280 + screen_height : i32 = 1000 + win_title : cstring = "Sectr Prototype" + rl.InitWindow( screen_width, screen_height, win_title ) + defer { + rl.CloseWindow() + } + + monitor_id := rl.GetCurrentMonitor() + monitor_refresh_rate := rl.GetMonitorRefreshRate( monitor_id ) + rl.SetTargetFPS( monitor_refresh_rate ) + + font_rec_mono_semicasual_reg : rl.Font; { + path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" } ) + cstr := strings.clone_to_cstring(path_rec_mono_semicasual_reg) + font_rec_mono_semicasual_reg = rl.LoadFontEx( cstr, 24, nil, 0 ) + delete( cstr ) + } + + hovered_frame : ^Frame = nil + focused_frame : ^Frame = nil + text_box : TextBox + { + builder, err := strings.builder_make_len_cap( 0, megabytes( cast(int) 1 ) / 4 ) + if err != mem.Allocator_Error.None { + fmt.println( "Failed to allocate text arena!" ) + return + } + text_box.text = builder + } + + for ; ! rl.WindowShouldClose() ; + { + mouse_pos := rl.GetMousePosition() + + // Logic Update + { + rect := &text_box.bounds + rect.width = 900 + rect.height = 400 + rect.x = cast(f32) (screen_width / 2) - rect.width / 2.0 + rect.y = cast(f32) (screen_height / 2) - rect.height + + if rl.CheckCollisionPointRec( mouse_pos, rect^ ) { + hovered_frame = & text_box + } + else { + hovered_frame = nil + } + + if rl.IsMouseButtonPressed( rl.MouseButton.LEFT ) + { + if hovered_frame != nil { + focused_frame = hovered_frame + } + else { + focused_frame = nil + } + } + + if focused_frame != nil { + for code_point := rl.GetCharPressed(); + code_point != Null_Rune; + { + strings.write_rune( & text_box.text, code_point ); + code_point = rl.GetCharPressed() + } + } + } + + // Rendering + { + rl.BeginDrawing() + rl.ClearBackground( Color_BG ) + + // Text Box + { + rl.DrawRectangleRec( text_box.bounds, Color_BG_TextBox ) + + if focused_frame != nil { + rl.DrawRectangleLinesEx( focused_frame.bounds, 2, Color_Frame_Select ) + } + else if hovered_frame != nil { + rl.DrawRectangleLinesEx( hovered_frame.bounds, 2, Color_Frame_Hover ) + } + + txt_str := strings.to_string( text_box.text ) + runes := utf8.string_to_runes(txt_str) + + rl.GuiSetFont( font_rec_mono_semicasual_reg ) + if len(txt_str) > 0 { + rl.DrawTextCodepoints( font_rec_mono_semicasual_reg, raw_data( runes ), + cast(i32) len(runes), + rl.Vector2 { text_box.bounds.x + 10, text_box.bounds.y + 10 }, + 24.0, // font size + 0.0, // font spacing + rl.WHITE + ) + } + } + + rl.EndDrawing() + } + } +}