[Xcb] A simple question on XCBGCFunction [SOLVED]
Barton C Massey
bart at cs.pdx.edu
Sun Jun 11 12:48:42 PDT 2006
The util library should probably contain vararg functions
for this sort of case that take lists of some kind of
struct. C is putrid. BTW, is auto array initialization
legal old ANSI C?
Bart
In message <1C214DB4-8FE2-4B71-9350-D6EB61C9B97D at quirkster.com> you wrote:
>
> --===============1843747594==
> Content-Type: multipart/alternative; boundary=Apple-Mail-3--54375222
>
>
> --Apple-Mail-3--54375222
> Content-Transfer-Encoding: 7bit
> Content-Type: text/plain;
> charset=US-ASCII;
> delsp=yes;
> format=flowed
>
> There are a couple of ways to avoid this type of error.
>
> First, you could fill in the values array during declaration:
>
> CARD32 mask = XCBGCFunction/*0*/ | XCBGCForeground/*2*/ |
> XCBGCBackground/*3*/ | XCBGCLineWidth/*4*/ |
> XCBGCLineStyle/*5*/ | XCBGCGraphicsExposures/
> *16*/;
> CARD32 values[] = {
> XCBGXxor, // XCBGCFunction
> screen->white_pixel, // XCBGCForeground
> 0x1ecf48, // XCBGCBackground (light
> green)
> 1, // XCBGCLineWidth
> XCBLineStyleOnOffDash, // XCBGCLineStyle
> 0 //
> XCBGCGraphicsExposures
> };
>
>
> Second, there are some convenience structures and functions
> in the XCBaux library that replace the value lists with structures:
>
> #include <X11/XCB/xcb_aux.h>
>
> XCBParamsGC params;
> params.function = XCBGXxor;
> params.foreground = screen->white_pixel;
> params.background = 0x1ecf48;
> params.line_width = 1;
> params.line_style = XCBLineStyleOnOffDash;
> params.graphics_exposures = 0;
>
> XCBAuxCreateGC(c, sel_rect, win, mask, ¶ms);
>
> This method also avoids errors due to incorrect ordering
> of the value list.
>
> Ian
>
> PS. What the heck is up with the mailing list server on freedesktop??
> This and a few other messages were posted almost a month ago!
>
> On May 18, 2006, at 6:48 AM, Osmo Maatta wrote:
>
> > Problem solved.
> >
> > The "values[]" variable was too small to store all values.
> > CARD32 values[2];
> >
> > CARD32 values[10];
> >
> > Thanks.
> >
> > -------------------------------------------------------------
> > This code is OK.
> >
> >
> > sel_rect = XCBGCONTEXTNew (c);
> >
> > mask = XCBGCFunction/*0*/ | XCBGCForeground/*2*/ |
> > XCBGCBackground/*3*/ | XCBGCLineWidth/*4*/ |
> > XCBGCLineStyle/*5*/ | XCBGCGraphicsExposures/*16*/;
> >
> > // In same order as the mask.
> > values[0] = XCBGXxor; // XCBGCFunction
> > values[1] = screen->white_pixel; // XCBGCForeground
> > values[2] = 0x1ecf48; // XCBGCBackground
> > (light green)
> > values[3] = 1; // XCBGCLineWidth
> > values[4] = XCBLineStyleOnOffDash; // XCBGCLineStyle
> > values[5] = 0; //
> > XCBGCGraphicsExposures
> >
> > XCBCreateGC (c, sel_rect, win, mask, values);
> > ....
> >
> > // Draw using the XOR (XCBGXxor) pen.
> >
> > case XCBExpose:
> > {
> > XCBPolyLine (c, CoordModeOrigin, win, sel_rect, 4, polyline);
> > XCBPolyRectangle (c, win, sel_rect, 2, rectangles);
> >
> > XCBSync (c, 0);
> >
> > break;
> > }
> >
> > case XCBButtonPress:
> > {
> > // Each second click will make the lines visible (XOR'ing pixels).
> > XCBPolyLine (c, CoordModeOrigin, win, sel_rect, 4, polyline);
> > XCBPolyRectangle (c, win, sel_rect, 2, rectangles);
> > }
> >
> > ...
> >
> >
> >
> >
> > Osmo Maatta wrote:
> >> Hello,
> >>
> >> I try to create a GC (graphic context) to draw some rubber lines
> >> using the XOR pen.
> >>
> >> I do this:
> >>
> >> XCBGCONTEXT sel_rect;
> >> ....
> >>
> >> sel_rect = XCBGCONTEXTNew (c);
> >> mask = XCBGCFunction | XCBGCForeground | XCBGCLineStyle |
> >> XCBGCGraphicsExposures;
> >> values[0] = XCBGXxor; values[1] = screen->black_pixel;
> >> values[2] = XCBLineStyleOnOffDash;
> >> values[3] = 0;
> >> XCBCreateGC (c, sel_rect, win, mask, values);
> >>
> >>
> >> and later in
> >>
> >> case XCBExpose:
> >> {
> >> printf("Debug expose\n");
> >>
> >> XCBPolyRectangle (c, win, sel_rect, 2, rectangles);
> >> XCBPolyLine (c, CoordModeOrigin, win, sel_rect, 4,
> >> polyline);
> >>
> >> break;
> >> }
> >> ---------------------------------
> >> But it does not draw anything. Only the debug line appears on
> >> the console.
> >> -------------------
> >>
> >> I have even tried with XCBGXcopy value as XCBGCFunction.
> >>
> >> values[0] = XCBGXcopy;
> >> Xlib manual says that GXcopy is the default GCFunction. I suppose
> >> it's the same in XCB.
> >> But it does not work.
> >>
> >> It works (draws lines in a window) if I remove XCBGCFunction from
> >> the mask and remove the value[0]= line.
> >> How to use the values for XCBGCFunction mask ?
> >> -------------------------------------------------------------------
> >>
> >> I follow this tutorial
> >> http://www.iecn.u-nancy.fr/~torri/files/xcb/doc/
> >>
> >> Many TIA.
> >> Osmo
> >>
> >> _______________________________________________
> >> Xcb mailing list
> >> Xcb at lists.freedesktop.org
> >> http://lists.freedesktop.org/mailman/listinfo/xcb
> >>
> >
> >
> > _______________________________________________
> > Xcb mailing list
> > Xcb at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/xcb
>
>
> --Apple-Mail-3--54375222
> Content-Transfer-Encoding: quoted-printable
> Content-Type: text/html;
> charset=ISO-8859-1
>
> <HTML><BODY style=3D"word-wrap: break-word; -khtml-nbsp-mode: space; =
> -khtml-line-break: after-white-space; ">There are a couple of ways to =
> avoid this type of error.<DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV>First, you could fill in =
> the values array during declaration:</DIV><BR><DIV>CARD32 mask =
> =3D=A0XCBGCFunction/*0*/=A0=A0=A0=A0=A0 | XCBGCForeground/*2*/=A0=A0 =
> |=A0</DIV><DIV>=A0 =A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0XCBGCBackground/*3*/=
> | XCBGCLineWidth/*4*/=A0=A0=A0=A0=A0 |=A0</DIV><DIV>=A0=A0 =A0=A0 =A0=A0 =
> =A0=A0 =A0=A0 =A0XCBGCLineStyle/*5*/=A0=A0=A0=A0=A0=A0 | =
> XCBGCGraphicsExposures/*16*/;</DIV><DIV>CARD32 values[] =3D =
> {</DIV><DIV>=A0 =A0 =A0=A0 =A0XCBGXxor, =A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =
> =A0=A0 =A0=A0 =A0// XCBGCFunction=A0</DIV><DIV>=A0 =A0 =A0=A0 =
> =A0screen->white_pixel,=A0 =A0 =A0// XCBGCForeground=A0</DIV><DIV>=A0 =
> =A0 =A0=A0 =A00x1ecf48,=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0=
> =A0// XCBGCBackground (light green)=A0</DIV><DIV>=A0 =A0 =A0=A0 =A01, =A0=
> =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =
> =A0=A0 =A0// XCBGCLineWidth=A0</DIV><DIV>=A0 =A0 =A0=A0 =
> =A0XCBLineStyleOnOffDash,=A0 // XCBGCLineStyle=A0</DIV><DIV>=A0 =A0 =A0=A0=
> =A00=A0 =A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0 =A0=A0=
> =A0=A0 =A0=A0 =A0=A0 =A0// =
> XCBGCGraphicsExposures=A0</DIV><DIV>};</DIV><DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV>Second, there are some =
> convenience structures and functions</DIV><DIV>in the XCBaux library =
> that replace the value lists with structures:</DIV><DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV>#include =
> <X11/XCB/xcb_aux.h></DIV><DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV>XCBParamsGC =
> params;</DIV><DIV>params.function =3D =
> XCBGXxor;</DIV><DIV>params.foreground =3D =
> screen->white_pixel;</DIV><DIV>params.background =3D =
> 0x1ecf48;</DIV><DIV>params.line_width =3D 1;</DIV><DIV>params.line_style =
> =3D XCBLineStyleOnOffDash;</DIV><DIV>params.graphics_exposures =3D =
> 0;</DIV><DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV>XCBAuxCreateGC(c, sel_rect, =
> win, mask, &params);</DIV><DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV>This method also avoids =
> errors due to incorrect ordering</DIV><DIV>of the value =
> list.</DIV><DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV>Ian</DIV><DIV><BR =
> class=3D"khtml-block-placeholder"></DIV><DIV>PS.=A0 What the heck is up =
> with the mailing list server on freedesktop??</DIV><DIV>This and a few =
> other messages were posted almost a month =
> ago!</DIV><DIV><BR><DIV><DIV>On May 18, 2006, at 6:48 AM, Osmo Maatta =
> wrote:</DIV><BR class=3D"Apple-interchange-newline"><BLOCKQUOTE =
> type=3D"cite"> Problem solved.<BR> <BR> The "values[]" variable was too =
> small to store all values.<BR> <STRIKE>=A0 CARD32=A0=A0 values[2];=A0=A0 =
> <BR> <BR> </STRIKE>=A0 CARD32=A0=A0 values[10];=A0=A0 <BR> <BR> =
> Thanks.<BR> <BR> =
> -------------------------------------------------------------<BR> This =
> code is OK.<BR> <BR> <BR> sel_rect =3D XCBGCONTEXTNew (c); <BR> <BR> =
> mask =3D XCBGCFunction/*0*/=A0=A0=A0=A0=A0 | XCBGCForeground/*2*/=A0=A0 =
> | <BR> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 XCBGCBackground/*3*/ | =
> XCBGCLineWidth/*4*/=A0=A0=A0=A0=A0 | <BR> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
> XCBGCLineStyle/*5*/=A0=A0=A0=A0=A0=A0 | XCBGCGraphicsExposures/*16*/; =
> <BR> <BR> // In same order as the mask. <BR> values[0] =3D =
> XCBGXxor;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0 =
> // XCBGCFunction <BR> values[1] =3D screen->white_pixel;=A0=A0=A0=A0 =
> // XCBGCForeground <BR> values[2] =3D 0x1ecf48;=A0=A0=A0=A0=A0=A0=A0=A0=A0=
> =A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0 // XCBGCBackground (light =
> green) <BR> values[3] =3D 1;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0 // =
> XCBGCLineWidth <BR> values[4] =3D XCBLineStyleOnOffDash;=A0 // =
> XCBGCLineStyle <BR> values[5] =3D 0;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=
> =A0 // XCBGCGraphicsExposures <BR> <BR> XCBCreateGC (c, sel_rect, win, =
> mask, values); <BR> ....<BR> <BR> // Draw using the XOR (XCBGXxor) pen. =
> <BR> <BR> case XCBExpose: <BR> =A0 { <BR> =A0=A0=A0=A0XCBPolyLine (c, =
> CoordModeOrigin, win, sel_rect, 4, polyline); <BR> =A0=A0=A0=A0XCBPolyRect=
> angle (c, win, sel_rect, 2, rectangles); <BR> <BR> =A0=A0=A0=A0XCBSync =
> (c, 0); <BR> <BR> =A0=A0=A0=A0break; <BR> =A0 } <BR> <BR> case =
> XCBButtonPress: <BR> =A0{ <BR> =A0=A0=A0 // Each second click will make =
> the lines visible (XOR'ing pixels).<BR> =A0=A0=A0=A0XCBPolyLine (c, =
> CoordModeOrigin, win, sel_rect, 4, polyline); <BR> =A0=A0=A0=A0XCBPolyRect=
> angle (c, win, sel_rect, 2, rectangles); <BR> =A0} <BR> <BR> ...<BR> =
> <BR> <BR> <BR> <BR> Osmo Maatta wrote: <BLOCKQUOTE =
> cite=3D"mid446C38B3.7010606 at gmail.com" type=3D"cite">Hello, <BR> <BR> I =
> try to create a GC (graphic context) to draw some rubber lines using the =
> XOR pen. <BR> <BR> I do this: <BR> <BR> =A0XCBGCONTEXT=A0=A0=A0 =
> sel_rect; <BR> =A0.... <BR> <BR> =A0sel_rect =3D XCBGCONTEXTNew (c); =
> <BR> =A0mask =3D=A0=A0 XCBGCFunction | XCBGCForeground | XCBGCLineStyle =
> | XCBGCGraphicsExposures; <BR> =A0values[0] =3D XCBGXxor; =A0values[1] =3D=
> screen->black_pixel; <BR> =A0values[2] =3D XCBLineStyleOnOffDash; =
> <BR> =A0values[3] =3D 0; <BR> =A0XCBCreateGC (c, sel_rect,=A0 win, mask, =
> values); <BR> <BR> <BR> and later in <BR> <BR> case XCBExpose: <BR> { =
> <BR> =A0=A0=A0 printf("Debug expose\n"); <BR> <BR> =A0=A0=A0 =
> XCBPolyRectangle (c, win, sel_rect, 2, rectangles); <BR> =A0=A0=A0=A0=A0 =
> =A0=A0=A0 XCBPolyLine (c, CoordModeOrigin, win, sel_rect, 4, polyline); =
> <BR> <BR> =A0=A0=A0 break; <BR> } <BR> =
> --------------------------------- <BR> =A0 But it does not draw =
> anything. Only the debug line appears on the console. <BR> =
> ------------------- <BR> <BR> I have even tried with=A0 XCBGXcopy=A0 =
> value as XCBGCFunction. <BR> <BR> values[0] =3D XCBGXcopy; <BR> Xlib =
> manual says that GXcopy is the default GCFunction. I suppose it's the =
> same in XCB. <BR> But it does not work. <BR> <BR> It works (draws lines =
> in a window) if I remove XCBGCFunction from the mask and remove the =
> value[0]=3D line. <BR> How to use the values for XCBGCFunction mask ? =
> <BR> ------------------------------------------------------------------- =
> <BR> <BR> I follow this tutorial <BR> <A class=3D"moz-txt-link-freetext"=
> =
> href=3D"http://www.iecn.u-nancy.fr/%7Etorri/files/xcb/doc/">http://www.iec=
> n.u-nancy.fr/~torri/files/xcb/doc/</A> <BR> <BR> Many TIA. <BR> =A0Osmo =
> <BR> <BR> _______________________________________________ <BR> Xcb =
> mailing list <BR> <A class=3D"moz-txt-link-abbreviated" =
> href=3D"mailto:Xcb at lists.freedesktop.org">Xcb at lists.freedesktop.org</A> =
> <BR> <A class=3D"moz-txt-link-freetext" =
> href=3D"http://lists.freedesktop.org/mailman/listinfo/xcb">http://lists.fr=
> eedesktop.org/mailman/listinfo/xcb</A> <BR> <BR> </BLOCKQUOTE> <BR> =
> <BR><DIV style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: =
> 0px; margin-left: 0px; =
> ">_______________________________________________</DIV><DIV =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; ">Xcb mailing list</DIV><DIV style=3D"margin-top: 0px; =
> margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A =
> href=3D"mailto:Xcb at lists.freedesktop.org">Xcb at lists.freedesktop.org</A></D=
> IV><DIV style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; "><A =
> href=3D"http://lists.freedesktop.org/mailman/listinfo/xcb">http://lists.fr=
> eedesktop.org/mailman/listinfo/xcb</A></DIV> =
> </BLOCKQUOTE></DIV><BR></DIV></BODY></HTML>=
>
> --Apple-Mail-3--54375222--
>
> --===============1843747594==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
>
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb
> --===============1843747594==--
More information about the Xcb
mailing list