diff --git a/modules/heliumScreenObjects/include/heliumMultilineText.h b/modules/heliumScreenObjects/include/heliumMultilineText.h new file mode 100644 index 0000000..fc36d1f --- /dev/null +++ b/modules/heliumScreenObjects/include/heliumMultilineText.h @@ -0,0 +1,84 @@ +/* ======================================================== + * Organization: The Green Box + * + * Project name: Helium + * File name: heliumScreenConsole.h + * Description: ScreenConsole Class + * Author: AKindyakov + * ======================================================== + */ + +#ifndef HELIUM_SCREEN_CONSOLE_INCLUDED +#define HELIUM_SCREEN_CONSOLE_INCLUDED + +#include +#include + +#include "heliumScreenObjects.h" + +class ScreenConsole { +public: + + /** + * Create ScreenConsole + * @param _textSize + * @param _maxVisibleLines + * @param _stackSize + * @param _lineSpacing + * @param _defaultColor + */ + ScreenConsole( int _textSize, + int _maxVisibleLines, + int _stackSize, + double _lineSpacing = 0.0, + Polycode::Vector3 _defaultColor = Polycode::Vector3(0,0,0) ); + + virtual ~ScreenConsole(); + + /** + * + */ + void setPosition( Polycode::Vector3 _defaultColor = Polycode::Vector3(0,0,0) ){}; + + /** + * + */ + void add(const char*); + void add(const Polycode::String&); + + /** + * Remove elements from the top + * @param numToRemove number of removed elements, + * if numToRemove > 0 - remove from the top of history + * if numToRemove < 0 - remove from the bottom of history + * if no arguements - remove all history + */ + void clear(int linesToRemove); + void clear(); + + /** + * Add new line to the ScreenConsole + */ + void newLine(); + + /** + * + */ + void scroll(int); + +private: + std::list< Polycode::ScreenLabel* > lines; + Polycode::Screen* screen; + + double lineSpacing; + int textSize; + int maxVisibleLines; + int maxLines; + Polycode::Vector3 defaultColor; + + int lines_count; + int visible_lines; +}; + +#endif // HELIUM_SCREEN_CONSOLE_INCLUDED + diff --git a/modules/heliumScreenObjects/src/heliumMultilineText.cpp b/modules/heliumScreenObjects/src/heliumMultilineText.cpp new file mode 100644 index 0000000..eb5cab2 --- /dev/null +++ b/modules/heliumScreenObjects/src/heliumMultilineText.cpp @@ -0,0 +1,98 @@ +/* ======================================================== + * Organization: The Green Box + * + * Project name: Helium + * File name: heliumScreenConsole.cpp + * Description: MultilineText Class + * Author: AKindyakov + * ======================================================== + */ + +#include +#include + +#include "heliumMultilineTxt.h" + +namespace P = Polycode; + +MultilineText::MultilineText(int _textSize, int _maxVisibleLines, int _stackSize, double _lineSpacing, P::Vector3 _defaultColor) + : screen(new P::Screen()), + lines_count(0), + visible_lines(0), + lineSpacing(_lineSpacing), + textSize(_textSize), + maxVisibleLines(_maxVisibleLines), + maxLines(_stackSize), + defaultColor(_defaultColor) { + this->newLine(); + this->add("Helium MultilineText :"); + this->newLine(); +} + +MultilineText::~MultilineText() { + this->clear(); +} + +void MultilineText::add(const char* str) { + lines.back()->setText(lines.back()->getText() + str); +} + +void MultilineText::add(const Polycode::String& str) { + lines.back()->setText(lines.back()->getText() + str); +} + +void MultilineText::clear(int linesToRemove) { + if (linesToRemove > 0) { + for ( ; linesToRemove != 0; --linesToRemove ) { + screen->removeChild(lines.front()); + // delete lines.front(); + lines.pop_front(); + } + } + else { + for ( ; linesToRemove != 0; ++linesToRemove) { + screen->removeChild(lines.back()); + // delete lines.back(); + lines.pop_back(); + } + } +} + +void MultilineText::clear() { + lines.clear(); + return 0; +} + +void MultilineText::newLine() { + //P::String lineBegin = P::String::IntToString(lines_count); + //lineBegin += " : "; + //P::ScreenLabel* label = new P::ScreenLabel(lineBegin, textSize, "mono"); + + P::ScreenLabel* label = new P::ScreenLabel("", textSize, "mono"); + + label->setColor( defaultColor.x, + defaultColor.y, + defaultColor.z, 1 ); + + label->setPosition(4, static_cast(lines_count*textSize)*(lineSpacing+1) ); + screen->addChild(label); + + lines.push_back(label); + ++lines_count; + if ( visible_lines >= maxVisibleLines ) { + scroll(-1); + } + else { + ++visible_lines; + } + if ( lines_count > maxLines ) { + this->clear(1); + } + +} + +void MultilineText::scroll(int n) { + double offset = static_cast((lines_count-visible_lines+n)*textSize) * (lineSpacing+1); + screen->setScreenOffset(0, -offset); + visible_lines += n; +}