title: Displaying from std::vector and handling events using SDL?
body: <p>I am trying to make a custom app library with <code>SDL</code> as apart of an <em>academic project</em>, and I ran into an issue..</p>
  
  <p>Basically, everything works fine, it compiles, does what I expect it to do, but... its extremely slow, the first element is reacting quite quickly, other elements within the set are completely unresponsive (i need to click them 20 times for the to react, they work just slow)</p>
  
  <p>Below the function that draws the elements from a vector type container, the return 1 means that the handle function ran into an unexpected error or the user X'ed out the window. </p>
  
  <p>Any advice on how to make this react faster?</p>
  
  <pre><code>void StoreDraw::setCamera(size_t input)
  {
      rectangle.x = containerArray[input].elementLocX;
      rectangle.y = containerArray[input].elementLocY;
      rectangle.h = containerArray[input].elementPicture-&gt;h;
      rectangle.w = containerArray[input].elementPicture-&gt;w;
  }
  
  bool StoreDraw::vectorDraw()
  {
      /* Draw FloatingElements */
      for(size_t i = 0; i &lt; containerArray.size(); i++)
      {
          if(SDL_PollEvent(&amp;event))//containerArray[i].event
          {
              if(event.type == SDL_MOUSEBUTTONDOWN)
              {
                   if(event.button.button == SDL_BUTTON_LEFT)
                   {
                      locationX = event.button.x;
                      locationY = event.button.y;
                      printf("X:%d\tY:%d\n", locationX, locationY);
                      if(!containerArray[i].handleEvent(locationX, locationY)){drawEnvironment();}
                  }
              }
              if(event.type == SDL_QUIT)
              {
                  return 1;
              }
          } 
      }
      SDL_Flip(screen);
      return 0;
  }
  
  bool StoreDraw::drawEnvironment()
  {
      SDL_FillRect(screen, NULL, SDL_MapRGB(screen-&gt;format, 0,0,0));
      SDL_BlitSurface(background, NULL, screen, NULL);
  
      for(size_t i = 0; i &lt; containerArray.size(); i++)
      {
          setCamera(i);
          SDL_BlitSurface(containerArray[i].elementPicture, NULL, screen, &amp;rectangle);
      }
  
      SDL_Flip(screen);
  }
  
  bool FloatingElement::handleEvent(int x, int y)
  {
      printf("Object responding.\n");
      if((x &gt; elementLocX) &amp;&amp; (x &lt; (elementLocX + (elementPicture-&gt;w))) &amp;&amp; (y &gt; elementLocY) &amp;&amp; (y &lt; (elementLocY + (elementPicture-&gt;h))))
      {
          x = (x - (elementPicture-&gt;w)/2);
          y = (y - (elementPicture-&gt;h)/2);
          setLocation(x,y);
          printf("Object responding.\n");
          return 0;
      }
      return 1;
  }
  </code></pre>