2019-11-20 21:46:41 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "clutter-build-config.h"
|
|
|
|
|
2020-10-17 13:18:37 -03:00
|
|
|
#include "clutter-backend.h"
|
2019-11-20 21:46:41 +01:00
|
|
|
#include "clutter-pick-context-private.h"
|
|
|
|
|
|
|
|
struct _ClutterPickContext
|
|
|
|
{
|
|
|
|
grefcount ref_count;
|
|
|
|
|
2020-10-16 09:59:54 -03:00
|
|
|
ClutterPickMode mode;
|
2020-10-16 19:13:12 -03:00
|
|
|
ClutterPickStack *pick_stack;
|
2020-10-22 21:10:33 -03:00
|
|
|
|
|
|
|
graphene_ray_t ray;
|
|
|
|
graphene_point3d_t point;
|
2019-11-20 21:46:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_BOXED_TYPE (ClutterPickContext, clutter_pick_context,
|
|
|
|
clutter_pick_context_ref,
|
|
|
|
clutter_pick_context_unref)
|
|
|
|
|
|
|
|
ClutterPickContext *
|
2020-10-22 21:10:33 -03:00
|
|
|
clutter_pick_context_new_for_view (ClutterStageView *view,
|
|
|
|
ClutterPickMode mode,
|
|
|
|
const graphene_point3d_t *point,
|
|
|
|
const graphene_ray_t *ray)
|
2019-11-20 21:46:41 +01:00
|
|
|
{
|
|
|
|
ClutterPickContext *pick_context;
|
2020-10-16 19:13:12 -03:00
|
|
|
CoglContext *context;
|
2019-11-20 21:46:41 +01:00
|
|
|
|
|
|
|
pick_context = g_new0 (ClutterPickContext, 1);
|
|
|
|
g_ref_count_init (&pick_context->ref_count);
|
2020-10-16 09:59:54 -03:00
|
|
|
pick_context->mode = mode;
|
2020-10-22 21:10:33 -03:00
|
|
|
graphene_ray_init_from_ray (&pick_context->ray, ray);
|
|
|
|
graphene_point3d_init_from_point (&pick_context->point, point);
|
2019-11-20 21:46:41 +01:00
|
|
|
|
2020-10-17 13:18:37 -03:00
|
|
|
context = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
2020-10-16 19:13:12 -03:00
|
|
|
pick_context->pick_stack = clutter_pick_stack_new (context);
|
|
|
|
|
2019-11-20 21:46:41 +01:00
|
|
|
return pick_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClutterPickContext *
|
|
|
|
clutter_pick_context_ref (ClutterPickContext *pick_context)
|
|
|
|
{
|
|
|
|
g_ref_count_inc (&pick_context->ref_count);
|
|
|
|
return pick_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_pick_context_dispose (ClutterPickContext *pick_context)
|
|
|
|
{
|
2020-10-16 19:13:12 -03:00
|
|
|
g_clear_pointer (&pick_context->pick_stack, clutter_pick_stack_unref);
|
2019-11-20 21:46:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clutter_pick_context_unref (ClutterPickContext *pick_context)
|
|
|
|
{
|
|
|
|
if (g_ref_count_dec (&pick_context->ref_count))
|
|
|
|
{
|
|
|
|
clutter_pick_context_dispose (pick_context);
|
|
|
|
g_free (pick_context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clutter_pick_context_destroy (ClutterPickContext *pick_context)
|
|
|
|
{
|
|
|
|
clutter_pick_context_dispose (pick_context);
|
|
|
|
clutter_pick_context_unref (pick_context);
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:59:54 -03:00
|
|
|
/**
|
|
|
|
* clutter_pick_context_get_mode: (skip)
|
|
|
|
*/
|
|
|
|
ClutterPickMode
|
|
|
|
clutter_pick_context_get_mode (ClutterPickContext *pick_context)
|
|
|
|
{
|
|
|
|
return pick_context->mode;
|
|
|
|
}
|
2020-10-16 19:13:12 -03:00
|
|
|
|
|
|
|
ClutterPickStack *
|
|
|
|
clutter_pick_context_steal_stack (ClutterPickContext *pick_context)
|
|
|
|
{
|
|
|
|
clutter_pick_stack_seal (pick_context->pick_stack);
|
|
|
|
return g_steal_pointer (&pick_context->pick_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_pick_context_log_pick:
|
|
|
|
* @pick_context: a #ClutterPickContext
|
Use graphene_ray_t to pick actors
This commit introduces a few important changes in order to
acommodate graphene_ray_t. Most of them are positive changes,
so don't panic :)
The first very visible change is that neither the actor box
nor the clip rectangles are projected before being pushed.
This required changing the parameters of the related functions
at both ClutterPickContext, and ClutterPickStack, to receive
boxes instead of vertices. These rectangles are projected on
demand now, so in the best case (first actor picked) only
one projection happens; and in the worst case, it projects
as much as it does now.
The second important change is that there are no more checks
for axis-alignment anymore. That's because picking now happens
in 3D space, using triangles.
Talking about triangles in 3D space, this is what is used now
for picking. We break down each actor rectangle in 2 triangles,
and check if the projected pick point is inside any one of them,
of if the ray intersects any one of them. The same check happens
for the clip rectangles.
Checking the projected pick point is both an optimization for the
2D case, and a workaround to graphene_ray_t problems with float
precision, which is specially visible on edges such as the top
bar.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1509
2020-10-17 11:52:45 -03:00
|
|
|
* @box: a #ClutterActorBox
|
2020-10-16 19:13:12 -03:00
|
|
|
* @actor: a #ClutterActor
|
|
|
|
*
|
|
|
|
* Logs a pick rectangle into the pick stack.
|
|
|
|
*/
|
|
|
|
void
|
Use graphene_ray_t to pick actors
This commit introduces a few important changes in order to
acommodate graphene_ray_t. Most of them are positive changes,
so don't panic :)
The first very visible change is that neither the actor box
nor the clip rectangles are projected before being pushed.
This required changing the parameters of the related functions
at both ClutterPickContext, and ClutterPickStack, to receive
boxes instead of vertices. These rectangles are projected on
demand now, so in the best case (first actor picked) only
one projection happens; and in the worst case, it projects
as much as it does now.
The second important change is that there are no more checks
for axis-alignment anymore. That's because picking now happens
in 3D space, using triangles.
Talking about triangles in 3D space, this is what is used now
for picking. We break down each actor rectangle in 2 triangles,
and check if the projected pick point is inside any one of them,
of if the ray intersects any one of them. The same check happens
for the clip rectangles.
Checking the projected pick point is both an optimization for the
2D case, and a workaround to graphene_ray_t problems with float
precision, which is specially visible on edges such as the top
bar.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1509
2020-10-17 11:52:45 -03:00
|
|
|
clutter_pick_context_log_pick (ClutterPickContext *pick_context,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
ClutterActor *actor)
|
2020-10-16 19:13:12 -03:00
|
|
|
{
|
Use graphene_ray_t to pick actors
This commit introduces a few important changes in order to
acommodate graphene_ray_t. Most of them are positive changes,
so don't panic :)
The first very visible change is that neither the actor box
nor the clip rectangles are projected before being pushed.
This required changing the parameters of the related functions
at both ClutterPickContext, and ClutterPickStack, to receive
boxes instead of vertices. These rectangles are projected on
demand now, so in the best case (first actor picked) only
one projection happens; and in the worst case, it projects
as much as it does now.
The second important change is that there are no more checks
for axis-alignment anymore. That's because picking now happens
in 3D space, using triangles.
Talking about triangles in 3D space, this is what is used now
for picking. We break down each actor rectangle in 2 triangles,
and check if the projected pick point is inside any one of them,
of if the ray intersects any one of them. The same check happens
for the clip rectangles.
Checking the projected pick point is both an optimization for the
2D case, and a workaround to graphene_ray_t problems with float
precision, which is specially visible on edges such as the top
bar.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1509
2020-10-17 11:52:45 -03:00
|
|
|
clutter_pick_stack_log_pick (pick_context->pick_stack, box, actor);
|
2020-10-16 19:13:12 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_pick_context_push_clip:
|
|
|
|
* @pick_context: a #ClutterPickContext
|
Use graphene_ray_t to pick actors
This commit introduces a few important changes in order to
acommodate graphene_ray_t. Most of them are positive changes,
so don't panic :)
The first very visible change is that neither the actor box
nor the clip rectangles are projected before being pushed.
This required changing the parameters of the related functions
at both ClutterPickContext, and ClutterPickStack, to receive
boxes instead of vertices. These rectangles are projected on
demand now, so in the best case (first actor picked) only
one projection happens; and in the worst case, it projects
as much as it does now.
The second important change is that there are no more checks
for axis-alignment anymore. That's because picking now happens
in 3D space, using triangles.
Talking about triangles in 3D space, this is what is used now
for picking. We break down each actor rectangle in 2 triangles,
and check if the projected pick point is inside any one of them,
of if the ray intersects any one of them. The same check happens
for the clip rectangles.
Checking the projected pick point is both an optimization for the
2D case, and a workaround to graphene_ray_t problems with float
precision, which is specially visible on edges such as the top
bar.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1509
2020-10-17 11:52:45 -03:00
|
|
|
* @box: a #ClutterActorBox
|
2020-10-16 19:13:12 -03:00
|
|
|
*
|
Use graphene_ray_t to pick actors
This commit introduces a few important changes in order to
acommodate graphene_ray_t. Most of them are positive changes,
so don't panic :)
The first very visible change is that neither the actor box
nor the clip rectangles are projected before being pushed.
This required changing the parameters of the related functions
at both ClutterPickContext, and ClutterPickStack, to receive
boxes instead of vertices. These rectangles are projected on
demand now, so in the best case (first actor picked) only
one projection happens; and in the worst case, it projects
as much as it does now.
The second important change is that there are no more checks
for axis-alignment anymore. That's because picking now happens
in 3D space, using triangles.
Talking about triangles in 3D space, this is what is used now
for picking. We break down each actor rectangle in 2 triangles,
and check if the projected pick point is inside any one of them,
of if the ray intersects any one of them. The same check happens
for the clip rectangles.
Checking the projected pick point is both an optimization for the
2D case, and a workaround to graphene_ray_t problems with float
precision, which is specially visible on edges such as the top
bar.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1509
2020-10-17 11:52:45 -03:00
|
|
|
* Pushes a clip rectangle defined by @box into the pick stack. Pop with
|
|
|
|
* clutter_pick_context_pop_clip() when done.
|
2020-10-16 19:13:12 -03:00
|
|
|
*/
|
|
|
|
void
|
Use graphene_ray_t to pick actors
This commit introduces a few important changes in order to
acommodate graphene_ray_t. Most of them are positive changes,
so don't panic :)
The first very visible change is that neither the actor box
nor the clip rectangles are projected before being pushed.
This required changing the parameters of the related functions
at both ClutterPickContext, and ClutterPickStack, to receive
boxes instead of vertices. These rectangles are projected on
demand now, so in the best case (first actor picked) only
one projection happens; and in the worst case, it projects
as much as it does now.
The second important change is that there are no more checks
for axis-alignment anymore. That's because picking now happens
in 3D space, using triangles.
Talking about triangles in 3D space, this is what is used now
for picking. We break down each actor rectangle in 2 triangles,
and check if the projected pick point is inside any one of them,
of if the ray intersects any one of them. The same check happens
for the clip rectangles.
Checking the projected pick point is both an optimization for the
2D case, and a workaround to graphene_ray_t problems with float
precision, which is specially visible on edges such as the top
bar.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1509
2020-10-17 11:52:45 -03:00
|
|
|
clutter_pick_context_push_clip (ClutterPickContext *pick_context,
|
|
|
|
const ClutterActorBox *box)
|
2020-10-16 19:13:12 -03:00
|
|
|
{
|
Use graphene_ray_t to pick actors
This commit introduces a few important changes in order to
acommodate graphene_ray_t. Most of them are positive changes,
so don't panic :)
The first very visible change is that neither the actor box
nor the clip rectangles are projected before being pushed.
This required changing the parameters of the related functions
at both ClutterPickContext, and ClutterPickStack, to receive
boxes instead of vertices. These rectangles are projected on
demand now, so in the best case (first actor picked) only
one projection happens; and in the worst case, it projects
as much as it does now.
The second important change is that there are no more checks
for axis-alignment anymore. That's because picking now happens
in 3D space, using triangles.
Talking about triangles in 3D space, this is what is used now
for picking. We break down each actor rectangle in 2 triangles,
and check if the projected pick point is inside any one of them,
of if the ray intersects any one of them. The same check happens
for the clip rectangles.
Checking the projected pick point is both an optimization for the
2D case, and a workaround to graphene_ray_t problems with float
precision, which is specially visible on edges such as the top
bar.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1509
2020-10-17 11:52:45 -03:00
|
|
|
clutter_pick_stack_push_clip (pick_context->pick_stack, box);
|
2020-10-16 19:13:12 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_pick_context_pop_clip:
|
|
|
|
* @pick_context: a #ClutterPickContext
|
|
|
|
*
|
|
|
|
* Pops the current clip rectangle from the clip stack. It is a programming
|
|
|
|
* error to call this without a corresponding clutter_pick_context_push_clip()
|
|
|
|
* call first.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_pick_context_pop_clip (ClutterPickContext *pick_context)
|
|
|
|
{
|
|
|
|
clutter_pick_stack_pop_clip (pick_context->pick_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_pick_context_push_transform:
|
|
|
|
* @pick_context: a #ClutterPickContext
|
|
|
|
* @transform: a #graphene_matrix_t
|
|
|
|
*
|
|
|
|
* Pushes @transform into the pick stack. Pop with
|
|
|
|
* clutter_pick_context_pop_transform() when done.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_pick_context_push_transform (ClutterPickContext *pick_context,
|
|
|
|
const graphene_matrix_t *transform)
|
|
|
|
{
|
|
|
|
clutter_pick_stack_push_transform (pick_context->pick_stack, transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_pick_context_get_transform:
|
|
|
|
* @pick_context: a #ClutterPickContext
|
|
|
|
* @out_matrix: (out): a #graphene_matrix_t
|
|
|
|
*
|
|
|
|
* Retrieves the current transform of the pick stack.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_pick_context_get_transform (ClutterPickContext *pick_context,
|
|
|
|
graphene_matrix_t *out_transform)
|
|
|
|
{
|
|
|
|
clutter_pick_stack_get_transform (pick_context->pick_stack, out_transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_pick_context_pop_transform:
|
|
|
|
* @pick_context: a #ClutterPickContext
|
|
|
|
*
|
|
|
|
* Pops the current transform from the clip stack. It is a programming error
|
|
|
|
* to call this without a corresponding clutter_pick_context_push_transform()
|
|
|
|
* call first.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_pick_context_pop_transform (ClutterPickContext *pick_context)
|
|
|
|
{
|
|
|
|
clutter_pick_stack_pop_transform (pick_context->pick_stack);
|
|
|
|
}
|
2020-10-22 21:12:10 -03:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
clutter_pick_context_intersects_box (ClutterPickContext *pick_context,
|
|
|
|
const graphene_box_t *box)
|
|
|
|
{
|
|
|
|
return graphene_box_contains_point (box, &pick_context->point) ||
|
|
|
|
graphene_ray_intersects_box (&pick_context->ray, box);
|
|
|
|
}
|