New transform input function for joeedh, to be used for edge slide.
Like Vertical or Horizontal ratio input, but along a line defined by two points on screen.
This commit is contained in:
@@ -210,6 +210,7 @@ typedef struct MouseInput {
|
||||
short precision_mval[2]; /* mouse position when precision key was pressed */
|
||||
int center[2];
|
||||
float factor;
|
||||
void *data; /* additional data, if needed by the particular function */
|
||||
} MouseInput;
|
||||
|
||||
typedef struct TransInfo {
|
||||
@@ -575,7 +576,8 @@ typedef enum {
|
||||
INPUT_HORIZONTAL_RATIO,
|
||||
INPUT_HORIZONTAL_ABSOLUTE,
|
||||
INPUT_VERTICAL_RATIO,
|
||||
INPUT_VERTICAL_ABSOLUTE
|
||||
INPUT_VERTICAL_ABSOLUTE,
|
||||
INPUT_CUSTOM_RATIO
|
||||
} MouseInputMode;
|
||||
|
||||
void initMouseInput(TransInfo *t, MouseInput *mi, int center[2], short mval[2]);
|
||||
@@ -583,6 +585,8 @@ void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode);
|
||||
int handleMouseInput(struct TransInfo *t, struct MouseInput *mi, struct wmEvent *event);
|
||||
void applyMouseInput(struct TransInfo *t, struct MouseInput *mi, short mval[2], float output[3]);
|
||||
|
||||
void setCustomPoints(TransInfo *t, MouseInput *mi, short start[2], short end[2]);
|
||||
|
||||
/*********************** Generics ********************************/
|
||||
|
||||
int initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, struct wmEvent *event);
|
||||
|
||||
@@ -1052,7 +1052,7 @@ void postTrans (TransInfo *t)
|
||||
}
|
||||
MEM_freeN(t->data);
|
||||
}
|
||||
|
||||
|
||||
if (t->ext) MEM_freeN(t->ext);
|
||||
if (t->data2d) {
|
||||
MEM_freeN(t->data2d);
|
||||
@@ -1068,6 +1068,11 @@ void postTrans (TransInfo *t)
|
||||
if (t->customData)
|
||||
MEM_freeN(t->customData);
|
||||
}
|
||||
|
||||
if (t->mouse.data)
|
||||
{
|
||||
MEM_freeN(t->mouse.data);
|
||||
}
|
||||
}
|
||||
|
||||
void applyTransObjects(TransInfo *t)
|
||||
|
||||
@@ -163,6 +163,47 @@ void InputVerticalAbsolute(TransInfo *t, MouseInput *mi, short mval[2], float ou
|
||||
output[0] = Inpf(t->viewinv[1], vec) * 2.0f;
|
||||
}
|
||||
|
||||
void setCustomPoints(TransInfo *t, MouseInput *mi, short start[2], short end[2])
|
||||
{
|
||||
short *data = mi->data;
|
||||
|
||||
data[0] = start[0];
|
||||
data[1] = start[1];
|
||||
data[2] = end[0];
|
||||
data[3] = end[1];
|
||||
}
|
||||
|
||||
void InputCustomRatio(TransInfo *t, MouseInput *mi, short mval[2], float output[3])
|
||||
{
|
||||
float length;
|
||||
float distance;
|
||||
short *data = mi->data;
|
||||
short dx, dy;
|
||||
|
||||
dx = data[2] - data[0];
|
||||
dy = data[3] - data[1];
|
||||
|
||||
length = (float)sqrtf(dx*dx + dy*dy);
|
||||
|
||||
if (mi->precision) {
|
||||
/* deal with Shift key by adding motion / 10 to motion before shift press */
|
||||
short mdx, mdy;
|
||||
mdx = (mi->precision_mval[0] + (float)(mval[0] - mi->precision_mval[0]) / 10.0f) - data[2];
|
||||
mdy = (mi->precision_mval[1] + (float)(mval[1] - mi->precision_mval[1]) / 10.0f) - data[3];
|
||||
|
||||
distance = (mdx*dx + mdy*dy) / length;
|
||||
}
|
||||
else {
|
||||
short mdx, mdy;
|
||||
mdx = mval[0] - data[2];
|
||||
mdy = mval[1] - data[3];
|
||||
|
||||
distance = (mdx*dx + mdy*dy) / length;
|
||||
}
|
||||
|
||||
output[0] = distance / length;
|
||||
}
|
||||
|
||||
void InputAngle(TransInfo *t, MouseInput *mi, short mval[2], float output[3])
|
||||
{
|
||||
double dx2 = mval[0] - mi->center[0];
|
||||
@@ -291,6 +332,11 @@ void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
|
||||
mi->apply = InputVerticalAbsolute;
|
||||
t->helpline = HLP_VARROW;
|
||||
break;
|
||||
case INPUT_CUSTOM_RATIO:
|
||||
mi->apply = InputCustomRatio;
|
||||
t->helpline = HLP_NONE;
|
||||
mi->data = MEM_callocN(sizeof(short) * 4, "custom points");
|
||||
break;
|
||||
case INPUT_NONE:
|
||||
default:
|
||||
mi->apply = NULL;
|
||||
|
||||
Reference in New Issue
Block a user