[ion] Update the Event model

Change-Id: I41a53caeb7dd8a15e7934f49675f6a53be8fe7be
This commit is contained in:
Romain Goyet
2016-11-09 17:31:26 +01:00
committed by Émilie Feral
parent b220ed5dd8
commit b87f06e3a2
34 changed files with 862 additions and 565 deletions

View File

@@ -42,7 +42,7 @@ VariableBoxController * AppsContainer::variableBoxController() {
}
bool AppsContainer::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Event::F1) {
if (event == Ion::Events::Home) {
switchTo(appAtIndex(0));
return true;
}

View File

@@ -69,28 +69,26 @@ void EditExpressionController::setTextBody(const char * text) {
}
bool EditExpressionController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
{
Calculation calculation = Calculation();
App * calculationApp = (App *)app();
calculation.setContent(textBody(), calculationApp->evaluateContext());
m_calculationStore->push(&calculation);
m_historyController->reload();
m_contentView.mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);
m_contentView.textField()->setText("");
return true;
}
case Ion::Events::Event::ESC:
return true;
case Ion::Events::Event::UP_ARROW:
if (m_calculationStore->numberOfCalculations() > 0) {
app()->setFirstResponder(m_historyController);
}
return true;
default:
return false;
if (event == Ion::Events::OK) {
Calculation calculation = Calculation();
App * calculationApp = (App *)app();
calculation.setContent(textBody(), calculationApp->evaluateContext());
m_calculationStore->push(&calculation);
m_historyController->reload();
m_contentView.mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);
m_contentView.textField()->setText("");
return true;
}
if (event == Ion::Events::Back) {
return true;
}
if (event == Ion::Events::Up) {
if (m_calculationStore->numberOfCalculations() > 0) {
app()->setFirstResponder(m_historyController);
}
return true;
}
return false;
}
void EditExpressionController::didBecomeFirstResponder() {

View File

@@ -30,90 +30,85 @@ void HistoryController::didBecomeFirstResponder() {
}
bool HistoryController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::DOWN_ARROW:
m_selectableTableView.deselectTable();
app()->setFirstResponder(parentResponder());
return true;
case Ion::Events::Event::UP_ARROW:
return true;
case Ion::Events::Event::ENTER:
{
int focusRow = m_selectableTableView.selectedRow();
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
EditExpressionController * editController = (EditExpressionController *)parentResponder();
Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow);
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
editController->setTextBody(calculation->text());
} else {
char buffer[Constant::FloatBufferSizeInScientificMode];
Float(calculation->evaluation()).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
editController->setTextBody(buffer);
}
m_selectableTableView.deselectTable();
app()->setFirstResponder(editController);
return true;
}
case Ion::Events::Event::EQUAL:
{
int focusRow = m_selectableTableView.selectedRow();
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
EditExpressionController * editController = (EditExpressionController *)parentResponder();
Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow);
Calculation newCalculation;
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
newCalculation = *calculation;
} else {
char buffer[Constant::FloatBufferSizeInScientificMode];
Float(calculation->evaluation()).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
App * calculationApp = (App *)app();
newCalculation.setContent(buffer, calculationApp->evaluateContext());
}
m_selectableTableView.deselectTable();
m_calculationStore->push(&newCalculation);
reload();
m_selectableTableView.scrollToCell(0, numberOfRows()-1);
app()->setFirstResponder(editController);
return true;
}
case Ion::Events::Event::DELETE:
{
int focusRow = m_selectableTableView.selectedRow();
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
EditExpressionController * editController = (EditExpressionController *)parentResponder();
m_calculationStore->deleteCalculationAtIndex(focusRow);
m_selectableTableView.deselectTable();
reload();
if (numberOfRows()== 0) {
app()->setFirstResponder(editController);
return true;
}
if (focusRow > 0) {
m_selectableTableView.selectCellAtLocation(0, focusRow-1);
} else {
m_selectableTableView.selectCellAtLocation(0, 0);
}
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
tableViewDidChangeSelection(&m_selectableTableView, 0, m_selectableTableView.selectedRow());
} else {
tableViewDidChangeSelection(&m_selectableTableView, 0, -1);
}
m_selectableTableView.scrollToCell(0, m_selectableTableView.selectedRow());
return true;
}
case Ion::Events::Event::CLEAR:
{
m_calculationStore->deleteAll();
reload();
app()->setFirstResponder(parentResponder());
return true;
}
default:
return false;
if (event == Ion::Events::Down) {
m_selectableTableView.deselectTable();
app()->setFirstResponder(parentResponder());
return true;
}
if (event == Ion::Events::Up) {
return true;
}
if (event == Ion::Events::OK) {
int focusRow = m_selectableTableView.selectedRow();
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
EditExpressionController * editController = (EditExpressionController *)parentResponder();
Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow);
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
editController->setTextBody(calculation->text());
} else {
char buffer[Constant::FloatBufferSizeInScientificMode];
Float(calculation->evaluation()).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
editController->setTextBody(buffer);
}
m_selectableTableView.deselectTable();
app()->setFirstResponder(editController);
return true;
}
if (event == Ion::Events::EXE) {
int focusRow = m_selectableTableView.selectedRow();
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
EditExpressionController * editController = (EditExpressionController *)parentResponder();
Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow);
Calculation newCalculation;
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
newCalculation = *calculation;
} else {
char buffer[Constant::FloatBufferSizeInScientificMode];
Float(calculation->evaluation()).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
App * calculationApp = (App *)app();
newCalculation.setContent(buffer, calculationApp->evaluateContext());
}
m_selectableTableView.deselectTable();
m_calculationStore->push(&newCalculation);
reload();
m_selectableTableView.scrollToCell(0, numberOfRows()-1);
app()->setFirstResponder(editController);
return true;
}
if (event == Ion::Events::Backspace) {
int focusRow = m_selectableTableView.selectedRow();
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
EditExpressionController * editController = (EditExpressionController *)parentResponder();
m_calculationStore->deleteCalculationAtIndex(focusRow);
m_selectableTableView.deselectTable();
reload();
if (numberOfRows()== 0) {
app()->setFirstResponder(editController);
return true;
}
if (focusRow > 0) {
m_selectableTableView.selectCellAtLocation(0, focusRow-1);
} else {
m_selectableTableView.selectCellAtLocation(0, 0);
}
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
tableViewDidChangeSelection(&m_selectableTableView, 0, m_selectableTableView.selectedRow());
} else {
tableViewDidChangeSelection(&m_selectableTableView, 0, -1);
}
m_selectableTableView.scrollToCell(0, m_selectableTableView.selectedRow());
return true;
}
if (event == Ion::Events::Clear) {
m_calculationStore->deleteAll();
reload();
app()->setFirstResponder(parentResponder());
return true;
}
return false;
}
void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) {

View File

@@ -87,32 +87,25 @@ void HistoryViewCell::setSelectedSubviewType(HistoryViewCell::SubviewType subvie
}
bool HistoryViewCell::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::DOWN_ARROW:
if (m_selectedSubviewType == HistoryViewCell::SubviewType::PrettyPrint) {
CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder();
tableView->scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType::Result, tableView->selectedColumn(), tableView->selectedRow());
HistoryViewCell * selectedCell = (HistoryViewCell *)(tableView->selectedCell());
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Result);
app()->setFirstResponder(selectedCell);
selectedCell->reloadCell();
return true;
}
return false;
case Ion::Events::Event::UP_ARROW:
if (m_selectedSubviewType == HistoryViewCell::SubviewType::Result) {
CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder();
tableView->scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType::PrettyPrint, tableView->selectedColumn(), tableView->selectedRow());
HistoryViewCell * selectedCell = (HistoryViewCell *)(tableView->selectedCell());
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::PrettyPrint);
app()->setFirstResponder(selectedCell);
selectedCell->reloadCell();
return true;
}
return false;
default:
return false;
if (event == Ion::Events::Down && m_selectedSubviewType == HistoryViewCell::SubviewType::PrettyPrint) {
CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder();
tableView->scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType::Result, tableView->selectedColumn(), tableView->selectedRow());
HistoryViewCell * selectedCell = (HistoryViewCell *)(tableView->selectedCell());
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Result);
app()->setFirstResponder(selectedCell);
selectedCell->reloadCell();
return true;
}
if (event == Ion::Events::Up && m_selectedSubviewType == HistoryViewCell::SubviewType::Result) {
CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder();
tableView->scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType::PrettyPrint, tableView->selectedColumn(), tableView->selectedRow());
HistoryViewCell * selectedCell = (HistoryViewCell *)(tableView->selectedCell());
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::PrettyPrint);
app()->setFirstResponder(selectedCell);
selectedCell->reloadCell();
return true;
}
return false;
}
}

