NUMBER.C 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/number.c $
  15. * $Revision: 1.2 $
  16. * $Author: john $
  17. * $Date: 1994/06/09 12:18:25 $
  18. *
  19. * Routine to input a number
  20. *
  21. * $Log: number.c $
  22. * Revision 1.2 1994/06/09 12:18:25 john
  23. * Took out keyboard flushes.
  24. *
  25. * Revision 1.1 1993/12/07 12:31:18 john
  26. * Initial revision
  27. *
  28. *
  29. */
  30. #pragma off (unreferenced)
  31. static char rcsid[] = "$Id: number.c 1.2 1994/06/09 12:18:25 john Exp $";
  32. #pragma on (unreferenced)
  33. #include <stdio.h>
  34. #include <stdarg.h>
  35. #include "fix.h"
  36. #include "types.h"
  37. #include "gr.h"
  38. #include "ui.h"
  39. #define TEXT_EXTRA_HEIGHT 5
  40. double ui_input_number( short xc, short yc, char * text, double OrgNumber )
  41. {
  42. UI_WINDOW * wnd;
  43. UI_GADGET_INPUTBOX * InputBox;
  44. short i, width, height, avg, x, y;
  45. short box_width, box_height, text_height, text_width;
  46. short w, h;
  47. char string[100];
  48. sprintf( string, "%f", OrgNumber );
  49. box_width = box_height = 0;
  50. gr_set_current_canvas( &grd_curscreen->sc_canvas );
  51. box_width = 8*20;
  52. box_height = 20;
  53. gr_get_string_size(text, &text_width, &text_height, &avg );
  54. width = box_width + 50;
  55. text_width += avg*6;
  56. text_width += 10;
  57. if (text_width > width )
  58. width = text_width;
  59. height = text_height;
  60. height += box_height;
  61. height += 4*5;
  62. // Center X and Y
  63. w = grd_curscreen->sc_w;
  64. h = grd_curscreen->sc_h;
  65. if ( xc == -1 ) xc = Mouse.x;
  66. if ( yc == -1 ) yc = Mouse.y - box_height/2;
  67. if ( xc == -2 ) xc = w/2;
  68. if ( yc == -2 ) yc = h/2;
  69. x = xc - width/2;
  70. y = yc - height/2;
  71. // Make sure that we're onscreen
  72. if (x < 0 ) x = 0;
  73. if ( (x+width-1) >= w ) x = w - width;
  74. if (y < 0 ) y = 0;
  75. if ( (y+height-1) >= h ) y = h - height;
  76. wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
  77. y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
  78. ui_string_centered( width/2, y, text );
  79. y = 2*TEXT_EXTRA_HEIGHT + text_height;
  80. y = height - TEXT_EXTRA_HEIGHT - box_height-10;
  81. InputBox = ui_add_gadget_inputbox( wnd, 10, y, 20, 20, string );
  82. ui_gadget_calc_keys(wnd);
  83. //key_flush();
  84. wnd->keyboard_focus_gadget = (UI_GADGET *)InputBox;
  85. while(1)
  86. {
  87. ui_mega_process();
  88. ui_window_do_gadgets(wnd);
  89. if (InputBox->pressed) break;
  90. }
  91. ui_close_window(wnd);
  92. OrgNumber = atof(inputbox->text);
  93. return OrgNumber;
  94. }
  95.