mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-25 20:27:31 +08:00
Reverse selection are now possible
This commit is contained in:
parent
bb73b8feb0
commit
810ae40b14
@ -15,6 +15,7 @@ struct Box {
|
||||
static auto Intersection(Box a, Box b) -> Box;
|
||||
static auto Union(Box a, Box b) -> Box;
|
||||
bool Contain(int x, int y) const;
|
||||
Box Clean() const;
|
||||
bool IsEmpty() const;
|
||||
bool operator==(const Box& other) const;
|
||||
bool operator!=(const Box& other) const;
|
||||
|
@ -65,6 +65,7 @@ class Screen : public Image {
|
||||
|
||||
bool selection_enabled = false;
|
||||
CapturedMouse selection_pending;
|
||||
Box mouse_selection_region;
|
||||
Box selection_region;
|
||||
std::string selection_text;
|
||||
|
||||
|
@ -843,10 +843,12 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
||||
return false;
|
||||
}
|
||||
selection_enabled = true;
|
||||
selection_region.x_min = mouse.x;
|
||||
selection_region.y_min = mouse.y;
|
||||
selection_region.x_max = mouse.x;
|
||||
selection_region.y_max = mouse.y;
|
||||
mouse_selection_region.x_min = mouse.x;
|
||||
mouse_selection_region.y_min = mouse.y;
|
||||
mouse_selection_region.x_max = mouse.x;
|
||||
mouse_selection_region.y_max = mouse.y;
|
||||
|
||||
selection_region = mouse_selection_region.Clean();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -855,18 +857,22 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
||||
}
|
||||
|
||||
if (mouse.motion == Mouse::Moved) {
|
||||
selection_region.x_max = mouse.x;
|
||||
selection_region.y_max = mouse.y;
|
||||
mouse_selection_region.x_max = mouse.x;
|
||||
mouse_selection_region.y_max = mouse.y;
|
||||
|
||||
selection_region = mouse_selection_region.Clean();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mouse.motion == Mouse::Released) {
|
||||
selection_region.x_max = mouse.x;
|
||||
selection_region.y_max = mouse.y;
|
||||
mouse_selection_region.x_max = mouse.x;
|
||||
mouse_selection_region.y_max = mouse.y;
|
||||
selection_pending = nullptr;
|
||||
|
||||
if (selection_region.x_min == selection_region.x_max &&
|
||||
selection_region.y_min == selection_region.y_max) {
|
||||
selection_region = mouse_selection_region.Clean();
|
||||
|
||||
if (mouse_selection_region.x_min == mouse_selection_region.x_max &&
|
||||
mouse_selection_region.y_min == mouse_selection_region.y_max) {
|
||||
selection_enabled = false;
|
||||
return true;
|
||||
}
|
||||
|
@ -39,6 +39,24 @@ bool Box::Contain(int x, int y) const {
|
||||
y_max >= y;
|
||||
}
|
||||
|
||||
/// @return a copy of box with the x_min <= x_max and y_min <= y_max.
|
||||
/// @ingroup screen
|
||||
Box Box::Clean() const {
|
||||
Box newBox = *this;
|
||||
|
||||
if(newBox.x_min > newBox.x_max)
|
||||
{
|
||||
std::swap(newBox.x_min, newBox.x_max);
|
||||
}
|
||||
|
||||
if(newBox.y_min > newBox.y_max)
|
||||
{
|
||||
std::swap(newBox.y_min, newBox.y_max);
|
||||
}
|
||||
|
||||
return newBox;
|
||||
}
|
||||
|
||||
/// @return whether the box is empty.
|
||||
/// @ingroup screen
|
||||
bool Box::IsEmpty() const {
|
||||
|
Loading…
Reference in New Issue
Block a user