[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-xorg
Subject:    Xlib hardware multi overlay transparency question
From:       "Diaz, James M" <James.Diaz () gdit ! com>
Date:       2011-07-14 21:46:20
Message-ID: 65E679D52B23864FAC609C4C4E11657486FFE99FA9 () EXCHCCR01 ! ad ! local
[Download RAW message or body]

[Attachment #2 (text/plain)]



Is this the proper list to post advanced Xlib questions? If not, any recommendations? \
Using Xlib, my hopes are to create two or more hardware overlay transparencies atop \
of a main window.  I found an example program for hardware overlays, but, with only \
one overlay.  Ive extended the example (see below) to several overlays.  My problem \
is the inner overlay graphics do not show through the top overlay window.  Partial \
code is listed below. Any oversights i have made, or, is there any tricks to make the \
inner layer visible through the top layer?  Perhaps an alternative software \
transparency technique is recommended?  i do have an example using the xshape \
extension.  Also have an example of the alpha blending technique made possible with \
the XRender extension.   Neither seem appropriate for my application. Xrender appears \
way to complicated to merge with my existing application.

The software application I am working on was written many years back using only the \
basic Xlib. The window depth was 8 bits and utilized a shifted color index \
methodology to create pseudo window overlays. My task is to revamp the graphics \
software to use a 24 bit color depth. In doing so, i now need a new way using Xlib to \
make two transparent overlays to go atop my main window, a window that displays a \
terrain map. Likewise, three more overlays are required for the menu. The top layers \
display vehicle icons, text, and temporary graphics. Ive explored both hardware \
overlays and software transparencies. it would so nice to be able to take advantage \
of hardware overlays. My graphics card supports up to 4 overlays.  I call an \
XRaiseWindow to draw on the requested layer. Also annoying is the Expose event \
initiated with the call to XRaiseWindow. Am using an Xlib single overlay example Mark \
Kilgard posted many years back.

In the following code snippet example, based on a single overlay example written my \
Mark Kilgard, I create three overlays. Perhaps there is an option to add to insure \
the middle overlays are visible through the top overlay?

my platform is a pc laptop running Red Hat release 4.  Video card is NVIDIA  Quadro \
FX 2700M.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "sovLayerUtil.h"

#define SIZE 400        /* Width and height of window. */

Display *dpy;
Window root, win, overlay1, overlay2, overlay[10];
Colormap cmap[10];
Visual *defaultVisual;
int screen, black, white, red,blue,green,brown,forcolor[10], nVisuals, i,k, status;
GC normalGC, overlay1GC, overlay2GC, overlayGC[10];
XEvent event;
sovVisualInfo template;
sovVisualInfo *otherLayerInfo, *yetanotherLayerInfo, *defaultLayerInfo;
XSetWindowAttributes winattrs;
XGCValues gcvals;
XColor color, exact;
int x = 0, y = SIZE / 2;

static char*text_color[]={"red","blue","green","yellow"};



main(int argc, char *argv[])
{

// open display, dpy, and retrieve the root window ID and default visual ID

  dpy = XOpenDisplay(NULL);

  if (dpy == NULL)
    fatalError("cannot open display");

  screen = DefaultScreen(dpy);                // screen
  root = RootWindow(dpy, screen);             // root window
  defaultVisual = DefaultVisual(dpy, screen); // default visual id


  /* Find layer info of default visual. */

//  Assignment of properties to template is required
//  for sovGetVisualInfo to compare and find a Visual
//  with similar properties as the template.

  template.vinfo.visualid = defaultVisual->visualid;
  defaultLayerInfo = sovGetVisualInfo(dpy, VisualIDMask,
    &template, &nVisuals);    // we now have default layer info


  /* Look for visual with transparent pixel in layer "above"
     default visual   */

  template.layer = defaultLayerInfo->layer + 1;   //VisualLayerMask
  template.vinfo.screen = screen;                 //VisualScreenMask
  template.type = TransparentPixel;               //VisualTransparentType


  otherLayerInfo = sovGetVisualInfo(dpy,
                   VisualScreenMask | VisualLayerMask | VisualTransparentType, \
&template, &nVisuals);


  if (otherLayerInfo == NULL) {

      fatalError("unable to find 2nd layer above default visual");  } else {


  //  layer above default Visual exists!

    /* Create *base* window using default visual. */

 //  the Simple Window inherets its depth, class, and visual
 //  from its parent. All other attributes have their default
 //  values.  Cursor will be that of the window's parent
 //  until the cursor attribute is set with XDefineCursor or
 //  XChangeWindowAttributes.  Note no colormap is required
 //  if visual is same as parent.

    black = BlackPixel(dpy, screen);
    white = WhitePixel(dpy, screen);

    win = XCreateSimpleWindow(dpy, root, 10, 10, SIZE, SIZE, 1,
      black, white);


//   Sort through next layers

     otherLayerInfo = sovGetVisualInfo(dpy,
      VisualScreenMask | VisualLayerMask | VisualTransparentType,
      &template, &nVisuals);


 for( i = 0; i<3; i++){

    printf(" i : %d\n", i);
    printf(" Visual ID: 0x%x\n", otherLayerInfo[i].vinfo.visualid);
    printf(" screen: %d\n", otherLayerInfo[i].vinfo.screen);
    printf(" depth: %d\n", otherLayerInfo[i].vinfo.depth);
    printf(" value: %d\n", otherLayerInfo[i].value);

    // now,create colormap for overlay
      cmap[i] = XCreateColormap(dpy, root,
                        otherLayerInfo[i].vinfo.visual, AllocNone);

    // fetch assignment for "red" the first layer, green the second layer, blue the \
third.

    // status = XAllocNamedColor(dpy, cmap[i], "red", &color, &exact);
    status = XAllocNamedColor(dpy, cmap[i], text_color[i], &color, &exact);

    if (status == 0)
          fatalError("could not allocate red");

     forcolor[i] = color.pixel;

     printf(" color allocated from cmap: %d\n",i);


     // set up window attributes with new colormap, no border


     /* Use transparent pixel for background */

     winattrs.background_pixel = otherLayerInfo[i].value;
     winattrs.border_pixel = 0;    /* No border but still
                                              necessary to avoid BadMatch. */
     winattrs.colormap = cmap[i];

     // create the window overlay
     overlay[i] = XCreateWindow(dpy, win, 0, 0, SIZE, SIZE, 0,
         otherLayerInfo[i].vinfo.depth,
         InputOutput, otherLayerInfo[i].vinfo.visual,
         CWBackPixel | CWBorderPixel | CWColormap, &winattrs);

      printf(" Finished Overlay: %d\n",i);

  }
}




// solicit input for normal window and input for overlay1

XSelectInput(dpy, win, ExposureMask);

for( i = 0; i<3; i++){

XSelectInput(dpy, overlay[i], ExposureMask | ButtonPressMask);


// set the WM_COLORMAP_WINDOWS property on window,win, to the list of
// windows specified in argument 3, ie &overlay1 of qty 1.
// This property tells the window manager that subwindows of this
// application need to have their own colormaps installed.
XSetWMColormapWindows(dpy, win, &overlay[0], 4);

// set graphic content values of normalGC

gcvals.foreground = black;
gcvals.line_width = 8;
gcvals.cap_style = CapRound;


// Create normalGC

normalGC = XCreateGC(dpy, win,
GCForeground | GCLineWidth | GCCapStyle, &gcvals);


// Create overlayGC, each with a new foreground color.

gcvals.foreground = forcolor[i];
overlayGC[i] = XCreateGC(dpy, overlay[i], GCForeground, &gcvals);

}


// map window and its subwindows


XMapSubwindows(dpy, win);
XMapWindow(dpy, win);

....

//in event loop, a call to redrawOverlayPlanesMessage to draw , upon mouse click, a \
message on each overlay:


printf(" draw on overlay: %// wait for action d\n", j);// wait for action
   i=0;

  while (1) {
    XNextEvent(dpy, &event);
    switch (event.type) {

    case Expose:

      if (event.xexpose.window == win)
          redrawNormalPlanes();
      else {
//       redrawOverlayPlanesMessage(i);
      }
      break;

    case ButtonPress:

      x = random() % SIZE / 2;
      y = random() % SIZE;

      i++;
      if( i>2) i=0;
//      XClearWindow(dpy, overlay[i]);
        redrawOverlayPlanesMessage(i);

        break;
  }
}




void redrawOverlayPlanesMessage(int j)
{

   if( j == 0){

     x = random() % SIZE / 2;
     y = random() % SIZE;


     XRaiseWindow(dpy,overlay[j]);
     XDrawString(dpy, overlay[j], overlayGC[j], x, y + 15,
      MESSAGE0, sizeof(MESSAGE0) - 1);
     printf("  draw on overlay: %d\n", j);

  }

  if( j == 1 ){
     x = random() % SIZE / 2;
     y = random() % SIZE;
     XRaiseWindow(dpy,overlay[j]);
     XDrawString(dpy, overlay[j], overlayGC[j], x, y + 15,
       MESSAGE1, sizeof(MESSAGE1) - 1);
     printf("  draw on overlay: %d\n", j);
  }
}
}


[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:x="urn:schemas-microsoft-com:office:excel" \
xmlns:p="urn:schemas-microsoft-com:office:powerpoint" \
xmlns:a="urn:schemas-microsoft-com:office:access" \
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" \
xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" \
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" \
xmlns:b="urn:schemas-microsoft-com:office:publisher" \
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" \
xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" \
xmlns:odc="urn:schemas-microsoft-com:office:odc" \
xmlns:oa="urn:schemas-microsoft-com:office:activation" \
xmlns:html="http://www.w3.org/TR/REC-html40" \
xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" \
xmlns:Repl="http://schemas.microsoft.com/repl/" \
xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" \
xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" \
xmlns:ppda="http://www.passport.com/NameSpace.xsd" \
xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" \
xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" \
xmlns:ds="http://www.w3.org/2000/09/xmldsig#" \
xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" \
xmlns:udc="http://schemas.microsoft.com/data/udc" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" \
xmlns:ec="http://www.w3.org/2001/04/xmlenc#" \
xmlns:sp="http://schemas.microsoft.com/sharepoint/" \
xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" \
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" \
xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" \
xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" \
xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" \
xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" \
xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" \
xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" \
xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" \
xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" \
xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" \
xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" \
xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" \
xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" \
xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="&#1;" \
xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type \
content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 12 \
(filtered medium)"><style><!-- /* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p
	{mso-style-priority:99;
	margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=EN-US link=blue \
vlink=purple><div class=WordSection1><p class=MsoNormal \
style='margin-bottom:12.0pt'><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'><br><br>Is this \
the proper list to post advanced Xlib questions? If not, any recommendations?&nbsp; \
Using Xlib, my hopes are to create two or more hardware overlay transparencies atop \
of a main window.&nbsp; I found an example program for hardware overlays, but, with \
only one overlay.&nbsp; Ive extended the example (see below) to several \
overlays.&nbsp; My problem is the inner overlay graphics do not show through the top \
overlay window.&nbsp; Partial code is listed below. Any oversights i have made, or, \
is there any tricks to make the inner layer visible through the top layer?&nbsp; \
Perhaps an alternative software transparency technique is recommended?&nbsp; i do \
have an example using the xshape extension.&nbsp; Also have an example of the alpha \
blending technique made possible with the XRender extension. &nbsp; Neither seem \
appropriate for my application. Xrender appears way to complicated to merge with my \
existing application.<br><br>The software application I am working on was written \
many years back using only the basic Xlib. The window depth was 8 bits and utilized a \
shifted color index methodology to create pseudo window overlays. My task is to \
revamp the graphics software to use a 24 bit color depth. In doing so, i now need a \
new way using Xlib to make two transparent overlays to go atop my main window, a \
window that displays a terrain map. Likewise, three more overlays are required for \
the menu. The top layers display vehicle icons, text, and temporary graphics. Ive \
explored both hardware overlays and software transparencies. it would so nice to be \
able to take advantage of hardware overlays. My graphics card supports up to 4 \
overlays.&nbsp; I call an XRaiseWindow to draw on the requested layer. Also annoying \
is the Expose event initiated with the call to XRaiseWindow. Am using an Xlib single \
overlay example Mark Kilgard posted many years back. <br><br>In the following code \
snippet example, based on a single overlay example written my Mark Kilgard, I create \
three overlays. Perhaps there is an option to add to insure the middle overlays are \
visible through the top overlay?<br><br>my platform is a pc laptop running Red Hat \
release 4.&nbsp; Video card is NVIDIA&nbsp; Quadro FX 2700M. <br><br>#include \
&lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;math.h&gt;<br>#include \
&quot;sovLayerUtil.h&quot;<br><br>#define SIZE \
400&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Width and height of window. \
*/<br><br>Display *dpy;<br>Window root, win, overlay1, overlay2, \
overlay[10];<br>Colormap cmap[10];<br>Visual *defaultVisual;<br>int screen, black, \
white, red,blue,green,brown,forcolor[10], nVisuals, i,k, status;<br>GC normalGC, \
overlay1GC, overlay2GC, overlayGC[10];<br>XEvent event;<br>sovVisualInfo \
template;<br>sovVisualInfo *otherLayerInfo, *yetanotherLayerInfo, \
*defaultLayerInfo;<br>XSetWindowAttributes winattrs;<br>XGCValues gcvals;<br>XColor \
color, exact;<br>int x = 0, y = SIZE / 2;<br><br>static \
char*text_color[]={&quot;red&quot;,&quot;blue&quot;,&quot;green&quot;,&quot;yellow&quot;};<br><br><br><br>main(int \
argc, char *argv[])<br>{<br><br>// open display, dpy, and retrieve the root window ID \
and default visual ID<br><br>&nbsp; dpy = XOpenDisplay(NULL);<br><br>&nbsp; if (dpy \
== NULL)<br>&nbsp;&nbsp;&nbsp; fatalError(&quot;cannot open \
display&quot;);<br><br>&nbsp; screen = \
DefaultScreen(dpy);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
// screen<br>&nbsp; root = RootWindow(dpy, \
screen);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // \
root window<br>&nbsp; defaultVisual = DefaultVisual(dpy, screen); // default visual \
id<br><br><br>&nbsp; /* Find layer info of default visual. */<br><br>//&nbsp; \
Assignment of properties to template is required<br>//&nbsp; for sovGetVisualInfo to \
compare and find a Visual<br>//&nbsp; with similar properties as the \
template.<br><br>&nbsp; template.vinfo.visualid = \
defaultVisual-&gt;visualid;<br>&nbsp; defaultLayerInfo = sovGetVisualInfo(dpy, \
VisualIDMask,<br>&nbsp;&nbsp;&nbsp; &amp;template, &amp;nVisuals);&nbsp;&nbsp;&nbsp; \
// we now have default layer info<br><br><br>&nbsp; /* Look for visual with \
transparent pixel in layer &quot;above&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp; default \
visual&nbsp;&nbsp; */<br><br>&nbsp; template.layer = defaultLayerInfo-&gt;layer + \
1;&nbsp;&nbsp; //VisualLayerMask<br>&nbsp; template.vinfo.screen = \
screen;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
//VisualScreenMask<br>&nbsp; template.type = \
TransparentPixel;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
//VisualTransparentType<br><br><br>&nbsp; otherLayerInfo = \
sovGetVisualInfo(dpy,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
VisualScreenMask | VisualLayerMask | VisualTransparentType, &amp;template, \
&amp;nVisuals);<br><br><br>&nbsp; if (otherLayerInfo == NULL) \
{<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fatalError(&quot;unable to find 2nd layer \
above default visual&quot;);&nbsp; } else {<br><br><br>&nbsp; //&nbsp; layer above \
default Visual exists!<br><br>&nbsp;&nbsp;&nbsp; /* Create *base* window using \
default visual. */<br><br>&nbsp;//&nbsp; the Simple Window inherets its depth, class, \
and visual<br>&nbsp;//&nbsp; from its parent. All other attributes have their \
default<br>&nbsp;//&nbsp; values.&nbsp; Cursor will be that of the window's \
parent<br>&nbsp;//&nbsp; until the cursor attribute is set with XDefineCursor \
or<br>&nbsp;//&nbsp; XChangeWindowAttributes.&nbsp; Note no colormap is \
required<br>&nbsp;//&nbsp; if visual is same as parent.<br><br>&nbsp;&nbsp;&nbsp; \
black = BlackPixel(dpy, screen);<br>&nbsp;&nbsp;&nbsp; white = WhitePixel(dpy, \
screen);<br><br>&nbsp;&nbsp;&nbsp; win = XCreateSimpleWindow(dpy, root, 10, 10, SIZE, \
SIZE, 1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; black, white);<br><br><br>//&nbsp;&nbsp; \
Sort through next layers<br><br>&nbsp;&nbsp;&nbsp;&nbsp; otherLayerInfo = \
sovGetVisualInfo(dpy,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VisualScreenMask | \
VisualLayerMask | VisualTransparentType,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&amp;template, &amp;nVisuals);<br><br><br>&nbsp;for( i = 0; i&lt;3; \
i++){<br><br>&nbsp;&nbsp;&nbsp; printf(&quot; i : %d\n&quot;, \
i);<br>&nbsp;&nbsp;&nbsp; printf(&quot; Visual ID: 0x%x\n&quot;, \
otherLayerInfo[i].vinfo.visualid);<br>&nbsp;&nbsp;&nbsp; printf(&quot; screen: \
%d\n&quot;, otherLayerInfo[i].vinfo.screen);<br>&nbsp;&nbsp;&nbsp; printf(&quot; \
depth: %d\n&quot;, otherLayerInfo[i].vinfo.depth);<br>&nbsp;&nbsp;&nbsp; \
printf(&quot; value: %d\n&quot;, otherLayerInfo[i].value);<br><br>&nbsp;&nbsp;&nbsp; \
// now,create colormap for overlay<br>&nbsp;&nbsp; &nbsp;&nbsp; cmap[i] = \
XCreateColormap(dpy, \
root,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
otherLayerInfo[i].vinfo.visual, AllocNone);<br><br>&nbsp;&nbsp;&nbsp; // fetch \
assignment for &quot;red&quot; the first layer, green the second layer, blue the \
third.<br><br>&nbsp;&nbsp;&nbsp; // status = XAllocNamedColor(dpy, cmap[i], \
&quot;red&quot;, &amp;color, &amp;exact);<br>&nbsp;&nbsp;&nbsp; status = \
XAllocNamedColor(dpy, cmap[i], text_color[i], &amp;color, \
&amp;exact);<br><br>&nbsp;&nbsp;&nbsp; if (status == \
0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fatalError(&quot;could \
not allocate red&quot;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp; forcolor[i] = \
color.pixel;<br><br>&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot; color allocated from cmap: \
%d\n&quot;,i);<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp; // set up window attributes with \
new colormap, no border<br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp;&nbsp; /* Use \
transparent pixel for background */<br><br>&nbsp;&nbsp;&nbsp;&nbsp; \
winattrs.background_pixel = otherLayerInfo[i].value;<br>&nbsp;&nbsp;&nbsp;&nbsp; \
winattrs.border_pixel = 0;&nbsp;&nbsp;&nbsp; /* No border but still<br>&nbsp;&nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; necessary to \
avoid BadMatch. */<br>&nbsp;&nbsp;&nbsp;&nbsp; winattrs.colormap = \
cmap[i];<br><br>&nbsp;&nbsp;&nbsp;&nbsp; // create the window \
overlay<br>&nbsp;&nbsp;&nbsp;&nbsp; overlay[i] = XCreateWindow(dpy, win, 0, 0, SIZE, \
SIZE, 0,<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
otherLayerInfo[i].vinfo.depth,<br>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; InputOutput, \
otherLayerInfo[i].vinfo.visual,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
CWBackPixel | CWBorderPixel | CWColormap, \
&amp;winattrs);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot; Finished Overlay: \
%d\n&quot;,i);<br>&nbsp;<br>&nbsp; }<br>}<br><br><br><br><br>// solicit input for \
normal window and input for overlay1<br><br>XSelectInput(dpy, win, \
ExposureMask);<br><br>for( i = 0; i&lt;3; i++){<br><br>XSelectInput(dpy, overlay[i], \
ExposureMask | ButtonPressMask);<br><br><br>// set the WM_COLORMAP_WINDOWS property \
on window,win, to the list of<br>// windows specified in argument 3, ie &amp;overlay1 \
of qty 1.<br>// This property tells the window manager that subwindows of this<br>// \
application need to have their own colormaps installed.<br>XSetWMColormapWindows(dpy, \
win, &amp;overlay[0], 4);<br><br>// set graphic content values of \
normalGC<br><br>gcvals.foreground = black;<br>gcvals.line_width = \
8;<br>gcvals.cap_style = CapRound;<br><br><br>// Create normalGC<br><br>normalGC = \
XCreateGC(dpy, win,<br>GCForeground | GCLineWidth | GCCapStyle, \
&amp;gcvals);<br><br><br>// Create overlayGC, each with a new foreground \
color.<br><br>gcvals.foreground = forcolor[i];<br>overlayGC[i] = XCreateGC(dpy, \
overlay[i], GCForeground, &amp;gcvals);<br><br>}<br><br><br>// map window and its \
subwindows<br><br><br>XMapSubwindows(dpy, win);<br>XMapWindow(dpy, \
win);<br><br>....<br><br>//in event loop, a call to redrawOverlayPlanesMessage to \
draw , upon mouse click, a message on each overlay:<br><br><br>printf(&quot; draw on \
overlay: %// wait for action d\n&quot;, j);// wait for action<br>&nbsp;&nbsp; \
i=0;<br><br>&nbsp; while (1) {<br>&nbsp;&nbsp;&nbsp; XNextEvent(dpy, \
&amp;event);<br>&nbsp;&nbsp;&nbsp; switch (event.type) {<br><br>&nbsp;&nbsp;&nbsp; \
case Expose:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (event.xexpose.window == \
win)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
redrawNormalPlanes();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else \
{<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
redrawOverlayPlanesMessage(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp; case \
ButtonPress:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = random() % SIZE / \
2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y = random() % \
SIZE;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
if( i&gt;2) i=0;<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XClearWindow(dpy, \
overlay[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
redrawOverlayPlanesMessage(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp; \
}<br>}<br><br><br><br><br>void redrawOverlayPlanesMessage(int \
j)<br>{<br><br>&nbsp;&nbsp; if( j == 0){<br><br>&nbsp;&nbsp;&nbsp;&nbsp; x = random() \
% SIZE / 2;<br>&nbsp;&nbsp;&nbsp;&nbsp; y = random() % \
SIZE;<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp; \
XRaiseWindow(dpy,overlay[j]);<br>&nbsp;&nbsp;&nbsp;&nbsp; XDrawString(dpy, \
overlay[j], overlayGC[j], x, y + 15,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MESSAGE0, \
sizeof(MESSAGE0) - 1);<br>&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;&nbsp; draw on \
overlay: %d\n&quot;, j);<br><br>&nbsp; }<br><br>&nbsp; if( j == 1 \
){<br>&nbsp;&nbsp;&nbsp;&nbsp; x = random() % SIZE / 2;<br>&nbsp;&nbsp;&nbsp;&nbsp; y \
= random() % SIZE;<br>&nbsp;&nbsp;&nbsp;&nbsp; \
XRaiseWindow(dpy,overlay[j]);<br>&nbsp;&nbsp;&nbsp;&nbsp; XDrawString(dpy, \
overlay[j], overlayGC[j], x, y + 15,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
MESSAGE1, sizeof(MESSAGE1) - 1);<br>&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;&nbsp; draw \
on overlay: %d\n&quot;, j);<br>&nbsp; \
}<br>}<br>}<br><br><br><br><br><o:p></o:p></span></p></div></body></html>



_______________________________________________
xorg@lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: freedesktop-xorg@progressive-comp.com
--===============1685922180==--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic