2014-03-31 18:08:14 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Giovanni Campagna <gcampagn@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 08:36:24 +00:00
|
|
|
#include "backends/meta-cursor.h"
|
2014-03-31 18:08:14 +00:00
|
|
|
|
2018-04-26 12:29:57 +00:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "cogl/cogl.h"
|
|
|
|
#include "meta/common.h"
|
|
|
|
|
2018-04-26 12:53:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2015-07-17 15:16:39 +00:00
|
|
|
PREPARE_AT,
|
2017-11-16 18:16:54 +00:00
|
|
|
TEXTURE_CHANGED,
|
2015-07-17 15:16:39 +00:00
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
2014-03-31 19:21:19 +00:00
|
|
|
|
2018-04-23 14:57:01 +00:00
|
|
|
typedef struct _MetaCursorSpritePrivate
|
2015-03-10 06:41:12 +00:00
|
|
|
{
|
|
|
|
GObject parent;
|
|
|
|
|
2015-07-17 03:56:42 +00:00
|
|
|
CoglTexture2D *texture;
|
2015-07-17 15:16:39 +00:00
|
|
|
float texture_scale;
|
2015-07-17 03:56:42 +00:00
|
|
|
int hot_x, hot_y;
|
2018-04-23 14:57:01 +00:00
|
|
|
} MetaCursorSpritePrivate;
|
2015-03-10 06:41:12 +00:00
|
|
|
|
2018-04-30 10:03:31 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCursorSprite,
|
|
|
|
meta_cursor_sprite,
|
|
|
|
G_TYPE_OBJECT)
|
2014-03-31 18:08:14 +00:00
|
|
|
|
2018-04-27 13:43:37 +00:00
|
|
|
gboolean
|
|
|
|
meta_cursor_sprite_is_animated (MetaCursorSprite *sprite)
|
2015-07-13 18:32:42 +00:00
|
|
|
{
|
2018-04-27 13:43:37 +00:00
|
|
|
MetaCursorSpriteClass *klass = META_CURSOR_SPRITE_GET_CLASS (sprite);
|
2018-04-23 14:57:01 +00:00
|
|
|
|
2018-04-27 13:43:37 +00:00
|
|
|
if (klass->is_animated)
|
|
|
|
return klass->is_animated (sprite);
|
|
|
|
else
|
|
|
|
return FALSE;
|
2015-07-13 18:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite)
|
2015-07-13 18:32:42 +00:00
|
|
|
{
|
2018-04-27 13:43:37 +00:00
|
|
|
return META_CURSOR_SPRITE_GET_CLASS (sprite)->tick_frame (sprite);
|
2015-07-13 18:32:42 +00:00
|
|
|
}
|
|
|
|
|
2018-04-27 13:43:37 +00:00
|
|
|
unsigned int
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite)
|
2015-07-13 18:32:42 +00:00
|
|
|
{
|
2018-04-27 13:43:37 +00:00
|
|
|
return META_CURSOR_SPRITE_GET_CLASS (sprite)->get_current_frame_time (sprite);
|
2015-07-13 18:32:42 +00:00
|
|
|
}
|
|
|
|
|
2018-04-27 13:43:37 +00:00
|
|
|
void
|
|
|
|
meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite)
|
2014-11-27 22:34:25 +00:00
|
|
|
{
|
2018-04-23 14:57:01 +00:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
2015-03-10 06:35:49 +00:00
|
|
|
|
2018-04-27 13:43:37 +00:00
|
|
|
g_clear_pointer (&priv->texture, cogl_object_unref);
|
2014-03-31 19:21:19 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 15:16:39 +00:00
|
|
|
void
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
|
2015-07-17 15:16:39 +00:00
|
|
|
CoglTexture *texture,
|
|
|
|
int hot_x,
|
|
|
|
int hot_y)
|
2014-03-31 19:21:19 +00:00
|
|
|
{
|
2018-04-23 14:57:01 +00:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->texture, cogl_object_unref);
|
2015-07-17 15:16:39 +00:00
|
|
|
if (texture)
|
2018-04-23 14:57:01 +00:00
|
|
|
priv->texture = cogl_object_ref (texture);
|
|
|
|
priv->hot_x = hot_x;
|
|
|
|
priv->hot_y = hot_y;
|
2017-11-16 18:16:54 +00:00
|
|
|
|
2018-04-23 14:44:11 +00:00
|
|
|
g_signal_emit (sprite, signals[TEXTURE_CHANGED], 0);
|
2014-03-31 21:13:03 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 15:16:39 +00:00
|
|
|
void
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_set_texture_scale (MetaCursorSprite *sprite,
|
2015-07-17 15:16:39 +00:00
|
|
|
float scale)
|
2014-03-31 21:13:03 +00:00
|
|
|
{
|
2018-04-23 14:57:01 +00:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
priv->texture_scale = scale;
|
2015-07-17 15:16:39 +00:00
|
|
|
}
|
2014-03-31 19:21:19 +00:00
|
|
|
|
2014-03-31 19:31:15 +00:00
|
|
|
CoglTexture *
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *sprite)
|
2014-03-31 19:31:15 +00:00
|
|
|
{
|
2018-04-23 14:57:01 +00:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
return COGL_TEXTURE (priv->texture);
|
2014-03-31 19:31:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 03:16:58 +00:00
|
|
|
void
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_get_hotspot (MetaCursorSprite *sprite,
|
2015-03-11 03:16:58 +00:00
|
|
|
int *hot_x,
|
|
|
|
int *hot_y)
|
|
|
|
{
|
2018-04-23 14:57:01 +00:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
*hot_x = priv->hot_x;
|
|
|
|
*hot_y = priv->hot_y;
|
2014-03-31 19:31:15 +00:00
|
|
|
}
|
2014-04-23 15:04:08 +00:00
|
|
|
|
2015-07-17 15:16:39 +00:00
|
|
|
float
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_get_texture_scale (MetaCursorSprite *sprite)
|
2014-04-23 15:04:08 +00:00
|
|
|
{
|
2018-04-23 14:57:01 +00:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
return priv->texture_scale;
|
2015-03-11 03:16:58 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 15:16:39 +00:00
|
|
|
void
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
|
2015-07-17 15:16:39 +00:00
|
|
|
int x,
|
|
|
|
int y)
|
|
|
|
{
|
2018-04-23 14:44:11 +00:00
|
|
|
g_signal_emit (sprite, signals[PREPARE_AT], 0, x, y);
|
2015-07-17 15:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite)
|
2015-03-11 03:16:58 +00:00
|
|
|
{
|
2018-04-27 13:43:37 +00:00
|
|
|
MetaCursorSpriteClass *klass = META_CURSOR_SPRITE_GET_CLASS (sprite);
|
2018-04-23 14:57:01 +00:00
|
|
|
|
2018-04-27 13:43:37 +00:00
|
|
|
if (klass->realize_texture)
|
|
|
|
klass->realize_texture (sprite);
|
2014-04-23 15:04:08 +00:00
|
|
|
}
|
2015-03-10 06:35:49 +00:00
|
|
|
|
|
|
|
static void
|
2018-04-23 14:44:11 +00:00
|
|
|
meta_cursor_sprite_init (MetaCursorSprite *sprite)
|
2015-03-10 06:35:49 +00:00
|
|
|
{
|
2018-04-23 14:57:01 +00:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
priv->texture_scale = 1.0f;
|
2015-03-10 06:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_sprite_finalize (GObject *object)
|
|
|
|
{
|
2018-04-23 14:44:11 +00:00
|
|
|
MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
|
2018-04-23 14:57:01 +00:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
2015-03-10 06:35:49 +00:00
|
|
|
|
2018-04-23 14:57:01 +00:00
|
|
|
g_clear_pointer (&priv->texture, cogl_object_unref);
|
2015-03-10 06:35:49 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_cursor_sprite_finalize;
|
2015-07-17 15:16:39 +00:00
|
|
|
|
|
|
|
signals[PREPARE_AT] = g_signal_new ("prepare-at",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
2017-11-16 18:16:54 +00:00
|
|
|
signals[TEXTURE_CHANGED] = g_signal_new ("texture-changed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2015-03-10 06:35:49 +00:00
|
|
|
}
|