feat(color): Generate layout icon bitmap at runtime to account for screen orientation (#3282)

* Simplify layouts code, use data driven layout definition.
Generate icon bitmap at runtime to account for screen orientation.
Move old layout png images to companion folder (still used in companion).

* Align buffer for bitmap.

* Use 'free' instead 'delete' for bitmap buffer to avoid failed build test.
This commit is contained in:
philmoz
2023-03-05 11:36:56 +10:00
committed by GitHub
parent 5b45b7ce2c
commit b8220e5be4
30 changed files with 219 additions and 496 deletions
+13 -13
View File
@@ -1275,18 +1275,18 @@
<file>themes/yerico/48/sdsync.png</file>
</qresource>
<qresource prefix="/layouts/">
<file alias="mask_layout1p2.png">../../radio/src/gui/colorlcd/layouts/mask_layout1+2.png</file>
<file alias="mask_layout1p3.png">../../radio/src/gui/colorlcd/layouts/mask_layout1+3.png</file>
<file alias="mask_layout1x1.png">../../radio/src/gui/colorlcd/layouts/mask_layout1x1.png</file>
<file alias="mask_layout1x2.png">../../radio/src/gui/colorlcd/layouts/mask_layout1x2.png</file>
<file alias="mask_layout1x3.png">../../radio/src/gui/colorlcd/layouts/mask_layout1x3.png</file>
<file alias="mask_layout1x4.png">../../radio/src/gui/colorlcd/layouts/mask_layout1x4.png</file>
<file alias="mask_layout2p1.png">../../radio/src/gui/colorlcd/layouts/mask_layout2+1.png</file>
<file alias="mask_layout2p3.png">../../radio/src/gui/colorlcd/layouts/mask_layout2+3.png</file>
<file alias="mask_layout2x1.png">../../radio/src/gui/colorlcd/layouts/mask_layout2x1.png</file>
<file alias="mask_layout2x2.png">../../radio/src/gui/colorlcd/layouts/mask_layout2x2.png</file>
<file alias="mask_layout2x3.png">../../radio/src/gui/colorlcd/layouts/mask_layout2x3.png</file>
<file alias="mask_layout2x4.png">../../radio/src/gui/colorlcd/layouts/mask_layout2x4.png</file>
<file alias="mask_layout4p2.png">../../radio/src/gui/colorlcd/layouts/mask_layout4+2.png</file>
<file alias="mask_layout1p2.png">images/layouts/mask_layout1+2.png</file>
<file alias="mask_layout1p3.png">images/layouts/mask_layout1+3.png</file>
<file alias="mask_layout1x1.png">images/layouts/mask_layout1x1.png</file>
<file alias="mask_layout1x2.png">images/layouts/mask_layout1x2.png</file>
<file alias="mask_layout1x3.png">images/layouts/mask_layout1x3.png</file>
<file alias="mask_layout1x4.png">images/layouts/mask_layout1x4.png</file>
<file alias="mask_layout2p1.png">images/layouts/mask_layout2+1.png</file>
<file alias="mask_layout2p3.png">images/layouts/mask_layout2+3.png</file>
<file alias="mask_layout2x1.png">images/layouts/mask_layout2x1.png</file>
<file alias="mask_layout2x2.png">images/layouts/mask_layout2x2.png</file>
<file alias="mask_layout2x3.png">images/layouts/mask_layout2x3.png</file>
<file alias="mask_layout2x4.png">images/layouts/mask_layout2x4.png</file>
<file alias="mask_layout4p2.png">images/layouts/mask_layout4+2.png</file>
</qresource>
</RCC>

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 201 B

After

Width:  |  Height:  |  Size: 201 B

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Before

Width:  |  Height:  |  Size: 182 B

After

Width:  |  Height:  |  Size: 182 B

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 207 B

After

Width:  |  Height:  |  Size: 207 B

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 196 B

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 196 B

-2
View File
@@ -20,7 +20,6 @@ add_bitmaps_target(${BITMAP_TARGET_PREFIX}_splash "${RADIO_SRC_DIR}/bitmaps/480x
add_bitmaps_target(${BITMAP_TARGET_PREFIX}_button_bitmaps "${RADIO_SRC_DIR}/bitmaps/480x272/button/alpha_*.png" "4/4/4/4" "${BITMAP_LZ4_ARGS}")
add_bitmaps_target(${BITMAP_TARGET_PREFIX}_masks "${RADIO_SRC_DIR}/bitmaps/480x272/mask_*.png" 8bits "${MASK_LZ4_ARGS}")
add_bitmaps_target(${BITMAP_TARGET_PREFIX}_slider_masks "${RADIO_SRC_DIR}/bitmaps/480x272/slider/*.png" 8bits "${MASK_LZ4_ARGS}")
add_bitmaps_target(${BITMAP_TARGET_PREFIX}_layouts_masks "${RADIO_SRC_DIR}/gui/colorlcd/layouts/*.png" 8bits "${MASK_LZ4_ARGS}")
add_bitmaps_target(${BITMAP_TARGET_PREFIX}_volume_masks ${RADIO_SRC_DIR}/bitmaps/480x272/volume/*.png 8bits "${MASK_LZ4_ARGS}")
add_bitmaps_target(${BITMAP_TARGET_PREFIX}_themes_masks "${RADIO_SRC_DIR}/bitmaps/480x272/default_theme/mask_*.png" 8bits "${MASK_LZ4_ARGS}")
add_bitmaps_target(${BITMAP_TARGET_PREFIX}_themes_alpha "${RADIO_SRC_DIR}/bitmaps/480x272/default_theme/alpha_*.png" "4/4/4/4" "${BITMAP_LZ4_ARGS}")
@@ -35,7 +34,6 @@ add_dependencies(${BITMAP_TARGET_PREFIX}_bitmaps
${BITMAP_TARGET_PREFIX}_button_bitmaps
${BITMAP_TARGET_PREFIX}_masks
${BITMAP_TARGET_PREFIX}_slider_masks
${BITMAP_TARGET_PREFIX}_layouts_masks
${BITMAP_TARGET_PREFIX}_themes_masks
${BITMAP_TARGET_PREFIX}_themes_alpha
${BITMAP_TARGET_PREFIX}_volume_masks
+7 -36
View File
@@ -21,42 +21,13 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_1P2[] = {
#include "mask_layout1+2.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_1P2);
const ZoneOption OPTIONS_LAYOUT_1P2[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
class Layout1P2 : public Layout
{
public:
Layout1P2(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 3; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
if (index == 0) {
return {zone.x, zone.y, zone.w, zone.h / 2};
} else if (index == 1) {
return {zone.x, zone.y + zone.h / 2, zone.w, zone.h / 4};
} else {
return {zone.x, zone.y + zone.h * 3 / 4, zone.w, zone.h / 4};
}
return zone;
}
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_HALF,
LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_3QTR, LAYOUT_MAP_FULL, LAYOUT_MAP_1QTR,
};
BaseLayoutFactory<Layout1P2> Layout1P2("Layout1P2", "1 + 2", LBM_LAYOUT_1P2,
OPTIONS_LAYOUT_1P2);
BaseLayoutFactory<Layout> Layout1P2("Layout1P2", "1 + 2",
defaultZoneOptions,
3, zmap);
+8 -45
View File
@@ -21,51 +21,14 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_1P3[] = {
#include "mask_layout1+3.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_1P3);
const ZoneOption OPTIONS_LAYOUT_1P3[] = {
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL,
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_HALF, LAYOUT_MAP_2THIRD, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
};
class Layout1P3 : public Layout
{
public:
Layout1P3(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 4; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
zone.w /= 2;
if (index == 0) {
if (isMirrored()) {
zone.x += zone.w;
}
} else {
index--;
zone.h /= 3;
zone.y += zone.h * (int)index;
if (!isMirrored()) {
zone.x += zone.w;
}
}
return zone;
}
};
BaseLayoutFactory<Layout1P3> Layout1P3("Layout1P3", "1 + 3", LBM_LAYOUT_1P3,
OPTIONS_LAYOUT_1P3);
BaseLayoutFactory<Layout> Layout1P3("Layout1P3", "1 + 3",
defaultZoneOptions,
4, zmap);
+5 -23
View File
@@ -21,29 +21,11 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_1x1[] = {
#include "mask_layout1x1.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_1x1);
const ZoneOption OPTIONS_LAYOUT_1x1[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
class Layout1x1 : public Layout
{
public:
Layout1x1(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 1; }
rect_t getZone(unsigned int index) const override { return getMainZone(); }
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_FULL,
};
BaseLayoutFactory<Layout1x1> layout1x1("Layout1x1", STR_WIDGET_FULLSCREEN,
LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1);
BaseLayoutFactory<Layout> layout1x1("Layout1x1", STR_WIDGET_FULLSCREEN,
defaultZoneOptions,
1, zmap);
+6 -31
View File
@@ -21,37 +21,12 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_1x2[] = {
#include "mask_layout1x2.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_1x2);
const ZoneOption OPTIONS_LAYOUT_1x2[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
class Layout1x2 : public Layout
{
public:
Layout1x2(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 2; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
zone.h /= 2;
zone.y += zone.h * index;
return zone;
}
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_HALF,
LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL, LAYOUT_MAP_HALF,
};
BaseLayoutFactory<Layout1x2> Layout1x2("Layout1x2", "1 x 2", LBM_LAYOUT_1x2,
OPTIONS_LAYOUT_1x2);
BaseLayoutFactory<Layout> Layout1x2("Layout1x2", "1 x 2",
defaultZoneOptions,
2, zmap);
+7 -31
View File
@@ -21,37 +21,13 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_1x3[] = {
#include "mask_layout1x3.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_1x3);
const ZoneOption OPTIONS_LAYOUT_1x3[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
class Layout1x3 : public Layout
{
public:
Layout1x3(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 3; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
zone.h /= 3;
zone.y += zone.h * index;
return zone;
}
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_0, LAYOUT_MAP_1THIRD, LAYOUT_MAP_FULL, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_0, LAYOUT_MAP_2THIRD, LAYOUT_MAP_FULL, LAYOUT_MAP_1THIRD,
};
BaseLayoutFactory<Layout1x3> Layout1x3("Layout1x3", "1 x 3", LBM_LAYOUT_1x3,
OPTIONS_LAYOUT_1x3);
BaseLayoutFactory<Layout> Layout1x3("Layout1x3", "1 x 3",
defaultZoneOptions,
3, zmap);
+8 -35
View File
@@ -21,41 +21,14 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_1x4[] = {
#include "mask_layout1x4.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_1x4);
const ZoneOption OPTIONS_LAYOUT_1x4[] = {
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_FULL, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_1QTR, LAYOUT_MAP_FULL, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_3QTR, LAYOUT_MAP_FULL, LAYOUT_MAP_1QTR,
};
class Layout1x4 : public Layout
{
public:
Layout1x4(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 4; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
if (index > 3) {
index = 3;
}
return {zone.x, zone.y + zone.h / 4 * (int)index, zone.w, zone.h / 4};
return zone;
}
};
BaseLayoutFactory<Layout1x4> Layout1x4("Layout1x4", "1 x 4", LBM_LAYOUT_1x4,
OPTIONS_LAYOUT_1x4);
BaseLayoutFactory<Layout> Layout1x4("Layout1x4", "1 x 4",
defaultZoneOptions,
4, zmap);
+7 -40
View File
@@ -21,48 +21,15 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_2P1[] = {
#include "mask_layout2+1.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_2P1);
const ZoneOption OPTIONS_LAYOUT_2P1[] = {
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
static uint8_t zmap[] = {
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL, // ordered to match previous implementation
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
};
class Layout2P1 : public Layout
{
public:
Layout2P1(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
BaseLayoutFactory<Layout> layout2P1("Layout2P1", "2 + 1",
defaultZoneOptions,
3, zmap);
unsigned int getZonesCount() const override { return 3; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
if (index == 0) {
return {isMirrored() ? zone.x : zone.x + zone.w / 2, zone.y, zone.w / 2,
zone.h};
} else if (index == 1) {
return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y, zone.w / 2,
zone.h / 2};
} else {
return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y + zone.h / 2,
zone.w / 2, zone.h / 2};
}
return zone;
}
};
BaseLayoutFactory<Layout2P1> layout2P1("Layout2P1", "2 + 1", LBM_LAYOUT_2P1,
OPTIONS_LAYOUT_2P1);
const LayoutFactory* defaultLayout = &layout2P1;
+9 -47
View File
@@ -21,53 +21,15 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_2P3[] = {
#include "mask_layout2+3.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_2P3);
const ZoneOption OPTIONS_LAYOUT_2P3[] = {
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_HALF, LAYOUT_MAP_2THIRD, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
};
class Layout2P3 : public Layout
{
public:
Layout2P3(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 5; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
zone.w /= 2;
if (index == 0 || index == 1) {
zone.h /= 2;
if (index == 1) zone.y += zone.h;
if (isMirrored()) {
zone.x += zone.w;
}
} else {
index -= 2;
zone.h /= 3;
zone.y += zone.h * (int)index;
if (!isMirrored()) {
zone.x += zone.w;
}
}
return zone;
}
};
BaseLayoutFactory<Layout2P3> Layout2P3("Layout2P3", "2 + 3", LBM_LAYOUT_2P3,
OPTIONS_LAYOUT_2P3);
BaseLayoutFactory<Layout> Layout2P3("Layout2P3", "2 + 3",
defaultZoneOptions,
5, zmap);
+6 -38
View File
@@ -21,44 +21,12 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_2x1[] = {
#include "mask_layout2x1.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_2x1);
const ZoneOption OPTIONS_LAYOUT_2x1[] = {
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL,
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_FULL,
};
class Layout2x1 : public Layout
{
public:
Layout2x1(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 2; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
if (index == 0) {
return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y, zone.w / 2,
zone.h};
} else {
return {isMirrored() ? zone.x : zone.x + zone.w / 2, zone.y, zone.w / 2,
zone.h};
}
return zone;
}
};
BaseLayoutFactory<Layout2x1> Layout2x1("Layout2x1", "2 x 1", LBM_LAYOUT_2x1,
OPTIONS_LAYOUT_2x1);
BaseLayoutFactory<Layout> Layout2x1("Layout2x1", "2 x 1",
defaultZoneOptions,
2, zmap);
+8 -38
View File
@@ -21,44 +21,14 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_2x2[] = {
#include "mask_layout2x2.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_2x2);
const ZoneOption OPTIONS_LAYOUT_2x2[] = {
LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
};
class Layout2x2 : public Layout
{
public:
Layout2x2(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 4; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
zone.w /= 2;
zone.h /= 2;
if (index == 1 || index == 3) zone.y += zone.h;
if ((!isMirrored() && index > 1) || (isMirrored() && index < 2))
zone.x += zone.w;
return zone;
}
};
BaseLayoutFactory<Layout2x2> layout2x2("Layout2x2", "2 x 2", LBM_LAYOUT_2x2,
OPTIONS_LAYOUT_2x2);
BaseLayoutFactory<Layout> layout2x2("Layout2x2", "2 x 2",
defaultZoneOptions,
4, zmap);
+10 -39
View File
@@ -21,45 +21,16 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_2x3[] = {
#include "mask_layout2x3.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_2x3);
const ZoneOption OPTIONS_LAYOUT_2x3[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
class Layout2x3 : public Layout
{
public:
Layout2x3(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 6; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
zone.w /= 2;
zone.h /= 3;
if (index == 1 || index == 3)
zone.y += zone.h;
else if (index == 2 || index == 4)
zone.y += zone.h * 2;
if ((!isMirrored() && index > 2) || (isMirrored() && index < 3))
zone.x += zone.w;
return zone;
}
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_0, LAYOUT_MAP_1THIRD, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_0, LAYOUT_MAP_2THIRD, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_HALF, LAYOUT_MAP_2THIRD, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD,
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1THIRD, // ordered to match previous implementation
};
BaseLayoutFactory<Layout2x3> layout2x3("Layout2x3", "2 x 3", LBM_LAYOUT_2x3,
OPTIONS_LAYOUT_2x3);
BaseLayoutFactory<Layout> layout2x3("Layout2x3", "2 x 3",
defaultZoneOptions,
6, zmap);
+16 -28
View File
@@ -21,12 +21,6 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_2x4[] = {
#include "mask_layout2x4.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_2x4);
const ZoneOption OPTIONS_LAYOUT_2x4[] = {
LAYOUT_COMMON_OPTIONS,
@@ -48,8 +42,8 @@ class Layout2x4 : public Layout
};
Layout2x4(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
Layout::PersistentData* persistentData, uint8_t zoneCount, uint8_t* zoneMap) :
Layout(parent, factory, persistentData, zoneCount, zoneMap)
{
}
@@ -62,24 +56,6 @@ class Layout2x4 : public Layout
getOptionValue(OPTION_PANEL2_COLOR)->unsignedValue = RGB(77, 112, 203);
}
unsigned int getZonesCount() const override { return 8; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
zone.w /= 2;
zone.h /= 4;
if ((!isMirrored() && index > 3) || (isMirrored() && index < 4)) {
zone.x += zone.w;
}
zone.y += (index % 4) * zone.h;
return zone;
}
void paint(BitmapBuffer* dc) override;
};
@@ -102,5 +78,17 @@ void Layout2x4::paint(BitmapBuffer* dc)
}
}
BaseLayoutFactory<Layout2x4> layout2x4("Layout2x4", "2 x 4", LBM_LAYOUT_2x4,
OPTIONS_LAYOUT_2x4);
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_1QTR, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_3QTR, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_HALF, LAYOUT_MAP_3QTR, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
};
BaseLayoutFactory<Layout2x4> layout2x4("Layout2x4", "2 x 4",
OPTIONS_LAYOUT_2x4,
8, zmap);
+10 -41
View File
@@ -21,47 +21,16 @@
#include "layout.h"
#include "layout_factory_impl.h"
#include "lz4_bitmaps.h"
const uint8_t _LBM_LAYOUT_4P2[] = {
#include "mask_layout4+2.lbm"
};
STATIC_LZ4_BITMAP(LBM_LAYOUT_4P2);
const ZoneOption OPTIONS_LAYOUT_4P2[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
class Layout4P2 : public Layout
{
public:
Layout4P2(Window* parent, const LayoutFactory* factory,
Layout::PersistentData* persistentData) :
Layout(parent, factory, persistentData)
{
}
unsigned int getZonesCount() const override { return 6; }
rect_t getZone(unsigned int index) const override
{
rect_t zone = getMainZone();
zone.w /= 2;
if (index < 4) {
zone.h /= 4;
zone.y += (index % 4) * zone.h;
} else {
zone.h /= 2;
zone.y += (index % 2) * zone.h;
}
if ((!isMirrored() && index > 3) || (isMirrored() && index < 4)) {
zone.x += zone.w;
}
return zone;
}
static uint8_t zmap[] = {
LAYOUT_MAP_0, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_1QTR, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_0, LAYOUT_MAP_3QTR, LAYOUT_MAP_HALF, LAYOUT_MAP_1QTR,
LAYOUT_MAP_HALF, LAYOUT_MAP_0, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF, LAYOUT_MAP_HALF,
};
BaseLayoutFactory<Layout4P2> layout4P2("Layout4P2", "4 + 2", LBM_LAYOUT_4P2,
OPTIONS_LAYOUT_4P2);
BaseLayoutFactory<Layout> layout4P2("Layout4P2", "4 + 2",
defaultZoneOptions,
6, zmap);
@@ -24,10 +24,12 @@
#include "layouts/sliders.h"
#include "view_main.h"
Layout::Layout(Window* parent, const LayoutFactory * factory, PersistentData * persistentData):
Layout::Layout(Window* parent, const LayoutFactory * factory, PersistentData * persistentData, uint8_t zoneCount, uint8_t* zoneMap):
LayoutBase(parent, {0, 0, LCD_W, LCD_H}, persistentData),
factory(factory),
decoration(new ViewMainDecoration(this))
decoration(new ViewMainDecoration(this)),
zoneCount(zoneCount),
zoneMap(zoneMap)
{
adjustLayout();
}
@@ -129,3 +131,23 @@ rect_t Layout::getMainZone() const
return ViewMain::instance()->getMainZone(zone, hasTopbar());
}
rect_t Layout::getZone(unsigned int index) const
{
rect_t z = getMainZone();
unsigned int i = index * 4;
coord_t xo = z.w * zoneMap[i] / LAYOUT_MAP_DIV;
coord_t yo = z.h * zoneMap[i+1] / LAYOUT_MAP_DIV;
coord_t w = z.w * zoneMap[i+2] / LAYOUT_MAP_DIV;
coord_t h = z.h * zoneMap[i+3] / LAYOUT_MAP_DIV;
if (isMirrored())
xo = z.w - xo - w;
return { z.x + xo, z.y + yo, w, h };
}
const ZoneOption defaultZoneOptions[] = {LAYOUT_COMMON_OPTIONS,
LAYOUT_OPTIONS_END};
@@ -44,13 +44,25 @@
typedef WidgetsContainerImpl<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> LayoutBase;
extern const ZoneOption defaultZoneOptions[];
#define LAYOUT_MAP_DIV 60
#define LAYOUT_MAP_0 0
#define LAYOUT_MAP_1QTR 15
#define LAYOUT_MAP_1THIRD 20
#define LAYOUT_MAP_HALF 30
#define LAYOUT_MAP_2THIRD 40
#define LAYOUT_MAP_3QTR 45
#define LAYOUT_MAP_FULL 60
class Layout: public LayoutBase
{
friend class LayoutFactory;
public:
Layout(Window* parent, const LayoutFactory * factory, PersistentData * persistentData);
Layout(Window* parent, const LayoutFactory * factory, PersistentData * persistentData,
uint8_t zoneCount, uint8_t* zoneMap);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
@@ -104,6 +116,8 @@ class Layout: public LayoutBase
protected:
const LayoutFactory * factory = nullptr;
std::unique_ptr<ViewMainDecoration> decoration;
uint8_t zoneCount;
uint8_t* zoneMap = nullptr;
enum DecorationSettings {
DECORATION_NONE = 0x00,
@@ -123,17 +137,69 @@ class Layout: public LayoutBase
// Get the available space for widgets
rect_t getMainZone() const;
unsigned int getZonesCount() const override { return zoneCount; }
rect_t getZone(unsigned int index) const override;
};
#if LCD_W > LCD_H
#define BM_W 51
#define BM_H 25
#else
#define BM_W 22
#define BM_H 34
#endif
template<class T>
class BaseLayoutFactory: public LayoutFactory
{
public:
BaseLayoutFactory(const char * id, const char * name, const uint8_t * bitmap, const ZoneOption * options):
BaseLayoutFactory(const char * id, const char * name,
const ZoneOption * options, uint8_t zoneCount, uint8_t* zoneMap):
LayoutFactory(id, name),
bitmap(bitmap),
options(options)
options(options),
zoneCount(zoneCount),
zoneMap(zoneMap)
{
this->bitmap = (uint8_t*)malloc(align32(BM_W * BM_H + 2 * sizeof(uint16_t) + 4));
uint16_t* hdr = (uint16_t*)this->bitmap;
hdr[0] = BM_W;
hdr[1] = BM_H;
uint8_t* bm = (uint8_t*)(this->bitmap + 2 * sizeof(uint16_t));
memset(bm, 0, BM_W * BM_H);
memset(bm, 0xFF, BM_W);
memset(bm+((BM_H-1)*BM_W), 0xFF, BM_W);
for (int y = 1; y < BM_H - 1; y += 1) {
bm[y*BM_W] = 0xFF;
bm[y*BM_W+BM_W-1] = 0xFF;
}
for (int i = 0; i < zoneCount * 4; i += 4) {
uint8_t xo = BM_W * zoneMap[i] / LAYOUT_MAP_DIV;
uint8_t yo = BM_H * zoneMap[i+1] / LAYOUT_MAP_DIV;
uint8_t w = BM_W * zoneMap[i+2] / LAYOUT_MAP_DIV;
uint8_t h = (BM_H * zoneMap[i+3] + LAYOUT_MAP_DIV/2) / LAYOUT_MAP_DIV;
if (yo > 0)
memset(bm+(yo*BM_W+xo), 0xFF, w);
if (xo > 0) {
for (int y = 0; y < h; y += 1) {
bm[(yo+y)*BM_W+xo] = 0xFF;
}
}
}
}
~BaseLayoutFactory()
{
if (bitmap) {
free((void*)bitmap);
bitmap = nullptr;
}
}
const uint8_t* getBitmap() const override { return bitmap; }
@@ -151,7 +217,7 @@ class BaseLayoutFactory: public LayoutFactory
Layout * create(Window* parent, Layout::PersistentData * persistentData) const override
{
initPersistentData(persistentData, true);
Layout * layout = new T(parent, this, persistentData);
Layout * layout = new T(parent, this, persistentData, zoneCount, zoneMap);
if (layout) {
layout->create();
}
@@ -161,7 +227,7 @@ class BaseLayoutFactory: public LayoutFactory
Layout * load(Window* parent, Layout::PersistentData * persistentData) const override
{
initPersistentData(persistentData, false);
Layout * layout = new T(parent, this, persistentData);
Layout * layout = new T(parent, this, persistentData, zoneCount, zoneMap);
if (layout) {
layout->load();
}
@@ -191,6 +257,8 @@ class BaseLayoutFactory: public LayoutFactory
}
protected:
const uint8_t * bitmap;
const uint8_t * bitmap = nullptr;
const ZoneOption * options;
uint8_t zoneCount;
uint8_t* zoneMap;
};