From e1d8289bea0487e31a2ed34ee29c1a892fff8c7b Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Fri, 30 Sep 2016 18:07:29 +0200 Subject: [PATCH] [apps] Add a Home app Change-Id: I4d2da7d8a954131a3e561f175f88cd72abf6f2ba --- apps/Makefile | 1 + apps/home/Makefile | 6 ++++++ apps/home/app.cpp | 15 ++++++++++++++ apps/home/app.h | 20 +++++++++++++++++++ apps/home/app_cell.cpp | 19 ++++++++++++++++++ apps/home/app_cell.h | 16 +++++++++++++++ apps/home/controller.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ apps/home/controller.h | 28 +++++++++++++++++++++++++++ 8 files changed, 147 insertions(+) create mode 100644 apps/home/Makefile create mode 100644 apps/home/app.cpp create mode 100644 apps/home/app.h create mode 100644 apps/home/app_cell.cpp create mode 100644 apps/home/app_cell.h create mode 100644 apps/home/controller.cpp create mode 100644 apps/home/controller.h diff --git a/apps/Makefile b/apps/Makefile index d070b985c..dd524d737 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,3 +1,4 @@ +include apps/home/Makefile include apps/graph/Makefile include apps/probability/Makefile #include apps/picview/Makefile diff --git a/apps/home/Makefile b/apps/home/Makefile new file mode 100644 index 000000000..d7da4e4f4 --- /dev/null +++ b/apps/home/Makefile @@ -0,0 +1,6 @@ +app_objs += $(addprefix apps/home/,\ + app.o\ + app_cell.o\ + controller.o\ +) + diff --git a/apps/home/app.cpp b/apps/home/app.cpp new file mode 100644 index 000000000..cde6768e9 --- /dev/null +++ b/apps/home/app.cpp @@ -0,0 +1,15 @@ +#include "app.h" + +namespace Home { + +App::App() : + ::App(), + m_controller(Controller(this)) +{ +} + +ViewController * App::rootViewController() { + return &m_controller; +} + +} diff --git a/apps/home/app.h b/apps/home/app.h new file mode 100644 index 000000000..44a6965b3 --- /dev/null +++ b/apps/home/app.h @@ -0,0 +1,20 @@ +#ifndef HOME_APP_H +#define HOME_APP_H + +#include +#include "controller.h" + +namespace Home { + +class App : public ::App { +public: + App(); +protected: + ViewController * rootViewController() override; +private: + Controller m_controller; +}; + +} + +#endif diff --git a/apps/home/app_cell.cpp b/apps/home/app_cell.cpp new file mode 100644 index 000000000..b77a144a6 --- /dev/null +++ b/apps/home/app_cell.cpp @@ -0,0 +1,19 @@ +#include "app_cell.h" +#include + +namespace Home { + +AppCell::AppCell() : + ChildlessView() +{ +} + +void AppCell::drawRect(KDContext * ctx, KDRect rect) const { + /* + KDColor * pixels = (KDColor *)apps_picview_image_raw; + assert(apps_picview_image_raw_len == bounds().width() * bounds().height() * sizeof(KDColor)); + ctx->fillRectWithPixels(bounds(), pixels, nullptr); + */ +} + +} diff --git a/apps/home/app_cell.h b/apps/home/app_cell.h new file mode 100644 index 000000000..3f4cd1d13 --- /dev/null +++ b/apps/home/app_cell.h @@ -0,0 +1,16 @@ +#ifndef HOME_APP_CELL_H +#define HOME_APP_CELL_H + +#include + +namespace Home { + +class AppCell : public ChildlessView { +public: + AppCell(); + void drawRect(KDContext * ctx, KDRect rect) const override; +}; + +} + +#endif diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp new file mode 100644 index 000000000..e9a5bd3ae --- /dev/null +++ b/apps/home/controller.cpp @@ -0,0 +1,42 @@ +#include "controller.h" +extern "C" { +#include +} + +namespace Home { + +Controller::Controller(Responder * parentResponder) : + ViewController(parentResponder), + m_tableView(TableView(this)) +{ +} + +View * Controller::view() { + return &m_tableView; +} + +int Controller::numberOfRows() { + return 10; +} + +int Controller::numberOfColumns() { + return 3; +} + +KDCoordinate Controller::cellHeight() { + return 50; +} + +KDCoordinate Controller::cellWidth() { + return 50; +} + +View * Controller::reusableCell(int index) { + return &m_cells[index]; +} + +int Controller::reusableCellCount() { + return k_maxNumberOfCells; +} + +} diff --git a/apps/home/controller.h b/apps/home/controller.h new file mode 100644 index 000000000..497d94549 --- /dev/null +++ b/apps/home/controller.h @@ -0,0 +1,28 @@ +#ifndef HOME_CONTROLLER_H +#define HOME_CONTROLLER_H + +#include +#include "app_cell.h" + +namespace Home { + +class Controller : public ViewController, public SimpleTableViewDataSource { +public: + Controller(Responder * parentResponder); + View * view() override; + + virtual int numberOfRows() override; + virtual int numberOfColumns() override; + virtual KDCoordinate cellHeight() override; + virtual KDCoordinate cellWidth() override; + virtual View * reusableCell(int index) override; + virtual int reusableCellCount() override; +private: + TableView m_tableView; + static constexpr int k_maxNumberOfCells = 16; + AppCell m_cells[k_maxNumberOfCells]; +}; + +} + +#endif