Deprecate gtk_snapshot_render apis

Move the implementations from gtksnapshot.c to
gtk/deprecated/gtkrender.c and deprecated these
functions. We want to get rid of them.

These functions are still used in some of our widgetry,
so use G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS around
them.
This commit is contained in:
Matthias Clasen 2022-10-08 09:22:26 -04:00
parent 35370752d5
commit 60dafebd91
22 changed files with 521 additions and 462 deletions

View File

@ -348,7 +348,7 @@
#include "deprecated/gtkcellareacontext.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontext.h"
#include "gtknative.h"

View File

@ -30,7 +30,7 @@
#include <glib/gi18n-lib.h>
#include "gtkorientable.h"
#include "gtkprivate.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontext.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS

View File

@ -26,7 +26,7 @@
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtksizerequest.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontextprivate.h"
#include "deprecated/gtktreeprivate.h"

View File

@ -24,7 +24,7 @@
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkrendericonprivate.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontextprivate.h"
#include "gtkwidgetprivate.h"
#include "deprecated/gtktreeprivate.h"

View File

@ -34,7 +34,7 @@
#include "gtkprivate.h"
#include "gtkscrollable.h"
#include "gtksizerequest.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontextprivate.h"
#include "gtktreednd.h"
#include "gtktypebuiltins.h"
@ -1712,9 +1712,11 @@ gtk_icon_view_snapshot (GtkWidget *widget,
gtk_style_context_save_to_node (context, icon_view->priv->dndnode);
gtk_style_context_set_state (context, gtk_style_context_get_state (context) | GTK_STATE_FLAG_DROP_ACTIVE);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_frame (snapshot, context,
rect.x, rect.y,
rect.width, rect.height);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_style_context_restore (context);
}
@ -2834,6 +2836,7 @@ gtk_icon_view_snapshot_item (GtkIconView *icon_view,
gtk_style_context_set_state (style_context, state);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (snapshot, style_context,
x - priv->item_padding,
y - priv->item_padding,
@ -2844,6 +2847,7 @@ gtk_icon_view_snapshot_item (GtkIconView *icon_view,
y - priv->item_padding,
item->cell_area.width + priv->item_padding * 2,
item->cell_area.height + priv->item_padding * 2);
G_GNUC_END_IGNORE_DEPRECATIONS
cell_area.x = x;
cell_area.y = y;
@ -2875,12 +2879,14 @@ gtk_icon_view_snapshot_rubberband (GtkIconView *icon_view,
gtk_style_context_save_to_node (context, priv->rubberband_node);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (snapshot, context,
rect.x, rect.y,
rect.width, rect.height);
gtk_snapshot_render_frame (snapshot, context,
rect.x, rect.y,
rect.width, rect.height);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_style_context_restore (context);
}

View File

@ -28,7 +28,10 @@
#include "gtkcssshadowvalueprivate.h"
#include "gtkcsstransformvalueprivate.h"
#include "gtkrendericonprivate.h"
#include "gtkrenderborderprivate.h"
#include "gtkrenderbackgroundprivate.h"
#include "gtkstylecontextprivate.h"
#include "gtksettings.h"
#include "gsk/gskroundedrectprivate.h"
#include <gdk/gdktextureprivate.h>
@ -539,3 +542,425 @@ gtk_render_icon (GtkStyleContext *context,
gsk_render_node_draw (node, cr);
cairo_restore (cr);
}
/**
* gtk_snapshot_render_background:
* @snapshot: a `GtkSnapshot`
* @context: the style context that defines the background
* @x: X origin of the rectangle
* @y: Y origin of the rectangle
* @width: rectangle width
* @height: rectangle height
*
* Creates a render node for the CSS background according to @context,
* and appends it to the current node of @snapshot, without changing
* the current node.
*
* Deprecated: 4.10
*/
void
gtk_snapshot_render_background (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height)
{
GtkCssBoxes boxes;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_css_boxes_init_border_box (&boxes,
gtk_style_context_lookup_style (context),
x, y, width, height);
gtk_css_style_snapshot_background (&boxes, snapshot);
}
/**
* gtk_snapshot_render_frame:
* @snapshot: a `GtkSnapshot`
* @context: the style context that defines the frame
* @x: X origin of the rectangle
* @y: Y origin of the rectangle
* @width: rectangle width
* @height: rectangle height
*
* Creates a render node for the CSS border according to @context,
* and appends it to the current node of @snapshot, without changing
* the current node.
*
* Deprecated: 4.10
*/
void
gtk_snapshot_render_frame (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height)
{
GtkCssBoxes boxes;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_css_boxes_init_border_box (&boxes,
gtk_style_context_lookup_style (context),
x, y, width, height);
gtk_css_style_snapshot_border (&boxes, snapshot);
}
/**
* gtk_snapshot_render_focus:
* @snapshot: a `GtkSnapshot`
* @context: the style context that defines the focus ring
* @x: X origin of the rectangle
* @y: Y origin of the rectangle
* @width: rectangle width
* @height: rectangle height
*
* Creates a render node for the focus outline according to @context,
* and appends it to the current node of @snapshot, without changing
* the current node.
*
* Deprecated: 4.10
*/
void
gtk_snapshot_render_focus (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height)
{
GtkCssBoxes boxes;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_css_boxes_init_border_box (&boxes,
gtk_style_context_lookup_style (context),
x, y, width, height);
gtk_css_style_snapshot_outline (&boxes, snapshot);
}
/**
* gtk_snapshot_render_layout:
* @snapshot: a `GtkSnapshot`
* @context: the style context that defines the text
* @x: X origin of the rectangle
* @y: Y origin of the rectangle
* @layout: the `PangoLayout` to render
*
* Creates a render node for rendering @layout according to the style
* information in @context, and appends it to the current node of @snapshot,
* without changing the current node.
*
* Deprecated: 4.10
*/
void
gtk_snapshot_render_layout (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
PangoLayout *layout)
{
const bool needs_translate = (x != 0 || y != 0);
const GdkRGBA *fg_color;
GtkCssValue *shadows_value;
gboolean has_shadow;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (PANGO_IS_LAYOUT (layout));
if (needs_translate)
{
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
}
fg_color = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
shadows_value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
has_shadow = gtk_css_shadow_value_push_snapshot (shadows_value, snapshot);
gtk_snapshot_append_layout (snapshot, layout, fg_color);
if (has_shadow)
gtk_snapshot_pop (snapshot);
if (needs_translate)
gtk_snapshot_restore (snapshot);
}
static void
draw_insertion_cursor (GtkStyleContext *context,
cairo_t *cr,
double x,
double y,
double width,
double height,
double aspect_ratio,
gboolean is_primary,
PangoDirection direction,
gboolean draw_arrow)
{
GdkRGBA primary_color;
GdkRGBA secondary_color;
int stem_width;
double angle;
double dx, dy;
double xx1, yy1, xx2, yy2;
cairo_save (cr);
cairo_new_path (cr);
_gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
stem_width = height * aspect_ratio + 1;
yy1 = y;
yy2 = y + height;
if (width < 0)
{
xx1 = x;
xx2 = x - width;
}
else
{
xx1 = x + width;
xx2 = x;
}
angle = atan2 (height, width);
dx = (stem_width/2.0) * cos (M_PI/2 - angle);
dy = (stem_width/2.0) * sin (M_PI/2 - angle);
if (draw_arrow)
{
if (direction == PANGO_DIRECTION_RTL)
{
double x0, y0, x1, y1, x2, y2;
x0 = xx2 - dx + 2 * dy;
y0 = yy2 - dy - 2 * dx;
x1 = x0 + 4 * dy;
y1 = y0 - 4 * dx;
x2 = x0 + 2 * dy - 3 * dx;
y2 = y0 - 2 * dx - 3 * dy;
cairo_move_to (cr, xx1 + dx, yy1 + dy);
cairo_line_to (cr, xx2 + dx, yy2 + dy);
cairo_line_to (cr, x2, y2);
cairo_line_to (cr, x1, y1);
cairo_line_to (cr, xx1 - dx, yy1 - dy);
}
else if (direction == PANGO_DIRECTION_LTR)
{
double x0, y0, x1, y1, x2, y2;
x0 = xx2 + dx + 2 * dy;
y0 = yy2 + dy - 2 * dx;
x1 = x0 + 4 * dy;
y1 = y0 - 4 * dx;
x2 = x0 + 2 * dy + 3 * dx;
y2 = y0 - 2 * dx + 3 * dy;
cairo_move_to (cr, xx1 - dx, yy1 - dy);
cairo_line_to (cr, xx2 - dx, yy2 - dy);
cairo_line_to (cr, x2, y2);
cairo_line_to (cr, x1, y1);
cairo_line_to (cr, xx1 + dx, yy1 + dy);
}
else
g_assert_not_reached();
}
else
{
cairo_move_to (cr, xx1 + dx, yy1 + dy);
cairo_line_to (cr, xx2 + dx, yy2 + dy);
cairo_line_to (cr, xx2 - dx, yy2 - dy);
cairo_line_to (cr, xx1 - dx, yy1 - dy);
}
cairo_fill (cr);
cairo_restore (cr);
}
static void
get_insertion_cursor_bounds (double width,
double height,
double aspect_ratio,
PangoDirection direction,
gboolean draw_arrow,
graphene_rect_t *bounds)
{
int stem_width;
if (width < 0)
width = - width;
stem_width = height * aspect_ratio + 1;
graphene_rect_init (bounds,
- 2 * stem_width, - stem_width,
width + 4 * stem_width, height + 2 * stem_width);
}
static void
snapshot_insertion_cursor (GtkSnapshot *snapshot,
GtkStyleContext *context,
double width,
double height,
double aspect_ratio,
gboolean is_primary,
PangoDirection direction,
gboolean draw_arrow)
{
if (width != 0 || draw_arrow)
{
cairo_t *cr;
graphene_rect_t bounds;
get_insertion_cursor_bounds (width, height, aspect_ratio, direction, draw_arrow, &bounds);
cr = gtk_snapshot_append_cairo (snapshot, &bounds);
draw_insertion_cursor (context, cr, 0, 0, width, height, aspect_ratio, is_primary, direction, draw_arrow);
cairo_destroy (cr);
}
else
{
GdkRGBA primary_color;
GdkRGBA secondary_color;
int stem_width;
int offset;
_gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
stem_width = height * aspect_ratio + 1;
/* put (stem_width % 2) on the proper side of the cursor */
if (direction == PANGO_DIRECTION_LTR)
offset = stem_width / 2;
else
offset = stem_width - stem_width / 2;
gtk_snapshot_append_color (snapshot,
is_primary ? &primary_color : &secondary_color,
&GRAPHENE_RECT_INIT (- offset, 0, stem_width, height));
}
}
/**
* gtk_snapshot_render_insertion_cursor:
* @snapshot: snapshot to render to
* @context: a `GtkStyleContext`
* @x: X origin
* @y: Y origin
* @layout: the `PangoLayout` of the text
* @index: the index in the `PangoLayout`
* @direction: the `PangoDirection` of the text
*
* Draws a text caret using @snapshot at the specified index of @layout.
*
* Deprecated: 4.10
*/
void
gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
PangoLayout *layout,
int index,
PangoDirection direction)
{
GdkDisplay *display;
gboolean split_cursor;
double aspect_ratio;
PangoRectangle strong_pos, weak_pos;
PangoRectangle *cursor1, *cursor2;
GdkSeat *seat;
PangoDirection keyboard_direction;
PangoDirection direction2;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (PANGO_IS_LAYOUT (layout));
g_return_if_fail (index >= 0);
display = gtk_style_context_get_display (context);
g_object_get (gtk_settings_get_for_display (display),
"gtk-split-cursor", &split_cursor,
"gtk-cursor-aspect-ratio", &aspect_ratio,
NULL);
keyboard_direction = PANGO_DIRECTION_LTR;
seat = gdk_display_get_default_seat (display);
if (seat)
{
GdkDevice *keyboard = gdk_seat_get_keyboard (seat);
if (keyboard)
keyboard_direction = gdk_device_get_direction (keyboard);
}
pango_layout_get_caret_pos (layout, index, &strong_pos, &weak_pos);
direction2 = PANGO_DIRECTION_NEUTRAL;
if (split_cursor)
{
cursor1 = &strong_pos;
if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
{
direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
cursor2 = &weak_pos;
}
}
else
{
if (keyboard_direction == direction)
cursor1 = &strong_pos;
else
cursor1 = &weak_pos;
}
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x + PANGO_PIXELS (MIN (cursor1->x, cursor1->x + cursor1->width)), y + PANGO_PIXELS (cursor1->y)));
snapshot_insertion_cursor (snapshot,
context,
PANGO_PIXELS (cursor1->width),
PANGO_PIXELS (cursor1->height),
aspect_ratio,
TRUE,
direction,
direction2 != PANGO_DIRECTION_NEUTRAL);
gtk_snapshot_restore (snapshot);
if (direction2 != PANGO_DIRECTION_NEUTRAL)
{
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x + PANGO_PIXELS (MIN (cursor2->x, cursor2->x + cursor2->width)), y + PANGO_PIXELS (cursor2->y)));
snapshot_insertion_cursor (snapshot,
context,
PANGO_PIXELS (cursor2->width),
PANGO_PIXELS (cursor2->height),
aspect_ratio,
FALSE,
direction2,
TRUE);
gtk_snapshot_restore (snapshot);
}
}

View File

@ -28,6 +28,7 @@
#include <gtk/gtkenums.h>
#include <gtk/gtktypes.h>
#include <gtk/gtksnapshot.h>
G_BEGIN_DECLS
@ -114,6 +115,43 @@ void gtk_render_icon (GtkStyleContext *context,
GdkTexture *texture,
double x,
double y);
GDK_DEPRECATED_IN_4_10
void gtk_snapshot_render_background (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height);
GDK_DEPRECATED_IN_4_10
void gtk_snapshot_render_frame (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height);
GDK_DEPRECATED_IN_4_10
void gtk_snapshot_render_focus (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height);
GDK_DEPRECATED_IN_4_10
void gtk_snapshot_render_layout (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
PangoLayout *layout);
GDK_DEPRECATED_IN_4_10
void gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
PangoLayout *layout,
int index,
PangoDirection direction);
G_END_DECLS
#endif /* __GTK_RENDER_H__ */

View File

@ -51,7 +51,7 @@
#include "gtkscrollable.h"
#include "gtksettingsprivate.h"
#include "gtkshortcutcontroller.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontextprivate.h"
#include "gtktooltip.h"
#include "gtktreednd.h"

View File

@ -97,7 +97,7 @@
#include "gtkorientable.h"
#include "gtkprivate.h"
#include "gtksizerequest.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontextprivate.h"
#include "gtktypebuiltins.h"
#include "gtkviewport.h"
@ -2586,7 +2586,9 @@ gtk_flow_box_snapshot (GtkWidget *widget,
cairo_clip (cr);
bg_snapshot = gtk_snapshot_new ();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (bg_snapshot, context, x, y, width, height);
G_GNUC_END_IGNORE_DEPRECATIONS
node = gtk_snapshot_free_to_node (bg_snapshot);
if (node)
{

View File

@ -29,6 +29,7 @@
#include "gtksnapshot.h"
#include "gtknative.h"
#include "gtkwidgetprivate.h"
#include "deprecated/gtkrender.h"
#include <epoxy/gl.h>
@ -659,10 +660,12 @@ gtk_gl_area_draw_error_screen (GtkGLArea *area,
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
pango_layout_get_pixel_size (layout, NULL, &layout_height);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_layout (snapshot,
gtk_widget_get_style_context (GTK_WIDGET (area)),
0, (height - layout_height) / 2,
layout);
G_GNUC_END_IGNORE_DEPRECATIONS
g_object_unref (layout);
}

View File

@ -24,7 +24,7 @@
#include "gtkcssnodeprivate.h"
#include "gtkcssstylechangeprivate.h"
#include "gtkpangoprivate.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
@ -520,7 +520,9 @@ gtk_inscription_snapshot (GtkWidget *widget,
gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT(0, 0, gtk_widget_get_width (widget), gtk_widget_get_height (widget)));
gtk_inscription_get_layout_location (self, &lx, &ly);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_layout (snapshot, context, lx, ly, self->layout);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_snapshot_pop (snapshot);
}

View File

@ -41,7 +41,7 @@
#include "gtkshortcutcontroller.h"
#include "gtkshortcuttrigger.h"
#include "gtkshow.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontextprivate.h"
#include "gtktextutilprivate.h"
#include "gtktooltip.h"
@ -1382,6 +1382,7 @@ gtk_label_snapshot (GtkWidget *widget,
int lx, ly;
int width, height;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (!self->text || (*self->text == '\0'))
return;
@ -1492,6 +1493,7 @@ gtk_label_snapshot (GtkWidget *widget,
gtk_style_context_restore (context);
}
}
G_GNUC_END_IGNORE_DEPRECATIONS
}
static GtkSizeRequestMode

