| 1 | /* |
| 2 | * GooCanvas Demo. Copyright (C) 2006 Damon Chaplin. |
| 3 | * Released under the GNU LGPL license. See COPYING for details. |
| 4 | * |
| 5 | * demo-item.c - a simple demo item. |
| 6 | */ |
| 7 | #include <config.h>cxx . . $ `<file>/config.h`/ |
| 8 | #include "goocanvas.h"cxx . . $ `<file>/src/goocanvas.h`/ |
| 9 | #include "demo-item.h"cxx . . $ `<file>/demo/demo-item.h`/ |
| 10 | |
| 11 | |
| 12 | /* Use the GLib convenience macro to define the type. GooDemoItem is the |
| 13 | class struct, goo_demo_item is the function prefix, and our class is a |
| 14 | subclass of GOO_TYPE_CANVAS_ITEM_SIMPLE. */ |
| 15 | G_DEFINE_TYPEcxx . . $ `<external>/9567554376676449156/gtype.h:1834:9`! (GooDemoItem, goo_demo_item, GOO_TYPE_CANVAS_ITEM_SIMPLEcxx . . $ `src/goocanvasitemsimple.h:65:9`!) |
| 16 | |
| 17 | |
| 18 | /* The standard object initialization function. */ |
| 19 | static void |
| 20 | goo_demo_item_initcxx . . $ goo_demo_item_init(c3f7e3815b025bc3). (GooDemoItemcxx . . $ GooDemoItem# *demo_item) |
| 21 | { |
| 22 | demo_item->xcxx . . $ _GooDemoItem#x. = 0.0; |
| 23 | demo_item->ycxx . . $ _GooDemoItem#y. = 0.0; |
| 24 | demo_item->widthcxx . . $ _GooDemoItem#width. = 0.0; |
| 25 | demo_item->heightcxx . . $ _GooDemoItem#height. = 0.0; |
| 26 | } |
| 27 | |
| 28 | |
| 29 | /* The convenience function to create new items. This should start with a |
| 30 | parent argument and end with a variable list of object properties to fit |
| 31 | in with the standard canvas items. */ |
| 32 | GooCanvasItemcxx . . $ GooCanvasItem#* |
| 33 | goo_demo_item_newcxx . . $ goo_demo_item_new(81fa6bcda469491f). (GooCanvasItemcxx . . $ GooCanvasItem# *parent, |
| 34 | gdoublecxx . . $ gdouble# x, |
| 35 | gdoublecxx . . $ gdouble# y, |
| 36 | gdoublecxx . . $ gdouble# width, |
| 37 | gdoublecxx . . $ gdouble# height, |
| 38 | ...) |
| 39 | { |
| 40 | GooCanvasItemcxx . . $ GooCanvasItem# *item; |
| 41 | GooDemoItemcxx . . $ GooDemoItem# *demo_item; |
| 42 | const char *first_property; |
| 43 | va_listcxx . . $ va_list# var_args; |
| 44 | |
| 45 | item = g_object_newcxx . . $ g_object_new(8485fe61b4be4c78). (GOO_TYPE_DEMO_ITEMcxx . . $ `demo/demo-item.h:16:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 46 | |
| 47 | demo_item = (GooDemoItemcxx . . $ GooDemoItem#*) item; |
| 48 | demo_item->xcxx . . $ _GooDemoItem#x. = x; |
| 49 | demo_item->ycxx . . $ _GooDemoItem#y. = y; |
| 50 | demo_item->widthcxx . . $ _GooDemoItem#width. = width; |
| 51 | demo_item->heightcxx . . $ _GooDemoItem#height. = height; |
| 52 | |
| 53 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`! (var_args, height); |
| 54 | first_property = va_argcxx . . $ `<external>/8105065126723003039/stdarg.h:53:9`! (var_args, char*); |
| 55 | if (first_property) |
| 56 | g_object_set_valistcxx . . $ g_object_set_valist(b170b7725713b0eb). ((GObjectcxx . . $ GObject#*) item, first_property, var_args); |
| 57 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`! (var_args); |
| 58 | |
| 59 | if (parent) |
| 60 | { |
| 61 | goo_canvas_item_add_childcxx . . $ goo_canvas_item_add_child(87fff2f0f9494eca). (parent, item, -1); |
| 62 | g_object_unrefcxx . . $ g_object_unref(5d22bdacc48458e8). (item); |
| 63 | } |
| 64 | |
| 65 | return item; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | /* The update method. This is called when the canvas is initially shown and |
| 70 | also whenever the object is updated and needs to change its size and/or |
| 71 | shape. It should calculate its new bounds in its own coordinate space, |
| 72 | storing them in simple->bounds. */ |
| 73 | static void |
| 74 | goo_demo_item_updatecxx . . $ goo_demo_item_update(9d4bfc2a7ae41ab9). (GooCanvasItemSimplecxx . . $ GooCanvasItemSimple# *simple, |
| 75 | cairo_tcxx . . $ cairo_t# *cr) |
| 76 | { |
| 77 | GooDemoItemcxx . . $ GooDemoItem# *demo_item = (GooDemoItemcxx . . $ GooDemoItem#*) simple; |
| 78 | |
| 79 | /* Compute the new bounds. */ |
| 80 | simple->boundscxx . . $ _GooCanvasItemSimple#bounds..x1cxx . . $ _GooCanvasBounds#x1. = demo_item->xcxx . . $ _GooDemoItem#x.; |
| 81 | simple->boundscxx . . $ _GooCanvasItemSimple#bounds..y1cxx . . $ _GooCanvasBounds#y1. = demo_item->ycxx . . $ _GooDemoItem#y.; |
| 82 | simple->boundscxx . . $ _GooCanvasItemSimple#bounds..x2cxx . . $ _GooCanvasBounds#x2. = demo_item->xcxx . . $ _GooDemoItem#x. + demo_item->widthcxx . . $ _GooDemoItem#width.; |
| 83 | simple->boundscxx . . $ _GooCanvasItemSimple#bounds..y2cxx . . $ _GooCanvasBounds#y2. = demo_item->ycxx . . $ _GooDemoItem#y. + demo_item->heightcxx . . $ _GooDemoItem#height.; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /* The paint method. This should draw the item on the given cairo_t, using |
| 88 | the item's own coordinate space. */ |
| 89 | static void |
| 90 | goo_demo_item_paintcxx . . $ goo_demo_item_paint(b8ec41b05fac55eb). (GooCanvasItemSimplecxx . . $ GooCanvasItemSimple# *simple, |
| 91 | cairo_tcxx . . $ cairo_t# *cr, |
| 92 | const GooCanvasBoundscxx . . $ GooCanvasBounds# *bounds) |
| 93 | { |
| 94 | GooDemoItemcxx . . $ GooDemoItem# *demo_item = (GooDemoItemcxx . . $ GooDemoItem#*) simple; |
| 95 | |
| 96 | cairo_move_tocxx . . $ cairo_move_to(e818af540ecaa23a). (cr, demo_item->xcxx . . $ _GooDemoItem#x., demo_item->ycxx . . $ _GooDemoItem#y.); |
| 97 | cairo_line_tocxx . . $ cairo_line_to(e818af540ecaa23a). (cr, demo_item->xcxx . . $ _GooDemoItem#x., demo_item->ycxx . . $ _GooDemoItem#y. + demo_item->heightcxx . . $ _GooDemoItem#height.); |
| 98 | cairo_line_tocxx . . $ cairo_line_to(e818af540ecaa23a). (cr, demo_item->xcxx . . $ _GooDemoItem#x. + demo_item->widthcxx . . $ _GooDemoItem#width., |
| 99 | demo_item->ycxx . . $ _GooDemoItem#y. + demo_item->heightcxx . . $ _GooDemoItem#height.); |
| 100 | cairo_line_tocxx . . $ cairo_line_to(e818af540ecaa23a). (cr, demo_item->xcxx . . $ _GooDemoItem#x. + demo_item->widthcxx . . $ _GooDemoItem#width., demo_item->ycxx . . $ _GooDemoItem#y.); |
| 101 | cairo_close_pathcxx . . $ cairo_close_path(21788b7825b29bf). (cr); |
| 102 | goo_canvas_style_set_fill_optionscxx . . $ goo_canvas_style_set_fill_options(d7308a4accee21ca). (simple->simple_datacxx . . $ _GooCanvasItemSimple#simple_data.->stylecxx . . $ _GooCanvasItemSimpleData#style., cr); |
| 103 | cairo_fillcxx . . $ cairo_fill(21788b7825b29bf). (cr); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /* Hit detection. This should check if the given coordinate (in the item's |
| 108 | coordinate space) is within the item. If it is it should return TRUE, |
| 109 | otherwise it should return FALSE. */ |
| 110 | static gbooleancxx . . $ gboolean# |
| 111 | goo_demo_item_is_item_atcxx . . $ goo_demo_item_is_item_at(f7a154ab26c49889). (GooCanvasItemSimplecxx . . $ GooCanvasItemSimple# *simple, |
| 112 | gdoublecxx . . $ gdouble# x, |
| 113 | gdoublecxx . . $ gdouble# y, |
| 114 | cairo_tcxx . . $ cairo_t# *cr, |
| 115 | gbooleancxx . . $ gboolean# is_pointer_event) |
| 116 | { |
| 117 | GooDemoItemcxx . . $ GooDemoItem# *demo_item = (GooDemoItemcxx . . $ GooDemoItem#*) simple; |
| 118 | |
| 119 | if (x < demo_item->xcxx . . $ _GooDemoItem#x. || (x > demo_item->xcxx . . $ _GooDemoItem#x. + demo_item->widthcxx . . $ _GooDemoItem#width.) |
| 120 | || y < demo_item->ycxx . . $ _GooDemoItem#y. || (y > demo_item->ycxx . . $ _GooDemoItem#y. + demo_item->heightcxx . . $ _GooDemoItem#height.)) |
| 121 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 122 | |
| 123 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | /* The class initialization function. Here we set the class' update(), paint() |
| 128 | and is_item_at() methods. */ |
| 129 | static void |
| 130 | goo_demo_item_class_initcxx . . $ goo_demo_item_class_init(f84e60fbe1537134). (GooDemoItemClasscxx . . $ GooDemoItemClass# *klass) |
| 131 | { |
| 132 | GooCanvasItemSimpleClasscxx . . $ GooCanvasItemSimpleClass# *simple_class = (GooCanvasItemSimpleClasscxx . . $ GooCanvasItemSimpleClass#*) klass; |
| 133 | |
| 134 | simple_class->simple_updatecxx . . $ _GooCanvasItemSimpleClass#simple_update. = goo_demo_item_updatecxx . . $ goo_demo_item_update(9d4bfc2a7ae41ab9).; |
| 135 | simple_class->simple_paintcxx . . $ _GooCanvasItemSimpleClass#simple_paint. = goo_demo_item_paintcxx . . $ goo_demo_item_paint(b8ec41b05fac55eb).; |
| 136 | simple_class->simple_is_item_atcxx . . $ _GooCanvasItemSimpleClass#simple_is_item_at. = goo_demo_item_is_item_atcxx . . $ goo_demo_item_is_item_at(f7a154ab26c49889).; |
| 137 | } |
| 138 | |
| 139 |