fix for [#8359] Sequencer image preview: HOME hotkey zooming at output res, not at "full view"

also made image and sequencer account for aspect ratio and added numpad 1,2,4,8 keys for zooming.
This commit is contained in:
Campbell Barton 2008-05-09 20:08:28 +00:00
parent a7a9c74ccb
commit 76c13cc0f7
7 changed files with 85 additions and 35 deletions

@ -96,7 +96,7 @@ float CalcNormFloat4(float *v1, float *v2, float *v3, float *v4, float *n);
void CalcNormLong(int *v1, int *v2, int *v3, float *n);
/* CalcNormShort: is ook uitprodukt - (translates as 'is also out/cross product') */
void CalcNormShort(short *v1, short *v2, short *v3, float *n);
float power_of_2(float val);
/**
* @section Euler conversion routines

@ -4345,3 +4345,8 @@ void tangent_from_uv(float *uv1, float *uv2, float *uv3, float *co1, float *co2,
if ((ct[0]*n[0] + ct[1]*n[1] + ct[2]*n[2]) < 0.0f)
VecMulf(tang, -1.0f);
}
/* used for zoom values*/
float power_of_2(float val) {
return pow(2, ceil(log(val) / log(2)));
}

@ -39,5 +39,7 @@ void set_special_seq_update(int val);
void seq_viewmove(SpaceSeq *sseq);
void seq_reset_imageofs(SpaceSeq *sseq);
void seq_viewzoom(unsigned short event, int invert);
void seq_home(void);
#endif

@ -2349,17 +2349,6 @@ void drawimagespace(ScrArea *sa, void *spacedata)
sa->win_swap= WIN_BACK_OK;
}
static void image_zoom_power_of_two(void)
{
/* 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;
@ -2503,8 +2492,10 @@ void image_home(void)
imgheight = 256;
}
else {
imgwidth = ibuf->x;
imgheight = ibuf->y;
float xuser_asp, yuser_asp;
image_pixel_aspect(G.sima->image, &xuser_asp, &yuser_asp);
imgwidth = ibuf->x * xuser_asp;
imgheight = ibuf->y * yuser_asp;
}
/* Check if the image will fit in the image with zoom==1 */
@ -2515,9 +2506,7 @@ void image_home(void)
/* Find the zoom value that will fit the image in the image space */
zoomX = ((float)width) / ((float)imgwidth);
zoomY = ((float)height) / ((float)imgheight);
G.sima->zoom= MIN2(zoomX, zoomY);
image_zoom_power_of_two();
G.sima->zoom = 1.0f / power_of_2(1/ MIN2(zoomX, zoomY) );
}
else {
G.sima->zoom= 1.0f;

@ -913,6 +913,64 @@ void seq_reset_imageofs(SpaceSeq *sseq)
sseq->xof = sseq->yof = sseq->zoom = 0;
}
void seq_home(void)
{
SpaceSeq *sseq= curarea->spacedata.first;
if (!sseq->mainb) {
G.v2d->cur= G.v2d->tot;
test_view2d(G.v2d, curarea->winx, curarea->winy);
view2d_do_locks(curarea, V2D_LOCK_COPY);
} else {
float zoomX, zoomY;
int width, height, imgwidth, imgheight;
width = curarea->winx;
height = curarea->winy;
seq_reset_imageofs(sseq);
imgwidth= (G.scene->r.size*G.scene->r.xsch)/100;
imgheight= (G.scene->r.size*G.scene->r.ysch)/100;
/* Apply aspect, dosnt need to be that accurate */
imgwidth= (int)(imgwidth * ((float)G.scene->r.xasp / (float)G.scene->r.yasp));
if (((imgwidth >= width) || (imgheight >= height)) &&
((width > 0) && (height > 0))) {
/* Find the zoom value that will fit the image in the image space */
zoomX = ((float)width) / ((float)imgwidth);
zoomY = ((float)height) / ((float)imgheight);
sseq->zoom= (zoomX < zoomY) ? zoomX : zoomY;
sseq->zoom = 1.0f / power_of_2(1/ MIN2(zoomX, zoomY) );
}
else {
sseq->zoom= 1.0f;
}
}
scrarea_queue_winredraw(curarea);
}
void seq_viewzoom(unsigned short event, int invert)
{
SpaceSeq *sseq= curarea->spacedata.first;
if(event==PAD1)
sseq->zoom= 1.0;
else if(event==PAD2)
sseq->zoom= (invert)? 2.0: 0.5;
else if(event==PAD4)
sseq->zoom= (invert)? 4.0: 0.25;
else if(event==PAD8)
sseq->zoom= (invert)? 8.0: 0.125;
/* ensure pixel exact locations for draw */
sseq->xof= (int)sseq->xof;
sseq->yof= (int)sseq->yof;
}
void seq_viewmove(SpaceSeq *sseq)
{
ScrArea *sa;

@ -81,7 +81,7 @@ static void do_seq_viewmenu(void *arg, int event)
play_anim(1);
break;
case 3:
do_seq_buttons(B_SEQHOME);
seq_home();
break;
case 4:
if(last_seq) {
@ -450,7 +450,7 @@ static void do_seq_editmenu(void *arg, int event)
seq_mute_sel(0);
break;
case 22:
seq_mute_sel(-1);
seq_mute_sel(0);
break;
case 23:
seq_cut(CFRA, 0);
@ -620,21 +620,13 @@ static uiBlock *seq_markermenu(void *arg_unused)
void do_seq_buttons(short event)
{
Editing *ed;
SpaceSeq *sseq= curarea->spacedata.first;
ed= G.scene->ed;
if(ed==0) return;
switch(event) {
case B_SEQHOME:
if(sseq->mainb)
seq_reset_imageofs(sseq);
else {
G.v2d->cur= G.v2d->tot;
test_view2d(G.v2d, curarea->winx, curarea->winy);
view2d_do_locks(curarea, V2D_LOCK_COPY);
}
scrarea_queue_winredraw(curarea);
case B_HOME:
seq_home();
break;
case B_SEQCLEAR:
free_imbuf_seq();

@ -4909,7 +4909,7 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
break;
case HOMEKEY:
if((G.qual==0))
do_seq_buttons(B_SEQHOME);
seq_home();
break;
case PADPERIOD:
if(last_seq) {
@ -5073,6 +5073,10 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
del_seq();
}
break;
case PAD1: case PAD2: case PAD4: case PAD8:
seq_viewzoom(event, (G.qual & LR_SHIFTKEY)==0);
doredraw= 1;
break;
}
}