mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-12-05 01:11:46 +08:00
Compare commits
6 Commits
c1c144a1ac
...
7d2dad77c9
Author | SHA1 | Date | |
---|---|---|---|
|
7d2dad77c9 | ||
|
52e92a99be | ||
|
907e146385 | ||
|
9a94abc31d | ||
|
26507ad5b9 | ||
|
46f7fbb8dc |
@ -837,37 +837,31 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mouse.motion == Mouse::Pressed) {
|
||||
selection_pending_ = CaptureMouse();
|
||||
if (!selection_pending_) {
|
||||
return false;
|
||||
}
|
||||
selection_enabled_ = true;
|
||||
selection_box_.x_min = mouse.x;
|
||||
selection_box_.y_min = mouse.y;
|
||||
selection_box_.x_max = mouse.x;
|
||||
selection_box_.y_max = mouse.y;
|
||||
return true;
|
||||
if(mouse.motion == Mouse::Pressed) {
|
||||
selection_pending_ = CaptureMouse();
|
||||
if (!selection_pending_) {
|
||||
return false;
|
||||
}
|
||||
selection_enabled_ = true;
|
||||
selection_box_.x_min = mouse.x;
|
||||
selection_box_.y_min = mouse.y;
|
||||
selection_box_.x_max = mouse.x;
|
||||
selection_box_.y_max = mouse.y;
|
||||
return true;
|
||||
}
|
||||
else if((mouse.motion == Mouse::Moved) && (selection_pending_)) {
|
||||
selection_box_.x_max = mouse.x;
|
||||
selection_box_.y_max = mouse.y;
|
||||
return true;
|
||||
}
|
||||
else if((mouse.motion == Mouse::Released) && (selection_pending_)) {
|
||||
selection_box_.x_max = mouse.x;
|
||||
selection_box_.y_max = mouse.y;
|
||||
selection_pending_ = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!selection_pending_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mouse.motion == Mouse::Moved) {
|
||||
selection_box_.x_max = mouse.x;
|
||||
selection_box_.y_max = mouse.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mouse.motion != Mouse::Released) {
|
||||
return false;
|
||||
}
|
||||
|
||||
selection_box_.x_max = mouse.x;
|
||||
selection_box_.y_max = mouse.y;
|
||||
selection_pending_ = nullptr;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// private
|
||||
|
@ -72,16 +72,16 @@ class HBox : public Node {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool xmin_satured =
|
||||
const bool xmin_saturated =
|
||||
selection.y_min < box_.y_min || selection.x_min < box_.x_min;
|
||||
const bool xmax_satured =
|
||||
const bool xmax_saturated =
|
||||
selection.y_max > box_.y_max || selection.x_max > box_.x_max;
|
||||
|
||||
if (xmin_satured) {
|
||||
selection.x_min = box_.x_min;
|
||||
if (xmin_saturated) {
|
||||
selection.x_min = std::min(box_.x_min, selection.x_min);
|
||||
}
|
||||
if (xmax_satured) {
|
||||
selection.x_max = box_.x_max;
|
||||
if (xmax_saturated) {
|
||||
selection.x_max = std::max(box_.x_max, selection.x_max);
|
||||
}
|
||||
|
||||
for (auto& child : children_) {
|
||||
|
@ -94,7 +94,21 @@ void Render(Screen& screen, Node* node, Box selection) {
|
||||
|
||||
// Step 3: Selection
|
||||
std::vector<Box> selected;
|
||||
node->Selection(selection, &selected);
|
||||
|
||||
Box selectionCleaned = selection;
|
||||
if(selection.x_min > selection.x_max)
|
||||
{
|
||||
selectionCleaned.x_min = selection.x_max;
|
||||
selectionCleaned.x_max = selection.x_min;
|
||||
}
|
||||
|
||||
if(selection.y_min > selection.y_max)
|
||||
{
|
||||
selectionCleaned.y_min = selection.y_max;
|
||||
selectionCleaned.y_max = selection.y_min;
|
||||
}
|
||||
|
||||
node->Selection(selectionCleaned, &selected);
|
||||
|
||||
// Step 4: Draw the element.
|
||||
screen.stencil = box;
|
||||
|
@ -33,13 +33,13 @@ class Text : public Node {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool xmin_satured =
|
||||
const bool xmin_saturated =
|
||||
selection.y_min < box_.y_min || selection.x_min < box_.x_min;
|
||||
const bool xmax_satured =
|
||||
const bool xmax_saturated =
|
||||
selection.y_max > box_.y_max || selection.x_max > box_.x_max;
|
||||
|
||||
selection_start_ = xmin_satured ? box_.x_min : selection.x_min;
|
||||
selection_end_ = xmax_satured ? box_.x_max : selection.x_max;
|
||||
selection_start_ = xmin_saturated ? box_.x_min : selection.x_min;
|
||||
selection_end_ = xmax_saturated ? box_.x_max : selection.x_max;
|
||||
|
||||
has_selection = true;
|
||||
|
||||
@ -67,17 +67,14 @@ class Text : public Node {
|
||||
}
|
||||
screen.PixelAt(x, y).character = cell;
|
||||
|
||||
if (has_selection) {
|
||||
if((x >= selection_start_) && (x <= selection_end_)) {
|
||||
screen.PixelAt(x, y).inverted = true;
|
||||
}
|
||||
}
|
||||
|
||||
++x;
|
||||
}
|
||||
|
||||
if (!has_selection) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Invert the selection
|
||||
for(int x = selection_start_; x <= selection_end_; x++) {
|
||||
screen.PixelAt(x, y).inverted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -72,15 +72,16 @@ class VBox : public Node {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool ymin_satured =
|
||||
const bool ymin_saturated =
|
||||
selection.x_min < box_.x_min || selection.y_min < box_.y_min;
|
||||
const bool ymax_satured =
|
||||
const bool ymax_saturated =
|
||||
selection.x_max > box_.x_max || selection.y_max > box_.y_max;
|
||||
if (ymin_satured) {
|
||||
selection.y_min = box_.y_min;
|
||||
|
||||
if (ymin_saturated) {
|
||||
selection.y_min = std::min(box_.y_min, selection.y_min);
|
||||
}
|
||||
if (ymax_satured) {
|
||||
selection.y_max = box_.y_max;
|
||||
if (ymax_saturated) {
|
||||
selection.y_max = std::max(box_.y_max, selection.y_max);
|
||||
}
|
||||
|
||||
for (auto& child : children_) {
|
||||
|
Loading…
Reference in New Issue
Block a user