aboutsummaryrefslogtreecommitdiff
path: root/src/cObject.cpp
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 15:04:57 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 15:04:57 +0100
commitf439ae911923ee70937592b1ee535e8e8e133808 (patch)
tree7e23e023d0187caf2d81b26217b3a484bd37f799 /src/cObject.cpp
parent6856fcf08c8c4686ddf9e5cb60862184e15d6f0b (diff)
downloadtermgl-f439ae911923ee70937592b1ee535e8e8e133808.tar.gz
Directory updates
Moved source files to ./src and exmaple and test to ./example Updated Makefile and .doxygen to use those directorys
Diffstat (limited to 'src/cObject.cpp')
-rw-r--r--src/cObject.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/cObject.cpp b/src/cObject.cpp
new file mode 100644
index 0000000..7dc194c
--- /dev/null
+++ b/src/cObject.cpp
@@ -0,0 +1,82 @@
+#include "cObject.h"
+
+cObject::cObject(int _sx, int _sy) : pos({0,0}) , bSizeSet(false)
+{
+ setSize(_sx, _sy);
+}
+
+cObject::~cObject()
+{
+ destruct();
+}
+
+sPos cObject::getPosition()
+{
+ return pos;
+}
+
+void cObject::setPosition(sPos _pos)
+{
+ pos = _pos;
+}
+
+
+void cObject::setPosition(int _x, int _y)
+{
+ pos.x = _x;
+ pos.y = _y;
+}
+
+
+sObject cObject::getObject()
+{
+ return sObject{pos, wColor, cScreen, sizeX, sizeY};
+}
+
+//protected
+cObject::cObject() : pos({0,0}) , bSizeSet(false){}
+
+void cObject::setSize(int _sx, int _sy)
+{
+ if(bSizeSet)
+ return;
+
+ bBlockRender = true; //Block inherited render capabilities of parent
+
+ sizeX = _sx;
+ sizeY = _sy;
+
+ //Initialize 2D array
+ cScreen = (char**) malloc(sizeof *cScreen * _sx);
+ for (int i = 0; i < _sx; i++)
+ cScreen[i] = (char*)malloc(sizeof *cScreen[i] * _sy);
+
+ wColor = (WORD**)malloc(sizeof *wColor * _sx);
+ for (int i = 0; i < _sx; i++)
+ wColor[i] = (WORD*)malloc(sizeof *wColor[i] * _sy);
+
+ for (int i = 0; i < sizeY; i++) {
+ for (int o = 0; o < sizeX; o++) {
+ cScreen[o][i] = NULL;
+ wColor[o][i] = _COL_DEFAULT;
+ }
+ }
+
+ bSizeSet = true;
+}
+
+void cObject::destruct()
+{
+ if(!bSizeSet)
+ return;
+
+ for (int i = 0; i < sizeX; i++) {
+ free(cScreen[i]);
+ free(wColor[i]);
+ }
+
+ free(cScreen);
+ free(wColor);
+
+ bSizeSet = false;
+}