Staffan
Topic Author
Posts: 3
Joined: 12 Sep 2019, 11:40

Issues with manipulation events

12 Sep 2019, 11:46

I'm trying to let users translate an object by touch but It's not quite working.
Do I need to create an instance of the class or register it somehow? What am i missing?

Xaml
 <Grid x:Name="InfoPanel_LayoutRoot" x:Class="cInfoPanelTouch">
     ...
      <Canvas Grid.Column="1" Grid.RowSpan="3" VerticalAlignment="Top">
        <Grid x:Name="InfoPanel"
              VerticalAlignment="Top"
              RenderTransformOrigin="0.5,0.5"
              Width="{Binding ActualWidth, ElementName=Panel_width}"
              MinHeight="{Binding ActualHeight, ElementName=InfoPanel_LayoutRoot}"
              IsManipulationEnabled="true">
             ....
              
c++
class cInfoPanelTouch : public Noesis::Grid
{
public:

	void OnManipulationStarting( const Noesis::ManipulationStartingEventArgs& e )
	{
		e.mode = Noesis::ManipulationModes_Translate;
		e.manipulationContainer = ( Noesis::Visual* )FindName( "InfoPanel_LayoutRoot" );
		e.handled = true;
	}

	void OnManipulationInertiaStarting( const Noesis::ManipulationInertiaStartingEventArgs& e )
	{
		e.translationBehavior.desiredDeceleration = 100.0f / ( 1000.0f * 1000.0f );
		e.handled = true;
	}

	void OnManipulationDelta( const Noesis::ManipulationDeltaEventArgs& e )
	{
		Noesis::UIElement* element = ( UIElement* )e.source;
		Noesis::MatrixTransform* transform = ( Noesis::MatrixTransform* )element->GetRenderTransform();
		Noesis::Transform2f matrix = transform->GetMatrix();

		matrix.Translate( 0.0f, e.deltaManipulation.translation.y );

		transform->SetMatrix( matrix );
		e.handled = true;
	}

private:

	NS_IMPLEMENT_INLINE_REFLECTION( cInfoPanelTouch, Noesis::Grid )
	{
		NsMeta<Noesis::TypeId>( "cInfoPanelTouch" );
	}
};
 
User avatar
jsantos
Site Admin
Posts: 3919
Joined: 20 Jan 2012, 17:18
Contact:

Re: Issues with manipulation events

12 Sep 2019, 16:08

The class should be registered with the rest of classes. Once it is registered it should be automatically created by the XAML. Please, check that before.
 
Staffan
Topic Author
Posts: 3
Joined: 12 Sep 2019, 11:40

Re: Issues with manipulation events

12 Sep 2019, 17:39

Thanks for your response

I've registered the component
NsRegisterComponent< InfoPanelTouch >();

But I'm still not getting break points in any of the events when touching the UI

Also Transform2f is not recognized (incomplete type ), even though I've included Rect.h
 
User avatar
jsantos
Site Admin
Posts: 3919
Joined: 20 Jan 2012, 17:18
Contact:

Re: Issues with manipulation events

12 Sep 2019, 17:45

But I'm still not getting break points in any of the events when touching the UI
Is the class being created? Could you put a breakpoint in the ctor? Besides, I recommend adding the c++ keyword override just to make sure you are overriding the proper functions.
Also Transform2f is not recognized (incomplete type ), even though I've included Rect.h
Not sure, to be following here, because if you are not able to compile previous comments make not sense. Transform2f is declated in "NsMath/Transform.h"
 
User avatar
jsantos
Site Admin
Posts: 3919
Joined: 20 Jan 2012, 17:18
Contact:

Re: Issues with manipulation events

12 Sep 2019, 17:47

There is a sample inside the C++ SDK, Touch, doing something similar to what you want to achieve. Could you please also try it? Thanks!
 
Staffan
Topic Author
Posts: 3
Joined: 12 Sep 2019, 11:40

