Author Topic: Curses - Issue with init_color  (Read 7297 times)

addtheninth

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Email
Curses - Issue with init_color
« on: January 25, 2009, 06:52:33 PM »
Hi Everyone  ;D

Firstly, I'm new to the boards, so wanted to say hi.  It's great to find a community like this.

I'm new to RL's (always wanted to make one) and have only recently started programming in C++ again (first time in 10+ years...coming from Java and IBM RPG).

I'm currently having an issue with the curse function init_color.

Per the header and all documentation I've found, this is supposed to let me manually set the RGB of a color for use.

For instance, I'm aiming for a grayish color, so am attempting to use:
init_color(COLOR_BLACK, 100, 100, 100);


However, the color's staying solid black whenever I use the new value in an init pair.  Am I missing something, or am I just using this function completely wrong?

I read somewhere about possibly recompiling my curses library to support all colors, but I'm not quite sure what parms I should be passing/how I should go about doing this.

I'm currently coding in CodeBlocks using Ming32 on a Vista system.  If anyone has any insight, I'd appreciate the help ;)

Thanks!

stu

  • Rogueliker
  • ***
  • Posts: 138
  • Karma: +0/-0
  • Moop!
    • View Profile
    • Stu's Rusty Bucket
Re: Curses - Issue with init_color
« Reply #1 on: January 26, 2009, 01:16:13 PM »
Quote
If a terminal is capable of redefining colors, the programmer can use the routine init_color to change  the  definition  of  a  color.

keyword here being _IF_. It is not garunteed to support it. and I'd wager outside of an 256 color xterm it probably wont be supported.

init_color will return an error if its unsupported so you can always check that, if no error is returned maybe something else is wrong.

are you correctly doing init_pairs as well?

--/\-[ Stu ]-/\--

addtheninth

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Email
Re: Curses - Issue with init_color
« Reply #2 on: January 26, 2009, 10:35:13 PM »
Quote
If a terminal is capable of redefining colors, the programmer can use the routine init_color to change  the  definition  of  a  color.

keyword here being _IF_. It is not garunteed to support it. and I'd wager outside of an 256 color xterm it probably wont be supported.

init_color will return an error if its unsupported so you can always check that, if no error is returned maybe something else is wrong.

are you correctly doing init_pairs as well?



I've already tested the console to confirm that it supports redefining colors.  I'm not getting an error thrown when I try to do it.

My init_pairs are as follows:
Code: [Select]
    init_pair(0, COLOR_BLACK, COLOR_BLACK);
    init_pair(1, COLOR_RED, COLOR_BLACK);
    init_pair(2, COLOR_GREEN, COLOR_BLACK);
    init_pair(3, COLOR_YELLOW, COLOR_BLACK);
    init_pair(4, COLOR_BLUE, COLOR_BLACK);
    init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
    init_pair(6, COLOR_CYAN, COLOR_BLACK);
    init_pair(7, COLOR_WHITE, COLOR_BLACK);
    init_pair(8, COLOR_GREEN, COLOR_BLACK);

I'll then use attron(COLOR_PAIR(n)); to turn on whatever color I want to use.
i.e. -
Code: [Select]
attron(COLOR_PAIR(0)); // turns on black/black

Cymon

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
  • Reviving the Type-Ins of Old
    • View Profile
    • Cymon's Games
    • Email
Re: Curses - Issue with init_color
« Reply #3 on: March 05, 2009, 07:16:05 PM »
My init_pairs are as follows:
Code: [Select]
    init_pair(0, COLOR_BLACK, COLOR_BLACK);
    init_pair(1, COLOR_RED, COLOR_BLACK);
    init_pair(2, COLOR_GREEN, COLOR_BLACK);
    init_pair(3, COLOR_YELLOW, COLOR_BLACK);
    init_pair(4, COLOR_BLUE, COLOR_BLACK);
    init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
    init_pair(6, COLOR_CYAN, COLOR_BLACK);
    init_pair(7, COLOR_WHITE, COLOR_BLACK);
    init_pair(8, COLOR_GREEN, COLOR_BLACK);

I'll then use attron(COLOR_PAIR(n)); to turn on whatever color I want to use.
i.e. -
Code: [Select]
attron(COLOR_PAIR(0)); // turns on black/black
That's about right, tho if I were you I'd change the init pair to something like this:
Code: [Select]
for (c = 0; c < COLORS; c++)
  init_pair(c, c, COLOR_BLACK);

Then when you init you can actually init with:

Code: [Select]
attron(COLOR_PAIR(COLOR_BLUE));
replacing with whatever color you want. There's one small caveat in that on PDCurses you'll initialize 16 colors, where as on nCurses you'll only initialize 8, but the naming will still work the same, and if you just stick to them you can maintain cross-platform compatibility.

I've actually considered extending this sort of functionality so that you can get the background colors in there too by multiplying the background color by COLORS.

Now as for defining other colors, I've never tried using init_colors. Maybe I'll have to play with that one.
A new game every week. Please visit Cymon's Games!