Skip to content

Commit 14f6433

Browse files
further enhancements of sliders which were still kinda broken, now should be ok
1 parent 9037843 commit 14f6433

File tree

6 files changed

+238
-122
lines changed

6 files changed

+238
-122
lines changed

libraries/userinterface/include/userinterface/widgets/Signal.h

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,25 @@ namespace curan
219219
{
220220
MOUSE_CLICKED_LEFT_EVENT = 1 << 1,
221221
MOUSE_CLICKED_LEFT = 1 << 2,
222-
MOUSE_CLICKED_RIGHT_EVENT = 1 << 3,
223-
MOUSE_CLICKED_RIGHT = 1 << 4,
224-
MOUSE_UNCLICK_LEFT_EVENT = 1 << 5,
225-
MOUSE_UNCLICK_RIGHT_EVENT = 1 << 6,
226-
MOUSE_MOVE_EVENT = 1 << 7, // move is always an event
227-
SCROLL_EVENT = 1 << 8, // scroll is always an event
228-
OUTSIDE_ALLOCATED_AREA = 1 << 9,
229-
INSIDE_ALLOCATED_AREA = 1 << 10,
230-
ENTERED_ALLOCATED_AREA_EVENT = 1 << 11,
231-
LEFT_ALLOCATED_AREA_EVENT = 1 << 12,
232-
OUTSIDE_FIXED_AREA = 1 << 13,
233-
INSIDE_FIXED_AREA = 1 << 14,
234-
LEFT_FIXED_AREA_EVENT = 1 << 15,
235-
ENTERED_FIXED_AREA_EVENT = 1 << 16,
236-
ITEM_DROPPED_EVENT = 1 << 17,
237-
KEYBOARD_EVENT = 1 << 18,
238-
HEART_BEAT = 1 << 19
222+
MOUSE_CLICKED_LEFT_WAS_INSIDE_FIXED = 1 << 3,
223+
MOUSE_CLICKED_RIGHT_EVENT = 1 << 4,
224+
MOUSE_CLICKED_RIGHT = 1 << 5,
225+
MOUSE_CLICKED_RIGHT_WAS_INSIDE_FIXED = 1 << 6,
226+
MOUSE_UNCLICK_LEFT_EVENT = 1 << 7,
227+
MOUSE_UNCLICK_RIGHT_EVENT = 1 << 8,
228+
MOUSE_MOVE_EVENT = 1 << 9, // move is always an event
229+
SCROLL_EVENT = 1 << 10, // scroll is always an event
230+
OUTSIDE_ALLOCATED_AREA = 1 << 11,
231+
INSIDE_ALLOCATED_AREA = 1 << 12,
232+
ENTERED_ALLOCATED_AREA_EVENT = 1 << 13,
233+
LEFT_ALLOCATED_AREA_EVENT = 1 << 14,
234+
OUTSIDE_FIXED_AREA = 1 << 15,
235+
INSIDE_FIXED_AREA = 1 << 16,
236+
LEFT_FIXED_AREA_EVENT = 1 << 17,
237+
ENTERED_FIXED_AREA_EVENT = 1 << 18,
238+
ITEM_DROPPED_EVENT = 1 << 19,
239+
KEYBOARD_EVENT = 1 << 20,
240+
HEART_BEAT = 1 << 21
239241
};
240242

