static void update_autoscale(ViewHelper *self) { GdkRectangle viewport = self->widget_allocation; GeglRectangle bbox = gegl_node_get_bounding_box(self->node); model_rect_to_view_rect(self, &bbox); if (!self->node || viewport.width < 0 || viewport.height < 0 || bbox.width < 0 || bbox.height < 0) return; if (self->autoscale_policy == GEGL_GTK_VIEW_AUTOSCALE_WIDGET) { /* Request widget size change */ /* XXX: Should we reset scale/x/y here? */ g_signal_emit(self, view_helper_signals[SIGNAL_SIZE_CHANGED], 0, &bbox, NULL); } else if (self->autoscale_policy == GEGL_GTK_VIEW_AUTOSCALE_CONTENT) { /* Calculate and set scaling factor to make the content fit inside */ float width_ratio = bbox.width / (float)viewport.width; float height_ratio = bbox.height / (float)viewport.height; float max_ratio = width_ratio >= height_ratio ? width_ratio : height_ratio; float current_scale = view_helper_get_scale(self); view_helper_set_scale(self, current_scale * (1.0 / max_ratio)); } }
/* Test that the redraw signal is emitted when the GeglNode has been computed. * * NOTE: Does not test that the actual drawing happens, or even * that queue_redraw is called, as this is hard to observe reliably * Redraws can be triggered by other things, and the exposed events * can be coalesced by GTK. */ static void test_redraw_on_computed (int x, int y, float scale, GeglRectangle *input, GeglRectangle *output) { ViewHelperTest test; RedrawTestState test_data; test_data.expected_result = output; setup_helper_test(&test); /* Setup will invalidate the node, make sure those events are processed. */ while (gtk_events_pending()) { gtk_main_iteration(); } gegl_node_process (test.out); view_helper_set_x(test.helper, x); view_helper_set_y(test.helper, y); view_helper_set_scale(test.helper, scale); g_signal_connect(G_OBJECT(test.helper), "redraw-needed", G_CALLBACK(needs_redraw_event), &test_data); g_signal_emit_by_name(test.out, "computed", input, NULL); g_timeout_add(300, test_utils_quit_gtk_main, NULL); gtk_main(); g_assert(test_data.needs_redraw_called); teardown_helper_test(&test); }
/** * gegl_gtk_view_set_scale: * @self: A #GeglGtkView * @scale: * * Setter for the :scale property **/ void gegl_gtk_view_set_scale(GeglGtkView *self, float scale) { view_helper_set_scale(GET_PRIVATE(self), scale); }