View File

@@ -39,28 +39,21 @@ bool PrettyPrintView::rightViewIsInvisible() {
}
bool PrettyPrintView::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::RIGHT_ARROW:
if (rightViewIsInvisible()) {
KDCoordinate rightSpace = m_expressionView.bounds().width() - m_manualScrolling - bounds().width();
KDCoordinate scrollAdd = rightSpace > 10 ? 10 : rightSpace;
m_manualScrolling += scrollAdd;
setContentOffset(KDPoint(m_manualScrolling, 0));
return true;
}
return false;
case Ion::Events::Event::LEFT_ARROW:
if (m_manualScrolling > 0) {
KDCoordinate leftSpace = m_manualScrolling;
KDCoordinate scrollSubstract = leftSpace > 10 ? 10 : leftSpace;
m_manualScrolling -= scrollSubstract;
setContentOffset(KDPoint(m_manualScrolling, 0));
return true;
}
return false;
default:
return false;
if (event == Ion::Events::Right && rightViewIsInvisible()) {
KDCoordinate rightSpace = m_expressionView.bounds().width() - m_manualScrolling - bounds().width();
KDCoordinate scrollAdd = rightSpace > 10 ? 10 : rightSpace;
m_manualScrolling += scrollAdd;
setContentOffset(KDPoint(m_manualScrolling, 0));
return true;
}
if (event == Ion::Events::Left && m_manualScrolling > 0) {
KDCoordinate leftSpace = m_manualScrolling;
KDCoordinate scrollSubstract = leftSpace > 10 ? 10 : leftSpace;
m_manualScrolling -= scrollSubstract;
setContentOffset(KDPoint(m_manualScrolling, 0));
return true;
}
return false;
}
}

View File

