~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/src/transform_numinput.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: transform_numinput.c,v 1.8 2005/06/05 14:26:45 theeth Exp $
 
3
 *
 
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version 2
 
9
 * of the License, or (at your option) any later version. The Blender
 
10
 * Foundation also sells licenses for use in proprietary software under
 
11
 * the Blender License.  See http://www.blender.org/BL/ for information
 
12
 * about this.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software Foundation,
 
21
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
22
 *
 
23
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 
24
 * All rights reserved.
 
25
 *
 
26
 * The Original Code is: all of this file.
 
27
 *
 
28
 * Contributor(s): none yet.
 
29
 *
 
30
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 
31
 */
 
32
 
 
33
#include <stdlib.h>
 
34
#include <string.h>
 
35
#include <math.h>
 
36
 
 
37
#ifdef HAVE_CONFIG_H
 
38
#include <config.h>
 
39
#endif
 
40
 
 
41
#ifndef WIN32
 
42
#include <unistd.h>
 
43
#else
 
44
#include <io.h>
 
45
#endif
 
46
 
 
47
#include "MEM_guardedalloc.h"
 
48
 
 
49
#include "BKE_global.h" /* for G */
 
50
 
 
51
#include "blendef.h"
 
52
 
 
53
#include "mydevice.h"
 
54
 
 
55
#include "BLI_arithb.h"
 
56
 
 
57
#include "transform.h"
 
58
 
 
59
/* ************************** Functions *************************** */
 
60
 
 
61
/* ************************** NUMINPUT **************************** */
 
62
 
 
63
void outputNumInput(NumInput *n, char *str)
 
64
{
 
65
        char cur;
 
66
        short i, j;
 
67
 
 
68
        for (j=0; j<=n->idx_max; j++) {
 
69
                /* if AFFECTALL and no number typed and cursor not on number, use first number */
 
70
                if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0)
 
71
                        i = 0;
 
72
                else
 
73
                        i = j;
 
74
 
 
75
                if (n->idx != i)
 
76
                        cur = ' ';
 
77
                else
 
78
                        cur = '|';
 
79
 
 
80
                switch (n->ctrl[i]) {
 
81
                case 0:
 
82
                        sprintf(&str[j*20], "NONE%c", cur);
 
83
                        break;
 
84
                case 1:
 
85
                case -1:
 
86
                        sprintf(&str[j*20], "%.0f%c", n->val[i], cur);
 
87
                        break;
 
88
                case 10:
 
89
                case -10:
 
90
                        sprintf(&str[j*20], "%.f.%c", n->val[i], cur);
 
91
                        break;
 
92
                case 100:
 
93
                case -100:
 
94
                        sprintf(&str[j*20], "%.1f%c", n->val[i], cur);
 
95
                        break;
 
96
                case 1000:
 
97
                case -1000:
 
98
                        sprintf(&str[j*20], "%.2f%c", n->val[i], cur);
 
99
                case 10000:
 
100
                case -10000:
 
101
                        sprintf(&str[j*20], "%.3f%c", n->val[i], cur);
 
102
                        break;
 
103
                default:
 
104
                        sprintf(&str[j*20], "%.4f%c", n->val[i], cur);
 
105
                }
 
106
        }
 
107
}
 
108
 
 
109
short hasNumInput(NumInput *n)
 
110
{
 
111
        short i;
 
112
 
 
113
        for (i=0; i<=n->idx_max; i++) {
 
114
                if (n->ctrl[i])
 
115
                        return 1;
 
116
        }
 
117
 
 
118
        return 0;
 
119
}
 
120
 
 
121
void applyNumInput(NumInput *n, float *vec)
 
122
{
 
123
        short i, j;
 
124
 
 
125
        if (hasNumInput(n)) {
 
126
                for (j=0; j<=n->idx_max; j++) {
 
127
                        /* if AFFECTALL and no number typed and cursor not on number, use first number */
 
128
                        if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0)
 
129
                                i = 0;
 
130
                        else
 
131
                                i = j;
 
132
 
 
133
                        if (n->ctrl[i] == 0 && n->flag & NUM_NULL_ONE) {
 
134
                                vec[j] = 1.0f;
 
135
                        }
 
136
                        else if (n->val[i] == 0.0f && n->flag & NUM_NO_ZERO) {
 
137
                                vec[j] = 0.0001f;
 
138
                        }
 
139
                        else {
 
140
                                vec[j] = n->val[i];
 
141
                        }
 
142
                }
 
143
        }
 
