Make view translation and zooming 'smooth' in the uv editor. Power-of-two

zoom levels can be found in the View > View Navigation menu. Also Ctrl+MMB
zooming was added.

Added the E-key, LSCM unwrap popup back again.
This commit is contained in:
Brecht Van Lommel 2005-04-24 11:57:23 +00:00
parent 6379ff9b70
commit 0016d29b51
5 changed files with 124 additions and 80 deletions

@ -42,8 +42,8 @@ void drawimagespace(struct ScrArea *sa, void *spacedata);
void draw_tfaces(void);
void image_changed(struct SpaceImage *sima, int dotile);
void image_home(void);
void image_viewmove(void);
void image_viewzoom(unsigned short event);
void image_viewmove(int mode);
void image_viewzoom(unsigned short event, int invert);
void image_viewcentre(void);
void uvco_to_areaco(float *vec, short *mval);
void uvco_to_areaco_noclip(float *vec, short *mval);

@ -215,10 +215,9 @@ typedef struct SpaceImage {
struct Image *image;
float zoom;
float pad2; /* padding is with 8 bytes aligned */
short mode, pin;
short imanr, curtile;
short xof, yof;
float xof, yof;
short flag, lock;
} SpaceImage;

@ -782,7 +782,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
ImBuf *ibuf= NULL;
float col[3];
unsigned int *rect;
int x1, y1, xmin, xmax, ymin, ymax;
int x1, y1;
short sx, sy, dx, dy;
BIF_GetThemeColor3fv(TH_BACK, col);
@ -792,9 +792,6 @@ void drawimagespace(ScrArea *sa, void *spacedata)
bwin_clear_viewmat(sa->win); /* clear buttons view */
glLoadIdentity();
xmin= curarea->winrct.xmin; xmax= curarea->winrct.xmax;
ymin= curarea->winrct.ymin; ymax= curarea->winrct.ymax;
what_image(G.sima);
if(G.sima->image) {
@ -900,80 +897,104 @@ void drawimagespace(ScrArea *sa, void *spacedata)
curarea->win_swap= WIN_BACK_OK;
}
void image_viewmove(void)
static void image_zoom_power_of_two(void)
{
short mval[2], mvalo[2], xof, yof;
/* Make zoom a power of 2 */
G.sima->zoom = 1 / G.sima->zoom;
G.sima->zoom = log(G.sima->zoom) / log(2);
G.sima->zoom = ceil(G.sima->zoom);
G.sima->zoom = pow(2, G.sima->zoom);
G.sima->zoom = 1 / G.sima->zoom;
}
static void image_zoom_set_factor(float zoomfac)
{
SpaceImage *sima= curarea->spacedata.first;
int width, height;
if (zoomfac <= 0.0f)
return;
sima->zoom *= zoomfac;
if (sima->zoom > 0.1f && sima->zoom < 4.0f)
return;
/* check zoom limits */
calc_image_view(G.sima, 'p');
width= 256;
height= 256;
if (sima->image) {
if (sima->image->ibuf) {
width= sima->image->ibuf->x;
height= sima->image->ibuf->y;
}
}
width *= sima->zoom;
height *= sima->zoom;
if ((width < 4) && (height < 4))
sima->zoom /= zoomfac;
else if((curarea->winrct.xmax - curarea->winrct.xmin) <= sima->zoom)
sima->zoom /= zoomfac;
else if((curarea->winrct.ymax - curarea->winrct.ymin) <= sima->zoom)
sima->zoom /= zoomfac;
}
void image_viewmove(int mode)
{
short mval[2], mvalo[2], zoom0;
getmouseco_sc(mvalo);
zoom0= G.sima->zoom;
while(get_mbut()&(L_MOUSE|M_MOUSE)) {
getmouseco_sc(mval);
if(mvalo[0]!=mval[0] || mvalo[1]!=mval[1]) {
xof= (mvalo[0]-mval[0])/G.sima->zoom;
yof= (mvalo[1]-mval[1])/G.sima->zoom;
if(xof || yof) {
G.sima->xof+= xof;
G.sima->yof+= yof;
if(mode==0) {
G.sima->xof += (mvalo[0]-mval[0])/G.sima->zoom;
G.sima->yof += (mvalo[1]-mval[1])/G.sima->zoom;
}
else if (mode==1) {
float factor;
factor= 1.0+(float)(mvalo[0]-mval[0]+mvalo[1]-mval[1])/300.0;
image_zoom_set_factor(factor);
}
mvalo[0]= mval[0];
mvalo[1]= mval[1];
scrarea_do_windraw(curarea);
screen_swapbuffers();
}
}
else BIF_wait_for_statechange();
}
}
void image_viewzoom(unsigned short event)
void image_viewzoom(unsigned short event, int invert)
{
SpaceImage *sima= curarea->spacedata.first;
int width, height;
if(U.uiflag & USER_WHEELZOOMDIR) {
if (event==WHEELDOWNMOUSE || event == PADPLUSKEY) {
sima->zoom *= 2;
} else {
sima->zoom /= 2;
/* Check if the image will still be visible after zooming out */
if (sima->zoom < 1) {
calc_image_view(G.sima, 'p');
if (sima->image) {
if (sima->image->ibuf) {
width = sima->image->ibuf->x * sima->zoom;
height = sima->image->ibuf->y * sima->zoom;
if ((width < 4) && (height < 4)) {
/* Image will become too small, reset value */
sima->zoom *= 2;
}
}
}
}
}
} else {
if (event==WHEELUPMOUSE || event == PADPLUSKEY) {
sima->zoom *= 2;
} else {
sima->zoom /= 2;
/* Check if the image will still be visible after zooming out */
if (sima->zoom < 1) {
calc_image_view(G.sima, 'p');
if (sima->image) {
if (sima->image->ibuf) {
width = sima->image->ibuf->x * sima->zoom;
height = sima->image->ibuf->y * sima->zoom;
if ((width < 4) && (height < 4)) {
/* Image will become too small, reset value */
sima->zoom *= 2;
}
}
}
}
}
}
if(event==WHEELDOWNMOUSE || event==PADMINUS)
image_zoom_set_factor((U.uiflag & USER_WHEELZOOMDIR)? 1.25: 0.8);
else if(event==WHEELUPMOUSE || event==PADPLUSKEY)
image_zoom_set_factor((U.uiflag & USER_WHEELZOOMDIR)? 0.8: 1.25);
else if(event==PAD1)
sima->zoom= 1.0;
else if(event==PAD2)
sima->zoom= (invert)? 2.0: 0.5;
else if(event==PAD4)
sima->zoom= (invert)? 4.0: 0.25;
else if(event==PAD8)
sima->zoom= (invert)? 8.0: 0.125;
else
return;
}
/**
@ -1002,12 +1023,7 @@ void image_home(void)
zoomY = ((float)height) / ((float)G.sima->image->ibuf->y);
G.sima->zoom= MIN2(zoomX, zoomY);
/* Now make it a power of 2 */
G.sima->zoom = 1 / G.sima->zoom;
G.sima->zoom = log(G.sima->zoom) / log(2);
G.sima->zoom = ceil(G.sima->zoom);
G.sima->zoom = pow(2, G.sima->zoom);
G.sima->zoom = 1 / G.sima->zoom;
image_zoom_power_of_two();
}
else {
G.sima->zoom= (float)1;

@ -351,10 +351,31 @@ static void do_image_view_viewnavmenu(void *arg, int event)
{
switch(event) {
case 1: /* Zoom In */
image_viewzoom(PADPLUSKEY);
image_viewzoom(PADPLUSKEY, 0);
break;
case 2: /* Zoom Out */
image_viewzoom(PADMINUS);
image_viewzoom(PADMINUS, 0);
break;
case 3: /* Zoom 8:1 */
image_viewzoom(PAD8, 0);
break;
case 4: /* Zoom 4:1 */
image_viewzoom(PAD4, 0);
break;
case 5: /* Zoom 2:1 */
image_viewzoom(PAD2, 0);
break;
case 6: /* Zoom 1:1 */
image_viewzoom(PAD1, 0);
break;
case 7: /* Zoom 1:2 */
image_viewzoom(PAD2, 1);
break;
case 8: /* Zoom 1:4 */
image_viewzoom(PAD4, 1);
break;
case 9: /* Zoom 1:8 */
image_viewzoom(PAD8, 1);
break;
}
allqueue(REDRAWIMAGE, 0);
@ -372,6 +393,16 @@ static uiBlock *image_view_viewnavmenu(void *arg_unused)
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom In|NumPad +", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom Out|NumPad -", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 1:8", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 1:4", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 1:2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 1:1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 2:1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 4:1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom 8:1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
uiBlockSetDirection(block, UI_RIGHT);
uiTextBoundsBlock(block, 50);
return block;

@ -3751,9 +3751,6 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
if(G.qual & LR_SHIFTKEY) mouseco_to_curtile();
else gesture();
break;
case MIDDLEMOUSE:
image_viewmove();
break;
case RIGHTMOUSE:
if(G.f & G_FACESELECT)
mouse_select_sima();
@ -3779,7 +3776,8 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
toggle_uv_select('f');
break;
case EKEY :
unwrap_lscm();
if(okee("LSCM Unwrap"))
unwrap_lscm();
break;
case GKEY:
if((G.qual==0))
@ -3865,13 +3863,13 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
do_imagebuts(val); // drawimage.c
break;
case MIDDLEMOUSE:
image_viewmove();
if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
image_viewmove(1);
else
image_viewmove(0);
break;
case WHEELUPMOUSE:
case WHEELDOWNMOUSE:
case PADPLUSKEY:
case PADMINUS:
image_viewzoom(event);
case WHEELUPMOUSE: case WHEELDOWNMOUSE: case PADPLUSKEY: case PADMINUS:
image_viewzoom(event, 0);
scrarea_queue_winredraw(curarea);
break;
case HOMEKEY: