[ShellSlicer] New class to display center of child
A #StBin that has 0 minimum size, and will clip its child in the middle. https://bugzilla.gnome.org/show_bug.cgi?id=605491
This commit is contained in:
parent
da797dff35
commit
262f92e0be
@ -85,6 +85,8 @@ libgnome_shell_la_SOURCES = \
|
||||
shell-global.c \
|
||||
shell-global.h \
|
||||
shell-global-private.h \
|
||||
shell-slicer.c \
|
||||
shell-slicer.h \
|
||||
shell-stack.c \
|
||||
shell-stack.h \
|
||||
shell-tray-manager.c \
|
||||
|
162
src/shell-slicer.c
Normal file
162
src/shell-slicer.c
Normal file
@ -0,0 +1,162 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/**
|
||||
* SECTION:shell-slicer
|
||||
* @short_description: Display only part of another actor
|
||||
*
|
||||
* A #StBin that has 0 minimum size, and will clip its child
|
||||
* in the middle.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "shell-slicer.h"
|
||||
|
||||
G_DEFINE_TYPE (ShellSlicer,
|
||||
shell_slicer,
|
||||
ST_TYPE_BIN);
|
||||
|
||||
static void
|
||||
shell_slicer_get_preferred_width (ClutterActor *self,
|
||||
gfloat for_height,
|
||||
gfloat *min_width_p,
|
||||
gfloat *natural_width_p)
|
||||
{
|
||||
ClutterActor *child = st_bin_get_child (ST_BIN (self));
|
||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||
|
||||
st_theme_node_adjust_for_height (theme_node, &for_height);
|
||||
|
||||
if (min_width_p)
|
||||
*min_width_p = 0;
|
||||
|
||||
if (child == NULL)
|
||||
{
|
||||
if (natural_width_p)
|
||||
*natural_width_p = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
clutter_actor_get_preferred_width (child, for_height,
|
||||
NULL,
|
||||
natural_width_p);
|
||||
}
|
||||
|
||||
st_theme_node_adjust_preferred_width (theme_node, min_width_p, natural_width_p);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_slicer_get_preferred_height (ClutterActor *self,
|
||||
gfloat for_width,
|
||||
gfloat *min_height_p,
|
||||
gfloat *natural_height_p)
|
||||
{
|
||||
ClutterActor *child = st_bin_get_child (ST_BIN (self));
|
||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||
|
||||
st_theme_node_adjust_for_width (theme_node, &for_width);
|
||||
|
||||
if (min_height_p)
|
||||
*min_height_p = 0;
|
||||
|
||||
if (child == NULL)
|
||||
{
|
||||
if (natural_height_p)
|
||||
*natural_height_p = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
clutter_actor_get_preferred_height (child, for_width,
|
||||
NULL,
|
||||
natural_height_p);
|
||||
}
|
||||
|
||||
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_slicer_allocate (ClutterActor *self,
|
||||
const ClutterActorBox *box,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
ClutterActor *child;
|
||||
|
||||
/* Chain up directly to ClutterActor to set actor->allocation. We explicitly skip our parent class
|
||||
* StBin here because we want to override the allocate function. */
|
||||
CLUTTER_ACTOR_CLASS (g_type_class_peek (clutter_actor_get_type ()))->allocate (self, box, flags);
|
||||
|
||||
child = st_bin_get_child (ST_BIN (self));
|
||||
if (child)
|
||||
clutter_actor_allocate_preferred_size (child, flags);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_slicer_paint_child (ShellSlicer *self)
|
||||
{
|
||||
ClutterActor *child;
|
||||
ClutterActorBox self_box;
|
||||
ClutterActorBox child_box;
|
||||
float width, height, child_width, child_height;
|
||||
double x_align, y_align;
|
||||
|
||||
child = st_bin_get_child (ST_BIN (self));
|
||||
|
||||
if (!child)
|
||||
return;
|
||||
|
||||
_st_bin_get_align_factors (ST_BIN (self), &x_align, &y_align);
|
||||
|
||||
clutter_actor_get_allocation_box (CLUTTER_ACTOR (self), &self_box);
|
||||
clutter_actor_get_allocation_box (child, &child_box);
|
||||
|
||||
width = self_box.x2 - self_box.x1;
|
||||
height = self_box.y2 - self_box.y1;
|
||||
child_width = child_box.x2 - child_box.x1;
|
||||
child_height = child_box.y2 - child_box.y1;
|
||||
|
||||
cogl_push_matrix ();
|
||||
|
||||
cogl_clip_push (0, 0, width, height);
|
||||
cogl_translate ((int)(0.5 + x_align * (width - child_width)),
|
||||
(int)(0.5 + y_align * (height - child_height)),
|
||||
0);
|
||||
|
||||
clutter_actor_paint (child);
|
||||
|
||||
cogl_clip_pop ();
|
||||
|
||||
cogl_pop_matrix ();
|
||||
}
|
||||
|
||||
static void
|
||||
shell_slicer_paint (ClutterActor *self)
|
||||
{
|
||||
/* StWidget paints CSS elements */
|
||||
CLUTTER_ACTOR_CLASS (g_type_class_peek (st_widget_get_type ()))->paint (self);
|
||||
|
||||
shell_slicer_paint_child (SHELL_SLICER (self));
|
||||
}
|
||||
|
||||
static void
|
||||
shell_slicer_pick (ClutterActor *self,
|
||||
const ClutterColor *pick_color)
|
||||
{
|
||||
shell_slicer_paint_child (SHELL_SLICER (self));
|
||||
}
|
||||
|
||||
static void
|
||||
shell_slicer_class_init (ShellSlicerClass *klass)
|
||||
{
|
||||
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
||||
|
||||
actor_class->get_preferred_width = shell_slicer_get_preferred_width;
|
||||
actor_class->get_preferred_height = shell_slicer_get_preferred_height;
|
||||
actor_class->allocate = shell_slicer_allocate;
|
||||
actor_class->paint = shell_slicer_paint;
|
||||
actor_class->pick = shell_slicer_pick;
|
||||
}
|
||||
|
||||
static void
|
||||
shell_slicer_init (ShellSlicer *actor)
|
||||
{
|
||||
}
|
33
src/shell-slicer.h
Normal file
33
src/shell-slicer.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
#ifndef __SHELL_SLICER_H__
|
||||
#define __SHELL_SLICER_H__
|
||||
|
||||
#include "st/st.h"
|
||||
|
||||
#define SHELL_TYPE_SLICER (shell_slicer_get_type ())
|
||||
#define SHELL_SLICER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHELL_TYPE_SLICER, ShellSlicer))
|
||||
#define SHELL_SLICER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SHELL_TYPE_SLICER, ShellSlicerClass))
|
||||
#define SHELL_IS_SLICER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SHELL_TYPE_SLICER))
|
||||
#define SHELL_IS_SLICER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SHELL_TYPE_SLICER))
|
||||
#define SHELL_SLICER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SHELL_TYPE_SLICER, ShellSlicerClass))
|
||||
|
||||
typedef struct _ShellSlicer ShellSlicer;
|
||||
typedef struct _ShellSlicerClass ShellSlicerClass;
|
||||
|
||||
typedef struct _ShellSlicerPrivate ShellSlicerPrivate;
|
||||
|
||||
struct _ShellSlicer
|
||||
{
|
||||
StBin parent;
|
||||
|
||||
ShellSlicerPrivate *priv;
|
||||
};
|
||||
|
||||
struct _ShellSlicerClass
|
||||
{
|
||||
StBinClass parent_class;
|
||||
};
|
||||
|
||||
GType shell_slicer_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#endif /* __SHELL_SLICER_H__ */
|
Loading…
Reference in New Issue
Block a user