/* This is the function that draws the puzzle piece. *Itjustdrawsarectangularcutoutofthepuzzlebyclipping *awaytherest.
*/ staticvoid
gtk_puzzle_piece_snapshot (GdkPaintable *paintable,
GdkSnapshot *snapshot, double width, double height)
{
GtkPuzzlePiece *self = GTK_PUZZLE_PIECE (paintable);
/* Do the same thing we did for the width with the height.
*/ return (gdk_paintable_get_intrinsic_height (self->puzzle) + self->height - 1) / self->height;
}
/* We can compute our aspect ratio relative to the puzzle. *Thislogicagainworksforthecasewherethepuzzle *hasnoaspectratio,becausethe0returnvalueisunchanged.
*/ return gdk_paintable_get_intrinsic_aspect_ratio (self->puzzle) * self->height / self->width;
}
/* When defining the GType, we need to implement the GdkPaintable interface */
G_DEFINE_TYPE_WITH_CODE (GtkPuzzlePiece, gtk_puzzle_piece, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
gtk_puzzle_piece_paintable_init))
/* We need to declare a destructor to release our reference to the *puzzlepaintableanddisconnectoursignalhandlers.
*/ staticvoid
gtk_puzzle_piece_dispose (GObject *object)
{
GtkPuzzlePiece *self = GTK_PUZZLE_PIECE (object);
/* And finally, we add a constructor. *Itisdeclaredintheheadersothattheotherexamples *canuseit.
*/
GdkPaintable *
gtk_puzzle_piece_new (GdkPaintable *puzzle,
guint x,
guint y,
guint width,
guint height)
{
GtkPuzzlePiece *self;
/* These are sanity checks, so that we get warnings if we accidentally
* do anything stupid. */
g_return_val_if_fail (GDK_IS_PAINTABLE (puzzle), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (x < width, NULL);
g_return_val_if_fail (y < height, NULL);
/* Here are the accessors that we need to inspect the puzzle *piecesinothercode.
*/
GdkPaintable *
gtk_puzzle_piece_get_puzzle (GtkPuzzlePiece *self)
{ /* Add sanity checks here, too. *Ifyoumakeahabitoutofthis,youcanalwaysrely *onyourcodehavingsanitychecks,whichmakesit *wayeasiertodebug.
*/
g_return_val_if_fail (GTK_IS_PUZZLE_PIECE (self), NULL);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.