[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

1017.0. "xdrawimagestring/monochrome problem" by NEXUS::B_BRADACH () Mon Jun 26 1989 10:43

    <<< HARBOR::SHPLOG$DUA1:[NOTES$LIBRARY]DECWINDOWS_PROGRAMMING.NOTE;1 >>>
                    -< DECwindows Programming hints/kinks >-
================================================================================
Note 332.0            xdrawimagestring - monochrome problem              1 reply
CSC32::B_BRADACH                                     19 lines  22-JUN-1989 17:37
--------------------------------------------------------------------------------

    customer is having a problem with xdrawimagestring.
    This program has been run on a VAXstation 2000 and VAXstation II,
    monochrome systems with VMS5.1-1 SDC.  VAXC2.4.  
    
    If xdrawimagestring is executed with a foreground and background having
    the same color index, the text is displayed in the correct foreground
    but with the opposite background color.  The text appears in the window
    as black on white background, although both color indicies are set to
    black.  If this code is executed on an 8 plane color system 
    everything appears correctly.
    
    
    Code follows in the first response. Already posted in
    decwindows_programming note #332.
    
    Any help/suggestions greatly appreciated.
    
    bernie
    csc/cs
    
    

T.RTitleUserPersonal
Name
DateLines
1017.1vaxc programNEXUS::B_BRADACHMon Jun 26 1989 10:46141
/*
 * Environment:
 *
 * VAXStation 2000 running VMS 5.1-1 SDC version.  Program was compiled 
 * using VAX C version 2.4. The program must run on a monochrome system.
 *
 * Problem: If XDrawImageString is executed with a foreground and background
 *          having the same color index, the text is displayed in the correct
 *	    foreground against the opposite background color.  If this code is
 *	    executed on an 8 plane color system everything appears correctly.
 *
 * Method to reproduce:
 *
 * Run the program.  The text appears in the window as black on white
 * background, although both color indicies are set to black.
 *
 */

#include <stdio.h>
#include "decw$include:xlib.h"
#include "decw$include:xutil.h"

/*
 * Constant data
 */

#define SQUARE_HEIGHT	8
#define SQUARE_WIDTH	16
#define NUMBER_ROWS	10
#define NUMBER_COLUMNS	10
#define NUMBER_SQUARES	NUMBER_ROWS * NUMBER_COLUMNS

Display			*display;	/* connection to the X server */
Window			window;		/* application window */
GC			gc;		/* g context for drawing ops */

main()
{
  Colormap		colormap;	/* application specific colormap */
  XEvent		event;		/* incoming events */
  XSetWindowAttributes	attr;		/* window attributes structure */

/*
 * Open the display
 */

  if ((display = XOpenDisplay("")) == NULL)
    fatalError("XOpenDisplay", "could not open display");

/*
 * Create a read/write colormap, with no entries allocated.
 */

  colormap = XDefaultColormap(display, XDefaultScreen(display));

/*
 * Create a window of the same visual type as our colormap
 */

  attr.event_mask = ExposureMask;
  attr.background_pixel = XBlackPixel(display, XDefaultScreen(display));

  window = XCreateWindow(display, RootWindow(display, 0), 0, 0,
			 NUMBER_COLUMNS * SQUARE_WIDTH,
			 NUMBER_ROWS * SQUARE_HEIGHT, 5, 
			 DefaultDepth(display, 0), InputOutput, 
			 DefaultVisual(display,0), 
			 CWEventMask | CWBackPixel, &attr);

/*
 * Map window
 */

  XMapWindow(display, window);
  XFlush(display);

/*
 * Create a GC for drawing operations
 */

gc = XCreateGC(display, window, 0, NULL);

/*
 * Process events
 */

  while(1) {
    XNextEvent(display, &event);
    switch(event.type) {
    case Expose:
      drawSquares(display, window, gc);
      break;
    default:
      break;
    }
  }
}

/*
 * Draw text in square
 */

drawSquares(display, window, gc)
Display	*display;
Window	window;
GC	gc;

{
  int	row, column, square;
  XFontStruct *our_font;

  if (our_font = XLoadQueryFont(display, "*COURIER_16*"))
    XSetFont(display, gc, our_font->fid);

  /*
   * Draw filled squares in different foreground colors
   */

  for (row = square = 0; row < NUMBER_ROWS; row++)
    for (column = 0; column < NUMBER_COLUMNS; column++, square++) {
      XSetForeground(display, gc, 0);
      XSetBackground(display, gc, 0);
      XDrawImageString(display, window, gc, column * 8, row * 16, "A", 1);
    }
}

/*
 * Something bad happened
 */

fatalError(string1, string2)
char *string1;
char *string2;

{
  fprintf(stderr, "Fatal Error: %s in routine %s\n", string1, string2);
  exit();
}
    
    

1017.2This might be part of the problemNEURON::NICHOLSONA belly as big as an oil spillMon Jun 26 1989 23:057
    On a GPX, 0 is NOT the pixel value for black.  You need to use 
    the macros blackpixel and whitepixel to get their pixel values
    on a GPX - I think that black and white are usually 253 & 254 (or
    something close).
    
    So your calls to XSetForeground and XSetBackground are incorrect.