Merge branch 'matthiasc/for-main' into 'main'
gtk4-demo: Fix rotation handling in image scaling See merge request GNOME/gtk!5643
This commit is contained in:
@@ -67,15 +67,13 @@ demo3_widget_snapshot (GtkWidget *widget,
|
|||||||
if (G_APPROX_VALUE (self->angle, 90.f, FLT_EPSILON) ||
|
if (G_APPROX_VALUE (self->angle, 90.f, FLT_EPSILON) ||
|
||||||
G_APPROX_VALUE (self->angle, 270.f, FLT_EPSILON))
|
G_APPROX_VALUE (self->angle, 270.f, FLT_EPSILON))
|
||||||
{
|
{
|
||||||
double s;
|
double s = w2;
|
||||||
|
|
||||||
s = w2;
|
|
||||||
w2 = h2;
|
w2 = h2;
|
||||||
h2 = s;
|
h2 = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = MAX (0, (width - ceil (w2)) / 2);
|
x = (width - ceil (w2)) / 2;
|
||||||
y = MAX (0, (height - ceil (h2)) / 2);
|
y = (height - ceil (h2)) / 2;
|
||||||
|
|
||||||
gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||||
gtk_snapshot_save (snapshot);
|
gtk_snapshot_save (snapshot);
|
||||||
@@ -102,14 +100,26 @@ demo3_widget_measure (GtkWidget *widget,
|
|||||||
int *natural_baseline)
|
int *natural_baseline)
|
||||||
{
|
{
|
||||||
Demo3Widget *self = DEMO3_WIDGET (widget);
|
Demo3Widget *self = DEMO3_WIDGET (widget);
|
||||||
|
int width, height;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
width = gdk_texture_get_width (self->texture);
|
||||||
size = gdk_texture_get_width (self->texture);
|
height = gdk_texture_get_height (self->texture);
|
||||||
else
|
|
||||||
size = gdk_texture_get_height (self->texture);
|
|
||||||
|
|
||||||
*minimum = *natural = self->scale * size;
|
if (G_APPROX_VALUE (self->angle, 90.f, FLT_EPSILON) ||
|
||||||
|
G_APPROX_VALUE (self->angle, 270.f, FLT_EPSILON))
|
||||||
|
{
|
||||||
|
int s = width;
|
||||||
|
width = height;
|
||||||
|
height = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
size = width;
|
||||||
|
else
|
||||||
|
size = height;
|
||||||
|
|
||||||
|
*minimum = *natural = (int) ceil (self->scale * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -267,7 +277,7 @@ demo3_widget_class_init (Demo3WidgetClass *class)
|
|||||||
|
|
||||||
g_object_class_install_property (object_class, PROP_SCALE,
|
g_object_class_install_property (object_class, PROP_SCALE,
|
||||||
g_param_spec_float ("scale", NULL, NULL,
|
g_param_spec_float ("scale", NULL, NULL,
|
||||||
0.0, 10.0, 1.0,
|
0.0, 1024.0, 1.0,
|
||||||
G_PARAM_READWRITE));
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
g_object_class_install_property (object_class, PROP_ANGLE,
|
g_object_class_install_property (object_class, PROP_ANGLE,
|
||||||
|
|||||||
@@ -84,6 +84,16 @@ rotate (GtkWidget *button,
|
|||||||
g_object_set (demo, "angle", angle, NULL);
|
g_object_set (demo, "angle", angle, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
scale_changed (GtkRange *range,
|
||||||
|
GtkWidget *widget)
|
||||||
|
{
|
||||||
|
float scale;
|
||||||
|
|
||||||
|
scale = (float) pow (2., gtk_range_get_value (range));
|
||||||
|
g_object_set (widget, "scale", scale, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
do_menu (GtkWidget *do_widget)
|
do_menu (GtkWidget *do_widget)
|
||||||
{
|
{
|
||||||
@@ -129,7 +139,7 @@ do_menu (GtkWidget *do_widget)
|
|||||||
g_signal_connect (button, "clicked", G_CALLBACK (rotate), widget);
|
g_signal_connect (button, "clicked", G_CALLBACK (rotate), widget);
|
||||||
gtk_box_append (GTK_BOX (box2), button);
|
gtk_box_append (GTK_BOX (box2), button);
|
||||||
|
|
||||||
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0.01, 10.0, 0.1);
|
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, -10, 10.0, 0.1);
|
||||||
gtk_widget_set_tooltip_text (scale, "Zoom");
|
gtk_widget_set_tooltip_text (scale, "Zoom");
|
||||||
gtk_range_set_value (GTK_RANGE (scale), 1.0);
|
gtk_range_set_value (GTK_RANGE (scale), 1.0);
|
||||||
gtk_widget_set_hexpand (scale, TRUE);
|
gtk_widget_set_hexpand (scale, TRUE);
|
||||||
@@ -140,10 +150,8 @@ do_menu (GtkWidget *do_widget)
|
|||||||
gtk_box_append (GTK_BOX (box2), dropdown);
|
gtk_box_append (GTK_BOX (box2), dropdown);
|
||||||
|
|
||||||
g_object_bind_property (dropdown, "selected", widget, "filter", G_BINDING_DEFAULT);
|
g_object_bind_property (dropdown, "selected", widget, "filter", G_BINDING_DEFAULT);
|
||||||
|
|
||||||
g_object_bind_property (gtk_range_get_adjustment (GTK_RANGE (scale)), "value",
|
g_signal_connect (scale, "value-changed", G_CALLBACK (scale_changed), widget);
|
||||||
widget, "scale",
|
|
||||||
G_BINDING_BIDIRECTIONAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gtk_widget_get_visible (window))
|
if (!gtk_widget_get_visible (window))
|
||||||
|
|||||||
@@ -1573,6 +1573,10 @@ gsk_texture_node_get_texture (const GskRenderNode *node)
|
|||||||
* Creates a `GskRenderNode` that will render the given
|
* Creates a `GskRenderNode` that will render the given
|
||||||
* @texture into the area given by @bounds.
|
* @texture into the area given by @bounds.
|
||||||
*
|
*
|
||||||
|
* Note that GSK applies linear filtering when textures are
|
||||||
|
* scaled and transformed. See [class@Gsk.TextureScaleNode]
|
||||||
|
* for a way to influence filtering.
|
||||||
|
*
|
||||||
* Returns: (transfer full) (type GskTextureNode): A new `GskRenderNode`
|
* Returns: (transfer full) (type GskTextureNode): A new `GskRenderNode`
|
||||||
*/
|
*/
|
||||||
GskRenderNode *
|
GskRenderNode *
|
||||||
@@ -1754,7 +1758,11 @@ gsk_texture_scale_node_get_filter (const GskRenderNode *node)
|
|||||||
* @filter: how to scale the texture
|
* @filter: how to scale the texture
|
||||||
*
|
*
|
||||||
* Creates a node that scales the texture to the size given by the
|
* Creates a node that scales the texture to the size given by the
|
||||||
* bounds and the filter and then places it at the bounds' position.
|
* bounds using the filter and then places it at the bounds' position.
|
||||||
|
*
|
||||||
|
* Note that further scaling and other transformations which are
|
||||||
|
* applied to the node will apply linear filtering to the resulting
|
||||||
|
* texture, as usual.
|
||||||
*
|
*
|
||||||
* This node is intended for tight control over scaling applied
|
* This node is intended for tight control over scaling applied
|
||||||
* to a texture, such as in image editors and requires the
|
* to a texture, such as in image editors and requires the
|
||||||
|
|||||||
Reference in New Issue
Block a user