parent
1a2cc21fbb
commit
6db58e14a7
@ -1,15 +1,16 @@ |
|||||||
set(COMPONENT_SRCS |
set(COMPONENT_SRCS |
||||||
"app_main.c" |
"app_main.c" |
||||||
"knob.c" |
"knob.c" |
||||||
"gui.c" |
"liquid/gui.c" |
||||||
"analog.c" |
"analog.c" |
||||||
"liquid/liquid.c" |
"liquid/liquid.c" |
||||||
"liquid/scene_root.c" |
"scenes/scene_root.c" |
||||||
"liquid/scene_car.c" |
"scenes/scene_car.c" |
||||||
"graphics/nokia.c" |
"graphics/nokia.c" |
||||||
"graphics/utf8.c" |
"graphics/utf8.c" |
||||||
"graphics/font.c" |
"graphics/font.c" |
||||||
|
"graphics/drawing.c" |
||||||
) |
) |
||||||
set(COMPONENT_ADD_INCLUDEDIRS "liquid" "graphics") |
set(COMPONENT_ADD_INCLUDEDIRS "." "liquid" "graphics") |
||||||
|
|
||||||
register_component() |
register_component() |
||||||
|
@ -0,0 +1,13 @@ |
|||||||
|
/**
|
||||||
|
* TODO file description |
||||||
|
*
|
||||||
|
* Created on 2020/01/05. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef REFLOWER_DISPLAY_SPEC_H |
||||||
|
#define REFLOWER_DISPLAY_SPEC_H |
||||||
|
|
||||||
|
#define LCD_WIDTH 84 // Note: x-coordinates go wide
|
||||||
|
#define LCD_HEIGHT 48 // Note: y-coordinates go high
|
||||||
|
|
||||||
|
#endif //REFLOWER_DISPLAY_SPEC_H
|
@ -0,0 +1,313 @@ |
|||||||
|
#include "drawing.h" |
||||||
|
#include "display_spec.h" |
||||||
|
#include "font.h" |
||||||
|
|
||||||
|
extern uint8_t LCD_displayMap[LCD_WIDTH * LCD_HEIGHT / 8]; |
||||||
|
|
||||||
|
// This function sets a pixel on displayMap to your preferred
|
||||||
|
// color. 1=Black, 0= white.
|
||||||
|
void LCD_setPixel(int x, int y, enum Color bw) |
||||||
|
{ |
||||||
|
// First, double check that the coordinate is in range.
|
||||||
|
if ((x >= 0) && (x < LCD_WIDTH) && (y >= 0) && (y < LCD_HEIGHT)) { |
||||||
|
uint8_t shift = y % 8; |
||||||
|
|
||||||
|
if (bw) // If black, set the bit.
|
||||||
|
LCD_displayMap[x + (y / 8) * LCD_WIDTH] |= 1 << shift; |
||||||
|
else // If white clear the bit.
|
||||||
|
LCD_displayMap[x + (y / 8) * LCD_WIDTH] &= ~(1 << shift); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// setLine draws a line from x0,y0 to x1,y1 with the set color.
|
||||||
|
// This function was grabbed from the SparkFun ColorLCDShield
|
||||||
|
// library.
|
||||||
|
void LCD_setLine(int x0, int y0, int x1, int y1, enum Color bw) |
||||||
|
{ |
||||||
|
int dy = y1 - y0; // Difference between y0 and y1
|
||||||
|
int dx = x1 - x0; // Difference between x0 and x1
|
||||||
|
int stepx, stepy; |
||||||
|
|
||||||
|
if (dy < 0) { |
||||||
|
dy = -dy; |
||||||
|
stepy = -1; |
||||||
|
} |
||||||
|
else |
||||||
|
stepy = 1; |
||||||
|
|
||||||
|
if (dx < 0) { |
||||||
|
dx = -dx; |
||||||
|
stepx = -1; |
||||||
|
} |
||||||
|
else |
||||||
|
stepx = 1; |
||||||
|
|
||||||
|
dy <<= 1; // dy is now 2*dy
|
||||||
|
dx <<= 1; // dx is now 2*dx
|
||||||
|
LCD_setPixel(x0, y0, bw); // Draw the first pixel.
|
||||||
|
|
||||||
|
if (dx > dy) { |
||||||
|
int fraction = dy - (dx >> 1); |
||||||
|
while (x0 != x1) { |
||||||
|
if (fraction >= 0) { |
||||||
|
y0 += stepy; |
||||||
|
fraction -= dx; |
||||||
|
} |
||||||
|
x0 += stepx; |
||||||
|
fraction += dy; |
||||||
|
LCD_setPixel(x0, y0, bw); |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
int fraction = dx - (dy >> 1); |
||||||
|
while (y0 != y1) { |
||||||
|
if (fraction >= 0) { |
||||||
|
x0 += stepx; |
||||||
|
fraction -= dy; |
||||||
|
} |
||||||
|
y0 += stepy; |
||||||
|
fraction += dx; |
||||||
|
LCD_setPixel(x0, y0, bw); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// setRect will draw a rectangle from x0,y0 top-left corner to
|
||||||
|
// a x1,y1 bottom-right corner. Can be filled with the fill
|
||||||
|
// parameter, and colored with bw.
|
||||||
|
// This function was grabbed from the SparkFun ColorLCDShield
|
||||||
|
// library.
|
||||||
|
void LCD_setRect(int x0, int y0, int x1, int y1, bool fill, enum Color bw) |
||||||
|
{ |
||||||
|
// check if the rectangle is to be filled
|
||||||
|
if (fill == 1) { |
||||||
|
int xDiff; |
||||||
|
|
||||||
|
if (x0 > x1) |
||||||
|
xDiff = x0 - x1; //Find the difference between the x vars
|
||||||
|
else |
||||||
|
xDiff = x1 - x0; |
||||||
|
|
||||||
|
while (xDiff > 0) { |
||||||
|
LCD_setLine(x0, y0, x0, y1, bw); |
||||||
|
|
||||||
|
if (x0 > x1) |
||||||
|
x0--; |
||||||
|
else |
||||||
|
x0++; |
||||||
|
|
||||||
|
xDiff--; |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
// best way to draw an unfilled rectangle is to draw four lines
|
||||||
|
LCD_setLine(x0, y0, x1, y0, bw); |
||||||
|
LCD_setLine(x0, y1, x1, y1, bw); |
||||||
|
LCD_setLine(x0, y0, x0, y1, bw); |
||||||
|
LCD_setLine(x1, y0, x1, y1, bw); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// setCircle draws a circle centered around x0,y0 with a defined
|
||||||
|
// radius. The circle can be black or white. And have a line
|
||||||
|
// thickness ranging from 1 to the radius of the circle.
|
||||||
|
// This function was grabbed from the SparkFun ColorLCDShield
|
||||||
|
// library.
|
||||||
|
void LCD_setCircle(int x0, int y0, int radius, enum Color bw, int lineThickness) |
||||||
|
{ |
||||||
|
for (int r = 0; r < lineThickness; r++) { |
||||||
|
int f = 1 - radius; |
||||||
|
int ddF_x = 0; |
||||||
|
int ddF_y = -2 * radius; |
||||||
|
int x = 0; |
||||||
|
int y = radius; |
||||||
|
|
||||||
|
LCD_setPixel(x0, y0 + radius, bw); |
||||||
|
LCD_setPixel(x0, y0 - radius, bw); |
||||||
|
LCD_setPixel(x0 + radius, y0, bw); |
||||||
|
LCD_setPixel(x0 - radius, y0, bw); |
||||||
|
|
||||||
|
while (x < y) { |
||||||
|
if (f >= 0) { |
||||||
|
y--; |
||||||
|
ddF_y += 2; |
||||||
|
f += ddF_y; |
||||||
|
} |
||||||
|
x++; |
||||||
|
ddF_x += 2; |
||||||
|
f += ddF_x + 1; |
||||||
|
|
||||||
|
LCD_setPixel(x0 + x, y0 + y, bw); |
||||||
|
LCD_setPixel(x0 - x, y0 + y, bw); |
||||||
|
LCD_setPixel(x0 + x, y0 - y, bw); |
||||||
|
LCD_setPixel(x0 - x, y0 - y, bw); |
||||||
|
LCD_setPixel(x0 + y, y0 + x, bw); |
||||||
|
LCD_setPixel(x0 - y, y0 + x, bw); |
||||||
|
LCD_setPixel(x0 + y, y0 - x, bw); |
||||||
|
LCD_setPixel(x0 - y, y0 - x, bw); |
||||||
|
} |
||||||
|
radius--; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// This function will draw a char (defined in the ASCII table
|
||||||
|
// near the beginning of this sketch) at a defined x and y).
|
||||||
|
// The color can be either black (1) or white (0).
|
||||||
|
void LCD_setChar(struct Utf8Char character, int x, int y, enum Color bw) |
||||||
|
{ |
||||||
|
LCD_setCharEx(character, x, y, bw, 1); |
||||||
|
} |
||||||
|
|
||||||
|
void LCD_setCharEx(struct Utf8Char character, int x, int y, enum Color bw, uint8_t style) |
||||||
|
{ |
||||||
|
const struct FontGraphic *symbol = Font_GetSymbol(character); |
||||||
|
bool bg = style & 0x80; |
||||||
|
enum FontStyle style_real = style & 0x7F; |
||||||
|
|
||||||
|
uint8_t column; // temp byte to store character's column bitmap
|
||||||
|
for (int i = 0; i < 5; i++) // 5 columns (x) per character
|
||||||
|
{ |
||||||
|
column = symbol->columns[i]; |
||||||
|
for (int j = 0; j < 8; j++) // 8 rows (y) per character
|
||||||
|
{ |
||||||
|
bool bit = column & (1 << j); |
||||||
|
|
||||||
|
if (style_real == FONT_NORMAL) { |
||||||
|
if (bit) {// test bits to set pixels
|
||||||
|
LCD_setPixel(x + i, y + j, bw); |
||||||
|
} |
||||||
|
else if (bg) { |
||||||
|
LCD_setPixel(x + i, y + j, !bw); |
||||||
|
} |
||||||
|
} |
||||||
|
else if (style_real == FONT_DOUBLE) { |
||||||
|
if (bit) {// test bits to set pixels
|
||||||
|
LCD_setPixel(x + i * 2, y + j * 2, bw); |
||||||
|
LCD_setPixel(x + i * 2 + 1, y + j * 2, bw); |
||||||
|
LCD_setPixel(x + i * 2, y + j * 2 + 1, bw); |
||||||
|
LCD_setPixel(x + i * 2 + 1, y + j * 2 + 1, bw); |
||||||
|
} |
||||||
|
else if (bg) { |
||||||
|
LCD_setPixel(x + i * 2, y + j * 2, !bw); |
||||||
|
LCD_setPixel(x + i * 2 + 1, y + j * 2, !bw); |
||||||
|
LCD_setPixel(x + i * 2, y + j * 2 + 1, !bw); |
||||||
|
LCD_setPixel(x + i * 2 + 1, y + j * 2 + 1, !bw); |
||||||
|
} |
||||||
|
} |
||||||
|
else if (style_real == FONT_BOLD) { |
||||||
|
if (bit) {// test bits to set pixels
|
||||||
|
LCD_setPixel(x + i, y + j, bw); |
||||||
|
LCD_setPixel(x + i + 1, y + j, bw); |
||||||
|
} |
||||||
|
else if (bg) { |
||||||
|
LCD_setPixel(x + i, y + j, !bw); |
||||||
|
LCD_setPixel(x + i + 1, y + j, !bw); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// setStr draws a string of characters, calling setChar with
|
||||||
|
// progressive coordinates until it's done.
|
||||||
|
// This function was grabbed from the SparkFun ColorLCDShield
|
||||||
|
// library.
|
||||||
|
void LCD_setStr(const char *dString, int x, int y, enum Color bw) |
||||||
|
{ |
||||||
|
LCD_setStrEx(dString, x, y, bw, 1); |
||||||
|
} |
||||||
|
|
||||||
|
// setStr draws a string of characters, calling setChar with
|
||||||
|
// progressive coordinates until it's done.
|
||||||
|
// This function was grabbed from the SparkFun ColorLCDShield
|
||||||
|
// library.
|
||||||
|
void LCD_setStrEx(const char *dString, int x, int y, enum Color bw, uint8_t style) |
||||||
|
{ |
||||||
|
struct Utf8Iterator iter; |
||||||
|
Utf8Iterator_Init(&iter, dString); |
||||||
|
bool bg = style & 0x80; |
||||||
|
enum FontStyle style_real = style & 0x7F; |
||||||
|
|
||||||
|
struct Utf8Char uchar; |
||||||
|
while ((uchar = Utf8Iterator_Next(&iter)).uint) { |
||||||
|
LCD_setCharEx(uchar, x, y, bw, style); |
||||||
|
|
||||||
|
if (style_real == FONT_NORMAL) { |
||||||
|
x += 5; |
||||||
|
if (bg) { |
||||||
|
for (int i = y; i < y + 8; i++) { |
||||||
|
LCD_setPixel(x, i, !bw); |
||||||
|
} |
||||||
|
} |
||||||
|
x++; |
||||||
|
if (x > (LCD_WIDTH - 5)) // Enables wrap around
|
||||||
|
{ |
||||||
|
x = 0; |
||||||
|
y += 8; |
||||||
|
} |
||||||
|
} |
||||||
|
else if (style_real == FONT_DOUBLE) { |
||||||
|
x += 10; |
||||||
|
if (bg) { |
||||||
|
for (int i = y; i < y + 16; i++) { |
||||||
|
LCD_setPixel(x, i, !bw); |
||||||
|
LCD_setPixel(x + 1, i, !bw); |
||||||
|
} |
||||||
|
} |
||||||
|
x += 2; |
||||||
|
if (x > (LCD_WIDTH - 10)) // Enables wrap around
|
||||||
|
{ |
||||||
|
x = 0; |
||||||
|
y += 16; |
||||||
|
} |
||||||
|
} |
||||||
|
else if (style_real == FONT_BOLD) { |
||||||
|
x += 6; |
||||||
|
if (bg) { |
||||||
|
for (int i = y; i < y + 8; i++) { |
||||||
|
LCD_setPixel(x, i, !bw); |
||||||
|
LCD_setPixel(x + 1, i, !bw); |
||||||
|
} |
||||||
|
} |
||||||
|
x += 1; |
||||||
|
if (x > (LCD_WIDTH - 6)) // Enables wrap around
|
||||||
|
{ |
||||||
|
x = 0; |
||||||
|
y += 8; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// This function will draw an array over the screen. (For now) the
|
||||||
|
// array must be the same size as the screen, covering the entirety
|
||||||
|
// of the display.
|
||||||
|
// Also, the array must reside in FLASH and declared with PROGMEM.
|
||||||
|
void LCD_setBitmap(const char *bitArray) |
||||||
|
{ |
||||||
|
for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) { |
||||||
|
char c = bitArray[i]; |
||||||
|
LCD_displayMap[i] = c; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// This function clears the entire display either white (0) or
|
||||||
|
// black (1).
|
||||||
|
// The screen won't actually clear until you call updateDisplay()!
|
||||||
|
void LCD_clearDisplay(enum Color bw) |
||||||
|
{ |
||||||
|
for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) { |
||||||
|
if (bw) |
||||||
|
LCD_displayMap[i] = 0xFF; |
||||||
|
else |
||||||
|
LCD_displayMap[i] = 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void LCD_invertDisplayData() |
||||||
|
{ |
||||||
|
/* Indirect, swap bits in displayMap option: */ |
||||||
|
for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) { |
||||||
|
LCD_displayMap[i] ^= 0xFF; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
/**
|
||||||
|
* TODO file description |
||||||
|
*
|
||||||
|
* Created on 2020/01/05. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef REFLOWER_DRAWING_H |
||||||
|
#define REFLOWER_DRAWING_H |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
#include <stdbool.h> |
||||||
|
|
||||||
|
#include "utf8.h" |
||||||
|
|
||||||
|
enum Color { |
||||||
|
WHITE = 0, |
||||||
|
BLACK = 1, |
||||||
|
}; |
||||||
|
|
||||||
|
// This function sets a pixel on displayMap to your preferred
|
||||||
|
// color. 1=Black, 0= white.
|
||||||
|
void LCD_setPixel(int x, int y, enum Color bw); |
||||||
|
|
||||||
|
// setLine draws a line from x0,y0 to x1,y1 with the set color
|
||||||
|
void LCD_setLine(int x0, int y0, int x1, int y1, enum Color bw); |
||||||
|
|
||||||
|
// setRect will draw a rectangle from x0,y0 top-left corner to
|
||||||
|
// a x1,y1 bottom-right corner. Can be filled with the fill
|
||||||
|
// parameter, and colored with bw.
|
||||||
|
void LCD_setRect(int x0, int y0, int x1, int y1, bool fill, enum Color bw); |
||||||
|
|
||||||
|
// setCircle draws a circle centered around x0,y0 with a defined
|
||||||
|
// radius. The circle can be black or white. And have a line
|
||||||
|
// thickness ranging from 1 to the radius of the circle.
|
||||||
|
void LCD_setCircle (int x0, int y0, int radius, enum Color bw, int lineThickness); |
||||||
|
|
||||||
|
/*
|
||||||
|
FONT FUNCTIONS |
||||||
|
size = 1 ... normal |
||||||
|
size = 2 ... 2x |
||||||
|
size = 3 ... normal bold |
||||||
|
size | 0x80 ... clear background behind characters |
||||||
|
*/ |
||||||
|
|
||||||
|
enum FontStyle { |
||||||
|
FONT_NORMAL = 1, |
||||||
|
FONT_DOUBLE = 2, |
||||||
|
FONT_BOLD = 3, |
||||||
|
FONT_BG = 0x80, |
||||||
|
}; |
||||||
|
|
||||||
|
// This function will draw a char (defined in the ASCII table
|
||||||
|
// near the beginning of this sketch) at a defined x and y).
|
||||||
|
// The color can be either black (1) or white (0).
|
||||||
|
void LCD_setChar(struct Utf8Char character, int x, int y, enum Color bw); |
||||||
|
|
||||||
|
void LCD_setCharEx(struct Utf8Char character, int x, int y, enum Color bw, uint8_t style); |
||||||
|
|
||||||
|
// setStr draws a string of characters, calling setChar with
|
||||||
|
// progressive coordinates until it's done.
|
||||||
|
// This function was grabbed from the SparkFun ColorLCDShield
|
||||||
|
// library.
|
||||||
|
void LCD_setStr(const char * dString, int x, int y, enum Color bw); |
||||||
|
|
||||||
|
void LCD_setStrEx(const char *dString, int x, int y, enum Color bw, uint8_t style); |
||||||
|
|
||||||
|
// This function clears the entire display either white (0) or
|
||||||
|
// black (1).
|
||||||
|
// The screen won't actually clear until you call updateDisplay()!
|
||||||
|
void LCD_clearDisplay(enum Color bw); |
||||||
|
|
||||||
|
/* Invert colors (hard change in data; does NOT send to display immediately) */ |
||||||
|
void LCD_invertDisplayData(); |
||||||
|
|
||||||
|
#endif //REFLOWER_DRAWING_H
|
@ -1,24 +1,20 @@ |
|||||||
/**
|
/**
|
||||||
* TODO file description |
* UTF-8 capable bitmap font |
||||||
*
|
*
|
||||||
* Created on 2020/01/04. |
* Created on 2020/01/04. |
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifndef REFLOWER_FONT_H |
#ifndef GFX_FONT_H |
||||||
#define REFLOWER_FONT_H |
#define GFX_FONT_H |
||||||
|
|
||||||
#include "font.h" |
#include "font.h" |
||||||
#include "utf8.h" |
#include "utf8.h" |
||||||
#include <stdint.h> |
#include <stdint.h> |
||||||
|
|
||||||
struct FontSymbol { |
struct FontGraphic { |
||||||
union { |
uint8_t columns[5]; |
||||||
const char symbol[4]; |
|
||||||
const uint32_t uint; |
|
||||||
}; |
|
||||||
uint8_t graphic[5]; |
|
||||||
}; |
}; |
||||||
|
|
||||||
const struct FontSymbol *Font_GetSymbol(struct Utf8Char ch); |
const struct FontGraphic *Font_GetSymbol(struct Utf8Char ch); |
||||||
|
|
||||||
#endif //REFLOWER_FONT_H
|
#endif //GFX_FONT_H
|
||||||
|
@ -0,0 +1,51 @@ |
|||||||
|
/**
|
||||||
|
* Input event structural enum |
||||||
|
*
|
||||||
|
* Created on 2020/01/05. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef LIQUID_INPUT_EVENT_H |
||||||
|
#define LIQUID_INPUT_EVENT_H |
||||||
|
|
||||||
|
enum InputEvent_Kind { |
||||||
|
InputEventKind_Wheel, |
||||||
|
InputEventKind_Button, |
||||||
|
}; |
||||||
|
|
||||||
|
struct InputEvent { |
||||||
|
enum InputEvent_Kind kind; |
||||||
|
union { |
||||||
|
struct { |
||||||
|
// Wheel delta
|
||||||
|
int32_t delta; |
||||||
|
} wheel; |
||||||
|
struct { |
||||||
|
// Button state
|
||||||
|
bool state; |
||||||
|
} button; |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
static inline struct InputEvent InputEvent_Wheel(int32_t delta) |
||||||
|
{ |
||||||
|
return (struct InputEvent) { |
||||||
|
.kind = InputEventKind_Wheel, |
||||||
|
.wheel = {.delta = delta} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* Button event (push, release) |
||||||
|
* |
||||||
|
* @param state - pushed |
||||||
|
* @return event |
||||||
|
*/ |
||||||
|
static inline struct InputEvent InputEvent_Button(bool state) |
||||||
|
{ |
||||||
|
return (struct InputEvent) { |
||||||
|
.kind = InputEventKind_Button, |
||||||
|
.button = {.state = state}, |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
#endif //LIQUID_INPUT_EVENT_H
|
@ -0,0 +1,99 @@ |
|||||||
|
/**
|
||||||
|
* Scene event structural enum |
||||||
|
*
|
||||||
|
* Created on 2020/01/05. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef LIQUID_SCENE_EVENT_H |
||||||
|
#define LIQUID_SCENE_EVENT_H |
||||||
|
|
||||||
|
// forward declaration
|
||||||
|
struct Scene; |
||||||
|
|
||||||
|
enum SceneEvent_Kind { |
||||||
|
SceneEventKind_Close, |
||||||
|
SceneEventKind_OpenChild, |
||||||
|
SceneEventKind_RequestRepaint, |
||||||
|
SceneEventKind_None, |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Scene event, returned from some scene methods. |
||||||
|
* |
||||||
|
* Use the constructor functions to create this struct. |
||||||
|
*/ |
||||||
|
struct SceneEvent { |
||||||
|
/** Event kind enum */ |
||||||
|
enum SceneEvent_Kind kind; |
||||||
|
union { |
||||||
|
/* data for Close event kind */ |
||||||
|
struct { |
||||||
|
// Status code
|
||||||
|
int32_t status; |
||||||
|
// Return data on heap
|
||||||
|
void *data; |
||||||
|
} close; |
||||||
|
/* Data for Open event kind */ |
||||||
|
struct { |
||||||
|
// Scene (initialized, with options loaded in through the constructor)
|
||||||
|
struct Scene *scene; |
||||||
|
// Tag used by parent to identify the open child
|
||||||
|
uint32_t tag; |
||||||
|
} open; |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Create empty (null object) scene event. |
||||||
|
* |
||||||
|
* @return event |
||||||
|
*/ |
||||||
|
static inline struct SceneEvent SceneEvent_None(void) |
||||||
|
{ |
||||||
|
return (struct SceneEvent) { |
||||||
|
.kind = SceneEventKind_None, |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* Request scene repaint |
||||||
|
* |
||||||
|
* @return event |
||||||
|
*/ |
||||||
|
static inline struct SceneEvent SceneEvent_Repaint(void) |
||||||
|
{ |
||||||
|
return (struct SceneEvent) { |
||||||
|
.kind = SceneEventKind_RequestRepaint |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* Request a sub-scene to be opened |
||||||
|
* |
||||||
|
* @param child - child scene |
||||||
|
* @param tag - scene tag |
||||||
|
* @return event |
||||||
|
*/ |
||||||
|
static inline struct SceneEvent SceneEvent_OpenChild(struct Scene *child, uint32_t tag) { |
||||||
|
return (struct SceneEvent) { |
||||||
|
.kind = SceneEventKind_OpenChild, |
||||||
|
.open = { .scene = child, .tag=tag }, |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* Close this scene, returning to parent. |
||||||
|
* |
||||||
|
* @param status - status number for the parent |
||||||
|
* @param data - heap-allocated data for parent, can be NULL; e.g. user input as string. |
||||||
|
* @return event |
||||||
|
*/ |
||||||
|
static inline struct SceneEvent SceneEvent_Close(int32_t status, void *data) |
||||||
|
{ |
||||||
|
return (struct SceneEvent) { |
||||||
|
.kind = SceneEventKind_Close, |
||||||
|
.close = {.status = status, .data=data}, |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
#endif //LIQUID_SCENE_EVENT_H
|
@ -0,0 +1,105 @@ |
|||||||
|
/**
|
||||||
|
* Scene struct |
||||||
|
*
|
||||||
|
* Created on 2020/01/05. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef LIQUID_SCENE_TYPE_H |
||||||
|
#define LIQUID_SCENE_TYPE_H |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
|
||||||
|
struct Scene; |
||||||
|
struct InputEvent; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Scene::onInput fp type - handle user input |
||||||
|
* |
||||||
|
* @param scene - self |
||||||
|
* @param event - the input event |
||||||
|
* @return follow-up scene event, can be SceneEvent_None() if not used. |
||||||
|
*/ |
||||||
|
typedef struct SceneEvent (*Scene_onInput_t)(struct Scene *scene, struct InputEvent event); |
||||||
|
|
||||||
|
/**
|
||||||
|
* Scene::onChildReturn fp type |
||||||
|
* |
||||||
|
* @param scene - self |
||||||
|
* @param tag - child's tag |
||||||
|
* @param status - status code returned from the child |
||||||
|
* @param data - data returned from the child, must be heap-allocated if not NULL. |
||||||
|
* @return follow-up scene event, can be SceneEvent_None() if not used. |
||||||
|
*/ |
||||||
|
typedef struct SceneEvent (*Scene_onChildReturn_t)(struct Scene *scene, uint32_t tag, int32_t status, void *data); |
||||||
|
|
||||||
|
/**
|
||||||
|
* Scene::onTick fp type |
||||||
|
* |
||||||
|
* @param scene - self |
||||||
|
* @return follow-up scene event, can be SceneEvent_None() if not used. |
||||||
|
*/ |
||||||
|
typedef struct SceneEvent (*Scene_onTick_t)(struct Scene *scene); |
||||||
|
|
||||||
|
/**
|
||||||
|
* Scene::paint fp type |
||||||
|
* |
||||||
|
* @param scene - self |
||||||
|
*/ |
||||||
|
typedef void (*Scene_paint_t)(struct Scene *scene); |
||||||
|
|
||||||
|
/**
|
||||||
|
* Scene::free fp type. |
||||||
|
* Release internally allocated resources. |
||||||
|
* This is called by the GUI engine when the scene is closed. |
||||||
|
* |
||||||
|
* @param scene - self |
||||||
|
*/ |
||||||
|
typedef void (*Scene_free_t)(struct Scene *scene); |
||||||
|
|
||||||
|
/**
|
||||||
|
* Scene instance in the framework |
||||||
|
*/ |
||||||
|
struct Scene { |
||||||
|
/**
|
||||||
|
* Tag given to the scene by its parent to identify its close event. |
||||||
|
*/ |
||||||
|
uint32_t tag; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle input event. |
||||||
|
* Can return a follow-up scene event, e.g. repaint request. |
||||||
|
* Nullable field. |
||||||
|
*/ |
||||||
|
Scene_onInput_t onInput; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Child scene closed, handle its return value and data, if any. |
||||||
|
* Can return a follow-up scene event. |
||||||
|
* In any case, the scene will be re-painted, if it stays open and on top. |
||||||
|
* Nullable field. |
||||||
|
*/ |
||||||
|
Scene_onChildReturn_t onChildReturn; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a periodic tick (10ms). |
||||||
|
* Can return a follow-up scene event, e.g. repaint request. |
||||||
|
* Nullable field. |
||||||
|
*/ |
||||||
|
Scene_onTick_t onTick; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw the scene to the LCD buffer. |
||||||
|
* DO NOT write to the display yet, it will be done by the GUI engine. |
||||||
|
* |
||||||
|
* MANDATORY FIELD |
||||||
|
*/ |
||||||
|
Scene_paint_t paint; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Release internally allocated resources, if any. Called on close. |
||||||
|
* Nullable field. |
||||||
|
*/ |
||||||
|
Scene_free_t free; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif //LIQUID_SCENE_TYPE_H
|
@ -1,7 +1,8 @@ |
|||||||
#include "scenes.h" |
#include "scenes.h" |
||||||
#include "liquid.h" |
#include "liquid.h" |
||||||
#include "../graphics/nokia.h" |
|
||||||
#include <malloc.h> |
#include <malloc.h> |
||||||
|
#include "graphics/nokia.h" |
||||||
|
#include "graphics/drawing.h" |
||||||
|
|
||||||
struct CarScene { |
struct CarScene { |
||||||
struct Scene base; |
struct Scene base; |
@ -1,10 +1,12 @@ |
|||||||
#include "scenes.h" |
|
||||||
#include "liquid.h" |
|
||||||
#include "../graphics/nokia.h" |
|
||||||
#include "../analog.h" |
|
||||||
#include <malloc.h> |
#include <malloc.h> |
||||||
#include <stdio.h> |
#include <stdio.h> |
||||||
|
|
||||||
|
#include "scenes.h" |
||||||
|
#include "liquid.h" |
||||||
|
#include "analog.h" |
||||||
|
#include "graphics/nokia.h" |
||||||
|
#include "graphics/drawing.h" |
||||||
|
|
||||||
/**
|
/**
|
||||||
* The struct is allocated bigger than 'Scene' to accommodate private fields. |
* The struct is allocated bigger than 'Scene' to accommodate private fields. |
||||||
* Since the base struct is located at the beginning, it can be cast and passed around as Scene. |
* Since the base struct is located at the beginning, it can be cast and passed around as Scene. |
Loading…
Reference in new issue