diff options
author | Martin Poirier <theeth@yahoo.com> | 2010-02-20 23:29:09 +0300 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2010-02-20 23:29:09 +0300 |
commit | aa67aa9ecc05efeb2546e41d85f6975e77157e3d (patch) | |
tree | 1465032d2ddd648e1887768f441960bfbc91520c /source/blender | |
parent | 02e7871149fb369a12725a319cb09accad7790b9 (diff) |
Split numinput from transform (reusable in other operator).
Use in marker move operator.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/animation/anim_markers.c | 31 | ||||
-rw-r--r-- | source/blender/editors/include/ED_numinput.h | 56 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.c | 8 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.h | 29 | ||||
-rw-r--r-- | source/blender/editors/util/numinput.c (renamed from source/blender/editors/transform/transform_numinput.c) | 14 | ||||
-rw-r--r-- | source/blender/python/generic/quat.c | 2 |
6 files changed, 103 insertions, 37 deletions
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 1d4773b0202..e6280a2556c 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -67,6 +67,7 @@ #include "ED_screen.h" #include "ED_types.h" #include "ED_util.h" +#include "ED_numinput.h" /* ************* Marker API **************** */ @@ -407,6 +408,7 @@ typedef struct MarkerMove { ListBase *markers; int event_type; /* store invoke-event, to verify */ int *oldframe, evtx, firstx; + NumInput num; } MarkerMove; /* copy selection to temp buffer */ @@ -430,6 +432,10 @@ static int ed_marker_move_init(bContext *C, wmOperator *op) mm->slink= CTX_wm_space_data(C); mm->markers= markers; mm->oldframe= MEM_callocN(totmark*sizeof(int), "MarkerMove oldframe"); + + initNumInput(&mm->num); + mm->num.idx_max = 0; /* one axis */ + mm->num.flag |= NUM_NO_FRACTION; for (a=0, marker= markers->first; marker; marker= marker->next) { if (marker->flag & SELECT) { @@ -518,6 +524,8 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt) ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; + case RETKEY: + case PADENTER: case LEFTMOUSE: case MIDDLEMOUSE: case RIGHTMOUSE: @@ -529,6 +537,9 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt) break; case MOUSEMOVE: + if(hasNumInput(&mm->num)) + break; + dx= v2d->mask.xmax-v2d->mask.xmin; dx= (v2d->cur.xmax-v2d->cur.xmin)/dx; @@ -602,6 +613,26 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt) } } + if(evt->val==KM_PRESS) { + float vec[3]; + char str_tx[256]; + + if (handleNumInput(&mm->num, evt, 1.0)) + { + applyNumInput(&mm->num, vec); + outputNumInput(&mm->num, str_tx); + + RNA_int_set(op->ptr, "frames", vec[0]); + ed_marker_move_apply(C, op); + // ed_marker_header_update(C, op, str, (int)vec[0]); + // strcat(str, str_tx); + sprintf(str, "Marker offset %s", str_tx); + ED_area_headerprint(CTX_wm_area(C), str); + + WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL); + } + } + return OPERATOR_RUNNING_MODAL; } diff --git a/source/blender/editors/include/ED_numinput.h b/source/blender/editors/include/ED_numinput.h new file mode 100644 index 00000000000..381131c8b2d --- /dev/null +++ b/source/blender/editors/include/ED_numinput.h @@ -0,0 +1,56 @@ +/** + * $Id: + * + * ***** 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 ***** + */ + +#ifndef ED_NUMINPUT_H +#define ED_NUMINPUT_H + + +typedef struct NumInput { + short idx; + short idx_max; + short flag; /* Different flags to indicate different behaviors */ + char inv[3]; /* If the value is inverted or not */ + float val[3]; /* Direct value of the input */ + int ctrl[3]; /* Control to indicate what to do with the numbers that are typed */ +} NumInput ; + +/* NUMINPUT FLAGS */ +#define NUM_NULL_ONE 2 +#define NUM_NO_NEGATIVE 4 +#define NUM_NO_ZERO 8 +#define NUM_NO_FRACTION 16 +#define NUM_AFFECT_ALL 32 + +/*********************** NumInput ********************************/ + +void initNumInput(NumInput *n); +void outputNumInput(NumInput *n, char *str); +short hasNumInput(NumInput *n); +void applyNumInput(NumInput *n, float *vec); +char handleNumInput(NumInput *n, struct wmEvent *event, float increment); + +#define NUM_MODAL_INCREMENT_UP 18 +#define NUM_MODAL_INCREMENT_DOWN 19 + +#endif diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index b6d0d3d3cc5..fcbadf5b7a6 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -496,8 +496,8 @@ wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf) {TFM_MODAL_CONS_OFF, "CONS_OFF", 0, "Remove Constraints", ""}, {TFM_MODAL_ADD_SNAP, "ADD_SNAP", 0, "Add Snap Point", ""}, {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""}, - {TFM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""}, - {TFM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""}, + {NUM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""}, + {NUM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""}, {0, NULL, 0, NULL, NULL}}; wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map"); @@ -525,8 +525,8 @@ wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf) WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP); WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP); - WM_modalkeymap_add_item(keymap, UPARROWKEY, KM_PRESS, 0, 0, TFM_MODAL_INCREMENT_UP); - WM_modalkeymap_add_item(keymap, DOWNARROWKEY, KM_PRESS, 0, 0, TFM_MODAL_INCREMENT_DOWN); + WM_modalkeymap_add_item(keymap, UPARROWKEY, KM_PRESS, 0, 0, NUM_MODAL_INCREMENT_UP); + WM_modalkeymap_add_item(keymap, DOWNARROWKEY, KM_PRESS, 0, 0, NUM_MODAL_INCREMENT_DOWN); return keymap; } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 42f30e48cad..6a0c51da370 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -31,6 +31,7 @@ #define TRANSFORM_H #include "ED_transform.h" +#include "ED_numinput.h" #include "DNA_listBase.h" @@ -68,14 +69,6 @@ typedef struct NDofInput { float factor[3]; } NDofInput; -typedef struct NumInput { - short idx; - short idx_max; - short flag; /* Different flags to indicate different behaviors */ - char inv[3]; /* If the value is inverted or not */ - float val[3]; /* Direct value of the input */ - int ctrl[3]; /* Control to indicate what to do with the numbers that are typed */ -} NumInput ; /* The ctrl value has different meaning: @@ -334,13 +327,6 @@ typedef struct TransInfo { /* ******************** Macros & Prototypes *********************** */ -/* NUMINPUT FLAGS */ -#define NUM_NULL_ONE 2 -#define NUM_NO_NEGATIVE 4 -#define NUM_NO_ZERO 8 -#define NUM_NO_FRACTION 16 -#define NUM_AFFECT_ALL 32 - /* NDOFINPUT FLAGS */ #define NDOF_INIT 1 @@ -678,17 +664,6 @@ void calculatePropRatio(TransInfo *t); void getViewVector(TransInfo *t, float coord[3], float vec[3]); -/*********************** NumInput ********************************/ - -void initNumInput(NumInput *n); -void outputNumInput(NumInput *n, char *str); -short hasNumInput(NumInput *n); -void applyNumInput(NumInput *n, float *vec); -char handleNumInput(NumInput *n, struct wmEvent *event, float increment); - -#define TFM_MODAL_INCREMENT_UP 18 -#define TFM_MODAL_INCREMENT_DOWN 19 - /*********************** NDofInput ********************************/ void initNDofInput(NDofInput *n); @@ -733,5 +708,3 @@ int createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3]) void freeSlideVerts(TransInfo *t); #endif - - diff --git a/source/blender/editors/transform/transform_numinput.c b/source/blender/editors/util/numinput.c index 8d1901348f8..d6e2621a235 100644 --- a/source/blender/editors/transform/transform_numinput.c +++ b/source/blender/editors/util/numinput.c @@ -36,7 +36,7 @@ #include "WM_types.h" #include "DNA_windowmanager_types.h" -#include "transform.h" +#include "ED_numinput.h" /* ************************** Functions *************************** */ @@ -166,13 +166,13 @@ char handleNumInput(NumInput *n, wmEvent *event, float increment) if (event->type == EVT_MODAL_MAP) { switch (event->val) { - case TFM_MODAL_INCREMENT_UP: + case NUM_MODAL_INCREMENT_UP: if (!n->ctrl[idx]) n->ctrl[idx] = 1; n->val[idx] += increment; break; - case TFM_MODAL_INCREMENT_DOWN: + case NUM_MODAL_INCREMENT_DOWN: if (!n->ctrl[idx]) n->ctrl[idx] = 1; @@ -204,7 +204,7 @@ char handleNumInput(NumInput *n, wmEvent *event, float increment) case PERIODKEY: case PADPERIOD: if (n->flag & NUM_NO_FRACTION) - break; + return 0; switch (n->ctrl[idx]) { @@ -232,9 +232,15 @@ char handleNumInput(NumInput *n, wmEvent *event, float increment) break; case PADSLASHKEY: case SLASHKEY: + if (n->flag & NUM_NO_FRACTION) + return 0; + n->inv[idx] = !n->inv[idx]; break; case TABKEY: + if (idx_max == 0) + return 0; + idx++; if (idx > idx_max) idx = 0; diff --git a/source/blender/python/generic/quat.c b/source/blender/python/generic/quat.c index 7a8733c970f..b7cc45a7690 100644 --- a/source/blender/python/generic/quat.c +++ b/source/blender/python/generic/quat.c @@ -74,7 +74,7 @@ static PyObject *Quaternion_ToEuler(QuaternionObject * self, PyObject *args) quat_to_mat3(mat, self->quat); if(order == 0) mat3_to_compatible_eul(eul, eul_compat->eul, mat); - else mat3_to_compatible_eulO(eul, order, eul_compat->eul, mat); + else mat3_to_compatible_eulO(eul, eul_compat->eul, order, mat); } else { if(order == 0) quat_to_eul(eul, self->quat); |