Fix [#21711] Position of 2d cursor is not displayed correctly and cannot be set

in uv/image editor properties panel

Note: Moved UV editor 2d cursor to SpaceImage rather than View2d, so it's 
more accessible to RNA.
This commit is contained in:
2010-03-30 05:52:05 +00:00
parent 5089663962
commit b09ee4923d
9 changed files with 71 additions and 74 deletions

View File

@@ -458,6 +458,9 @@ class IMAGE_PT_view_properties(bpy.types.Panel):
if show_uvedit:
col = layout.column()
col.prop(uvedit, "cursor_location")
col = layout.column()
col.label(text="UVs:")
row = col.row()

View File

@@ -1286,11 +1286,6 @@ float *editmesh_get_mirror_uv(int axis, float *uv, float *mirrCent, float *face_
cent_vec[1] = face_cent[1];
}
/*
G.v2d->cursor[0] = mirrCent[0];
G.v2d->cursor[1] = mirrCent[1];
*/
/* TODO - Optimize */
{
EditFace *efa;

View File

@@ -81,7 +81,6 @@
#define B_REDR 1
#define B_IMAGECHANGED 2
#define B_TRANS_IMAGE 3
#define B_CURSOR_IMAGE 4
#define B_NOP 0
#define B_TWINANIM 5
#define B_SIMAGETILE 6
@@ -109,7 +108,6 @@ static int simaUVSel_Check() {return 0;}
/* proto */
static void image_editvertex_buts(const bContext *C, uiBlock *block);
static void image_editcursor_buts(const bContext *C, View2D *v2d, uiBlock *block);
static void do_image_panel_events(bContext *C, void *arg, int event)
@@ -123,9 +121,6 @@ static void do_image_panel_events(bContext *C, void *arg, int event)
case B_TRANS_IMAGE:
image_editvertex_buts(C, NULL);
break;
case B_CURSOR_IMAGE:
image_editcursor_buts(C, &ar->v2d, NULL);
break;
}
/* all events now */
@@ -316,41 +311,6 @@ static void image_editvertex_buts(const bContext *C, uiBlock *block)
/* is used for both read and write... */
static void image_editcursor_buts(const bContext *C, View2D *v2d, uiBlock *block)
{
SpaceImage *sima= CTX_wm_space_image(C);
static float ocent[2];
int imx= 256, imy= 256;
int step, digits;
image_transform_but_attr(sima, &imx, &imy, &step, &digits);
if(block) { // do the buttons
ocent[0]= v2d->cursor[0];
ocent[1]= v2d->cursor[1];
if (sima->flag & SI_COORDFLOATS) {
} else {
ocent[0] *= imx;
ocent[1] *= imy;
}
uiBlockBeginAlign(block);
uiDefButF(block, NUM, B_CURSOR_IMAGE, "Cursor X:", 165, 120, 145, 19, &ocent[0], -10*imx, 10.0*imx, step, digits, "");
uiDefButF(block, NUM, B_CURSOR_IMAGE, "Cursor Y:", 165, 100, 145, 19, &ocent[1], -10*imy, 10.0*imy, step, digits, "");
uiBlockEndAlign(block);
}
else { // apply event
if (sima->flag & SI_COORDFLOATS) {
v2d->cursor[0]= ocent[0];
v2d->cursor[1]= ocent[1];
}
else {
v2d->cursor[0]= ocent[0]/imx;
v2d->cursor[1]= ocent[1]/imy;
}
WM_event_add_notifier(C, NC_IMAGE, sima->image);
}
}
static int image_panel_poll(const bContext *C, PanelType *pt)
{
@@ -1002,19 +962,20 @@ static void image_panel_uv(const bContext *C, Panel *pa)
uiBlockSetHandleFunc(block, do_image_panel_events, NULL);
image_editvertex_buts(C, block);
image_editcursor_buts(C, &ar->v2d, block);
}
void image_buttons_register(ARegionType *art)
{
PanelType *pt;
/* editvertex_buts not working atm
pt= MEM_callocN(sizeof(PanelType), "spacetype image panel uv");
strcpy(pt->idname, "IMAGE_PT_uv");
strcpy(pt->label, "UV");
pt->draw= image_panel_uv;
pt->poll= image_panel_uv_poll;
BLI_addtail(&art->paneltypes, pt);
*/
pt= MEM_callocN(sizeof(PanelType), "spacetype image panel curves");
strcpy(pt->idname, "IMAGE_PT_curves");

View File

@@ -1223,13 +1223,18 @@ void calculateCenterCursor2D(TransInfo *t)
{
View2D *v2d= t->view;
float aspx=1.0, aspy=1.0;
float *cursor;
if(t->spacetype==SPACE_IMAGE) /* only space supported right now but may change */
ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
if(t->spacetype==SPACE_IMAGE) {
SpaceImage *sima= (SpaceImage *)t->sa->spacedata.first;
/* only space supported right now but may change */
ED_space_image_uv_aspect(sima, &aspx, &aspy);
cursor = sima->cursor;
}
if (v2d) {
t->center[0] = v2d->cursor[0] * aspx;
t->center[1] = v2d->cursor[1] * aspy;
t->center[0] = cursor[0] * aspx;
t->center[1] = cursor[1] * aspy;
}
calculateCenter2D(t);

View File

@@ -56,7 +56,6 @@
static void drawcursor_sima(SpaceImage *sima, ARegion *ar)
{
View2D *v2d= &ar->v2d;
float zoomx, zoomy, w, h;
int width, height;
@@ -67,7 +66,7 @@ static void drawcursor_sima(SpaceImage *sima, ARegion *ar)
h= zoomy*height/256.0f;
cpack(0xFFFFFF);
glTranslatef(v2d->cursor[0], v2d->cursor[1], 0.0f);
glTranslatef(sima->cursor[0], sima->cursor[1], 0.0f);
fdrawline(-0.05/w, 0, 0, 0.05/h);
fdrawline(0, 0.05/h, 0.05/w, 0);
fdrawline(0.05/w, 0, 0, -0.05/h);
@@ -95,7 +94,7 @@ static void drawcursor_sima(SpaceImage *sima, ARegion *ar)
fdrawline(0, -0.020/h, 0, -0.1/h);
fdrawline(0, 0.1/h, 0, 0.020/h);
glTranslatef(-v2d->cursor[0], -v2d->cursor[1], 0.0f);
glTranslatef(-sima->cursor[0], -sima->cursor[1], 0.0f);
setlinestyle(0);
}

View File

@@ -2357,17 +2357,17 @@ static void snap_uv_to_pixel(float *uvco, float w, float h)
uvco[1] = ((float)((int)((uvco[1]*h) + 0.5f)))/h;
}
static void snap_cursor_to_pixels(SpaceImage *sima, View2D *v2d)
static void snap_cursor_to_pixels(SpaceImage *sima)
{
int width= 0, height= 0;
ED_space_image_size(sima, &width, &height);
snap_uv_to_pixel(v2d->cursor, width, height);
snap_uv_to_pixel(sima->cursor, width, height);
}
static int snap_cursor_to_selection(Scene *scene, Image *ima, Object *obedit, View2D *v2d)
static int snap_cursor_to_selection(Scene *scene, Image *ima, Object *obedit, SpaceImage *sima)
{
return uvedit_center(scene, ima, obedit, v2d->cursor, 0);
return uvedit_center(scene, ima, obedit, sima->cursor, 0);
}
static int snap_cursor_exec(bContext *C, wmOperator *op)
@@ -2376,23 +2376,22 @@ static int snap_cursor_exec(bContext *C, wmOperator *op)
Scene *scene= CTX_data_scene(C);
Object *obedit= CTX_data_edit_object(C);
Image *ima= CTX_data_edit_image(C);
ARegion *ar= CTX_wm_region(C);
int change= 0;
switch(RNA_boolean_get(op->ptr, "target")) {
case 0:
snap_cursor_to_pixels(sima, &ar->v2d);
snap_cursor_to_pixels(sima);
change= 1;
break;
case 1:
change= snap_cursor_to_selection(scene, ima, obedit, &ar->v2d);
change= snap_cursor_to_selection(scene, ima, obedit, sima);
break;
}
if(!change)
return OPERATOR_CANCELLED;
ED_region_tag_redraw(ar);
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_IMAGE, sima);
return OPERATOR_FINISHED;
}
@@ -2420,7 +2419,7 @@ void UV_OT_snap_cursor(wmOperatorType *ot)
/* ******************** snap selection operator **************** */
static int snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, View2D *v2d)
static int snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, SpaceImage *sima)
{
EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
EditFace *efa;
@@ -2430,11 +2429,11 @@ static int snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, View2D *
for(efa= em->faces.first; efa; efa= efa->next) {
tface= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if(uvedit_face_visible(scene, ima, efa, tface)) {
if(uvedit_uv_selected(scene, efa, tface, 0)) VECCOPY2D(tface->uv[0], v2d->cursor);
if(uvedit_uv_selected(scene, efa, tface, 1)) VECCOPY2D(tface->uv[1], v2d->cursor);
if(uvedit_uv_selected(scene, efa, tface, 2)) VECCOPY2D(tface->uv[2], v2d->cursor);
if(uvedit_uv_selected(scene, efa, tface, 0)) VECCOPY2D(tface->uv[0], sima->cursor);
if(uvedit_uv_selected(scene, efa, tface, 1)) VECCOPY2D(tface->uv[1], sima->cursor);
if(uvedit_uv_selected(scene, efa, tface, 2)) VECCOPY2D(tface->uv[2], sima->cursor);
if(efa->v4)
if(uvedit_uv_selected(scene, efa, tface, 3)) VECCOPY2D(tface->uv[3], v2d->cursor);
if(uvedit_uv_selected(scene, efa, tface, 3)) VECCOPY2D(tface->uv[3], sima->cursor);
change= 1;
}
@@ -2614,7 +2613,6 @@ static int snap_selection_exec(bContext *C, wmOperator *op)
Scene *scene= CTX_data_scene(C);
Object *obedit= CTX_data_edit_object(C);
Image *ima= CTX_data_edit_image(C);
ARegion *ar= CTX_wm_region(C);
int change= 0;
switch(RNA_boolean_get(op->ptr, "target")) {
@@ -2622,7 +2620,7 @@ static int snap_selection_exec(bContext *C, wmOperator *op)
change= snap_uvs_to_pixels(sima, scene, obedit);
break;
case 1:
change= snap_uvs_to_cursor(scene, ima, obedit, &ar->v2d);
change= snap_uvs_to_cursor(scene, ima, obedit, sima);
break;
case 2:
change= snap_uvs_to_adjacent_unselected(scene, ima, obedit);
@@ -3038,14 +3036,14 @@ void UV_OT_reveal(wmOperatorType *ot)
static int set_2d_cursor_exec(bContext *C, wmOperator *op)
{
ARegion *ar= CTX_wm_region(C);
SpaceImage *sima = CTX_wm_space_image(C);
float location[2];
RNA_float_get_array(op->ptr, "location", location);
ar->v2d.cursor[0]= location[0];
ar->v2d.cursor[1]= location[1];
sima->cursor[0]= location[0];
sima->cursor[1]= location[1];
ED_area_tag_redraw(CTX_wm_area(C));
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_IMAGE, NULL);
return OPERATOR_FINISHED;
}
@@ -3096,7 +3094,7 @@ static int set_tile_exec(bContext *C, wmOperator *op)
RNA_int_get_array(op->ptr, "tile", tile);
ED_uvedit_set_tile(C, CTX_data_scene(C), CTX_data_edit_object(C), ima, tile[0] + ima->xrep*tile[1]);
ED_area_tag_redraw(CTX_wm_area(C));
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_IMAGE, NULL);
return OPERATOR_FINISHED;
}

