]> icculus.org git repositories - btb/d2x.git/blob - ui/number.c
remove rcs tags
[btb/d2x.git] / ui / number.c
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 #ifdef HAVE_CONFIG_H
15 #include "conf.h"
16 #endif
17
18 #include <stdio.h>
19 #include <stdarg.h>
20
21 #include "fix.h"
22 #include "pstypes.h"
23 #include "gr.h"
24 #include "ui.h"
25
26 #define TEXT_EXTRA_HEIGHT 5
27
28 double ui_input_number( short xc, short yc, char * text, double OrgNumber )
29 {
30         UI_WINDOW * wnd;
31         UI_GADGET_INPUTBOX * InputBox;
32
33         int text_width, text_height, avg;
34         short box_width, box_height, width, height, x, y;
35         short w, h;
36         char string[100];
37
38         sprintf( string, "%f", OrgNumber );
39
40         box_width = box_height = 0;
41
42         gr_set_current_canvas( &grd_curscreen->sc_canvas );
43
44         box_width = 8*20;
45         box_height = 20;
46
47         gr_get_string_size(text, &text_width, &text_height, &avg );
48
49         width = box_width + 50;
50
51         text_width += avg*6;
52         text_width += 10;
53
54         if (text_width > width )
55                 width = text_width;
56
57         height = text_height;
58         height += box_height;
59         height += 4*5;
60
61         // Center X and Y
62         w = grd_curscreen->sc_w;
63         h = grd_curscreen->sc_h;
64
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
70         x = xc - width/2;
71         y = yc - height/2;
72
73         // Make sure that we're onscreen
74         if (x < 0 ) x = 0;
75         if ( (x+width-1) >= w ) x = w - width;
76         if (y < 0 ) y = 0;
77         if ( (y+height-1) >= h ) y = h - height;
78
79
80         wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
81
82         y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
83
84         ui_string_centered( width/2, y, text );
85
86         y = 2*TEXT_EXTRA_HEIGHT + text_height;
87
88         y = height - TEXT_EXTRA_HEIGHT - box_height-10;
89
90         InputBox = ui_add_gadget_inputbox( wnd, 10, y, 20, 20, string );
91
92         ui_gadget_calc_keys(wnd);
93
94         //key_flush();
95
96         wnd->keyboard_focus_gadget = (UI_GADGET *)InputBox;
97
98         while(1)
99         {
100                 ui_mega_process();
101                 ui_window_do_gadgets(wnd);
102
103                 if (InputBox->pressed) break;
104
105                 gr_update();
106         }
107
108         ui_close_window(wnd);
109
110         OrgNumber = atof(InputBox->text);
111
112         return OrgNumber;
113
114 }
115
116