コード例 #1
0
ファイル: GUIHandler.cpp プロジェクト: greeduomacro/Iris1
void GUIHandler::HandleMessageQueues (void)
{
  Control *control;
  Container *container;

  gui_message msg;

  std::list < Uint32 >::iterator refresh_iter;
  Uint32 currenttime = SDL_GetTicks ();
  bool do_refresh = false;
  for (refresh_iter = refresh_times.begin ();
       refresh_iter != refresh_times.end ();)
      {
        if (*refresh_iter < currenttime)
            {
              std::list < Uint32 >::iterator nextiter = refresh_iter;
              nextiter++;
              refresh_times.erase (refresh_iter);
              refresh_iter = nextiter;
              do_refresh = true;
            }
        else
          refresh_iter++;
      }

  if (do_refresh)
      {
        msg.type = MESSAGE_DOREFRESH;
        msg.refresh.time = currenttime;
        stack.Push (msg);
      }

  ControlList_t::iterator iter;
  for (iter = control_root.begin (); iter != control_root.end (); iter++)
    while (iter->second->stack.Pop (&msg))
      stack.Push (msg);

  while (stack.Pop (&msg))
    switch (msg.type)
        {
        case MESSAGE_CLOSEGUMP:
          CloseWindow (msg.windowaction.controlid);
          break;
        case MESSAGE_SETFOCUS:
          SetFocus (msg.windowaction.controlid);
          break;
        case MESSAGE_RELEASEFOCUS:
          ReleaseFocus (msg.windowaction.controlid);
          break;
        case MESSAGE_BRINGTOFRONT:
          BringToFront (msg.windowaction.controlid);
          break;
        case MESSAGE_QUIT:
			SDLEvent::KillApplication();
			break;
        case MESSAGE_STARTGAME:
          startflag = -1;
          break;
        case MESSAGE_CALLBACK:
          if (msg.callback.containerid)
              {
                control = GetControl (msg.callback.containerid);
                if (control)
                    {
                      if (control->getType () == CONTROLTYPE_CONTAINER)
                          {
                            container = (Container *) control;
                            control = container->GetControl (msg.callback.id);
                          }
                      else
                        control = NULL;
                    }
              }
          else
            control = GetControl (msg.callback.id);
          if (control)
            switch (msg.callback.callback_type)
                {
                case CALLBACK_ONCLICK:
                  if (control->getType () == CONTROLTYPE_BUTTON)
                    ((Button *) control)->DoOnClick ();
                  break;
                case CALLBACK_ONKEYPRESS:
                  if (control->getType () == CONTROLTYPE_INPUTFIELD)
                    ((InputField *) control)->DoOnKeyPress (msg.callback.key);
                  break;
                case CALLBACK_ONCLOSE:
                  control->DoOnClose ();
                  break;
                case CALLBACK_ONMOUSEUP:
                  control->DoOnMouseUp ();
                  break;
                case CALLBACK_ONMOUSEDOWN:
                  control->DoOnMouseDown ();
                  break;
                }
          break;
        case MESSAGE_ONDRAGITEM:
          if (callback_OnDrag)
            callback_OnDrag (msg.dragitem.itemid, msg.dragitem.model);
          drag_id = msg.dragitem.itemid;
          drag_model = msg.dragitem.model;

          break;
        case MESSAGE_ONCLICKITEM:
          if (callback_OnItemClick)
            callback_OnItemClick (msg.onclickitem.itemid,
                                  msg.onclickitem.doubleclick);
          break;
        case MESSAGE_REFRESHREQUEST:
          refresh_times.push_back (msg.refresh.time);
          break;
        default:
          HandleMessage (&msg);
        }

}