Split numinput from transform (reusable in other operator).

Use in marker move operator.
This commit is contained in:
2010-02-20 20:29:09 +00:00
parent 02e7871149
commit aa67aa9ecc
6 changed files with 103 additions and 37 deletions

View File

@@ -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 */
@@ -431,6 +433,10 @@ static int ed_marker_move_init(bContext *C, wmOperator *op)
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) {
mm->oldframe[a]= marker->frame;
@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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);