StringScrollInterpolator

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

ArnaudM
Just popping in
Just popping in
Posts: 5
Joined: Fri Jan 20, 2012 09:02

StringScrollInterpolator

Postby ArnaudM » Thu Feb 02, 2012 09:33

Hi,

I'm added an new interpolator in the source code. It's named StringScrollInterpolator and of course it scrolles the text.
It can be used in the text label to show text too long or other.

The code is very simple :
In the end of CEGUIBasicInterpolators.h

Code: Select all

class CEGUIEXPORT StringScrollInterpolator : public Interpolator
{
public:
    virtual ~StringScrollInterpolator(void) {};

    virtual const String& getType() const;

    virtual String interpolateAbsolute(const String& value1,
                                       const String& value2,
                                       float position);
    virtual String interpolateRelative(const String& base,
                                       const String& value1,
                                       const String& value2,
                                       float position);
    virtual String interpolateRelativeMultiply(const String& base,
            const String& value1,
            const String& value2,
            float position);
protected:
   String combineStrings(const String& str1,
                         const String& str2,
                         float position);
};


In the end of CEGUIBasicInterpolators.cpp

Code: Select all

/********************************************
* String scroll interpolator
********************************************/
const String& StringScrollInterpolator::getType() const
{
    static String type = "StringScroll";
    return type;
}

//----------------------------------------------------------------------------//
String StringScrollInterpolator::interpolateAbsolute(const String& value1,
        const String& value2,
        float position)
{
    return combineStrings(value1, value2, position);
}

//----------------------------------------------------------------------------//
String StringScrollInterpolator::interpolateRelative(const String& base,
        const String& value1,
        const String& value2,
        float position)
{
    return base + combineStrings(value1, value2, position);
}

//----------------------------------------------------------------------------//
String StringScrollInterpolator::interpolateRelativeMultiply(const String& base,
        const String& value1,
        const String& value2,
        float position)
{
    // ????
    return base;
}

//----------------------------------------------------------------------------//
String StringScrollInterpolator::combineStrings(const String& str1,
        const String& str2,
        float position)
{
    String::size_type s1size = str1.size();
    String::size_type s2size = str2.size();
    String fullText = str1 + str2;
    String::size_type maxsize = fullText.size();

    String res("");
    res.resize(maxsize);

    String::size_type startIndex = maxsize * position;
    String::size_type textIntex = 0;
    for(String::size_type i = startIndex; i< maxsize; ++i)
    {
        res[textIntex] = fullText[i];
        ++textIntex;
    }
    for(String::size_type i = 0; i < startIndex; ++i){
        res[textIntex] = fullText[i];
        ++textIntex;
    }

    return res;
}


Finally, add this line in the function AnimationManager from CEGUIAnimationManager.cpp

Code: Select all

    addBasicInterpolator(new StringScrollInterpolator());


To test this animation, you can write this code :

Code: Select all

    // TEST //////////////////////////////
    CEGUI::Animation* anim = CEGUI::AnimationManager::getSingleton().createAnimation("Testing");
    anim->setDuration(10.0f);
    CEGUI::Affector* affector = anim->createAffector("Text", "StringScroll");
    affector->createKeyFrame(0.0f, "     Je suis en train de ");
    affector->createKeyFrame(10.0f, "defiler devant vous !!"));

    CEGUI::AnimationInstance* instance = CEGUI::AnimationManager::getSingleton().instantiateAnimation(anim);
    instance->setTargetWindow(_px_contextualTextWindow);
    instance->start();
    //////////////////////////////////////


Yes I'm French :)

Is it possible to add this sources in cegui source code ?
My name is Arnaud Moura.

Good luck.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: StringScrollInterpolator

Postby Kulik » Thu Feb 02, 2012 10:28

Hi,
cool interpolator!

I think it could be easier to understand (and probably more efficient) if written with substr instead of loops. Could you add comments with some examples so that it's clearer what the code does? It took me a while to figure it out :-)

IMO it can go into CEGUIBase, it's small and very useful.

ArnaudM
Just popping in
Just popping in
Posts: 5
Joined: Fri Jan 20, 2012 09:02

Re: StringScrollInterpolator

Postby ArnaudM » Thu Feb 02, 2012 10:50

Thank you !

I go to replace my loops by substr and I will create an example with perhaps a small video.

I come back.

ArnaudM
Just popping in
Just popping in
Posts: 5
Joined: Fri Jan 20, 2012 09:02

Re: StringScrollInterpolator

Postby ArnaudM » Thu Feb 02, 2012 11:47

New code with substr function :

Code: Select all

String StringScrollInterpolator::combineStrings(const String& str1,
        const String& str2,
        float position)
{
    String fullText = str1 + str2;
    String::size_type maxsize = fullText.size();
    String::size_type startIndex = maxsize * position;
   
    String res = fullText.substr(startIndex, maxsize - 1);
    if( startIndex != 0 )
    {
        res += fullText.substr(0, startIndex - 1);
    }
    return res;
}


A small video : http://www.2shared.com/file/hPDDc8Ea/StringScrollInterpolator.html
Last edited by ArnaudM on Mon Feb 06, 2012 12:53, edited 1 time in total.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: StringScrollInterpolator

Postby Kulik » Mon Feb 06, 2012 11:53

Cool, I will integrate it this evening hopefully.

ArnaudM
Just popping in
Just popping in
Posts: 5
Joined: Fri Jan 20, 2012 09:02

Re: StringScrollInterpolator

Postby ArnaudM » Mon Feb 06, 2012 13:08

I'm changed the code to test if the startIndex is not equal to zero.

Thank to add my code in Cegui. You can add me in the list of contributor, I have others features and bug fixs.

Thank you.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: StringScrollInterpolator

Postby Kulik » Mon Feb 06, 2012 17:24

Hi, you will definitely be added to list of contributors once it's accepted.

However I can't accept it as it is now. It is not presented in unified diff or pull request form. It is also not written for 0.8. And it has no comments in the code.

I also don't really know where to put it since in 0.8 I changed interpolators to be generic using template metaprogramming, so only 5 classes are used for all interpolators. Probably a new file called BasicInterpolators.h again I guess. Maybe more of these will go in.

ArnaudM
Just popping in
Just popping in
Posts: 5
Joined: Fri Jan 20, 2012 09:02

Re: StringScrollInterpolator

Postby ArnaudM » Tue Feb 07, 2012 12:06

Okay, I will update my cegui to 0.8 and I will create a new file called "StringInterpolator".
I don't know when I could write this file with the diff file, but most probably this week-end.


Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: No registered users and 8 guests