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,37 +837,31 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse.motion == Mouse::Pressed) {
|
if(mouse.motion == Mouse::Pressed) {
|
||||||
selection_pending_ = CaptureMouse();
|
selection_pending_ = CaptureMouse();
|
||||||
if (!selection_pending_) {
|
if (!selection_pending_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
selection_enabled_ = true;
|
selection_enabled_ = true;
|
||||||
selection_box_.x_min = mouse.x;
|
selection_box_.x_min = mouse.x;
|
||||||
selection_box_.y_min = mouse.y;
|
selection_box_.y_min = mouse.y;
|
||||||
selection_box_.x_max = mouse.x;
|
selection_box_.x_max = mouse.x;
|
||||||
selection_box_.y_max = mouse.y;
|
selection_box_.y_max = mouse.y;
|
||||||
return true;
|
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;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
|
@ -72,16 +72,16 @@ class HBox : public Node {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool xmin_satured =
|
const bool xmin_saturated =
|
||||||
selection.y_min < box_.y_min || selection.x_min < box_.x_min;
|
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.y_max > box_.y_max || selection.x_max > box_.x_max;
|
||||||
|
|
||||||
if (xmin_satured) {
|
if (xmin_saturated) {
|
||||||
selection.x_min = box_.x_min;
|
selection.x_min = std::min(box_.x_min, selection.x_min);
|
||||||
}
|
}
|
||||||
if (xmax_satured) {
|
if (xmax_saturated) {
|
||||||
selection.x_max = box_.x_max;
|
selection.x_max = std::max(box_.x_max, selection.x_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& child : children_) {
|
for (auto& child : children_) {
|
||||||
|
@ -94,7 +94,21 @@ void Render(Screen& screen, Node* node, Box selection) {
|
|||||||
|
|
||||||
// Step 3: Selection
|
// Step 3: Selection
|
||||||
std::vector<Box> selected;
|
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.
|
// Step 4: Draw the element.
|
||||||
screen.stencil = box;
|
screen.stencil = box;
|
||||||
|
@ -33,13 +33,13 @@ class Text : public Node {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool xmin_satured =
|
const bool xmin_saturated =
|
||||||
selection.y_min < box_.y_min || selection.x_min < box_.x_min;
|
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.y_max > box_.y_max || selection.x_max > box_.x_max;
|
||||||
|
|
||||||
selection_start_ = xmin_satured ? box_.x_min : selection.x_min;
|
selection_start_ = xmin_saturated ? box_.x_min : selection.x_min;
|
||||||
selection_end_ = xmax_satured ? box_.x_max : selection.x_max;
|
selection_end_ = xmax_saturated ? box_.x_max : selection.x_max;
|
||||||
|
|
||||||
has_selection = true;
|
has_selection = true;
|
||||||
|
|
||||||
@ -67,17 +67,14 @@ class Text : public Node {
|
|||||||
}
|
}
|
||||||
screen.PixelAt(x, y).character = cell;
|
screen.PixelAt(x, y).character = cell;
|
||||||
|
|
||||||
|
if (has_selection) {
|
||||||
|
if((x >= selection_start_) && (x <= selection_end_)) {
|
||||||
|
screen.PixelAt(x, y).inverted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
++x;
|
++x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!has_selection) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invert the selection
|
|
||||||
for(int x = selection_start_; x <= selection_end_; x++) {
|
|
||||||
screen.PixelAt(x, y).inverted = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -72,15 +72,16 @@ class VBox : public Node {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool ymin_satured =
|
const bool ymin_saturated =
|
||||||
selection.x_min < box_.x_min || selection.y_min < box_.y_min;
|
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;
|
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) {
|
if (ymax_saturated) {
|
||||||
selection.y_max = box_.y_max;
|
selection.y_max = std::max(box_.y_max, selection.y_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& child : children_) {
|
for (auto& child : children_) {
|
||||||
|
Loading…
Reference in New Issue
Block a user