Skip to content

Commit

Permalink
untested multitext added #33
Browse files Browse the repository at this point in the history
  • Loading branch information
SergNikitin committed Sep 29, 2013
1 parent 8d0fe9f commit c2f1bd2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 47 deletions.
8 changes: 5 additions & 3 deletions modules/heliumScreenObjects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ PROJECT( heliumScreenObjects )
INCLUDE( heliumIncludes )

SET ( heliumScreenObjects_SRCS
${HELIUM_MODULES_DIR}/heliumScreenObjects/src/heliumMultilineText.cpp
${HELIUM_MODULES_DIR}/heliumScreenObjects/src/heliumScreenConsole.cpp
${HELIUM_MODULES_DIR}/heliumScreenObjects/src/heliumScreenObjects.cpp
${HELIUM_MODULES_DIR}/heliumScreenObjects/src/heliumScreenButton.cpp
${HELIUM_MODULES_DIR}/heliumScreenObjects/src/heliumScreenButton.cpp
${HELIUM_MODULES_DIR}/heliumScreenObjects/src/heliumPreparedScreenButton.cpp
)

SET ( heliumScreenObjects_HDRS
${HELIUM_MODULES_DIR}/heliumScreenObjects/include/heliumMultilineText.h
${HELIUM_MODULES_DIR}/heliumScreenObjects/include/heliumScreenConsole.h
${HELIUM_MODULES_DIR}/heliumScreenObjects/include/heliumScreenObjects.h
${HELIUM_MODULES_DIR}/heliumScreenObjects/include/heliumScreenButton.h
${HELIUM_MODULES_DIR}/heliumScreenObjects/include/heliumPreparedScreenButton.h
)
)

ADD_LIBRARY ( heliumScreenObjects STATIC
${heliumScreenObjects_SRCS}
${heliumScreenbjects_HDRS}
${heliumScreenbjects_HDRS}
)

