chore(color): Replace dynamic_cast with virtual functions, disable RTTI to reduce FLASH usage (#3885)
* Replace dynamic_cast with virtual functions and disable RTTI. * Cleanup TopBar class hierarchy. * Fix compiler warning.
This commit is contained in:
@@ -508,7 +508,7 @@ set(COMMON_FLAGS "${COMMON_FLAGS} -O${OPT} ${FPU_FLAGS}")
|
|||||||
set(COMMON_FLAGS "${COMMON_FLAGS} ${WARNING_FLAGS}")
|
set(COMMON_FLAGS "${COMMON_FLAGS} ${WARNING_FLAGS}")
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS} -Wimplicit")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS} -Wimplicit")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS} -fno-rtti")
|
||||||
|
|
||||||
# these are in addition to CMAKE_CXX_FLAGS
|
# these are in addition to CMAKE_CXX_FLAGS
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "-lm -T${RADIO_SRC_DIR}/${LINKER_SCRIPT}")
|
set(CMAKE_EXE_LINKER_FLAGS "-lm -T${RADIO_SRC_DIR}/${LINKER_SCRIPT}")
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "view_main.h"
|
#include "view_main.h"
|
||||||
|
#include "topbar_impl.h"
|
||||||
|
|
||||||
WidgetsContainer * customScreens[MAX_CUSTOM_SCREENS] = {};
|
WidgetsContainer * customScreens[MAX_CUSTOM_SCREENS] = {};
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ class Layout: public LayoutBase
|
|||||||
// Updates settings for trims, sliders, pots, etc...
|
// Updates settings for trims, sliders, pots, etc...
|
||||||
void adjustLayout() override;
|
void adjustLayout() override;
|
||||||
|
|
||||||
|
bool isLayout() override { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const LayoutFactory * factory = nullptr;
|
const LayoutFactory * factory = nullptr;
|
||||||
std::unique_ptr<ViewMainDecoration> decoration;
|
std::unique_ptr<ViewMainDecoration> decoration;
|
||||||
|
|||||||
@@ -24,17 +24,17 @@
|
|||||||
|
|
||||||
constexpr uint32_t TOPBAR_REFRESH = 1000 / 10; // 10 Hz
|
constexpr uint32_t TOPBAR_REFRESH = 1000 / 10; // 10 Hz
|
||||||
|
|
||||||
TopbarImpl::TopbarImpl(Window * parent) :
|
TopBar::TopBar(Window * parent) :
|
||||||
TopbarImplBase(parent, {0, 0, LCD_W, MENU_HEADER_HEIGHT}, &g_model.topbarData)
|
TopBarBase(parent, {0, 0, LCD_W, MENU_HEADER_HEIGHT}, &g_model.topbarData)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int TopbarImpl::getZonesCount() const
|
unsigned int TopBar::getZonesCount() const
|
||||||
{
|
{
|
||||||
return MAX_TOPBAR_ZONES;
|
return MAX_TOPBAR_ZONES;
|
||||||
}
|
}
|
||||||
|
|
||||||
rect_t TopbarImpl::getZone(unsigned int index) const
|
rect_t TopBar::getZone(unsigned int index) const
|
||||||
{
|
{
|
||||||
if (index == MAX_TOPBAR_ZONES - 1) {
|
if (index == MAX_TOPBAR_ZONES - 1) {
|
||||||
coord_t size = LCD_W - 48 - (MAX_TOPBAR_ZONES - 1) * (TOPBAR_ZONE_WIDTH + TOPBAR_ZONE_HMARGIN);
|
coord_t size = LCD_W - 48 - (MAX_TOPBAR_ZONES - 1) * (TOPBAR_ZONE_WIDTH + TOPBAR_ZONE_HMARGIN);
|
||||||
@@ -49,7 +49,7 @@ rect_t TopbarImpl::getZone(unsigned int index) const
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopbarImpl::setVisible(float visible) // 0.0 -> 1.0
|
void TopBar::setVisible(float visible) // 0.0 -> 1.0
|
||||||
{
|
{
|
||||||
if (visible == 0.0) {
|
if (visible == 0.0) {
|
||||||
setTop(-(int)MENU_HEADER_HEIGHT);
|
setTop(-(int)MENU_HEADER_HEIGHT);
|
||||||
@@ -63,7 +63,7 @@ void TopbarImpl::setVisible(float visible) // 0.0 -> 1.0
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
coord_t TopbarImpl::getVisibleHeight(float visible) const // 0.0 -> 1.0
|
coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
|
||||||
{
|
{
|
||||||
if (visible == 0.0) {
|
if (visible == 0.0) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -76,13 +76,13 @@ coord_t TopbarImpl::getVisibleHeight(float visible) const // 0.0 -> 1.0
|
|||||||
return (coord_t)h;
|
return (coord_t)h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopbarImpl::paint(BitmapBuffer * dc)
|
void TopBar::paint(BitmapBuffer * dc)
|
||||||
{
|
{
|
||||||
dc->drawSolidFilledRect(0, 0, width(), height(), COLOR_THEME_SECONDARY1);
|
dc->drawSolidFilledRect(0, 0, width(), height(), COLOR_THEME_SECONDARY1);
|
||||||
EdgeTxTheme::instance()->drawHeaderIcon(dc, ICON_EDGETX);
|
EdgeTxTheme::instance()->drawHeaderIcon(dc, ICON_EDGETX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopbarImpl::checkEvents()
|
void TopBar::checkEvents()
|
||||||
{
|
{
|
||||||
uint32_t now = RTOS_GET_MS();
|
uint32_t now = RTOS_GET_MS();
|
||||||
if (now - lastRefresh >= TOPBAR_REFRESH) {
|
if (now - lastRefresh >= TOPBAR_REFRESH) {
|
||||||
@@ -91,7 +91,7 @@ void TopbarImpl::checkEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopbarImpl::removeWidget(unsigned int index)
|
void TopBar::removeWidget(unsigned int index)
|
||||||
{
|
{
|
||||||
bool mark = false;
|
bool mark = false;
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,12 @@
|
|||||||
#include "topbar.h"
|
#include "topbar.h"
|
||||||
#include "layouts/layout_factory_impl.h"
|
#include "layouts/layout_factory_impl.h"
|
||||||
|
|
||||||
typedef WidgetsContainerImpl<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS> TopbarImplBase;
|
typedef WidgetsContainerImpl<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS> TopBarBase;
|
||||||
|
|
||||||
class TopbarImpl:
|
class TopBar: public TopBarBase
|
||||||
public TopbarImplBase,
|
|
||||||
public Topbar
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TopbarImpl(Window * parent);
|
explicit TopBar(Window * parent);
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override
|
std::string getName() const override
|
||||||
@@ -42,7 +40,7 @@ class TopbarImpl:
|
|||||||
|
|
||||||
void load() override
|
void load() override
|
||||||
{
|
{
|
||||||
TopbarImplBase::load();
|
TopBarBase::load();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getZonesCount() const override;
|
unsigned int getZonesCount() const override;
|
||||||
@@ -56,6 +54,8 @@ class TopbarImpl:
|
|||||||
|
|
||||||
void checkEvents() override;
|
void checkEvents() override;
|
||||||
|
|
||||||
|
bool isTopBar() override { return true; }
|
||||||
|
|
||||||
void removeWidget(unsigned int index) override;
|
void removeWidget(unsigned int index) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -238,9 +238,9 @@ void ScreenSetupPage::build(FormWindow * window)
|
|||||||
auto idx = customScreenIndex;
|
auto idx = customScreenIndex;
|
||||||
|
|
||||||
LayoutChoice::LayoutFactoryGetter getFactory = [idx] () -> const LayoutFactory * {
|
LayoutChoice::LayoutFactoryGetter getFactory = [idx] () -> const LayoutFactory * {
|
||||||
auto layout = dynamic_cast<Layout*>(customScreens[idx]);
|
auto layout = customScreens[idx];
|
||||||
if (!layout) return nullptr;
|
if (!layout->isLayout()) return nullptr;
|
||||||
return layout->getFactory();
|
return ((Layout*)layout)->getFactory();
|
||||||
};
|
};
|
||||||
|
|
||||||
LayoutChoice::LayoutFactorySetter setLayout =
|
LayoutChoice::LayoutFactorySetter setLayout =
|
||||||
@@ -298,10 +298,10 @@ void ScreenSetupPage::buildLayoutOptions()
|
|||||||
layoutOptions->setFlexLayout();
|
layoutOptions->setFlexLayout();
|
||||||
|
|
||||||
// Layout options...
|
// Layout options...
|
||||||
auto layout = dynamic_cast<Layout*>(customScreens[customScreenIndex]);
|
auto layout = customScreens[customScreenIndex];
|
||||||
if (!layout) return;
|
if (!layout->isLayout()) return;
|
||||||
|
|
||||||
auto factory = layout->getFactory();
|
auto factory = ((Layout*)layout)->getFactory();
|
||||||
if (!factory) return;
|
if (!factory) return;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|||||||
@@ -29,9 +29,9 @@
|
|||||||
#include "widgets_setup.h"
|
#include "widgets_setup.h"
|
||||||
|
|
||||||
|
|
||||||
Topbar * TopbarFactory::create(Window * parent)
|
TopBar * TopbarFactory::create(Window * parent)
|
||||||
{
|
{
|
||||||
return new TopbarImpl(parent);
|
return new TopBar(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupTopBarWidgetsPage::SetupTopBarWidgetsPage():
|
SetupTopBarWidgetsPage::SetupTopBarWidgetsPage():
|
||||||
@@ -48,7 +48,7 @@ SetupTopBarWidgetsPage::SetupTopBarWidgetsPage():
|
|||||||
// adopt the dimensions of the main view
|
// adopt the dimensions of the main view
|
||||||
setRect(viewMain->getRect());
|
setRect(viewMain->getRect());
|
||||||
|
|
||||||
auto topbar = dynamic_cast<TopbarImpl*>(viewMain->getTopbar());
|
auto topbar = viewMain->getTopbar();
|
||||||
for (unsigned i = 0; i < topbar->getZonesCount(); i++) {
|
for (unsigned i = 0; i < topbar->getZonesCount(); i++) {
|
||||||
auto rect = topbar->getZone(i);
|
auto rect = topbar->getZone(i);
|
||||||
new SetupWidgetsPageSlot(this, rect, topbar, i);
|
new SetupWidgetsPageSlot(this, rect, topbar, i);
|
||||||
|
|||||||
@@ -29,18 +29,12 @@ constexpr coord_t TOPBAR_ZONE_HMARGIN = 3;
|
|||||||
constexpr coord_t TOPBAR_ZONE_HEIGHT = MENU_HEADER_HEIGHT - 2 * TOPBAR_ZONE_VMARGIN;
|
constexpr coord_t TOPBAR_ZONE_HEIGHT = MENU_HEADER_HEIGHT - 2 * TOPBAR_ZONE_VMARGIN;
|
||||||
|
|
||||||
class ScreenMenu;
|
class ScreenMenu;
|
||||||
class TopbarImpl;
|
class TopBar;
|
||||||
|
|
||||||
class Topbar
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void load() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TopbarFactory
|
class TopbarFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Topbar* create(Window* parent);
|
static TopBar* create(Window* parent);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetupTopBarWidgetsPage : public FormWindow
|
class SetupTopBarWidgetsPage : public FormWindow
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ ViewMain::ViewMain():
|
|||||||
lv_obj_add_event_cb(lvobj, ViewMain::long_pressed, LV_EVENT_LONG_PRESSED, nullptr);
|
lv_obj_add_event_cb(lvobj, ViewMain::long_pressed, LV_EVENT_LONG_PRESSED, nullptr);
|
||||||
|
|
||||||
// create last to be on top
|
// create last to be on top
|
||||||
topbar = dynamic_cast<TopbarImpl*>(TopbarFactory::create(this));
|
topbar = TopbarFactory::create(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewMain::~ViewMain()
|
ViewMain::~ViewMain()
|
||||||
@@ -167,7 +167,7 @@ void ViewMain::previousMainView()
|
|||||||
saveViewId(view);
|
saveViewId(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topbar* ViewMain::getTopbar()
|
TopBar* ViewMain::getTopbar()
|
||||||
{
|
{
|
||||||
return topbar;
|
return topbar;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ class ViewMain: public Window
|
|||||||
void nextMainView();
|
void nextMainView();
|
||||||
void previousMainView();
|
void previousMainView();
|
||||||
|
|
||||||
Topbar* getTopbar();
|
TopBar* getTopbar();
|
||||||
|
|
||||||
void onEvent(event_t event) override;
|
void onEvent(event_t event) override;
|
||||||
void onClicked() override;
|
void onClicked() override;
|
||||||
void onCancel() override;
|
void onCancel() override;
|
||||||
@@ -87,7 +87,7 @@ class ViewMain: public Window
|
|||||||
static ViewMain * _instance;
|
static ViewMain * _instance;
|
||||||
|
|
||||||
lv_obj_t* tile_view = nullptr;
|
lv_obj_t* tile_view = nullptr;
|
||||||
TopbarImpl* topbar = nullptr;
|
TopBar* topbar = nullptr;
|
||||||
bool widget_select = false;
|
bool widget_select = false;
|
||||||
lv_timer_t* widget_select_timer = nullptr;
|
lv_timer_t* widget_select_timer = nullptr;
|
||||||
ViewMainMenu* viewMainMenu = nullptr;
|
ViewMainMenu* viewMainMenu = nullptr;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Widget::Widget(const WidgetFactory* factory, Window* parent,
|
|||||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLLABLE);
|
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||||
|
|
||||||
if (dynamic_cast<Topbar*>(parent))
|
if (parent->isTopBar())
|
||||||
fsAllowed = false;
|
fsAllowed = false;
|
||||||
|
|
||||||
setPressHandler([&]() -> uint8_t {
|
setPressHandler([&]() -> uint8_t {
|
||||||
@@ -112,9 +112,8 @@ void Widget::setFullscreen(bool enable)
|
|||||||
if (!enable) {
|
if (!enable) {
|
||||||
|
|
||||||
// Reset all zones in container
|
// Reset all zones in container
|
||||||
auto container = dynamic_cast<WidgetsContainer*>(parent);
|
if (parent->isWidgetsContainer())
|
||||||
if (container)
|
((WidgetsContainer*)parent)->updateZones();
|
||||||
container->updateZones();
|
|
||||||
|
|
||||||
setWindowFlags(getWindowFlags() & ~OPAQUE);
|
setWindowFlags(getWindowFlags() & ~OPAQUE);
|
||||||
lv_obj_set_style_bg_opa(lvobj, LV_OPA_0, LV_PART_MAIN);
|
lv_obj_set_style_bg_opa(lvobj, LV_OPA_0, LV_PART_MAIN);
|
||||||
|
|||||||
@@ -180,6 +180,8 @@ class WidgetFactory
|
|||||||
|
|
||||||
virtual Widget * create(Window* parent, const rect_t & rect, Widget::PersistentData * persistentData, bool init = true) const = 0;
|
virtual Widget * create(Window* parent, const rect_t & rect, Widget::PersistentData * persistentData, bool init = true) const = 0;
|
||||||
|
|
||||||
|
virtual bool isLuaWidgetFactory() const { return false; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char * name;
|
const char * name;
|
||||||
const char * displayName;
|
const char * displayName;
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ class WidgetsContainer: public Window
|
|||||||
virtual void adjustLayout() = 0;
|
virtual void adjustLayout() = 0;
|
||||||
virtual void updateZones() = 0;
|
virtual void updateZones() = 0;
|
||||||
virtual void updateFromTheme() = 0;
|
virtual void updateFromTheme() = 0;
|
||||||
|
|
||||||
|
virtual bool isLayout() { return false; }
|
||||||
|
bool isWidgetsContainer() override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ class LuaWidgetFactory : public WidgetFactory
|
|||||||
Widget::PersistentData* persistentData,
|
Widget::PersistentData* persistentData,
|
||||||
bool init = true) const override;
|
bool init = true) const override;
|
||||||
|
|
||||||
|
bool isLuaWidgetFactory() const override { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void translateOptions(ZoneOption * options);
|
void translateOptions(ZoneOption * options);
|
||||||
|
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ void luaUnregisterWidgets()
|
|||||||
{
|
{
|
||||||
std::list<const WidgetFactory *> regWidgets(getRegisteredWidgets());
|
std::list<const WidgetFactory *> regWidgets(getRegisteredWidgets());
|
||||||
for (auto w : regWidgets) {
|
for (auto w : regWidgets) {
|
||||||
if (dynamic_cast<const LuaWidgetFactory*>(w)) {
|
if (w->isLuaWidgetFactory()) {
|
||||||
delete w;
|
delete w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -201,6 +201,9 @@ class Window
|
|||||||
|
|
||||||
inline lv_obj_t *getLvObj() { return lvobj; }
|
inline lv_obj_t *getLvObj() { return lvobj; }
|
||||||
|
|
||||||
|
virtual bool isTopBar() { return false; }
|
||||||
|
virtual bool isWidgetsContainer() { return false; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static std::list<Window*> trash;
|
static std::list<Window*> trash;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user