[Xcb] A simple question on XCBGCFunction [SOLVED]
Ian Osgood
iano at quirkster.com
Sun Jun 11 11:45:16 PDT 2006
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/xcb/attachments/20060611/e8d8cd29/attachment.html
More information about the Xcb
mailing list