MENUBAR1.C 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. /*
  14. * $Source: $
  15. * $Revision: $
  16. * $Author: $
  17. * $Date: $
  18. *
  19. * .
  20. *
  21. * $Log: $
  22. *
  23. */
  24. #pragma off (unreferenced)
  25. static char rcsid[] = "$Id: $";
  26. #pragma on (unreferenced)
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "mem.h"
  30. #include "fix.h"
  31. #include "types.h"
  32. #include "gr.h"
  33. #include "ui.h"
  34. #include "key.h"
  35. typedef struct {
  36. short x, y, w, h;
  37. char * text;
  38. short level;
  39. short item;
  40. short nextlevel;
  41. short active;
  42. short displayed;
  43. short isdisplayed;
  44. short hotkey;
  45. grs_bitmap * background;
  46. } MITEM;
  47. MITEM MenuSystem[] = { \
  48. { 0, 0, 40, 20, "&File", 0, 0, 1, 0,0,0,0, NULL},
  49. { 0, 20, 90, 20, "&New", 1, 0, -1, 0,0,0,0, NULL },
  50. { 0, 40, 90, 20, "&Open", 1, 1, -1, 0,0,0,0, NULL },
  51. { 0, 60, 90, 20, "&Merge", 1, 2, -1, 0,0,0,0, NULL },
  52. { 0, 80, 90, 20, "E&xit", 1, 3, -1, 0,0,0,0, NULL },
  53. { 40, 0, 40, 20, "&Edit", 0, 1, 2, 0,0,0,0, NULL},
  54. { 40, 20, 90, 20, "&Cut", 2, 0, -1, 0,0,0,0, NULL },
  55. { 40, 40, 90, 20, "C&opy", 2, 1, -1, 0,0,0,0, NULL },
  56. { 40, 60, 90, 20, "&Past", 2, 2, -1, 0,0,0,0, NULL },
  57. { 80, 0, 40, 20, "&View", 0, 2, 3, 0,0,0,0, NULL },
  58. { 80, 20, 90, 20, "&All", 3, 0, -1, 0,0,0,0, NULL },
  59. { 80, 40, 90, 20, "&Some", 3, 1, -1, 0,0,0,0, NULL },
  60. { 80, 60, 90, 20, "&Few", 3, 2, -1, 0,0,0,0, NULL } };
  61. static int show_citem[10];
  62. static int citem[10];
  63. static int num_items = 13;
  64. static int level = -1;
  65. static int state;
  66. void menubar_draw(int i)
  67. {
  68. int w = MenuSystem[i].w;
  69. int h = MenuSystem[i].h;
  70. int x = MenuSystem[i].x;
  71. int y = MenuSystem[i].y;
  72. if (MenuSystem[i].displayed != MenuSystem[i].isdisplayed )
  73. {
  74. if ( MenuSystem[i].isdisplayed )
  75. {
  76. gr_bm_ubitblt(w, h, x, y, 0, 0, MenuSystem[i].background, &(grd_curscreen->sc_canvas.cv_bitmap));
  77. } else {
  78. gr_bm_ubitblt(w, h, 0, 0, x, y, &(grd_curscreen->sc_canvas.cv_bitmap), MenuSystem[i].background);
  79. }
  80. MenuSystem[i].isdisplayed = MenuSystem[i].displayed;
  81. }
  82. if (MenuSystem[i].displayed)
  83. {
  84. gr_set_current_canvas( NULL );
  85. if (citem[MenuSystem[i].level] == MenuSystem[i].item && show_citem[MenuSystem[i].level])
  86. gr_set_fontcolor( CWHITE, CBLACK );
  87. else
  88. gr_set_fontcolor( CBLACK, CGREY );
  89. gr_ustring( x, y, MenuSystem[i].text );
  90. }
  91. }
  92. void show_level( int level )
  93. {
  94. int i;
  95. for (i=0; i< num_items; i++ )
  96. if (MenuSystem[i].level == level)
  97. MenuSystem[i].displayed = 1;
  98. }
  99. void hide_level( int level )
  100. {
  101. int i;
  102. for (i=0; i< num_items; i++ )
  103. if (MenuSystem[i].level == level)
  104. MenuSystem[i].displayed = 0;
  105. }
  106. void deactive_level( int level )
  107. {
  108. int i;
  109. for (i=0; i< num_items; i++ )
  110. if (MenuSystem[i].level == level)
  111. MenuSystem[i].active = 0;
  112. }
  113. static state2_alt_down;
  114. static state3_alt_down;
  115. void menubar_do( int keypress )
  116. {
  117. int i;
  118. switch(state)
  119. {
  120. case 0:
  121. if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] )
  122. {
  123. state = 1;
  124. show_citem[0] = 0;
  125. show_level(0);
  126. deactive_level( 0 );
  127. }
  128. break;
  129. case 1:
  130. if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] )
  131. {
  132. state = 2;
  133. state2_alt_down = 0;
  134. show_citem[0] = 1;
  135. }
  136. break;
  137. case 2:
  138. if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] )
  139. state2_alt_down = 1;
  140. if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] && state2_alt_down )
  141. {
  142. state = 0;
  143. hide_level(0);
  144. hide_level(1);
  145. hide_level(2);
  146. hide_level(3);
  147. break;
  148. }
  149. if (keypress==KEY_ESC)
  150. {
  151. state = 0;
  152. hide_level(0);
  153. hide_level(1);
  154. hide_level(2);
  155. hide_level(3);
  156. break;
  157. }
  158. if (keypress==KEY_LEFT)
  159. citem[0]--;
  160. if (keypress==KEY_RIGHT)
  161. citem[0]++;
  162. if (keypress==KEY_ENTER || keypress==KEY_DOWN )
  163. {
  164. state3_alt_down = 0;
  165. state = 3;
  166. show_level( citem[0]+1 );
  167. show_citem[ citem[0]+1 ] = 1;
  168. }
  169. break;
  170. case 3:
  171. if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] )
  172. state3_alt_down = 1;
  173. if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] && state3_alt_down )
  174. {
  175. hide_level( citem[0]+1 );
  176. state = 2;
  177. break;
  178. }
  179. if (keypress==KEY_ESC)
  180. {
  181. state = 0;
  182. hide_level(0);
  183. hide_level(1);
  184. hide_level(2);
  185. hide_level(3);
  186. }
  187. if (keypress==KEY_DOWN)
  188. citem[ citem[0]+1 ]++;
  189. if (keypress==KEY_UP)
  190. citem[ citem[0]+1 ]--;
  191. if (keypress==KEY_RIGHT )
  192. {
  193. hide_level( citem[0]+1 );
  194. for (i=0; i<num_items;i++ )
  195. menubar_draw(i);
  196. citem[0]++;
  197. show_citem[ citem[0]+1 ] = 1;
  198. show_level( citem[0]+1 );
  199. }
  200. if (keypress==KEY_LEFT )
  201. {
  202. hide_level( citem[0]+1 );
  203. for (i=0; i<num_items;i++ )
  204. menubar_draw(i);
  205. citem[0]--;
  206. show_citem[ citem[0]+1 ] = 1;
  207. show_level( citem[0]+1 );
  208. }
  209. break;
  210. default:
  211. state = 0;
  212. }
  213. for (i=0; i<num_items;i++ )
  214. menubar_draw(i);
  215. }
  216. void menubar_init()
  217. {
  218. int i;
  219. state = 0;
  220. citem[0] = 0;
  221. citem[1] = 0;
  222. citem[2] = 0;
  223. citem[3] = 0;
  224. show_citem[0] = 0;
  225. show_citem[1] = 0;
  226. show_citem[2] = 0;
  227. show_citem[3] = 0;
  228. for (i=0; i< num_items; i++ )
  229. {
  230. MenuSystem[i].background = gr_create_bitmap( MenuSystem[i].w, MenuSystem[i].h );
  231. menubar_draw(i);
  232. }
  233. }
  234. void menubar_close()
  235. {
  236. int i;
  237. for (i=0; i< num_items; i++ )
  238. {
  239. MenuSystem[i].displayed = 0;
  240. menubar_draw(i);
  241. gr_free_bitmap( MenuSystem[i].background );
  242. }
  243. }
  244.