Skip to content

Commit

Permalink
Multiline text files added #33
Browse files Browse the repository at this point in the history
  • Loading branch information
SergNikitin committed Sep 29, 2013
1 parent a0ecd13 commit 8d0fe9f
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 0 deletions.
84 changes: 84 additions & 0 deletions modules/heliumScreenObjects/include/heliumMultilineText.h
Original file line number Diff line number Diff line change
@@ -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 <list>
#include <Polycode.h>

#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

98 changes: 98 additions & 0 deletions modules/heliumScreenObjects/src/heliumMultilineText.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* ========================================================
* Organization: The Green Box
*
* Project name: Helium
* File name: heliumScreenConsole.cpp
* Description: MultilineText Class
* Author: AKindyakov
* ========================================================
*/

#include <iostream>
#include <list>

#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<double>(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<double>((lines_count-visible_lines+n)*textSize) * (lineSpacing+1);
screen->setScreenOffset(0, -offset);
visible_lines += n;
}

0 comments on commit 8d0fe9f

Please sign in to comment.