예제 #1
0
   bool Layout::Update(const ActionMap & actions, unsigned int tElapsed)  {
      if (_layoutChanged)  {
         std::vector<Control*>::iterator iter = _children.begin();
         int curWide = _padding, curTall = _padding, maxHeight = 0;

         switch (_layout)  {
            case None:
               // Don't move controls
               _layoutChanged = false;
               break;
            case Grid:
               // Grid of controls
               for (; iter != _children.end(); iter++)  {
                  if (curWide + (*iter)->Width() > width)  {
                     curTall += maxHeight + _padding;
                     curWide = _padding;
                     maxHeight = 0;
                  }

                  if ((*iter)->Height() > static_cast<unsigned int>(maxHeight)) maxHeight = (int) (*iter)->Height();

                  _moveChildRelative(*iter, curWide, curTall);
                  curWide += (*iter)->Width() + _padding;
               }
               
               _layoutChanged = false;
               break;
            case HorizontalLine:
               // Horizontal line of controls
               for (; iter != _children.end(); iter++)  {
                  if (curWide + static_cast<int>((*iter)->Width()) > Right()) break;

                  _moveChildRelative(*iter, curWide, 0);
                  curWide += (*iter)->Width() + _padding;
               }

               _layoutChanged = false;
               break;
            case VerticalLine:
               // Vertical line of controls
               for (; iter != _children.end(); iter++)  {                 
                  if (curTall > Bottom()) break;

                  _moveChildRelative(*iter, 0, curTall);
                  curTall += (*iter)->Height() + _padding;
               }

               _layoutChanged = false;
               break;
         }
      }

      UpdateChildren(actions, tElapsed);

      return Collide(actions.GetInputState()->mouseX, actions.GetInputState()->mouseY);
   }
예제 #2
0
void ConsoleState::Update(const ActionMap & actions, unsigned int tElapsed)  {
   const InputState & input = *actions.GetInputState();

   if (input.KeyDown(SDLKey::SDLK_PAGEUP))
      console.ScrollUp(3);

   if (input.KeyDown(SDLKey::SDLK_PAGEDOWN))
      console.ScrollDown(3);

   if (!input.KeyDown(SDLKey::SDLK_BACKQUOTE))
      _input->Update(actions, tElapsed);

   if (input.KeyDown(SDLKey::SDLK_RETURN)) {
      ConsoleCommand c = _parseCommand(_input->GetText());

      if (c.Command == "dumplog")  {

         if (c.Params.size() > 0) 
            console.Write(c.Params.at(0).c_str());
         else
            console.Write("console.log");

         console.AddLine("Successfully wrote console log to file!");

      } else if (c.Command == "showfps")  {

         Preferences.SetValue<bool>("SHOWFPS", !Preferences.GetValue<bool>("SHOWFPS"));
         if (Preferences.GetValue<bool>("SHOWFPS"))
            console.AddLine("Frames per second display on.");
         else
            console.AddLine("Frames per second display off.");

      } else
         console.AddLine(std::string("[echo] ") + _input->GetText());

      _input->SetText(std::string(""));
   }
}