This shows you the differences between two versions of the page.
c:graphics.h:getpalette [2015/05/06 23:06] |
c:graphics.h:getpalette [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== getpalette ===== | ||
+ | |||
+ | |||
+ | ====Syntax of getpalette ==== | ||
+ | <code c> | ||
+ | #include <graphics.h> | ||
+ | void getpalette(struct palettetype *palette); | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== Description of getpalette ==== | ||
+ | <code c> | ||
+ | getpalette fills the palettetype structure pointed to by palette with | ||
+ | information about the current palette's size and colors. | ||
+ | The MAXCOLORS constant and the palettetype structure used by getpalette | ||
+ | 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. | ||
+ | getpalette cannot be used with the IBM-8514 driver. | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== Example of getpalette ==== | ||
+ | <code c> | ||
+ | /* getpalette example */ | ||
+ | |||
+ | #include <graphics.h> | ||
+ | #include <stdlib.h> | ||
+ | #include <stdio.h> | ||
+ | #include <conio.h> | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | |||
+ | /* request autodetection */ | ||
+ | int gdriver = DETECT, gmode, errorcode; | ||
+ | struct palettetype pal; | ||
+ | char psize[80], pval[20]; | ||
+ | int i, ht; | ||
+ | int y = 10; | ||
+ | |||
+ | /* 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 */ | ||
+ | } | ||
+ | |||
+ | /* grab a copy of the palette */ | ||
+ | getpalette(&pal); | ||
+ | |||
+ | /* convert palette info into strings */ | ||
+ | sprintf(psize, "The palette has %d modifiable entries.", pal.size); | ||
+ | |||
+ | /* display the information */ | ||
+ | outtextxy(0, y, psize); | ||
+ | if (pal.size != 0) { | ||
+ | ht = textheight("W"); | ||
+ | |||
+ | y += 2*ht; | ||
+ | outtextxy(0, y, "Here are the current values:"); | ||
+ | y += 2*ht; | ||
+ | for (i=0; i<pal.size; i++, y+=ht) { | ||
+ | sprintf(pval, "palette[%02d]: 0x%02X", i, pal.colors[i]); | ||
+ | outtextxy(0, y, pval); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /* clean up */ | ||
+ | getch(); | ||
+ | closegraph(); | ||
+ | return 0; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== See also ==== | ||
+ | [[getbkcolor]] | ||
+ | [[getcolor]] | ||
+ | [[getdefaultpalette]] | ||
+ | [[getmaxcolor]] | ||
+ | [[setallpalette]] | ||
+ | [[setpalette]] | ||
+ | |||
+ | |||
+ | ===== output of getpalette example ===== | ||
+ | |||
+ | no output of example at the moment | ||
+ | do not hesitate and add it... | ||
+ | |||
+ | |||