diff --git a/Makefile b/Makefile index 32510bc..740111a 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE CFLAGS := -g -Wall -O2 -ffunction-sections \ $(ARCH) $(DEFINES) -CFLAGS += $(INCLUDE) -D__SWITCH__ +CFLAGS += $(INCLUDE) -D__SWITCH__ -DVERSION_NUM=\"$(VERSION)\" -DSTABLE=\"$(STABLE)\" CXXFLAGS := $(CFLAGS) -std=c++17 -O2 -Wno-volatile diff --git a/include/aboutTab.hpp b/include/aboutTab.hpp new file mode 100644 index 0000000..aa13aa7 --- /dev/null +++ b/include/aboutTab.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + +struct AboutTab : public brls::Box +{ + AboutTab(); + + static brls::View* create(); + + private: + BRLS_BIND(brls::Label, versionLabel, "Version Label"); +}; \ No newline at end of file diff --git a/include/calculatorTab.hpp b/include/calculatorTab.hpp index 4d5459d..abd9057 100644 --- a/include/calculatorTab.hpp +++ b/include/calculatorTab.hpp @@ -9,4 +9,13 @@ struct CalculatorTab : public brls::Box static brls::View* create(); private: + void onButtonPressed(char c); + bool onEqualButtonPressed(brls::View *view); + bool onDeleteButtonPressed(brls::View *view); + + void updateScreenBufferFromExpStr(); + void updateScreen(); + + BRLS_BIND(brls::Label, screenLabel, "screen"); + std::string expressionStr = "", screenBuffer; }; \ No newline at end of file diff --git a/resources/i18n/en-US/text.json b/resources/i18n/en-US/text.json index 604d8f5..ba1f80c 100644 --- a/resources/i18n/en-US/text.json +++ b/resources/i18n/en-US/text.json @@ -9,5 +9,10 @@ "calculator": { "expression_enter": "Enter an expression" + }, + + "about": { + "appname": "Calculator_NX", + "developer": "Developed by EmreTech" } } \ No newline at end of file diff --git a/resources/xml/activity/main.xml b/resources/xml/activity/main.xml index 436c419..4bfeb03 100644 --- a/resources/xml/activity/main.xml +++ b/resources/xml/activity/main.xml @@ -11,6 +11,8 @@ - + + + \ No newline at end of file diff --git a/resources/xml/tabs/about.xml b/resources/xml/tabs/about.xml new file mode 100644 index 0000000..7205e03 --- /dev/null +++ b/resources/xml/tabs/about.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/xml/tabs/calculator.xml b/resources/xml/tabs/calculator.xml index 3d26faa..003ce11 100644 --- a/resources/xml/tabs/calculator.xml +++ b/resources/xml/tabs/calculator.xml @@ -13,6 +13,7 @@ height="20%"> + + + + +AboutTab::AboutTab() +{ + this->inflateFromXMLRes("xml/tabs/about.xml"); + versionLabel->setText(VERSION_NUM + std::string(" | ") + STABLE); +} + +brls::View *AboutTab::create() +{ + return new AboutTab(); +} \ No newline at end of file diff --git a/source/calculatorTab.cpp b/source/calculatorTab.cpp index 1e79d71..6acd6c1 100644 --- a/source/calculatorTab.cpp +++ b/source/calculatorTab.cpp @@ -1,11 +1,95 @@ #include +#include +#include + +#include + +std::vector> allButtons { + std::make_pair("(Button", '('), + std::make_pair(")Button", ')'), + std::make_pair("9Button", '9'), + std::make_pair("6Button", '6'), + std::make_pair("3Button", '3'), + std::make_pair("0Button", '0'), + std::make_pair("8Button", '8'), + std::make_pair("5Button", '5'), + std::make_pair("2Button", '2'), + std::make_pair("DotButton", '.'), + std::make_pair("7Button", '7'), + std::make_pair("4Button", '4'), + std::make_pair("1Button", '1'), + std::make_pair("PlusButton", '+'), + std::make_pair("MinusButton", '-'), + std::make_pair("MultiplyButton", '*'), + std::make_pair("DivideButton", '/'), +}; + CalculatorTab::CalculatorTab() { this->inflateFromXMLRes("xml/tabs/calculator.xml"); + + for (auto &e : allButtons) + { + char c = e.second; + + this->getView(e.first)->registerAction( + "", brls::BUTTON_A, + [this, c](brls::View *view) { + onButtonPressed(c); + return true; + }, + false, brls::SOUND_CLICK + ); + } + + BRLS_REGISTER_CLICK_BY_ID("EqualButton", this->onEqualButtonPressed); + BRLS_REGISTER_CLICK_BY_ID("DelButton", this->onDeleteButtonPressed); } brls::View* CalculatorTab::create() { return new CalculatorTab(); +} + +void CalculatorTab::onButtonPressed(char c) +{ + expressionStr += c; + updateScreenBufferFromExpStr(); +} + +bool CalculatorTab::onEqualButtonPressed(brls::View *view) +{ + if (expressionStr != "") + { + double result = Calculator::getInstance().evaluateExpression(expressionStr); + screenBuffer += " = " + std::to_string(result); + updateScreen(); + + expressionStr = ""; + } + return true; +} + +bool CalculatorTab::onDeleteButtonPressed(brls::View *view) +{ + if (expressionStr != "") + { + expressionStr.pop_back(); + updateScreenBufferFromExpStr(); + } + + return true; +} + +void CalculatorTab::updateScreen() +{ + screenLabel->setText(screenBuffer); +} + +void CalculatorTab::updateScreenBufferFromExpStr() +{ + screenBuffer = expressionStr; + if (expressionStr.length() >= 30) + screenBuffer = expressionStr.substr(29); } \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index ad64012..c7a27b5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,21 +1,27 @@ #include +#include #include +#include #include using namespace brls::literals; int main(int argc, char *argv[]) { + //brls::Logger::setLogLevel(brls::LogLevel::DEBUG); + if (!brls::Application::init()) { brls::Logger::error("Unable to init Borealis application"); return EXIT_FAILURE; } - brls::Application::createWindow("Calculator_NX rewrite"); + brls::Application::createWindow("text/title"_i18n); brls::Application::setGlobalQuit(true); brls::Application::registerXMLView("CalculatorTab", CalculatorTab::create); + brls::Application::registerXMLView("AboutTab", AboutTab::create); + brls::Application::pushActivity(new MainActivity()); while (brls::Application::mainLoop());