Exemplo n.º 1
0
Arquivo: toolkit.c Projeto: Delll/naev
/**
 * @brief Focus previous widget.
 */
void toolkit_prevFocus( Window *wdw )
{
   Widget *wgt, *prev;

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

      /* See if we found the current one. */
      if (wdw->focus == wgt->id) {
         if (prev == NULL)
            wdw->focus = -1;
         else
            wdw->focus = prev->id;
         return;
      }

      /* Store last focusable widget. */
      prev = wgt;
   }

   /* Focus nothing. */
   if (prev == NULL)
      wdw->focus = -1;
   else
      wdw->focus = prev->id;
   return;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
Arquivo: toolkit.c Projeto: Delll/naev
/**
 * @brief Focus next widget.
 */
void toolkit_nextFocus( Window *wdw )
{
   Widget *wgt;
   int next;

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

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

   /* Focus nothing. */
   wdw->focus = -1;
   return;
}
Exemplo n.º 4
0
Arquivo: toolkit.c Projeto: Delll/naev
/**
 * @brief Handle widget mouse input.
 *
 *    @param w Window to which widget belongs.
 *    @param wgt Widget recieving event.
 *    @param event Event recieved by the window.
 */
static void toolkit_mouseEventWidget( Window *w, Widget *wgt,
      Uint8 type, Uint8 button, int x, int y, int rx, int ry )
{
   int inbounds;

   /* Widget translations. */
   x -= wgt->x;
   y -= wgt->y;

   /* Check inbounds. */
   inbounds = !((x < 0) || (x >= wgt->w) || (y < 0) || (y >= wgt->h));

   /* Regular widgets. */
   switch (type) {
      case SDL_MOUSEMOTION:
         /* Change the status of the widget if mouse isn't down. */

         /* Not scrolling. */
         if (wgt->status != WIDGET_STATUS_SCROLLING) {
            if (inbounds) {
               if (wgt->status != WIDGET_STATUS_MOUSEDOWN)
                  wgt->status = WIDGET_STATUS_MOUSEOVER;
            }
            else
               wgt->status = WIDGET_STATUS_NORMAL;
         }
         else
            inbounds = 1; /* Scrolling is always inbounds. */

         /* If always gets the event. */
         if (wgt_isFlag( wgt, WGT_FLAG_ALWAYSMMOVE ))
            inbounds = 1;

         /* Try to give the event to the widget. */
         if (inbounds && (wgt->mmoveevent != NULL))
            (*wgt->mmoveevent)( wgt, x, y, rx, ry );

         break;

      case SDL_MOUSEBUTTONDOWN:
         if (!inbounds)
            break;

         /* Update the status. */
         if (button == SDL_BUTTON_LEFT)
            wgt->status = WIDGET_STATUS_MOUSEDOWN;

         if (toolkit_isFocusable(wgt))
            w->focus = wgt->id;

         /* Try to give the event to the widget. */
         if (wgt->mclickevent != NULL)
            (*wgt->mclickevent)( wgt, button, x, y );
         break;

      case SDL_MOUSEBUTTONUP:
         /* Since basically only buttons are handled here, we ignore
          * it all except the left mouse button. */
         if (button != SDL_BUTTON_LEFT)
            break;

         if (wgt->status==WIDGET_STATUS_MOUSEDOWN) {
            if ((wgt->type==WIDGET_BUTTON) &&
                  (wgt->dat.btn.disabled==0)) {
               if (wgt->dat.btn.fptr==NULL)
                  DEBUG("Toolkit: Button '%s' of Window '%s' "
                        "doesn't have a function trigger",
                        wgt->name, w->name );
               else {
                  (*wgt->dat.btn.fptr)(w->id, wgt->name);
               }
            }
         }

         /* Always goes normal unless is below mouse. */
         if (inbounds)
            wgt->status = WIDGET_STATUS_MOUSEOVER;
         else
            wgt->status = WIDGET_STATUS_NORMAL;

         break;
   }
}