MESSAGE.C 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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/message.c $
  15. * $Revision: 1.8 $
  16. * $Author: john $
  17. * $Date: 1994/11/18 23:07:31 $
  18. *
  19. * Routines for doing a popup messagebox
  20. *
  21. * $Log: message.c $
  22. * Revision 1.8 1994/11/18 23:07:31 john
  23. * Changed a bunch of shorts to ints.
  24. *
  25. * Revision 1.7 1994/06/09 12:18:31 john
  26. * Took out keyboard flushes.
  27. *
  28. * Revision 1.6 1994/01/10 16:24:37 john
  29. * Fixed bug in 800x600 mode with restoring
  30. * bogus font.
  31. *
  32. * Revision 1.5 1994/01/10 15:10:34 john
  33. * made messagebox use smallfont in modes with
  34. * with < 640.
  35. *
  36. * Revision 1.4 1993/12/07 12:30:00 john
  37. * new version.
  38. *
  39. * Revision 1.3 1993/10/26 13:46:01 john
  40. * *** empty log message ***
  41. *
  42. * Revision 1.2 1993/10/05 17:31:29 john
  43. * *** empty log message ***
  44. *
  45. * Revision 1.1 1993/09/20 10:35:22 john
  46. * Initial revision
  47. *
  48. *
  49. */
  50. #pragma off (unreferenced)
  51. static char rcsid[] = "$Id: message.c 1.8 1994/11/18 23:07:31 john Exp $";
  52. #pragma on (unreferenced)
  53. #include <stdio.h>
  54. #include <stdarg.h>
  55. #include "fix.h"
  56. #include "types.h"
  57. #include "gr.h"
  58. #include "ui.h"
  59. #include "key.h"
  60. // ts = total span
  61. // w = width of each item
  62. // n = number of items
  63. // i = item number (0 based)
  64. #define EVEN_DIVIDE(ts,w,n,i) ((((ts)-((w)*(n)))*((i)+1))/((n)+1))+((w)*(i))
  65. #define BUTTON_HORZ_SPACING 20
  66. #define TEXT_EXTRA_HEIGHT 5
  67. int MessageBoxN( short xc, short yc, int NumButtons, char * text, char * Button[] )
  68. {
  69. grs_font * temp_font;
  70. UI_WINDOW * wnd;
  71. UI_GADGET_BUTTON * ButtonG[10];
  72. int i, width, height, avg, x, y;
  73. int button_width, button_height, text_height, text_width;
  74. int w, h;
  75. int choice;
  76. if ((NumButtons < 1) || (NumButtons>10)) return -1;
  77. button_width = button_height = 0;
  78. gr_set_current_canvas( &grd_curscreen->sc_canvas );
  79. w = grd_curscreen->sc_w;
  80. h = grd_curscreen->sc_h;
  81. temp_font = grd_curscreen->sc_canvas.cv_font;
  82. if ( w < 640 ) {
  83. grd_curscreen->sc_canvas.cv_font = ui_small_font;
  84. }
  85. for (i=0; i<NumButtons; i++ )
  86. {
  87. ui_get_button_size( Button[i], &width, &height );
  88. if ( width > button_width ) button_width = width;
  89. if ( height > button_height ) button_height = height;
  90. }
  91. gr_get_string_size(text, &text_width, &text_height, &avg );
  92. width = button_width*NumButtons;
  93. width += BUTTON_HORZ_SPACING*(NumButtons+1);
  94. width ++;
  95. text_width += avg*6;
  96. text_width += 10;
  97. if (text_width > width )
  98. width = text_width;
  99. height = text_height;
  100. height += button_height;
  101. height += 4*TEXT_EXTRA_HEIGHT;
  102. height += 2; // For line in middle
  103. if ( xc == -1 )
  104. xc = Mouse.x;
  105. if ( yc == -1 )
  106. yc = Mouse.y - button_height/2;
  107. if ( xc == -2 )
  108. xc = w/2;
  109. if ( yc == -2 )
  110. yc = h/2;
  111. x = xc - width/2;
  112. y = yc - height/2;
  113. if (x < 0 ) {
  114. x = 0;
  115. }
  116. if ( (x+width-1) >= w ) {
  117. x = w - width;
  118. }
  119. if (y < 0 ) {
  120. y = 0;
  121. }
  122. if ( (y+height-1) >= h ) {
  123. y = h - height;
  124. }
  125. wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
  126. //ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER );
  127. y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
  128. ui_string_centered( width/2, y, text );
  129. y = 2*TEXT_EXTRA_HEIGHT + text_height;
  130. gr_setcolor( CGREY );
  131. Hline(1, width-2, y+1 );
  132. gr_setcolor( CBRIGHT );
  133. Hline(2, width-2, y+2 );
  134. y = height - TEXT_EXTRA_HEIGHT - button_height;
  135. for (i=0; i<NumButtons; i++ )
  136. {
  137. x = EVEN_DIVIDE(width,button_width,NumButtons,i);
  138. ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
  139. }
  140. ui_gadget_calc_keys(wnd);
  141. //key_flush();
  142. wnd->keyboard_focus_gadget = (UI_GADGET *)ButtonG[0];
  143. choice = 0;
  144. while(choice==0)
  145. {
  146. ui_mega_process();
  147. ui_window_do_gadgets(wnd);
  148. for (i=0; i<NumButtons; i++ )
  149. {
  150. if (ButtonG[i]->pressed) {
  151. choice = i+1;
  152. break;
  153. }
  154. }
  155. }
  156. ui_close_window(wnd);
  157. grd_curscreen->sc_canvas.cv_font = temp_font;
  158. return choice;
  159. }
  160. int MessageBox( short xc, short yc, int NumButtons, char * text, ... )
  161. {
  162. va_list marker;
  163. char * Button[10];
  164. short i;
  165. if ((NumButtons < 1) || (NumButtons>10)) return -1;
  166. va_start( marker, text );
  167. for (i=0; i<NumButtons; i++ )
  168. {
  169. Button[i] = va_arg( marker, char * );
  170. }
  171. va_end( marker );
  172. return MessageBoxN( xc, yc, NumButtons, text, Button );
  173. }
  174.