Transform helpline and experimental drawing code to indicate direction of motion for specific transformations.
This commit is contained in:
2009-04-30 11:47:35 +00:00
parent a29551751c
commit 3c9e3e69ed
9 changed files with 287 additions and 105 deletions

View File

@@ -940,4 +940,6 @@ void UI_SetTheme(int spacetype, int regionid);
char *UI_ThemeGetColorPtr(struct bTheme *btheme, int spacetype, int colorid);
char *UI_ThemeColorsPup(int spacetype);
void UI_make_axis_color(char *src_col, char *dst_col, char axis);
#endif /* UI_ICONS_H */

View File

@@ -841,6 +841,28 @@ void UI_GetColorPtrBlendShade3ubv(char *cp1, char *cp2, char *col, float fac, in
col[2] = b;
}
void UI_make_axis_color(char *src_col, char *dst_col, char axis)
{
switch(axis)
{
case 'x':
case 'X':
dst_col[0]= src_col[0]>219?255:src_col[0]+36;
dst_col[1]= src_col[1]<26?0:src_col[1]-26;
dst_col[2]= src_col[2]<26?0:src_col[2]-26;
break;
case 'y':
case 'Y':
dst_col[0]= src_col[0]<46?0:src_col[0]-36;
dst_col[1]= src_col[1]>189?255:src_col[1]+66;
dst_col[2]= src_col[2]<46?0:src_col[2]-36;
break;
default:
dst_col[0]= src_col[0]<26?0:src_col[0]-26;
dst_col[1]= src_col[1]<26?0:src_col[1]-26;
dst_col[2]= src_col[2]>209?255:src_col[2]+46;
}
}
/* ************************************************************* */

View File

@@ -5135,7 +5135,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
char col[4], col2[4];
UI_GetThemeColor3ubv(TH_GRID, col);
make_axis_color(col, col2, 'z');
UI_make_axis_color(col, col2, 'z');
glColor3ubv((GLubyte *)col2);
cob= constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);

View File

