void ED_mask_get_aspect(ScrArea *sa, ARegion *UNUSED(ar), float *aspx, float *aspy) { if (sa && sa->spacedata.first) { switch (sa->spacetype) { case SPACE_CLIP: { SpaceClip *sc = sa->spacedata.first; ED_space_clip_get_aspect(sc, aspx, aspy); break; } case SPACE_SEQ: { *aspx = *aspy = 1.0f; /* MASKTODO - render aspect? */ break; } case SPACE_IMAGE: { SpaceImage *sima = sa->spacedata.first; ED_space_image_get_aspect(sima, aspx, aspy); break; } default: /* possible other spaces from which mask editing is available */ BLI_assert(0); *aspx = *aspy = 1.0f; break; } } else { BLI_assert(0); *aspx = *aspy = 1.0f; } }
/* called from drawview.c, as an extra per-window draw option */ void drawPropCircle(const struct bContext *C, TransInfo *t) { if (t->flag & T_PROP_EDIT) { RegionView3D *rv3d = CTX_wm_region_view3d(C); float tmat[4][4], imat[4][4]; float center[3]; int depth_test_enabled; UI_ThemeColor(TH_GRID); if (t->spacetype == SPACE_VIEW3D && rv3d != NULL) { copy_m4_m4(tmat, rv3d->viewmat); invert_m4_m4(imat, tmat); } else { unit_m4(tmat); unit_m4(imat); } glPushMatrix(); copy_v3_v3(center, t->center); if ((t->spacetype == SPACE_VIEW3D) && t->obedit) { mul_m4_v3(t->obedit->obmat, center); /* because t->center is in local space */ } else if (t->spacetype == SPACE_IMAGE) { float aspx, aspy; if (t->options & CTX_MASK) { /* untested - mask aspect is TODO */ ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy); } else { ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); } glScalef(1.0f / aspx, 1.0f / aspy, 1.0); } depth_test_enabled = glIsEnabled(GL_DEPTH_TEST); if (depth_test_enabled) glDisable(GL_DEPTH_TEST); set_inverted_drawing(1); drawcircball(GL_LINE_LOOP, center, t->prop_size, imat); set_inverted_drawing(0); if (depth_test_enabled) glEnable(GL_DEPTH_TEST); glPopMatrix(); } }
void ED_mask_pixelspace_factor(ScrArea *sa, ARegion *ar, float *scalex, float *scaley) { if (sa && sa->spacedata.first) { switch (sa->spacetype) { case SPACE_CLIP: { SpaceClip *sc = sa->spacedata.first; float aspx, aspy; UI_view2d_getscale(&ar->v2d, scalex, scaley); ED_space_clip_get_aspect(sc, &aspx, &aspy); *scalex *= aspx; *scaley *= aspy; break; } case SPACE_SEQ: { *scalex = *scaley = 1.0f; /* MASKTODO? */ break; } case SPACE_IMAGE: { SpaceImage *sima = sa->spacedata.first; float aspx, aspy; UI_view2d_getscale(&ar->v2d, scalex, scaley); ED_space_image_get_aspect(sima, &aspx, &aspy); *scalex *= aspx; *scaley *= aspy; break; } default: /* possible other spaces from which mask editing is available */ BLI_assert(0); *scalex = *scaley = 1.0f; break; } } else { BLI_assert(0); *scalex = *scaley = 1.0f; } }
void ED_space_image_get_uv_aspect(SpaceImage *sima, float *aspx, float *aspy) { int w, h; ED_space_image_get_aspect(sima, aspx, aspy); ED_space_image_get_size(sima, &w, &h); *aspx *= (float)w; *aspy *= (float)h; if (*aspx < *aspy) { *aspy = *aspy / *aspx; *aspx = 1.0f; } else { *aspx = *aspx / *aspy; *aspy = 1.0f; } }
void drawSnapping(const struct bContext *C, TransInfo *t) { unsigned char col[4], selectedCol[4], activeCol[4]; if (!activeSnap(t)) return; UI_GetThemeColor3ubv(TH_TRANSFORM, col); col[3] = 128; UI_GetThemeColor3ubv(TH_SELECT, selectedCol); selectedCol[3] = 128; UI_GetThemeColor3ubv(TH_ACTIVE, activeCol); activeCol[3] = 192; if (t->spacetype == SPACE_VIEW3D) { if (validSnap(t)) { TransSnapPoint *p; View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); float imat[4][4]; float size; glDisable(GL_DEPTH_TEST); size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE); invert_m4_m4(imat, rv3d->viewmat); for (p = t->tsnap.points.first; p; p = p->next) { if (p == t->tsnap.selectedPoint) { glColor4ubv(selectedCol); } else { glColor4ubv(col); } drawcircball(GL_LINE_LOOP, p->co, ED_view3d_pixel_size(rv3d, p->co) * size * 0.75f, imat); } if (t->tsnap.status & POINT_INIT) { glColor4ubv(activeCol); drawcircball(GL_LINE_LOOP, t->tsnap.snapPoint, ED_view3d_pixel_size(rv3d, t->tsnap.snapPoint) * size, imat); } /* draw normal if needed */ if (usingSnappingNormal(t) && validSnappingNormal(t)) { glColor4ubv(activeCol); glBegin(GL_LINES); glVertex3f(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]); glVertex3f(t->tsnap.snapPoint[0] + t->tsnap.snapNormal[0], t->tsnap.snapPoint[1] + t->tsnap.snapNormal[1], t->tsnap.snapPoint[2] + t->tsnap.snapNormal[2]); glEnd(); } if (v3d->zbuf) glEnable(GL_DEPTH_TEST); } } else if (t->spacetype == SPACE_IMAGE) { if (validSnap(t)) { /* This will not draw, and Im nor sure why - campbell */ #if 0 float xuser_asp, yuser_asp; int wi, hi; float w, h; calc_image_view(G.sima, 'f'); // float myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax); glLoadIdentity(); ED_space_image_get_aspect(t->sa->spacedata.first, &xuser_aspx, &yuser_asp); ED_space_image_width(t->sa->spacedata.first, &wi, &hi); w = (((float)wi) / IMG_SIZE_FALLBACK) * G.sima->zoom * xuser_asp; h = (((float)hi) / IMG_SIZE_FALLBACK) * G.sima->zoom * yuser_asp; cpack(0xFFFFFF); glTranslate2fv(t->tsnap.snapPoint); //glRectf(0, 0, 1, 1); setlinestyle(0); cpack(0x0); fdrawline(-0.020 / w, 0, -0.1 / w, 0); fdrawline(0.1 / w, 0, 0.020 / w, 0); fdrawline(0, -0.020 / h, 0, -0.1 / h); fdrawline(0, 0.1 / h, 0, 0.020 / h); glTranslatef(-t->tsnap.snapPoint[0], -t->tsnap.snapPoint[1], 0.0f); setlinestyle(0); #endif } } else if (t->spacetype == SPACE_NODE) { if (validSnap(t)) { ARegion *ar = CTX_wm_region(C); TransSnapPoint *p; float size; size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE); glEnable(GL_BLEND); for (p = t->tsnap.points.first; p; p = p->next) { if (p == t->tsnap.selectedPoint) { glColor4ubv(selectedCol); } else { glColor4ubv(col); } ED_node_draw_snap(&ar->v2d, p->co, size, 0); } if (t->tsnap.status & POINT_INIT) { glColor4ubv(activeCol); ED_node_draw_snap(&ar->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder); } glDisable(GL_BLEND); } } }