mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-07-19 01:31:12 +08:00
Reverse selection are now possible
This commit is contained in:
parent
92586f76bc
commit
437439c945
@ -15,6 +15,7 @@ struct Box {
|
|||||||
static auto Intersection(Box a, Box b) -> Box;
|
static auto Intersection(Box a, Box b) -> Box;
|
||||||
static auto Union(Box a, Box b) -> Box;
|
static auto Union(Box a, Box b) -> Box;
|
||||||
bool Contain(int x, int y) const;
|
bool Contain(int x, int y) const;
|
||||||
|
Box Clean() const;
|
||||||
bool IsEmpty() const;
|
bool IsEmpty() const;
|
||||||
bool operator==(const Box& other) const;
|
bool operator==(const Box& other) 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;
|
bool selection_enabled = false;
|
||||||
CapturedMouse selection_pending;
|
CapturedMouse selection_pending;
|
||||||
|
Box mouse_selection_region;
|
||||||
Box selection_region;
|
Box selection_region;
|
||||||
std::string selection_text;
|
std::string selection_text;
|
||||||
|
|
||||||
|
@ -843,10 +843,12 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
selection_enabled = true;
|
selection_enabled = true;
|
||||||
selection_region.x_min = mouse.x;
|
mouse_selection_region.x_min = mouse.x;
|
||||||
selection_region.y_min = mouse.y;
|
mouse_selection_region.y_min = mouse.y;
|
||||||
selection_region.x_max = mouse.x;
|
mouse_selection_region.x_max = mouse.x;
|
||||||
selection_region.y_max = mouse.y;
|
mouse_selection_region.y_max = mouse.y;
|
||||||
|
|
||||||
|
selection_region = mouse_selection_region.Clean();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -855,18 +857,22 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mouse.motion == Mouse::Moved) {
|
if (mouse.motion == Mouse::Moved) {
|
||||||
selection_region.x_max = mouse.x;
|
mouse_selection_region.x_max = mouse.x;
|
||||||
selection_region.y_max = mouse.y;
|
mouse_selection_region.y_max = mouse.y;
|
||||||
|
|
||||||
|
selection_region = mouse_selection_region.Clean();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse.motion == Mouse::Released) {
|
if (mouse.motion == Mouse::Released) {
|
||||||
selection_region.x_max = mouse.x;
|
mouse_selection_region.x_max = mouse.x;
|
||||||
selection_region.y_max = mouse.y;
|
mouse_selection_region.y_max = mouse.y;
|
||||||
selection_pending = nullptr;
|
selection_pending = nullptr;
|
||||||
|
|
||||||
if (selection_region.x_min == selection_region.x_max &&
|
selection_region = mouse_selection_region.Clean();
|
||||||
selection_region.y_min == selection_region.y_max) {
|
|
||||||
|
if (mouse_selection_region.x_min == mouse_selection_region.x_max &&
|
||||||
|
mouse_selection_region.y_min == mouse_selection_region.y_max) {
|
||||||
selection_enabled = false;
|
selection_enabled = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,24 @@ bool Box::Contain(int x, int y) const {
|
|||||||
y_max >= y;
|
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.
|
/// @return whether the box is empty.
|
||||||
/// @ingroup screen
|
/// @ingroup screen
|
||||||
bool Box::IsEmpty() const {
|
bool Box::IsEmpty() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user