From 081dcdd98fab172d0f62aab705b18d8808f4f46e Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 26 Feb 2018 19:44:29 +0100 Subject: [PATCH] embed/unix: resize emulator window if no background image found --- embed/extmod/modtrezorui/display-unix.h | 26 ++++++++++++++++++-- embed/extmod/modtrezorui/display.c | 1 - embed/trezorhal/options.h | 23 ------------------ embed/unix/options.h | 32 ------------------------- embed/unix/touch.c | 12 ++++++---- 5 files changed, 31 insertions(+), 63 deletions(-) delete mode 100644 embed/trezorhal/options.h delete mode 100644 embed/unix/options.h diff --git a/embed/extmod/modtrezorui/display-unix.h b/embed/extmod/modtrezorui/display-unix.h index a0eafacb13..796589ce9a 100644 --- a/embed/extmod/modtrezorui/display-unix.h +++ b/embed/extmod/modtrezorui/display-unix.h @@ -22,10 +22,21 @@ #include #include +#define DISPLAY_EMULATOR_BORDER 16 + +#define DISPLAY_TOUCH_OFFSET_X 180 +#define DISPLAY_TOUCH_OFFSET_Y 120 + +#define WINDOW_WIDTH 600 +#define WINDOW_HEIGHT 800 + static SDL_Renderer *RENDERER; static SDL_Surface *BUFFER; static SDL_Texture *TEXTURE, *BACKGROUND; +int sdl_display_res_x = DISPLAY_RESX, sdl_display_res_y = DISPLAY_RESX; +int sdl_touch_offset_x, sdl_touch_offset_y; + static struct { struct { uint16_t x, y; @@ -83,6 +94,12 @@ void display_init(void) BACKGROUND = IMG_LoadTexture(RENDERER, "../embed/unix/background.jpg"); if (BACKGROUND) { SDL_SetTextureBlendMode(BACKGROUND, SDL_BLENDMODE_NONE); + sdl_touch_offset_x = DISPLAY_TOUCH_OFFSET_X; + sdl_touch_offset_y = DISPLAY_TOUCH_OFFSET_Y; + } else { + SDL_SetWindowSize(win, DISPLAY_RESX + 2 * DISPLAY_EMULATOR_BORDER, DISPLAY_RESY + 2 * DISPLAY_EMULATOR_BORDER); + sdl_touch_offset_x = DISPLAY_EMULATOR_BORDER; + sdl_touch_offset_y = DISPLAY_EMULATOR_BORDER; } DISPLAY_BACKLIGHT = 0; DISPLAY_ORIENTATION = 0; @@ -115,8 +132,13 @@ void display_refresh(void) SDL_UpdateTexture(TEXTURE, NULL, BUFFER->pixels, BUFFER->pitch); #define BACKLIGHT_NORMAL 150 SDL_SetTextureAlphaMod(TEXTURE, MIN(255, 255 * DISPLAY_BACKLIGHT / BACKLIGHT_NORMAL)); - const SDL_Rect r = {DISPLAY_TOUCH_OFFSET_X, DISPLAY_TOUCH_OFFSET_Y, DISPLAY_RESX, DISPLAY_RESY}; - SDL_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, DISPLAY_ORIENTATION, NULL, 0); + if (BACKGROUND) { + const SDL_Rect r = {DISPLAY_TOUCH_OFFSET_X, DISPLAY_TOUCH_OFFSET_Y, DISPLAY_RESX, DISPLAY_RESY}; + SDL_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, DISPLAY_ORIENTATION, NULL, 0); + } else { + const SDL_Rect r = {DISPLAY_EMULATOR_BORDER, DISPLAY_EMULATOR_BORDER, DISPLAY_RESX, DISPLAY_RESY}; + SDL_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, DISPLAY_ORIENTATION, NULL, 0); + } SDL_RenderPresent(RENDERER); #endif } diff --git a/embed/extmod/modtrezorui/display.c b/embed/extmod/modtrezorui/display.c index 16f3ee3c77..389d970105 100644 --- a/embed/extmod/modtrezorui/display.c +++ b/embed/extmod/modtrezorui/display.c @@ -32,7 +32,6 @@ #include "trezor-qrenc/qr_encode.h" #include "common.h" -#include "options.h" #include "display.h" #include diff --git a/embed/trezorhal/options.h b/embed/trezorhal/options.h deleted file mode 100644 index 406d4b86ea..0000000000 --- a/embed/trezorhal/options.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is part of the TREZOR project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program 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. - * - * This program 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 this program. If not, see . - */ - -#ifndef __OPTIONS_H__ -#define __OPTIONS_H__ - -#endif diff --git a/embed/unix/options.h b/embed/unix/options.h deleted file mode 100644 index cd31546ec9..0000000000 --- a/embed/unix/options.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of the TREZOR project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program 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. - * - * This program 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 this program. If not, see . - */ - -#ifndef __OPTIONS_H__ -#define __OPTIONS_H__ - -#define DISPLAY_RESX 240 -#define DISPLAY_RESY 240 - -#define DISPLAY_TOUCH_OFFSET_X 180 -#define DISPLAY_TOUCH_OFFSET_Y 120 - -#define WINDOW_WIDTH 600 -#define WINDOW_HEIGHT 800 - -#endif diff --git a/embed/unix/touch.c b/embed/unix/touch.c index 76e9093528..a399ed4ae3 100644 --- a/embed/unix/touch.c +++ b/embed/unix/touch.c @@ -22,10 +22,12 @@ #include #endif -#include "options.h" #include "touch.h" -void __shutdown(void); +extern int sdl_display_res_x, sdl_display_res_y; +extern int sdl_touch_offset_x, sdl_touch_offset_y; + +extern void __shutdown(void); uint32_t touch_read(void) { @@ -38,9 +40,9 @@ uint32_t touch_read(void) case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: - x = event.button.x - DISPLAY_TOUCH_OFFSET_X; - y = event.button.y - DISPLAY_TOUCH_OFFSET_Y; - if (x < 0 || y < 0 || x >= DISPLAY_RESX || y >= DISPLAY_RESY) break; + x = event.button.x - sdl_touch_offset_x; + y = event.button.y - sdl_touch_offset_y; + if (x < 0 || y < 0 || x >= sdl_display_res_x || y >= sdl_display_res_y) break; switch (event.type) { case SDL_MOUSEBUTTONDOWN: return TOUCH_START | touch_pack_xy(x, y);