Beispiel #1
0
uint64_t input_overlay_poll(input_overlay_t *ol, int16_t norm_x, int16_t norm_y)
{
   if (!ol->enable)
   {
      ol->blocked = false;
      return 0;
   }

   // norm_x and norm_y is in [-0x7fff, 0x7fff] range, like RETRO_DEVICE_POINTER.
   float x = (float)(norm_x + 0x7fff) / 0xffff;
   float y = (float)(norm_y + 0x7fff) / 0xffff;

   x -= ol->active->x;
   y -= ol->active->y;
   x /= ol->active->w;
   y /= ol->active->h;

   uint64_t state = 0;
   for (size_t i = 0; i < ol->active->size; i++)
   {
      if (inside_hitbox(&ol->active->descs[i], x, y))
         state |= ol->active->descs[i].key_mask;
   }

   if (!state)
      ol->blocked = false;
   else if (ol->blocked)
      state = 0;

   return state;
}
Beispiel #2
0
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t norm_x, int16_t norm_y)
{
   memset(out, 0, sizeof(*out));

   if (!ol->enable)
   {
      ol->blocked = false;
      return;
   }

   // norm_x and norm_y is in [-0x7fff, 0x7fff] range, like RETRO_DEVICE_POINTER.
   float x = (float)(norm_x + 0x7fff) / 0xffff;
   float y = (float)(norm_y + 0x7fff) / 0xffff;

   x -= ol->active->mod_x;
   y -= ol->active->mod_y;
   x /= ol->active->mod_w;
   y /= ol->active->mod_h;

   for (size_t i = 0; i < ol->active->size; i++)
   {
      if (!inside_hitbox(&ol->active->descs[i], x, y))
         continue;

      if (ol->active->descs[i].type == OVERLAY_TYPE_BUTTONS)
      {
         uint64_t mask = ol->active->descs[i].key_mask;
         out->buttons |= mask;

         if (mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
            ol->next_index = ol->active->descs[i].next_index;
      }
      else
      {
         float x_val = (x - ol->active->descs[i].x) / ol->active->descs[i].range_x / ol->active->descs[i].analog_saturate_pct;
         float y_val = (y - ol->active->descs[i].y) / ol->active->descs[i].range_y / ol->active->descs[i].analog_saturate_pct;

         if (fabs(x_val) > 1.0f)
            x_val = (x_val > 0.0f) ? 1.0f : -1.0f;

         if (fabs(y_val) > 1.0f)
            y_val = (y_val > 0.0f) ? 1.0f : -1.0f;

         unsigned int base = (ol->active->descs[i].type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0;
         out->analog[base + 0] = x_val * 32767.0f;
         out->analog[base + 1] = y_val * 32767.0f;
      }
   }

   if (!out->buttons)
      ol->blocked = false;
   else if (ol->blocked)
      memset(out, 0, sizeof(*out));
}
Beispiel #3
0
/**
 * input_overlay_poll:
 * @out                   : Polled output data.
 * @norm_x                : Normalized X coordinate.
 * @norm_y                : Normalized Y coordinate.
 *
 * Polls input overlay.
 *
 * @norm_x and @norm_y are the result of
 * input_translate_coord_viewport().
 **/
static void input_overlay_poll(input_overlay_state_t *out,
      int16_t norm_x, int16_t norm_y)
{
   size_t i;
   float x, y;
   input_overlay_t *ol      = overlay_ptr;

   memset(out, 0, sizeof(*out));

   if (!ol->enable)
   {
      ol->blocked = false;
      return;
   }

   /* norm_x and norm_y is in [-0x7fff, 0x7fff] range,
    * like RETRO_DEVICE_POINTER. */
   x = (float)(norm_x + 0x7fff) / 0xffff;
   y = (float)(norm_y + 0x7fff) / 0xffff;

   x -= ol->active->mod_x;
   y -= ol->active->mod_y;
   x /= ol->active->mod_w;
   y /= ol->active->mod_h;

   for (i = 0; i < ol->active->size; i++)
   {
      float x_dist, y_dist;
      struct overlay_desc *desc = &ol->active->descs[i];

      if (!desc)
         continue;
      if (!inside_hitbox(desc, x, y))
         continue;

      desc->updated = true;
      x_dist        = x - desc->x;
      y_dist        = y - desc->y;

      switch (desc->type)
      {
         case OVERLAY_TYPE_BUTTONS:
            {
               uint64_t mask = desc->key_mask;

               out->buttons |= mask;

               if (mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
                  ol->next_index = desc->next_index;
            }
            break;
         case OVERLAY_TYPE_KEYBOARD:
            if (desc->key_mask < RETROK_LAST)
               OVERLAY_SET_KEY(out, desc->key_mask);
            break;
         default:
            {
               float x_val     = x_dist / desc->range_x;
               float y_val     = y_dist / desc->range_y;
               float x_val_sat = x_val / desc->analog_saturate_pct;
               float y_val_sat = y_val / desc->analog_saturate_pct;

               unsigned int base = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0;

               out->analog[base + 0] = clamp_float(x_val_sat, -1.0f, 1.0f) * 32767.0f;
               out->analog[base + 1] = clamp_float(y_val_sat, -1.0f, 1.0f) * 32767.0f;
            }
            break;
      }

      if (desc->movable)
      {
         desc->delta_x = clamp_float(x_dist, -desc->range_x, desc->range_x)
            * ol->active->mod_w;
         desc->delta_y = clamp_float(y_dist, -desc->range_y, desc->range_y)
            * ol->active->mod_h;
      }
   }

   if (!out->buttons)
      ol->blocked = false;
   else if (ol->blocked)
      memset(out, 0, sizeof(*out));
}
Beispiel #4
0
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t norm_x, int16_t norm_y)
{
   size_t i;
   memset(out, 0, sizeof(*out));

   if (!ol->enable)
   {
      ol->blocked = false;
      return;
   }

   // norm_x and norm_y is in [-0x7fff, 0x7fff] range, like RETRO_DEVICE_POINTER.
   float x = (float)(norm_x + 0x7fff) / 0xffff;
   float y = (float)(norm_y + 0x7fff) / 0xffff;

   x -= ol->active->mod_x;
   y -= ol->active->mod_y;
   x /= ol->active->mod_w;
   y /= ol->active->mod_h;

   input_overlay_set_alpha_mod(ol, g_settings.input.overlay_opacity);

   for (i = 0; i < ol->active->size; i++)
   {
      struct overlay_desc *desc = &ol->active->descs[i];
      if (!inside_hitbox(desc, x, y))
      {
         desc->range_x_mod = desc->range_x;
         desc->range_y_mod = desc->range_y;
         continue;
      }

      // If pressed, change the hitbox.
      desc->range_x_mod = desc->range_x * desc->range_mod;
      desc->range_y_mod = desc->range_y * desc->range_mod;

      if (desc->image.image)
         ol->iface->set_alpha(ol->iface_data, desc->image_index,
               desc->alpha_mod * g_settings.input.overlay_opacity);

      if (desc->type == OVERLAY_TYPE_BUTTONS)
      {
         uint64_t mask = desc->key_mask;
         out->buttons |= mask;

         if (mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
            ol->next_index = desc->next_index;
      }
      else
      {
         float x_val = (x - desc->x) / desc->range_x_mod / desc->analog_saturate_pct;
         float y_val = (y - desc->y) / desc->range_y_mod / desc->analog_saturate_pct;

         unsigned int base = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0;
         out->analog[base + 0] = clamp(x_val, -1.0f, 1.0f) * 32767.0f;
         out->analog[base + 1] = clamp(y_val, -1.0f, 1.0f) * 32767.0f;
      }
   }

   if (!out->buttons)
      ol->blocked = false;
   else if (ol->blocked)
      memset(out, 0, sizeof(*out));
}