241243
/*
@@ -330,6 +332,7 @@ namespace curan
330332
{
331333
std::visit(curan::utilities::overloaded{[&](curan::ui::Empty arg)
332334
{
335+
shutoff_oneoff_events();
333336
current_status |= HEART_BEAT;
334337
},
335338
[&](curan::ui::Move arg)
@@ -346,10 +349,16 @@ namespace curan
346349
shutoff_oneoff_events();
347350
allocated_area_logic(std::forward<allocated>(inside_allocated), arg.xpos, arg.ypos);
348351
fixed_area_logic(std::forward<fixed>(inside_fixed), arg.xpos, arg.ypos);
349-
if (!(current_status & MOUSE_CLICKED_LEFT))
350-
{
352+
if (!(current_status & MOUSE_CLICKED_LEFT)){
353+
if(current_status & INSIDE_FIXED_AREA)
354+
current_status |= MOUSE_CLICKED_LEFT_WAS_INSIDE_FIXED;
351355
current_status |= MOUSE_CLICKED_LEFT_EVENT | MOUSE_CLICKED_LEFT;
352356
}
357+
if (!(current_status & MOUSE_CLICKED_RIGHT)){
358+
if(current_status & INSIDE_FIXED_AREA)
359+
current_status |= MOUSE_CLICKED_RIGHT_WAS_INSIDE_FIXED;
360+
current_status |= MOUSE_CLICKED_RIGHT_EVENT | MOUSE_CLICKED_RIGHT;
361+
}
353362
x_last_press = arg.xpos;
354363
y_last_press = arg.ypos;
355364
},
@@ -370,6 +379,12 @@ namespace curan
370379
current_status |= MOUSE_UNCLICK_LEFT_EVENT;
371380
current_status &= ~MOUSE_CLICKED_LEFT;
372381
}
382+
if ((current_status & MOUSE_CLICKED_RIGHT))
383+
{
384+
current_status |= MOUSE_UNCLICK_RIGHT_EVENT;
385+
current_status &= ~MOUSE_CLICKED_RIGHT;
386+
}
387+
current_status &= ~(MOUSE_CLICKED_LEFT_WAS_INSIDE_FIXED | MOUSE_CLICKED_RIGHT_WAS_INSIDE_FIXED);
373388
},
374389
[&](curan::ui::Key arg)
375390
{
@@ -442,6 +457,16 @@ namespace curan
442457
o << "MOUSE_UNCLICK_RIGHT_EVENT\n";
443458
}
444459

460+
if(val.current_status & MOUSE_CLICKED_LEFT_WAS_INSIDE_FIXED)
461+
{
462+
o << "MOUSE_CLICKED_LEFT_WAS_INSIDE_FIXED\n";
463+
}
464+
465+
if(val.current_status & MOUSE_CLICKED_RIGHT_WAS_INSIDE_FIXED)
466+
{
467+
o << "MOUSE_CLICKED_RIGHT_WAS_INSIDE_FIXED\n";
468+
}
469+
445470
if (val.current_status & MOUSE_MOVE_EVENT)
446471
{
447472
o << "MOUSE_MOVE_EVENT\n";

libraries/userinterface/include/userinterface/widgets/Slider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace curan {
2828
SkColor waiting_color;
2929
SkColor click_color;
3030
SkColor slider_color;
31+
std::pair<double,double> old_pressed_value;
3132

3233
SkPaint paint;
3334
SkRect widget_rect_text;

libraries/userinterface/include/userinterface/widgets/SliderPanel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ namespace curan
225225
masks_z[_current_index_z].erase(iterator_to_inserted_object);
226226
return insertion_successeful;
227227
}
228+
default:
229+
throw std::runtime_error("incorrect mask direction selected");
228230
};
229231
}
230232

@@ -312,6 +314,8 @@ namespace curan
312314
return masks_y[along_dimension];
313315
case Direction::Z:
314316
return masks_z[along_dimension];
317+
default :
318+
throw std::runtime_error("incorrect mask direction selected");
315319
};
316320
}
317321
};
@@ -380,6 +384,7 @@ namespace curan
380384
float current_value = 0.5;
381385
float value_pressed = 0.5;
382386
float dragable_percent_size = 0.01f;
387+
std::pair<double,double> old_pressed_value;
383388

384389
SkSamplingOptions options;
385390
std::optional<SkPaint> paint_compliant_filtered_image;

libraries/userinterface/src/Slider.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,11 @@ namespace curan
114114
return true;
115115
}
116116

117-
static std::pair<double,double> old_pressed_value;
118-
119117
if(interpreter.check(INSIDE_FIXED_AREA | MOUSE_CLICKED_LEFT_EVENT)){
120118
old_pressed_value = interpreter.last_move();
121119
}
122120

123-
if (interpreter.check(INSIDE_FIXED_AREA | MOUSE_CLICKED_LEFT))
121+
if (interpreter.check(MOUSE_CLICKED_LEFT_WAS_INSIDE_FIXED))
124122
{
125123
auto widget_rect = get_position();
126124
auto size = get_size();

libraries/userinterface/src/SliderPanel.cpp

Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ namespace curan
591591
for (auto &pending : volumetric_mask->callbacks_pressedhighlighted)
592592
pending(volumetric_mask, config, highlighted_stroke);
593593

594+
594595
pending_strokes_to_process.clear();
595596

596597
auto check_inside_fixed_area = [this](double x, double y)
@@ -601,8 +602,35 @@ namespace curan
601602
{
602603
return get_position().contains(x, y);
603604
};
605+
606+
604607
interpreter.process(check_inside_allocated_area, check_inside_fixed_area, sig);
605608

609+
if (interpreter.check(KEYBOARD_EVENT)){
610+
set_current_state(SliderStates::WAITING);
611+
auto arg = std::get<curan::ui::Key>(sig);
612+
if (arg.key == GLFW_KEY_A && arg.action == GLFW_PRESS)
613+
{
614+
if (zoom_in)
615+
zoom_in.deactivate();
616+
else
617+
zoom_in.activate();
618+
return true;
619+
}
620+
621+
if (arg.key == GLFW_KEY_S && arg.action == GLFW_PRESS)
622+
{
623+
is_highlighting = !is_highlighting;
624+
if (!current_stroke.empty())
625+
{
626+
insert_in_map(current_stroke);
627+
current_stroke.clear();
628+
}
629+
return true;
630+
}
631+
return false;
632+
}
633+
606634
is_pressed = false;
607635

608636
if (interpreter.check(OUTSIDE_ALLOCATED_AREA))
@@ -632,92 +660,71 @@ namespace curan
632660
is_pressed = true;
633661
else
634662
is_pressed = false;
635-
636-
if (interpreter.check(INSIDE_ALLOCATED_AREA | MOUSE_MOVE_EVENT | MOUSE_CLICKED_LEFT) && interpreter.check(OUTSIDE_FIXED_AREA) && get_current_state()!=SliderStates::SCROLL)
637-
{
638-
set_current_state(SliderStates::PRESSED);
639-
if (!is_highlighting)
640-
current_stroke.add_point(homogenenous_transformation, SkPoint::Make((float)xpos, (float)ypos));
641-
return true;
642-
}
643-
else if (interpreter.check(INSIDE_ALLOCATED_AREA | MOUSE_MOVE_EVENT) && !current_stroke.empty() && interpreter.check(OUTSIDE_FIXED_AREA) && get_current_state()!=SliderStates::SCROLL)
644-
{
663+
664+
if(interpreter.check(MOUSE_UNCLICK_RIGHT_EVENT | MOUSE_UNCLICK_LEFT_EVENT | LEFT_ALLOCATED_AREA_EVENT)){
645665
set_current_state(SliderStates::WAITING);
646666
insert_in_map(current_stroke);
647667
current_stroke.clear();
648668
return false;
649-
} else if (interpreter.check(INSIDE_ALLOCATED_AREA | MOUSE_MOVE_EVENT) && !current_stroke.empty() && interpreter.check(OUTSIDE_FIXED_AREA) && get_current_state()==SliderStates::SCROLL){
650-
set_current_state(SliderStates::SCROLL);
651-
auto offset_x = ((float)xpos - reserved_slider_space.x()) / reserved_slider_space.width();
669+
}
670+
671+
if (interpreter.check(INSIDE_ALLOCATED_AREA | SCROLL_EVENT))
672+
{
673+
auto widget_rect = get_position();
674+
auto size = get_size();
675+
SkRect drawable = size;
676+
auto arg = std::get<curan::ui::Scroll>(sig);
677+
drawable.offsetTo(widget_rect.centerX() - drawable.width() / 2.0f, widget_rect.centerY() - drawable.height() / 2.0f);
678+
auto offsetx = (float)arg.xoffset / size.width();
679+
auto offsety = (float)arg.yoffset / size.width();
652680
auto current_val = get_current_value();
653-
current_val += offset_x - read_trigger();
654-
trigger(offset_x);
681+
current_val += (std::abs(offsetx) > std::abs(offsety)) ? offsetx : offsety;
655682
set_current_value(current_val);
683+
set_current_state(SliderStates::PRESSED);
656684
return true;
657685
}
658686

659-
if (interpreter.check(INSIDE_FIXED_AREA | MOUSE_MOVE_EVENT | MOUSE_CLICKED_LEFT))
687+
if(interpreter.check(INSIDE_FIXED_AREA | MOUSE_CLICKED_LEFT_EVENT)){
688+
old_pressed_value = interpreter.last_move();
689+
}
690+
691+
if (interpreter.check(MOUSE_CLICKED_LEFT_WAS_INSIDE_FIXED))
660692
{
661-
set_current_state(SliderStates::SCROLL);
662-
auto offset_x = ((float)xpos - reserved_slider_space.x()) / reserved_slider_space.width();
693+
auto widget_rect = get_position();
694+
auto size = get_size();
695+
SkRect drawable = size;
696+
auto [xarg,yarg] = interpreter.last_move();
697+
auto [xarg_last,yarg_last] = old_pressed_value;
663698
auto current_val = get_current_value();
664-
current_val += offset_x - read_trigger();
665-
trigger(offset_x);
666-
set_current_value(current_val);
699+
drawable.offsetTo(widget_rect.centerX() - drawable.width() / 2.0f, widget_rect.centerY() - drawable.height() / 2.0f);
700+
auto offsetx = (float)(xarg-xarg_last) / size.width();
701+
set_current_value(offsetx+current_val);
702+
set_current_state(SliderStates::PRESSED);
703+
old_pressed_value = interpreter.last_move();
704+
return true;
667705
}
668706

669-
if (interpreter.check(INSIDE_ALLOCATED_AREA | MOUSE_CLICKED_LEFT_EVENT) && interpreter.check(OUTSIDE_FIXED_AREA))
670-
{
707+
if(interpreter.status() & ~MOUSE_CLICKED_LEFT_WAS_INSIDE_FIXED && interpreter.check(INSIDE_ALLOCATED_AREA | MOUSE_MOVE_EVENT | MOUSE_CLICKED_LEFT) ){
708+
set_current_state(SliderStates::PRESSED);
671709
if (!is_highlighting)
672-
{
673-
if (current_stroke.normalized_recorded_points.size() == 1)
674-
{
675-
insert_in_map(current_stroke);
676-
current_stroke.clear();
677-
}
678-
auto [xpos, ypos] = interpreter.last_press();
679710
current_stroke.add_point(homogenenous_transformation, SkPoint::Make((float)xpos, (float)ypos));
680-
set_current_state(SliderStates::PRESSED);
681-
}
711+
return true;
682712
}
683713

684-
if (interpreter.check(SCROLL_EVENT))
714+
if (interpreter.check(INSIDE_FIXED_AREA))
685715
{
686-
auto arg = std::get<curan::ui::Scroll>(sig);
687-
auto offsetx = (float)arg.xoffset / reserved_slider_space.width();
688-
auto offsety = (float)arg.yoffset / reserved_slider_space.width();
689-
auto current_val = get_current_value();
690-
current_val += (std::abs(offsetx) > std::abs(offsety)) ? offsetx : offsety;
691-
set_current_value(current_val);
692-
set_current_state(SliderStates::SCROLL);
716+
set_current_state(SliderStates::HOVER);
717+
return true;
693718
}
694719

695-
if (interpreter.check(KEYBOARD_EVENT))
720+
if (interpreter.check(OUTSIDE_FIXED_AREA | MOUSE_MOVE_EVENT))
696721
{
697722
set_current_state(SliderStates::WAITING);
698-
auto arg = std::get<curan::ui::Key>(sig);
699-
if (arg.key == GLFW_KEY_A && arg.action == GLFW_PRESS)
700-
{
701-
if (zoom_in)
702-
zoom_in.deactivate();
703-
else
704-
zoom_in.activate();
705-
return true;
706-
}
707-
708-
if (arg.key == GLFW_KEY_S && arg.action == GLFW_PRESS)
709-
{
710-
is_highlighting = !is_highlighting;
711-
if (!current_stroke.empty())
712-
{
713-
insert_in_map(current_stroke);
714-
current_stroke.clear();
715-
}
716-
return true;
717-
}
718-
return false;
723+
return true;
719724
}
720725

726+
set_current_state(SliderStates::WAITING);
727+
721728
return false;
722729
};
723730
return lamb;

0 commit comments

Comments
 (0)