aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/AsciiRenderer.cpp97
-rw-r--r--src/ui/AsciiRenderer.h33
2 files changed, 130 insertions, 0 deletions
diff --git a/src/ui/AsciiRenderer.cpp b/src/ui/AsciiRenderer.cpp
new file mode 100644
index 0000000..0f17d85
--- /dev/null
+++ b/src/ui/AsciiRenderer.cpp
@@ -0,0 +1,97 @@
+/*
+ * Renderer.cpp
+ *
+ * Created on: Nov 23, 2017
+ * Author: naopross
+ */
+
+#include "AsciiRenderer.h"
+
+#include <memory>
+
+namespace samb {
+
+AsciiRenderer::AsciiRenderer(Structogram& structogram, unsigned int width):
+ m_structogram(structogram), m_width(width) {}
+
+AsciiRenderer::~AsciiRenderer() {}
+
+void AsciiRenderer::drawPadding(unsigned int amt) {
+ while (amt--) {
+ std::cout << " ";
+ }
+}
+
+void AsciiRenderer::drawLine() const {
+ for (unsigned int i = 0; i < m_width; i++) {
+ std::cout << "-";
+ }
+
+ std::cout << std::endl;
+}
+
+void AsciiRenderer::drawText(std::string text, unsigned int width, std::string before, std::string after) const {
+
+ if (width == 0) {
+ width = m_width;
+ }
+
+ unsigned int textWidth = width - before.length() - after.length();
+
+
+ std::cout << before;
+ for (unsigned int i = 0; i < text.length(); i++) {
+ if (i % textWidth == 0) {
+ std::cout << after << "\n" << before;
+ }
+
+ std::cout << text[i];
+ }
+
+ std::cout << std::endl;
+}
+
+void AsciiRenderer::drawDecision(std::string condition, std::string trueText, std::string falseText, unsigned int width) const {
+ if (width == 0) {
+ width = m_width -2;
+ }
+
+ std::cout << "|";
+
+// drawPadding(width - condition.length());
+}
+
+void AsciiRenderer::render() {
+ const std::list<Statement>& statements = m_structogram.getStatements();
+
+ for (std::list<Statement>::const_iterator it = statements.begin(); it != statements.end(); it++) {
+ Statement st = *it;
+ switch (st.type) {
+ case Statement::Type::PROCESS:
+ drawLine();
+ drawText(st.text);
+ break;
+
+ case Statement::Type::DECISION:
+ drawLine();
+ break;
+
+ case Statement::Type::SWITCH:
+ break;
+
+ case Statement::Type::SCOPE:
+ break;
+
+ case Statement::Type::WHILE:
+ break;
+
+ case Statement::Type::UNTIL:
+ break;
+
+ case Statement::Type::PARALLEL:
+ break;
+ }
+ }
+}
+
+} /* namespace samb */
diff --git a/src/ui/AsciiRenderer.h b/src/ui/AsciiRenderer.h
new file mode 100644
index 0000000..4f9020a
--- /dev/null
+++ b/src/ui/AsciiRenderer.h
@@ -0,0 +1,33 @@
+/*
+ * Renderer.h
+ *
+ * Created on: Nov 23, 2017
+ * Author: naopross
+ */
+
+#ifndef SRC_UI_ASCIIRENDERER_H_
+#define SRC_UI_ASCIIRENDERER_H_
+
+#include "../diagram/Structogram.h"
+
+namespace samb {
+
+class AsciiRenderer {
+private:
+ Structogram m_structogram;
+ const unsigned int m_width;
+
+ void drawPadding(unsigned int amt);
+ void drawLine() const;
+ void drawText(std::string text, unsigned int width = 0, std::string before = "|", std::string after = "|") const;
+ void drawDecision(std::string condition, std::string trueText, std::string falseText, unsigned int width = 0) const;
+public:
+ AsciiRenderer(Structogram& structogram, unsigned int width);
+ ~AsciiRenderer();
+
+ void render();
+};
+
+} /* namespace samb */
+
+#endif /* SRC_UI_ASCIIRENDERER_H_ */