Move ShellDrawingArea to StDrawingArea
It's nicer to have ShellDrawingArea as a St widget so it can participate more cleanly in CSS styling, such as queuing a redraw automatically on style changes, and allowing subclasses to use CSS styling. https://bugzilla.gnome.org/show_bug.cgi?id=602131
This commit is contained in:
parent
b0cb8fb85a
commit
f815844eb4
@ -686,7 +686,7 @@ AppSwitcher.prototype = {
|
||||
appIcon.actor.reactive = false;
|
||||
|
||||
let n = this._arrows.length;
|
||||
let arrow = new Shell.DrawingArea();
|
||||
let arrow = new St.DrawingArea();
|
||||
arrow.connect('redraw', Lang.bind(this,
|
||||
function (area, texture) {
|
||||
Shell.draw_box_pointer(texture, Shell.PointerDirection.DOWN,
|
||||
|
@ -307,7 +307,7 @@ AppIconMenu.prototype = {
|
||||
this._windowContainer.connect('leave-event', Lang.bind(this, this._onMenuLeave));
|
||||
this._windowContainer.connect('button-release-event', Lang.bind(this, this._onMenuButtonRelease));
|
||||
|
||||
this._arrow = new Shell.DrawingArea();
|
||||
this._arrow = new St.DrawingArea();
|
||||
this._arrow.connect('redraw', Lang.bind(this, function (area, texture) {
|
||||
Shell.draw_box_pointer(texture,
|
||||
this._type == MenuType.ON_RIGHT ? Shell.PointerDirection.LEFT : Shell.PointerDirection.UP,
|
||||
|
@ -73,6 +73,7 @@ st_source_h = \
|
||||
st/st-box-layout-child.h \
|
||||
st/st-button.h \
|
||||
st/st-clipboard.h \
|
||||
st/st-drawing-area.h \
|
||||
st/st-entry.h \
|
||||
st/st-im-text.h \
|
||||
st/st-label.h \
|
||||
@ -109,6 +110,7 @@ st_source_c = \
|
||||
st/st-box-layout-child.c \
|
||||
st/st-button.c \
|
||||
st/st-clipboard.c \
|
||||
st/st-drawing-area.c \
|
||||
st/st-entry.c \
|
||||
st/st-im-text.c \
|
||||
st/st-label.c \
|
||||
|
@ -67,8 +67,6 @@ libgnome_shell_la_SOURCES = \
|
||||
shell-button-box.h \
|
||||
shell-drawing.c \
|
||||
shell-drawing.h \
|
||||
shell-drawing-area.c \
|
||||
shell-drawing-area.h \
|
||||
shell-embedded-window.c \
|
||||
shell-embedded-window.h \
|
||||
shell-embedded-window-private.h \
|
||||
|
@ -1,102 +0,0 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/**
|
||||
* SECTION:shell-drawing-area
|
||||
* @short_description: A dynamically-sized Cairo drawing area
|
||||
*
|
||||
* #ShellDrawingArea is similar to #ClutterCairoTexture in that
|
||||
* it allows drawing via Cairo; the primary difference is that
|
||||
* it is dynamically sized. To use, connect to the @redraw
|
||||
* signal, and inside the signal handler, call
|
||||
* clutter_cairo_texture_create() to begin drawing.
|
||||
*/
|
||||
|
||||
#include "shell-drawing-area.h"
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <cairo.h>
|
||||
|
||||
G_DEFINE_TYPE(ShellDrawingArea, shell_drawing_area, CLUTTER_TYPE_GROUP);
|
||||
|
||||
struct _ShellDrawingAreaPrivate {
|
||||
ClutterCairoTexture *texture;
|
||||
};
|
||||
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
REDRAW,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint shell_drawing_area_signals [LAST_SIGNAL] = { 0 };
|
||||
|
||||
static void
|
||||
shell_drawing_area_allocate (ClutterActor *self,
|
||||
const ClutterActorBox *box,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
ShellDrawingArea *area = SHELL_DRAWING_AREA (self);
|
||||
int width = box->x2 - box->x1;
|
||||
int height = box->y2 - box->y1;
|
||||
ClutterActorBox child_box;
|
||||
|
||||
/* Chain up directly to ClutterActor to set actor->allocation. We explicitly skip our parent class
|
||||
* ClutterGroup 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_box.x1 = 0;
|
||||
child_box.x2 = width;
|
||||
child_box.y1 = 0;
|
||||
child_box.y2 = height;
|
||||
|
||||
clutter_actor_allocate (CLUTTER_ACTOR (area->priv->texture), &child_box, flags);
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
clutter_cairo_texture_set_surface_size (area->priv->texture,
|
||||
width, height);
|
||||
g_signal_emit (G_OBJECT (self), shell_drawing_area_signals[REDRAW], 0,
|
||||
area->priv->texture);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
shell_drawing_area_class_init (ShellDrawingAreaClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
||||
|
||||
actor_class->allocate = shell_drawing_area_allocate;
|
||||
|
||||
shell_drawing_area_signals[REDRAW] =
|
||||
g_signal_new ("redraw",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ShellDrawingAreaClass, redraw),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT,
|
||||
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (ShellDrawingAreaPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
shell_drawing_area_init (ShellDrawingArea *area)
|
||||
{
|
||||
area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, SHELL_TYPE_DRAWING_AREA,
|
||||
ShellDrawingAreaPrivate);
|
||||
area->priv->texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (1, 1));
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (area), CLUTTER_ACTOR (area->priv->texture));
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_drawing_area_get_texture:
|
||||
*
|
||||
* Return Value: (transfer none):
|
||||
*/
|
||||
ClutterCairoTexture *
|
||||
shell_drawing_area_get_texture (ShellDrawingArea *area)
|
||||
{
|
||||
return area->priv->texture;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
#ifndef __SHELL_DRAWING_AREA_H__
|
||||
#define __SHELL_DRAWING_AREA_H__
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define SHELL_TYPE_DRAWING_AREA (shell_drawing_area_get_type ())
|
||||
#define SHELL_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHELL_TYPE_DRAWING_AREA, ShellDrawingArea))
|
||||
#define SHELL_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SHELL_TYPE_DRAWING_AREA, ShellDrawingAreaClass))
|
||||
#define SHELL_IS_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SHELL_TYPE_DRAWING_AREA))
|
||||
#define SHELL_IS_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SHELL_TYPE_DRAWING_AREA))
|
||||
#define SHELL_DRAWING_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SHELL_TYPE_DRAWING_AREA, ShellDrawingAreaClass))
|
||||
|
||||
typedef struct _ShellDrawingArea ShellDrawingArea;
|
||||
typedef struct _ShellDrawingAreaClass ShellDrawingAreaClass;
|
||||
|
||||
typedef struct _ShellDrawingAreaPrivate ShellDrawingAreaPrivate;
|
||||
|
||||
struct _ShellDrawingArea
|
||||
{
|
||||
ClutterGroup parent;
|
||||
|
||||
ShellDrawingAreaPrivate *priv;
|
||||
};
|
||||
|
||||
struct _ShellDrawingAreaClass
|
||||
{
|
||||
ClutterGroupClass parent_class;
|
||||
|
||||
void (*redraw) (ShellDrawingArea *area, ClutterCairoTexture *texture);
|
||||
};
|
||||
|
||||
GType shell_drawing_area_get_type (void) G_GNUC_CONST;
|
||||
|
||||
ClutterCairoTexture *shell_drawing_area_get_texture (ShellDrawingArea *area);
|
||||
|
||||
#endif /* __SHELL_DRAWING_AREA_H__ */
|
@ -3,102 +3,6 @@
|
||||
#include "shell-drawing.h"
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
* shell_create_vertical_gradient:
|
||||
* @top: the color at the top
|
||||
* @bottom: the color at the bottom
|
||||
*
|
||||
* Creates a vertical gradient actor.
|
||||
*
|
||||
* Return value: (transfer none): a #ClutterCairoTexture actor with the
|
||||
* gradient. The texture actor is floating, hence (transfer none).
|
||||
*/
|
||||
ClutterCairoTexture *
|
||||
shell_create_vertical_gradient (ClutterColor *top,
|
||||
ClutterColor *bottom)
|
||||
{
|
||||
ClutterCairoTexture *texture;
|
||||
cairo_t *cr;
|
||||
cairo_pattern_t *pattern;
|
||||
|
||||
/* Draw the gradient on an 8x8 pixel texture. Because the gradient is drawn
|
||||
* from the uppermost to the lowermost row, after stretching 1/16 of the
|
||||
* texture height has the top color and 1/16 has the bottom color. The 8
|
||||
* pixel width is chosen for reasons related to graphics hardware internals.
|
||||
*/
|
||||
texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 8));
|
||||
cr = clutter_cairo_texture_create (texture);
|
||||
|
||||
pattern = cairo_pattern_create_linear (0, 0, 0, 8);
|
||||
cairo_pattern_add_color_stop_rgba (pattern, 0,
|
||||
top->red / 255.,
|
||||
top->green / 255.,
|
||||
top->blue / 255.,
|
||||
top->alpha / 255.);
|
||||
cairo_pattern_add_color_stop_rgba (pattern, 1,
|
||||
bottom->red / 255.,
|
||||
bottom->green / 255.,
|
||||
bottom->blue / 255.,
|
||||
bottom->alpha / 255.);
|
||||
|
||||
cairo_set_source (cr, pattern);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_pattern_destroy (pattern);
|
||||
cairo_destroy (cr);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_create_horizontal_gradient:
|
||||
* @left: the color on the left
|
||||
* @right: the color on the right
|
||||
*
|
||||
* Creates a horizontal gradient actor.
|
||||
*
|
||||
* Return value: (transfer none): a #ClutterCairoTexture actor with the
|
||||
* gradient. The texture actor is floating, hence (transfer none).
|
||||
*/
|
||||
ClutterCairoTexture *
|
||||
shell_create_horizontal_gradient (ClutterColor *left,
|
||||
ClutterColor *right)
|
||||
{
|
||||
ClutterCairoTexture *texture;
|
||||
cairo_t *cr;
|
||||
cairo_pattern_t *pattern;
|
||||
|
||||
/* Draw the gradient on an 8x1 pixel texture. Because the gradient is drawn
|
||||
* from the left to the right column, after stretching 1/16 of the
|
||||
* texture width has the left side color and 1/16 has the right side color.
|
||||
* There is no reason to use the 8 pixel height that would be similar to the
|
||||
* reason we are using the 8 pixel width for the vertical gradient, so we
|
||||
* are just using the 1 pixel height instead.
|
||||
*/
|
||||
texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 1));
|
||||
cr = clutter_cairo_texture_create (texture);
|
||||
|
||||
pattern = cairo_pattern_create_linear (0, 0, 8, 0);
|
||||
cairo_pattern_add_color_stop_rgba (pattern, 0,
|
||||
left->red / 255.,
|
||||
left->green / 255.,
|
||||
left->blue / 255.,
|
||||
left->alpha / 255.);
|
||||
cairo_pattern_add_color_stop_rgba (pattern, 1,
|
||||
right->red / 255.,
|
||||
right->green / 255.,
|
||||
right->blue / 255.,
|
||||
right->alpha / 255.);
|
||||
|
||||
cairo_set_source (cr, pattern);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_pattern_destroy (pattern);
|
||||
cairo_destroy (cr);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
void
|
||||
shell_draw_clock (ClutterCairoTexture *texture,
|
||||
int hour,
|
||||
|
@ -7,12 +7,6 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
ClutterCairoTexture *shell_create_vertical_gradient (ClutterColor *top,
|
||||
ClutterColor *bottom);
|
||||
|
||||
ClutterCairoTexture *shell_create_horizontal_gradient (ClutterColor *left,
|
||||
ClutterColor *right);
|
||||
|
||||
typedef enum {
|
||||
SHELL_POINTER_UP,
|
||||
SHELL_POINTER_DOWN,
|
||||
|
125
src/st/st-drawing-area.c
Normal file
125
src/st/st-drawing-area.c
Normal file
@ -0,0 +1,125 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/**
|
||||
* SECTION:st-drawing-area
|
||||
* @short_description: A dynamically-sized Cairo drawing area
|
||||
*
|
||||
* #StDrawingArea is similar to #ClutterCairoTexture in that
|
||||
* it allows drawing via Cairo; the primary difference is that
|
||||
* it is dynamically sized. To use, connect to the #StDrawingArea::redraw
|
||||
* signal, and inside the signal handler, call
|
||||
* clutter_cairo_texture_create() to begin drawing. The
|
||||
* #StDrawingArea::redraw signal will be emitted by default when the area is
|
||||
* resized or the CSS style changes; you can use the
|
||||
* st_drawing_area_emit_redraw() as well.
|
||||
*/
|
||||
|
||||
#include "st-drawing-area.h"
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
G_DEFINE_TYPE(StDrawingArea, st_drawing_area, ST_TYPE_BIN);
|
||||
|
||||
struct _StDrawingAreaPrivate {
|
||||
ClutterCairoTexture *texture;
|
||||
};
|
||||
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
REDRAW,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint st_drawing_area_signals [LAST_SIGNAL] = { 0 };
|
||||
|
||||
static void
|
||||
st_drawing_area_allocate (ClutterActor *self,
|
||||
const ClutterActorBox *box,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
StThemeNode *theme_node;
|
||||
ClutterActorBox content_box;
|
||||
StDrawingArea *area = ST_DRAWING_AREA (self);
|
||||
int width = box->x2 - box->x1;
|
||||
int height = box->y2 - box->y1;
|
||||
|
||||
(CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class))->allocate (self, box, flags);
|
||||
|
||||
theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||
|
||||
st_theme_node_get_content_box (theme_node, box, &content_box);
|
||||
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
clutter_cairo_texture_set_surface_size (area->priv->texture,
|
||||
content_box.x2 - content_box.x1,
|
||||
content_box.y2 - content_box.y1);
|
||||
g_signal_emit (G_OBJECT (self), st_drawing_area_signals[REDRAW], 0,
|
||||
area->priv->texture);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
st_drawing_area_style_changed (StWidget *self)
|
||||
{
|
||||
(ST_WIDGET_CLASS (st_drawing_area_parent_class))->style_changed (self);
|
||||
|
||||
st_drawing_area_emit_redraw (ST_DRAWING_AREA (self));
|
||||
}
|
||||
|
||||
static void
|
||||
st_drawing_area_class_init (StDrawingAreaClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
||||
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
|
||||
|
||||
actor_class->allocate = st_drawing_area_allocate;
|
||||
widget_class->style_changed = st_drawing_area_style_changed;
|
||||
|
||||
st_drawing_area_signals[REDRAW] =
|
||||
g_signal_new ("redraw",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (StDrawingAreaClass, redraw),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT,
|
||||
G_TYPE_NONE, 1, CLUTTER_TYPE_CAIRO_TEXTURE);
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (StDrawingAreaPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
st_drawing_area_init (StDrawingArea *area)
|
||||
{
|
||||
area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, ST_TYPE_DRAWING_AREA,
|
||||
StDrawingAreaPrivate);
|
||||
area->priv->texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (1, 1));
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (area), CLUTTER_ACTOR (area->priv->texture));
|
||||
}
|
||||
|
||||
/**
|
||||
* st_drawing_area_get_texture:
|
||||
*
|
||||
* Return Value: (transfer none):
|
||||
*/
|
||||
ClutterCairoTexture *
|
||||
st_drawing_area_get_texture (StDrawingArea *area)
|
||||
{
|
||||
return area->priv->texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* st_drawing_area_emit_redraw:
|
||||
* @area: A #StDrawingArea
|
||||
*
|
||||
* Immediately emit a redraw signal. Useful if
|
||||
* some parameters for the area being drawn other
|
||||
* than the size or style have changed.
|
||||
*/
|
||||
void
|
||||
st_drawing_area_emit_redraw (StDrawingArea *area)
|
||||
{
|
||||
g_signal_emit ((GObject*)area, st_drawing_area_signals[REDRAW], 0, area->priv->texture);
|
||||
}
|
39
src/st/st-drawing-area.h
Normal file
39
src/st/st-drawing-area.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
#ifndef __ST_DRAWING_AREA_H__
|
||||
#define __ST_DRAWING_AREA_H__
|
||||
|
||||
#include "st-bin.h"
|
||||
|
||||
#define ST_TYPE_DRAWING_AREA (st_drawing_area_get_type ())
|
||||
#define ST_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ST_TYPE_DRAWING_AREA, StDrawingArea))
|
||||
#define ST_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ST_TYPE_DRAWING_AREA, StDrawingAreaClass))
|
||||
#define ST_IS_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ST_TYPE_DRAWING_AREA))
|
||||
#define ST_IS_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ST_TYPE_DRAWING_AREA))
|
||||
#define ST_DRAWING_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ST_TYPE_DRAWING_AREA, StDrawingAreaClass))
|
||||
|
||||
typedef struct _StDrawingArea StDrawingArea;
|
||||
typedef struct _StDrawingAreaClass StDrawingAreaClass;
|
||||
|
||||
typedef struct _StDrawingAreaPrivate StDrawingAreaPrivate;
|
||||
|
||||
struct _StDrawingArea
|
||||
{
|
||||
StBin parent;
|
||||
|
||||
StDrawingAreaPrivate *priv;
|
||||
};
|
||||
|
||||
struct _StDrawingAreaClass
|
||||
{
|
||||
StBinClass parent_class;
|
||||
|
||||
void (*redraw) (StDrawingArea *area, ClutterCairoTexture *texture);
|
||||
};
|
||||
|
||||
GType st_drawing_area_get_type (void) G_GNUC_CONST;
|
||||
|
||||
ClutterCairoTexture *st_drawing_area_get_texture (StDrawingArea *area);
|
||||
|
||||
void st_drawing_area_emit_redraw (StDrawingArea *area);
|
||||
|
||||
#endif /* __ST_DRAWING_AREA_H__ */
|
Loading…
Reference in New Issue
Block a user