config "bind UP ui_up"
config "bind DOWN ui_down"
config "bind MOUSE_LEFT ui_click"
-
config "bind LEFT_SHIFT ui_select"
config "bind RIGHT_SHIFT ui_select"
#include <unistd.h>
SDL_Mutex *_audio_mutex;
-_Thread_local static bool _audio_have_lock = 0;
+_Thread_local static b8 _audio_have_lock = 0;
static f32 _master_volume = 1.0f;
enum channel_stage
f32 lfo_attenuation_amount; /* multiply volume by (1 + value) */
f32 spacial_falloff[4]; /* xyz, range */
- bool pause;
+ b8 pause;
}
controls;
u32 cursor;
i32 volume, pan,
spacial_volume, spacial_pan;
- bool spacial_warm;
+ b8 spacial_warm;
union
{
struct audio_channel channels[ AUDIO_CHANNELS ];
stb_vorbis_alloc vorbis_decoders[ AUDIO_CHANNELS ];
- bool inspector_open;
+ b8 inspector_open;
struct audio_master_controls
{
f32 listener_position[3],
listener_right_ear_direction[3],
listener_velocity[3];
- bool dsp_enabled;
+ b8 dsp_enabled;
i32 volume_target;
}
controls;
f32 master_volume_ui;
i32 dsp_enabled_ui;
- bool working;
+ b8 working;
i32 sdl_output_device;
}
/* clip loading from disk
* -------------------------------------------------------------------------------
*/
-bool audio_clip_load( struct audio_clip *clip, struct stack_allocator *stack )
+b8 audio_clip_load( struct audio_clip *clip, struct stack_allocator *stack )
{
ASSERT_CRITICAL( _thread_has_flags( _get_thread_id(), THREAD_FLAG_ASYNC ) );
_audio.controls.dsp_enabled = _audio.dsp_enabled_ui;
}
-void _audio_set_channel_volume( audio_channel_id id, f64 volume, bool instant )
+void _audio_set_channel_volume( audio_channel_id id, f64 volume, b8 instant )
{
_audio_assert_lock();
controls->volume_slew_rate_per_sample = (f64)AUDIO_VOLUME_100 / (length_seconds * 44100.0);
}
-void _audio_set_channel_pan( audio_channel_id id, f64 pan, bool instant )
+void _audio_set_channel_pan( audio_channel_id id, f64 pan, b8 instant )
{
_audio_assert_lock();
return new_id;
}
-bool _audio_is_channel_using_clip( audio_channel_id id, struct audio_clip *clip )
+b8 _audio_is_channel_using_clip( audio_channel_id id, struct audio_clip *clip )
{
_audio_assert_lock();
struct audio_channel *channel = get_audio_channel( id );
}
}
-bool _audio_flagged_stopped( u32 flag )
+b8 _audio_flagged_stopped( u32 flag )
{
_audio_lock();
for( u32 id=1; id<=AUDIO_CHANNELS; id ++ )
return 1;
}
-void _audio_set_channel_pause( audio_channel_id id, bool pause )
+void _audio_set_channel_pause( audio_channel_id id, b8 pause )
{
_audio_assert_lock();
struct audio_channel_controls *controls = get_audio_channel_controls( id );
controls->pause = pause;
}
-void _audio_set_flagged_pause( u32 flag, bool pause )
+void _audio_set_flagged_pause( u32 flag, b8 pause )
{
_audio_assert_lock();
for( u32 id=1; id<=AUDIO_CHANNELS; id ++ )
{
struct audio_channel_state *state = get_audio_channel_state( id );
- bool is_3d = controls->flags & AUDIO_FLAG_SPACIAL_3D? 1: 0;
- bool use_doppler = controls->flags & AUDIO_FLAG_NO_DOPPLER? 0: 1;
+ b8 is_3d = controls->flags & AUDIO_FLAG_SPACIAL_3D? 1: 0;
+ b8 use_doppler = controls->flags & AUDIO_FLAG_NO_DOPPLER? 0: 1;
f32 frame_sample_rate = controls->sampling_rate_multiplier;
if( controls->flags & AUDIO_FLAG_RELINQUISHED )
{
- bool die = 0;
+ b8 die = 0;
if( state->activity == k_channel_activity_end ) die = 1;
if( state->activity == k_channel_activity_error ) die = 1;
if( state->volume == 0 ) die = 1;
void vg_audio_preupdate(void)
{
#if 0
- bool before_working = _audio.working;
+ b8 before_working = _audio.working;
_audio.working = 1;
if( _audio.sdl_output_device == 0 )
_audio.working = 0;
void vg_audio_device_init(void);
void vg_audio_begin(void);
-bool audio_clip_load( struct audio_clip *clip, struct stack_allocator *stack );
+b8 audio_clip_load( struct audio_clip *clip, struct stack_allocator *stack );
u32 audio_clip_loadn( struct audio_clip *arr, u32 count, struct stack_allocator *stack );
void _audio_lock(void);
audio_channel_id _audio_get_first_active_channel_in_group( u16 group );
void _audio_sidechain_lfo_to_channel( audio_channel_id id, audio_channel_id lfo_id, f32 amount );
void _audio_set_channel_spacial_falloff( audio_channel_id id, f32 co[3], f32 range );
-void _audio_set_channel_volume( audio_channel_id id, f64 volume, bool instant );
+void _audio_set_channel_volume( audio_channel_id id, f64 volume, b8 instant );
void _audio_set_channel_volume_slew_duration( audio_channel_id id, f64 length_seconds );
-void _audio_set_channel_pan( audio_channel_id id, f64 pan, bool instant );
+void _audio_set_channel_pan( audio_channel_id id, f64 pan, b8 instant );
void _audio_set_channel_pan_slew_duration( audio_channel_id id, f64 length_seconds );
void _audio_set_channel_sampling_rate( audio_channel_id id, f32 rate );
void _audio_start_channel( audio_channel_id id );
audio_channel_id _audio_crossfade( audio_channel_id id, struct audio_clip *new_clip, f32 transition_seconds );
void _audio_oneshot_3d( struct audio_clip *clip, f32 co[3], f32 range, f32 volume, u16 group, u32 flags );
void _audio_oneshot( struct audio_clip *clip, f32 volume, f32 pan, u16 group, u32 flags );
-void _audio_set_channel_pause( audio_channel_id id, bool pause );
+void _audio_set_channel_pause( audio_channel_id id, b8 pause );
/* half measures... Don't expect these functions to stay. */
void _audio_fadeout_flagged_audio( u32 flag, f32 length );
-bool _audio_flagged_stopped( u32 flag );
-bool _audio_is_channel_using_clip( audio_channel_id id, struct audio_clip *clip );
-void _audio_set_flagged_pause( u32 flag, bool pause );
+b8 _audio_flagged_stopped( u32 flag );
+b8 _audio_is_channel_using_clip( audio_channel_id id, struct audio_clip *clip );
+void _audio_set_flagged_pause( u32 flag, b8 pause );
_engine.framerate_limit = hz;
}
-#if 0
-void _character_callback( GLFWwindow *window, u32 codepoint )
-{
- if( _input_layer_filter( 1<<k_input_layer_ui ) )
- _engine_ui_input_character( codepoint );
-}
-#endif
-
void _engine_options(void)
{
- const c8 *arg;
+ //const c8 *arg;
if( _option_long( "high-performance", "Turn graphics to lowest quality" ) )
_engine.quality = k_quality_profile_low;
_fatal_exit();
}
- const c8* glver = glGetString( GL_VERSION );
+ const c8 *glver = (const c8 *)glGetString( GL_VERSION );
$log( $ok, {"Load setup complete, OpenGL version: "}, {glver} );
glEnable ( GL_DEBUG_OUTPUT );
{
_input_keyboard_event( (SDL_KeyboardEvent *)&e );
}
+ else if( e.type == SDL_EVENT_TEXT_INPUT )
+ {
+ SDL_TextInputEvent *ev = (SDL_TextInputEvent*)&e;
+
+ if( _input_layer_filter( 1<<k_input_layer_ui ) )
+ {
+ const u8 *utf8_text = (const u8 *)ev->text;
+ for( u32 i=0; utf8_text[i]; i ++ )
+ _engine_ui_input_character( utf8_text[i] );
+ }
+ }
}
goto L_new_frame;
{
{ "SHIFT", k_input_device_modifier, .key = SDL_KMOD_LSHIFT },
{ "CONTROL", k_input_device_modifier, .key = SDL_KMOD_LCTRL },
- { "RETURN", k_input_device_keyboard, .key = SDLK_RETURN },
+ { "ALT", k_input_device_modifier, .key = SDL_KMOD_LALT },
+ { "ENTER", k_input_device_keyboard, .key = SDLK_RETURN },
{ "ESCAPE", k_input_device_keyboard, .key = SDLK_ESCAPE },
{ "BACKSPACE", k_input_device_keyboard, .key = SDLK_BACKSPACE },
{ "TAB", k_input_device_keyboard, .key = SDLK_TAB },
{ "RIGHTBRACKET", k_input_device_keyboard, .key = SDLK_RIGHTBRACKET },
{ "CARET", k_input_device_keyboard, .key = SDLK_CARET },
{ "UNDERSCORE", k_input_device_keyboard, .key = SDLK_UNDERSCORE },
- { "GRAVE", k_input_device_keyboard, .key = SDLK_GRAVE },
+ { "GRAVE_ACCENT", k_input_device_keyboard, .key = SDLK_GRAVE },
{ "A", k_input_device_keyboard, .key = SDLK_A },
{ "B", k_input_device_keyboard, .key = SDLK_B },
{ "C", k_input_device_keyboard, .key = SDLK_C },
{ "KP_OCTAL", k_input_device_keyboard, .key = SDLK_KP_OCTAL },
{ "KP_DECIMAL", k_input_device_keyboard, .key = SDLK_KP_DECIMAL },
{ "KP_HEXADECIMAL", k_input_device_keyboard, .key = SDLK_KP_HEXADECIMAL },
- { "LCTRL", k_input_device_keyboard, .key = SDLK_LCTRL },
- { "LSHIFT", k_input_device_keyboard, .key = SDLK_LSHIFT },
- { "LALT", k_input_device_keyboard, .key = SDLK_LALT },
+ { "LEFT_CTRL", k_input_device_keyboard, .key = SDLK_LCTRL },
+ { "LEFT_SHIFT", k_input_device_keyboard, .key = SDLK_LSHIFT },
+ { "LEFT_ALT", k_input_device_keyboard, .key = SDLK_LALT },
{ "LGUI", k_input_device_keyboard, .key = SDLK_LGUI },
- { "RCTRL", k_input_device_keyboard, .key = SDLK_RCTRL },
- { "RSHIFT", k_input_device_keyboard, .key = SDLK_RSHIFT },
- { "RALT", k_input_device_keyboard, .key = SDLK_RALT },
+ { "RIGHT_CTRL", k_input_device_keyboard, .key = SDLK_RCTRL },
+ { "RIGHT_SHIFT", k_input_device_keyboard, .key = SDLK_RSHIFT },
+ { "RIGHT_ALT", k_input_device_keyboard, .key = SDLK_RALT },
{ "RGUI", k_input_device_keyboard, .key = SDLK_RGUI },
{ "MODE", k_input_device_keyboard, .key = SDLK_MODE },
{ "SLEEP", k_input_device_keyboard, .key = SDLK_SLEEP },
//_graphics_fill_rect( (i16[]){ 0, 0, _engine.w, _engine.h }, (union colour){{0,0,0,255}} );
}
-void _engine_ui_input_character( u32 codepoint )
-{
- if( (codepoint >= (u32)' ') && (codepoint <= (u32)'~') )
- _ui_input_text( (const c8[]){ codepoint, 0 } );
-}
-
void _engine_ui_post_render(void)
{
glEnable( GL_BLEND );
_render_fullscreen_quad();
glDisable( GL_BLEND );
+
+ static b8 want_text_prev = 0;
+ b8 want_text = _ui_want_text();
+ if( want_text != want_text_prev )
+ {
+ if( want_text ) SDL_StartTextInput( _engine.window_handle );
+ else SDL_StopTextInput( _engine.window_handle );
+ want_text_prev = want_text;
+ }
+}
+
+void _engine_ui_input_character( u32 codepoint )
+{
+ if( (codepoint >= (u32)' ') && (codepoint <= (u32)'~') )
+ _ui_input_text( (const c8[]){ codepoint, 0 } );
}
void _engine_ui_pre_render(void);
void _engine_ui_post_render(void);
+b8 _engine_ui_want_text_input(void);
+void _engine_ui_input_character( u32 codepoint );
void _log_init(void)
{
_log.lock = _mutex_create();
+#ifdef _WIN32
+ _stdout_stream.posix_stream = fopen( "stdout.txt", "w" );
+#else
_stdout_stream.posix_stream = stdout;
+#endif
_stdout_stream.offset = 0;
_stdout_stream.buffer_length = 0;
_stdout_stream.flags = k_stream_posix | k_stream_write;
return 0;
}
+
+b8 _ui_want_text(void)
+{
+ return _ui.active_control_type == k_ui_control_textbox;
+}
void _ui_get_mouse_co( i16 out_co[2] );
void _ui_input_text( const c8 *text );
b8 _ui_want_mouse( i16 area[4] );
+b8 _ui_want_text(void);
#define UI_PADDING_PX 8
#define UI_ROW_PADDING_PX 18
v2_muladds( a, v0, t, d );
return t;
}
+
+static void closest_point_aabb( f32 p[3], f32 box[2][3], f32 dest[3] )
+{
+ v3_max( p, box[0], dest );
+ v3_min( dest, box[1], dest );
+}