@@ -406,6 +406,92 @@ int dengine_load_asset(const char* path, void** mem, size_t* length)
406406 return 1 ;
407407}
408408
409+ void dengine_input_swinput_joystick (
410+ int x , int y , int dim ,
411+ int snap_lim ,
412+ Texture * clamp , float * clamp_color_vec4 ,
413+ Texture * handle , float * handle_color_vec4 ,
414+ float * outx , float * outy ,
415+ SWInput_Joystick * joystick )
416+ {
417+ float hwinput_x , hwinput_y ;
418+ vec2 output ;
419+
420+ /* TODO: we use mouse for now. use touches too */
421+ joystick -> isdown = dengine_input_get_mousebtn (DENGINE_INPUT_MSEBTN_PRIMARY );
422+ hwinput_x = dengine_input_get_mousepos_x ();
423+ hwinput_y = dengine_input_get_mousepos_y ();
424+
425+ int joyx = x ;
426+ int joyy = y ;
427+ int joyhanddim = dim / 2 ;
428+ int joyhandx , joyhandy ;
429+
430+ int sqregionoffset =
431+ snap_lim ?
432+ snap_lim : dim ;
433+
434+ /*TODO: doesn't consider the center of joystick. the user
435+ * wont notice anyway (0_-), (-_-), (0_-)
436+ */
437+ int inregion = hwinput_x >= x - sqregionoffset && hwinput_x <= x + sqregionoffset &&
438+ hwinput_y >= y - sqregionoffset && hwinput_y <= y + sqregionoffset ;
439+
440+ if (snap_lim )
441+ {
442+ joyx = hwinput_x - (dim / 2.0f );
443+ joyy = hwinput_y - (dim / 2.0f );
444+ if (inregion && !joystick -> isregion_ondown )
445+ {
446+ joystick -> snap_x = joyx ;;
447+ joystick -> snap_y = joyy ;
448+ joystick -> isregion_ondown = 1 ;
449+ }
450+
451+ if (joystick -> isdown )
452+ {
453+ joyx = joystick -> snap_x ;
454+ joyy = joystick -> snap_y ;
455+ }
456+ }else {
457+ if (joystick -> isdown && inregion )
458+ joystick -> isregion_ondown = 1 ;
459+ }
460+
461+ if (joystick -> isdown && joystick -> isregion_ondown ){
462+ joyhandx = hwinput_x - (joyhanddim / 2.0f );
463+ joyhandy = hwinput_y - (joyhanddim / 2.0f );
464+ vec2 a = {joyhandx + (joyhanddim / 2.0f ), joyhandy + (joyhanddim / 2.0f )};
465+ vec2 b = {joyx + (dim / 2.0f ), joyy + (dim / 2.0f )};
466+ vec2 c ;
467+ glm_vec2_sub (a , b , c );
468+ float mag = glm_vec2_norm (c );
469+ if (mag > dim / 2.0f )
470+ {
471+ glm_vec2_scale_as (c , dim / 2.0f , c );
472+ }
473+ joyhandx = joyx + (joyhanddim / 2.0f ) + c [0 ];
474+ joyhandy = joyy + (joyhanddim / 2.0f ) + c [1 ];
475+ glm_vec2_divs (c , dim / 2.0f , output );
476+ ;
477+ }else {
478+ joyx = x ;
479+ joyy = y ;
480+ joystick -> isregion_ondown = 0 ;
481+ joyhandx = joyx + (dim / 2.0f ) - (joyhanddim / 2.0f );
482+ joyhandy = joyy + (dim / 2.0f ) - (joyhanddim / 2.0f );
483+ glm_vec2_zero (output );
484+ }
485+
486+ * outx = output [0 ];
487+ * outy = output [1 ];
488+
489+ denginegui_set_panel_discard (1 );
490+ denginegui_panel (joyx , joyy , dim , dim , clamp , NULL , clamp_color_vec4 );
491+ denginegui_panel (joyhandx , joyhandy , joyhanddim , joyhanddim , handle , NULL , handle_color_vec4 );
492+ denginegui_set_panel_discard (0 );
493+ }
494+
409495#ifdef DENGINE_ANDROID
410496void backbutton_func (struct android_app * app )
411497{
0 commit comments