Re: Issues with manipulation events

12 Sep 2019, 20:52

Thanks, I took a look at the code in the sdk and made some changes. Now I'm getting the events

However, when trying to translate the rendertransform, nothing happens.
Any ideas what could prevent the translation?
void cMainWindow::OnManipulationDelta( const Noesis::ManipulationDeltaEventArgs& e )
	{
		Noesis::UIElement* info_panel = ( Noesis::UIElement* )e.source;
		Noesis::MatrixTransform* transform = ( Noesis::MatrixTransform* )info_panel->GetRenderTransform();
		Noesis::Transform2f matrix = transform->GetMatrix();
		matrix.Translate( 0.0f, e.deltaManipulation.translation.y );

		transform->SetMatrix( matrix );
		e.handled = true;
	}
<Grid x:Name="InfoPanel"
                      VerticalAlignment="Top" 
                      RenderTransformOrigin="0.5,0.5"
                      Width="{Binding ActualWidth, ElementName=Panel_width}"
                      MinHeight="{Binding ActualHeight, ElementName=InfoPanel_LayoutRoot}"
                      IsManipulationEnabled="true">

                    <Grid.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                          <TranslateTransform Y="{Binding ActualHeight, ElementName=PanelMiddle_offset}"/>
                        </TransformGroup>
                    </Grid.RenderTransform>



                    <Border BorderBrush="{DynamicResource UIBrush_Border}" BorderThickness="4,4,4,0" CornerRadius="16,16,0,0" Background="{DynamicResource UIBrush_Primary}"/>
                    <StackPanel x:Name="infoPanelEverything" Margin="0" Orientation="Vertical">

                        <Grid x:Name="InfoPanel_Touch" Height="{Binding ActualHeight, ElementName=PanelTop_height}" Margin="0" VerticalAlignment="Top" Background="#00000000">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="2*"/>
                                <RowDefinition/>
                                <RowDefinition Height="2*"/>
                            </Grid.RowDefinitions>

                            <Viewbox HorizontalAlignment="Center" Grid.Row="1">
                                <Border Background="{DynamicResource UIBrush_Border}" Width="142" CornerRadius="8" BorderThickness="0" Height="16"/>
                            </Viewbox>
                        </Grid>

                        <Viewbox Margin="16,0">
                            <StackPanel x:Name="Infopanel_Content" RenderTransformOrigin="0.5,0.5" Width="468.706">
                                <StackPanel.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform/>
                                        <SkewTransform/>
                                        <RotateTransform/>
                                        <TranslateTransform/>
                                    </TransformGroup>
                                </StackPanel.RenderTransform>

                               <!--....-->

                            </StackPanel>

                        </Viewbox>

                    </StackPanel>
                </Grid>
 
User avatar
sfernandez
Site Admin
Posts: 2995
Joined: 22 Dec 2011, 19:20

Re: Issues with manipulation events

13 Sep 2019, 08:48

Looking at the xaml I see what was the problem. InfoPanel grid has a TransformGroup as RenderTransform, but you are casting to MatrixTransform.
You have to cast to TransformGroup and get the TranslateTransform from the Children to update the vertical offset.

Although if you only want to translate that element it would be even better if you just have a TranslateTransform as RenderTransform:
<Grid x:Name="InfoPanel" ...>
  <Grid.RenderTransform>
    <TranslateTransform />
  </Grid.RenderTransform>
  ...
</Grid>
void cMainWindow::OnManipulationDelta( const Noesis::ManipulationDeltaEventArgs& e )
{
    Noesis::UIElement* info_panel = ( Noesis::UIElement* )e.source;
    Noesis::TranslateTransform* transform = ( Noesis::TranslateTransform* )info_panel->GetRenderTransform();
    transform->SetY(transform->GetY() + e.deltaManipulation.translation.y);

    e.handled = true;
}

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests