mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[home] Added support for a wallpaper in a special format (.obm)
This commit is contained in:
@@ -3,6 +3,7 @@ app_home_src = $(addprefix apps/home/,\
|
||||
app_cell.cpp \
|
||||
apps_layout.py \
|
||||
controller.cpp \
|
||||
selectable_table_view_with_background.cpp \
|
||||
)
|
||||
|
||||
apps_src += $(app_home_src)
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Home {
|
||||
AppCell::AppCell() :
|
||||
HighlightCell(),
|
||||
m_nameView(KDFont::SmallFont, (I18n::Message)0, 0.5f, 0.5f, Palette::HomeCellText, Palette::HomeCellBackground),
|
||||
m_backgroundView(nullptr),
|
||||
m_visible(true), m_external_app(false)
|
||||
{
|
||||
}
|
||||
@@ -15,8 +16,8 @@ AppCell::AppCell() :
|
||||
|
||||
void AppCell::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
KDSize nameSize = m_nameView.minimalSizeForOptimalDisplay();
|
||||
ctx->fillRect(KDRect(0, bounds().height()-nameSize.height() - 2*k_nameHeightMargin, bounds().width(), nameSize.height()+2*k_nameHeightMargin), Palette::HomeBackground);
|
||||
}
|
||||
m_backgroundView->drawRect(ctx, KDRect(0, bounds().height()-nameSize.height() - 2*k_nameHeightMargin, bounds().width(), nameSize.height()+2*k_nameHeightMargin));
|
||||
}
|
||||
|
||||
int AppCell::numberOfSubviews() const {
|
||||
return m_visible ? 2 : 0;
|
||||
@@ -70,6 +71,10 @@ void AppCell::setVisible(bool visible) {
|
||||
}
|
||||
}
|
||||
|
||||
void AppCell::setBackgroundView(const BackgroundView * backgroundView) {
|
||||
m_backgroundView = backgroundView;
|
||||
}
|
||||
|
||||
void AppCell::reloadCell() {
|
||||
m_nameView.setTextColor(isHighlighted() ? (m_external_app ? Palette::HomeCellTextExternalActive : Palette::HomeCellTextActive) : (m_external_app ? Palette::HomeCellTextExternal : Palette::HomeCellText));
|
||||
m_nameView.setBackgroundColor(isHighlighted() ? Palette::HomeCellBackgroundActive : Palette::HomeCellBackground);
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
void layoutSubviews(bool force = false) override;
|
||||
|
||||
void setVisible(bool visible);
|
||||
void setBackgroundView(const BackgroundView * backgroundView);
|
||||
void reloadCell() override;
|
||||
void setAppDescriptor(::App::Descriptor * appDescriptor);
|
||||
void setExtAppDescriptor(const char* name, const Image* icon);
|
||||
@@ -25,8 +26,9 @@ private:
|
||||
static constexpr KDCoordinate k_iconHeight = 56;
|
||||
static constexpr KDCoordinate k_nameWidthMargin = 4;
|
||||
static constexpr KDCoordinate k_nameHeightMargin = 1;
|
||||
ImageView m_iconView;
|
||||
IconView m_iconView;
|
||||
MessageTextView m_nameView;
|
||||
const BackgroundView * m_backgroundView;
|
||||
bool m_visible;
|
||||
bool m_external_app;
|
||||
};
|
||||
|
||||
@@ -18,11 +18,11 @@ extern "C" {
|
||||
namespace Home {
|
||||
|
||||
Controller::ContentView::ContentView(Controller * controller, SelectableTableViewDataSource * selectionDataSource) :
|
||||
m_selectableTableView(controller, controller, selectionDataSource, controller)
|
||||
m_selectableTableView(controller, controller, &m_backgroundView, selectionDataSource, controller),
|
||||
m_backgroundView()
|
||||
{
|
||||
m_selectableTableView.setVerticalCellOverlap(0);
|
||||
m_selectableTableView.setMargins(0, k_sideMargin, k_bottomMargin, k_sideMargin);
|
||||
m_selectableTableView.setBackgroundColor(Palette::HomeBackground);
|
||||
static_cast<ScrollView::BarDecorator *>(m_selectableTableView.decorator())->verticalBar()->setMargin(k_indicatorMargin);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ SelectableTableView * Controller::ContentView::selectableTableView() {
|
||||
}
|
||||
|
||||
void Controller::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(bounds(), Palette::HomeBackground);
|
||||
m_selectableTableView.drawRect(ctx, rect);
|
||||
}
|
||||
|
||||
void Controller::ContentView::reloadBottomRow(SimpleTableViewDataSource * dataSource, int numberOfIcons, int numberOfColumns) {
|
||||
@@ -45,6 +45,10 @@ void Controller::ContentView::reloadBottomRow(SimpleTableViewDataSource * dataSo
|
||||
}
|
||||
}
|
||||
|
||||
BackgroundView * Controller::ContentView::backgroundView() {
|
||||
return &m_backgroundView;
|
||||
}
|
||||
|
||||
int Controller::ContentView::numberOfSubviews() const {
|
||||
return 1;
|
||||
}
|
||||
@@ -56,6 +60,8 @@ View * Controller::ContentView::subviewAtIndex(int index) {
|
||||
|
||||
void Controller::ContentView::layoutSubviews(bool force) {
|
||||
m_selectableTableView.setFrame(bounds(), force);
|
||||
m_backgroundView.setFrame(KDRect(0, Metric::TitleBarHeight, Ion::Display::Width, Ion::Display::Height-Metric::TitleBarHeight), force);
|
||||
m_backgroundView.updateDataValidity();
|
||||
}
|
||||
|
||||
Controller::Controller(Responder * parentResponder, SelectableTableViewDataSource * selectionDataSource, ::App * app) :
|
||||
@@ -63,6 +69,21 @@ Controller::Controller(Responder * parentResponder, SelectableTableViewDataSourc
|
||||
m_view(this, selectionDataSource)
|
||||
{
|
||||
m_app = app;
|
||||
for (int i = 0; i < k_maxNumberOfCells; i++) {
|
||||
m_cells[i].setBackgroundView(m_view.backgroundView());
|
||||
}
|
||||
|
||||
m_view.backgroundView()->setDefaultColor(Palette::HomeBackground);
|
||||
|
||||
|
||||
#ifdef HOME_DISPLAY_EXTERNALS
|
||||
int index = External::Archive::indexFromName("wallpaper.obm");
|
||||
if(index > -1) {
|
||||
External::Archive::File image;
|
||||
External::Archive::fileAtIndex(index, image);
|
||||
m_view.backgroundView()->setBackgroundImage(image.data);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Controller::handleEvent(Ion::Events::Event event) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define HOME_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "selectable_table_view_with_background.h"
|
||||
#include "app_cell.h"
|
||||
|
||||
namespace Home {
|
||||
@@ -35,11 +36,13 @@ private:
|
||||
SelectableTableView * selectableTableView();
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void reloadBottomRow(SimpleTableViewDataSource * dataSource, int numberOfIcons, int numberOfColumns);
|
||||
BackgroundView * backgroundView();
|
||||
private:
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews(bool force = false) override;
|
||||
SelectableTableView m_selectableTableView;
|
||||
SelectableTableViewWithBackground m_selectableTableView;
|
||||
BackgroundView m_backgroundView;
|
||||
};
|
||||
static constexpr KDCoordinate k_sideMargin = 4;
|
||||
static constexpr KDCoordinate k_bottomMargin = 14;
|
||||
|
||||
16
apps/home/selectable_table_view_with_background.cpp
Normal file
16
apps/home/selectable_table_view_with_background.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "selectable_table_view_with_background.h"
|
||||
|
||||
SelectableTableViewWithBackground::SelectableTableViewWithBackground(Responder * parentResponder, TableViewDataSource * dataSource, BackgroundView * backgroundView, SelectableTableViewDataSource * selectionDataSource, SelectableTableViewDelegate * delegate) :
|
||||
SelectableTableView(parentResponder, dataSource, selectionDataSource, delegate),
|
||||
m_backgroundInnerView(this, backgroundView)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SelectableTableViewWithBackground::BackgroundInnerView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
m_backgroundView->drawRect(ctx, rect);
|
||||
}
|
||||
|
||||
void SelectableTableViewWithBackground::BackgroundInnerView::setBackgroundView(const uint8_t * data) {
|
||||
m_backgroundView->setBackgroundImage(data);
|
||||
}
|
||||
25
apps/home/selectable_table_view_with_background.h
Normal file
25
apps/home/selectable_table_view_with_background.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef ESCHER_SELECTABLE_TABLE_VIEW_WITH_BACKGROUND_H
|
||||
#define ESCHER_SELECTABLE_TABLE_VIEW_WITH_BACKGROUND_H
|
||||
|
||||
#include <escher/selectable_table_view.h>
|
||||
#include <escher/background_view.h>
|
||||
|
||||
class SelectableTableViewWithBackground : public SelectableTableView {
|
||||
public:
|
||||
SelectableTableViewWithBackground(Responder * parentResponder, TableViewDataSource * dataSource, BackgroundView * backgroundView,
|
||||
SelectableTableViewDataSource * selectionDataSource = nullptr, SelectableTableViewDelegate * delegate = nullptr);
|
||||
View * subviewAtIndex(int index) override { return (index == 0) ? &m_backgroundInnerView : decorator()->indicatorAtIndex(index); }
|
||||
protected:
|
||||
virtual InnerView * getInnerView() { return &m_backgroundInnerView; }
|
||||
class BackgroundInnerView : public ScrollView::InnerView {
|
||||
public:
|
||||
BackgroundInnerView(ScrollView * scrollView, BackgroundView * backgroundView): InnerView(scrollView), m_backgroundView(backgroundView) {}
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setBackgroundView(const uint8_t * data);
|
||||
private:
|
||||
BackgroundView * m_backgroundView;
|
||||
};
|
||||
BackgroundInnerView m_backgroundInnerView;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user