From 0f69b2f47a87c58ea01c4a4ae4157b4ee92a9d89 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Wed, 20 Mar 2019 02:00:56 +0100 Subject: Added forced screen size and mute to cRender for testing --- example/test.cpp | 3 +++ src/cRender.cpp | 32 +++++++++++++++++++++++++++++--- src/cRender.h | 6 ++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/example/test.cpp b/example/test.cpp index 4d9af96..ca6f38e 100644 --- a/example/test.cpp +++ b/example/test.cpp @@ -43,6 +43,9 @@ int main() cObjectHandler screen(&render); cInput input; + render.forceScreenSize({20,20}); + render.mute(true); + ball aball; edge edgeLeft(1,10); edge edgeRight(1,10); diff --git a/src/cRender.cpp b/src/cRender.cpp index 71c4d76..3b4573a 100644 --- a/src/cRender.cpp +++ b/src/cRender.cpp @@ -15,6 +15,9 @@ cRender::cRender(char _backound, WORD _color, unsigned int _sx, unsigned int _sy lastFrameTime = 0; lastRenderTime = 0; + bMute = false; + bLockScreenSize = false; + #ifdef __linux__ //In Linux, setting Console size is not supported, so it gets Size of Console (Window) instead. wDefColor = _COL_DEFAULT; @@ -23,7 +26,7 @@ cRender::cRender(char _backound, WORD _color, unsigned int _sx, unsigned int _sy setAlternateBufferScreen(true); setConsoleCursor(false); - setBufferSize( getConsoleWindowSize() ); + //setBufferSize( getConsoleWindowSize() ); if(sizeX < _sx || sizeY < _sy) //Notify Program tha screen is too small for desired Size iLastError = _ERR_SCREEN_TOO_SMALL_; @@ -40,7 +43,7 @@ cRender::cRender(char _backound, WORD _color, unsigned int _sx, unsigned int _sy #endif //_WIN32 setConsoleEcho(false); - clear(true); //Init backround array + //clear(true); //Init backround array }//render() @@ -240,7 +243,9 @@ int cRender::render(void) int cbuf = sprintf(buffer,"\e[%u;%uH\e[%sm%c\e[0m", i + 1, o + 1, colorstr, cScreen[o][i]); // Position Color Origin is at 1,1 //int cbuf = sprintf(buffer,"\e[%u;%uH%c", i + 1, o + 1, cScreen[o][i]); - write (STDOUT_FILENO, buffer, cbuf); + + if(!bMute) + write (STDOUT_FILENO, buffer, cbuf); #endif //__linux__ } @@ -361,6 +366,9 @@ void cRender::setConsoleCursor(bool _enable) void cRender::setBufferSize(sPos _size) { + if(bLockScreenSize) + return; + if(_size.x == (int)sizeX && _size.y == (int)sizeY) return; @@ -481,3 +489,21 @@ void cRender::waitForFrametime() } + +void cRender::forceScreenSize(sPos _size) +{ + if(_size.x || _size.y) + { + setBufferSize(_size); + bLockScreenSize = true; + } + else + { + bLockScreenSize = false; + } +} + +void cRender::mute(bool _mute) +{ + bMute = _mute; +} diff --git a/src/cRender.h b/src/cRender.h index 19a0367..6aa4cce 100644 --- a/src/cRender.h +++ b/src/cRender.h @@ -142,6 +142,9 @@ public: */ void setTargetFPS(unsigned int _fps); + void forceScreenSize(sPos _size); + + void mute(bool _mute); protected: /** Empty Constructor for being inheritable @@ -156,6 +159,9 @@ protected: bool bBlockRender; //* Used by children to block render function + bool bMute; + bool bLockScreenSize; + char **cScreen; //* Pixel Map WORD **wColor; -- cgit v1.2.3