View File

@@ -252,6 +252,7 @@ typedef struct SpaceImage {
char sticky; /* sticky selection type */
char dt_uvstretch;
char around;
float cursor[2]; /* UV editor 2d cursor */
float xof, yof; /* user defined offset, image is centered */
float zoom, pad4; /* user defined zoom level */

View File

@@ -58,7 +58,6 @@ typedef struct View2D {
short oldwinx, oldwiny; /* storage of previous winx/winy values encountered by UI_view2d_curRect_validate(), for keepaspect */
short around; /* pivot point for transforms (rotate and scale) */
float cursor[2]; /* only used in the UV view for now (for 2D-cursor) */
float *tab_offset; /* different offset per tab, for buttons */
int tab_num; /* number of tabs stored */

View File

@@ -415,6 +415,36 @@ static EnumPropertyItem *rna_SpaceImageEditor_draw_channels_itemf(bContext *C, P
return item;
}
static void rna_SpaceImageEditor_cursor_location_get(PointerRNA *ptr, float *values)
{
SpaceImage *sima= (SpaceImage*)ptr->data;
if (sima->flag & SI_COORDFLOATS) {
copy_v2_v2(values, sima->cursor);
} else {
int w, h;
ED_space_image_size(sima, &w, &h);
values[0] = sima->cursor[0] * w;
values[1] = sima->cursor[1] * h;
}
}
static void rna_SpaceImageEditor_cursor_location_set(PointerRNA *ptr, const float *values)
{
SpaceImage *sima= (SpaceImage*)ptr->data;
if (sima->flag & SI_COORDFLOATS) {
copy_v2_v2(sima->cursor, values);
} else {
int w, h;
ED_space_image_size(sima, &w, &h);
sima->cursor[0] = values[0] / w;
sima->cursor[1] = values[1] / h;
}
}
static void rna_SpaceImageEditor_curves_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
SpaceImage *sima= (SpaceImage*)ptr->data;
@@ -693,6 +723,12 @@ static void rna_def_space_image_uv(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flag", SI_COORDFLOATS);
RNA_def_property_ui_text(prop, "Normalized Coordinates", "Display UV coordinates from 0.0 to 1.0 rather than in pixels");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, NULL);
prop= RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_NONE);
RNA_def_property_array(prop, 2);
RNA_def_property_float_funcs(prop, "rna_SpaceImageEditor_cursor_location_get", "rna_SpaceImageEditor_cursor_location_set", NULL);
RNA_def_property_ui_text(prop, "2D Cursor Location", "2D cursor location for this view");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, NULL);
/* todo: move edge and face drawing options here from G.f */