@@ -9,11 +9,11 @@ TextField::TextField(Responder * parentResponder, char * textBuffer, size_t text
bool TextField::handleEvent(Ion::Events::Event event) {
if (m_currentTextLength == 0 &&
(event == Ion::Events::Event::PRODUCT ||
event == Ion::Events::Event::PLUS ||
event == Ion::Events::Event::MINUS ||
event == Ion::Events::Event::DOT ||
event == Ion::Events::Event::DIVISION)) {
(event == Ion::Events::Multiplication ||
event == Ion::Events::Plus ||
event == Ion::Events::Minus ||
event == Ion::Events::Dot ||
event == Ion::Events::Division)) {
KDSize sizePreviousText = KDText::stringSize(m_textBuffer);
m_textBuffer[m_currentTextLength++] = 'a';
m_textBuffer[m_currentTextLength++] = 'n';

View File

@@ -3,29 +3,26 @@
#include <math.h>
bool ExpressionTextFieldDelegate::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
if (event == Ion::Events::Event::ENTER && Expression::parse(textField->text()) == nullptr) {
if (event == Ion::Events::OK && Expression::parse(textField->text()) == nullptr) {
if (textField->textLength() == 0) {
return true;
}
textField->app()->displayWarning("Attention a la syntaxe jeune padawan");
return true;
}
if (event == Ion::Events::Event::ENTER &&
if (event == Ion::Events::OK &&
isnan(Expression::parse(textField->text())->approximate(*evaluateContext()))) {
textField->app()->displayWarning("Relis ton cours de maths, veux tu?");
return true;
}
// TODO: correct events
//if (event == Ion::Events::Event::TOOLBOX) {
if (event == Ion::Events::Event::F5) {
if (event == Ion::Events::Toolbox) {
AppsContainer * appsContainer = (AppsContainer *)textField->app()->container();
ToolboxController * toolboxController = appsContainer->toolboxController();
toolboxController->setTextFieldCaller(textField);
textField->app()->displayModalViewController(toolboxController, 0.f, 0.f, 50, 50, 0, 50);
return true;
}
//if (event == Ion::Events::Event::VARIABLE_BOX) {
if (event == Ion::Events::Event::SECOND) {
if (event == Ion::Events::Var) {
AppsContainer * appsContainer = (AppsContainer *)textField->app()->container();
VariableBoxController * variableBoxController = appsContainer->variableBoxController();
variableBoxController->setTextFieldCaller(textField);

View File

@@ -51,29 +51,27 @@ void GraphController::didBecomeFirstResponder() {
bool GraphController::handleEvent(Ion::Events::Event event) {
if (m_headerSelected) {
switch (event) {
case Ion::Events::Event::DOWN_ARROW:
if (event == Ion::Events::Down) {
setSelectedButton(-1);
m_headerSelected = false;
return true;
case Ion::Events::Event::UP_ARROW:
setSelectedButton(-1);
app()->setFirstResponder(tabController());
default:
return HeaderViewController::handleEvent(event);
}
if (event == Ion::Events::Up) {
setSelectedButton(-1);
app()->setFirstResponder(tabController());
}
return HeaderViewController::handleEvent(event);
} else {
switch (event) {
case Ion::Events::Event::ENTER:
m_view.moveCursorRight();
return true;
case Ion::Events::Event::UP_ARROW:
setSelectedButton(0);
m_headerSelected = true;
return true;
default:
return false;
if (event == Ion::Events::OK) {
m_view.moveCursorRight();
return true;
}
if (event == Ion::Events::Up) {
setSelectedButton(0);
m_headerSelected = true;
return true;
}
return false;
}
}

View File

@@ -135,22 +135,22 @@ void ListController::editExpression(FunctionExpressionView * functionCell, bool
}
bool ListController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::UP_ARROW:
m_selectableTableView.deselectTable();
assert(m_selectableTableView.selectedRow() == -1);
app()->setFirstResponder(tabController());
return true;
case Ion::Events::Event::ENTER:
return handleEnter();
default:
if ((int)event >= 0x100 || m_selectableTableView.selectedColumn() == 0) {
return false;
}
FunctionExpressionView * functionCell = (FunctionExpressionView *)(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()));
editExpression(functionCell, true, (char)event);
return true;
if (event == Ion::Events::Up) {
m_selectableTableView.deselectTable();
assert(m_selectableTableView.selectedRow() == -1);
app()->setFirstResponder(tabController());
return true;
}
if (event == Ion::Events::OK) {
return handleEnter();
}
if (!event.hasText() || m_selectableTableView.selectedColumn() == 0) {
return false;
}
FunctionExpressionView * functionCell = (FunctionExpressionView *)(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()));
// FIXME: Only first character handled!
editExpression(functionCell, true, event.text()[0]);
return true;
}
bool ListController::handleEnter() {

View File

@@ -39,12 +39,10 @@ void ParameterController::setFunction(Function * function) {
}
bool ParameterController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
return handleEnter();
default:
return false;
if (event == Ion::Events::OK) {
return handleEnter();
}
return false;
}
bool ParameterController::handleEnter() {

View File

@@ -28,12 +28,10 @@ void AbscissaParameterController::didBecomeFirstResponder() {
}
bool AbscissaParameterController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
return handleEnter();
default:
return false;
if (event == Ion::Events::OK) {
return handleEnter();
}
return false;
}
bool AbscissaParameterController::handleEnter() {

View File

@@ -38,12 +38,10 @@ void DerivativeParameterController::didBecomeFirstResponder() {
}
bool DerivativeParameterController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
return handleEnter();
default:
return false;
if (event == Ion::Events::OK) {
return handleEnter();
}
return false;
}
bool DerivativeParameterController::handleEnter() {

View File

@@ -38,12 +38,10 @@ void FunctionParameterController::didBecomeFirstResponder() {
}
bool FunctionParameterController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
return handleEnter();
default:
return false;
if (event == Ion::Events::OK) {
return handleEnter();
}
return false;
}
bool FunctionParameterController::handleEnter() {

View File

@@ -185,64 +185,69 @@ void ValuesController::didBecomeFirstResponder() {
bool ValuesController::handleEvent(Ion::Events::Event event) {
if (m_contentView.tableState() == ContentView::TableState::Empty) {
if (event == Ion::Events::Event::UP_ARROW) {
if (event == Ion::Events::Up) {
app()->setFirstResponder(tabController());
return true;
}
return false;
}
switch (event) {
case Ion::Events::Event::DOWN_ARROW:
if (activeRow() == -1) {
setSelectedButton(-1);
m_selectableTableView.selectCellAtLocation(0,0);
app()->setFirstResponder(&m_selectableTableView);
return true;
}
return false;
case Ion::Events::Event::UP_ARROW:
if (activeRow() == -1) {
setSelectedButton(-1);
app()->setFirstResponder(tabController());
return true;
}
m_selectableTableView.deselectTable();
setSelectedButton(0);
if (event == Ion::Events::Down) {
if (activeRow() == -1) {
setSelectedButton(-1);
m_selectableTableView.selectCellAtLocation(0,0);
app()->setFirstResponder(&m_selectableTableView);
return true;
case Ion::Events::Event::ENTER:
if (activeRow() == -1) {
return HeaderViewController::handleEvent(event);
}
if (activeRow() == 0) {
if (activeColumn() == 0) {
configureAbscissa();
return true;
}
if (isDerivativeColumn(activeColumn())) {
configureDerivativeFunction();
} else {
configureFunction();
}
return true;
}
if (activeColumn() == 0) {
editValue(false);
return true;
}
return false;
default:
if (activeRow() == -1) {
return HeaderViewController::handleEvent(event);
}
if ((int)event < 0x100) {
if (activeColumn() == 0 && activeRow() > 0) {
editValue(true, (char)event);
return true;
}
return false;
}
return false;
}
return false;
}
if (event == Ion::Events::Up) {
if (activeRow() == -1) {
setSelectedButton(-1);
app()->setFirstResponder(tabController());
return true;
}
m_selectableTableView.deselectTable();
setSelectedButton(0);
return true;
}
if (event == Ion::Events::OK) {
if (activeRow() == -1) {
return HeaderViewController::handleEvent(event);
}
if (activeRow() == 0) {
if (activeColumn() == 0) {
configureAbscissa();
return true;
}
if (isDerivativeColumn(activeColumn())) {
configureDerivativeFunction();
} else {
configureFunction();
}
return true;
}
if (activeColumn() == 0) {
editValue(false);
return true;
}
return false;
}
if (activeRow() == -1) {
return HeaderViewController::handleEvent(event);
}
if (event.hasText()) {
if (activeColumn() == 0 && activeRow() > 0) {
// FIXME: Only first character!
editValue(true, event.text()[0]);
return true;
}
return false;
}
return false;
}

View File

@@ -77,17 +77,15 @@ void ValuesParameterController::setIntervalParameterAtIndex(int parameterIndex,
}
bool ValuesParameterController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
editInterval(false);
return true;
default:
if ((int)event >= 0x100) {
return false;
}
editInterval(true, (char)event);
return true;
if (event == Ion::Events::OK) {
editInterval(false);
return true;
}
if (event.hasText()) {
editInterval(true, event.text()[0]); // FIXME: only first char
return true;
}
return false;
}
void ValuesParameterController::editInterval(bool overwrite, char initialDigit) {

View File

@@ -14,13 +14,11 @@ Controller::Controller(Responder * parentResponder, ::AppsContainer * container)
}
bool Controller::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
m_container->switchTo(m_container->appAtIndex(m_selectableTableView.selectedRow()*k_numberOfColumns+m_selectableTableView.selectedColumn()+1));
return true;
default:
return false;
if (event == Ion::Events::OK) {
m_container->switchTo(m_container->appAtIndex(m_selectableTableView.selectedRow()*k_numberOfColumns+m_selectableTableView.selectedColumn()+1));
return true;
}
return false;
}
void Controller::didBecomeFirstResponder() {

View File

@@ -75,21 +75,18 @@ const char * NodeNavigationController::title() const {
}
bool NodeNavigationController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ESC:
return returnToPreviousMenu();
case Ion::Events::Event::ENTER:
{
int selectedRow = m_listViewController.selectedRow();
Node * selectedNode = (Node *)m_listViewController.nodeModel()->children(selectedRow);
if (selectedNode->numberOfChildren() == 0) {
return selectLeaf(selectedNode);
}
return selectSubMenu(selectedNode);
}
default:
return false;
if (event == Ion::Events::Back) {
return returnToPreviousMenu();
}
if (event == Ion::Events::OK) {
int selectedRow = m_listViewController.selectedRow();
Node * selectedNode = (Node *)m_listViewController.nodeModel()->children(selectedRow);
if (selectedNode->numberOfChildren() == 0) {
return selectLeaf(selectedNode);
}
return selectSubMenu(selectedNode);
}
return false;
}
bool NodeNavigationController::returnToPreviousMenu() {

View File

@@ -38,13 +38,11 @@ void Probability::LawController::didBecomeFirstResponder() {
}
bool Probability::LawController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
((Probability::App *)app())->setLaw(App::Law::Normal);
return true;
default:
return false;
if (event == Ion::Events::OK) {
((Probability::App *)app())->setLaw(App::Law::Normal);
return true;
}
return false;
}
int Probability::LawController::numberOfRows() {

View File

@@ -1,7 +1,7 @@
#ifndef ESCHER_RESPONDER_H
#define ESCHER_RESPONDER_H
#include <ion/events.h>
#include <ion.h>
class App;

View File

@@ -27,13 +27,11 @@ void Button::layoutSubviews() {
}
bool Button::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::ENTER:
m_invocation.perform(this);
return true;
default:
return false;
if (event == Ion::Events::OK) {
m_invocation.perform(this);
return true;
}
return false;
}
void Button::setBackgroundColor(KDColor backgroundColor) {

View File

@@ -123,20 +123,20 @@ bool HeaderViewController::setSelectedButton(int selectedButton) {
}
bool HeaderViewController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::LEFT_ARROW:
if (m_contentView.selectedButton() == 0) {
return true;
} else {
setSelectedButton(m_contentView.selectedButton() - 1);
return true;
}
case Ion::Events::Event::RIGHT_ARROW:
setSelectedButton(m_contentView.selectedButton() + 1);
if (event == Ion::Events::Left) {
if (m_contentView.selectedButton() == 0) {
return true;
case Ion::Events::Event::ENTER:
} else {
setSelectedButton(m_contentView.selectedButton() - 1);
return true;
default:
return false;
}
}
if (event == Ion::Events::Right) {
setSelectedButton(m_contentView.selectedButton() + 1);
return true;
}
if (event == Ion::Events::OK) {
return true;
}
return false;
}

View File

@@ -49,18 +49,17 @@ bool InputViewController::handleEvent(Ion::Events::Event event) {
if (!isDisplayingModal()) {
return false;
}
switch (event) {
case Ion::Events::Event::ENTER:
m_successAction.perform(this);
dismissModalViewController();
return true;
case Ion::Events::Event::ESC:
m_failureAction.perform(this);
dismissModalViewController();
return true;
default:
return false;
if (event == Ion::Events::OK) {
m_successAction.perform(this);
dismissModalViewController();
return true;
}
if (event == Ion::Events::Back) {
m_failureAction.perform(this);
dismissModalViewController();
return true;
}
return false;
}
void InputViewController::edit(Responder * caller, const char * initialContent, void * context, Invocation::Action successAction, Invocation::Action failureAction) {

View File

@@ -136,11 +136,9 @@ bool ModalViewController::handleEvent(Ion::Events::Event event) {
if (!m_contentView.isDisplayingModal()) {
return false;
}
switch (event) {
case Ion::Events::Event::ESC:
dismissModalViewController();
return true;
default:
return false;
if (event == Ion::Events::Back) {
dismissModalViewController();
return true;
}
return false;
}

View File

@@ -60,40 +60,29 @@ TableViewCell * SelectableTableView::selectedCell() {
}
bool SelectableTableView::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::DOWN_ARROW:
if (selectCellAtLocation(m_selectedCellX, m_selectedCellY+1)) {
if (m_delegate) {
m_delegate->tableViewDidChangeSelection(this, m_selectedCellX, m_selectedCellY - 1);
}
return true;
}
return false;
case Ion::Events::Event::UP_ARROW:
if (selectCellAtLocation(m_selectedCellX, m_selectedCellY-1)) {
if (m_delegate) {
m_delegate->tableViewDidChangeSelection(this, m_selectedCellX, m_selectedCellY + 1);
}
return true;
}
return false;
case Ion::Events::Event::LEFT_ARROW:
if (selectCellAtLocation(m_selectedCellX-1, m_selectedCellY)) {
if (m_delegate) {
m_delegate->tableViewDidChangeSelection(this, m_selectedCellX + 1, m_selectedCellY);
}
return true;
}
return false;
case Ion::Events::Event::RIGHT_ARROW:
if (selectCellAtLocation(m_selectedCellX+1, m_selectedCellY)) {
if (m_delegate) {
m_delegate->tableViewDidChangeSelection(this, m_selectedCellX - 1, m_selectedCellY);
}
return true;
}
return false;
default:
return false;
if (event == Ion::Events::Down && selectCellAtLocation(m_selectedCellX, m_selectedCellY+1)) {
if (m_delegate) {
m_delegate->tableViewDidChangeSelection(this, m_selectedCellX, m_selectedCellY - 1);
}
return true;
}
if (event == Ion::Events::Up && selectCellAtLocation(m_selectedCellX, m_selectedCellY-1)) {
if (m_delegate) {
m_delegate->tableViewDidChangeSelection(this, m_selectedCellX, m_selectedCellY + 1);
}
return true;
}
if (event == Ion::Events::Left && selectCellAtLocation(m_selectedCellX-1, m_selectedCellY)) {
if (m_delegate) {
m_delegate->tableViewDidChangeSelection(this, m_selectedCellX + 1, m_selectedCellY);
}
return true;
}
if (event == Ion::Events::Right && selectCellAtLocation(m_selectedCellX+1, m_selectedCellY)) {
if (m_delegate) {
m_delegate->tableViewDidChangeSelection(this, m_selectedCellX - 1, m_selectedCellY);
}
return true;
}
return false;
}

View File

@@ -109,7 +109,7 @@ void StackViewController::didBecomeFirstResponder() {
}
bool StackViewController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Event::ESC && m_numberOfChildren > 1) {
if (event == Ion::Events::Back && m_numberOfChildren > 1) {
pop();
return true;
}

View File

@@ -78,24 +78,23 @@ bool TabViewController::handleEvent(Ion::Events::Event event) {
if (app()->firstResponder() != this) {
return false;
}
switch(event) {
case Ion::Events::Event::LEFT_ARROW:
if (m_selectedChildIndex > 0) {
setSelectedTab(m_selectedChildIndex-1);
}
return true;
case Ion::Events::Event::RIGHT_ARROW:
if (m_selectedChildIndex < m_numberOfChildren-1) {
setSelectedTab(m_selectedChildIndex+1);
}
return true;
case Ion::Events::Event::DOWN_ARROW:
case Ion::Events::Event::ENTER:
setActiveTab(m_selectedChildIndex);
return true;
default:
return false;
if (event == Ion::Events::Left) {
if (m_selectedChildIndex > 0) {
setSelectedTab(m_selectedChildIndex-1);
}
return true;
}
if (event == Ion::Events::Right) {
if (m_selectedChildIndex < m_numberOfChildren-1) {
setSelectedTab(m_selectedChildIndex+1);
}
return true;
}
if (event == Ion::Events::Down || event == Ion::Events::OK) {
setActiveTab(m_selectedChildIndex);
return true;
}
return false;
}
/*

View File

@@ -39,42 +39,43 @@ bool TextField::handleEvent(Ion::Events::Event event) {
return true;
}
}
switch (event) {
case Ion::Events::Event::LEFT_ARROW:
if (m_currentCursorPosition > 0) {
m_currentCursorPosition--;
}
return true;
case Ion::Events::Event::RIGHT_ARROW:
if (m_currentCursorPosition < m_currentTextLength) {
m_currentCursorPosition++;
}
return true;
case Ion::Events::Event::DELETE:
if (m_currentCursorPosition > 0) {
reload();
m_currentTextLength--;
m_currentCursorPosition--;
for (int k = m_currentCursorPosition; k < m_currentTextLength; k ++) {
m_textBuffer[k] = m_textBuffer[k+1];
}
m_textBuffer[m_currentTextLength] = 0;
}
return true;
default:
if ((int)event >= 0x100) {
return false;
}
if (m_currentTextLength == 0 || m_currentTextLength-1 < m_textBufferSize) {
for (int k = m_currentTextLength; k > m_currentCursorPosition; k--) {
m_textBuffer[k] = m_textBuffer[k-1];
}
m_textBuffer[++m_currentTextLength] = 0;
m_textBuffer[m_currentCursorPosition++] = (int)event;
reload();
}
return true;
if (event == Ion::Events::Left) {
if (m_currentCursorPosition > 0) {
m_currentCursorPosition--;
}
return true;
}
if (event == Ion::Events::Right) {
if (m_currentCursorPosition < m_currentTextLength) {
m_currentCursorPosition++;
}
return true;
}
if (event == Ion::Events::Backspace) {
if (m_currentCursorPosition > 0) {
reload();
m_currentTextLength--;
m_currentCursorPosition--;
for (int k = m_currentCursorPosition; k < m_currentTextLength; k ++) {
m_textBuffer[k] = m_textBuffer[k+1];
}
m_textBuffer[m_currentTextLength] = 0;
}
return true;
}
if (event.hasText()) {
// FIXME: Only inserting the first letter!
if (m_currentTextLength == 0 || m_currentTextLength-1 < m_textBufferSize) {
for (int k = m_currentTextLength; k > m_currentCursorPosition; k--) {
m_textBuffer[k] = m_textBuffer[k-1];
}
m_textBuffer[++m_currentTextLength] = 0;
m_textBuffer[m_currentCursorPosition++] = event.text()[0];
reload();
}
return true;
}
return false;
}
const char * TextField::text() const {

View File

@@ -1,110 +1,190 @@
#ifndef ION_EVENTS_H
#define ION_EVENTS_H
#include <ion/keyboard.h>
namespace Ion {
namespace Events {
enum class Event {
LEFT_PARENTHESIS = '(', // 0x28
RIGHT_PARENTHESIS = ')', // 0x29
COMMA = ',',
PRODUCT = '*', // 0x2a
PLUS = '+', // 0x2b
MINUS = '-', // 0x2d
DOT = '.', // 0x2e
DIVISION = '/', // 0x2f
ZERO = '0', // 0x30
ONE = '1',
TWO = '2',
THREE = '3',
FOUR = '4',
FIVE = '5',
SIX = '6',
SEVEN = '7',
EIGHT = '8',
NINE = '9',
EQUAL = '=', // 0x3d
UPPER_CASE_A = 'A', // 0x41
UPPER_CASE_B,
UPPER_CASE_C,
UPPER_CASE_D,
UPPER_CASE_E,
UPPER_CASE_F,
UPPER_CASE_G,
UPPER_CASE_H,
UPPER_CASE_I,
UPPER_CASE_J,
UPPER_CASE_K,
UPPER_CASE_L,
UPPER_CASE_M,
UPPER_CASE_N,
UPPER_CASE_O,
UPPER_CASE_P,
UPPER_CASE_Q,
UPPER_CASE_R,
UPPER_CASE_S,
UPPER_CASE_T,
UPPER_CASE_U,
UPPER_CASE_V,
UPPER_CASE_W,
UPPER_CASE_X,
UPPER_CASE_Y,
UPPER_CASE_Z,
POWER = '^', // 0x5e
LOWER_CASE_A = 'a', // 0X61
LOWER_CASE_B,
LOWER_CASE_C,
LOWER_CASE_D,
LOWER_CASE_E,
LOWER_CASE_F,
LOWER_CASE_G,
LOWER_CASE_H,
LOWER_CASE_I,
LOWER_CASE_J,
LOWER_CASE_K,
LOWER_CASE_L,
LOWER_CASE_M,
LOWER_CASE_N,
LOWER_CASE_O,
LOWER_CASE_P,
LOWER_CASE_Q,
LOWER_CASE_R,
LOWER_CASE_S,
LOWER_CASE_T,
LOWER_CASE_U,
LOWER_CASE_V,
LOWER_CASE_W,
LOWER_CASE_X,
LOWER_CASE_Y,
LOWER_CASE_Z,
LEFT_ARROW = 0x100, // events for things outside of ASCII.
RIGHT_ARROW,
UP_ARROW,
DOWN_ARROW,
TRIG_MENU,
DELETE,
PLOT,
F1,
F2,
F3,
F4,
F5,
SECOND,
SHIFT,
ESC,
ENTER,
DIAMOND,
ALPHA,
APPS,
HOME,
MODE,
CATALOG,
CLEAR,
//ERROR = 0xffffffff,
class Event {
public:
static constexpr Event PlainKey(Keyboard::Key k) { return Event((int)k); }
static constexpr Event ShiftKey(Keyboard::Key k) { return Event(k_eventPageSize+(int)k); }
static constexpr Event AlphaKey(Keyboard::Key k) { return Event(2*k_eventPageSize+(int)k); }
static constexpr Event ShiftAlphaKey(Keyboard::Key k) { return Event(3*k_eventPageSize+(int)k); }
constexpr Event(int i) : m_id(i){}
Event(Keyboard::Key key, bool shift, bool alpha);
bool operator ==(const Event &other) const {
return (m_id == other.m_id);
}
const char * text() const;
bool hasText() const;
private:
static constexpr int k_eventPageSize = 54;
uint8_t m_id;
};
Event getEvent();
bool isShiftActive();
bool isAlphaActive();
bool isAlphaLocked();
// Plain
constexpr Event Left = Event::PlainKey(Keyboard::Key::A1);
constexpr Event Up = Event::PlainKey(Keyboard::Key::A2);
constexpr Event Down = Event::PlainKey(Keyboard::Key::A3);
constexpr Event Right = Event::PlainKey(Keyboard::Key::A4);
constexpr Event OK = Event::PlainKey(Keyboard::Key::A5);
constexpr Event Back = Event::PlainKey(Keyboard::Key::A6);
constexpr Event Home = Event::PlainKey(Keyboard::Key::B1);
constexpr Event OnOff = Event::PlainKey(Keyboard::Key::B2);
constexpr Event Shift = Event::PlainKey(Keyboard::Key::C1);
constexpr Event Alpha = Event::PlainKey(Keyboard::Key::C2);
constexpr Event XNT = Event::PlainKey(Keyboard::Key::C3);
constexpr Event Var = Event::PlainKey(Keyboard::Key::C4);
constexpr Event Toolbox = Event::PlainKey(Keyboard::Key::C5);
constexpr Event Backspace = Event::PlainKey(Keyboard::Key::C6);
constexpr Event Exp = Event::PlainKey(Keyboard::Key::D1);
constexpr Event Ln = Event::PlainKey(Keyboard::Key::D2);
constexpr Event Log = Event::PlainKey(Keyboard::Key::D3);
constexpr Event Imaginary = Event::PlainKey(Keyboard::Key::D4);
constexpr Event Comma = Event::PlainKey(Keyboard::Key::D5);
constexpr Event Power = Event::PlainKey(Keyboard::Key::D6);
constexpr Event Sine = Event::PlainKey(Keyboard::Key::E1);
constexpr Event Cosine = Event::PlainKey(Keyboard::Key::E2);
constexpr Event Tangent = Event::PlainKey(Keyboard::Key::E3);
constexpr Event Pi = Event::PlainKey(Keyboard::Key::E4);
constexpr Event Sqrt = Event::PlainKey(Keyboard::Key::E5);
constexpr Event Square = Event::PlainKey(Keyboard::Key::E6);
constexpr Event Seven = Event::PlainKey(Keyboard::Key::F1);
constexpr Event Eight = Event::PlainKey(Keyboard::Key::F2);
constexpr Event Nine = Event::PlainKey(Keyboard::Key::F3);
constexpr Event LeftParenthesis = Event::PlainKey(Keyboard::Key::F4);
constexpr Event RightParenthesis = Event::PlainKey(Keyboard::Key::F5);
constexpr Event Four = Event::PlainKey(Keyboard::Key::G1);
constexpr Event Five = Event::PlainKey(Keyboard::Key::G2);
constexpr Event Six = Event::PlainKey(Keyboard::Key::G3);
constexpr Event Multiplication = Event::PlainKey(Keyboard::Key::G4);
constexpr Event Division = Event::PlainKey(Keyboard::Key::G5);
constexpr Event One = Event::PlainKey(Keyboard::Key::H1);
constexpr Event Two = Event::PlainKey(Keyboard::Key::H2);
constexpr Event Three = Event::PlainKey(Keyboard::Key::H3);
constexpr Event Plus = Event::PlainKey(Keyboard::Key::H4);
constexpr Event Minus = Event::PlainKey(Keyboard::Key::H5);
constexpr Event Zero = Event::PlainKey(Keyboard::Key::I1);
constexpr Event Dot = Event::PlainKey(Keyboard::Key::I2);
constexpr Event EE = Event::PlainKey(Keyboard::Key::I3);
constexpr Event Ans = Event::PlainKey(Keyboard::Key::I4);
constexpr Event EXE = Event::PlainKey(Keyboard::Key::I5);
// Shift
constexpr Event AlphaLock = Event::ShiftKey(Keyboard::Key::C2);
constexpr Event Cut = Event::ShiftKey(Keyboard::Key::C3);
constexpr Event Copy = Event::ShiftKey(Keyboard::Key::C4);
constexpr Event Paste = Event::ShiftKey(Keyboard::Key::C5);
constexpr Event Clear = Event::ShiftKey(Keyboard::Key::C6);
constexpr Event LeftBracket = Event::ShiftKey(Keyboard::Key::D1);
constexpr Event RightBracket = Event::ShiftKey(Keyboard::Key::D2);
constexpr Event LeftBrace = Event::ShiftKey(Keyboard::Key::D3);
constexpr Event RightBrace = Event::ShiftKey(Keyboard::Key::D4);
constexpr Event Underscore = Event::ShiftKey(Keyboard::Key::D5);
constexpr Event Sto = Event::ShiftKey(Keyboard::Key::D6);
constexpr Event Arcsine = Event::ShiftKey(Keyboard::Key::E1);
constexpr Event Arccosine = Event::ShiftKey(Keyboard::Key::E2);
constexpr Event Arctangent = Event::ShiftKey(Keyboard::Key::E3);
constexpr Event Equal = Event::ShiftKey(Keyboard::Key::E4);
constexpr Event Lower = Event::ShiftKey(Keyboard::Key::E5);
constexpr Event Greater = Event::ShiftKey(Keyboard::Key::E6);
// Alpha
constexpr Event Colon = Event::AlphaKey(Keyboard::Key::C3);
constexpr Event SemiColon = Event::AlphaKey(Keyboard::Key::C4);
constexpr Event DoubleQuotes = Event::AlphaKey(Keyboard::Key::C5);
constexpr Event LowerA = Event::AlphaKey(Keyboard::Key::D1);
constexpr Event LowerB = Event::AlphaKey(Keyboard::Key::D2);
constexpr Event LowerC = Event::AlphaKey(Keyboard::Key::D3);
constexpr Event LowerD = Event::AlphaKey(Keyboard::Key::D4);
constexpr Event LowerE = Event::AlphaKey(Keyboard::Key::D5);
constexpr Event LowerF = Event::AlphaKey(Keyboard::Key::D6);
constexpr Event LowerG = Event::AlphaKey(Keyboard::Key::E1);
constexpr Event LowerH = Event::AlphaKey(Keyboard::Key::E2);
constexpr Event LowerI = Event::AlphaKey(Keyboard::Key::E3);
constexpr Event LowerJ = Event::AlphaKey(Keyboard::Key::E4);
constexpr Event LowerK = Event::AlphaKey(Keyboard::Key::E5);
constexpr Event LowerL = Event::AlphaKey(Keyboard::Key::E6);
constexpr Event LowerM = Event::AlphaKey(Keyboard::Key::F1);
constexpr Event LowerN = Event::AlphaKey(Keyboard::Key::F2);
constexpr Event LowerO = Event::AlphaKey(Keyboard::Key::F3);
constexpr Event LowerP = Event::AlphaKey(Keyboard::Key::F4);
constexpr Event LowerQ = Event::AlphaKey(Keyboard::Key::F5);
constexpr Event LowerR = Event::AlphaKey(Keyboard::Key::G1);
constexpr Event LowerS = Event::AlphaKey(Keyboard::Key::G2);
constexpr Event LowerT = Event::AlphaKey(Keyboard::Key::G3);
constexpr Event LowerU = Event::AlphaKey(Keyboard::Key::G4);
constexpr Event LowerV = Event::AlphaKey(Keyboard::Key::G5);
constexpr Event LowerW = Event::AlphaKey(Keyboard::Key::H1);
constexpr Event LowerX = Event::AlphaKey(Keyboard::Key::H2);
constexpr Event LowerY = Event::AlphaKey(Keyboard::Key::H3);
constexpr Event LowerZ = Event::AlphaKey(Keyboard::Key::H4);
constexpr Event Space = Event::AlphaKey(Keyboard::Key::H5);
constexpr Event Question = Event::AlphaKey(Keyboard::Key::I1);
constexpr Event Exclamation = Event::AlphaKey(Keyboard::Key::I2);
// Shift + Alpha
constexpr Event UpperA = Event::ShiftAlphaKey(Keyboard::Key::D1);
constexpr Event UpperB = Event::ShiftAlphaKey(Keyboard::Key::D2);
constexpr Event UpperC = Event::ShiftAlphaKey(Keyboard::Key::D3);
constexpr Event UpperD = Event::ShiftAlphaKey(Keyboard::Key::D4);
constexpr Event UpperE = Event::ShiftAlphaKey(Keyboard::Key::D5);
constexpr Event UpperF = Event::ShiftAlphaKey(Keyboard::Key::D6);
constexpr Event UpperG = Event::ShiftAlphaKey(Keyboard::Key::E1);
constexpr Event UpperH = Event::ShiftAlphaKey(Keyboard::Key::E2);
constexpr Event UpperI = Event::ShiftAlphaKey(Keyboard::Key::E3);
constexpr Event UpperJ = Event::ShiftAlphaKey(Keyboard::Key::E4);
constexpr Event UpperK = Event::ShiftAlphaKey(Keyboard::Key::E5);
constexpr Event UpperL = Event::ShiftAlphaKey(Keyboard::Key::E6);
constexpr Event UpperM = Event::ShiftAlphaKey(Keyboard::Key::F1);
constexpr Event UpperN = Event::ShiftAlphaKey(Keyboard::Key::F2);
constexpr Event UpperO = Event::ShiftAlphaKey(Keyboard::Key::F3);
constexpr Event UpperP = Event::ShiftAlphaKey(Keyboard::Key::F4);
constexpr Event UpperQ = Event::ShiftAlphaKey(Keyboard::Key::F5);
constexpr Event UpperR = Event::ShiftAlphaKey(Keyboard::Key::G1);
constexpr Event UpperS = Event::ShiftAlphaKey(Keyboard::Key::G2);
constexpr Event UpperT = Event::ShiftAlphaKey(Keyboard::Key::G3);
constexpr Event UpperU = Event::ShiftAlphaKey(Keyboard::Key::G4);
constexpr Event UpperV = Event::ShiftAlphaKey(Keyboard::Key::G5);
constexpr Event UpperW = Event::ShiftAlphaKey(Keyboard::Key::H1);
constexpr Event UpperX = Event::ShiftAlphaKey(Keyboard::Key::H2);
constexpr Event UpperY = Event::ShiftAlphaKey(Keyboard::Key::H3);
constexpr Event UpperZ = Event::ShiftAlphaKey(Keyboard::Key::H4);
}
}

View File

@@ -1,23 +1,26 @@
#ifndef ION_KEYBOARD_H
#define ION_KEYBOARD_H
extern "C" {
#include <stdint.h>
}
namespace Ion {
namespace Keyboard {
enum class Key {
A1 = 0, A2 = 1, A3 = 2, A4 = 3, A5 = 4,
B1 = 5, B2 = 6, B3 = 7, B4 = 8, B5 = 9,
C1 = 10, C2 = 11, C3 = 12, C4 = 13, C5 = 14,
D1, D2, D3, D4, D5,
E1, E2, E3, E4, E5,
F1, F2, F3, F4, F5,
G1, G2, G3, G4, G5,
H1, H2, H3, H4, H5,
I1, I2, I3, I4, I5,
J1, J2, J3, J4, J5
enum class Key : uint8_t {
A1=0, A2=1, A3=2, A4=3, A5=4, A6=5,
B1=6, B2=7, /* B3=8, B4=9, B5=10, B6=11, */
C1=12, C2=13, C3=14, C4=15, C5=16, C6=17,
D1=18, D2=19, D3=20, D4=21, D5=22, D6=23,
E1=24, E2=25, E3=26, E4=27, E5=28, E6=29,
F1=30, F2=31, F3=32, F4=33, F5=34, // F6=35,
G1=36, G2=37, G3=38, G4=39, G5=40, // G6=41,
H1=42, H2=43, H3=44, H4=45, H5=46, // H6=47,
I1=48, I2=49, I3=50, I4=51, I5=52, // I6=53,
};
constexpr int NumberOfKeys = 50;
constexpr int NumberOfKeys = 53;
bool keyDown(Key k);

111
ion/src/device/events.cpp Normal file
View File

@@ -0,0 +1,111 @@
#include <ion.h>
namespace Ion {
namespace Events {
static constexpr char s_textAtIndex[] = { 'A', 0, 'B', 0, 'C', 0,'D', 0};
class EventInfo {
public:
static constexpr EventInfo Undefined() { return EventInfo(0); }
static constexpr EventInfo Textless() { return EventInfo(1); }
static constexpr EventInfo Text(int index) { return EventInfo(index << 2 & 3); }
bool isUndefined() const { return (m_data == 0); }
const char * text() const;
private:
constexpr EventInfo(uint8_t data) : m_data(data) {}
uint8_t m_data;
};
const char * EventInfo::text() const {
if (m_data <= 1) {
return nullptr;
}
return s_textAtIndex + (m_data >> 2);
}
static constexpr EventInfo s_infoForEvent[] = {
EventInfo::Textless(), EventInfo::Textless(), EventInfo::Textless(), EventInfo::Undefined()
};
Event::Event(Keyboard::Key key, bool shift, bool alpha) {
// We're mapping a key, shift and alpha to an event
// This can be a bit more complicated than it seems since we want to fall back:
// for example, alpha-up is just plain up.
// Fallback order :
// alpha-X -> X
// shift-X -> X
// shift-alpha-X -> alpha-X -> X
m_data = 255;// Undefined. FIXME
int noFallbackOffsets[] = {0};
int alphaFallbackOffsets[] = {2*k_eventPageSize, 0};
int shiftFallbackOffsets[] = {k_eventPageSize, 0};
int shiftAlphaFallbackOffsets[] = {3*k_eventPageSize, 2*k_eventPageSize, 0};
int * fallbackOffsets[] = {noFallbackOffsets, shiftFallbackOffsets, alphaFallbackOffsets, shiftAlphaFallbackOffsets};
int * fallbackOffset = fallbackOffsets[shift+2*alpha];
int i=0;
int offset = 0;
do {
offset = fallbackOffset[i++];
m_data = offset + (int)key;
} while (offset > 0 && s_infoForEvent[m_data].isUndefined());
//TODO assert(m_data != 255); //FIXME: Undefined
}
const char * Event::text() const {
EventInfo info = s_infoForEvent[m_data];
return info.text();
}
}
}
#if 0
class Event {
Event(); // Constructor, by the hardware
private:
uint8_t m_data;
};
ActionInfo Event::Action::info() {
return s_actionInfo[(int)this];
}
Event::Event(Key key, bool shift, bool alpha) {
// We're mapping a key, shift and alpha to an action
// This can be a bit more complicated than it seems since we want to fall back:
// for example, alpha-up is just plain up.
// Fallback order :
// alpha-X -> X
// shift-X -> X
// shift-alpha-X -> alpha-X -> X
int noFallbackOffsets[] = {0};
int alphaFallbackOffsets[] = {2*k_actionPageSize, 0};
int shiftFallbackOffsets[] = {k_actionPageSize, 0};
int shiftAlphaFallbackOffsets[] = {3*k_actionPageSize, 2*k_actionPageSize, 0};
int * fallbackOffsets[] = {noFallbackOffsets, shiftFallbackOffsets, alphaFallbackOffsets, shiftAlphaFallbackOffsets};
int * fallbackOffset = fallbackOffsets[shift+2*alpha];
Action action = Action::Undefined;
int action = A
int i=0;
int offset = 0;
do {
offset = fallbackOffset[i++];
action = offset + (int)key;
} while (offset > 0 && action.info().isUndefined());
assert(!action.info().isUndefined());
return action;
}
#endif

View File

@@ -9,7 +9,7 @@ void Ion::Power::suspend() {
Display::Device::suspend();
CM4.SCR()->setSLEEPDEEP(true);
Keyboard::Device::generateWakeUpEventForKey(Ion::Keyboard::Key::J1);
Keyboard::Device::generateWakeUpEventForKey(Ion::Keyboard::Key::B2);
msleep(300);
asm("wfe");

View File

@@ -1,3 +1,4 @@
objs += $(addprefix ion/src/shared/,\
events.o\
events_from_keyboard.o\
)

View File

@@ -1,36 +1,117 @@
#include <ion.h>
const Ion::Events::Event kEventForKeyDown[] = {
Ion::Events::Event::F1, Ion::Events::Event::F2, Ion::Events::Event::F3, Ion::Events::Event::F4, Ion::Events::Event::F5, Ion::Events::Event::SECOND, Ion::Events::Event::SHIFT, Ion::Events::Event::ESC, Ion::Events::Event::LEFT_ARROW, Ion::Events::Event::UP_ARROW, Ion::Events::Event::DIAMOND, Ion::Events::Event::ALPHA, Ion::Events::Event::APPS, Ion::Events::Event::DOWN_ARROW, Ion::Events::Event::RIGHT_ARROW, Ion::Events::Event::HOME, Ion::Events::Event::MODE, Ion::Events::Event::CATALOG, Ion::Events::Event::DELETE, Ion::Events::Event::CLEAR, Ion::Events::Event::LOWER_CASE_X, Ion::Events::Event::LOWER_CASE_Y, Ion::Events::Event::LOWER_CASE_Z, Ion::Events::Event::LOWER_CASE_T, Ion::Events::Event::POWER, Ion::Events::Event::EQUAL, Ion::Events::Event::LEFT_PARENTHESIS, Ion::Events::Event::RIGHT_PARENTHESIS, Ion::Events::Event::COMMA, Ion::Events::Event::DIVISION, Ion::Events::Event::DOT, Ion::Events::Event::SEVEN, Ion::Events::Event::EIGHT, Ion::Events::Event::NINE, Ion::Events::Event::PRODUCT, Ion::Events::Event::UPPER_CASE_E, Ion::Events::Event::FOUR, Ion::Events::Event::FIVE, Ion::Events::Event::SIX, Ion::Events::Event::MINUS, Ion::Events::Event::DOT, Ion::Events::Event::ONE, Ion::Events::Event::TWO, Ion::Events::Event::THREE, Ion::Events::Event::PLUS, Ion::Events::Event::DOT, Ion::Events::Event::ZERO, Ion::Events::Event::DOT, Ion::Events::Event::MINUS, Ion::Events::Event::ENTER
extern "C" {
#include <assert.h>
}
namespace Ion {
namespace Events {
class EventData {
public:
static constexpr EventData Undefined() { return EventData(nullptr); }
static constexpr EventData Textless() { return EventData(k_textless); }
static constexpr EventData Text(const char * text) { return EventData(text); }
bool isUndefined() const { return (m_data == nullptr); }
const char * text() const;
private:
static constexpr const char * k_textless = "";
constexpr EventData(const char * data) : m_data(data) {}
const char * m_data;
};
// Debouncing, qnd change to get_key event.
Ion::Events::Event Ion::Events::getEvent() {
// Let's start by saving which keys we've seen up
bool key_seen_up[Ion::Keyboard::NumberOfKeys];
for (int k=0; k<Ion::Keyboard::NumberOfKeys; k++) {
key_seen_up[k] = !Ion::Keyboard::keyDown((Ion::Keyboard::Key)k);
}
#define TL() EventData::Textless()
#define U() EventData::Undefined()
#define T(x) EventData::Text(x)
// Wait a little to debounce the button.
msleep(10);
static constexpr EventData s_dataForEvent[] = {
// Plain
TL(), TL(), TL(), TL(), TL(), TL(),
TL(), TL(), U(), U(), U(), U(),
TL(), TL(), TL(), TL(), TL(), TL(),
T("exp()"), T("ln()"), T("log()"), T("i"), T(","), T("^"),
T("sin()"), T("cos()"), T("tan()"), T("p"), T("sqrt()"), T("^2"),
T("7"), T("8"), T("9"), T("("), T(")"), U(),
T("4"), T("5"), T("6"), T("*"), T("/"), U(),
T("1"), T("2"), T("3"), T("+"), T("-"), U(),
T("0"), T("."), T("E"), TL(), TL(), U(),
// Shift
U(), U(), U(), U(), U(), U(),
U(), U(), U(), U(), U(), U(),
U(), U(), TL(), TL(), TL(), TL(),
T("["), T("]"), T("{"), T("}"), T("_"), T("sto"),
T("asin()"), T("acos()"), T("atan()"), T("="), T("<"), T(">"),
U(), U(), TL(), TL(), TL(), TL(),
U(), U(), TL(), TL(), TL(), TL(),
U(), U(), TL(), TL(), TL(), TL(),
U(), U(), TL(), TL(), TL(), TL(),
// Alpha
U(), U(), U(), U(), U(), U(),
U(), U(), U(), U(), U(), U(),
U(), U(), U(), T(":"), T(";"), U(),
T("a"), T("b"), T("c"), T("d"), T("e"), T("f"),
T("g"), T("h"), T("i"), T("j"), T("k"), T("l"),
T("m"), T("n"), T("o"), T("p"), T("q"), U(),
T("r"), T("s"), T("t"), T("u"), T("v"), U(),
T("w"), T("x"), T("y"), T("z"), T(" "), U(),
T("?"), T("!"), U(), U(), U(),
// Shift+Alpha
U(), U(), U(), U(), U(), U(),
U(), U(), U(), U(), U(), U(),
U(), U(), U(), U(), U(), U(),
T("A"), T("B"), T("C"), T("D"), T("E"), T("F"),
T("G"), T("H"), T("I"), T("J"), T("K"), T("L"),
T("M"), T("N"), T("O"), T("P"), T("Q"), U(),
T("R"), T("S"), T("T"), T("U"), T("V"), U(),
T("W"), T("X"), T("Y"), T("Z"), T(" "), U(),
U(), U(), U(), U(), U(), U(),
};
/* Let's discard the keys we previously saw up but which aren't anymore: those
* were probably bouncing! */
for (int k=0; k<Ion::Keyboard::NumberOfKeys; k++) {
key_seen_up[k] &= !Ion::Keyboard::keyDown((Ion::Keyboard::Key)k);
}
while (1) {
for (int k=0; k<Ion::Keyboard::NumberOfKeys; k++) {
if (Ion::Keyboard::keyDown((Ion::Keyboard::Key)k)) {
if (key_seen_up[k]) {
return kEventForKeyDown[k];
}
} else {
key_seen_up[k] = true;
}
}
msleep(10);
const char * EventData::text() const {
if (m_data == nullptr || m_data == k_textless) {
return nullptr;
}
return m_data;
}
Event::Event(Keyboard::Key key, bool shift, bool alpha) {
// We're mapping a key, shift and alpha to an event
// This can be a bit more complicated than it seems since we want to fall back:
// for example, alpha-up is just plain up.
// Fallback order :
// shift-X -> X
// alpha-X -> X
// shift-alpha-X -> alpha-X -> X
constexpr uint8_t undefinedEventId = 4*k_eventPageSize;
m_id = undefinedEventId;
int noFallbackOffsets[] = {0};
int shiftFallbackOffsets[] = {k_eventPageSize, 0};
int alphaFallbackOffsets[] = {2*k_eventPageSize, 0};
int shiftAlphaFallbackOffsets[] = {3*k_eventPageSize, 2*k_eventPageSize, 0};
int * fallbackOffsets[] = {noFallbackOffsets, shiftFallbackOffsets, alphaFallbackOffsets, shiftAlphaFallbackOffsets};
int * fallbackOffset = fallbackOffsets[shift+2*alpha];
int i=0;
int offset = 0;
do {
offset = fallbackOffset[i++];
m_id = offset + (int)key;
} while (offset > 0 && s_dataForEvent[m_id].isUndefined());
assert(m_id != undefinedEventId);
}
const char * Event::text() const {
return s_dataForEvent[m_id].text();
}
bool Event::hasText() const {
return text() != nullptr;
}
}
}

View File

@@ -0,0 +1,75 @@
#include <ion.h>
namespace Ion {
namespace Events {
static bool sIsShiftActive = false;
static bool sIsAlphaActive = false;
static bool sIsAlphaLocked = false;
bool isShiftActive() {
return sIsShiftActive;
}
bool isAlphaActive() {
return sIsAlphaActive;
}
bool isAlphaLocked() {
return sIsAlphaLocked;
}
void updateModifiersFromEvent(Event e) {
if (e == Shift) {
sIsShiftActive = !sIsShiftActive;
} else if (e == Alpha) {
if (sIsAlphaLocked) {
sIsAlphaLocked = false;
sIsAlphaActive = false;
} else if (sIsAlphaActive) {
sIsAlphaLocked = true;
sIsAlphaActive = false;
} else {
sIsAlphaActive = true;
}
} else {
sIsShiftActive = false;
sIsAlphaActive = false;
}
}
// Debouncing, and change to get_key event.
Event getEvent() {
// Let's start by saving which keys we've seen up
bool keySeenUp[Keyboard::NumberOfKeys];
for (int k=0; k<Keyboard::NumberOfKeys; k++) {
keySeenUp[k] = !Keyboard::keyDown((Ion::Keyboard::Key)k);
}
// Wait a little to debounce the button.
msleep(10);
/* Let's discard the keys we previously saw up but which aren't anymore: those
* were probably bouncing! */
for (int k=0; k<Keyboard::NumberOfKeys; k++) {
keySeenUp[k] &= !Keyboard::keyDown((Ion::Keyboard::Key)k);
}
while (1) {
for (int k=0; k<Keyboard::NumberOfKeys; k++) {
if (Keyboard::keyDown((Ion::Keyboard::Key)k)) {
if (keySeenUp[k]) {
Event result((Keyboard::Key)k, sIsShiftActive, sIsAlphaActive || sIsAlphaLocked);
updateModifiersFromEvent(result);
return result;
}
} else {
keySeenUp[k] = true;
}
}
msleep(10);
}
}
}
}