Wanderer
Topic Author
Posts: 168
Joined: 08 May 2017, 18:36

C++ how to detect if mouse is over IView? (Layered views)

08 Oct 2017, 21:27

Due problems with Noesis with glfw windows (under windows 10) I decided my application will have one window. I created second IView and render it inside main window.
How can I detect mouse under IView to attach mouse and keyboard input? Now when some control is behind second IView, it interact with first IView.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: C++ how to detect if mouse is over IView? (Layered views)

09 Oct 2017, 18:41

IView is operating system agnostic. It means you are in charge of sending the events whenever they are needed. If you are rendering to the same window, then you know the sizes given to each view rigth? it should be easy to know if the mouse is on top of a view or not. You could also use the HitTesting functionality provided by VisualTreeHelper.h.

By the way, we don't recommend using more than one view for the same window. We optimized this scenario a lot in 2.X but better if you can avoid it.
 
Wanderer
Topic Author
Posts: 168
Joined: 08 May 2017, 18:36

Re: C++ how to detect if mouse is over IView? (Layered views)

09 Oct 2017, 20:50

And what is better to create new "window" inside window? This "window" I mean Grid which will be rendered before main Grid.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: C++ how to detect if mouse is over IView? (Layered views)

10 Oct 2017, 00:54

If you want to add several Window/Dialogs to the same IView define a root panel (for example a Grid) that can serve as container (desktop). Then you can add all the windows you want to that root panel and use Panel.ZIndex property to manage the z order.

For example, you can have the following xaml loaded and initially set as content of the IView:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid x:Name="WindowContainer"/>
    ...
</Grid>
Then whenever you want to add a new window:
auto window = Noesis::GUI::LoadXaml<Noesis::FrameworkElement>("GUI/Dialogs/SettingsWindow.xaml");
auto windowContainer = mXamlView->GetContent()->FindName<Noesis::Grid>("WindowContainer");
windowContainer->GetChildren()->Add(window.GetPtr());
And when you need to change the z order of a window:
void MoveWindowToForeground(Noesis::FrameworkElement* window)
{
  mTopWindowZ++;
  Noesis::Panel::SetZIndex(window, mTopWindowZ);  
}
 
Wanderer
Topic Author
Posts: 168
Joined: 08 May 2017, 18:36

Re: C++ how to detect if mouse is over IView? (Layered views)

10 Oct 2017, 11:58

Thanks sfernandez, it is looks like working except Z-Index:
void MoveWindowToForeground(Noesis::FrameworkElement* window)
{
  mTopWindowZ++;
  Noesis::Panel::SetZIndex(window, mTopWindowZ);  
}
second Grid is still behind main grid, whatever value I add in to mTopWindowZ. But maybe it is windows 10 and opengl problem. Another problem is, when second grid is created, GUI rendering have problems, it looks like it render twice or more and it is blended and color is additive and it start flickering when window is resized. I can't test it under windows 7 now.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: C++ how to detect if mouse is over IView? (Layered views)

10 Oct 2017, 12:47

From what you are describing it seems like you are not clearing the surface each frame.
If for example you are under a GL environment the minimum steps to perform each frame should be:
mView->Update(currentTimeInSeconds);

Noesis::IRenderer* renderer = mView->GetRenderer();
renderer->UpdateRenderTree();

if (renderer->NeedsOffscreen())
{
  renderer->RenderOffscreen();
}

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, width, height);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

renderer->Render();
 
Wanderer
Topic Author
Posts: 168
Joined: 08 May 2017, 18:36

Re: C++ how to detect if mouse is over IView? (Layered views)

10 Oct 2017, 12:54

I apologize, it was ok (Z Index). Porblem is, it not show full grid (choose window), only part of this grid without textboxes and buttons.
 
Wanderer
Topic Author
Posts: 168
Joined: 08 May 2017, 18:36

Re: C++ how to detect if mouse is over IView? (Layered views)

10 Oct 2017, 14:36

I discover, the buttons and other "window" elements, they there are, but rendered grid is only limited size.
When I add Height="500" for example, Grid is not changed to this size. I implement move window, and if grid is moved with Height="500", is not moved, but only grid inside this grid. I create video for this problem and post it here, when I will have time.

Finally, problem described above is due my mainGrid has rows,
<Grid.RowDefinitions>
		<RowDefinition Height="40" />
		<RowDefinition Height="*" />
	</Grid.RowDefinitions>
	<Grid.ColumnDefinitions>
		<ColumnDefinition Width="*" />
	</Grid.ColumnDefinitions>
	<Label Grid.Row="0" Content="TEXT" FontSize="16" FontWeight="Bold" Foreground="White"/>
	<!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// GRID RESOURCES -->
	<Grid.Resources>
        <DataModel x:Name="dataModel" />
    </Grid.Resources>
	<!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
	<Grid  x:Name="WindowContainer" >
	</Grid>
if I add this code in WindowContainer
Grid.Row="1"
Grid is displayed in row 1 insitead row 0. And then grid inside WindowContainer grid is displayed full. Now question is, how to display grid in full window without add grid in to row or column?

Who is online

Users browsing this forum: Google [Bot] and 0 guests