1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

embed/unix: implement nice background into emulator

This commit is contained in:
Pavol Rusnak 2018-02-25 02:09:52 +01:00
parent 64f7089d45
commit 2bb9d80c18
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
7 changed files with 33 additions and 10 deletions

BIN
assets/background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 KiB

View File

@ -10,11 +10,9 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#define DISPLAY_BORDER 16
static SDL_Renderer *RENDERER;
static SDL_Surface *BUFFER;
static SDL_Texture *TEXTURE;
static SDL_Texture *TEXTURE, *BACKGROUND;
static struct {
struct {
@ -53,7 +51,7 @@ void display_init(void)
ensure(secfalse, "SDL_Init error");
}
atexit(SDL_Quit);
SDL_Window *win = SDL_CreateWindow("TREZOR", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, DISPLAY_RESX + 2 * DISPLAY_BORDER, DISPLAY_RESY + 2 * DISPLAY_BORDER, SDL_WINDOW_SHOWN);
SDL_Window *win = SDL_CreateWindow("TREZOR Emulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
if (!win) {
printf("%s\n", SDL_GetError());
ensure(secfalse, "SDL_CreateWindow error");
@ -69,7 +67,11 @@ void display_init(void)
BUFFER = SDL_CreateRGBSurface(0, MAX_DISPLAY_RESX, MAX_DISPLAY_RESY, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
TEXTURE = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, DISPLAY_RESX, DISPLAY_RESY);
SDL_SetTextureBlendMode(TEXTURE, SDL_BLENDMODE_BLEND);
// TODO: find better way how to embed/distribute background image
BACKGROUND = IMG_LoadTexture(RENDERER, "../embed/unix/background.jpg");
if (BACKGROUND) {
SDL_SetTextureBlendMode(BACKGROUND, SDL_BLENDMODE_NONE);
}
DISPLAY_BACKLIGHT = 0;
DISPLAY_ORIENTATION = 0;
#endif
@ -93,11 +95,15 @@ void display_refresh(void)
if (!RENDERER) {
display_init();
}
if (BACKGROUND) {
SDL_RenderCopy(RENDERER, BACKGROUND, NULL, NULL);
} else {
SDL_RenderClear(RENDERER);
}
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_BORDER, DISPLAY_BORDER, DISPLAY_RESX, DISPLAY_RESY};
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);
SDL_RenderPresent(RENDERER);
#endif

View File

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

11
embed/trezorhal/options.h Normal file
View File

@ -0,0 +1,11 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#ifndef __OPTIONS_H__
#define __OPTIONS_H__
#endif

BIN
embed/unix/background.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View File

@ -10,6 +10,11 @@
#define DISPLAY_RESX 240
#define DISPLAY_RESY 240
#define DISPLAY_BORDER 16
#define DISPLAY_TOUCH_OFFSET_X 180
#define DISPLAY_TOUCH_OFFSET_Y 120
#define WINDOW_WIDTH 600
#define WINDOW_HEIGHT 800
#endif

View File

@ -26,8 +26,8 @@ uint32_t touch_read(void)
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONUP:
x = event.button.x - DISPLAY_BORDER;
y = event.button.y - DISPLAY_BORDER;
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;
switch (event.type) {
case SDL_MOUSEBUTTONDOWN: