Compare commits

..

6 Commits

Author SHA1 Message Date
Clément Roblot
7d2dad77c9
Merge 52e92a99be into ad0392ec39 2024-11-27 03:24:11 +00:00
Clement Roblot
52e92a99be More robust saturation mechanism 2024-11-27 00:29:08 +07:00
Clement Roblot
907e146385 Correct the title highlighting of hbox grabing to top border 2024-11-26 21:47:01 +07:00
Clement Roblot
9a94abc31d We can reverse select 2024-11-26 21:39:29 +07:00
Clement Roblot
26507ad5b9 Corrected typo 2024-11-26 17:25:16 +07:00
Clement Roblot
46f7fbb8dc Easier to read HandleSelection 2024-11-26 17:13:40 +07:00
5 changed files with 61 additions and 55 deletions

View File

@ -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

View File

@ -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_) {

View File

@ -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;

View File

@ -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:

View File

@ -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_) {