114 lines
2.5 KiB
C++
114 lines
2.5 KiB
C++
#include "Calculator.h"
|
|
#include "modules/ImguiModule/ImguiModule.h"
|
|
|
|
|
|
Calculator::Calculator(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
|
|
|
name = "Calculator";
|
|
|
|
ImguiModule* im = new ImguiModule(a, h);
|
|
deps[*im] = im;
|
|
}
|
|
|
|
Calculator::~Calculator() {
|
|
|
|
if(app) {
|
|
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
|
im->releaseContext(ImGui::GetCurrentContext());
|
|
}
|
|
}
|
|
|
|
void Calculator::onLoad() {
|
|
|
|
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
|
|
|
if(!im) {
|
|
std::cout << "No ImguiModule for Calculator!\n";
|
|
std::abort();
|
|
}
|
|
|
|
ImGui::SetCurrentContext(im->aquireContext());
|
|
|
|
}
|
|
|
|
void Calculator::run() {
|
|
|
|
if(open) {
|
|
basicCalculator();
|
|
} else {
|
|
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
|
}
|
|
|
|
}
|
|
|
|
void Calculator::basicCalculator() {
|
|
|
|
static bool b = true;
|
|
|
|
static std::string s;
|
|
|
|
if(b) {
|
|
|
|
ImGui::Begin("Basic Calculator", &open);
|
|
|
|
ImGui::InputText("equation", &s);
|
|
|
|
if(ImGui::Button("7")) {
|
|
s += "7";
|
|
}
|
|
ImGui::SameLine();
|
|
if(ImGui::Button("8")) {
|
|
s += "8";
|
|
}
|
|
ImGui::SameLine();
|
|
if(ImGui::Button("9")) {
|
|
s += "9";
|
|
}
|
|
if(ImGui::Button("4")) {
|
|
s += "4";
|
|
}
|
|
ImGui::SameLine();
|
|
if(ImGui::Button("5")) {
|
|
s += "5";
|
|
}
|
|
ImGui::SameLine();
|
|
if(ImGui::Button("6")) {
|
|
s += "6";
|
|
}
|
|
if(ImGui::Button("1")) {
|
|
s += "1";
|
|
}
|
|
ImGui::SameLine();
|
|
if(ImGui::Button("2")) {
|
|
s += "2";
|
|
}
|
|
ImGui::SameLine();
|
|
if(ImGui::Button("3")) {
|
|
s += "3";
|
|
}
|
|
if(ImGui::Button("0")) {
|
|
s += "1";
|
|
}
|
|
ImGui::SameLine();
|
|
if(ImGui::Button(".")) {
|
|
s += "2";
|
|
}
|
|
ImGui::SameLine();
|
|
if(ImGui::Button("")) {
|
|
if(s.back() == ' ') {
|
|
s.pop_back();
|
|
s.pop_back();
|
|
s.pop_back();
|
|
} else {
|
|
s.pop_back();
|
|
}
|
|
}
|
|
|
|
ImGui::End();
|
|
}
|
|
}
|
|
|
|
void Calculator::graphingCalculator() {
|
|
|
|
}
|