144
}
 
145
 
 
146
char handleNumInput(NumInput *n, unsigned short event)
 
147
{
 
148
        float Val = 0;
 
149
        short idx = n->idx, idx_max = n->idx_max;
 
150
 
 
151
        switch (event) {
 
152
        case BACKSPACEKEY:
 
153
                if (n->ctrl[idx] == 0) {
 
154
                        n->val[0]               = 
 
155
                                n->val[1]       = 
 
156
                                n->val[2]       = 0.0f;
 
157
                        n->ctrl[0]              = 
 
158
                                n->ctrl[1]      = 
 
159
                                n->ctrl[2]      = 0;
 
160
                }
 
161
                else {
 
162
                        n->val[idx] = 0.0f;
 
163
                        n->ctrl[idx] = 0;
 
164
                }
 
165
                break;
 
166
        case PERIODKEY:
 
167
        case PADPERIOD:
 
168
                if (n->flag & NUM_NO_FRACTION)
 
169
                        break;
 
170
 
 
171
                switch (n->ctrl[idx])
 
172
                {
 
173
                case 0:
 
174
                case 1:
 
175
                        n->ctrl[idx] = 10;
 
176
                        break;
 
177
                case -1:
 
178
                        n->ctrl[idx] = -10;
 
179
                }
 
180
                break;
 
181
        case PADMINUS:
 
182
                if(G.qual & LR_ALTKEY)
 
183
                        break;
 
184
        case MINUSKEY:
 
185
                if (n->flag & NUM_NO_NEGATIVE)
 
186
                        break;
 
187
 
 
188
                if (n->ctrl[idx]) {
 
189
                        n->ctrl[idx] *= -1;
 
190
                        n->val[idx] *= -1;
 
191
                }
 
192
                else
 
193
                        n->ctrl[idx] = -1;
 
194
                break;
 
195
        case TABKEY:
 
196
                idx++;
 
197
                if (idx > idx_max)
 
198
                        idx = 0;
 
199
                n->idx = idx;
 
200
                break;
 
201
        case PAD9:
 
202
        case NINEKEY:
 
203
                Val += 1.0f;
 
204
        case PAD8:
 
205
        case EIGHTKEY:
 
206
                Val += 1.0f;
 
207
        case PAD7:
 
208
        case SEVENKEY:
 
209
                Val += 1.0f;
 
210
        case PAD6:
 
211
        case SIXKEY:
 
212
                Val += 1.0f;
 
213
        case PAD5:
 
214
        case FIVEKEY:
 
215
                Val += 1.0f;
 
216
        case PAD4:
 
217
        case FOURKEY:
 
218
                Val += 1.0f;
 
219
        case PAD3:
 
220
        case THREEKEY:
 
221
                Val += 1.0f;
 
222
        case PAD2:
 
223
        case TWOKEY:
 
224
                Val += 1.0f;
 
225
        case PAD1:
 
226
        case ONEKEY:
 
227
                Val += 1.0f;
 
228
        case PAD0:
 
229
        case ZEROKEY:
 
230
                if (!n->ctrl[idx])
 
231
                        n->ctrl[idx] = 1;
 
232
 
 
233
                if (n->ctrl[idx] == 1) {
 
234
                        n->val[idx] *= 10;
 
235
                        n->val[idx] += Val;
 
236
                }
 
237
                else if (n->ctrl[idx] == -1) {
 
238
                        n->val[idx] *= 10;
 
239
                        n->val[idx] -= Val;
 
240
                }
 
241
                else {
 
242
                        n->val[idx] += Val / (float)n->ctrl[idx];
 
243
                        n->ctrl[idx] *= 10;
 
244
                }
 
245
                break;
 
246
        default:
 
247
                return 0;
 
248
        }
 
249
        /* REDRAW SINCE NUMBERS HAVE CHANGED */
 
250
        return 1;
 
251
}