MENU.C 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: f:/miner/source/ui/rcs/menu.c $
  15. * $Revision: 1.5 $
  16. * $Author: john $
  17. * $Date: 1994/11/18 23:07:19 $
  18. *
  19. * Routines for doing popup menus.
  20. *
  21. * $Log: menu.c $
  22. * Revision 1.5 1994/11/18 23:07:19 john
  23. * Changed a bunch of shorts to ints.
  24. *
  25. * Revision 1.4 1993/12/07 12:30:24 john
  26. * new version.
  27. *
  28. * Revision 1.3 1993/10/26 13:46:18 john
  29. * *** empty log message ***
  30. *
  31. * Revision 1.2 1993/10/05 17:31:25 john
  32. * *** empty log message ***
  33. *
  34. * Revision 1.1 1993/09/20 10:35:16 john
  35. * Initial revision
  36. *
  37. *
  38. */
  39. #pragma off (unreferenced)
  40. static char rcsid[] = "$Id: menu.c 1.5 1994/11/18 23:07:19 john Exp $";
  41. #pragma on (unreferenced)
  42. #include <stdlib.h>
  43. #include "mem.h"
  44. #include "fix.h"
  45. #include "types.h"
  46. #include "gr.h"
  47. #include "ui.h"
  48. #define MENU_BORDER 2
  49. #define MENU_VERT_SPACING 2
  50. int MenuX( int x, int y, int NumButtons, char * text[] )
  51. {
  52. UI_WINDOW * wnd;
  53. UI_GADGET_BUTTON ** ButtonG;
  54. char ** Button;
  55. int button_width, button_height, width, height;
  56. int i;
  57. int w, h;
  58. int choice;
  59. ButtonG = (UI_GADGET_BUTTON **)malloc( sizeof(UI_GADGET_BUTTON *)*NumButtons );
  60. Button = (char **)malloc( sizeof(char *)*NumButtons );
  61. button_width = button_height = 0;
  62. for (i=0; i<NumButtons; i++ )
  63. {
  64. Button[i] = text[i];
  65. ui_get_button_size( Button[i], &width, &height );
  66. if ( width > button_width ) button_width = width;
  67. if ( height > button_height ) button_height = height;
  68. }
  69. width = button_width + 2*(MENU_BORDER+3);
  70. height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
  71. height += (MENU_BORDER+3) * 2;
  72. w = grd_curscreen->sc_w;
  73. h = grd_curscreen->sc_h;
  74. if ( x == -1 ) x = Mouse.x - width/2;
  75. if ( y == -1 ) y = Mouse.y;
  76. if (x < 0 ) {
  77. x = 0;
  78. }
  79. if ( (x+width-1) >= w ) {
  80. x = w - width;
  81. }
  82. if (y < 0 ) {
  83. y = 0;
  84. }
  85. if ( (y+height-1) >= h ) {
  86. y = h - height;
  87. }
  88. wnd = ui_open_window( x, y, width, height, WIN_FILLED | WIN_SAVE_BG );
  89. x = MENU_BORDER+3;
  90. y = MENU_BORDER+3;
  91. for (i=0; i<NumButtons; i++ )
  92. {
  93. ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
  94. y += button_height+MENU_VERT_SPACING;
  95. }
  96. choice = 0;
  97. while(choice==0)
  98. {
  99. ui_mega_process();
  100. ui_window_do_gadgets(wnd);
  101. for (i=0; i<NumButtons; i++ )
  102. {
  103. if (ButtonG[i]->pressed) {
  104. choice = i+1;
  105. break;
  106. }
  107. }
  108. if ( (choice==0) && B1_JUST_RELEASED ) {
  109. choice = -1;
  110. break;
  111. }
  112. }
  113. ui_close_window(wnd);
  114. free(Button);
  115. free(ButtonG);
  116. return choice;
  117. }
  118.