2017-03-16 18:14:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Pavol Rusnak, SatoshiLabs
|
|
|
|
*
|
|
|
|
* Licensed under TREZOR License
|
|
|
|
* see LICENSE file for details
|
|
|
|
*/
|
|
|
|
|
2017-03-16 18:40:20 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#ifndef TREZOR_NOUI
|
2017-03-16 18:14:12 +00:00
|
|
|
#include <SDL2/SDL.h>
|
2017-03-16 18:40:20 +00:00
|
|
|
#endif
|
2017-03-16 18:14:12 +00:00
|
|
|
|
|
|
|
#include "options.h"
|
2017-12-14 23:06:09 +00:00
|
|
|
#include "touch.h"
|
2017-03-16 18:14:12 +00:00
|
|
|
|
2017-12-07 14:31:23 +00:00
|
|
|
void __shutdown(void);
|
|
|
|
|
2017-03-16 18:14:12 +00:00
|
|
|
uint32_t touch_read(void)
|
|
|
|
{
|
2017-03-16 18:40:20 +00:00
|
|
|
#ifndef TREZOR_NOUI
|
2017-03-16 18:14:12 +00:00
|
|
|
SDL_Event event;
|
|
|
|
int x, y;
|
|
|
|
SDL_PumpEvents();
|
|
|
|
if (SDL_PollEvent(&event) > 0) {
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
x = event.button.x - DISPLAY_BORDER;
|
|
|
|
y = event.button.y - DISPLAY_BORDER;
|
|
|
|
if (x < 0 || y < 0 || x >= DISPLAY_RESX || y >= DISPLAY_RESY) break;
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
2017-10-26 14:23:04 +00:00
|
|
|
return TOUCH_START | (x << 12) | y;
|
2017-03-16 18:14:12 +00:00
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
// remove other SDL_MOUSEMOTION events from queue
|
|
|
|
SDL_FlushEvent(SDL_MOUSEMOTION);
|
|
|
|
if (event.motion.state) {
|
2017-10-26 14:23:04 +00:00
|
|
|
return TOUCH_MOVE | (x << 12) | y;
|
2017-03-16 18:14:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2017-10-26 14:23:04 +00:00
|
|
|
return TOUCH_END | (x << 12) | y;
|
2017-03-16 18:14:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
|
|
|
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
2017-12-07 14:31:23 +00:00
|
|
|
__shutdown();
|
2017-03-16 18:14:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_QUIT:
|
2017-12-07 14:31:23 +00:00
|
|
|
__shutdown();
|
2017-03-16 18:14:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-16 18:40:20 +00:00
|
|
|
#endif
|
2017-03-16 18:14:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|