2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
1997-11-24 22:37:52 +00:00
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1997-11-24 22:37:52 +00:00
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
1997-11-24 22:37:52 +00:00
|
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-24 22:37:52 +00:00
|
|
|
|
*/
|
1999-02-24 07:37:18 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:37:18 +00:00
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
|
* files for a list of changes. These files are distributed with
|
2011-01-04 18:07:28 +00:00
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
1999-02-24 07:37:18 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
|
#include "gtkdrawingarea.h"
|
2005-09-01 05:11:46 +00:00
|
|
|
|
#include "gtkintl.h"
|
2020-05-05 15:49:00 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
2016-11-18 03:00:02 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2016-11-19 18:58:23 +00:00
|
|
|
|
#include "gtksnapshot.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
|
#include "gtkstylecontext.h"
|
2017-06-28 06:19:35 +00:00
|
|
|
|
#include "gtkwidgetprivate.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2016-11-18 03:00:02 +00:00
|
|
|
|
typedef struct _GtkDrawingAreaPrivate GtkDrawingAreaPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GtkDrawingAreaPrivate {
|
|
|
|
|
int content_width;
|
|
|
|
|
int content_height;
|
2016-11-18 04:45:36 +00:00
|
|
|
|
|
|
|
|
|
GtkDrawingAreaDrawFunc draw_func;
|
|
|
|
|
gpointer draw_func_target;
|
|
|
|
|
GDestroyNotify draw_func_target_destroy_notify;
|
2016-11-18 03:00:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_CONTENT_WIDTH,
|
|
|
|
|
PROP_CONTENT_HEIGHT,
|
|
|
|
|
LAST_PROP
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GParamSpec *props[LAST_PROP] = { NULL, };
|
2015-07-20 15:13:35 +00:00
|
|
|
|
|
2020-05-05 15:49:00 +00:00
|
|
|
|
enum {
|
|
|
|
|
RESIZE,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
|
2011-01-04 18:07:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtkdrawingarea
|
2020-04-18 00:05:04 +00:00
|
|
|
|
* @Short_description: A simple widget for drawing with cairo
|
2011-01-04 18:07:28 +00:00
|
|
|
|
* @Title: GtkDrawingArea
|
|
|
|
|
* @See_also: #GtkImage
|
|
|
|
|
*
|
|
|
|
|
* The #GtkDrawingArea widget is used for creating custom user interface
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* elements. It’s essentially a blank widget; you can draw on it. After
|
2011-01-04 18:07:28 +00:00
|
|
|
|
* creating a drawing area, the application may want to connect to:
|
|
|
|
|
*
|
2014-02-02 06:07:39 +00:00
|
|
|
|
* - The #GtkWidget::realize signal to take any necessary actions
|
|
|
|
|
* when the widget is instantiated on a particular display.
|
|
|
|
|
* (Create GDK resources in response to this signal.)
|
2014-02-05 02:00:58 +00:00
|
|
|
|
*
|
2020-05-05 15:49:00 +00:00
|
|
|
|
* - The #GtkDrawingArea::resize signal to take any necessary
|
2014-02-02 06:07:39 +00:00
|
|
|
|
* actions when the widget changes size.
|
|
|
|
|
*
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* - Call gtk_drawing_area_set_draw_func() to handle redrawing the
|
2014-02-02 06:07:39 +00:00
|
|
|
|
* contents of the widget.
|
2011-01-04 18:07:28 +00:00
|
|
|
|
*
|
|
|
|
|
* The following code portion demonstrates using a drawing
|
|
|
|
|
* area to display a circle in the normal widget foreground
|
|
|
|
|
* color.
|
|
|
|
|
*
|
2014-02-04 21:57:57 +00:00
|
|
|
|
* ## Simple GtkDrawingArea usage
|
|
|
|
|
*
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* void
|
|
|
|
|
* draw_function (GtkDrawingArea *area, cairo_t *cr,
|
|
|
|
|
* int width, int height,
|
|
|
|
|
* gpointer data)
|
2011-01-04 18:07:28 +00:00
|
|
|
|
* {
|
|
|
|
|
* GdkRGBA color;
|
2016-02-21 05:46:54 +00:00
|
|
|
|
* GtkStyleContext *context;
|
|
|
|
|
*
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* context = gtk_widget_get_style_context (GTK_WIDGET (area));
|
2016-02-21 05:46:54 +00:00
|
|
|
|
*
|
2011-01-04 18:07:28 +00:00
|
|
|
|
* cairo_arc (cr,
|
|
|
|
|
* width / 2.0, height / 2.0,
|
|
|
|
|
* MIN (width, height) / 2.0,
|
|
|
|
|
* 0, 2 * G_PI);
|
|
|
|
|
*
|
2016-02-21 05:46:54 +00:00
|
|
|
|
* gtk_style_context_get_color (context,
|
2014-01-27 20:42:15 +00:00
|
|
|
|
* &color);
|
|
|
|
|
* gdk_cairo_set_source_rgba (cr, &color);
|
2011-01-04 18:07:28 +00:00
|
|
|
|
*
|
|
|
|
|
* cairo_fill (cr);
|
|
|
|
|
* }
|
2017-10-11 11:20:15 +00:00
|
|
|
|
*
|
|
|
|
|
* void main (int argc, char **argv)
|
|
|
|
|
* {
|
|
|
|
|
* gtk_init ();
|
|
|
|
|
*
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* GtkWidget *area = gtk_drawing_area_new ();
|
|
|
|
|
* gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (area), 100);
|
|
|
|
|
* gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (area), 100);
|
|
|
|
|
* gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (area),
|
|
|
|
|
* draw_function,
|
|
|
|
|
* NULL, NULL);
|
2017-10-11 11:20:15 +00:00
|
|
|
|
*
|
|
|
|
|
* }
|
2014-01-27 17:12:55 +00:00
|
|
|
|
* ]|
|
2011-01-04 18:07:28 +00:00
|
|
|
|
*
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* The draw function is normally called when a drawing area first comes
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* onscreen, or when it’s covered by another window and then uncovered.
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* You can also force a redraw by adding to the “damage region” of the
|
2019-06-04 14:59:32 +00:00
|
|
|
|
* drawing area’s window using gtk_widget_queue_draw().
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* This will cause the drawing area to call the draw function again.
|
2011-01-04 18:07:28 +00:00
|
|
|
|
*
|
2014-02-07 02:07:03 +00:00
|
|
|
|
* The available routines for drawing are documented on the
|
|
|
|
|
* [GDK Drawing Primitives][gdk3-Cairo-Interaction] page
|
2011-01-04 18:07:28 +00:00
|
|
|
|
* and the cairo documentation.
|
|
|
|
|
*
|
|
|
|
|
* To receive mouse events on a drawing area, you will need to enable
|
|
|
|
|
* them with gtk_widget_add_events(). To receive keyboard events, you
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* will need to set the “can-focus” property on the drawing area, and you
|
2011-01-04 18:07:28 +00:00
|
|
|
|
* should probably draw some user-visible indication that the drawing
|
2011-01-29 20:26:12 +00:00
|
|
|
|
* area is focused. Use gtk_widget_has_focus() in your expose event
|
2011-01-04 18:07:28 +00:00
|
|
|
|
* handler to decide whether to draw the focus indicator. See
|
2011-01-29 20:26:12 +00:00
|
|
|
|
* gtk_render_focus() for one way to draw focus.
|
2016-11-18 04:45:36 +00:00
|
|
|
|
*
|
|
|
|
|
* If you need more complex control over your widget, you should consider
|
|
|
|
|
* creating your own #GtkWidget subclass.
|
2011-01-04 18:07:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2016-11-18 03:00:02 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkDrawingArea, gtk_drawing_area, GTK_TYPE_WIDGET)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drawing_area_set_property (GObject *gobject,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingArea *self = GTK_DRAWING_AREA (gobject);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_CONTENT_WIDTH:
|
|
|
|
|
gtk_drawing_area_set_content_width (self, g_value_get_int (value));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_CONTENT_HEIGHT:
|
|
|
|
|
gtk_drawing_area_set_content_height (self, g_value_get_int (value));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drawing_area_get_property (GObject *gobject,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingArea *self = GTK_DRAWING_AREA (gobject);
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_CONTENT_WIDTH:
|
|
|
|
|
g_value_set_int (value, priv->content_width);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_CONTENT_HEIGHT:
|
|
|
|
|
g_value_set_int (value, priv->content_height);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 04:45:36 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_drawing_area_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingArea *self = GTK_DRAWING_AREA (object);
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
if (priv->draw_func_target_destroy_notify != NULL)
|
|
|
|
|
priv->draw_func_target_destroy_notify (priv->draw_func_target);
|
|
|
|
|
|
|
|
|
|
priv->draw_func = NULL;
|
|
|
|
|
priv->draw_func_target = NULL;
|
|
|
|
|
priv->draw_func_target_destroy_notify = NULL;
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_drawing_area_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 03:00:02 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_drawing_area_measure (GtkWidget *widget,
|
|
|
|
|
GtkOrientation orientation,
|
|
|
|
|
int for_size,
|
|
|
|
|
int *minimum,
|
|
|
|
|
int *natural,
|
|
|
|
|
int *minimum_baseline,
|
|
|
|
|
int *natural_baseline)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingArea *self = GTK_DRAWING_AREA (widget);
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
|
{
|
|
|
|
|
*minimum = *natural = priv->content_width;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*minimum = *natural = priv->content_height;
|
|
|
|
|
}
|
|
|
|
|
}
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2020-05-05 15:49:00 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_drawing_area_size_allocate (GtkWidget *widget,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
int baseline)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (widget, signals[RESIZE], 0, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 04:45:36 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_drawing_area_snapshot (GtkWidget *widget,
|
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingArea *self = GTK_DRAWING_AREA (widget);
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
cairo_t *cr;
|
2017-06-28 06:19:35 +00:00
|
|
|
|
int width, height;
|
2016-11-18 04:45:36 +00:00
|
|
|
|
|
|
|
|
|
if (!priv->draw_func)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-12-06 06:56:12 +00:00
|
|
|
|
width = gtk_widget_get_width (widget);
|
|
|
|
|
height = gtk_widget_get_height (widget);
|
|
|
|
|
|
2017-06-28 06:19:35 +00:00
|
|
|
|
|
2017-01-13 03:46:09 +00:00
|
|
|
|
cr = gtk_snapshot_append_cairo (snapshot,
|
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
|
0, 0,
|
2017-06-28 06:19:35 +00:00
|
|
|
|
width, height
|
2018-04-24 01:17:23 +00:00
|
|
|
|
));
|
2016-11-18 04:45:36 +00:00
|
|
|
|
priv->draw_func (self,
|
|
|
|
|
cr,
|
2017-06-28 06:19:35 +00:00
|
|
|
|
width, height,
|
2016-11-18 04:45:36 +00:00
|
|
|
|
priv->draw_func_target);
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
}
|
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
|
|
|
|
|
{
|
2000-05-19 10:00:46 +00:00
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2016-11-18 03:00:02 +00:00
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
|
|
gobject_class->set_property = gtk_drawing_area_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_drawing_area_get_property;
|
2016-11-18 04:45:36 +00:00
|
|
|
|
gobject_class->dispose = gtk_drawing_area_dispose;
|
2016-11-18 03:00:02 +00:00
|
|
|
|
|
|
|
|
|
widget_class->measure = gtk_drawing_area_measure;
|
2020-05-05 15:49:00 +00:00
|
|
|
|
widget_class->size_allocate = gtk_drawing_area_size_allocate;
|
2020-05-05 18:57:21 +00:00
|
|
|
|
widget_class->snapshot = gtk_drawing_area_snapshot;
|
2016-11-18 03:00:02 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkDrawingArea:content-width
|
|
|
|
|
*
|
|
|
|
|
* The content width. See gtk_drawing_area_set_content_width() for details.
|
|
|
|
|
*/
|
|
|
|
|
props[PROP_CONTENT_WIDTH] =
|
|
|
|
|
g_param_spec_int ("content-width",
|
|
|
|
|
P_("Content Width"),
|
|
|
|
|
P_("Desired width for displayed content"),
|
|
|
|
|
0, G_MAXINT, 0,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkDrawingArea:content-height
|
|
|
|
|
*
|
|
|
|
|
* The content height. See gtk_drawing_area_set_content_height() for details.
|
|
|
|
|
*/
|
|
|
|
|
props[PROP_CONTENT_HEIGHT] =
|
|
|
|
|
g_param_spec_int ("content-height",
|
|
|
|
|
P_("Content Height"),
|
|
|
|
|
P_("Desired height for displayed content"),
|
|
|
|
|
0, G_MAXINT, 0,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class, LAST_PROP, props);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2020-05-05 15:49:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkDrawingArea::resize:
|
|
|
|
|
* @area: the #GtkDrawingArea that emitted the signal
|
|
|
|
|
* @width: the width of the viewport
|
|
|
|
|
* @height: the height of the viewport
|
|
|
|
|
*
|
|
|
|
|
* The ::resize signal is emitted once when the widget is realized, and
|
|
|
|
|
* then each time the widget is changed while realized. This is useful
|
|
|
|
|
* in order to keep state up to date with the widget size, like for
|
|
|
|
|
* instance a backing surface.
|
|
|
|
|
*/
|
|
|
|
|
signals[RESIZE] =
|
|
|
|
|
g_signal_new (I_("resize"),
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkDrawingAreaClass, resize),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__INT_INT,
|
|
|
|
|
G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
|
|
|
|
|
g_signal_set_va_marshaller (signals[RESIZE],
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
_gtk_marshal_VOID__INT_INTv);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drawing_area_init (GtkDrawingArea *darea)
|
|
|
|
|
{
|
2020-05-05 18:57:21 +00:00
|
|
|
|
gtk_widget_set_focusable (GTK_WIDGET (darea), FALSE);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 18:07:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drawing_area_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new drawing area.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a new #GtkDrawingArea
|
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
|
GtkWidget*
|
1998-05-03 22:41:32 +00:00
|
|
|
|
gtk_drawing_area_new (void)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
2002-10-05 23:15:39 +00:00
|
|
|
|
return g_object_new (GTK_TYPE_DRAWING_AREA, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
2016-11-18 03:00:02 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_drawing_area_set_content_width:
|
|
|
|
|
* @self: a #GtkDrawingArea
|
|
|
|
|
* @width: the width of contents
|
|
|
|
|
*
|
|
|
|
|
* Sets the desired width of the contents of the drawing area. Note that
|
|
|
|
|
* because widgets may be allocated larger sizes than they requested, it is
|
|
|
|
|
* possible that the actual width passed to your draw function is larger
|
|
|
|
|
* than the width set here. You can use gtk_widget_set_halign() to avoid
|
|
|
|
|
* that.
|
|
|
|
|
*
|
|
|
|
|
* If the width is set to 0 (the default), the drawing area may disappear.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gtk_drawing_area_set_content_width (GtkDrawingArea *self,
|
|
|
|
|
int width)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_DRAWING_AREA (self));
|
|
|
|
|
g_return_if_fail (width >= 0);
|
|
|
|
|
|
|
|
|
|
if (priv->content_width == width)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
priv->content_width = width;
|
|
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (self));
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CONTENT_WIDTH]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_drawing_area_get_content_width:
|
|
|
|
|
* @self: a #GtkDrawingArea
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the value previously set via gtk_drawing_area_set_content_width().
|
|
|
|
|
*
|
|
|
|
|
* Returns: The width requested for content of the drawing area
|
|
|
|
|
**/
|
|
|
|
|
int
|
|
|
|
|
gtk_drawing_area_get_content_width (GtkDrawingArea *self)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_DRAWING_AREA (self), 0);
|
|
|
|
|
|
|
|
|
|
return priv->content_width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_drawing_area_set_content_height:
|
|
|
|
|
* @self: a #GtkDrawingArea
|
|
|
|
|
* @height: the height of contents
|
|
|
|
|
*
|
|
|
|
|
* Sets the desired height of the contents of the drawing area. Note that
|
|
|
|
|
* because widgets may be allocated larger sizes than they requested, it is
|
|
|
|
|
* possible that the actual height passed to your draw function is larger
|
|
|
|
|
* than the height set here. You can use gtk_widget_set_valign() to avoid
|
|
|
|
|
* that.
|
|
|
|
|
*
|
|
|
|
|
* If the height is set to 0 (the default), the drawing area may disappear.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gtk_drawing_area_set_content_height (GtkDrawingArea *self,
|
|
|
|
|
int height)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_DRAWING_AREA (self));
|
|
|
|
|
g_return_if_fail (height >= 0);
|
|
|
|
|
|
|
|
|
|
if (priv->content_height == height)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
priv->content_height = height;
|
|
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (self));
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CONTENT_HEIGHT]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_drawing_area_get_content_height:
|
|
|
|
|
* @self: a #GtkDrawingArea
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the value previously set via gtk_drawing_area_set_content_height().
|
|
|
|
|
*
|
|
|
|
|
* Returns: The height requested for content of the drawing area
|
|
|
|
|
**/
|
|
|
|
|
int
|
|
|
|
|
gtk_drawing_area_get_content_height (GtkDrawingArea *self)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_DRAWING_AREA (self), 0);
|
|
|
|
|
|
|
|
|
|
return priv->content_height;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 04:45:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drawing_area_set_draw_func:
|
|
|
|
|
* @self: a #GtkDrawingArea
|
2020-01-13 01:11:15 +00:00
|
|
|
|
* @draw_func: (allow-none): callback that lets you draw
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* the drawing area's contents
|
2020-01-13 01:11:15 +00:00
|
|
|
|
* @user_data: (closure): user data passed to @draw_func
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* @destroy: destroy notifier for @user_data
|
|
|
|
|
*
|
|
|
|
|
* Setting a draw function is the main thing you want to do when using a drawing
|
2020-05-05 15:49:00 +00:00
|
|
|
|
* area. It is called whenever GTK needs to draw the contents of the drawing area
|
2016-11-18 04:45:36 +00:00
|
|
|
|
* to the screen.
|
|
|
|
|
*
|
|
|
|
|
* The draw function will be called during the drawing stage of GTK. In the
|
|
|
|
|
* drawing stage it is not allowed to change properties of any GTK widgets or call
|
|
|
|
|
* any functions that would cause any properties to be changed.
|
|
|
|
|
* You should restrict yourself exclusively to drawing your contents in the draw
|
|
|
|
|
* function.
|
|
|
|
|
*
|
|
|
|
|
* If what you are drawing does change, call gtk_widget_queue_draw() on the
|
2018-06-18 09:17:41 +00:00
|
|
|
|
* drawing area. This will cause a redraw and will call @draw_func again.
|
2016-11-18 04:45:36 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_drawing_area_set_draw_func (GtkDrawingArea *self,
|
|
|
|
|
GtkDrawingAreaDrawFunc draw_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GDestroyNotify destroy)
|
|
|
|
|
{
|
|
|
|
|
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_DRAWING_AREA (self));
|
|
|
|
|
|
|
|
|
|
if (priv->draw_func_target_destroy_notify != NULL)
|
|
|
|
|
priv->draw_func_target_destroy_notify (priv->draw_func_target);
|
|
|
|
|
|
|
|
|
|
priv->draw_func = draw_func;
|
|
|
|
|
priv->draw_func_target = user_data;
|
|
|
|
|
priv->draw_func_target_destroy_notify = destroy;
|
|
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (self));
|
|
|
|
|
}
|
|
|
|
|
|