1 /* $Id: number.c,v 1.3 2004-12-19 15:21:11 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 static char rcsid[] = "$Id: number.c,v 1.3 2004-12-19 15:21:11 btb Exp $";
31 #define TEXT_EXTRA_HEIGHT 5
33 double ui_input_number( short xc, short yc, char * text, double OrgNumber )
36 UI_GADGET_INPUTBOX * InputBox;
38 short i, width, height, avg, x, y;
39 short box_width, box_height, text_height, text_width;
43 sprintf( string, "%f", OrgNumber );
45 box_width = box_height = 0;
47 gr_set_current_canvas( &grd_curscreen->sc_canvas );
52 gr_get_string_size(text, &text_width, &text_height, &avg );
54 width = box_width + 50;
59 if (text_width > width )
67 w = grd_curscreen->sc_w;
68 h = grd_curscreen->sc_h;
70 if ( xc == -1 ) xc = Mouse.x;
71 if ( yc == -1 ) yc = Mouse.y - box_height/2;
72 if ( xc == -2 ) xc = w/2;
73 if ( yc == -2 ) yc = h/2;
78 // Make sure that we're onscreen
80 if ( (x+width-1) >= w ) x = w - width;
82 if ( (y+height-1) >= h ) y = h - height;
85 wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
87 y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
89 ui_string_centered( width/2, y, text );
91 y = 2*TEXT_EXTRA_HEIGHT + text_height;
93 y = height - TEXT_EXTRA_HEIGHT - box_height-10;
95 InputBox = ui_add_gadget_inputbox( wnd, 10, y, 20, 20, string );
97 ui_gadget_calc_keys(wnd);
101 wnd->keyboard_focus_gadget = (UI_GADGET *)InputBox;
106 ui_window_do_gadgets(wnd);
108 if (InputBox->pressed) break;
111 ui_close_window(wnd);
113 OrgNumber = atof(inputbox->text);