ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to align Objects in relation to each other?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
yogiyang Posted - Apr 29 2016 : 05:57:33
Hello,

There is facility to align Layers.

In the same way is there any way to align Selected Objects in relation each other?

I mean can we align objects to:
  • Left
  • Top
  • Right
  • Bottom
  • Center Horizontally
  • Center Vertically


Besides this can I also want to arrange Selected Objects with equal spacing between them.

How can I do this?

TIA


Yogi Yang
4   L A T E S T    R E P L I E S    (Newest First)
w2m Posted - May 02 2016 : 10:28:55
Your current code does not produce the result you are looking for. Your current code aligns all selected objects to the leftmost object position. It looks like you want to align the selected objects to the left of a unselected object.

Is this correct or do you want do to something different?

What should occur if there are more than one unselected object or in your case will there never be more than one unselected object?

Anyway... maybe this will work?

procedure TMainForm.AutoAlign1Click(Sender: TObject);
var
  i: Integer;
  iCurrentLeftMostValue, iFinalLeftMostValue: Integer;
  iObject: integer;
  iIEVStyle : TIEVStyle;
  iUnselectedObjectLeft: integer;
begin
  { Get the position of the unselected object for all selectable objects }
  { This eliminates getting the position of unselectable objects }
  if ImageEnVect1.SelObjectsCount > 1 then
  begin
    iUnselectedObjectLeft := -1;
    for i := 0 to ImageEnVect1.ObjectsCount - 1 do
    begin
      { Get the object from the index }
      iObject := ImageEnVect1.GetObjFromIndex(i);
      iIEVStyle := ImageEnVect1.ObjStyle[iObject];
      if (ImageEnVect1.IsSelObject(iObject) = False) and (ievsSelectable in iIEVStyle) then
        iUnselectedObjectLeft := ImageEnVect1.ObjLeft[iObject];
    end;

    {Get the left most value from selected objects}
    for i := 0 to ImageEnVect1.SelObjectsCount - 1 do
    begin
      iCurrentLeftMostValue := ImageEnVect1.ObjLeft[ImageEnVect1.SelObjects[i]];
      if i = 0 then
        iFinalLeftMostValue := iCurrentLeftMostValue
      else if iFinalLeftMostValue > iCurrentLeftMostValue then
        iFinalLeftMostValue := iCurrentLeftMostValue;
    end;

    { If the unselected object is to the right of the left most value then align the selected objects
    to the unselected object }
    if iUnselectedObjectLeft >= iFinalLeftMostValue then
    { Align all selected objects to left of the unselected object }
    for i := 0 to ImageEnVect1.SelObjectsCount - 1 do
    begin
      { Get the object from the index }
      iObject := ImageEnVect1.GetObjFromIndex(i);
      ImageEnVect1.ObjLeft[ImageEnVect1.SelObjects[iObject]] := iUnselectedObjectLeft - iFinalLeftMostValue;
    end;
  end;
end;

This code attempts to not handle unselectable objects (Your marker lines}. Having said that, it would probably be best if you paint the marker lines in the OnBackBuffer drawing event or draw GDI lines in a transparent layer.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
yogiyang Posted - May 02 2016 : 02:04:59
Hello Bill,

Here is the screen shot before aligning objects:

The blue lines and the red lines are locked objects whose style is set to keep the objects un-selectable, un-moveable, un-resizeable, etc. In short these objects are support to work as guides and user cannot interact with them.

I have selected three objects.

After giving the command to align to left this is what I am getting:


What I want is this


So I have written this small code snippet. Here is the code that I am using:
procedure TfrmMain.pmnuAlignLeftClick(Sender: TObject);
var
  I: Integer;
  CurrentLeftMostValue, FinalLeftMostValue: Integer;
begin
  if ievMain.SelObjectsCount > 1 then
  begin
    //Let the Left Most value from selected Objects
    for I := 0 to ievMain.SelObjectsCount - 1 do
    begin
      CurrentLeftMostValue := ievMain.ObjLeft[ievMain.SelObjects[I]];
      if I = 0 then
        FinalLeftMostValue := CurrentLeftMostValue
      else
        if FinalLeftMostValue > CurrentLeftMostValue then
          FinalLeftMostValue := CurrentLeftMostValue;
    end;  //for I := 0 to ievMain.SelObjectsCount - 1 do

    //Repeate the loop gain to Align all selected Objects to Left
    for I := 0 to ievMain.SelObjectsCount - 1 do
    begin
      ievMain.ObjLeft[ievMain.SelObjects[I]] := FinalLeftMostValue;
    end;  //for I := 0 to ievMain.SelObjectsCount - 1 do
  end;
end;


Can you help me in compacting this code?

TIA


Yogi Yang
yogiyang Posted - May 02 2016 : 01:49:48
Hello Bill,

Thanks for your reply. But actually AlignObjects does not do what I want! That was the reason why I asked for help here...

It does align the objects but it also moves all the objects to the left or right or... edge of the image. I don't want to do that.

When I align selected objects left it should find the object that is left most and align all the selected objects to the left as per the left most object.

TIA


Yogi Yang
w2m Posted - Apr 29 2016 : 16:33:30
TImageEnVect.AlignObjects

Declaration
procedure AlignObjects(Alignment: TIEAlignLayers; bSelectedOnly: Boolean = true);

Description
Aligns objects relative to the image or other objects. If bSelectedOnly is false, then all objects are aligned.

Example
// Move all objects to the center of the image
ImageEnView1.AlignObjects(ilaAlignToVerticalCenter);

See the help file...

I am not aware of any procedures to arrange objects with equal spacing, but this may work:

procedure TForm1.AdjustObjectSpacing(APercent: Double);
// Adjust selected object spacing (left and top) by APercent
// APercent values can be negative and positive values (0.10, 0.25, -0.10, -0.25)
// Negative APercent values reduce spacing
// Positive APercent values increase spacing
var
  i: Integer;
  iHObj: Integer;
begin
  // find all objects and adjust spacing by APercent
  for i := 0 to ImageEnVect1.SelObjectsCount - 1 do
    if i >= 0 then
    begin
      iHObj := ImageEnVect1.SelObjects[i];
      ImageEnVect1.ObjLeft[iHObj] := ImageEnVect1.ObjLeft[iHObj] + Round(ImageEnVect1.ObjLeft[iHObj] * APercent);
      ImageEnVect1.ObjTop[iHObj] := ImageEnVect1.ObjTop[iHObj] + Round(ImageEnVect1.ObjTop[iHObj] * APercent);
    end;
  ImageEnVect1.Update;
end;

AdjustObjectSpacing(StrToFloat(Spacing1.Text));
AdjustObjectSpacing(0.10);

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development