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 - tigerBellySleeper

Pages: [1]
1
Graphics / Blinking Functionality to the Cursor
« on: April 03, 2021, 06:49:13 pm »
I have created a Typing Class that displays keyboard events onto an SFML window. I am not trying to create a Cursor class that will show a blinking cursor onto the same SFML window.
My thinking is to have the addEventHandler function read the mouse input, then the actual blinking occurs in my update function. I want the blinking to occur every 500ms, I'm stuck on what else I need to make the blinking occur on the SFML window. Thanks in advance.
class Cursor : public sf::Drawable{
public:
    Cursor();
    void addEventHandler(sf::RenderWindow& window, sf::Event event);
    void update();
    virtual void draw(sf::RenderTarget& window, sf::RenderStates states) const;


private:
    sf::Cursor cursor;
    sf::Clock clock;
    bool showCursor;
    const sf::Time delay;

};
 
////////////////////Cursor.cpp//////////////////////////
#include "Cursor.h"

Cursor::Cursor(){
}

void Cursor::addEventHandler(sf::RenderWindow &window, sf::Event event) {
    if(event.type == sf::Event::MouseButtonPressed)
    {
        std::cout << "Mouse" << std::endl;
        if (cursor.loadFromSystem(sf::Cursor::Arrow)){
            window.setMouseCursor(cursor);
            window.setMouseCursorVisible(true);
        }
    }
}

void Cursor::update() {
    if(clock.getElapsedTime() >= sf::milliseconds(500))
    {
        clock.restart();
        cursor.loadFromSystem(sf::Cursor::Arrow);
        std::cout<<"Update"<<std::endl;
    }
}

void Cursor::draw(sf::RenderTarget &window, sf::RenderStates states) const {

}
 
////////////////////main.cpp//////////////////////////
#include <iostream>
#include "SFML/Graphics.hpp"
#include "Typing.h"
#include "Cursor.h"

int main() {
    sf::RenderWindow window;
    window.create(sf::VideoMode(800,600), "Typing in SFML");
    Typing typing;
    Cursor cursor;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }
            typing.addEventHandler(window, event);
            cursor.addEventHandler(window, event);
        }
        cursor.update();
        typing.update();
        window.clear();
        window.draw(typing);
        window.draw(cursor);
        window.display();
    }
    return 0;
}
 

Pages: [1]
anything