TARGET_LINK_LIBRARIES ( heliumScreenObjects
Expand Down
31 changes: 16 additions & 15 deletions modules/heliumScreenObjects/include/heliumMultilineText.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,43 @@
*
* Project name: Helium
* File name: heliumScreenConsole.h
* Description: ScreenConsole Class
* Author: AKindyakov
* Description: heliumMultilineText Class
* Author:
* ========================================================
*/

#ifndef HELIUM_SCREEN_CONSOLE_INCLUDED
#define HELIUM_SCREEN_CONSOLE_INCLUDED
#ifndef HELIUM_MULTILINE_TEXT_INCLUDED
#define HELIUM_MULTILINE_TEXT_INCLUDED

#include <list>
#include <Polycode.h>

#include "heliumScreenObjects.h"
#include "pathGlobal.h"

class ScreenConsole {
class heliumMultilineText : public PackagedScreenObject {
public:

/**
* Create ScreenConsole
* Create heliumMultilineText
* @param _textSize
* @param _maxVisibleLines
* @param _stackSize
* @param _lineSpacing
* @param _defaultColor
*/
ScreenConsole( int _textSize,
heliumMultilineText( int _textSize,
int _maxVisibleLines,
int _stackSize,
double _lineSpacing = 0.0,
Polycode::Vector3 _defaultColor = Polycode::Vector3(0,0,0) );

virtual ~ScreenConsole();
virtual ~heliumMultilineText();

/**
*
*/
void setPosition( Polycode::Vector3 _defaultColor = Polycode::Vector3(0,0,0) ){};
// void setPosition( Polycode::Vector3 _defaultColor = Polycode::Vector3(0,0,0) ){};

/**
*
Expand All @@ -53,22 +54,22 @@ class ScreenConsole {
* if numToRemove < 0 - remove from the bottom of history
* if no arguements - remove all history
*/
void clear(int linesToRemove);
void clear();
int clear(int linesToRemove);
int clear();

/**
* Add new line to the ScreenConsole
* Add new line to the heliumMultilineText
*/
void newLine();

/**
*
*/
void scroll(int);
// void scroll(int n);

private:
std::list< Polycode::ScreenLabel* > lines;
Polycode::Screen* screen;
Polycode::ScreenShape* shape;

double lineSpacing;
int textSize;
Expand All @@ -80,5 +81,5 @@ class ScreenConsole {
int visible_lines;
};

#endif // HELIUM_SCREEN_CONSOLE_INCLUDED
#endif // HELIUM_MULTILINE_TEXT_INCLUDED

76 changes: 47 additions & 29 deletions modules/heliumScreenObjects/src/heliumMultilineText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,85 @@
*
* Project name: Helium
* File name: heliumScreenConsole.cpp
* Description: MultilineText Class
* Author: AKindyakov
* Description: heliumMultilineText Class
* Author:
* ========================================================
*/

#include <iostream>
#include <list>

#include "heliumMultilineTxt.h"
#include "Polycode2DPhysics.h"

#include "heliumPreparedScreenButton.h"
#include "heliumMultilineText.h"

namespace P = Polycode;

MultilineText::MultilineText(int _textSize, int _maxVisibleLines, int _stackSize, double _lineSpacing, P::Vector3 _defaultColor)
: screen(new P::Screen()),
heliumMultilineText::heliumMultilineText(int _textSize, int _maxVisibleLines, int _stackSize, double _lineSpacing, P::Vector3 _defaultColor)
: shape(new P::ScreenShape(P::ScreenShape::SHAPE_RECT, 300, 100) ),
lines_count(0),
visible_lines(0),
lineSpacing(_lineSpacing),
textSize(_textSize),
maxVisibleLines(_maxVisibleLines),
maxLines(_stackSize),
defaultColor(_defaultColor) {

shape->loadTexture(g_helium_resource_path + "window_background.png");
shape->setPosition(100, 100);

this->heliumAlife = new ScreenButton( shape, new EscapeGame(), NULL );
this->entityType = PackagedScreenObject::ENTITY_COLLISION_ONLY;
this->entityShapeType = P::PhysicsScreenEntity::ENTITY_RECT;
this->alife = 1;

this->newLine();
this->add("Helium MultilineText :");
this->add("I am heliumMultilineText! Now love me!");
this->newLine();
}

MultilineText::~MultilineText() {
heliumMultilineText::~heliumMultilineText() {
this->clear();
}

void MultilineText::add(const char* str) {
void heliumMultilineText::add(const char* str) {
lines.back()->setText(lines.back()->getText() + str);
}

void MultilineText::add(const Polycode::String& str) {
void heliumMultilineText::add(const Polycode::String& str) {
lines.back()->setText(lines.back()->getText() + str);
}

void MultilineText::clear(int linesToRemove) {
int heliumMultilineText::clear(int linesToRemove) {
if (linesToRemove > 0) {
for ( ; linesToRemove != 0; --linesToRemove ) {
screen->removeChild(lines.front());
// delete lines.front();
shape->removeChild(lines.front());
delete lines.front();
lines.pop_front();
}
}
else {
for ( ; linesToRemove != 0; ++linesToRemove) {
screen->removeChild(lines.back());
// delete lines.back();
shape->removeChild(lines.back());
delete lines.back();
lines.pop_back();
}
}
return 0;
}

void MultilineText::clear() {
lines.clear();
int heliumMultilineText::clear() {
while (! lines.empty() ) {
shape->removeChild(lines.back());
delete lines.back();
lines.pop_back();
}
// lines.clear();
return 0;
}

void MultilineText::newLine() {
void heliumMultilineText::newLine() {
//P::String lineBegin = P::String::IntToString(lines_count);
//lineBegin += " : ";
//P::ScreenLabel* label = new P::ScreenLabel(lineBegin, textSize, "mono");
Expand All @@ -75,24 +93,24 @@ void MultilineText::newLine() {
defaultColor.z, 1 );

label->setPosition(4, static_cast<double>(lines_count*textSize)*(lineSpacing+1) );
screen->addChild(label);
shape->addChild(label);

lines.push_back(label);
++lines_count;
if ( visible_lines >= maxVisibleLines ) {
scroll(-1);
}
else {
++visible_lines;
}
// 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;
}
// void heliumMultilineText::scroll(int n) {
// double offset = static_cast<double>((lines_count-visible_lines+n)*textSize) * (lineSpacing+1);
// shape->setScreenOffset(0, -offset);
// visible_lines += n;
// }
5 changes: 5 additions & 0 deletions tests/firstKeyControl/src/wrapClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "heliumGameGlobal.h"
#include "heliumPreparedScreenButton.h"
#include "heliumPreparedSceneObjects.h"
#include "heliumMultilineText.h"

namespace P = Polycode;

Expand Down Expand Up @@ -131,6 +132,10 @@ ProGameObject::ProGameObject( P::Core* _core )

HeliumTextScreenButton textBt(this, "I am a text", new EscapeGame(), 50, 100, 0, 0, "sans", 12);
this->getScreenWorldPt()->addObject( &textBt );

heliumMultilineText multilineTxt(10, 20, 20, 15, P::Vector3(0));
this->getScreenWorldPt()->addObject( &multilineTxt );

}

ProGameObject::~ProGameObject(){
Expand Down

0 comments on commit c2f1bd2

Please sign in to comment.