diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 134bbe8bd..368818d0c 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -114,8 +114,9 @@ VariableBoxController * AppsContainer::variableBoxController() { void AppsContainer::suspend(bool checkIfPowerKeyReleased) { resetShiftAlphaStatus(); + GlobalPreferences * globalPreferences = GlobalPreferences::sharedGlobalPreferences(); #ifdef EPSILON_BOOT_PROMPT - if (activeApp()->snapshot()!= onBoardingAppSnapshot() && activeApp()->snapshot() != hardwareTestAppSnapshot() && GlobalPreferences::sharedGlobalPreferences()->showPopUp()) { + if (activeApp()->snapshot()!= onBoardingAppSnapshot() && activeApp()->snapshot() != hardwareTestAppSnapshot() && globalPreferences->showPopUp()) { activeApp()->displayModalViewController(&m_promptController, 0.f, 0.f); } #endif @@ -123,7 +124,7 @@ void AppsContainer::suspend(bool checkIfPowerKeyReleased) { /* Ion::Power::suspend() completely shuts down the LCD controller. Therefore * the frame memory is lost. That's why we need to force a window redraw * upon wakeup, otherwise the screen is filled with noise. */ - Ion::Backlight::setBrightness(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()); + Ion::Backlight::setBrightness(globalPreferences->brightnessLevel()); m_backlightDimmingTimer.reset(); window()->redraw(true); } diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index beb2446a7..240e9b60e 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -144,7 +144,8 @@ Calculation::EqualSign Calculation::exactAndApproximateDisplayedOutputsAreEqual( return m_equalSign; } char buffer[k_printedExpressionSize]; - m_equalSign = exactOutput(context).isEqualToItsApproximationLayout(approximateOutput(context), buffer, k_printedExpressionSize, Preferences::sharedPreferences()->angleUnit(), Preferences::sharedPreferences()->displayMode(), Preferences::sharedPreferences()->numberOfSignificantDigits(), *context) ? EqualSign::Equal : EqualSign::Approximation; + Preferences * preferences = Preferences::sharedPreferences(); + m_equalSign = exactOutput(context).isEqualToItsApproximationLayout(approximateOutput(context), buffer, k_printedExpressionSize, preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context) ? EqualSign::Equal : EqualSign::Approximation; return m_equalSign; } diff --git a/apps/global_preferences.cpp b/apps/global_preferences.cpp index 6c93c5e0c..ddc5d5709 100644 --- a/apps/global_preferences.cpp +++ b/apps/global_preferences.cpp @@ -1,15 +1,5 @@ #include "global_preferences.h" -GlobalPreferences::GlobalPreferences() : - m_language(I18n::Language::EN), - m_examMode(ExamMode::Desactivate), -#ifdef EPSILON_BOOT_PROMPT - m_showPopUp(true), -#endif - m_brightnessLevel(Ion::Backlight::MaxBrightness) -{ -} - GlobalPreferences * GlobalPreferences::sharedGlobalPreferences() { static GlobalPreferences globalPreferences; return &globalPreferences; @@ -20,9 +10,7 @@ I18n::Language GlobalPreferences::language() const { } void GlobalPreferences::setLanguage(I18n::Language language) { - if (language != m_language) { - m_language = language; - } + m_language = language; } GlobalPreferences::ExamMode GlobalPreferences::examMode() const { @@ -30,17 +18,13 @@ GlobalPreferences::ExamMode GlobalPreferences::examMode() const { } void GlobalPreferences::setExamMode(ExamMode examMode) { - if (examMode != m_examMode) { - m_examMode = examMode; - } + m_examMode = examMode; } #ifdef EPSILON_BOOT_PROMPT void GlobalPreferences::setShowPopUp(bool showPopUp) { - if (showPopUp != m_showPopUp) { - m_showPopUp = showPopUp; - } + m_showPopUp = showPopUp; } #endif diff --git a/apps/global_preferences.h b/apps/global_preferences.h index 35c7af844..361ee5047 100644 --- a/apps/global_preferences.h +++ b/apps/global_preferences.h @@ -9,7 +9,6 @@ public: Activate, Desactivate }; - GlobalPreferences(); static GlobalPreferences * sharedGlobalPreferences(); I18n::Language language() const; void setLanguage(I18n::Language language); @@ -23,6 +22,13 @@ public: void setBrightnessLevel(int brightnessLevel); constexpr static int NumberOfBrightnessStates = 5; private: + GlobalPreferences() : + m_language(I18n::Language::EN), + m_examMode(ExamMode::Desactivate), +#ifdef EPSILON_BOOT_PROMPT + m_showPopUp(true), +#endif + m_brightnessLevel(Ion::Backlight::MaxBrightness) {} I18n::Language m_language; ExamMode m_examMode; #ifdef EPSILON_BOOT_PROMPT diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index 87a68b7ed..cae5ba05a 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -261,12 +261,13 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const { Poincare::Symbol vn1Symbol(Symbol::SpecialSymbols::vn1); Poincare::Symbol unSymbol(Symbol::SpecialSymbols::un); Poincare::Symbol un1Symbol(Symbol::SpecialSymbols::un1); + Preferences * preferences = Poincare::Preferences::sharedPreferences(); switch (m_type) { case Type::Explicit: { ctx.setValueForSymbol(un, unSymbol); ctx.setValueForSymbol(vn, vnSymbol); - return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)n, ctx, Poincare::Preferences::sharedPreferences()->angleUnit()); + return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)n, ctx, preferences->angleUnit()); } case Type::SingleRecurrence: { @@ -277,7 +278,7 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const { ctx.setValueForSymbol(unm1, unSymbol); ctx.setValueForSymbol(vn, vn1Symbol); ctx.setValueForSymbol(vnm1, vnSymbol); - return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)(n-1), ctx, Poincare::Preferences::sharedPreferences()->angleUnit()); + return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)(n-1), ctx, preferences->angleUnit()); } default: { @@ -291,7 +292,7 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const { ctx.setValueForSymbol(unm2, unSymbol); ctx.setValueForSymbol(vnm1, vn1Symbol); ctx.setValueForSymbol(vnm2, vnSymbol); - return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)(n-2), ctx, Poincare::Preferences::sharedPreferences()->angleUnit()); + return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)(n-2), ctx, preferences->angleUnit()); } } } diff --git a/apps/settings/main_controller.cpp b/apps/settings/main_controller.cpp index 0ca243151..8b8ab6a50 100644 --- a/apps/settings/main_controller.cpp +++ b/apps/settings/main_controller.cpp @@ -69,6 +69,7 @@ void MainController::didBecomeFirstResponder() { } bool MainController::handleEvent(Ion::Events::Event event) { + GlobalPreferences * globalPreferences = GlobalPreferences::sharedGlobalPreferences(); if (m_messageTreeModel->children(selectedRow())->numberOfChildren() == 0) { #if EPSILON_BOOT_PROMPT == EPSILON_BETA_PROMPT if (m_messageTreeModel->children(selectedRow())->label() == I18n::Message::BetaPopUp) { @@ -77,7 +78,7 @@ bool MainController::handleEvent(Ion::Events::Event event) { #endif #ifdef EPSILON_BOOT_PROMPT if (event == Ion::Events::OK || event == Ion::Events::EXE) { - GlobalPreferences::sharedGlobalPreferences()->setShowPopUp(!GlobalPreferences::sharedGlobalPreferences()->showPopUp()); + globalPreferences->setShowPopUp(!globalPreferences->showPopUp()); m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); return true; } @@ -88,7 +89,7 @@ bool MainController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::Right || event == Ion::Events::Left || event == Ion::Events::Plus || event == Ion::Events::Minus) { int delta = Ion::Backlight::MaxBrightness/GlobalPreferences::NumberOfBrightnessStates; int direction = (event == Ion::Events::Right || event == Ion::Events::Plus) ? delta : -delta; - GlobalPreferences::sharedGlobalPreferences()->setBrightnessLevel(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()+direction); + globalPreferences->setBrightnessLevel(globalPreferences->brightnessLevel()+direction); m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); return true; } @@ -184,16 +185,18 @@ int MainController::typeAtLocation(int i, int j) { } void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) { + GlobalPreferences * globalPreferences = GlobalPreferences::sharedGlobalPreferences(); + Preferences * preferences = Preferences::sharedPreferences(); MessageTableCell * myCell = (MessageTableCell *)cell; myCell->setMessage(m_messageTreeModel->children(index)->label()); if (index == 4) { MessageTableCellWithGauge * myGaugeCell = (MessageTableCellWithGauge *)cell; GaugeView * myGauge = (GaugeView *)myGaugeCell->accessoryView(); - myGauge->setLevel((float)GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()/(float)Ion::Backlight::MaxBrightness); + myGauge->setLevel((float)globalPreferences->brightnessLevel()/(float)Ion::Backlight::MaxBrightness); return; } if (index == 5) { - int index = (int)GlobalPreferences::sharedGlobalPreferences()->language()-1; + int index = (int)globalPreferences->language()-1; static_cast(cell)->setSubtitle(I18n::LanguageNames[index]); return; } @@ -201,7 +204,7 @@ void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) { if (index == 7) { MessageTableCellWithSwitch * mySwitchCell = (MessageTableCellWithSwitch *)cell; SwitchView * mySwitch = (SwitchView *)mySwitchCell->accessoryView(); - mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->showPopUp()); + mySwitch->setState(globalPreferences->showPopUp()); return; } #endif @@ -209,16 +212,16 @@ void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) { int childIndex = -1; switch (index) { case 0: - childIndex = (int)Preferences::sharedPreferences()->angleUnit(); + childIndex = (int)preferences->angleUnit(); break; case 1: - childIndex = (int)Preferences::sharedPreferences()->displayMode(); + childIndex = (int)preferences->displayMode(); break; case 2: - childIndex = (int)Preferences::sharedPreferences()->editionMode(); + childIndex = (int)preferences->editionMode(); break; case 3: - childIndex = (int)Preferences::sharedPreferences()->complexFormat(); + childIndex = (int)preferences->complexFormat(); break; } I18n::Message message = childIndex >= 0 ? m_messageTreeModel->children(index)->children(childIndex)->label() : I18n::Message::Default; diff --git a/apps/settings/sub_menu/preferences_controller.cpp b/apps/settings/sub_menu/preferences_controller.cpp index bc6c5d8a6..3305d8fd5 100644 --- a/apps/settings/sub_menu/preferences_controller.cpp +++ b/apps/settings/sub_menu/preferences_controller.cpp @@ -109,32 +109,34 @@ void PreferencesController::willDisplayCellForIndex(HighlightCell * cell, int in } void PreferencesController::setPreferenceWithValueIndex(I18n::Message message, int valueIndex) { + Preferences * preferences = Preferences::sharedPreferences(); if (message == I18n::Message::AngleUnit) { - Preferences::sharedPreferences()->setAngleUnit((Preferences::AngleUnit)valueIndex); + preferences->setAngleUnit((Preferences::AngleUnit)valueIndex); } if (message == I18n::Message::DisplayMode) { - Preferences::sharedPreferences()->setDisplayMode((Preferences::PrintFloatMode)valueIndex); + preferences->setDisplayMode((Preferences::PrintFloatMode)valueIndex); } if (message == I18n::Message::EditionMode) { - Preferences::sharedPreferences()->setEditionMode((Preferences::EditionMode)valueIndex); + preferences->setEditionMode((Preferences::EditionMode)valueIndex); } if (message == I18n::Message::ComplexFormat) { - Preferences::sharedPreferences()->setComplexFormat((Preferences::ComplexFormat)valueIndex); + preferences->setComplexFormat((Preferences::ComplexFormat)valueIndex); } } int PreferencesController::valueIndexForPreference(I18n::Message message) { + Preferences * preferences = Preferences::sharedPreferences(); if (message == I18n::Message::AngleUnit) { - return (int)Preferences::sharedPreferences()->angleUnit(); + return (int)preferences->angleUnit(); } if (message == I18n::Message::DisplayMode) { - return (int)Preferences::sharedPreferences()->displayMode(); + return (int)preferences->displayMode(); } if (message == I18n::Message::EditionMode) { - return (int)Preferences::sharedPreferences()->editionMode(); + return (int)preferences->editionMode(); } if (message == I18n::Message::ComplexFormat) { - return (int)Preferences::sharedPreferences()->complexFormat(); + return (int)preferences->complexFormat(); } return 0; } diff --git a/apps/solver/equation_store.cpp b/apps/solver/equation_store.cpp index 10ce4b447..765dd69e0 100644 --- a/apps/solver/equation_store.cpp +++ b/apps/solver/equation_store.cpp @@ -119,8 +119,9 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) { Expression coefficients[k_maxNumberOfEquations][Expression::k_maxNumberOfVariables]; Expression constants[k_maxNumberOfEquations]; bool isLinear = true; // Invalid the linear system if one equation is non-linear + Preferences * preferences = Preferences::sharedPreferences(); for (int i = 0; i < numberOfDefinedModels(); i++) { - isLinear = isLinear && definedModelAtIndex(i)->standardForm(context).getLinearCoefficients(m_variables, coefficients[i], &constants[i], *context, Preferences::sharedPreferences()->angleUnit()); + isLinear = isLinear && definedModelAtIndex(i)->standardForm(context).getLinearCoefficients(m_variables, coefficients[i], &constants[i], *context, preferences->angleUnit()); if (!isLinear) { // TODO: should we clean pool allocated memory if the system is not linear #if 0 @@ -151,7 +152,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) { assert(numberOfVariables == 1 && numberOfDefinedModels() == 1); char x = m_variables[0]; Expression polynomialCoefficients[Expression::k_maxNumberOfPolynomialCoefficients]; - int degree = definedModelAtIndex(0)->standardForm(context).getPolynomialReducedCoefficients(x, polynomialCoefficients, *context, Preferences::sharedPreferences()->angleUnit()); + int degree = definedModelAtIndex(0)->standardForm(context).getPolynomialReducedCoefficients(x, polynomialCoefficients, *context, preferences->angleUnit()); if (degree == 2) { /* Polynomial degree <= 2*/ m_type = Type::PolynomialMonovariable; @@ -179,7 +180,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) { /* Check for equality between exact and approximate layouts */ if (!m_exactSolutionIdentity[i]) { char buffer[Shared::ExpressionModel::k_expressionBufferSize]; - m_exactSolutionEquality[i] = exactSolutions[i].isEqualToItsApproximationLayout(approximate, buffer, Shared::ExpressionModel::k_expressionBufferSize, Preferences::sharedPreferences()->angleUnit(), Preferences::sharedPreferences()->displayMode(), Preferences::sharedPreferences()->numberOfSignificantDigits(), *context); + m_exactSolutionEquality[i] = exactSolutions[i].isEqualToItsApproximationLayout(approximate, buffer, Shared::ExpressionModel::k_expressionBufferSize, preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context); } } } diff --git a/apps/title_bar_view.cpp b/apps/title_bar_view.cpp index 44bddcc41..097895e57 100644 --- a/apps/title_bar_view.cpp +++ b/apps/title_bar_view.cpp @@ -84,10 +84,11 @@ void TitleBarView::refreshPreferences() { constexpr size_t bufferSize = 13; char buffer[bufferSize]; int numberOfChar = 0; - if (Preferences::sharedPreferences()->displayMode() == Preferences::PrintFloatMode::Scientific) { + Preferences * preferences = Preferences::sharedPreferences(); + if (preferences->displayMode() == Preferences::PrintFloatMode::Scientific) { numberOfChar += strlcpy(buffer, I18n::translate(I18n::Message::Sci), bufferSize); } - if (Preferences::sharedPreferences()->angleUnit() == Preferences::AngleUnit::Radian) { + if (preferences->angleUnit() == Preferences::AngleUnit::Radian) { numberOfChar += strlcpy(buffer+numberOfChar, I18n::translate(I18n::Message::Rad), bufferSize - numberOfChar); } else { numberOfChar += strlcpy(buffer+numberOfChar, I18n::translate(I18n::Message::Deg), bufferSize - numberOfChar); diff --git a/poincare/src/global_context.cpp b/poincare/src/global_context.cpp index bd43d8fc6..3d3c3887f 100644 --- a/poincare/src/global_context.cpp +++ b/poincare/src/global_context.cpp @@ -43,7 +43,8 @@ void GlobalContext::setExpressionForSymbolName(const Expression & expression, co FileName symbolFileName = fileNameForSymbol(symbol); // evaluate before deleting anything (to be able to evaluate A+2->A) - Expression evaluation = expression.isUninitialized() ? Expression() : expression.approximate(context, Preferences::sharedPreferences()->angleUnit(), Preferences::sharedPreferences()->complexFormat()); + Preferences * preferences = Preferences::sharedPreferences(); + Expression evaluation = expression.isUninitialized() ? Expression() : expression.approximate(context, preferences->angleUnit(), preferences->complexFormat()); // Delete any record with same name (as it is going to be override) Ion::Storage::sharedStorage()->recordNamed(symbolFileName.nameWithExtension).destroy();