Color problems

Help
2008-06-07
2013-04-25
  • Hi all!

    Were there any changes between PDCurses 2.8 and 3.x, that would cause wrong colors (on Win32)? With PDC28 all is fine, but with PDC30 or later everything looks so bluish. Here's the source code module I'm talking about: http://bochs.cvs.sourceforge.net/bochs/bochs/gui/term.cc?view=markup

     
    • It looks like it uses COLORS when initializing the table with init_pair(), but then implicitly assumes that COLORS == 8, by doing a "<< 3", in get_color_pair(). That's wrong -- COLORS is usually 16 in PDCurses 3.x.

      There are several ways to fix this, but for your purposes, I'd just replace the references to "COLORS" in specific_init() with 8.

       
      • Thanks! This works nice for me.

        Do you also have an idea why we have troubles with Alt-key combinations? Please see <http://sourceforge.net/mailarchive/forum.php?thread_name=4846FE26.6E4E2CD4%40bttr-software.de&forum_name=bochs-developers> for a description of the problem.

         
    • First, a comment on this:

      "But I don't know how this influences targets other than Win32."

      The current code is simply wrong, for all platforms. Either COLORS is 8, in which case, the use of "COLORS" abstracts nothing; or COLORS is not 8, in which case its use here, in combination with the "<< 3", is a disaster.

      The table, curses_color[], has eight entries (the eight symbolic color names), and never has any other number. get_color_pair(), likewise, never extracts anything but one of eight colors from each half of the VGA attribute. So there is no reason to use COLORS here.

      As for the ALT keys, yeah, it looks like you'd need to add a block in do_char() to handle PDCurses-specific keys. The current code appears to be ncurses-oriented.

      The way ALT keys are handled in PDCurses is not ideal, but it's a backwards compatibility issue.

       
    • Bruce Gray
      Bruce Gray
      2008-07-29

      New member here.  Since this topic already exists, I have a new question about color...

      I wrote a program under Linux that displays a grid of values based on data coming in from a USB interface.  The values can be displayed in one of three formats and I set up a color pair for each one (see code snippet below).  This works as expected.  The text is displayed in color on a white background.

      I then ported this program to WIN32 (using DEV-C++ with pdcurses 3.2 added).  When I run this program, I get white text on a black background for the labels and the values in the grid look grayish.  The colors do not change if I select the different formats as they did under Linux.

      I've done a lot of poking around trying to understand what's going on, but I haven't found the answer.  Can someone in this forum point me to the right place to understand the difference between a console terminal under Linux and a console application under WIN32?

      Thanks,
      Bruce

      Here's the relevant code:

          WINDOW *scrn;
          int i, j, n;
          int maxy, maxx;
          int savey, savex;
          int ncols, nrows;

          // Initialize curses
          scrn = initscr();
          start_color();
          assume_default_colors(-1, -1);
          init_pair(1, COLOR_MAGENTA, -1);   // Label color
          init_pair(2, COLOR_BLUE, -1);      // Decimal values color
          init_pair(3, COLOR_GREEN, -1);     // Percent values color
          init_pair(4, COLOR_RED, -1);       // Hex values color
          noecho();
          raw();
          nodelay(scrn, TRUE);
          clear();
          getmaxyx(scrn, maxy, maxx);
          ncols = (maxx - COL1_OFFSET)/DMX_CELL_SIZE;
          if (ncols > MAX_COLS) {
              ncols = MAX_COLS;
          }
          nrows = DISP_UNIV_SIZE/ncols;
          if (nrows > (maxy - ROW1_OFFSET -1)) {
              nrows = maxy - ROW1_OFFSET - 1;
          }
         
          move(nrows + ROW1_OFFSET,0);
          printw("p = percent, d = decimal, h = hex, x = exit");
          getyx(scrn, savey, savex);
         
          // Print out column and row labels
          attron(A_UNDERLINE | A_BOLD | COLOR_PAIR(1));
          for (i=0; i < ncols; i++) {
              move(0,i*DMX_CELL_SIZE+COL1_OFFSET);
              printw(" %03i",i);
          }
         
          attroff(A_UNDERLINE);
          for (i=0; i < nrows; i++) {
              move(i+ROW1_OFFSET,0);
              printw("%03i",(i*ncols)+1);
          }
         
          // Assume decimal as default
          attroff(A_BOLD);
          attron(COLOR_PAIR(2));
          move(0,0);
          printw("DEC");
          refresh();

       
    • You should call use_default_colors() instead of assume_default_colors(-1, -1). PDCurses will not recognize -1 as a valid color until you do. (To ncurses, the calls are equivalent.)

       
    • Bruce Gray
      Bruce Gray
      2008-08-01

      Thanks William, that did it.  However, I found that I also have to use attron(A_BOLD) in order to see the text in color, otherwise it looks like I get the default foreground color (in my case, black) and the COLOR_PAIR(n) attribute is ignored.

      Bruce