123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- Copyright (C) 2011 Weber Yann, Schuck Clement
-
- This file is part of Tansive.
-
- Tansive is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Tansive is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Tansive. If not, see <http://www.gnu.org/licenses/>.
- */
- #include"event.h"
-
- /*
- Thread function for SDL events handling
- */
- void* event_catcher_loop(void* arg)
- {
- t_param_thread_event *param = (t_param_thread_event*)arg;
- *(param->again) = 1;
- SDL_Event event;
-
- while(*(param->again))
- {
- bzero(&event,sizeof(SDL_Event));
- SDL_PollEvent(&event);
-
- switch(event.type)
- {
- case SDL_QUIT:
- pthread_mutex_lock(param->mutex);
- *(param->again) = 0;
- pthread_mutex_unlock(param->mutex);
- break;
- case SDL_MOUSEMOTION:
- pthread_mutex_lock(param->mutex);
- *(param->mx) = event.motion.x;
- *(param->my) = event.motion.y;
- pthread_mutex_unlock(param->mutex);
- break;
- case SDL_MOUSEBUTTONUP:
- pthread_mutex_lock(param->mutex);
-
- if (event.button.button == SDL_BUTTON_RIGHT || event.button.button == SDL_BUTTON_WHEELDOWN)
- {
- if(*(param->zoom) < 3)
- {
- *(param->x) = *(param->x_resol)/2;
- *(param->y) = *(param->y_resol)/2;
- }
- else
- {
- *(param->x) -= (*(param->x_resol)/ *(param->zoom))/2;
- *(param->y) -= (*(param->y_resol)/ *(param->zoom))/2;
- *(param->x) += event.button.x/ *(param->zoom);
- *(param->y) += event.button.y/ *(param->zoom);
- }
-
- *(param->zoom) = (*(param->zoom)>1?*(param->zoom)-1:1);
- }
- else if (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_WHEELUP)
- {
- *(param->x) -= (*(param->x_resol)/ *(param->zoom))/2;
- *(param->y) -= (*(param->y_resol)/ *(param->zoom))/2;
- *(param->x) += event.button.x/ *(param->zoom);
- *(param->y) += event.button.y/ *(param->zoom);
- *(param->zoom)+=1;
- }
-
- pthread_mutex_unlock(param->mutex);
- break;
- case SDL_KEYDOWN:
- pthread_mutex_lock(param->mutex);
- switch(event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- *(param->again) = 0;
- break;
- case SDLK_UP:
- *(param->y)-=1;
- *(param->y) = *(param->y)<0?0:*(param->y);
- break;
- case SDLK_DOWN:
- *(param->y)+=1;
- *(param->y) = *(param->y)>*(param->y_resol)-1?*(param->y_resol)-1:*(param->y);
- break;
- case SDLK_RIGHT:
- *(param->x)+=1;
- *(param->x) = *(param->x)>*(param->x_resol)-1?*(param->x_resol)-1:*(param->x);
- break;
- case SDLK_LEFT:
- *(param->x)-=1;
- *(param->x) = *(param->x)<0?0:*(param->x);
- break;
- }
- pthread_mutex_unlock(param->mutex);
- break;
-
- }
-
- }
-
- exit(0);
- }
|