@@ -232,27 +232,6 @@ static void drawgrid_draw(ARegion *ar, float wx, float wy, float x, float y, flo
}
// not intern, called in editobject for constraint axis too
void make_axis_color(char *col, char *col2, char axis)
{
if(axis=='x') {
col2[0]= col[0]>219?255:col[0]+36;
col2[1]= col[1]<26?0:col[1]-26;
col2[2]= col[2]<26?0:col[2]-26;
}
else if(axis=='y') {
col2[0]= col[0]<46?0:col[0]-36;
col2[1]= col[1]>189?255:col[1]+66;
col2[2]= col[2]<46?0:col[2]-36;
}
else {
col2[0]= col[0]<26?0:col[0]-26;
col2[1]= col[1]<26?0:col[1]-26;
col2[2]= col[2]>209?255:col[2]+46;
}
}
static void drawgrid(ARegion *ar, View3D *v3d)
{
/* extern short bgpicmode; */
@@ -365,15 +344,15 @@ static void drawgrid(ARegion *ar, View3D *v3d)
/* center cross */
if( ELEM(rv3d->view, V3D_VIEW_RIGHT, V3D_VIEW_LEFT))
make_axis_color(col, col2, 'y');
else make_axis_color(col, col2, 'x');
UI_make_axis_color(col, col2, 'y');
else UI_make_axis_color(col, col2, 'x');
glColor3ubv((GLubyte *)col2);
fdrawline(0.0, y, (float)ar->winx, y);
if( ELEM(rv3d->view, V3D_VIEW_TOP, V3D_VIEW_BOTTOM))
make_axis_color(col, col2, 'y');
else make_axis_color(col, col2, 'z');
UI_make_axis_color(col, col2, 'y');
else UI_make_axis_color(col, col2, 'z');
glColor3ubv((GLubyte *)col2);
fdrawline(x, 0.0, x, (float)ar->winy);
@@ -412,7 +391,7 @@ static void drawfloor(Scene *scene, View3D *v3d)
if(a==0) {
/* check for the 'show Y axis' preference */
if (v3d->gridflag & V3D_SHOW_Y) {
make_axis_color(col, col2, 'y');
UI_make_axis_color(col, col2, 'y');
glColor3ubv((GLubyte *)col2);
draw_line = 1;
@@ -451,7 +430,7 @@ static void drawfloor(Scene *scene, View3D *v3d)
if(a==0) {
/* check for the 'show X axis' preference */
if (v3d->gridflag & V3D_SHOW_X) {
make_axis_color(col, col2, 'x');
UI_make_axis_color(col, col2, 'x');
glColor3ubv((GLubyte *)col2);
draw_line = 1;
@@ -488,7 +467,7 @@ static void drawfloor(Scene *scene, View3D *v3d)
/* draw the Z axis line */
/* check for the 'show Z axis' preference */
if (v3d->gridflag & V3D_SHOW_Z) {
make_axis_color(col, col2, 'z');
UI_make_axis_color(col, col2, 'z');
glColor3ubv((GLubyte *)col2);
glBegin(GL_LINE_STRIP);
@@ -567,7 +546,7 @@ static void draw_view_axis(RegionView3D *rv3d)
vec[1] = vec[2] = 0;
QuatMulVecf(rv3d->viewquat, vec);
make_axis_color((char *)gridcol, (char *)col, 'x');
UI_make_axis_color((char *)gridcol, (char *)col, 'x');
rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
s = s<0.5 ? s+0.5 : 1.0;
v = 0.3;
@@ -588,7 +567,7 @@ static void draw_view_axis(RegionView3D *rv3d)
vec[0] = vec[2] = 0;
QuatMulVecf(rv3d->viewquat, vec);
make_axis_color((char *)gridcol, (char *)col, 'y');
UI_make_axis_color((char *)gridcol, (char *)col, 'y');
rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
s = s<0.5 ? s+0.5 : 1.0;
v = 0.3;
@@ -609,7 +588,7 @@ static void draw_view_axis(RegionView3D *rv3d)
vec[1] = vec[0] = 0;
QuatMulVecf(rv3d->viewquat, vec);
make_axis_color((char *)gridcol, (char *)col, 'z');
UI_make_axis_color((char *)gridcol, (char *)col, 'z');
rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
s = s<0.5 ? s+0.5 : 1.0;
v = 0.5;

View File

@@ -99,7 +99,6 @@ void draw_depth(Scene *scene, struct ARegion *ar, View3D *v3d, int (* func)(void
void view3d_clr_clipping(void);
void view3d_set_clipping(RegionView3D *rv3d);
void add_view3d_after(View3D *v3d, Base *base, int type, int flag);
void make_axis_color(char *col, char *col2, char axis);
void calc_viewborder(Scene *scene, struct ARegion *ar, View3D *v3d, rctf *viewborder_r);
void circf(float x, float y, float rad);

View File

@@ -111,54 +111,14 @@
#include "PIL_time.h" /* sleep */
#include "UI_resources.h"
//#include "blendef.h"
//
//#include "mydevice.h"
#include "transform.h"
/* ************************** Dashed help line **************************** */
/* bad frontbuffer call... because it is used in transform after force_draw() */
static void helpline(TransInfo *t, float *vec)
{
#if 0 // TRANSFORM_FIX_ME
float vecrot[3], cent[2];
short mval[2];
VECCOPY(vecrot, vec);
if(t->flag & T_EDIT) {
Object *ob= t->obedit;
if(ob) Mat4MulVecfl(ob->obmat, vecrot);
}
else if(t->flag & T_POSE) {
Object *ob=t->poseobj;
if(ob) Mat4MulVecfl(ob->obmat, vecrot);
}
getmouseco_areawin(mval);
projectFloatView(t, vecrot, cent); // no overflow in extreme cases
persp(PERSP_WIN);
glDrawBuffer(GL_FRONT);
BIF_ThemeColor(TH_WIRE);
setlinestyle(3);
glBegin(GL_LINE_STRIP);
glVertex2sv(mval);
glVertex2fv(cent);
glEnd();
setlinestyle(0);
persp(PERSP_VIEW);
bglFlush(); // flush display for frontbuffer
glDrawBuffer(GL_BACK);
#endif
}
/* ************************** SPACE DEPENDANT CODE **************************** */
void setTransformViewMatrices(TransInfo *t)
@@ -936,6 +896,231 @@ int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float
return success;
}
typedef enum {
UP,
DOWN,
LEFT,
RIGHT
} ArrowDirection;
static void drawArrow(ArrowDirection d, short offset, short length, short size)
{
switch(d)
{
case LEFT:
offset = -offset;
length = -length;
size = -size;
case RIGHT:
glBegin(GL_LINES);
glVertex2s( offset, 0);
glVertex2s( offset + length, 0);
glVertex2s( offset + length, 0);
glVertex2s( offset + length - size, -size);
glVertex2s( offset + length, 0);
glVertex2s( offset + length - size, size);
glEnd();
break;
case DOWN:
offset = -offset;
length = -length;
size = -size;
case UP:
glBegin(GL_LINES);
glVertex2s( 0, offset);
glVertex2s( 0, offset + length);
glVertex2s( 0, offset + length);
glVertex2s(-size, offset + length - size);
glVertex2s( 0, offset + length);
glVertex2s( size, offset + length - size);
glEnd();
break;
}
}
static void drawArrowHead(ArrowDirection d, short size)
{
switch(d)
{
case LEFT:
size = -size;
case RIGHT:
glBegin(GL_LINES);
glVertex2s( 0, 0);
glVertex2s( -size, -size);
glVertex2s( 0, 0);
glVertex2s( -size, size);
glEnd();
break;
case DOWN:
size = -size;
case UP:
glBegin(GL_LINES);
glVertex2s( 0, 0);
glVertex2s(-size, -size);
glVertex2s( 0, 0);
glVertex2s( size, -size);
glEnd();
break;
}
}
static void drawArc(float size, float angle_start, float angle_end, int segments)
{
float delta = (angle_end - angle_start) / segments;
float angle;
glBegin(GL_LINE_STRIP);
for( angle = angle_start; angle < angle_end; angle += delta)
{
glVertex2f( cosf(angle) * size, sinf(angle) * size);
}
glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
glEnd();
}
void drawHelpline(const struct bContext *C, TransInfo *t)
{
if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
{
float vecrot[3], cent[2];
VECCOPY(vecrot, t->center);
if(t->flag & T_EDIT) {
Object *ob= t->obedit;
if(ob) Mat4MulVecfl(ob->obmat, vecrot);
}
else if(t->flag & T_POSE) {
Object *ob=t->poseobj;
if(ob) Mat4MulVecfl(ob->obmat, vecrot);
}
projectFloatView(t, vecrot, cent); // no overflow in extreme cases
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
ED_region_pixelspace(t->ar);
switch(t->helpline)
{
case HLP_SPRING:
UI_ThemeColor(TH_WIRE);
setlinestyle(3);
glBegin(GL_LINE_STRIP);
glVertex2sv(t->mval);
glVertex2fv(cent);
glEnd();
glTranslatef(t->mval[0], t->mval[1], 0);
glRotatef(-180 / M_PI * atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1]), 0, 0, 1);
setlinestyle(0);
glLineWidth(3.0);
drawArrow(UP, 5, 10, 5);
drawArrow(DOWN, 5, 10, 5);
glLineWidth(1.0);
break;
case HLP_HARROW:
UI_ThemeColor(TH_WIRE);
glTranslatef(t->mval[0], t->mval[1], 0);
glLineWidth(3.0);
drawArrow(RIGHT, 5, 10, 5);
drawArrow(LEFT, 5, 10, 5);
glLineWidth(1.0);
break;
case HLP_VARROW:
UI_ThemeColor(TH_WIRE);
glTranslatef(t->mval[0], t->mval[1], 0);
glLineWidth(3.0);
glBegin(GL_LINES);
drawArrow(UP, 5, 10, 5);
drawArrow(DOWN, 5, 10, 5);
glLineWidth(1.0);
break;
case HLP_ANGLE:
{
float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
float angle = atan2f(dy, dx);
float dist = sqrtf(dx*dx + dy*dy);
float delta_angle = MIN2(15 / dist, M_PI/4);
float spacing_angle = MIN2(5 / dist, M_PI/12);
UI_ThemeColor(TH_WIRE);
setlinestyle(3);
glBegin(GL_LINE_STRIP);
glVertex2sv(t->mval);
glVertex2fv(cent);
glEnd();
glTranslatef(cent[0], cent[1], 0);
setlinestyle(0);
glLineWidth(3.0);
drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
glPushMatrix();
glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1);
drawArrowHead(DOWN, 5);
glPopMatrix();
glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
glRotatef(180 / M_PI * (angle + delta_angle), 0, 0, 1);
drawArrowHead(UP, 5);
glLineWidth(1.0);
break;
}
case HLP_TRACKBALL:
{
char col[3], col2[3];
UI_GetThemeColor3ubv(TH_GRID, col);
glTranslatef(t->mval[0], t->mval[1], 0);
glLineWidth(3.0);
UI_make_axis_color(col, col2, 'x');
glColor3ubv((GLubyte *)col2);
drawArrow(RIGHT, 5, 10, 5);
drawArrow(LEFT, 5, 10, 5);
UI_make_axis_color(col, col2, 'y');
glColor3ubv((GLubyte *)col2);
drawArrow(UP, 5, 10, 5);
drawArrow(DOWN, 5, 10, 5);
glLineWidth(1.0);
break;
}
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
}
}
void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
{
TransInfo *t = arg;
@@ -943,6 +1128,7 @@ void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
drawConstraint(C, t);
drawPropCircle(C, t);
drawSnapping(C, t);
drawHelpline(C, t);
}
void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
@@ -1813,7 +1999,7 @@ void initWarp(TransInfo *t)
t->snap[2] = 1.0f;
t->flag |= T_NO_CONSTRAINT;
/* we need min/max in view space */
for(i = 0; i < t->total; i++) {
float center[3];
@@ -1949,8 +2135,6 @@ int Warp(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
helpline(t, gcursor);
return 1;
}
@@ -2071,8 +2255,6 @@ int Shear(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
helpline (t, t->center);
return 1;
}
@@ -2349,8 +2531,6 @@ int Resize(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
return 1;
}
@@ -2374,7 +2554,7 @@ void initToSphere(TransInfo *t)
t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
t->flag |= T_NO_CONSTRAINT;
// Calculate average radius
for(i = 0 ; i < t->total; i++, td++) {
t->val += VecLenf(t->center, td->iloc);
@@ -2776,8 +2956,6 @@ int Rotation(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
return 1;
}
@@ -2883,8 +3061,6 @@ int Trackball(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
return 1;
}
@@ -3230,8 +3406,6 @@ int Tilt(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
helpline (t, t->center);
return 1;
}
@@ -3296,8 +3470,6 @@ int CurveShrinkFatten(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
return 1;
}
@@ -3569,8 +3741,6 @@ int BevelWeight(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
helpline (t, t->center);
return 1;
}
@@ -3645,8 +3815,6 @@ int Crease(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
helpline (t, t->center);
return 1;
}
@@ -3762,8 +3930,6 @@ int BoneSize(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
return 1;
}
@@ -3830,8 +3996,6 @@ int BoneEnvelope(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
return 1;
}
@@ -3896,8 +4060,6 @@ int BoneRoll(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
return 1;
}
@@ -3974,8 +4136,6 @@ int BakeTime(TransInfo *t, short mval[2])
ED_area_headerprint(t->sa, str);
helpline (t, t->center);
return 1;
}
@@ -4506,6 +4666,7 @@ void initTimeScale(TransInfo *t)
t->transform = TimeScale;
initMouseInputMode(t, &t->mouse, INPUT_NONE);
t->helpline = HLP_SPRING; /* set manually because we don't use a predefined input */
t->flag |= T_NULL_ONE;
t->num.flag |= NUM_NULL_ONE;

View File

@@ -232,6 +232,7 @@ typedef struct TransInfo {
short persp;
short around;
char spacetype; /* spacetype where transforming is */
char helpline; /* helpline modes (not to be confused with hotline) */
float vec[3]; /* translation, to show for widget */
float mat[3][3]; /* rot/rescale, to show for widget */
@@ -325,6 +326,14 @@ typedef struct TransInfo {
/* ******************************************************************************** */
/* transinfo->helpline */
#define HLP_NONE 0
#define HLP_SPRING 1
#define HLP_ANGLE 2
#define HLP_HARROW 3
#define HLP_VARROW 4
#define HLP_TRACKBALL 5
/* transinfo->con->mode */
#define CON_APPLY 1
#define CON_AXIS0 2

View File

@@ -620,7 +620,6 @@ void recalcData(TransInfo *t)
void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
{
extern void make_axis_color(char *col, char *col2, char axis); // view3d_draw.c
float v1[3], v2[3], v3[3];
char col[3], col2[3];
@@ -645,7 +644,7 @@ void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
else {
UI_GetThemeColor3ubv(TH_GRID, col);
}
make_axis_color(col, col2, axis);
UI_make_axis_color(col, col2, axis);
glColor3ubv((GLubyte *)col2);
setlinestyle(0);
@@ -684,6 +683,8 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
t->data = NULL;
t->ext = NULL;
t->helpline = HLP_NONE;
t->flag = 0;
t->redraw = 1; /* redraw first time */

View File

@@ -251,35 +251,44 @@ void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
{
case INPUT_VECTOR:
mi->apply = InputVector;
t->helpline = HLP_NONE;
break;
case INPUT_SPRING:
calcSpringFactor(mi);
mi->apply = InputSpring;
t->helpline = HLP_SPRING;
break;
case INPUT_SPRING_FLIP:
calcSpringFactor(mi);
mi->apply = InputSpringFlip;
t->helpline = HLP_SPRING;
break;
case INPUT_ANGLE:
mi->apply = InputAngle;
t->helpline = HLP_ANGLE;
break;
case INPUT_TRACKBALL:
/* factor has to become setting or so */
mi->factor = 0.1f;
mi->apply = InputTrackBall;
t->helpline = HLP_TRACKBALL;
break;
case INPUT_HORIZONTAL_RATIO:
mi->factor = (float)(mi->center[0] - mi->imval[0]);
mi->apply = InputHorizontalRatio;
t->helpline = HLP_HARROW;
break;
case INPUT_HORIZONTAL_ABSOLUTE:
mi->apply = InputHorizontalAbsolute;
t->helpline = HLP_HARROW;
break;
case INPUT_VERTICAL_RATIO:
mi->apply = InputVerticalRatio;
t->helpline = HLP_VARROW;
break;
case INPUT_VERTICAL_ABSOLUTE:
mi->apply = InputVerticalAbsolute;
t->helpline = HLP_VARROW;
break;
case INPUT_NONE:
default: