| 
									
										
										
										
											2011-02-21 07:25:24 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-02-20 20:29:09 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): none yet. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-21 07:25:24 +00:00
										 |  |  | /** \file ED_numinput.h
 | 
					
						
							|  |  |  |  *  \ingroup editors | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-17 18:59:41 +00:00
										 |  |  | #ifndef __ED_NUMINPUT_H__
 | 
					
						
							|  |  |  | #define __ED_NUMINPUT_H__
 | 
					
						
							| 
									
										
										
										
											2010-02-20 20:29:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Support units in modal numinput
Summary:
This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value.
We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so).
Features:
- units (cm, ", deg, etc.).
- basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.).
- you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything.
- you can go to next/previous value with (ctrl-)TAB key.
- As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse.
Notes:
- Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent.
- Added back radian support in BKE_unit.
- Added arcminute/arcsecond to BKE_unit.
(those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units).
Related to T37600.
Reviewers: brecht, campbellbarton, carter2422
Reviewed By: brecht, campbellbarton, carter2422
Thanks everybody!
Differential Revision: http://developer.blender.org/D61
											
										 
											2013-12-21 17:11:43 +01:00
										 |  |  | #define NUM_STR_REP_LEN 64
 | 
					
						
							|  |  |  | #define NUM_MAX_ELEMENTS 3
 | 
					
						
							| 
									
										
										
										
											2012-03-10 21:40:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-20 20:29:09 +00:00
										 |  |  | typedef struct NumInput { | 
					
						
							| 
									
										
											  
											
												Support units in modal numinput
Summary:
This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value.
We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so).
Features:
- units (cm, ", deg, etc.).
- basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.).
- you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything.
- you can go to next/previous value with (ctrl-)TAB key.
- As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse.
Notes:
- Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent.
- Added back radian support in BKE_unit.
- Added arcminute/arcsecond to BKE_unit.
(those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units).
Related to T37600.
Reviewers: brecht, campbellbarton, carter2422
Reviewed By: brecht, campbellbarton, carter2422
Thanks everybody!
Differential Revision: http://developer.blender.org/D61
											
										 
											2013-12-21 17:11:43 +01:00
										 |  |  | 	short  idx_max;                      /* idx_max < NUM_MAX_ELEMENTS */ | 
					
						
							|  |  |  | 	int    unit_sys; | 
					
						
							|  |  |  | 	int    unit_type[NUM_MAX_ELEMENTS];  /* Each value can have a different type */ | 
					
						
							|  |  |  | 	bool   unit_use_radians; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	short  flag;                         /* Flags affecting all values' behavior */ | 
					
						
							|  |  |  | 	short  val_flag[NUM_MAX_ELEMENTS];   /* Per-value flags */ | 
					
						
							|  |  |  | 	float  val[NUM_MAX_ELEMENTS];        /* Direct value of the input */ | 
					
						
							|  |  |  | 	float  val_org[NUM_MAX_ELEMENTS];    /* Original value of the input, for reset */ | 
					
						
							|  |  |  | 	float  val_inc[NUM_MAX_ELEMENTS];    /* Increment steps */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	short  idx;                          /* Active element/value */ | 
					
						
							|  |  |  | 	char   str[NUM_STR_REP_LEN];         /* String as typed by user for edited value (we assume ASCII world!) */ | 
					
						
							|  |  |  | 	/* Current position of cursor in edited value str (first byte of "current" letter, so 0 for an empty str) */ | 
					
						
							|  |  |  | 	int    str_cur; | 
					
						
							| 
									
										
										
										
											2012-02-27 10:35:39 +00:00
										 |  |  | } NumInput; | 
					
						
							| 
									
										
										
										
											2010-02-20 20:29:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Support units in modal numinput
Summary:
This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value.
We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so).
Features:
- units (cm, ", deg, etc.).
- basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.).
- you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything.
- you can go to next/previous value with (ctrl-)TAB key.
- As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse.
Notes:
- Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent.
- Added back radian support in BKE_unit.
- Added arcminute/arcsecond to BKE_unit.
(those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units).
Related to T37600.
Reviewers: brecht, campbellbarton, carter2422
Reviewed By: brecht, campbellbarton, carter2422
Thanks everybody!
Differential Revision: http://developer.blender.org/D61
											
										 
											2013-12-21 17:11:43 +01:00
										 |  |  | /* NumInput.flag */ | 
					
						
							|  |  |  | enum { | 
					
						
							|  |  |  | 	NUM_AFFECT_ALL      = (1 << 0), | 
					
						
							| 
									
										
										
										
											2014-02-20 16:11:36 +11:00
										 |  |  | 	/* (1 << 9) and above are reserved for internal flags! */ | 
					
						
							| 
									
										
											  
											
												Support units in modal numinput
Summary:
This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value.
We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so).
Features:
- units (cm, ", deg, etc.).
- basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.).
- you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything.
- you can go to next/previous value with (ctrl-)TAB key.
- As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse.
Notes:
- Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent.
- Added back radian support in BKE_unit.
- Added arcminute/arcsecond to BKE_unit.
(those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units).
Related to T37600.
Reviewers: brecht, campbellbarton, carter2422
Reviewed By: brecht, campbellbarton, carter2422
Thanks everybody!
Differential Revision: http://developer.blender.org/D61
											
										 
											2013-12-21 17:11:43 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* NumInput.val_flag[] */ | 
					
						
							|  |  |  | enum { | 
					
						
							|  |  |  | 	/* Public! */ | 
					
						
							|  |  |  | 	NUM_NULL_ONE        = (1 << 0), | 
					
						
							|  |  |  | 	NUM_NO_NEGATIVE     = (1 << 1), | 
					
						
							|  |  |  | 	NUM_NO_ZERO         = (1 << 2), | 
					
						
							|  |  |  | 	NUM_NO_FRACTION     = (1 << 3), | 
					
						
							|  |  |  | 	/* (1 << 9) and above are reserved for internal flags! */ | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2010-02-20 20:29:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-26 12:04:24 +02:00
										 |  |  | struct UnitSettings; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-20 20:29:09 +00:00
										 |  |  | /*********************** NumInput ********************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-22 23:20:14 +01:00
										 |  |  | /* There are important things to note here for code using numinput:
 | 
					
						
							|  |  |  |  * * Values passed to applyNumInput() should be valid and are stored as default ones (val_org), if it is not EDITED. | 
					
						
							|  |  |  |  * * bool returned by applyNumInput should be used to decide whether to apply numinput-specific post-process to data. | 
					
						
							|  |  |  |  * * *Once applyNumInput has been called*, hasNumInput returns a valid value to decide whether to use numinput | 
					
						
							|  |  |  |  *   as drawstr source or not (i.e. to call outputNumInput). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Those two steps have to be separated (so do not use a common call to hasNumInput() to do both in the same time!). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-20 20:29:09 +00:00
										 |  |  | void initNumInput(NumInput *n); | 
					
						
							| 
									
										
										
										
											2014-08-26 12:04:24 +02:00
										 |  |  | void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings); | 
					
						
							| 
									
										
										
										
											2013-10-23 06:48:36 +00:00
										 |  |  | bool hasNumInput(const NumInput *n); | 
					
						
							| 
									
										
										
										
											2014-03-22 23:20:14 +01:00
										 |  |  | bool applyNumInput(NumInput *n, float *vec); | 
					
						
							| 
									
										
											  
											
												Support units in modal numinput
Summary:
This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value.
We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so).
Features:
- units (cm, ", deg, etc.).
- basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.).
- you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything.
- you can go to next/previous value with (ctrl-)TAB key.
- As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse.
Notes:
- Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent.
- Added back radian support in BKE_unit.
- Added arcminute/arcsecond to BKE_unit.
(those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units).
Related to T37600.
Reviewers: brecht, campbellbarton, carter2422
Reviewed By: brecht, campbellbarton, carter2422
Thanks everybody!
Differential Revision: http://developer.blender.org/D61
											
										 
											2013-12-21 17:11:43 +01:00
										 |  |  | bool handleNumInput(struct bContext *C, NumInput *n, const struct wmEvent *event); | 
					
						
							| 
									
										
										
										
											2010-02-20 20:29:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define NUM_MODAL_INCREMENT_UP   18
 | 
					
						
							|  |  |  | #define NUM_MODAL_INCREMENT_DOWN 19
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-23 06:48:36 +00:00
										 |  |  | #endif  /* __ED_NUMINPUT_H__ */
 |