Borland C++ reference

setallpalette

raw OCR

Changes all palette colors as specified.

Defined in header <graphics.h>

Syntax

#include <graphics.h>
void far setallpalette(struct palettetype far*palette);

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

setallpalette sets the current palette to the values given in the palettetype structure pointed to by palette.

You can partially (or completely) change the colors in the EGA/VGA palette with setallpalette.

The MAXCOLORSconstant and the palettetype structure used by

setallpalette are defined in graphics.h as follows:

#define MAXCOLORS 15

struct palettetype { unsigned char size;

signed char colors[MAXCOLORS-+ 1];

size gives the number of colors in the palette for the current graphics driver in the current mode.

colors is an array of size bytes containing the actual raw color numbers for each entry in the palette. If an element of colors is -1, the palette color for that entry is not changed.

The elements in the colors array used by setallpalette can be represented by symbolic constants defined in graphics.h.

Table 2.6

CGAEGA/VGA

Actual color table

NameValueNameValue
BLACK0EGA BLACK0
BLUE1EGA BLUE1
GREEN2EGA GREEN2
CYAN3EGA CYAN3
RED4EGA RED4
MAGENTA5EGA MAGENTA5
BROWN6EGA LIGHTGRAY7
LIGHTGRAY7EGA BROWN20
DARKGRAY8EGA DARKGRAY56
LIGHTBLUE9EGA LIGHTBLUE57
LIGHTGREEN10EGA LIGHTGREEN58
LIGHTCYAN11EGA LIGHTCYAN59
LIGHTRED12EGA LIGHTRED60
LIGHTMAGENTA13EGA LIGHTMAGENTA61
YELLOW14EGA YELLOW62
WHITE15EGA WHITE63

Note that valid colors depend on the current graphics driver and current graphics mode.

Changes made to the palette are seen immediately onscreen. Each time a palette color is changed, all occurrences of that color onscreen will change to the new color value.

setallpalette cannot be used with the IBM-8514 driver.

Return value

If invalid input is passed to setallpalette, graphresult returns -11 (grError), and the current palette remains unchanged.

See also

Example

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

int main(void)
{ ■
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode;
   struct palettetype pal;
   int color, maxcolor, ht;
   int y = 10;
   char msg[80];

   /* initialize graphics and local variables  */
   initgraph(&gdriver, &gmode,  "");

   /* read result of initialization */
   errorcode = graphresult ();
   if (errorcode != grOk)    /* an error occurred  */
   {
      printf("Graphics error: %s\n", grapherrormsg (errorcode));
      printf("Press any key to halt:");
      getchO ;
      exit(l);               /* terminate with  an error code */
   }
   maxcolor = getmaxcolor ();
   ht = 2 * textheight("W");
   /* grab a copy of the palette */
   getpalette(&pal);
   /* display the default palette colors  */
   for (color=l; 'color<=maxcolor; color++) {
      setcolor(color);
      sprintf(msg, "Color: %d", color);
      outtextxy(l, y, msg);
      y += ht;
   }
   /* wait for a key */
   getchO ;

   /* black out the colors one by one  */
   for (color=l; color<=maxcolor; color++)  {
      setpalette(color, BLACK);
      getchO ;
   }
   /* restore the palette colors */
   setallpalette(&pal);

   /* clean up */
   getchO ;
   closegraphO ;
return

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.