summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-01-07 23:12:00 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-01-07 23:12:00 +0100
commit58d83d0394b81e079bfbb767936f7449235a236d (patch)
treeef7b06381893c82d73c91b52c83c6bd998d05243
parent89de9d2f5d4a05eeefa2cc77e7a4f7dd48b31048 (diff)
downloadtermgl-0.1.tar.gz
added documentationv0.1
-rw-r--r--cInput.h4
-rw-r--r--cObject.h28
-rw-r--r--cObjectHandler.h41
-rw-r--r--cRender.h74
4 files changed, 103 insertions, 44 deletions
diff --git a/cInput.h b/cInput.h
index 9ff2041..e0d1632 100644
--- a/cInput.h
+++ b/cInput.h
@@ -40,6 +40,10 @@ public:
~cInput();
+ /** Reads inputevents
+ * returns event struct
+ * event queu is empty, when sInputEvent.type == _EVENT_NULL
+ */
sInputEvent poll();
private:
diff --git a/cObject.h b/cObject.h
index f9b42c4..a72b1cc 100644
--- a/cObject.h
+++ b/cObject.h
@@ -12,33 +12,49 @@ struct sObject
int sizeX;
int sizeY;
};
-
+/* cObject can be used standalone as well as inherited
+* every cObject has its own framebuffer as well as position viariables to be moveable.
+* cObject is used by cObjectHandler to manage all objects to be displayed
+*/
class cObject : public cRender
{
public:
+ /* Sets the size to _sx x _sy
+ */
cObject(int _sx, int _sy);
- //_sx : SizeX
- //_sy : SizeY
virtual ~cObject();
+ /** Returns current position
+ */
sPos getPosition();
+ /** Sets position to _pos
+ */
void setPosition(sPos _pos);
-
+ /** Sets position by coordinates
+ */
void setPosition(int _x, int _y);
+ /** Returns sObject with framebuffer and current position
+ */
sObject getObject();
+ /** Called by cObjecthandler if cObject is clicked
+ */
virtual void onClick(sPos _pos, unsigned int _button){}
-
+ /** Called by cObjecthandler if cObject is active on keyboard input
+ */
virtual void onChar(unsigned char _c){}
protected: //For child classes
cObject();
-
+ /** For inheriting classes: sets size of framebuffer
+ */
void setSize(int _sx, int _sy);
+ /** For inheriting classes: frees the framebuffer
+ */
void destruct();
private:
diff --git a/cObjectHandler.h b/cObjectHandler.h
index 555b373..010783a 100644
--- a/cObjectHandler.h
+++ b/cObjectHandler.h
@@ -10,40 +10,55 @@
using namespace std;
-//class cObject; //Circular dependency break (Bad practice. I Know.)
+/** Manages cObjects and writes them to screenbuffer
+* forwards input events to cObjects
+*/
class cObjectHandler
{
public:
+ /** *_render: pointer to instance of cRender all objects will be written to
+ */
cObjectHandler(cRender *_render);
+ /** Adds _object to managed objects vector
+ * returns Identifier for newly created vector
+ */
int createObject(cObject *_object);
- //Adds _object to managed objects vector
- //returns Identifier for newly created vector
+ /** Alters position of _object by _pos either relative to old position or Absolute
+ * Depending on selected _mode (_MOVE_RELATIVE / _MOVE_ABSOLUTE).
+ */
int moveObject(int _object, sPos _pos, int _mode);
- //Alters position of _object by _pos either relative to old position or Absolute
- //Depending on selected _mode (_MOVE_RELATIVE / _MOVE_ABSOLUTE).
+ /** removes _object from vector after deleting it
+ */
int destroyObject(int _object);
- //removes _object from vector after deleting it
+ /** writes all objects in objects[] to render buffer
+ */
int write();
- //writes all objects in objects[] to render buffer
+
+ /** Calls onClick of cObject at _pos, focuses Object
+ * returns 0 if successfull, 1 if no Object is at _pos
+ */
int clickEvent(sPos _pos, unsigned int _button);
- //Calls onClick of cObject at _pos, focuses Object
- //returns 0 if successfull, 1 if Object is empty
+ /** Calls onChar of active cObject, default 0
+ * returns 0 if successfull, 1 if no Object or destroyed Object is empty
+ */
int charEvent(unsigned char _c);
- //Calls onChar of active cObject, default 0
- //returns 0 if successfull, 1 if focused Object is empty
+ /** Focuses next Object
+ */
void focusNext();
- //Focuses next Object
+ /**Focuses Object by id.
+ * 0 is empty by default and can be used to unfocus
+ */
void focus(unsigned int _id);
- //Focuses specific Object
+
private:
void buildHitmap();
diff --git a/cRender.h b/cRender.h
index 1334cc3..14b66dd 100644
--- a/cRender.h
+++ b/cRender.h
@@ -64,70 +64,94 @@ struct sPos
int x;
int y;
};
-
+/** cRender manages a framebuffer the size of the console (window) it is run in.
+*/
class cRender
{
public:
+ /** Constructor
+ * sets cBackround[][] to _backround & wColor[][] to _color
+ * Resizes console window for Windows
+ * Sets Size to Console Window Size for Linux. Writes Error for _sx or _sy smaller than Screen. Get by getLastError()
+ */
cRender(char _backound, WORD _color, int _sx, int _sy);
- //Constructor
- //sets cBackround[][] to _backround & wColor[][] to _color
- //Resizes console window for Windows
- //Sets Size to Console Window Size for Linux. Writes Error for _sx or _sy smaller than Screen. Get by getLastError()
virtual ~cRender();
- //frees allocated memory
+ /** Draws _c @ _pos in screenbuffer
+ * Returns _COLLOSION_ if _pos is already set to !cBackround && _overrideCollision isnt set
+ */
int drawPoint(char _c, sPos _pos, bool _overrideCollision, WORD _color);
- //Draws _c @ _pos
- //Returns _COLLOSION_ if _pos is already set to !cBackround && _overrideCollision isnt set
+ /** draws Line from _pos1 to _pos2 in screenbuffer
+ * x Value of pos1 MUSTNT exceed the x value of pos2!
+ */
int drawLine(char _c, sPos _pos1, sPos _pos2, bool _overrideCollision, WORD _color);
- //x Value of pos1 MUSTNT exceed the x value of pos2!
+ /** Draws Text _s @ _pos in screenbuffer
+ * First char is @ _pos
+ */
int drawText(string _s, sPos _pos, WORD _color);
- //Draws Text _s @ _pos
- //First char is @ _pos
+ /** writes rectangle to screenbuffer
+ * x Value of pos1 MUSTNT exceed the x value of pos2!
+ */
int drawRectangle(char _border, char _fill, sPos _pos1, sPos _pos2, WORD _borderColor, WORD _fillColor);
- //x Value of pos1 MUSTNT exceed the x value of pos2!
+ /** Dumps screenbuffer to stdout
+ * prints changed pixels
+ */
int render(void);
- //Prints cScreen
+ /** clears cScreen + wColor
+ * for _forceReRender == true, the bChanged[][] is set to true to force Re-Render of whole Screen
+ * clear(void) calls clear(_forceReRender = false)
+ */
int clear();
int clear(bool _forceReRender);
- //clears cScreen + wColor
- // for _forceReRender == true, the bChanged[][] is set to true to force Re-Render of whole Screen
- // clear(void) calls clear(_forceReRender = false)
+ /** Returns last Error that was not returnable
+ */
int getLastError();
- //Returns last Error that was not returnable
+ /** Returns size of screenbuffer
+ */
sPos getSize();
- //Returns actual Size of screen
protected:
- cRender(); //Empty Constructor for being inheritable
+ /** Empty Constructor for being inheritable
+ */
+ cRender();
+ /** Sets screenbuffer size
+ */
void setBufferSize(sPos _size);
- bool bBlockRender; //Used by children to block render function
+ bool bBlockRender;
+ //* Used by children to block render function
- char **cScreen; //Pixel Map
- WORD **wColor; //Color Map
- bool **bChanged; //Pixel Change Map
+ char **cScreen;
+ //* Pixel Map
+ WORD **wColor;
+ //* Color Map
+ bool **bChanged;
+ //* Pixel Change Map
- char cBackound; //Default backround
+ char cBackound;
+ //* Default backround
WORD wBackColor;
+ //* Default backround color
int sizeX, sizeY;
+ //* Size of screen array
#ifdef _WIN32
HANDLE hstdout;
CONSOLE_SCREEN_BUFFER_INFO csbi;
#endif
- WORD wDefColor; //Default Color
+ WORD wDefColor;
+ //* Default Color
int iLastError;