home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / RAYCAST.ZIP / PALETTE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-15  |  2.7 KB  |  116 lines

  1. #include "os.h"
  2. #include "scrcntl.h"
  3. #include "palette.h"
  4. #include <mem.h>
  5. #include <stdlib.h>
  6.  
  7. pal_component pal_entries[MAX_PAL_ENTRIES * PAL_ENTRY_SIZE];
  8.  
  9. #ifdef OS_WINDOWS
  10. #include "winpal.h"
  11. HPALETTE hpalApp=NULL;
  12. RQBQUAD win_palette[MAX_PAL_ENTRIES];
  13. #endif
  14.  
  15. #ifdef OS_DOS
  16. #include "screen.h"
  17. #endif
  18.  
  19. void Init_Palette() {
  20.  
  21. memset(pal_entries, 0, (MAX_PAL_ENTRIES * PAL_ENTRY_SIZE));
  22.  
  23. #ifdef OS_WINDOWS
  24.    ClearSystemPalette();
  25. #endif
  26. }
  27.  
  28. void Load_Palette(palette_ptr new_palette, short start_pos, short num_entries) {
  29. int cur_color;
  30.  
  31. memcpy(pal_entries+(start_pos * PAL_ENTRY_SIZE), new_palette,
  32.         num_entries * PAL_ENTRY_SIZE);
  33.  
  34. #ifdef OS_WINDOWS
  35. //my palette vals are stored 0..64, but most systems except DOS are 0..256
  36. for (cur_color=start_pos; cur_color<(start_pos+num_entries); cur_color++) {
  37.    pal_entries[cur_color*PAL_ENTRY_SIZE]<<=2;
  38.    pal_entries[cur_color*PAL_ENTRY_SIZE+1]<<=2;
  39.    pal_entries[cur_color*PAL_ENTRY_SIZE+2]<<=2;
  40. } /* endfor */
  41. #endif
  42.  
  43. #ifdef OS_WINDOWS
  44. for (cur_color=0; cur_color<MAX_PAL_ENTRIES; cur_color++) {
  45.   win_palette[cur_color].rgbRed=pal_entries[cur_color*PAL_ENTRY_SIZE];
  46.   win_palette[cur_color].rgbBlue=pal_entries[cur_color*PAL_ENTRY_SIZE+1];
  47.   win_palette[cur_color].rgbGreen=pal_entries[cur_color*PAL_ENTRY_SIZE+2];
  48.   win_palette[cur_color].rgbReserved=0;
  49. } /* endfor */
  50.  
  51. if (hpalApp)
  52.    DeleteObject(hpalApp);
  53. hpalApp=CreateIdentityPalette(win_palette, MAX_PAL_ENTRIES);
  54.  
  55. #endif
  56. }
  57.  
  58. void Get_Palette(palette_ptr receive_palette, short start_pos, short num_entries) {
  59. memcpy(receive_palette, pal_entries+(start_pos * PAL_ENTRY_SIZE),
  60.         num_entries * PAL_ENTRY_SIZE);
  61. }
  62.  
  63. void Activate_Palette(BOOL active) {
  64. #ifdef OS_DOS
  65.    setpalette(pal_entries);
  66. #endif
  67.  
  68. #ifdef OS_WINDOWS
  69. // *** Remap the system colors and deal with the palette
  70.  
  71. AppActivate(active);
  72. if (hpalApp) {
  73.    UnrealizeObject(hpalApp);
  74.    SelectPalette(Get_Screen_Window(), hpalApp, FALSE);
  75.    RealizePalette(Get_Screen_Window());
  76.    }
  77.  
  78. #endif
  79. }
  80.  
  81. BOOL Update_Palette() {
  82. #ifdef OS_DOS
  83.    setpalette(pal_entries);
  84.    return TRUE;
  85. #endif
  86.  
  87. #ifdef OS_WINDOWS
  88. if (hpalApp)
  89.    SelectPalette(Get_Screen_Window(), hpalApp, FALSE);
  90. BOOL f=RealizePalette(Get_Screen_Window());
  91. return TRUE;
  92.  
  93. #endif
  94. }
  95.  
  96. void Close_Palette() {
  97. #ifdef OS_WINDOWS
  98.     if(hpalApp)
  99.     {
  100.         DeleteObject(hpalApp);
  101.     }
  102. #endif
  103. }
  104.  
  105. pal_component Get_Palette_Red_Val(short color_index) {
  106.    return pal_entries[color_index*PAL_ENTRY_SIZE];
  107. }
  108.  
  109. pal_component Get_Palette_Green_Val(short color_index) {
  110.    return pal_entries[color_index*PAL_ENTRY_SIZE+1];
  111. }
  112.  
  113. pal_component Get_Palette_Blue_Val(short color_index) {
  114.    return pal_entries[color_index*PAL_ENTRY_SIZE+2];
  115. }
  116.