Suppression d'objets en drag&drop dans éditeur
This commit is contained in:
parent
b4b8aaedac
commit
2daa1e8aa6
|
@ -5,7 +5,7 @@
|
|||
#include "level.hpp"
|
||||
#include "util/widget_timer.hpp"
|
||||
|
||||
enum class DragMode {NONE, PLACE_OBJECTS, SELECT_RECT, SELECT_BULK};
|
||||
enum class DragMode {NONE, PLACE, SELECT_RECT, SELECT_BULK, REMOVE};
|
||||
enum class SelectionMode {REPLACE, FLIP, ADD};
|
||||
|
||||
/**
|
||||
|
|
|
@ -67,22 +67,27 @@ bool Editor::processEvent(const sf::Event& event) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// clic gauche dans le vide : démarrage du placement
|
||||
// en drag&ndrop
|
||||
// clic gauche dans le vide : démarrage du placement en drag&drop
|
||||
drag_start = position;
|
||||
drag_end = position;
|
||||
drag_mode = DragMode::PLACE_OBJECTS;
|
||||
drag_mode = DragMode::PLACE;
|
||||
|
||||
select(addObject(position), SelectionMode::REPLACE);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.mouseButton.button == sf::Mouse::Right) {
|
||||
// clic droit : on supprime l'objet pointé
|
||||
// clic droit sur un objet : démarrage de la suppression en drag&drop
|
||||
if (pointed_object != nullptr) {
|
||||
drag_start = position;
|
||||
drag_end = position;
|
||||
drag_mode = DragMode::REMOVE;
|
||||
|
||||
removeObject(pointed_object);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lorsqu'on déplace la souris
|
||||
if (event.type == sf::Event::MouseMoved) {
|
||||
|
@ -91,11 +96,17 @@ bool Editor::processEvent(const sf::Event& event) {
|
|||
drag_end = position;
|
||||
|
||||
// mode placement d'objets
|
||||
if (drag_mode == DragMode::PLACE_OBJECTS && pointed_object == nullptr) {
|
||||
if (drag_mode == DragMode::PLACE && pointed_object == nullptr) {
|
||||
select(addObject(position), SelectionMode::ADD);
|
||||
return true;
|
||||
}
|
||||
|
||||
// mode suppression d'objets
|
||||
if (drag_mode == DragMode::REMOVE && pointed_object != nullptr) {
|
||||
removeObject(pointed_object);
|
||||
return true;
|
||||
}
|
||||
|
||||
// mode sélection libre : on l'objet à la sélection
|
||||
if (drag_mode == DragMode::SELECT_BULK) {
|
||||
select(position, SelectionMode::ADD);
|
||||
|
@ -228,7 +239,7 @@ void Editor::removeObject(ObjectPtr object) {
|
|||
// on supprime l'objet de la liste d'objets
|
||||
objects.erase(std::remove(
|
||||
objects.begin(), objects.end(), object
|
||||
), selection.end());
|
||||
), objects.end());
|
||||
}
|
||||
|
||||
void Editor::removeObject(sf::Vector2f position) {
|
||||
|
|
Loading…
Reference in New Issue