diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp index ebdd85905..b1c2e4dba 100644 --- a/apps/sequence/list/list_parameter_controller.cpp +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -23,38 +23,18 @@ const char * ListParameterController::title() { bool ListParameterController::handleEvent(Ion::Events::Event event) { bool hasAdditionalRow = hasInitialRankRow(); -#if FUNCTION_COLOR_CHOICE - if (event == Ion::Events::OK || event == Ion::Events::EXE || (event == Ion::Events::Right && selectedRow() == 1)) { -#else if (event == Ion::Events::OK || event == Ion::Events::EXE || (event == Ion::Events::Right && selectedRow() == 0)) { -#endif int selectedRowIndex = selectedRow(); -#if FUNCTION_COLOR_CHOICE if (selectedRowIndex == 0) { - return handleEnterOnRow(selectedRowIndex); - } - if (selectedRowIndex == 1) { -#else - if (selectedRowIndex == 0) { -#endif StackViewController * stack = (StackViewController *)(parentResponder()); m_typeParameterController.setRecord(m_record); stack->push(&m_typeParameterController); return true; } -#if FUNCTION_COLOR_CHOICE - if (selectedRowIndex == 2+hasAdditionalRow) { - -#else - if (selectedRowIndex == 1+hasAdditionalRow) { -#endif + if (selectedRowIndex == 1+hasAdditionalRow || selectedRowIndex == 2+hasAdditionalRow) { return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1); } -#if FUNCTION_COLOR_CHOICE if (selectedRowIndex == 3+hasAdditionalRow) { -#else - if (selectedRowIndex == 2+hasAdditionalRow) { -#endif App::app()->localContext()->resetCache(); return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1); } diff --git a/apps/sequence/list/list_parameter_controller.h b/apps/sequence/list/list_parameter_controller.h index cc5ddae78..04d582b1a 100644 --- a/apps/sequence/list/list_parameter_controller.h +++ b/apps/sequence/list/list_parameter_controller.h @@ -25,11 +25,7 @@ public: HighlightCell * reusableCell(int index, int type) override; void willDisplayCellForIndex(HighlightCell * cell, int index) override; private: -#if FUNCTION_COLOR_CHOICE constexpr static int k_totalNumberOfCell = 5; -#else - constexpr static int k_totalNumberOfCell = 4; -#endif int totalNumberOfCells() const override; Sequence * sequence() { return static_cast(function().pointer()); } bool hasInitialRankRow() const; diff --git a/apps/shared/Makefile b/apps/shared/Makefile index 4ffcd50df..62e670808 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -24,6 +24,8 @@ app_shared_src = $(addprefix apps/shared/,\ buffer_function_title_cell.cpp \ buffer_text_view_with_text_field.cpp \ button_with_separator.cpp \ + color_cell.cpp \ + color_parameter_controller.cpp \ cursor_view.cpp \ curve_view_cursor.cpp \ editable_cell_table_view_controller.cpp \ diff --git a/apps/shared/color_cell.cpp b/apps/shared/color_cell.cpp new file mode 100644 index 000000000..c6ecc147b --- /dev/null +++ b/apps/shared/color_cell.cpp @@ -0,0 +1,51 @@ +#include "color_cell.h" +#include + +namespace Shared { + +MessageTableCellWithColor::MessageTableCellWithColor() : + MessageTableCell(), + m_accessoryView() + {} + +View * MessageTableCellWithColor::accessoryView() const { + return (View *)&m_accessoryView; +} + +void MessageTableCellWithColor::setColor(int i) { + m_accessoryView.setColor(i); + MessageTextView * label = (MessageTextView*)(labelView()); + switch(i) { + case 0: + return label->setMessage(k_textForIndex[0]); // FIXME + case 1: + return label->setMessage(k_textForIndex[1]); // FIXME + case 2: + return label->setMessage(k_textForIndex[2]); // FIXME + case 3: + return label->setMessage(k_textForIndex[3]); // FIXME + case 4: + return label->setMessage(k_textForIndex[4]); // FIXME + case 5: + return label->setMessage(k_textForIndex[5]); // FIXME + case 6: + return label->setMessage(k_textForIndex[6]); // FIXME + default: + assert(false); + } + //return label->setMessage(k_textForIndex[i]); // FIXME +} + +MessageTableCellWithColor::ColorView::ColorView() : + m_index(0) + {} + +void MessageTableCellWithColor::ColorView::drawRect(KDContext * ctx, KDRect rect) const { + ctx->fillRect(bounds(), Palette::DataColor[m_index]); +} + +KDSize MessageTableCellWithColor::ColorView::minimalSizeForOptimalDisplay() const { + return KDSize(10, 10); +} + +} diff --git a/apps/shared/color_cell.h b/apps/shared/color_cell.h new file mode 100644 index 000000000..be7bfb4d4 --- /dev/null +++ b/apps/shared/color_cell.h @@ -0,0 +1,41 @@ +#ifndef SHARED_COLOR_CELL_CONTROLLER_H +#define SHARED_COLOR_CELL_CONTROLLER_H + +#include +#include + +namespace Shared { + +class MessageTableCellWithColor : public MessageTableCell { +public: + MessageTableCellWithColor(); + View * accessoryView() const override; + void setColor(int i); +private: + class ColorView : public TransparentView { + public: + ColorView(); + void setColor(int i) { m_index = i; } + void drawRect(KDContext * ctx, KDRect rect) const override; + KDSize minimalSizeForOptimalDisplay() const override; + constexpr static KDCoordinate k_chevronHeight = 10; + constexpr static KDCoordinate k_chevronWidth = 8; + private: + int m_index; + }; + ColorView m_accessoryView; + constexpr static I18n::Message k_textForIndex[] = { + I18n::Message::PythonColorRed, + I18n::Message::PythonColorBlue, + I18n::Message::PythonColorGreen, + I18n::Message::PythonColorYellow, + I18n::Message::PythonColorPurple, + I18n::Message::PythonColorBlue, + I18n::Message::PythonColorPink, + I18n::Message::PythonColorOrange + }; +}; + +} + +#endif diff --git a/apps/shared/color_parameter_controller.cpp b/apps/shared/color_parameter_controller.cpp new file mode 100644 index 000000000..21d573a0e --- /dev/null +++ b/apps/shared/color_parameter_controller.cpp @@ -0,0 +1,73 @@ +#include "color_parameter_controller.h" + +#include "function_app.h" +#include "../apps_container.h" +#include + +namespace Shared { + +ColorParameterController::ColorParameterController(Responder * parentResponder, I18n::Message title) : + ViewController(parentResponder), + m_selectableTableView(this), + m_record(), + m_title(title) +{ + for(int i = 0; i < Palette::numberOfDataColors(); i++){ + m_cells[i].setColor(i); + } +} + +void ColorParameterController::viewWillAppear() { + ViewController::viewWillAppear(); + selectCellAtLocation(0,0); + m_selectableTableView.reloadData(); +} + +void ColorParameterController::didBecomeFirstResponder() { + Container::activeApp()->setFirstResponder(&m_selectableTableView); +} + +bool ColorParameterController::handleEvent(Ion::Events::Event event) { + StackViewController * stack = (StackViewController *)(parentResponder()); + if (event == Ion::Events::Left) { + stack->pop(); + return true; + } + if (event == Ion::Events::OK || event == Ion::Events::EXE) { + handleEnterOnRow(selectedRow()); + stack->pop(); + return true; + } + return false; +} + +KDCoordinate ColorParameterController::cellHeight() { + return Metric::ParameterCellHeight; +} + +HighlightCell * ColorParameterController::reusableCell(int index) { + assert(index < numberOfRows()); + return &m_cells[index]; +} + +bool ColorParameterController::handleEnterOnRow(int rowIndex) { + function()->setColor(Palette::DataColor[rowIndex]); + return true; +} + +void ColorParameterController::setRecord(Ion::Storage::Record record) { + m_record = record; + selectCellAtLocation(0, 0); +} + +ExpiringPointer ColorParameterController::function() { + return functionStore()->modelForRecord(m_record); +} + +FunctionStore * ColorParameterController::functionStore() { + return FunctionApp::app()->functionStore(); +} + + +} + diff --git a/apps/shared/color_parameter_controller.h b/apps/shared/color_parameter_controller.h new file mode 100644 index 000000000..b4cb3429c --- /dev/null +++ b/apps/shared/color_parameter_controller.h @@ -0,0 +1,43 @@ +#ifndef SHARED_COLOR_PARAM_CONTROLLER_H +#define SHARED_COLOR_PARAM_CONTROLLER_H + +#include +#include "function_store.h" +#include "color_cell.h" +#include + +namespace Shared { + +class ColorParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource { +public: + ColorParameterController(Responder * parentResponder, I18n::Message title); + + View * view() override { return &m_selectableTableView; } + void viewWillAppear() override; + void didBecomeFirstResponder() override; + + const char * title() override { return I18n::translate(m_title); } + + bool handleEvent(Ion::Events::Event event) override; + + TELEMETRY_ID("ColorParameter"); + + void setRecord(Ion::Storage::Record record); + + int numberOfRows() const override { return Palette::numberOfDataColors(); } + KDCoordinate cellHeight() override; + HighlightCell * reusableCell(int index) override; + int reusableCellCount() const override { return Palette::numberOfDataColors(); } // FIXME Display issue +private: + bool handleEnterOnRow(int rowIndex); + FunctionStore * functionStore(); + ExpiringPointer function(); + SelectableTableView m_selectableTableView; + Ion::Storage::Record m_record; + I18n::Message m_title; + MessageTableCellWithColor m_cells[Palette::numberOfDataColors()]; +}; + +} + +#endif diff --git a/apps/shared/function.cpp b/apps/shared/function.cpp index 31b1e01e0..42e8b20ee 100644 --- a/apps/shared/function.cpp +++ b/apps/shared/function.cpp @@ -46,6 +46,10 @@ void Function::setActive(bool active) { recordData()->setActive(active); } +void Function::setColor(KDColor color) { + recordData()->setColor(color); +} + int Function::printValue(double cursorT, double cursorX, double cursorY, char * buffer, int bufferSize, int precision, Poincare::Context * context) { return PoincareHelpers::ConvertFloatToText(cursorY, buffer, bufferSize, precision); } diff --git a/apps/shared/function.h b/apps/shared/function.h index 52bdff733..69fc810bb 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -36,6 +36,7 @@ public: bool isActive() const; KDColor color() const; void setActive(bool active); + void setColor(KDColor color); // Definition Interval virtual bool shouldClipTRangeToXRange() const { return true; } // Returns true if the function will not be displayed if t is outside x range. @@ -65,6 +66,7 @@ protected: KDColor color() const { return KDColor::RGB16(m_color); } + void setColor(KDColor color) { m_color = color; } bool isActive() const { return m_active; } void setActive(bool active) { m_active = active; } private: diff --git a/apps/shared/list_parameter_controller.cpp b/apps/shared/list_parameter_controller.cpp index 27c11745f..b04e1b254 100644 --- a/apps/shared/list_parameter_controller.cpp +++ b/apps/shared/list_parameter_controller.cpp @@ -8,11 +8,10 @@ ListParameterController::ListParameterController(Responder * parentResponder, I1 ViewController(parentResponder), m_selectableTableView(this, this, this, tableDelegate), m_record(), -#if FUNCTION_COLOR_CHOICE m_colorCell(functionColorMessage), -#endif m_enableCell(I18n::Message::ActivateDeactivate), - m_deleteCell(deleteFunctionMessage) + m_deleteCell(deleteFunctionMessage), + m_colorParameterController(parentResponder, functionColorMessage) { } @@ -64,11 +63,7 @@ int ListParameterController::indexFromCumulatedHeight(KDCoordinate offsetY) { HighlightCell * ListParameterController::reusableCell(int index, int type) { assert(index == 0); assert(index < totalNumberOfCells()); -#if FUNCTION_COLOR_CHOICE HighlightCell * cells[] = {&m_colorCell, &m_enableCell, &m_deleteCell}; -#else - HighlightCell * cells[] = {&m_enableCell, &m_deleteCell}; -#endif return cells[type]; } @@ -78,22 +73,17 @@ int ListParameterController::typeAtLocation(int i, int j) { bool ListParameterController::handleEnterOnRow(int rowIndex) { switch (rowIndex) { -#if FUNCTION_COLOR_CHOICE - case 0: - /* TODO: implement function color choice */ + case 0: { + StackViewController * stack = (StackViewController *)(parentResponder()); + m_colorParameterController.setRecord(m_record); + stack->push(&m_colorParameterController); return true; + } case 1: -#else - case 0: -#endif function()->setActive(!function()->isActive()); m_selectableTableView.reloadData(); return true; -#if FUNCTION_COLOR_CHOICE - case 2: -#else - case 1: -#endif + case 2: { assert(functionStore()->numberOfModels() > 0); functionStore()->removeModel(m_record); diff --git a/apps/shared/list_parameter_controller.h b/apps/shared/list_parameter_controller.h index 4ef2b616e..24dd45642 100644 --- a/apps/shared/list_parameter_controller.h +++ b/apps/shared/list_parameter_controller.h @@ -3,6 +3,7 @@ #include #include "function_store.h" +#include "color_parameter_controller.h" #include namespace Shared { @@ -31,22 +32,17 @@ public: protected: virtual bool handleEnterOnRow(int rowIndex); virtual int totalNumberOfCells() const { -#if FUNCTION_COLOR_CHOICE return 3; -#else - return 2; -#endif } FunctionStore * functionStore(); ExpiringPointer function(); SelectableTableView m_selectableTableView; Ion::Storage::Record m_record; private: -#if FUNCTION_COLOR_CHOICE MessageTableCellWithChevron m_colorCell; -#endif MessageTableCellWithSwitch m_enableCell; MessageTableCell m_deleteCell; + ColorParameterController m_colorParameterController; }; }