tapio / rlutil

C and C++ utilities for cross-platform console roguelike game creation.
http://tapio.github.com/rlutil/
229 stars 42 forks source link

Background color #18

Closed Zorgatone closed 8 years ago

Zorgatone commented 8 years ago

Is there any support for background colors? If not, could we have it added? :smile:

nabijaczleweli commented 8 years ago

Let's see

Zorgatone commented 8 years ago

:smile: :+1:

nabijaczleweli commented 8 years ago

Please test the background-color branch on my fork

Zorgatone commented 8 years ago

Working fine on Windows' CMD. Tested on Windows 10, with raster fonts

Zorgatone commented 8 years ago

How do you reset the background color?

For me resetColor() is resetting the foreground color correctly. But when I cls() the screen after that reset, I still get the wrong background

Zorgatone commented 8 years ago

Example:

#include <stdio.h>
#include <stdlib.h>

#include "rlutil.h"

int main(void) {
    cls();

    saveDefaultColor(); // Saved GREY foreground

    /* Now I change foreground and background colors */
    setBackgroundColor(WHITE);
    setColor(BLACK);

    printf("Hello world!\n");

    getch();

    resetColor(); // Trying to reset the color (only Foreground is reset)

    cls(); // Here the CMD is GREY on WHITE instead of GREY on BLACK

    return 0;
}
nabijaczleweli commented 8 years ago

Interesting

Zorgatone commented 8 years ago

The CPP test seemed to work corretly though. Could it be just C?

Zorgatone commented 8 years ago

Oh nevermind. That was because you were resetting it explicitly to black again

nabijaczleweli commented 8 years ago

I forgot to reset all attributes in resetColor(), your example works now

Zorgatone commented 8 years ago

Good I'll try tomorrow :smile:

nabijaczleweli commented 8 years ago

Windows fix pushed, still not sure if works with ANSI

nabijaczleweli commented 8 years ago

Fixed, submitting a PR

tapio commented 8 years ago

Closing, since nabijaczleweli's implementation is merged to master.