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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
12 */
13
14
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: number.c,v 1.1.1.1 2001/01/19 03:30:14 bradleyb Exp $";
17 #pragma on (unreferenced)
18
19
20 #include <stdio.h>
21 #include <stdarg.h>
22
23 #include "fix.h"
24 #include "types.h"
25 #include "gr.h"
26 #include "ui.h"
27
28 #define TEXT_EXTRA_HEIGHT 5
29
ui_input_number(short xc,short yc,char * text,double OrgNumber)30 double ui_input_number( short xc, short yc, char * text, double OrgNumber )
31 {
32 UI_WINDOW * wnd;
33 UI_GADGET_INPUTBOX * InputBox;
34
35 short i, width, height, avg, x, y;
36 short box_width, box_height, text_height, text_width;
37 short w, h;
38 char string[100];
39
40 sprintf( string, "%f", OrgNumber );
41
42 box_width = box_height = 0;
43
44 gr_set_current_canvas( &grd_curscreen->sc_canvas );
45
46 box_width = 8*20;
47 box_height = 20;
48
49 gr_get_string_size(text, &text_width, &text_height, &avg );
50
51 width = box_width + 50;
52
53 text_width += avg*6;
54 text_width += 10;
55
56 if (text_width > width )
57 width = text_width;
58
59 height = text_height;
60 height += box_height;
61 height += 4*5;
62
63 // Center X and Y
64 w = grd_curscreen->sc_w;
65 h = grd_curscreen->sc_h;
66
67 if ( xc == -1 ) xc = Mouse.x;
68 if ( yc == -1 ) yc = Mouse.y - box_height/2;
69 if ( xc == -2 ) xc = w/2;
70 if ( yc == -2 ) yc = h/2;
71
72 x = xc - width/2;
73 y = yc - height/2;
74
75 // Make sure that we're onscreen
76 if (x < 0 ) x = 0;
77 if ( (x+width-1) >= w ) x = w - width;
78 if (y < 0 ) y = 0;
79 if ( (y+height-1) >= h ) y = h - height;
80
81
82 wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
83
84 y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
85
86 ui_string_centered( width/2, y, text );
87
88 y = 2*TEXT_EXTRA_HEIGHT + text_height;
89
90 y = height - TEXT_EXTRA_HEIGHT - box_height-10;
91
92 InputBox = ui_add_gadget_inputbox( wnd, 10, y, 20, 20, string );
93
94 ui_gadget_calc_keys(wnd);
95
96 //key_flush();
97
98 wnd->keyboard_focus_gadget = (UI_GADGET *)InputBox;
99
100 while(1)
101 {
102 ui_mega_process();
103 ui_window_do_gadgets(wnd);
104
105 if (InputBox->pressed) break;
106 }
107
108 ui_close_window(wnd);
109
110 OrgNumber = atof(inputbox->text);
111
112 return OrgNumber;
113
114 }
115
116
117