diff --git a/assets/background.png b/assets/background.png new file mode 100644 index 00000000..6cee82c4 Binary files /dev/null and b/assets/background.png differ diff --git a/embed/extmod/modtrezorui/display-unix.h b/embed/extmod/modtrezorui/display-unix.h index 9e3ffe54..de9dd535 100644 --- a/embed/extmod/modtrezorui/display-unix.h +++ b/embed/extmod/modtrezorui/display-unix.h @@ -10,11 +10,9 @@ #include #include -#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(); } - SDL_RenderClear(RENDERER); + 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 diff --git a/embed/extmod/modtrezorui/display.c b/embed/extmod/modtrezorui/display.c index 51856713..7718d2c5 100644 --- a/embed/extmod/modtrezorui/display.c +++ b/embed/extmod/modtrezorui/display.c @@ -20,6 +20,7 @@ #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 new file mode 100644 index 00000000..d587f025 --- /dev/null +++ b/embed/trezorhal/options.h @@ -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 diff --git a/embed/unix/background.jpg b/embed/unix/background.jpg new file mode 100644 index 00000000..e7396c35 Binary files /dev/null and b/embed/unix/background.jpg differ diff --git a/embed/unix/options.h b/embed/unix/options.h index 0d5ce955..72fbc9d0 100644 --- a/embed/unix/options.h +++ b/embed/unix/options.h @@ -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 diff --git a/embed/unix/touch.c b/embed/unix/touch.c index 2f337b4a..e0785e48 100644 --- a/embed/unix/touch.c +++ b/embed/unix/touch.c @@ -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: