Beispiel #1
0
/**
 * @brief Focus next widget.
 */
void toolkit_nextFocus (void)
{
   Window *wdw;
   Widget *wgt;
   int next;

   /* Get window. */
   wdw = toolkit_getActiveWindow();
   if (wdw == NULL)
      return;

   /* See what to focus. */
   next = (wdw->focus == -1);
   for (wgt=wdw->widgets; wgt!=NULL; wgt=wgt->next) {
      if (toolkit_isFocusable(wgt)) {

         if (next) {
            wdw->focus = wgt->id;
            return;
         }
         else if (wdw->focus == wgt->id)
            next = 1;
      }
   }

   /* Focus nothing. */
   wdw->focus = -1;
   return;
}
Beispiel #2
0
/**
 * @brief Updates the toolkit input for repeating keys.
 */
void toolkit_update (void)
{
   unsigned int t;
   Window *wdw;
   Widget *wgt;
   char buf[2];
   SDL_Event event;
   int ret;

   /* Clean up the dead if needed. */
   if (!dialogue_isOpen()) { /* Hack, since dialogues use secondary loop. */
      if (toolkit_delayCounter > 0)
         toolkit_delayCounter--;
      else
         toolkit_purgeDead();
   }

   /* Killed all the windows. */
   if (windows == NULL) {
      SDL_ShowCursor(SDL_DISABLE);
      toolkit_open = 0; /* disable toolkit */
      if (paused)
         unpause_game();
   }

   /* Must have a key pressed. */
   if (input_key == 0)
      return;

   t = SDL_GetTicks();

   /* Should be repeating. */
   if (input_keyTime + INPUT_DELAY + input_keyCounter*INPUT_FREQ > t)
      return;

   /* Increment counter. */
   input_keyCounter++;

   /* Check to see what it affects. */
   if (windows != NULL) {
      /* Get the window. */
      wdw = toolkit_getActiveWindow();
      if (wdw == NULL)
         return;


      /* See if widget needs event. */
      for (wgt=wdw->widgets; wgt!=NULL; wgt=wgt->next) {
         if (wgt_isFlag( wgt, WGT_FLAG_RAWINPUT )) {
            if (wgt->rawevent != NULL) {
               event.type           = SDL_KEYDOWN;
               event.key.state      = SDL_PRESSED;
               event.key.keysym.sym = input_key;
               event.key.keysym.mod = 0;
               ret = wgt->rawevent( wgt, &event );
               if (ret != 0)
                  return;
            }
         }
      }

      /* Handle the focused widget. */
      wgt = toolkit_getFocus( wdw );
      if ((wgt != NULL) && (wgt->keyevent != NULL)) {
         wgt->keyevent( wgt, input_key, 0 );
      }
      if ((input_text != 0) && (wgt != NULL) && (wgt->textevent != NULL)) {
         buf[0] = input_text;
         buf[1] = '\0';
         wgt->textevent( wgt, buf );
      }
   }
}