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