aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-06-12 20:48:30 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-06-12 20:48:30 +0200
commit7756a11530d9338954922c1df8e57c66a89fbdea (patch)
tree1fc4f9f070de5b1882f5953713f27e02b66a81e5
downloadascedit-7756a11530d9338954922c1df8e57c66a89fbdea.tar.gz
Initial commit
-rw-r--r--.gitignore4
-rw-r--r--Makefile34
-rw-r--r--src/colorpicker.cpp36
-rw-r--r--src/colorpicker.h23
-rw-r--r--src/editor.cpp94
-rw-r--r--src/editor.h37
-rw-r--r--src/main.cpp83
7 files changed, 311 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..85c7c5d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+tags
+obj/
+inc/
+build/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..7ad89e6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,34 @@
+CC = clang
+CFLAGS = -Wall -std=c++11 -Iinc/
+LDFLAGS = -lstdc++ -ltermgl
+BUILDDIR = build
+SOURCEDIR = src
+OBJECTDIR = obj
+
+OUTPUT = ascedit
+
+SRCS = $(wildcard $(SOURCEDIR)/*.cpp)
+OBJS = $(SRCS:.cpp=.o)
+OBJ = $(OBJS:$(SOURCEDIR)/%=$(OBJECTDIR)/%)
+
+build: dir $(OBJ)
+ @echo [LD] $(OBJ)
+ @$(CC) $(CFLAGS) -o $(BUILDDIR)/$(OUTPUT) $(OBJ) $(LDFLAGS)
+
+debug: CFLAGS += -g -D _DEBUG
+debug: build;
+
+dir:
+ @mkdir -p $(OBJECTDIR)
+ @mkdir -p $(BUILDDIR)
+
+$(OBJECTDIR)/%.o: $(SOURCEDIR)/%.cpp
+ @echo [CC] $<
+ @$(CC) $(CFLAGS) -c $< -o $@
+
+.PHONY: clean
+clean:
+ @echo [RM] $(OBJ)
+ @echo [RM] $(BUILDDIR)/$(OUTPUT)
+ @rm -df $(OBJ)
+ @rm -Rdf $(BUILDDIR) $(OBJECTDIR)
diff --git a/src/colorpicker.cpp b/src/colorpicker.cpp
new file mode 100644
index 0000000..f0eb2ea
--- /dev/null
+++ b/src/colorpicker.cpp
@@ -0,0 +1,36 @@
+#include "colorpicker.h"
+
+
+colorpicker::colorpicker()
+{
+ setSize(32,17);
+ update();
+}
+colorpicker::~colorpicker()
+{
+ destruct();
+}
+
+void colorpicker::onClick(sPos _pos, unsigned int _button)
+{
+
+}
+
+uint16_t colorpicker::getColor()
+{
+ return currentFG | (currentBG << 8);
+}
+
+void colorpicker::update()
+{
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ uint16_t xx = x, yy = y;
+ drawText(" ", {2*x,y}, _COL_WHITE | ((16u*yy + xx) << 8));
+ }
+ }
+
+ char text[17];
+ snprintf(text, 16,"asdf");
+ drawText(text, {0,16}, _COL_WHITE_BG | _COL_BLACK);
+}
diff --git a/src/colorpicker.h b/src/colorpicker.h
new file mode 100644
index 0000000..d4619d1
--- /dev/null
+++ b/src/colorpicker.h
@@ -0,0 +1,23 @@
+#include <cObject.h>
+#include <cObjectHandler.h>
+#include <cRender.h>
+#include <cInput.h>
+
+#include <stdint.h>
+
+class colorpicker : public cObject
+{
+
+public:
+ colorpicker();
+ ~colorpicker();
+
+ void onClick(sPos _pos, unsigned int _button);
+
+ uint16_t getColor();
+
+ void update();
+private:
+ uint8_t currentFG;
+ uint8_t currentBG;
+};
diff --git a/src/editor.cpp b/src/editor.cpp
new file mode 100644
index 0000000..f8aafac
--- /dev/null
+++ b/src/editor.cpp
@@ -0,0 +1,94 @@
+#include "editor.h"
+
+editor::editor(sPos _size)
+{
+ setSize(_size.x + 2, _size.y + 2);
+ size = _size;
+
+ currentPosition = {0,0};
+ currentColor = _COL_WHITE | _COL_BLACK_BG;
+ currentChar = ' ';
+ currentMode = 0;
+
+ storage = new cObject(size.x, size.y);
+ storage->drawRectangle(currentChar, currentChar, {0,0}, {size.x-1, size.y-1}, _COL_BLACK_BG | _COL_WHITE, _COL_BLACK_BG | _COL_WHITE);
+ storage->setPosition(1,1);
+
+ drawLine('-', {1,0}, {_size.x, 0}, _COL_DEFAULT);
+ drawLine('-', {1, _size.y + 1}, {_size.x, _size.y + 1}, _COL_DEFAULT);
+ drawLine('|', {0,1}, {0,_size.y}, _COL_DEFAULT);
+ drawLine('|', {_size.x + 1,1}, {_size.x + 1,_size.y}, _COL_DEFAULT);
+
+ drawPoint('+', {0,0} ,_COL_DEFAULT);
+ drawPoint('+', {_size.x + 1,0} ,_COL_DEFAULT);
+ drawPoint('+', {0,_size.y + 1} ,_COL_DEFAULT);
+ drawPoint('+', {_size.x + 1,_size.y + 1} ,_COL_DEFAULT);
+}
+
+editor::~editor()
+{
+ delete storage;
+ destruct();
+}
+
+void editor::onChar(unsigned char _c)
+{
+ storage->drawPoint(_c, currentPosition, _COL_DEFAULT);
+ currentChar = _c;
+ update();
+}
+
+void editor::onClick(sPos _pos, unsigned int _button)
+{
+ if (_pos.x < 1 || _pos.y < 1 || _pos.x > size.x || _pos.y > size.y)
+ return;
+
+ currentPosition = {_pos.x - 1, _pos.y - 1};
+
+ update();
+}
+
+void editor::setCursor(sPos _pos)
+{
+
+ if (_pos.x < 0 || _pos.y < 0 || _pos.x >= size.x || _pos.y >= size.y)
+ return;
+
+ currentPosition = _pos;
+
+ update();
+}
+
+void editor::setColor(uint16_t _color)
+{
+ currentColor = _color;
+
+ update();
+}
+
+void editor::setChar(unsigned char _c)
+{
+ currentChar = _c;
+
+ update();
+}
+
+void editor::update()
+{
+ storage->write(this, {0,0});
+
+ int tx = currentPosition.x + 1;
+ int ty = currentPosition.y + 1;
+
+ drawPoint( cScreen[tx][ty], {tx, ty}, _COL_WHITE_BG | _COL_BLACK);
+
+ char text[5];
+ snprintf(text, 4, "#%c#", currentChar);
+ drawText(text, {0, size.y + 1}, currentColor);
+}
+
+void editor::moveCursor(sPos _relMovement)
+{
+ setCursor({currentPosition.x + _relMovement.x, currentPosition.y + _relMovement.y});
+}
+
diff --git a/src/editor.h b/src/editor.h
new file mode 100644
index 0000000..7c5a848
--- /dev/null
+++ b/src/editor.h
@@ -0,0 +1,37 @@
+#include <cObject.h>
+#include <cObjectHandler.h>
+#include <cRender.h>
+#include <cInput.h>
+
+#include <stdint.h>
+
+class editor : public cObject
+{
+public:
+ editor(sPos _size);
+ ~editor();
+
+ void onChar(unsigned char _c);
+ void onClick(sPos _pos, unsigned int _button);
+ void moveCursor(sPos _relMovement);
+
+ void setCursor(sPos _pos);
+ void setColor(uint16_t _color);
+ void setChar(unsigned char _c);
+
+ void setMode(uint8_t _mode);
+
+ void update();
+private:
+ sPos currentPosition;
+ unsigned char currentChar;
+ uint16_t currentColor;
+ uint8_t currentMode;
+
+ sPos size;
+ unsigned char char_under_cursor;
+
+ cObject *storage;
+
+};
+
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..b6be560
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,83 @@
+#include <cObject.h>
+#include <cObjectHandler.h>
+#include <cRender.h>
+#include <cInput.h>
+
+#include "editor.h"
+#include "colorpicker.h"
+
+class status : public cObject
+{
+public:
+ status(unsigned int width) { setSize(10,5); }
+ ~status() { destruct(); }
+};
+
+int main() {
+ cRender render(' ', _COL_DEFAULT);
+ cObjectHandler handler(&render, true, false);
+ cInput input;
+ render.render();
+
+ editor edit({30,30});
+ unsigned int edit_id = handler.createObject(&edit);
+
+ colorpicker pick;
+ unsigned int pick_id = handler.createObject(&pick);
+
+ handler.moveObject(pick_id, {34, 0}, _MOVE_ABSOLUTE);
+
+ render.setTargetFPS( 60 );
+
+ while ( 1 ){
+ sInputEvent ie = input.poll();
+ if ( ie.type != _EVENT_NULL ) {
+ if ( ie.type == _EVENT_KEY ) {
+ switch ( ie.c ) {
+ case 'A'://up
+ edit.moveCursor({0,-1});
+ break;
+ case 'B'://down
+ edit.moveCursor({0,1});
+ break;
+ case 'D'://Left
+ edit.moveCursor({-1,0});
+ break;
+ case 'C'://Right
+ edit.moveCursor({1,0});
+ break;
+ };//switch
+ }//if
+ else if ( ie.type == _EVENT_MOUSE ) {
+ if ( ie.b == 0 )
+ handler.clickEvent({ie.x, ie.y}, 0);
+ }// if
+ else if ( ie.type == _EVENT_CHAR )
+ {
+ switch ( ie.c )
+ {
+ case 'w':
+ break;
+ case 's':
+ break;
+ case 'g':
+ render.enableDebugInfo(true);
+ break;
+ case 'G':
+ render.enableDebugInfo(false);
+ break;
+ default:
+ handler.charEvent( ie.c );
+ };//switch
+ }//if
+ else if ( ie.type == _EVENT_TERM ) {
+ return 0;
+ }//if
+ }//if
+
+ handler.write();
+ render.render();
+ }
+
+ return 0;
+}