1a05542005-07-28Martin Nilsson /* -*- C -*- */ class GDK2.GC; inherit G.Object; //! A GC, or Graphics Context, is used for most low-level drawing operations. //! <p> //! As an example, the foreground color, background color, and drawing //! function is stored in the GC.</p> //! //! NOIMG
81d1512006-08-07Lance Dillon void create(GTK2.Widget|GDK2.Drawable context, mapping|void attributes)
1a05542005-07-28Martin Nilsson //! The argument is either a W(Widget) or a GDK2(Drawable) in //! which the gc will be valid. { struct object *o;
3d76632005-11-03Lance Dillon  GdkGC *gc;
81d1512006-08-07Lance Dillon  GdkGCValues values; int have_values=0;
0c50a82010-02-09Lance Dillon  struct mapping *m=NULL; struct svalue *sv;
81d1512006-08-07Lance Dillon 
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_setup(); pgtk2_verify_not_inited();
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o.%m",&o,&m);
0c50a82010-02-09Lance Dillon  memset(&values,0,sizeof(values));
81d1512006-08-07Lance Dillon 
0c50a82010-02-09Lance Dillon  if (m!=NULL) {
81d1512006-08-07Lance Dillon  have_values=1; #define VALUE(X,Y) \
2edd4f2008-01-30Per Hedbor  if ( (sv=simple_mapping_string_lookup(m,#X)) ) { \
af14f62006-08-08Henrik Grubbström (Grubba)  values.X=sv->u.integer; \ have_values|=Y; \ }
81d1512006-08-07Lance Dillon  VALUE(graphics_exposures,GDK_GC_EXPOSURES); VALUE(subwindow_mode,GDK_GC_SUBWINDOW); VALUE(join_style,GDK_GC_JOIN_STYLE); VALUE(cap_style,GDK_GC_CAP_STYLE);
e4e5af2006-08-08Henrik Grubbström (Grubba)  VALUE(line_style,GDK_GC_LINE_STYLE); VALUE(line_width,GDK_GC_LINE_WIDTH);
81d1512006-08-07Lance Dillon  VALUE(clip_x_origin,GDK_GC_CLIP_X_ORIGIN); VALUE(clip_y_origin,GDK_GC_CLIP_Y_ORIGIN); VALUE(ts_x_origin,GDK_GC_TS_X_ORIGIN); VALUE(ts_y_origin,GDK_GC_TS_Y_ORIGIN); VALUE(fill,GDK_GC_FILL); VALUE(function,GDK_GC_FUNCTION);
847d4c2016-09-18Chris Angelico  if (g_type_is_a(G_TYPE_FROM_INSTANCE(get_gobject(o)), GDK_TYPE_DRAWABLE))
81d1512006-08-07Lance Dillon  gc=gdk_gc_new_with_values(GDK_WINDOW(get_gobject(o)),
af14f62006-08-08Henrik Grubbström (Grubba)  &values,have_values);
81d1512006-08-07Lance Dillon  else gc=gdk_gc_new_with_values(GTK_WIDGET(get_gobject(o))->window, &values,have_values); } else {
847d4c2016-09-18Chris Angelico  if (g_type_is_a(G_TYPE_FROM_INSTANCE(get_gobject(o)), GDK_TYPE_DRAWABLE))
81d1512006-08-07Lance Dillon  gc=gdk_gc_new(GDK_WINDOW(get_gobject(o))); else gc=gdk_gc_new(GTK_WIDGET(get_gobject(o))->window); }
3d76632005-11-03Lance Dillon  THIS->obj=G_OBJECT(gc);
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args); pgtk2__init_this_object();
1a05542005-07-28Martin Nilsson }
81d1512006-08-07Lance Dillon GDK2.Screen get_screen(); //! Gets the screen.
1a05542005-07-28Martin Nilsson mapping(string:mixed) get_values() //! Get all (or rather most) values from the GC. //! Even though GdkGCValues contains a GdkFont object, we won't return //! this value because GdkFont is deprecated. The Pango methods should //! be used instead. { GdkGCValues v; struct svalue *osp; if (args)
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  gdk_gc_get_values(GDK_GC(THIS->obj),&v); osp=Pike_sp;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("join_style")); push_int(v.join_style); ref_push_string(_STR("cap_style")); push_int(v.cap_style); ref_push_string(_STR("line_style")); push_int(v.line_style); ref_push_string(_STR("line_width")); push_int(v.line_width); ref_push_string(_STR("clip_x_origin")); push_int(v.clip_x_origin); ref_push_string(_STR("clip_y_origin")); push_int(v.clip_y_origin); ref_push_string(_STR("ts_x_origin")); push_int(v.ts_x_origin); ref_push_string(_STR("ts_y_origin")); push_int(v.ts_y_origin); ref_push_string(_STR("subwindow_mode")); push_int(v.subwindow_mode); ref_push_string(_STR("clip_mask")); push_gobject(v.clip_mask); ref_push_string(_STR("stipple")); push_gobject(v.stipple); ref_push_string(_STR("tile")); push_gobject(v.tile);
e0b3b22008-01-30Per Hedbor /*push_text("font"); push_gdkobject(v.font,font,0); */
1a05542005-07-28Martin Nilsson  /*if (v.font) g_object_ref(v.font); */ if (v.tile) g_object_ref(v.tile); if (v.stipple) g_object_ref(v.stipple); if (v.clip_mask) g_object_ref(v.clip_mask);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("fill")); push_int(v.fill);
6a932b2014-08-18Martin Nilsson  ref_push_string(literal_function_string); push_int(v.function);
1a05542005-07-28Martin Nilsson  {
3d76632005-11-03Lance Dillon  GdkColor *f,*b;
eae3272008-01-18Henrik Grubbström (Grubba)  f=g_malloc(sizeof(GdkColor));
1a05542005-07-28Martin Nilsson  if (f==NULL)
32353e2005-12-30Martin Nilsson  SIMPLE_OUT_OF_MEMORY_ERROR("get_values",sizeof(GdkColor));
3d76632005-11-03Lance Dillon  b=g_malloc(sizeof(GdkColor));
1a05542005-07-28Martin Nilsson  if (b==NULL)
32353e2005-12-30Martin Nilsson  { g_free(f); SIMPLE_OUT_OF_MEMORY_ERROR("get_values",sizeof(GdkColor)); }
1a05542005-07-28Martin Nilsson  *f=v.foreground; *b=v.background;
2edd4f2008-01-30Per Hedbor  ref_push_string(_STR("foreground")); push_gdkobject(f,color,1); ref_push_string(_STR("background")); push_gdkobject(b,color,1);
1a05542005-07-28Martin Nilsson  } f_aggregate_mapping(Pike_sp-osp); } void set_foreground(GDK2.Color color) //! Set the foreground to the specified GDK2.Color. {
81d1512006-08-07Lance Dillon  pgtk2_verify_inited(); { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
81d1512006-08-07Lance Dillon  gdk_gc_set_foreground(GDK_GC(THIS->obj),get_gdkobject(o,color)); }
1a05542005-07-28Martin Nilsson  RETURN_THIS(); } void set_background(GDK2.Color color) //! Set the background to the specified GDK2.Color. {
81d1512006-08-07Lance Dillon  pgtk2_verify_inited(); { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
81d1512006-08-07Lance Dillon  gdk_gc_set_background(GDK_GC(THIS->obj),get_gdkobject(o,color)); }
1a05542005-07-28Martin Nilsson  RETURN_THIS(); } /* void set_font(GDK22.Font font) //! Set the font to the specified GDK2.Font. //! Deprecated: Use Pango.Layout instead. { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
1a05542005-07-28Martin Nilsson  gdk_gc_set_font(GDK_GC(THIS->obj),get_gdkobject(o,font)); RETURN_THIS(); } */ void set_clip_origin(int x, int y) //! Set the clip mask origin to the specified point. {
81d1512006-08-07Lance Dillon  pgtk2_verify_inited(); { INT_TYPE x,y;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%i%i",&x,&y);
81d1512006-08-07Lance Dillon  gdk_gc_set_clip_origin(GDK_GC(THIS->obj),x,y); }
1a05542005-07-28Martin Nilsson  RETURN_THIS(); } void set_clip_mask(GDK2.Bitmap mask) //! Set the clip mask to the specified GDK2.Bitmap {
81d1512006-08-07Lance Dillon  pgtk2_verify_inited(); { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
81d1512006-08-07Lance Dillon  gdk_gc_set_clip_mask(GDK_GC(THIS->obj),GDK_DRAWABLE(get_gobject(o))); }
1a05542005-07-28Martin Nilsson  RETURN_THIS(); } void set_function(int fun) //! Set the function to the specified one. One of GDK2.Xor, //! GDK2.Invert and GDK2.Copy. {
e4e5af2006-08-08Henrik Grubbström (Grubba)  pgtk2_verify_inited();
81d1512006-08-07Lance Dillon  { INT_TYPE a;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%i",&a);
81d1512006-08-07Lance Dillon  gdk_gc_set_function(GDK_GC(THIS->obj),a); }
1a05542005-07-28Martin Nilsson  RETURN_THIS(); } void set_subwindow(int draw_on_subwindows) //! If set, anything drawn with this GC will draw on subwindows as well //! as the window in which the drawing is done. {
81d1512006-08-07Lance Dillon  pgtk2_verify_inited(); { INT_TYPE a;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%i",&a);
81d1512006-08-07Lance Dillon  gdk_gc_set_subwindow(GDK_GC(THIS->obj),a); } RETURN_THIS(); } void set_fill(int fill) //! Set the fill method to fill. { pgtk2_verify_inited(); { INT_TYPE i;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%d",&i);
81d1512006-08-07Lance Dillon  gdk_gc_set_fill(GDK_GC(THIS->obj),i); } RETURN_THIS(); } void set_tile(GDK2.Pixmap tile) //! Set the background type. Fill must be GDK_TILED { pgtk2_verify_inited(); { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
81d1512006-08-07Lance Dillon  if (GDK_IS_PIXMAP(get_gobject(o))) gdk_gc_set_tile(GDK_GC(THIS->obj),GDK_PIXMAP(get_gobject(o))); } RETURN_THIS(); } void set_stipple(GDK2.Bitmap stipple) //! Set the background type. Fill must be GDK_STIPPLED or GDK_OPAQUE_STIPPLED. { pgtk2_verify_inited(); { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
81d1512006-08-07Lance Dillon  if (GDK_IS_DRAWABLE(get_gobject(o))) gdk_gc_set_stipple(GDK_GC(THIS->obj),GDK_DRAWABLE(get_gobject(o))); } RETURN_THIS(); } void set_ts_origin(int x, int y) //! Set the origin when using tiles or stipples with the GC. The tile //! or stipple will be aligned such that the upper left corner of the //! tile or stipple will coincide with this point. { pgtk2_verify_inited(); { INT_TYPE x,y;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%i%i",&x,&y);
81d1512006-08-07Lance Dillon  gdk_gc_set_ts_origin(GDK_GC(THIS->obj),x,y); } RETURN_THIS(); } void set_clip_rectangle(?GDK2.Rectangle rect) //! Sets the clip mask for a graphics context from a rectangle. The //! clip mask is interpreted relative to the clip origin. { pgtk2_verify_inited(); if (args==1) { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
81d1512006-08-07Lance Dillon  gdk_gc_set_clip_rectangle(GDK_GC(THIS->obj),get_gdkobject(o,rectangle)); } else gdk_gc_set_clip_rectangle(GDK_GC(THIS->obj),NULL); RETURN_THIS(); } void set_clip_region(GDK2.Region rect) //! Sets the clip mask for a graphs context from a region. The //! clip mask is interpreted relative to the clip origin. { pgtk2_verify_inited(); if (args==1) { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
81d1512006-08-07Lance Dillon  gdk_gc_set_clip_region(GDK_GC(THIS->obj),get_gdkobject(o,region)); } else gdk_gc_set_clip_region(GDK_GC(THIS->obj),NULL);
1a05542005-07-28Martin Nilsson  RETURN_THIS(); }
81d1512006-08-07Lance Dillon void set_dashes(int offset, array dashes) //! Sets the way dashed-lines are drawn. Lines will be drawn with //! alternating on and off segments of the lengths specified in //! dashes. The manner in which the on and off segments are drawn is //! determined by the line_style value of the GC. { pgtk2_verify_inited(); { int i; INT_TYPE o; struct array *a;
0556f92007-05-01Martin Nilsson  gint8 *list;
81d1512006-08-07Lance Dillon 
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%d%a",&o,&a);
81d1512006-08-07Lance Dillon  list=xalloc(a->size); for (i=0; i<a->size; i++) list[i]=a->item[i].u.integer;
0556f92007-05-01Martin Nilsson 
81d1512006-08-07Lance Dillon  gdk_gc_set_dashes(GDK_GC(THIS->obj),o,list,a->size); free(list); } RETURN_THIS(); } void set_line_attributes(int line_width, int line_style, int cap_style, int join_style) //! Control how lines are drawn. //! line_style is one of GDK2.LineSolid, GDK2,LineOnOffDash and GDK2.LineDoubleDash. //! cap_style is one of GDK2.CapNotLast, GDK2.CapButt, GDK2.CapRound and GDK2.CapProjecting. //! join_style is one of GDK2.JoinMiter, GDK2.JoinRound and GDK2.JoinBevel. { pgtk2_verify_inited(); { INT_TYPE a,b,c,d;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%d%d%d%d",&a,&b,&c,&d);
81d1512006-08-07Lance Dillon  gdk_gc_set_line_attributes(GDK_GC(THIS->obj),a,b,c,d); } RETURN_THIS(); } void copy(GDK2.GC source) //! Copy all attributes from the source GC { pgtk2_verify_inited(); { struct object *o;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o);
81d1512006-08-07Lance Dillon  gdk_gc_copy(GDK_GC(THIS->obj),GDK_GC(get_gobject(o))); } RETURN_THIS(); } void set_exposures(int exp) //! Sets whether copying non-visible portions of a drawable using this gc //! generates exposure events for the corresponding regions of the dest //! drawable. { pgtk2_verify_inited(); { INT_TYPE a;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%i",&a);
81d1512006-08-07Lance Dillon  gdk_gc_set_exposures(GDK_GC(THIS->obj),a); } RETURN_THIS(); }