delphi - Scaling the TRotLayer -


i'm working on graphics32. , i'm using given component examples, trotlayer. basing on example (examples/layers/rotlayer_ex), created rotlayer scales imgview. if imgview.bitmap not assigned, rotlayer doesn't scale. tinkered source code, changing it's behavior. changed trotlayer.adjusttransformation procedure. here's did.

procedure trotlayer.adjusttransformation; var scalex, scaley, shiftx, shifty: single; begin transformation.clear; transformation.translate(-bitmapcenter.x, -bitmapcenter.y); transformation.rotate(0, 0, angle); transformation.translate(position.x, position.y); transformation.scale(scale.x, scale.y); transformation.translate(shift.x, shift.y); //  if scaled , assigned(layercollection) //    layercollection //    begin //      getviewportscale(scalex, scaley); //      getviewportshift(shiftx, shifty); //      transformation.scale(scalex, scaley); //      transformation.translate(shiftx, shifty); //    end; end; 

i ommitted restriction , executed .scale procedure. passed values scale.x , scale.y , worked expected. image resized problem positioning. image moves or down if scale it's height moves right or left if scale it's width. wanted resize , stay in it's original position. noticed function .translate can possibly fix problem don't know pass in parameters. or don't know how compute values pass.

anyone can me problem. thanks.

pseudo code:

  • calculate original bounds:

    transformation.srcrect := floatrect(0, 0, old.width, old.height);

  • shift origin center of bounds:

    transformation.translate(-0.5 * old.width, -0.5 * old.height);

  • rotate around new origin:

    transformation.rotate(0, 0, degrees);

  • scale

  • calculate new bounds:

    new.bounds := transformation.gettransformedbounds;

  • shift origin (0, 0) of new bounds:

    transformation.translate(0.5 * new.width, 0.5 * new.height);

you might take @ rotate bitmap real angle graphics32 example (without scaling).


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -