From 8990d5beca11976562891c7954f81ad053d343e9 Mon Sep 17 00:00:00 2001 From: Erin Catto Date: Tue, 27 Oct 2026 22:26:09 -0700 Subject: [PATCH] minor sample polish --- samples/gfx/keycodes.h | 1 + samples/main.cpp | 20 +++++++++++++++++++- samples/sample.cpp | 13 +++++++++++-- samples/sample.h | 3 +++ samples/sample_character.cpp | 17 +++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/samples/gfx/keycodes.h b/samples/gfx/keycodes.h index e238fb8..48c81d0 100644 --- a/samples/gfx/keycodes.h +++ b/samples/gfx/keycodes.h @@ -16,6 +16,7 @@ enum KEY_D = SAPP_KEYCODE_D, KEY_F = SAPP_KEYCODE_F, KEY_G = SAPP_KEYCODE_G, + KEY_K = SAPP_KEYCODE_K, KEY_L = SAPP_KEYCODE_L, KEY_M = SAPP_KEYCODE_M, KEY_O = SAPP_KEYCODE_O, diff --git a/samples/main.cpp b/samples/main.cpp index 84d373d..9cc23f1 100644 --- a/samples/main.cpp +++ b/samples/main.cpp @@ -14,6 +14,7 @@ #include "gfx/debug_adapter.h" #include "gfx/keycodes.h" #include "gfx/renderer.h" +#include "gfx/text.h" #include "host/gui.h" #include "sample.h" #include "sokol_app.h" @@ -192,7 +193,18 @@ static void OnEvent( const sapp_event* e ) switch ( e->key_code ) { case SAPP_KEYCODE_TAB: - s_context.showUI = !s_context.showUI; + if ( mods & SAPP_MODIFIER_SHIFT ) + { + bool hide = s_context.showUI || s_context.showText; + s_context.showUI = !hide; + s_context.showText = !hide; + } + else + { + // Plain Tab also restores text so it always leads back to the full view + s_context.showUI = !s_context.showUI; + s_context.showText = true; + } break; case SAPP_KEYCODE_ESCAPE: @@ -413,6 +425,12 @@ static void OnFrame( void ) s_context.sample->Step(); s_context.sample->Render(); + // Before RenderFrame so world labels drop too + if ( s_context.showText == false ) + { + ResetTextArena(); + } + FrameInput fi{}; fi.view = camera.View(); fi.viewInv = camera.ViewInverse(); diff --git a/samples/sample.cpp b/samples/sample.cpp index a299724..22c0b35 100644 --- a/samples/sample.cpp +++ b/samples/sample.cpp @@ -1794,6 +1794,11 @@ static void DrawMenuBar( SampleContext* context ) { context->showUI = false; } + if ( ImGui::MenuItem( "Hide UI and Text", "Shift+Tab" ) ) + { + context->showUI = false; + context->showText = false; + } if ( ImGui::MenuItem( "Frame Selection", "F" ) ) { FrameSelection( context ); @@ -1926,6 +1931,7 @@ static void DrawMenuBar( SampleContext* context ) if ( ImGui::BeginTable( "keys", 2, ImGuiTableFlags_SizingFixedFit ) ) { DrawRow( "Tab", "Show / hide UI" ); + DrawRow( "Shift+Tab", "Show / hide UI and text" ); DrawRow( "M", "Show / hide metrics" ); DrawRow( "I", "Show / hide profile" ); DrawRow( "P", "Pause / resume" ); @@ -2266,7 +2272,7 @@ static void DrawHud( SampleContext* context ) const SampleEntry& entry = g_sampleEntries[context->sampleIndex]; float fontSize = ImGui::GetFontSize(); - DrawScreenStringFormat( 5, (int)( 1.5f * fontSize ), MakeColor( b3_colorYellow ), "%s : %s", entry.Category, entry.Name ); + DrawScreenStringFormat( 5, (int)( 0.5f * fontSize ), MakeColor( b3_colorYellow ), "%s : %s", entry.Category, entry.Name ); if ( context->pause ) { @@ -2282,7 +2288,10 @@ void DrawUI( SampleContext* context ) // Hidden shows only the minimal in-world HUD. if ( context->showUI == false ) { - DrawHud( context ); + if ( context->showText ) + { + DrawHud( context ); + } return; } diff --git a/samples/sample.h b/samples/sample.h index f9a8466..d6027ff 100644 --- a/samples/sample.h +++ b/samples/sample.h @@ -97,6 +97,9 @@ struct SampleContext // UI visibility (Tab / View > Hide UI). When hidden only the minimal HUD shows. bool showUI = true; + // Viewport text: HUD, sample text lines and world labels. + bool showText = true; + // Bottom metrics drawer (M), set by Ctrl+O for the fuzzy picker. bool showMetrics = false; bool openSamplePicker = false; diff --git a/samples/sample_character.cpp b/samples/sample_character.cpp index e4356ce..3790835 100644 --- a/samples/sample_character.cpp +++ b/samples/sample_character.cpp @@ -14,6 +14,8 @@ #include +#include + class CapsulePlane : public Sample { public: @@ -1679,6 +1681,21 @@ public: { ToggleThirdPerson(); } + + // Align movement for video + if ( key == KEY_K && action == ACTION_PRESS ) + { + float quarterTurn = 0.5f * B3_PI; + m_camera->m_yaw = quarterTurn * roundf( m_camera->m_yaw / quarterTurn ); + m_camera->m_pitch = 15.0f * B3_DEG_TO_RAD; + + b3BodyId bodyId = m_mover.GetBodyId(); + b3Pos position = b3Body_GetPosition( bodyId ); + position.x = roundf( position.x ); + position.z = roundf( position.z ); + b3Body_SetTransform( bodyId, position, b3Body_GetRotation( bodyId ) ); + b3Body_SetLinearVelocity( bodyId, b3Vec3_zero ); + } } bool DrawControls() override