TESTG.C 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <conio.h>
  16. #include <math.h>
  17. #include <dos.h>
  18. #include <string.h>
  19. #include <direct.h>
  20. #include "types.h"
  21. #include "gr.h"
  22. #include "key.h"
  23. #include "mono.h"
  24. #include "ui.h"
  25. #include "mem.h"
  26. #include "cflib.h"
  27. char TempFilename[100];
  28. extern int ui_button_any_drawn;
  29. UI_WINDOW * MainWindow;
  30. UI_GADGET_BUTTON * ColorButton[256];
  31. UI_GADGET_BUTTON * FadeButton[16];
  32. UI_GADGET_BUTTON * OrgFadeButton[16];
  33. UI_GADGET_BUTTON * QuitButton;
  34. UI_GADGET_BUTTON * SaveButton;
  35. UI_GADGET_BUTTON * CurrentColorButton;
  36. UI_GADGET_BUTTON * RestoreButton;
  37. UI_GADGET_BUTTON * RestoreAllButton;
  38. UI_GADGET_BUTTON * HelpButton;
  39. ubyte SavedFadeTable[256*16];
  40. int Changed=0;
  41. int CurrentFader = 0;
  42. int Mode = 0;
  43. int CurrentColor = 0;
  44. char MainHelpText[] = \
  45. "\nHELP\n" \
  46. "\nClick on any color to make it the\n" \
  47. "current color. Shift+click on the\n" \
  48. "fade bar assigns the current color\n" \
  49. "to the fade level you clicked on.\n" \
  50. "Shift+click on one of the 256 colors\n" \
  51. "at the bottom selects that color to\n" \
  52. "be the one on the fade bar at top." \
  53. "";
  54. void init_color_buttons()
  55. {
  56. int i,x,y,w,h;
  57. w = 320/16; h = 100/16;
  58. x = 0;
  59. y = 100;
  60. for (i=0; i<256; i++ ) {
  61. ColorButton[i]=ui_add_gadget_button( MainWindow, x, y, w, h, NULL, NULL );
  62. ColorButton[i]->canvas->cv_color = i;
  63. ColorButton[i]->status = 1;
  64. y+=h;
  65. if ( y > (199-h) ) {
  66. y = 100;
  67. x += w;
  68. }
  69. }
  70. x = 0; y = 0;
  71. for (i=0; i<16; i++ ) {
  72. OrgFadeButton[i]=ui_add_gadget_button( MainWindow, x, y, w, h, NULL, NULL );
  73. OrgFadeButton[i]->canvas->cv_color = i;
  74. OrgFadeButton[i]->status = 1;
  75. FadeButton[i]=ui_add_gadget_button( MainWindow, x+w, y, w, h, NULL, NULL );
  76. FadeButton[i]->canvas->cv_color = i;
  77. FadeButton[i]->status = 1;
  78. y += h;
  79. if ( y > (199-h) ) {
  80. y = 100;
  81. x += w;
  82. }
  83. }
  84. }
  85. void set_fade_buttons(int color)
  86. {
  87. int i;
  88. if (color < 0 ) color += 256;
  89. if (color > 255 ) color -= 256;
  90. CurrentFader = color;
  91. for (i=0; i<16; i++ ) {
  92. FadeButton[i]->canvas->cv_color = gr_fade_table[i*256+color];
  93. FadeButton[i]->status = 1;
  94. OrgFadeButton[i]->canvas->cv_color = SavedFadeTable[i*256+color];
  95. OrgFadeButton[i]->status = 1;
  96. }
  97. }
  98. void set_fade_color_to_current(int fade_level) {
  99. gr_fade_table[fade_level*256+CurrentFader ] = CurrentColor ;
  100. Changed = 1;
  101. FadeButton[fade_level]->canvas->cv_color = CurrentColor ;
  102. FadeButton[fade_level]->status = 1;
  103. }
  104. void outline_current_fader()
  105. {
  106. int color;
  107. UI_GADGET_BUTTON * button;
  108. ui_mouse_hide();
  109. button = ColorButton[CurrentFader];
  110. color = button->canvas->cv_color;
  111. gr_set_current_canvas( button->canvas );
  112. gr_setcolor( CBRIGHT );
  113. gr_box( 0, 0, button->width, button->height );
  114. button->canvas->cv_color = color;
  115. ui_mouse_show();
  116. }
  117. void outline_current_color()
  118. {
  119. int color;
  120. UI_GADGET_BUTTON * button;
  121. ui_mouse_hide();
  122. button = ColorButton[CurrentColor];
  123. color = button->canvas->cv_color;
  124. gr_set_current_canvas( button->canvas );
  125. gr_setcolor( CRED );
  126. gr_box( 0, 0, button->width, button->height );
  127. button->canvas->cv_color = color;
  128. ui_mouse_show();
  129. }
  130. void set_current_color( int color )
  131. {
  132. CurrentColor = color;
  133. CurrentColorButton->canvas->cv_color = CurrentColor;
  134. CurrentColorButton->status = 1;
  135. }
  136. void RestoreAll()
  137. {
  138. int i, j;
  139. for (i=0; i<256; i++ ) {
  140. for (j=0; j<16; j++ ) {
  141. gr_fade_table[256*j+i]=SavedFadeTable[256*j+i];
  142. if (i==CurrentFader) {
  143. FadeButton[j]->canvas->cv_color = gr_fade_table[256*j+i];
  144. FadeButton[j]->status = 1;
  145. }
  146. }
  147. }
  148. }
  149. void RestoreCurrent()
  150. {
  151. int j;
  152. for (j=0; j<16; j++ ) {
  153. gr_fade_table[256*j+CurrentFader]=SavedFadeTable[256*j+CurrentFader];
  154. FadeButton[j]->canvas->cv_color = gr_fade_table[256*j+CurrentFader];
  155. FadeButton[j]->status = 1;
  156. }
  157. }
  158. void SaveTables( )
  159. {
  160. WriteFile( "PALETTE.256", gr_palette, 256*3 );
  161. AppendFile( "PALETTE.256", gr_inverse_table, 32*32*32 );
  162. AppendFile( "PALETTE.256", gr_blend_table, 256*256 );
  163. AppendFile( "PALETTE.256", gr_fade_table, 256*16 );
  164. MessageBox( -2, -2, 1, "Palette saved successfully.", "Ok" );
  165. Changed = 0;
  166. }
  167. main()
  168. { int i,j, last_fader, last_color;
  169. grs_font * my_font;
  170. minit();
  171. gr_init( SM_320x200C );
  172. gr_use_palette_table( "PALETTE.256");
  173. for (i=0; i<256; i++ ) {
  174. gr_fade_table[15*256+i] = i; // Make all fades start at the right color
  175. for (j=0; j<16; j++ )
  176. SavedFadeTable[256*j+i] = gr_fade_table[256*j+i];
  177. }
  178. my_font = gr_init_font( "xm4x5.fnt" );
  179. ui_init();
  180. MainWindow = ui_open_window( 0 , 0, 320, 200, 0 );
  181. QuitButton = ui_add_gadget_button( MainWindow, 270, 0, 50, 10, "Exit", NULL );
  182. SaveButton = ui_add_gadget_button( MainWindow, 270, 10, 50, 10, "Save", NULL );
  183. RestoreAllButton = ui_add_gadget_button( MainWindow, 270, 20, 50, 10, "RestoreAll", NULL );
  184. HelpButton = ui_add_gadget_button( MainWindow, 270, 30, 50, 10, "Help", NULL ) ;
  185. CurrentColorButton = ui_add_gadget_button( MainWindow, 40, 0, 320/16, (100/16)*16, NULL, NULL );
  186. RestoreButton = ui_add_gadget_button( MainWindow, 70, 80, 40, 10, "Restore", NULL );
  187. init_color_buttons();
  188. set_fade_buttons(0);
  189. last_fader = last_color = -1;
  190. while ( 1 )
  191. {
  192. ui_button_any_drawn = 0;
  193. ui_mega_process();
  194. ui_window_do_gadgets(MainWindow);
  195. switch(last_keypress) {
  196. case KEY_UP:
  197. set_fade_buttons(CurrentFader-1);
  198. break;
  199. case KEY_DOWN:
  200. set_fade_buttons(CurrentFader+1);
  201. break;
  202. case KEY_LEFT:
  203. set_fade_buttons(CurrentFader-16);
  204. break;
  205. case KEY_RIGHT:
  206. set_fade_buttons(CurrentFader+16);
  207. break;
  208. case KEY_HOME:
  209. set_fade_buttons(0);
  210. break;
  211. case KEY_END:
  212. set_fade_buttons(255);
  213. break;
  214. }
  215. if (keyd_pressed[KEY_LSHIFT]) {
  216. for (i=0; i<256; i++ ) {
  217. if (ColorButton[i]->position>0 ) {
  218. set_fade_buttons(i);
  219. Mode = 0;
  220. }
  221. }
  222. for (i=0; i<15; i++ ) {
  223. if (FadeButton[i]->position>0 ) {
  224. set_fade_color_to_current(i);
  225. }
  226. }
  227. } else {
  228. for (i=0; i<256; i++ ) {
  229. if (ColorButton[i]->position>0) {
  230. set_current_color(i);
  231. }
  232. }
  233. for (i=0; i<16; i++ ) {
  234. if (FadeButton[i]->position>0 ) {
  235. set_current_color( FadeButton[i]->canvas->cv_color );
  236. }
  237. }
  238. }
  239. if (last_fader != CurrentFader) {
  240. if (last_fader >= 0 ) {
  241. ColorButton[last_fader]->status = 1;
  242. }
  243. outline_current_fader();
  244. last_fader = CurrentFader;
  245. }
  246. if (last_color != CurrentColor) {
  247. if (last_color >= 0 ) {
  248. ColorButton[last_color]->status = 1;
  249. }
  250. outline_current_color();
  251. last_color = CurrentColor;
  252. }
  253. if (ui_button_any_drawn) {
  254. outline_current_fader();
  255. outline_current_color();
  256. }
  257. if (RestoreButton->pressed )
  258. RestoreCurrent();
  259. if (RestoreAllButton->pressed )
  260. RestoreAll();
  261. if (SaveButton->pressed )
  262. SaveTables();
  263. if (QuitButton->pressed ) {
  264. if ( Changed == 1 ) {
  265. int choice;
  266. choice = MessageBox(-2,-2, 3, "Save palette?", "Yes", "No", "Cancel" );
  267. if (choice==2) break;
  268. if (choice==1) {
  269. SaveTables();
  270. break;
  271. }
  272. } else {
  273. break;
  274. }
  275. }
  276. if (HelpButton->pressed) {
  277. MessageBox( -2, -2, 1, MainHelpText, "Ok" );
  278. }
  279. }
  280. ui_close_window( MainWindow );
  281. return 0;
  282. }
  283.