TTY.C 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <stdio.h>
  14. #include <stdarg.h>
  15. #include "fix.h"
  16. #include "types.h"
  17. #include "gr.h"
  18. #include "ui.h"
  19. // ts = total span
  20. // w = width of each item
  21. // n = number of items
  22. // i = item number (0 based)
  23. #define EVEN_DIVIDE(ts,w,n,i) ((((ts)-((w)*(n)))*((i)+1))/((n)+1))+((w)*(i))
  24. #define BUTTON_HORZ_SPACING 20
  25. #define TEXT_EXTRA_HEIGHT 5
  26. int MessageBox( short xc, short yc, int NumButtons, char * text, ... )
  27. {
  28. UI_WINDOW * wnd;
  29. UI_GADGET_BUTTON * ButtonG[10];
  30. va_list marker;
  31. char * Button[10];
  32. short i, width, height, avg, x, y;
  33. short button_width, button_height, text_height, text_width;
  34. short w, h;
  35. int choice;
  36. if ((NumButtons < 1) || (NumButtons>10)) return -1;
  37. button_width = button_height = 0;
  38. gr_set_current_canvas( &grd_curscreen->sc_canvas );
  39. va_start( marker, text );
  40. for (i=0; i<NumButtons; i++ )
  41. {
  42. Button[i] = va_arg( marker, char * );
  43. ui_get_button_size( Button[i], &width, &height );
  44. if ( width > button_width ) button_width = width;
  45. if ( height > button_height ) button_height = height;
  46. }
  47. va_end( marker );
  48. gr_get_string_size(text, &text_width, &text_height, &avg );
  49. width = button_width*NumButtons;
  50. width += BUTTON_HORZ_SPACING*(NumButtons+1);
  51. width ++;
  52. text_width += avg*6;
  53. text_width += 10;
  54. if (text_width > width )
  55. width = text_width;
  56. height = text_height;
  57. height += button_height;
  58. height += 4*TEXT_EXTRA_HEIGHT;
  59. height += 2; // For line in middle
  60. w = grd_curscreen->sc_w;
  61. h = grd_curscreen->sc_h;
  62. if ( xc == -1 )
  63. xc = Mouse.x;
  64. if ( yc == -1 )
  65. yc = Mouse.y - button_height/2;
  66. if ( xc == -2 )
  67. xc = w/2;
  68. if ( yc == -2 )
  69. yc = h/2;
  70. x = xc - width/2;
  71. y = yc - height/2;
  72. if (x < 0 ) {
  73. x = 0;
  74. }
  75. if ( (x+width-1) >= w ) {
  76. x = w - width;
  77. }
  78. if (y < 0 ) {
  79. y = 0;
  80. }
  81. if ( (y+height-1) >= h ) {
  82. y = h - height;
  83. }
  84. wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
  85. //ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER );
  86. y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
  87. ui_string_centered( width/2, y, text );
  88. y = 2*TEXT_EXTRA_HEIGHT + text_height;
  89. gr_setcolor( CGREY );
  90. Hline(1, width-2, y+1 );
  91. gr_setcolor( CBRIGHT );
  92. Hline(2, width-2, y+2 );
  93. y = height - TEXT_EXTRA_HEIGHT - button_height;
  94. for (i=0; i<NumButtons; i++ )
  95. {
  96. x = EVEN_DIVIDE(width,button_width,NumButtons,i);
  97. ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i] );
  98. }
  99. wnd->keyboard_focus_gadget = (UI_GADGET *)ButtonG[0];
  100. choice = 0;
  101. while(choice==0)
  102. {
  103. ui_mega_process();
  104. ui_window_do_gadgets(wnd);
  105. for (i=0; i<NumButtons; i++ )
  106. {
  107. if (ButtonG[i]->pressed) {
  108. choice = i+1;
  109. break;
  110. }
  111. }
  112. }
  113. ui_close_window(wnd);
  114. return choice;
  115. }