use UI_view2d_getscale() to get the scale for image cursor drawing and ED_mask_pixelspace_factor(). - was getting the image width/height when its not needed before.

This commit is contained in:
Campbell Barton 2012-12-14 16:51:02 +00:00
parent bb26d80ad8
commit da7ce6a3cc
4 changed files with 21 additions and 18 deletions

@ -199,6 +199,7 @@ struct View2D *UI_view2d_fromcontext(const struct bContext *C);
struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C); struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C);
void UI_view2d_getscale(struct View2D *v2d, float *x, float *y); void UI_view2d_getscale(struct View2D *v2d, float *x, float *y);
void UI_view2d_getscale_inverse(struct View2D *v2d, float *x, float *y);
short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y); short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y);

@ -2059,6 +2059,12 @@ void UI_view2d_getscale(View2D *v2d, float *x, float *y)
if (x) *x = BLI_rcti_size_x(&v2d->mask) / BLI_rctf_size_x(&v2d->cur); if (x) *x = BLI_rcti_size_x(&v2d->mask) / BLI_rctf_size_x(&v2d->cur);
if (y) *y = BLI_rcti_size_y(&v2d->mask) / BLI_rctf_size_y(&v2d->cur); if (y) *y = BLI_rcti_size_y(&v2d->mask) / BLI_rctf_size_y(&v2d->cur);
} }
/* Same as UI_view2d_getscale() - 1.0f / x, y */
void UI_view2d_getscale_inverse(View2D *v2d, float *x, float *y)
{
if (x) *x = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
if (y) *y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
}
/* Check if mouse is within scrollers /* Check if mouse is within scrollers
* - Returns appropriate code for match * - Returns appropriate code for match

@ -324,15 +324,13 @@ void ED_mask_pixelspace_factor(ScrArea *sa, ARegion *ar, float *scalex, float *s
case SPACE_CLIP: case SPACE_CLIP:
{ {
SpaceClip *sc = sa->spacedata.first; SpaceClip *sc = sa->spacedata.first;
int width, height; float aspx, aspy;
float zoomx, zoomy, aspx, aspy;
ED_space_clip_get_size(sc, &width, &height); UI_view2d_getscale(&ar->v2d, scalex, scaley);
ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
ED_space_clip_get_aspect(sc, &aspx, &aspy); ED_space_clip_get_aspect(sc, &aspx, &aspy);
*scalex = ((float)width * aspx) * zoomx; *scalex *= aspx;
*scaley = ((float)height * aspy) * zoomy; *scaley *= aspy;
break; break;
} }
case SPACE_SEQ: case SPACE_SEQ:
@ -343,15 +341,13 @@ void ED_mask_pixelspace_factor(ScrArea *sa, ARegion *ar, float *scalex, float *s
case SPACE_IMAGE: case SPACE_IMAGE:
{ {
SpaceImage *sima = sa->spacedata.first; SpaceImage *sima = sa->spacedata.first;
int width, height; float aspx, aspy;
float zoomx, zoomy, aspx, aspy;
ED_space_image_get_size(sima, &width, &height); UI_view2d_getscale(&ar->v2d, scalex, scaley);
ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
ED_space_image_get_aspect(sima, &aspx, &aspy); ED_space_image_get_aspect(sima, &aspx, &aspy);
*scalex = ((float)width * aspx) * zoomx; *scalex *= aspx;
*scaley = ((float)height * aspy) * zoomy; *scaley *= aspy;
break; break;
} }
default: default:

@ -61,19 +61,19 @@
#include "UI_resources.h" #include "UI_resources.h"
#include "UI_interface.h" #include "UI_interface.h"
#include "UI_view2d.h"
#include "uvedit_intern.h" #include "uvedit_intern.h"
void draw_image_cursor(SpaceImage *sima, ARegion *ar) void draw_image_cursor(SpaceImage *sima, ARegion *ar)
{ {
float zoomx, zoomy, x_fac, y_fac; float zoom[2], x_fac, y_fac;
int width, height;
ED_space_image_get_size(sima, &width, &height); UI_view2d_getscale_inverse(&ar->v2d, &zoom[0], &zoom[1]);
ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
x_fac = (1.0f / (zoomx * width / 256.0f)) * UI_DPI_FAC; mul_v2_fl(zoom, 256.0f * UI_DPI_FAC);
y_fac = (1.0f / (zoomy * height / 256.0f)) * UI_DPI_FAC; x_fac = zoom[0];
y_fac = zoom[1];
cpack(0xFFFFFF); cpack(0xFFFFFF);
glTranslatef(sima->cursor[0], sima->cursor[1], 0.0); glTranslatef(sima->cursor[0], sima->cursor[1], 0.0);