View File

@ -118,7 +118,7 @@
#include "gdk/gdkeventsprivate.h"
#include "gtkpointerfocusprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkshortcutmanager.h"
#include "gtkbuildable.h"
#include "gtktooltipprivate.h"
@ -1572,11 +1572,13 @@ create_arrow_render_node (GtkPopover *popover)
/* Render the arrow background */
bg_snapshot = gtk_snapshot_new ();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (bg_snapshot,
context,
0, 0,
gtk_widget_get_width (widget),
gtk_widget_get_height (widget));
G_GNUC_END_IGNORE_DEPRECATIONS
node = gtk_snapshot_free_to_node (bg_snapshot);
if (node)
{

View File

@ -46,6 +46,7 @@
#include "gtkbuildable.h"
#include "gtkmessagedialog.h"
#include "gtkbutton.h"
#include "deprecated/gtkrender.h"
#include <glib/gi18n-lib.h>
#include "gtkprivate.h"
#include "gtktypebuiltins.h"
@ -1964,8 +1965,10 @@ paint_page (GtkPrintUnixDialog *dialog,
gtk_style_context_save_to_node (context, dialog->collate_paper_node);
snapshot = gtk_snapshot_new ();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (snapshot, context, x, y, width, height);
gtk_snapshot_render_frame (snapshot, context, x, y, width, height);
G_GNUC_END_IGNORE_DEPRECATIONS
node = gtk_snapshot_free_to_node (snapshot);
if (node)
{
@ -2498,8 +2501,10 @@ draw_page (GtkDrawingArea *da,
cairo_translate (cr, pos_x, pos_y);
snapshot = gtk_snapshot_new ();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (snapshot, context, 1, 1, w, h);
gtk_snapshot_render_frame (snapshot, context, 1, 1, w, h);
G_GNUC_END_IGNORE_DEPRECATIONS
node = gtk_snapshot_free_to_node (snapshot);
if (node)
{

View File

@ -47,7 +47,7 @@
#include "gtkscrollable.h"
#include "gtkscrollbar.h"
#include "gtksettingsprivate.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontextprivate.h"
#include "gtktypebuiltins.h"
#include "gtkviewport.h"
@ -1885,12 +1885,14 @@ gtk_scrolled_window_snapshot_scrollbars_junction (GtkScrolledWindow *scrolled_wi
context = gtk_widget_get_style_context (widget);
gtk_style_context_save_to_node (context, priv->junction_node);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (snapshot, context,
junction_rect.x, junction_rect.y,
junction_rect.width, junction_rect.height);
gtk_snapshot_render_frame (snapshot, context,
junction_rect.x, junction_rect.y,
junction_rect.width, junction_rect.height);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_style_context_restore (context);
}
@ -1905,6 +1907,7 @@ gtk_scrolled_window_snapshot_overshoot (GtkScrolledWindow *scrolled_window,
GtkStyleContext *context;
GdkRectangle rect;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (!_gtk_scrolled_window_get_overshoot (scrolled_window, &overshoot_x, &overshoot_y))
return;
@ -1943,6 +1946,7 @@ gtk_scrolled_window_snapshot_overshoot (GtkScrolledWindow *scrolled_window,
gtk_snapshot_render_frame (snapshot, context, rect.x, rect.y, rect.width, -overshoot_y);
gtk_style_context_restore (context);
}
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
@ -1955,6 +1959,7 @@ gtk_scrolled_window_snapshot_undershoot (GtkScrolledWindow *scrolled_window,
GdkRectangle rect;
GtkAdjustment *adj;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
context = gtk_widget_get_style_context (widget);
gtk_scrolled_window_inner_allocation (scrolled_window, &rect);
@ -1990,6 +1995,7 @@ gtk_scrolled_window_snapshot_undershoot (GtkScrolledWindow *scrolled_window,
gtk_snapshot_render_frame (snapshot, context, rect.x, rect.y, rect.width, UNDERSHOOT_SIZE);
gtk_style_context_restore (context);
}
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void

View File

@ -23,9 +23,6 @@
#include "gtkcsscolorvalueprivate.h"
#include "gtkcssshadowvalueprivate.h"
#include "gtkdebug.h"
#include "gtkrenderbackgroundprivate.h"
#include "gtkrenderborderprivate.h"
#include "gtkrendericonprivate.h"
#include "gtkrendernodepaintableprivate.h"
#include "gtkstylecontextprivate.h"
#include "gsktransformprivate.h"
@ -1977,150 +1974,6 @@ gtk_snapshot_append_color (GtkSnapshot *snapshot,
gtk_snapshot_append_node_internal (snapshot, node);
}
/**
* gtk_snapshot_render_background:
* @snapshot: a `GtkSnapshot`
* @context: the style context that defines the background
* @x: X origin of the rectangle
* @y: Y origin of the rectangle
* @width: rectangle width
* @height: rectangle height
*
* Creates a render node for the CSS background according to @context,
* and appends it to the current node of @snapshot, without changing
* the current node.
*/
void
gtk_snapshot_render_background (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height)
{
GtkCssBoxes boxes;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_css_boxes_init_border_box (&boxes,
gtk_style_context_lookup_style (context),
x, y, width, height);
gtk_css_style_snapshot_background (&boxes, snapshot);
}
/**
* gtk_snapshot_render_frame:
* @snapshot: a `GtkSnapshot`
* @context: the style context that defines the frame
* @x: X origin of the rectangle
* @y: Y origin of the rectangle
* @width: rectangle width
* @height: rectangle height
*
* Creates a render node for the CSS border according to @context,
* and appends it to the current node of @snapshot, without changing
* the current node.
*/
void
gtk_snapshot_render_frame (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height)
{
GtkCssBoxes boxes;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_css_boxes_init_border_box (&boxes,
gtk_style_context_lookup_style (context),
x, y, width, height);
gtk_css_style_snapshot_border (&boxes, snapshot);
}
/**
* gtk_snapshot_render_focus:
* @snapshot: a `GtkSnapshot`
* @context: the style context that defines the focus ring
* @x: X origin of the rectangle
* @y: Y origin of the rectangle
* @width: rectangle width
* @height: rectangle height
*
* Creates a render node for the focus outline according to @context,
* and appends it to the current node of @snapshot, without changing
* the current node.
*/
void
gtk_snapshot_render_focus (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height)
{
GtkCssBoxes boxes;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_css_boxes_init_border_box (&boxes,
gtk_style_context_lookup_style (context),
x, y, width, height);
gtk_css_style_snapshot_outline (&boxes, snapshot);
}
/**
* gtk_snapshot_render_layout:
* @snapshot: a `GtkSnapshot`
* @context: the style context that defines the text
* @x: X origin of the rectangle
* @y: Y origin of the rectangle
* @layout: the `PangoLayout` to render
*
* Creates a render node for rendering @layout according to the style
* information in @context, and appends it to the current node of @snapshot,
* without changing the current node.
*/
void
gtk_snapshot_render_layout (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
PangoLayout *layout)
{
const bool needs_translate = (x != 0 || y != 0);
const GdkRGBA *fg_color;
GtkCssValue *shadows_value;
gboolean has_shadow;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (PANGO_IS_LAYOUT (layout));
if (needs_translate)
{
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
}
fg_color = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
shadows_value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
has_shadow = gtk_css_shadow_value_push_snapshot (shadows_value, snapshot);
gtk_snapshot_append_layout (snapshot, layout, fg_color);
if (has_shadow)
gtk_snapshot_pop (snapshot);
if (needs_translate)
gtk_snapshot_restore (snapshot);
}
void
gtk_snapshot_append_text (GtkSnapshot *snapshot,
PangoFont *font,

View File

@ -225,43 +225,6 @@ void gtk_snapshot_append_layout (GtkSnapshot
const GdkRGBA *color);
GDK_AVAILABLE_IN_ALL
void gtk_snapshot_render_background (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height);
GDK_AVAILABLE_IN_ALL
void gtk_snapshot_render_frame (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height);
GDK_AVAILABLE_IN_ALL
void gtk_snapshot_render_focus (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
double width,
double height);
GDK_AVAILABLE_IN_ALL
void gtk_snapshot_render_layout (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
PangoLayout *layout);
GDK_AVAILABLE_IN_ALL /* in gtkstylecontext.c */
void gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
PangoLayout *layout,
int index,
PangoDirection direction);
G_END_DECLS
#endif /* __GTK_SNAPSHOT_H__ */

View File

@ -28,7 +28,7 @@
#include "gtkprivate.h"
#include "gtksettings.h"
#include "gtksettingsprivate.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
/**
@ -949,271 +949,6 @@ _gtk_style_context_get_cursor_color (GtkStyleContext *context,
*secondary_color = *gtk_css_color_value_get_rgba (style->font->secondary_caret_color ? style->font->secondary_caret_color : style->core->color);
}
static void
draw_insertion_cursor (GtkStyleContext *context,
cairo_t *cr,
double x,
double y,
double width,
double height,
double aspect_ratio,
gboolean is_primary,
PangoDirection direction,
gboolean draw_arrow)
{
GdkRGBA primary_color;
GdkRGBA secondary_color;
int stem_width;
double angle;
double dx, dy;
double xx1, yy1, xx2, yy2;
cairo_save (cr);
cairo_new_path (cr);
_gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
stem_width = height * aspect_ratio + 1;
yy1 = y;
yy2 = y + height;
if (width < 0)
{
xx1 = x;
xx2 = x - width;
}
else
{
xx1 = x + width;
xx2 = x;
}
angle = atan2 (height, width);
dx = (stem_width/2.0) * cos (M_PI/2 - angle);
dy = (stem_width/2.0) * sin (M_PI/2 - angle);
if (draw_arrow)
{
if (direction == PANGO_DIRECTION_RTL)
{
double x0, y0, x1, y1, x2, y2;
x0 = xx2 - dx + 2 * dy;
y0 = yy2 - dy - 2 * dx;
x1 = x0 + 4 * dy;
y1 = y0 - 4 * dx;
x2 = x0 + 2 * dy - 3 * dx;
y2 = y0 - 2 * dx - 3 * dy;
cairo_move_to (cr, xx1 + dx, yy1 + dy);
cairo_line_to (cr, xx2 + dx, yy2 + dy);
cairo_line_to (cr, x2, y2);
cairo_line_to (cr, x1, y1);
cairo_line_to (cr, xx1 - dx, yy1 - dy);
}
else if (direction == PANGO_DIRECTION_LTR)
{
double x0, y0, x1, y1, x2, y2;
x0 = xx2 + dx + 2 * dy;
y0 = yy2 + dy - 2 * dx;
x1 = x0 + 4 * dy;
y1 = y0 - 4 * dx;
x2 = x0 + 2 * dy + 3 * dx;
y2 = y0 - 2 * dx + 3 * dy;
cairo_move_to (cr, xx1 - dx, yy1 - dy);
cairo_line_to (cr, xx2 - dx, yy2 - dy);
cairo_line_to (cr, x2, y2);
cairo_line_to (cr, x1, y1);
cairo_line_to (cr, xx1 + dx, yy1 + dy);
}
else
g_assert_not_reached();
}
else
{
cairo_move_to (cr, xx1 + dx, yy1 + dy);
cairo_line_to (cr, xx2 + dx, yy2 + dy);
cairo_line_to (cr, xx2 - dx, yy2 - dy);
cairo_line_to (cr, xx1 - dx, yy1 - dy);
}
cairo_fill (cr);
cairo_restore (cr);
}
static void
get_insertion_cursor_bounds (double width,
double height,
double aspect_ratio,
PangoDirection direction,
gboolean draw_arrow,
graphene_rect_t *bounds)
{
int stem_width;
if (width < 0)
width = - width;
stem_width = height * aspect_ratio + 1;
graphene_rect_init (bounds,
- 2 * stem_width, - stem_width,
width + 4 * stem_width, height + 2 * stem_width);
}
static void
snapshot_insertion_cursor (GtkSnapshot *snapshot,
GtkStyleContext *context,
double width,
double height,
double aspect_ratio,
gboolean is_primary,
PangoDirection direction,
gboolean draw_arrow)
{
if (width != 0 || draw_arrow)
{
cairo_t *cr;
graphene_rect_t bounds;
get_insertion_cursor_bounds (width, height, aspect_ratio, direction, draw_arrow, &bounds);
cr = gtk_snapshot_append_cairo (snapshot, &bounds);
draw_insertion_cursor (context, cr, 0, 0, width, height, aspect_ratio, is_primary, direction, draw_arrow);
cairo_destroy (cr);
}
else
{
GdkRGBA primary_color;
GdkRGBA secondary_color;
int stem_width;
int offset;
_gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
stem_width = height * aspect_ratio + 1;
/* put (stem_width % 2) on the proper side of the cursor */
if (direction == PANGO_DIRECTION_LTR)
offset = stem_width / 2;
else
offset = stem_width - stem_width / 2;
gtk_snapshot_append_color (snapshot,
is_primary ? &primary_color : &secondary_color,
&GRAPHENE_RECT_INIT (- offset, 0, stem_width, height));
}
}
/**
* gtk_snapshot_render_insertion_cursor:
* @snapshot: snapshot to render to
* @context: a `GtkStyleContext`
* @x: X origin
* @y: Y origin
* @layout: the `PangoLayout` of the text
* @index: the index in the `PangoLayout`
* @direction: the `PangoDirection` of the text
*
* Draws a text caret using @snapshot at the specified index of @layout.
*/
void
gtk_snapshot_render_insertion_cursor (GtkSnapshot *snapshot,
GtkStyleContext *context,
double x,
double y,
PangoLayout *layout,
int index,
PangoDirection direction)
{
GtkStyleContextPrivate *priv = gtk_style_context_get_instance_private (context);
gboolean split_cursor;
double aspect_ratio;
PangoRectangle strong_pos, weak_pos;
PangoRectangle *cursor1, *cursor2;
GdkSeat *seat;
PangoDirection keyboard_direction;
PangoDirection direction2;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (PANGO_IS_LAYOUT (layout));
g_return_if_fail (index >= 0);
g_object_get (gtk_settings_get_for_display (priv->display),
"gtk-split-cursor", &split_cursor,
"gtk-cursor-aspect-ratio", &aspect_ratio,
NULL);
keyboard_direction = PANGO_DIRECTION_LTR;
seat = gdk_display_get_default_seat (priv->display);
if (seat)
{
GdkDevice *keyboard = gdk_seat_get_keyboard (seat);
if (keyboard)
keyboard_direction = gdk_device_get_direction (keyboard);
}
pango_layout_get_caret_pos (layout, index, &strong_pos, &weak_pos);
direction2 = PANGO_DIRECTION_NEUTRAL;
if (split_cursor)
{
cursor1 = &strong_pos;
if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
{
direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
cursor2 = &weak_pos;
}
}
else
{
if (keyboard_direction == direction)
cursor1 = &strong_pos;
else
cursor1 = &weak_pos;
}
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x + PANGO_PIXELS (MIN (cursor1->x, cursor1->x + cursor1->width)), y + PANGO_PIXELS (cursor1->y)));
snapshot_insertion_cursor (snapshot,
context,
PANGO_PIXELS (cursor1->width),
PANGO_PIXELS (cursor1->height),
aspect_ratio,
TRUE,
direction,
direction2 != PANGO_DIRECTION_NEUTRAL);
gtk_snapshot_restore (snapshot);
if (direction2 != PANGO_DIRECTION_NEUTRAL)
{
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x + PANGO_PIXELS (MIN (cursor2->x, cursor2->x + cursor2->width)), y + PANGO_PIXELS (cursor2->y)));
snapshot_insertion_cursor (snapshot,
context,
PANGO_PIXELS (cursor2->width),
PANGO_PIXELS (cursor2->height),
aspect_ratio,
FALSE,
direction2,
TRUE);
gtk_snapshot_restore (snapshot);
}
}
/**
* GtkStyleContextPrintFlags:
* @GTK_STYLE_CONTEXT_PRINT_NONE: Default value.

View File

@ -53,7 +53,7 @@
#include "gtkpopovermenu.h"
#include "gtkprivate.h"
#include "gtksettings.h"
#include "gtksnapshot.h"
#include "deprecated/gtkrender.h"
#include "gtkstylecontextprivate.h"
#include "gtktexthandleprivate.h"
#include "gtktexthistoryprivate.h"
@ -65,6 +65,7 @@
#include "gtknative.h"
#include "gtkactionmuxerprivate.h"
#include "gtkjoinedmenuprivate.h"
#include "deprecated/gtkrender.h"
#include <cairo-gobject.h>
#include <string.h>
@ -2524,6 +2525,7 @@ gtk_text_draw_undershoot (GtkText *self,
GtkStyleContext *context;
int min_offset, max_offset;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
context = gtk_widget_get_style_context (GTK_WIDGET (self));
gtk_text_get_scroll_limits (self, &min_offset, &max_offset);
@ -2543,6 +2545,7 @@ gtk_text_draw_undershoot (GtkText *self,
gtk_snapshot_render_frame (snapshot, context, text_width - UNDERSHOOT_SIZE, 0, UNDERSHOOT_SIZE, text_height);
gtk_style_context_restore (context);
}
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
@ -4604,6 +4607,7 @@ gtk_text_draw_text (GtkText *self,
PangoLayout *layout;
int x, y;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/* Nothing to display at all */
if (gtk_text_get_display_mode (self) == DISPLAY_BLANK)
return;
@ -4645,6 +4649,7 @@ gtk_text_draw_text (GtkText *self,
gtk_style_context_restore (context);
}
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
@ -4663,6 +4668,7 @@ gtk_text_draw_cursor (GtkText *self,
const char *text;
int x, y;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
context = gtk_widget_get_style_context (widget);
layout = g_object_ref (gtk_text_ensure_layout (self, TRUE));
@ -4707,6 +4713,7 @@ gtk_text_draw_cursor (GtkText *self,
}
g_object_unref (layout);
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void

View File

@ -4271,9 +4271,11 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
if (cursor.is_insert || cursor.is_selection_bound)
gtk_snapshot_push_opacity (cursor_snapshot, cursor_alpha);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_insertion_cursor (cursor_snapshot, context,
line_display->x_offset, offset_y + line_display->top_margin,
line_display->layout, cursor.pos, dir);
G_GNUC_END_IGNORE_DEPRECATIONS
if (cursor.is_insert || cursor.is_selection_bound)
gtk_snapshot_pop (cursor_snapshot);

View File

@ -34,6 +34,7 @@
#include "gtkwidgetprivate.h"
#include "gtkcssstyleprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "deprecated/gtkrender.h"
#define DRAG_ICON_MAX_WIDTH 250
#define DRAG_ICON_MAX_HEIGHT 250
@ -146,10 +147,12 @@ gtk_text_util_create_drag_icon (GtkWidget *widget,
else
bg_widget = widget;
pango_layout_get_size (layout, &layout_width, &layout_height);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (snapshot,
gtk_widget_get_style_context (bg_widget),
0, 0, layout_width / PANGO_SCALE,
layout_height / PANGO_SCALE);
G_GNUC_END_IGNORE_DEPRECATIONS
}
gtk_snapshot_append_layout (snapshot, layout, color);
@ -274,9 +277,11 @@ gtk_text_util_create_rich_drag_icon (GtkWidget *widget,
if (!gdk_display_is_rgba (display) ||
!gdk_display_is_composited (display))
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (snapshot,
gtk_widget_get_style_context (widget),
0, 0, layout_width, layout_height);
G_GNUC_END_IGNORE_DEPRECATIONS
}
gtk_text_layout_snapshot (layout, widget, snapshot, &(GdkRectangle) { 0, 0, layout_width, layout_height }, 1.0);

View File

@ -59,6 +59,7 @@
#include "gtkjoinedmenuprivate.h"
#include "gtkcsslineheightvalueprivate.h"
#include "gtkcssenumvalueprivate.h"
#include "deprecated/gtkrender.h"
/**
@ -5864,6 +5865,7 @@ draw_text (GtkWidget *widget,
context = gtk_widget_get_style_context (widget);
gtk_style_context_save_to_node (context, text_view->priv->text_window->css_node);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_snapshot_render_background (snapshot, context,
-priv->xoffset, -priv->yoffset - priv->top_margin,
MAX (SCREEN_WIDTH (text_view), priv->width),
@ -5872,6 +5874,7 @@ draw_text (GtkWidget *widget,
-priv->xoffset, -priv->yoffset - priv->top_margin,
MAX (SCREEN_WIDTH (text_view), priv->width),
MAX (SCREEN_HEIGHT (text_view), priv->height));
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_style_context_restore (context);
if (GTK_TEXT_VIEW_GET_CLASS (text_view)->snapshot_layer != NULL)