Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - smusman

Pages: [1]
1
Graphics / How to Make a text Scrollable in a rectangle?
« on: March 18, 2018, 08:30:59 am »
I am displaying multiple of lines text inside a rectangle using SFML. Now if my text lines go out of rectangle size vertically, I want to make the text be able scroll using mouse inside the rectangle.

Here is a code for an example:


#include <iostream>
#include <SFML/Graphics.hpp>
using  namespace sf;
using namespace std;

int main()
{
    sf::RenderWindow window(sf::VideoMode(700, 700), "Window");

    RectangleShape rec;
    rec.setFillColor(Color(210,210,210));
    rec.setSize(sf::Vector2f(400,400));
    rec.setPosition(Vector2f(100,100));

    Font font;
    if (!font.loadFromFile("Consolas.ttf"))
    {
        cout<<"Unable to load font"<<endl;
    }

    Text t1[20];
    int text_difference=22;
    int text_incrementer=0;
    for(int var=0;var<20;var++)
    {
    t1[var].setFont(font);
    t1[var].setString("this is a line");
    t1[var].setCharacterSize(20);
    t1[var].setStyle(Text::Bold);
    t1[var].setPosition(Vector2f(110,110+text_incrementer));
    text_incrementer+=text_difference;
    t1[var].setFillColor(Color(255,255,255));
    }



    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(rec);

        for(int i=0; i<20; i++)
        {
            window.draw(t1[i]);
        }

        window.display();
    }

    return 0;
}


 

Please help me write the code which makes the text scroll able.

Pages: [1]