mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-16 17:42:02 +00:00
embed/unix: implement nice background into emulator
This commit is contained in:
parent
64f7089d45
commit
2bb9d80c18
BIN
assets/background.png
Normal file
BIN
assets/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 747 KiB |
@ -10,11 +10,9 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
|
||||||
#define DISPLAY_BORDER 16
|
|
||||||
|
|
||||||
static SDL_Renderer *RENDERER;
|
static SDL_Renderer *RENDERER;
|
||||||
static SDL_Surface *BUFFER;
|
static SDL_Surface *BUFFER;
|
||||||
static SDL_Texture *TEXTURE;
|
static SDL_Texture *TEXTURE, *BACKGROUND;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
struct {
|
struct {
|
||||||
@ -53,7 +51,7 @@ void display_init(void)
|
|||||||
ensure(secfalse, "SDL_Init error");
|
ensure(secfalse, "SDL_Init error");
|
||||||
}
|
}
|
||||||
atexit(SDL_Quit);
|
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) {
|
if (!win) {
|
||||||
printf("%s\n", SDL_GetError());
|
printf("%s\n", SDL_GetError());
|
||||||
ensure(secfalse, "SDL_CreateWindow error");
|
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);
|
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);
|
TEXTURE = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, DISPLAY_RESX, DISPLAY_RESY);
|
||||||
SDL_SetTextureBlendMode(TEXTURE, SDL_BLENDMODE_BLEND);
|
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_BACKLIGHT = 0;
|
||||||
DISPLAY_ORIENTATION = 0;
|
DISPLAY_ORIENTATION = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -93,11 +95,15 @@ void display_refresh(void)
|
|||||||
if (!RENDERER) {
|
if (!RENDERER) {
|
||||||
display_init();
|
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);
|
SDL_UpdateTexture(TEXTURE, NULL, BUFFER->pixels, BUFFER->pitch);
|
||||||
#define BACKLIGHT_NORMAL 150
|
#define BACKLIGHT_NORMAL 150
|
||||||
SDL_SetTextureAlphaMod(TEXTURE, MIN(255, 255 * DISPLAY_BACKLIGHT / BACKLIGHT_NORMAL));
|
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_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, DISPLAY_ORIENTATION, NULL, 0);
|
||||||
SDL_RenderPresent(RENDERER);
|
SDL_RenderPresent(RENDERER);
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "trezor-qrenc/qr_encode.h"
|
#include "trezor-qrenc/qr_encode.h"
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "options.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
11
embed/trezorhal/options.h
Normal file
11
embed/trezorhal/options.h
Normal 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
BIN
embed/unix/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 88 KiB |
@ -10,6 +10,11 @@
|
|||||||
|
|
||||||
#define DISPLAY_RESX 240
|
#define DISPLAY_RESX 240
|
||||||
#define DISPLAY_RESY 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
|
#endif
|
||||||
|
@ -26,8 +26,8 @@ uint32_t touch_read(void)
|
|||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
x = event.button.x - DISPLAY_BORDER;
|
x = event.button.x - DISPLAY_TOUCH_OFFSET_X;
|
||||||
y = event.button.y - DISPLAY_BORDER;
|
y = event.button.y - DISPLAY_TOUCH_OFFSET_Y;
|
||||||
if (x < 0 || y < 0 || x >= DISPLAY_RESX || y >= DISPLAY_RESY) break;
|
if (x < 0 || y < 0 || x >= DISPLAY_RESX || y >= DISPLAY_RESY) break;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
Loading…
Reference in New Issue
Block a user