How to set GC with transparent pixmap

This is a discussion on How to set GC with transparent pixmap within the Linux Programming forums, part of the Platform Specific Boards category; Hello everyone. I'm programming in C with xlib (standart libs). I need set GC with transparent pixmap (in some pixels). ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    4

    How to set GC with transparent pixmap

    Hello everyone.
    I'm programming in C with xlib (standart libs).
    I need set GC with transparent pixmap (in some pixels).
    I have colored pixmap, that set tile for GC via XSetTile. This pixmap is painted on all screen.
    And I have mask, created by this pixmap. This mask is set by XSetClipMask.
    But mask is set only for one pixmap, that stay in (0, 0).
    How I can multiple this mask on all screen?

  2. #2
    Registered User
    Join Date
    Jan 2013
    Posts
    4
    Function create bitmaps from mulricolor pixmap (xpm), set context by each bitmap
    and draw polygons with each context:
    Code:
    void XFillPolygonByPixmap(Display *disp, Drawable d, GC gc,
                              XPoint *polygon, int len,
                              Pixmap pixmap, Pixmap mask)
    {
        const unsigned short MAX_PIXMAP_WHC = 50;
    
    
        char data[MAX_PIXMAP_WHC*MAX_PIXMAP_WHC];
        unsigned short indData = 0;
        unsigned short currColor = 0;
        char colorHex[6];
        unsigned short ind;
        static signed short noneColor = -1;
        XpmImage xpmImage;       // xpm color of line
        unsigned short indBuf = 0;
        unsigned char buf = 0;
        static Pixmap currBitmap[MAX_PIXMAP_WHC];
        static Pixmap prevPixmap = NULL;
        static unsigned short indBitmap = 0;
        static unsigned long colorLong[MAX_PIXMAP_WHC];
        static unsigned int ncolor = 0;
    
    
        // Using tile if no mask in *.xpm
        if (!mask)
        {
            XSetFillStyle(disp, gc, FillTiled);
            XSetTile(disp, gc, pixmap);
            XFillPolygon(disp, d, gc, polygon, len, Complex, CoordModeOrigin);
            return;
        }
    
    
        // Generate new data. Else - use previous
        if (pixmap != prevPixmap)
        {
            prevPixmap = pixmap;
            noneColor = -1;
            XpmCreateXpmImageFromPixmap(disp, pixmap, mask, &xpmImage, NULL);
            ncolor = xpmImage.ncolors;
    
    
            // Take all colors
            for (ind = 0; ind < ncolor; ind++)
            {
                // for look and understand format of c_color use:
                // printf("%s\n", xpmImage.colorTable[ind].c_color);
                colorHex[0] = xpmImage.colorTable[ind].c_color[1];
                colorHex[1] = xpmImage.colorTable[ind].c_color[2];
                colorHex[2] = xpmImage.colorTable[ind].c_color[5];
                colorHex[3] = xpmImage.colorTable[ind].c_color[6];
                colorHex[4] = xpmImage.colorTable[ind].c_color[9];
                colorHex[5] = xpmImage.colorTable[ind].c_color[10];
    
    
                // Get index of None color in colorTable
                if (xpmImage.colorTable[ind].c_color[0] == 'N'
                        && xpmImage.colorTable[ind].c_color[1] == 'o'
                        && xpmImage.colorTable[ind].c_color[2] == 'n'
                        && xpmImage.colorTable[ind].c_color[3] == 'e')
                    noneColor = ind;
    
    
                // Save all colors
                colorLong[ind] = strtol(colorHex, NULL, 16);
            }
    
    
            for (ind = 0; ind < indBitmap; ind++)
                XFreePixmap(disp, currBitmap[ind]);
    
    
            // Create bitmaps for each color
            for (currColor = 0, indBitmap = 0;
                 currColor < ncolor; currColor++)
            {
                if (currColor == noneColor)
                    continue;
    
    
                // Filter all array on current color
                for (ind = 0, buf = 0, indBuf = 0, indData = 0;
                     ind < xpmImage.width*xpmImage.height; ind++)
                {
                    // If current pixel is equal current color - set high bit
                    // else - bit is zero
                    if (xpmImage.data[ind] == currColor)
                        buf |= 0x80;
    
    
                    // if index is equal width - shift right on width-indBuf bits
                    bool flagWidth = ((ind+1)%xpmImage.width == 0);
    
    
                    // If num of bits is 8 or flag is set, save data
                    if (indBuf == 7 || flagWidth)
                    {
                        if (flagWidth)
                        {
                            while(indBuf < 7)
                            {
                                buf = buf >> 1;
                                indBuf++;
                            }
                        }
                        data[indData++] = buf;
                        indBuf = 0;
                        buf = 0;
                    }
                    else
                    {
                        indBuf++;
                        buf = buf >> 1;
                    }
                }
    
    
                // Create bitmaps for each color
                currBitmap[indBitmap++] = XCreateBitmapFromData(disp, d, data,
                                                   xpmImage.width, xpmImage.height);
            }
        }
    
    
        // For each color set stipple by bitmap  and fill polygon
        for (currColor = 0, ind = 0;
             currColor < ncolor, ind < indBitmap; currColor++)
        {
            if (currColor == noneColor)
                continue;
    
    
            XSetFillStyle(disp, gc, FillStippled);
            XSetForeground(disp, gc, colorLong[currColor]);
            XSetStipple(disp, gc, currBitmap[ind++]);
            XFillPolygon(disp, d, gc, polygon, len, Complex, CoordModeOrigin);
        }
        return;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GTK rotating pixmap
    By belgian1990 in forum C Programming
    Replies: 2
    Last Post: 05-23-2010, 11:36 PM
  2. Cairo and GTK, still need a pixmap?
    By TriKri in forum Linux Programming
    Replies: 0
    Last Post: 03-18-2008, 05:18 PM
  3. Transparent BMP display
    By Devil Panther in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2005, 07:35 AM
  4. X!!! pixmap cursor!
    By K-$ in forum C Programming
    Replies: 1
    Last Post: 06-20-2002, 07:56 AM
  5. Transparent Windows
    By genghis in forum Windows Programming
    Replies: 1
    Last Post: 01-16-2002, 06:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21