leonid_golovko
Topic Author
Posts: 13
Joined: 13 Jun 2024, 15:06

mouse_args.position problem in view model.

04 Aug 2024, 08:50

I have a problem. I can't get the position that I should be able to get.(mouse_args.position.x). How to fix it? It don't seem to change at all.
<Button x:Name="LeftOneIncisionPoint" Width="35" Height="35" Background="Transparent" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding IncisionVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource TransparentButtonStyle}">
                    <Grid>
                        <Image Source="{StaticResource CenterCircleButtonOff}" Stretch="Uniform" Visibility="{Binding IncisionCenterOffMouseVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        <Image Source="{StaticResource CenterCircleButtonOn}" Stretch="Uniform" Visibility="{Binding IncisionCenterOnMouseVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        <Image Source="{StaticResource CenterRotator}" Stretch="Uniform" Visibility="{Binding IncisionCenterOnMousePressVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    </Grid>
                    <Button.RenderTransform>
                          <TranslateTransform X="{Binding CenterIncisionPointX}" Y="{Binding CenterIncisionPointY}"/>
                    </Button.RenderTransform>
                    <b:Interaction.Triggers>
                        <b:EventTrigger EventName="MouseEnter">
                           <b:InvokeCommandAction Command="{Binding HandleCenterButtomEnterCommand}" PassEventArgsToCommand="True"/>
                        </b:EventTrigger>
                        <b:EventTrigger EventName="MouseLeave">
                           <b:InvokeCommandAction Command="{Binding HandleCenterButtomLeaveCommand}" PassEventArgsToCommand="True"/>
                        </b:EventTrigger>
                        <b:EventTrigger EventName="PreviewMouseLeftButtonDown">
                              <b:InvokeCommandAction Command="{Binding HandleCenterButtomDownCommand}" PassEventArgsToCommand="True" CommandParameter="{Binding RelativeSource={RelativeSource Self}}"/>
                         </b:EventTrigger>
                         <b:EventTrigger EventName="PreviewMouseLeftButtonUp">
                              <b:InvokeCommandAction Command="{Binding HandleCenterButtomUpCommand}" PassEventArgsToCommand="True" CommandParameter="{Binding RelativeSource={RelativeSource Self}}"/>
                         </b:EventTrigger>
                         <b:EventTrigger EventName="PreviewMouseMove">
                              <b:InvokeCommandAction Command="{Binding HandleCenterButtomMoveCommand}" PassEventArgsToCommand="True" CommandParameter="{Binding RelativeSource={RelativeSource Self}}"/>
                         </b:EventTrigger>
                     </b:Interaction.Triggers>
                </Button>
void IncisionViewModel::HandleMouseMoveSideButtom(Noesis::BaseComponent* param)
{
    const Noesis::EventArgs *event_args = Noesis::Boxing::Unbox<const Noesis::EventArgs *>(param);
    // Cast the unboxed event arguments to the relevant event argument type
    const Noesis::MouseEventArgs &mouse_args = *(const Noesis::MouseEventArgs *) (event_args);
    if (is_dragging) {
        Noesis::Point incision_ellipse_center_point = GetCenterEllipseIncisionPoint();
        float angle = AngleOfPoint(Noesis::Point(mouse_args.position.x - incision_ellipse_center_point.x, mouse_args.position.y - incision_ellipse_center_point.y));
        float incision_angle = GetIncisionAngle();
        std::cout<< "Incision Angle is " << angle << std::endl;
        if(std::abs(incision_angle - angle) > 1) {
            SetArcAngle(std::abs(incision_angle - angle) * 2);
            SetPointsOnScreen(incision_angle);
        }
        arc_length_mm = CalculateTotalLengthWithAngles(GetIncisionAngle() - GetArcAngle() / (float)2, GetIncisionAngle() + GetArcAngle() / (float)2);
    }
}
 
User avatar
sfernandez
Site Admin
Posts: 3112
Joined: 22 Dec 2011, 19:20

Re: mouse_args.position problem in view model.

05 Aug 2024, 17:58

The position received in the mouse event args is in screen space. You can use Visual::PointFromScreen() funtion to transform it to a specific element in the UI.

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 2 guests