From 37a33efc57cdd840c25cf9a75b5684d041b484ef Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 1 Apr 2016 00:44:59 +0200 Subject: [PATCH 1/2] refactor color and font definitions to trezor.ui module --- src/layout.py | 43 +++++++------------------------------- src/playground/__init__.py | 8 +++---- src/playground/utils.py | 2 -- src/trezor/ui.py | 29 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 43 deletions(-) delete mode 100644 src/playground/utils.py diff --git a/src/layout.py b/src/layout.py index 3b8c90ae3a..34f4903398 100644 --- a/src/layout.py +++ b/src/layout.py @@ -1,39 +1,10 @@ from trezor import ui -def rgb2color(r, g, b): - return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3) - -RED = rgb2color(0xF4, 0x43, 0x36) -PINK = rgb2color(0xE9, 0x1E, 0x63) -PURPLE = rgb2color(0x9C, 0x27, 0xB0) -DEEP_PURPLE = rgb2color(0x67, 0x3A, 0xB7) -INDIGO = rgb2color(0x3F, 0x51, 0xB5) -BLUE = rgb2color(0x21, 0x96, 0xF3) -LIGHT_BLUE = rgb2color(0x03, 0xA9, 0xF4) -CYAN = rgb2color(0x00, 0xBC, 0xD4) -TEAL = rgb2color(0x00, 0x96, 0x88) -GREEN = rgb2color(0x4C, 0xAF, 0x50) -LIGHT_GREEN = rgb2color(0x8B, 0xC3, 0x4A) -LIME = rgb2color(0xCD, 0xDC, 0x39) -YELLOW = rgb2color(0xFF, 0xEB, 0x3B) -AMBER = rgb2color(0xFF, 0xC1, 0x07) -ORANGE = rgb2color(0xFF, 0x98, 0x00) -DEEP_ORANGE = rgb2color(0xFF, 0x57, 0x22) -BROWN = rgb2color(0x79, 0x55, 0x48) -GREY = rgb2color(0x9E, 0x9E, 0x9E) -BLUE_GRAY = rgb2color(0x60, 0x7D, 0x8B) -BLACK = rgb2color(0x00, 0x00, 0x00) -WHITE = rgb2color(0xFF, 0xFF, 0xFF) - -MONO = 0 -NORMAL = 1 -BOLD = 2 - def show_send(address, amount, currency='BTC'): - ui.display.bar(0, 0, 240, 40, GREEN) - ui.display.bar(0, 40, 240, 200, WHITE) - ui.display.text(10, 28, 'Sending', BOLD, WHITE, GREEN) - ui.display.text(10, 80, '%f %s' % (amount, currency), BOLD, BLACK, WHITE) - ui.display.text(10, 110, 'to this address:', NORMAL, BLACK, WHITE) - ui.display.text(10, 140, address[:18], MONO, BLACK, WHITE) - ui.display.text(10, 160, address[18:], MONO, BLACK, WHITE) \ No newline at end of file + ui.display.bar(0, 0, 240, 40, ui.GREEN) + ui.display.bar(0, 40, 240, 200, ui.WHITE) + ui.display.text(10, 28, 'Sending', ui.BOLD, ui.WHITE, ui.GREEN) + ui.display.text(10, 80, '%f %s' % (amount, currency), ui.BOLD, ui.BLACK, ui.WHITE) + ui.display.text(10, 110, 'to this address:', ui.NORMAL, ui.BLACK, ui.WHITE) + ui.display.text(10, 140, address[:18], ui.MONO, ui.BLACK, ui.WHITE) + ui.display.text(10, 160, address[18:], ui.MONO, ui.BLACK, ui.WHITE) diff --git a/src/playground/__init__.py b/src/playground/__init__.py index 225fddc6cd..a29ac9da2f 100644 --- a/src/playground/__init__.py +++ b/src/playground/__init__.py @@ -9,8 +9,6 @@ import gc from uasyncio import core from trezor import ui -from .import utils - logging.basicConfig(level=logging.INFO) loop = core.get_event_loop() @@ -28,7 +26,7 @@ def animate(): col %= 0xff col += 0x0f - ui.display.icon(190, 170, f.read(), utils.rgb2color(col, 0, 0), 0xffff) + ui.display.icon(190, 170, f.read(), ui.rgbcolor(col, 0, 0), 0xffff) f.seek(0) yield from core.sleep(0.5) @@ -64,7 +62,7 @@ def tap_to_confirm(): MIN_COLOR = 0x00 MAX_COLOR = 0xB0 - _background = utils.rgb2color(255, 255, 255) + _background = ui.rgbcolor(255, 255, 255) x = math.pi while True: x += STEP_X @@ -74,7 +72,7 @@ def tap_to_confirm(): # Normalize color from interval 0:2 to MIN_COLOR:MAX_COLOR col = int((MAX_COLOR - MIN_COLOR) / 2 * y) + MIN_COLOR - foreground = utils.rgb2color(BASE_COLOR[0] + col, BASE_COLOR[1] + col, BASE_COLOR[2] + col) + foreground = ui.rgbcolor(BASE_COLOR[0] + col, BASE_COLOR[1] + col, BASE_COLOR[2] + col) ui.display.text(10, 220, 'TAP TO CONFIRM', 2, foreground, _background) diff --git a/src/playground/utils.py b/src/playground/utils.py deleted file mode 100644 index 3345c0f898..0000000000 --- a/src/playground/utils.py +++ /dev/null @@ -1,2 +0,0 @@ -def rgb2color(r, g, b): - return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3) \ No newline at end of file diff --git a/src/trezor/ui.py b/src/trezor/ui.py index cd77a231c7..0f6bf2eb36 100644 --- a/src/trezor/ui.py +++ b/src/trezor/ui.py @@ -2,3 +2,32 @@ from TrezorUi import Display, Touch display = Display() touch = Touch() + +def rgbcolor(r, g, b): + return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3) + +RED = rgbcolor(0xF4, 0x43, 0x36) +PINK = rgbcolor(0xE9, 0x1E, 0x63) +PURPLE = rgbcolor(0x9C, 0x27, 0xB0) +DEEP_PURPLE = rgbcolor(0x67, 0x3A, 0xB7) +INDIGO = rgbcolor(0x3F, 0x51, 0xB5) +BLUE = rgbcolor(0x21, 0x96, 0xF3) +LIGHT_BLUE = rgbcolor(0x03, 0xA9, 0xF4) +CYAN = rgbcolor(0x00, 0xBC, 0xD4) +TEAL = rgbcolor(0x00, 0x96, 0x88) +GREEN = rgbcolor(0x4C, 0xAF, 0x50) +LIGHT_GREEN = rgbcolor(0x8B, 0xC3, 0x4A) +LIME = rgbcolor(0xCD, 0xDC, 0x39) +YELLOW = rgbcolor(0xFF, 0xEB, 0x3B) +AMBER = rgbcolor(0xFF, 0xC1, 0x07) +ORANGE = rgbcolor(0xFF, 0x98, 0x00) +DEEP_ORANGE = rgbcolor(0xFF, 0x57, 0x22) +BROWN = rgbcolor(0x79, 0x55, 0x48) +GREY = rgbcolor(0x9E, 0x9E, 0x9E) +BLUE_GRAY = rgbcolor(0x60, 0x7D, 0x8B) +BLACK = rgbcolor(0x00, 0x00, 0x00) +WHITE = rgbcolor(0xFF, 0xFF, 0xFF) + +MONO = 0 +NORMAL = 1 +BOLD = 2 From 1d06839b37a0f0d14a1120ab48f74a01949e141b Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 1 Apr 2016 00:59:09 +0200 Subject: [PATCH 2/2] prepare touch events for SDL --- extmod/modTrezorUi/modTrezorUi-unix.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/extmod/modTrezorUi/modTrezorUi-unix.h b/extmod/modTrezorUi/modTrezorUi-unix.h index eb11f5bf95..d2d321960b 100644 --- a/extmod/modTrezorUi/modTrezorUi-unix.h +++ b/extmod/modTrezorUi/modTrezorUi-unix.h @@ -37,16 +37,27 @@ static int HandleEvents(void *ptr) { SDL_Event event; int x, y; - bool down; while (SDL_WaitEvent(&event) >= 0) { switch (event.type) { - case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEMOTION: + case SDL_MOUSEBUTTONUP: x = event.button.x - DISPLAY_BORDER; y = event.button.y - DISPLAY_BORDER; if (x < 0 || y < 0 || x >= RESX || y >= RESY) continue; - down = (event.type == SDL_MOUSEBUTTONDOWN); - printf("CLICK %s: %d %d\n", down ? "DOWN" : "UP", x, y); + switch (event.type) { + case SDL_MOUSEBUTTONDOWN: + printf("TOUCH START: %d %d\n", x, y); + break; + case SDL_MOUSEMOTION: + if (event.motion.state) { + printf("TOUCH MOVE: %d %d\n", x, y); + } + break; + case SDL_MOUSEBUTTONUP: + printf("TOUCH END: %d %d\n", x, y); + break; + } break; } }