What you want is a Button and a Drag and Drop behavior. User interacts with your program using the input hardware that he has available (mouse, keyboard, etc...). You can read these inputs using
sf::Events (see detailed description). You can take a look at the available SFML GUI libraries and see if you like what you see, but for learning purposes I would recommend you to make your own button, at least the first one! Buttons are the most basic GUI element and most of the other elements are just specialized buttons.
A
suggestion of how to implement a button.
A button has 3 states:
- non-active: mouse outside of the button.
- hovered: mouse over button AND mouse button not pressed.
- active: mouse over button AND mouse button pressed.
A button also has a trigger, something that happens when it goes from active to hovered (trigger on release) and/or from hovered to active (trigger on press).
Make a button class, create a button, put it in your game loop, update the state according to the mouse state and make a function to be called when the button is triggered. This function will create a new object, a brand new object, the button that you made doesn't even need to know what it just did.
Now your other object also behaves like a button (things happen when you click on it) so you can either inherit from button (not my favorite) or have a button inside it (weeks from now, when you start reading about ECS vs OOP you will understand this better). Now, what's the trigger of this other button?
Let 'drag' be a boolean type inside your object. This button sets drag to true on press and drag to false on release. And then in another part of your game loop you check if the object is being draged and update according to the mouse position.
Easy enough, right?