minor sample polish
This commit is contained in:
parent
6190a96483
commit
8990d5beca
5 changed files with 51 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue