#include #include "lx.h" #include "proto.h" #include "internal.h" LX_XID lx_CreateGC(LX_CONN *xc, LX_XID drawable, ...) { LX_XID gcid; va_list ap; int key; LX_XID arg_Function; int proto_Function; unsigned int arg_PlaneMask; unsigned int arg_Foreground; unsigned int arg_Background; unsigned int arg_LineWidth; LX_XID arg_LineStyle; int proto_LineStyle; LX_XID arg_CapStyle; int proto_CapStyle; LX_XID arg_JoinStyle; int proto_JoinStyle; LX_XID arg_FillStyle; int proto_FillStyle; LX_XID arg_FillRule; int proto_FillRule; LX_XID arg_Tile; LX_XID arg_Stipple; int arg_TileStipXOrigin; int arg_TileStipYOrigin; LX_XID arg_Font; LX_XID arg_SubwindowMode; int proto_SubwindowMode; int arg_GraphicsExposures; int arg_ClipXOrigin; int arg_ClipYOrigin; LX_XID arg_ClipMask; unsigned int arg_DashOffset; unsigned int arg_Dashes; LX_XID arg_ArcMode; int proto_ArcMode; unsigned int mask; int o; unsigned char req[108]; if (xc->flags & XCF_FAIL) { lx__bad_call(xc,"lx_CreateGC"); return(LX_GC_None); } mask = 0; va_start(ap,drawable); while <"args"> (1) { key = va_arg(ap,int); #define MAPPED(name,converter,bit)\ case LX__GCV_##name: \ arg_##name = va_arg(ap,unsigned long int); \ proto_##name = converter(arg_##name); \ if (proto_##name < 0) \ { lx__bad_call(xc,"lx_CreateGC"); \ return(LX_GC_None); \ } \ mask |= bit; \ break; #define SIMPLE(name,type,bit)\ case LX__GCV_##name: \ arg_##name = va_arg(ap,type); \ mask |= bit; \ break; switch (key) { MAPPED(Function,lx__gcfunction_to_proto,0x000001) SIMPLE(PlaneMask,unsigned int,0x000002) SIMPLE(Foreground,unsigned int,0x000004) SIMPLE(Background,unsigned int,0x000008) SIMPLE(LineWidth,unsigned int,0x000010) MAPPED(LineStyle,lx__gclinestyle_to_proto,0x000020) MAPPED(CapStyle,lx__gccapstyle_to_proto,0x000040) MAPPED(JoinStyle,lx__gcjoinstyle_to_proto,0x000080) MAPPED(FillStyle,lx__gcfillstyle_to_proto,0x000100) MAPPED(FillRule,lx__gcfillrule_to_proto,0x000200) SIMPLE(Tile,unsigned long int,0x000400) SIMPLE(Stipple,unsigned long int,0x000800) SIMPLE(TileStipXOrigin,int,0x001000) SIMPLE(TileStipYOrigin,int,0x002000) SIMPLE(Font,unsigned long int,0x004000) MAPPED(SubwindowMode,lx__gcsubwindowmode_to_proto,0x008000) case LX__GCV_GraphicsExposures: arg_GraphicsExposures = lx__boolean_to_proto(va_arg(ap,int)); mask |= 0x010000; break; SIMPLE(ClipXOrigin,int,0x020000) SIMPLE(ClipYOrigin,int,0x040000) case LX__GCV_ClipMask: arg_ClipMask = va_arg(ap,unsigned long int); if (arg_ClipMask == LX_GCCLIPMASK_None) arg_ClipMask = 0; mask |= 0x080000; break; SIMPLE(DashOffset,unsigned int,0x100000) SIMPLE(Dashes,unsigned int,0x200000) MAPPED(ArcMode,lx__gcarcmode_to_proto,0x400000) case LX__GCV_END: break <"args">; default: lx_abort(); break; } #undef SIMPLE #undef MAPPED } va_end(ap); gcid = lx__new_resource_id(xc); req[0] = XP_REQ_CreateGC; req[1] = 0; // req[2] and [3] filled in later w_card32(&req[4],gcid); w_card32(&req[8],drawable); w_card32(&req[12],mask); o = 16; #define FOO(bit,var) do { if (mask & (bit)) { mask &= ~(bit); w_card32(&req[o],(var)); o += 4; } } while (0) FOO(0x000001,proto_Function); FOO(0x000002,arg_PlaneMask); FOO(0x000004,arg_Foreground); FOO(0x000008,arg_Background); FOO(0x000010,arg_LineWidth); FOO(0x000020,proto_LineStyle); FOO(0x000040,proto_CapStyle); FOO(0x000080,proto_JoinStyle); FOO(0x000100,proto_FillStyle); FOO(0x000200,proto_FillRule); FOO(0x000400,arg_Tile); FOO(0x000800,arg_Stipple); FOO(0x001000,arg_TileStipXOrigin); FOO(0x002000,arg_TileStipYOrigin); FOO(0x004000,arg_Font); FOO(0x008000,proto_SubwindowMode); FOO(0x010000,arg_GraphicsExposures); FOO(0x020000,arg_ClipXOrigin); FOO(0x040000,arg_ClipYOrigin); FOO(0x080000,arg_ClipMask); FOO(0x100000,arg_DashOffset); FOO(0x200000,arg_Dashes); FOO(0x400000,proto_ArcMode); #undef FOO w_card16(&req[2],o>>2); lx__send_req(xc,&req[0],o); return(gcid); }