MCPcopy Create free account
hub / github.com/BobbyAnguelov/Esoterica / DrawTriggerButton

Function DrawTriggerButton

Code/Engine/Input/Debug/DebugView_Input.cpp:55–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53 static void DrawTriggerButton( ImDrawList* pDrawList, Float2 const& position, Float2 const& dimensions, char const* const pLabel, ControllerDevice const& controller, bool isLeftTrigger )
54 {
55 EE_ASSERT( pDrawList != nullptr );
56
57 // Draw the label if set
58 Float2 drawPosition = position;
59 if ( pLabel != nullptr )
60 {
61 Float2 const textDimensions = ImGui::CalcTextSize( pLabel );
62 Float2 const textPos = Float2( drawPosition.m_x + ( dimensions.m_x / 2 ) - ( textDimensions.m_x / 2 ) + 1, drawPosition.m_y + g_buttonBorderThickness );
63 pDrawList->AddText( textPos, 0xFFFFFFFF, pLabel );
64 drawPosition.m_y += textDimensions.m_y + 4;
65 }
66
67 // Draw the border
68 Float2 const borderDimensions( dimensions.m_x, dimensions.m_y - ( drawPosition.m_y - position.m_y + 4 ) );
69 Float2 const triggerTopLeft = drawPosition;
70 Float2 const triggerBottomRight = triggerTopLeft + borderDimensions;
71 pDrawList->AddRect( triggerTopLeft, triggerBottomRight, g_controlOutlineColor, 0.0f, g_buttonBorderThickness, ImDrawFlags_RoundCornersAll );
72
73 // Get Values
74 float triggerValue = 0.0f;
75 uint32_t triggerValueColor = 0;
76
77 if ( isLeftTrigger )
78 {
79 triggerValue = controller.GetValue( InputID::Controller_LeftTrigger );
80 triggerValueColor = 0xFF0000FF;
81 }
82 else
83 {
84 triggerValue = controller.GetValue( InputID::Controller_RightTrigger );
85 triggerValueColor = 0xFF00FF00;
86 }
87
88 // Draw the trigger values
89 if ( triggerValue > 0 )
90 {
91 float const valueMaxLength = borderDimensions.m_y - ( g_buttonBorderThickness * 2 );
92 float const triggerValueWidth = ( borderDimensions.m_x - g_buttonBorderThickness * 2 ) / 2;
93 float const triggerValue0TopLeftX = drawPosition.m_x + g_buttonBorderThickness;
94 float const triggerValue1TopLeftX = triggerValue0TopLeftX + triggerValueWidth;
95 float const triggerValue0TopLeftY = drawPosition.m_y + g_buttonBorderThickness + ( 1.0f - triggerValue ) * valueMaxLength;
96
97 Float2 const triggerValue0TopLeft( triggerValue0TopLeftX, triggerValue0TopLeftY );
98 Float2 const triggerValue0BottomRight( triggerValue1TopLeftX, triggerBottomRight.m_y - g_buttonBorderThickness );
99 pDrawList->AddRectFilled( triggerValue0TopLeft, triggerValue0BottomRight, triggerValueColor );
100 }
101 }
102
103 static void DrawAnalogStick( ImDrawList* pDrawList, Float2 const position, ControllerDevice const& controller, bool isLeftStick )
104 {
105 EE_ASSERT( pDrawList != nullptr );
106

Callers 1

DrawControllerStateMethod · 0.85

Calls 5

AddTextMethod · 0.80
AddRectMethod · 0.80
AddRectFilledMethod · 0.80
Float2Function · 0.50
GetValueMethod · 0.45

Tested by

no test coverage detected