Browse Source

Add rotation support to the UI task

master
Adam Pippin 4 years ago
parent
commit
11b8cb75d9
  1. 77
      UI.cpp
  2. 13
      UI.h

77
UI.cpp

@ -1,6 +1,7 @@
#include <M5StickC.h> #include <M5StickC.h>
#include "Kernel.h" #include "Kernel.h"
#include "UI.h" #include "UI.h"
#include "EAT.h"
#define MAX_WINDOWS 8 #define MAX_WINDOWS 8
@ -10,22 +11,41 @@ void UI_draw(int parent_hwnd, int x, int y, int width, int height);
struct Window windows[MAX_WINDOWS]; struct Window windows[MAX_WINDOWS];
int next_hwnd = 1; int next_hwnd = 1;
int rotation = ROTATION_HORIZONTAL_BUTTON_LEFT;
int UI(int pid, unsigned int signal) int UI(int pid, unsigned int signal)
{ {
if (signal & SIGNAL_START) if (signal & SIGNAL_START)
{ {
Kernel_signal_mask(pid, SIGNAL_START | SIGNAL_STOP | SIGNAL_REDRAW); Kernel_signal_mask(pid, SIGNAL_START | SIGNAL_STOP | SIGNAL_REDRAW | SIGNAL_INPUT_A);
windows[0].hwnd = next_hwnd++; windows[0].hwnd = next_hwnd++;
windows[0].hwnd_parent = 0; windows[0].hwnd_parent = 0;
windows[0].layout_mode = LAYOUT_MODE_SPLIT_VERTICAL; windows[0].layout_mode = LAYOUT_MODE_SPLIT_AUTO;
windows[0].callback = &base_window_callback; windows[0].callback = &base_window_callback;
if (EAT_allocate(3, 1))
{
EAT_write(3, 0, rotation);
}
else
{
rotation = EAT_read(3, 0);
}
} }
if (signal & SIGNAL_STOP) if (signal & SIGNAL_STOP)
{ {
EAT_write(3, 0, rotation);
return 255; return 255;
} }
if (signal & SIGNAL_INPUT_A)
{
rotation = rotation + 1;
if (rotation == 4)
rotation = 0;
Kernel_signal(SIGNAL_REDRAW);
}
if (signal & SIGNAL_REDRAW) if (signal & SIGNAL_REDRAW)
{ {
@ -36,11 +56,16 @@ int UI(int pid, unsigned int signal)
continue; continue;
} }
M5.Lcd.setTextColor(TFT_WHITE, TFT_DARKGREY); M5.Lcd.setTextColor(TFT_WHITE, TFT_DARKGREY);
// TODO: Get actual screen bounds somehow if (rotation == ROTATION_HORIZONTAL_BUTTON_LEFT || rotation == ROTATION_HORIZONTAL_BUTTON_RIGHT)
// Horizontal {
UI_draw(windows[i].hwnd, 0, 0, 160, 80); // Horizontal
// Vertical UI_draw(windows[i].hwnd, 0, 0, 160, 80);
//UI_draw(windows[i].hwnd, 0, 0, 80, 160); }
else if (rotation == ROTATION_VERTICAL_BUTTON_UP || rotation == ROTATION_VERTICAL_BUTTON_DOWN)
{
// Vertical
UI_draw(windows[i].hwnd, 0, 0, 80, 160);
}
} }
} }
@ -88,7 +113,21 @@ void UI_draw(int parent_hwnd, int x, int y, int width, int height)
} }
} }
switch (parent_window->layout_mode) int layout_mode = parent_window->layout_mode;
if (layout_mode == LAYOUT_MODE_SPLIT_AUTO)
{
if (rotation == ROTATION_HORIZONTAL_BUTTON_LEFT || rotation == ROTATION_HORIZONTAL_BUTTON_RIGHT)
{
layout_mode = LAYOUT_MODE_SPLIT_VERTICAL;
}
else if (rotation == ROTATION_VERTICAL_BUTTON_UP || rotation == ROTATION_VERTICAL_BUTTON_DOWN)
{
layout_mode = LAYOUT_MODE_SPLIT_HORIZONTAL;
}
}
switch (layout_mode)
{ {
case LAYOUT_MODE_NONE: case LAYOUT_MODE_NONE:
{ {
@ -122,10 +161,10 @@ void UI_draw(int parent_hwnd, int x, int y, int width, int height)
void base_window_callback(int hwnd, int x, int y, int width, int height) void base_window_callback(int hwnd, int x, int y, int width, int height)
{ {
M5.Lcd.fillScreen(TFT_DARKGREY); M5.Lcd.fillScreen(TFT_DARKGREY);
M5.Lcd.setRotation(3); M5.Lcd.setRotation(rotation);
} }
int UI_create_window(void (*callback)(int, int, int, int, int), int parent /* = 0 */, int zorder /* = 0 */, bool placeholder /* = true */) int UI_create_window(void (*callback)(int, int, int, int, int), int parent /* = 0 */, int zorder /* = 0 */)
{ {
Window* window = UI_get_window(0); Window* window = UI_get_window(0);
if (window->hwnd == -1) if (window->hwnd == -1)
@ -135,15 +174,29 @@ int UI_create_window(void (*callback)(int, int, int, int, int), int parent /* =
window->hwnd = next_hwnd++; window->hwnd = next_hwnd++;
window->hwnd_parent = parent; window->hwnd_parent = parent;
window->placeholder = placeholder; window->placeholder = false;
window->callback = callback; window->callback = callback;
return window->hwnd; return window->hwnd;
} }
void UI_set_layout_mode(int hwnd, int layout_mode) int UI_create_window(int parent /* = 0 */, int zorder /* = 0 */)
{ {
Window* window = UI_get_window(0); Window* window = UI_get_window(0);
if (window->hwnd == -1) if (window->hwnd == -1)
{
Kernel_panic("Cannot create window! Out of handles!");
}
window->hwnd = next_hwnd++;
window->hwnd_parent = parent;
window->placeholder = true;
return window->hwnd;
}
void UI_set_layout_mode(int hwnd, int layout_mode)
{
Window* window = UI_get_window(hwnd);
if (window->hwnd == -1)
{ {
return; return;
} }

13
UI.h

@ -8,10 +8,17 @@ struct Window
bool placeholder = false; bool placeholder = false;
}; };
#define LAYOUT_MODE_NONE 0 #define LAYOUT_MODE_NONE 0
#define LAYOUT_MODE_SPLIT_VERTICAL 1 #define LAYOUT_MODE_SPLIT_VERTICAL 1
#define LAYOUT_MODE_SPLIT_HORIZONTAL 2 #define LAYOUT_MODE_SPLIT_HORIZONTAL 2
#define LAYOUT_MODE_SPLIT_AUTO 3
#define ROTATION_VERTICAL_BUTTON_UP 0
#define ROTATION_HORIZONTAL_BUTTON_RIGHT 1
#define ROTATION_VERTICAL_BUTTON_DOWN 2
#define ROTATION_HORIZONTAL_BUTTON_LEFT 3
int UI(int pid, unsigned int signal); int UI(int pid, unsigned int signal);
int UI_create_window(void (*callback)(int, int, int, int, int), int parent = 0, int zorder = 0, bool placeholder = false); int UI_create_window(void (*callback)(int, int, int, int, int), int parent = 0, int zorder = 0);
int UI_create_window(int parent = 0, int zorder = 0);
void UI_set_layout_mode(int hwnd, int layout_mode); void UI_set_layout_mode(int hwnd, int layout_mode);

Loading…
Cancel
Save