mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-12-05 01:11:46 +08:00
Compare commits
5 Commits
d38f3d229a
...
52e92a99be
Author | SHA1 | Date | |
---|---|---|---|
|
52e92a99be | ||
|
907e146385 | ||
|
9a94abc31d | ||
|
26507ad5b9 | ||
|
46f7fbb8dc |
@ -837,7 +837,7 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mouse.motion == Mouse::Pressed) {
|
||||
if(mouse.motion == Mouse::Pressed) {
|
||||
selection_pending_ = CaptureMouse();
|
||||
if (!selection_pending_) {
|
||||
return false;
|
||||
@ -849,25 +849,19 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
||||
selection_box_.y_max = mouse.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!selection_pending_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mouse.motion == Mouse::Moved) {
|
||||
else if((mouse.motion == Mouse::Moved) && (selection_pending_)) {
|
||||
selection_box_.x_max = mouse.x;
|
||||
selection_box_.y_max = mouse.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mouse.motion != Mouse::Released) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,19 +67,16 @@ class Text : public Node {
|
||||
}
|
||||
screen.PixelAt(x, y).character = cell;
|
||||
|
||||
++x;
|
||||
}
|
||||
|
||||
if (!has_selection) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Invert the selection
|
||||
for(int x = selection_start_; x <= selection_end_; x++) {
|
||||
if (has_selection) {
|
||||
if((x >= selection_start_) && (x <= selection_end_)) {
|
||||
screen.PixelAt(x, y).inverted = true;
|
||||
}
|
||||
}
|
||||
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::string text_;
|
||||
bool has_selection = false;
|
||||
|
@ -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