User Tools

Site Tools


c:graphics.h:setallpalette

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:graphics.h:setallpalette [2015/05/06 23:06] (current)
Line 1: Line 1:
 +===== setallpalette =====
 +
 +
 +====Syntax of setallpalette ==== 
 + <code c>
 +#include <graphics.h>
 +void setallpalette(struct palettetype *palette);
 +  </code>
 +
 +
 +==== Description of setallpalette ==== 
 +<code c>
 +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 MAXCOLORS constant 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 which are defined in graphics.h. See Actual Color
 +Table given here:
 +Name Value
 +BLACK0
 +BLUE 1
 +GREEN2
 +CYAN 3
 +RED  4
 +MAGENTA    5
 +BROWN6
 +LIGHTGRAY  7
 +DARKGRAY   8
 +LIGHTBLUE  9
 +LIGHTGREEN 10
 +LIGHTCYAN  11
 +LIGHTRED   12
 +LIGHTMAGENTA     13
 +YELLOW     14
 +WHITE15
 +EGA_BROWN  20
 +EGA_DARKGRAY     56
 +EGA_LIGHTBLUE    57
 +EGA_LIGHTGREEN   58
 +EGA_LIGHTCYAN    59
 +EGA_LIGHTRED     60
 +EGA_LIGHTMAGENTA 61
 +EGA_YELLOW 62
 +EGA_WHITE  63
 +Changes made to the palette are seen immediately onscreen. Each time a
 +palette color is changed, all occurrences of that color onscreen change
 +to the new color value.
 +Note: Valid colors depend on the current graphics driver and current
 +graphics mode.
 +setallpalette cannot be used with the IBM-8514 driver.
 +</code>
 +
 +
 +==== Example of setallpalette ====
 +<code c>
 +
 +  See also
 +_getpalette_
 +_getpalettesize_
 +_graphresult_
 +_setbkcolor_
 +_setcolor_
 +_setpalette_
 +
 +
 +==== Example of setallpalette ====
 +<code c>
 +
 +/* setallpalette 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:");
 +getch();
 +exit(1);   /* 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=1; color<=maxcolor; color++) {
 +setcolor(color);
 +sprintf(msg, "Color: %d", color);
 +
 +outtextxy(1, y, msg);
 +y += ht;
 +   }
 +
 +   /* wait for a key */
 +   getch();
 +
 +   /* black out the colors one by one */
 +   for (color=1; color<=maxcolor; color++) {
 +setpalette(color, BLACK);
 +getch();
 +   }
 +
 +   /* restore the palette colors */
 +   setallpalette(&pal);
 +
 +   /* clean up */
 +   getch();
 +   closegraph();
 +   return 0;
 +}
 +</code>
 +
 +
 +==== See also ====
 +[[getpalette]]
 +[[getpalettesize]]
 +[[graphresult]]
 +[[setbkcolor]]
 +[[setcolor]]
 +[[setpalette]]
 +==== See also ====
 +[[_getpalette_]]
 +[[_getpalettesize_]]
 +[[_graphresult_]]
 +[[_setbkcolor_]]
 +[[_setcolor_]]
 +[[_setpalette_]]
 +
 +
 +
 +
 +===== output of setallpalette example ===== 
 +
 +    no output of example at the moment
 +    do not hesitate and add it...  
 +
 +
  
advertising
c/graphics.h/setallpalette.txt · Last modified: 2015/05/06 23:06 (external edit)

Impressum Datenschutz