1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

embed/unix: resize emulator window if no background image found

This commit is contained in:
Pavol Rusnak 2018-02-26 19:44:29 +01:00
parent 81e31afc58
commit 081dcdd98f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 31 additions and 63 deletions

View File

@ -22,10 +22,21 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#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
}

View File

@ -32,7 +32,6 @@
#include "trezor-qrenc/qr_encode.h"
#include "common.h"
#include "options.h"
#include "display.h"
#include <string.h>

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef __OPTIONS_H__
#define __OPTIONS_H__
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -22,10 +22,12 @@
#include <SDL2/SDL.h>
#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);