1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
/* -*- C -*- */ 
class GDK2.Drawable; 
inherit G.Object; 
 
//! The GDK2.Bitmap, GDK2.Window and GDK2.Pixmap classes are all GDK drawables. 
//! <br /> 
//! This means that you can use the same set of functions to draw in them.<br /> 
//! <p> 
//! Pixmaps are offscreen drawables. They can be drawn upon with the 
//! standard drawing primitives, then copied to another drawable (such 
//! as a GDK2.Window) with window->draw_pixmap(), set as the background 
//! for a window or widget, or otherwise used to show graphics (in a 
//! W(Pixmap), as an example). The depth of a pixmap is the number of 
//! bits per pixels. Bitmaps are simply pixmaps with a depth of 
//! 1. (That is, they are monochrome bitmaps - each pixel can be either 
//! on or off). 
//! </p><p> 
//! Bitmaps are mostly used as masks when drawing pixmaps, or as a 
//! shape for a GDK2.Window or a W(Widget) 
//! </p> 
%{ 
#undef TWIN 
#undef GC 
#define TWIN (GDK_DRAWABLE(THIS->obj)) 
/* 
#define GC(X) (get_gdkobject(X, gc)) 
*/ 
#define  GC(X) GDK_GC(get_gobject(X)) 
%} 
 
#include "common_draw.inc" 
 
require x11; 
int xid() 
//! Return the xwindow id. 
{ 
  pgtk2_pop_n_elems(args); 
  push_int((INT_TYPE)GDK_WINDOW_XWINDOW(GDK_DRAWABLE(THIS->obj))); 
} 
endrequire; 
 
int xsize() 
//! Returns the width of the drawable specified in pixels 
{ 
  int s; 
/*  gdk_window_get_size( TWIN, &s, 0 ); */ 
  gdk_drawable_get_size(TWIN,&s,0); 
  pgtk2_pop_n_elems(args); 
  push_int(s); 
} 
 
int ysize() 
//! Returns the height of the drawable specified in pixels 
{ 
  int s; 
/*  gdk_window_get_size( TWIN, 0, &s ); */ 
  gdk_drawable_get_size(TWIN,0,&s); 
  pgtk2_pop_n_elems(args); 
  push_int(s); 
} 
 
mapping(string:int) get_geometry() 
//! Get width, height position and depth of the drawable as a mapping. 
//! <br /> 
//! ([ "x":xpos, "y":ypos, "width":xsize, "height":ysize, 
//!    "depth":bits_per_pixel ]) 
{ 
  int x=0,y=0; 
  int w=0,h=0,d=0; 
  gdk_window_get_geometry(TWIN,&x,&y,&w,&h,&d); 
  pgtk2_pop_n_elems(args); 
  ref_push_string(_STR("x"));  push_int(x); 
  ref_push_string(_STR("y"));  push_int(y); 
  ref_push_string(_STR("width"));  push_int(w); 
  ref_push_string(_STR("height")); push_int(h); 
  ref_push_string(_STR("depth")); push_int(d); 
  f_aggregate_mapping(10); 
} 
 
require gtk28; 
require cairo; 
%{ 
#ifdef HAVE_CAIRO 
#include <cairo.h> 
 
struct program *cairo_program=NULL; 
 
int verify_cairo() { 
  if (!cairo_program) { 
    push_static_text("Cairo.Context"); 
    APPLY_MASTER("resolv",1); 
    cairo_program=program_from_svalue(Pike_sp-1); 
    Pike_sp--; 
 
    if (!cairo_program) 
      Pike_error("Unable to find cairo module.\n"); 
  } 
  if (cairo_program) 
    return 1; 
  return 0; 
} 
#endif 
%} 
 
object get_cairo_context() 
//! Creates a Cairo context for this drawable. 
{ 
  pgtk2_verify_inited(); 
  if (verify_cairo()) { 
    cairo_t *ctx; 
    struct object *o; 
 
    ctx=gdk_cairo_create(GDK_DRAWABLE(THIS->obj)); 
    o=fast_clone_object(cairo_program); 
    ((struct cairo_mod_context *)o->storage)->ctx=ctx; 
    ref_push_object(o); 
  } else { 
    Pike_error("Unable to find cairo module.\n"); 
  } 
} 
 
void set_source_color(object o, GDK2.Color color) 
//! Sets the source color. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
 
    get_all_args("set_source_color",args,"%o%o",&o1,&o2); 
    gdk_cairo_set_source_color(((struct cairo_mod_context *)o1->storage)->ctx, 
                        (GdkColor *)get_gdkobject(o2,color)); 
  } 
  RETURN_THIS(); 
} 
 
void set_source_pixbuf(object o, GDK2.Pixbuf pixbuf, float x, float y) 
//! Sets the pixbuf as the source pattern for a Cairo context. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
    FLOAT_TYPE x,y; 
 
    get_all_args("set_source_pixbuf",args,"%o%o%f%f",&o1,&o2,&x,&y); 
    gdk_cairo_set_source_pixbuf(((struct cairo_mod_context *)o1->storage)->ctx, 
                        GDK_PIXBUF(get_gobject(o2)),x,y); 
  } 
  RETURN_THIS(); 
} 
 
require gtk210; 
void set_source_pixmap(object o, GDK2.Pixmap, float x, float y) 
//! Sets the pixmap as the source pattern for a Cairo context. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
    FLOAT_TYPE x,y; 
 
    get_all_args("set_source_pixmap",args,"%o%o%f%f",&o1,&o2,&x,&y); 
    gdk_cairo_set_source_pixmap(((struct cairo_mod_context *)o1->storage)->ctx, 
                        GDK_PIXMAP(get_gobject(o2)),x,y); 
  } 
  RETURN_THIS(); 
} 
endrequire; 
 
void rectangle(object o, GDK2.Rectangle rect) 
//! Adds the given rectangle to the current path. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
 
    get_all_args("rectangle",args,"%o%o",&o1,&o2); 
    gdk_cairo_rectangle(((struct cairo_mod_context *)o1->storage)->ctx, 
                        (GdkRectangle *)get_gdkobject(o2,rectangle)); 
  } 
  RETURN_THIS(); 
} 
 
void region(object o, GDK2.Region region) 
//! Adds the given region to the current path. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
 
    get_all_args("region",args,"%o%o",&o1,&o2); 
    gdk_cairo_region(((struct cairo_mod_context *)o1->storage)->ctx, 
                        (GdkRegion *)get_gdkobject(o2,region)); 
  } 
  RETURN_THIS(); 
} 
endrequire; 
endrequire;