Esempio n. 1
0
void handle_events(void)
{
   SDL_Event event;
   int x, y;

   while (SDL_PollEvent(&event)) {
      switch (event.type) {
      case SDL_MOUSEBUTTONDOWN:
         /* Get mouse position */
         SDL_GetMouseState(&x, &y);
         mouse_clicked(x, y);
         break;
      case SDL_KEYDOWN:
         /* Quit if key is escape or q */
         switch (event.key.keysym.sym) {
         case SDLK_ESCAPE:
         case SDLK_q:
            escape_pressed();
            break;
         case SDLK_p:
            pause_pressed();
            break;
         default:
            break;
         }
         break;
      case SDL_QUIT:
         escape_pressed();
         break;
      default:
         break;
      }
   }
}
Esempio n. 2
0
void _listbox::check()
{
	if (delay <= 0)
	{
		if (up.mousedown())
		{
			scroll(-1);
			delay = 5;
		}
		else if (down.mousedown())
		{
			scroll(1);
			delay = 5;
		}
		else if ((sel != -1) && (key[KEY_UP]))
		{
			if ((mouse_x > x) && (mouse_x < x + w - 2))
			{
				if ((mouse_y > y) && (mouse_y < y + h))
				{
					if (sel > 0) sel--;
					if (sel < offset) scroll(-1);
					delay = 5;
				}
			}
		}
		else if ((sel != -1) && (key[KEY_DOWN]))
		{
			if ((mouse_x > x) && (mouse_x < x + w - 2))
			{
				if ((mouse_y > y) && (mouse_y < y + h))
				{
					if (sel < listsize - 1) sel++;
					if (sel > offset + (h / listbox_textheight) - 2) scroll(1);
					delay = 5;
				}
			}
		}
		else if (mouse_zval != mouse_z)
		{
			if (mouse_z > mouse_zval)
			{
				scroll(-1);
			}
			else
			{
				scroll(1);
			}
			mouse_zval = mouse_z;
		}
	}
	else
	{
		delay--;
	}
	
	if (mouse_clicked() == 1)
	{
		if ((mouse_x > x) && (mouse_x < x + w - 2))
		{
			if ((mouse_y > y) && (mouse_y < y + h))
			{
				sel = ((mouse_y - y) / listbox_textheight) + offset;
				if (sel >= listsize) sel = -1;
			}
		}
	}
	
	draw();
}