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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Arrange shapes as user add Vector Shapes
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Dec 10 2015 :  08:05:18  Show Profile  Reply
Hello,

I have been trying to implement a way by which user can click on a button to add shapes (vector) to ImageEn.

When a shape is added it should automatically arrange itself as per number of count. For example if there are:
3 Shapes then they should get arranged like this https://www.dropbox.com/s/6ppnsdjela8bx3z/001.jpg?dl=0

4 Shapes then they should get arranged like this https://www.dropbox.com/s/s6s3ef34tkicjgx/002.jpg?dl=0

5 Shapes then they should get arranged like this https://www.dropbox.com/s/fpjhz5aua8wq1py/003.jpg?dl=0

6 Shapes then they should get arranged like this https://www.dropbox.com/s/8yxkz7ai1klqg37/004.jpg?dl=0

Here all arrangements and size have to be dynamically, and gets calculated as per size of loaded Image and in each shape user will either fill it with color or load a bitmap into it.

All help is highly appreciated as I have already spend 4 day trying to get this to work.

TIA


Yogi Yang

w2m

USA
1990 Posts

Posted - Dec 11 2015 :  11:28:39  Show Profile  Reply
This code will get you started. I am sure you will have to make some adjustments, but the object positions and relative size is similar to what your images show. Each time you click on the button an object is added and all existing buttons are repositioned and resized accordingly.
procedure TForm1.Add1Click(Sender: TObject);
var
  ihObj: integer;
  iObjectCount: integer;
  iLeft: integer;
  iTop: integer;
  iWidth: integer;
  iHeight: integer;
begin
  ImageEnVect1.MouseInteractVt := [miPutBox];
  ImageEnVect1.ObjKind[IEV_NEXT_INSERTED_OBJECT] := iekBOX;
  ImageEnVect1.ObjPenWidth[IEV_NEXT_INSERTED_OBJECT] := 1;
  ImageEnVect1.ObjPenColor[IEV_NEXT_INSERTED_OBJECT] := clBlack;
  ImageEnVect1.ObjBrushColor[IEV_NEXT_INSERTED_OBJECT] := clBlue;
  ImageEnVect1.ObjBrushStyle[IEV_NEXT_INSERTED_OBJECT] := bsSolid;
  ihObj := ImageEnVect1.AddNewObject;
  iObjectCount := ImageEnVect1.ObjectsCount;
  case ihObj of
    0: begin {1 object}
         iLeft := AObjSpacing;
         iTop := AObjSpacing;
         iWidth := ImageEnVect1.ExtentX - AObjSpacing;
         iHeight := ImageEnVect1.ExtentY - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj] := iLeft;
         ImageEnVect1.ObjTop[ihObj] := iTop;
         ImageEnVect1.ObjWidth[ihObj] := iWidth;
         ImageEnVect1.ObjHeight[ihObj] := iHeight;
    end;
    1: begin {2 objects}
         iLeft := AObjSpacing;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 2) - AObjSpacing;
         iHeight := ImageEnVect1.ExtentY - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-1] := iLeft;
         ImageEnVect1.ObjTop[ihObj-1] := iTop;
         ImageEnVect1.ObjWidth[ihObj-1] := iWidth;
         ImageEnVect1.ObjHeight[ihobj-1] := iHeight;

         iLeft := ImageEnVect1.ObjLeft[ihObj-1] + ImageEnVect1.ObjWidth[ihObj-1] + AObjSpacing;
         iTop := ImageEnVect1.ObjTop[ihObj-1];
         ImageEnVect1.ObjLeft[ihObj] := iLeft;
         ImageEnVect1.ObjTop[ihObj] := iTop;
         ImageEnVect1.ObjWidth[ihObj] := iWidth;
         ImageEnVect1.ObjHeight[ihObj] := iHeight;
    end;
    2: begin {3 objects}
         iLeft := AObjSpacing;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 2) - AObjSpacing;
         iHeight := ImageEnVect1.ExtentY - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-2] := iLeft;
         ImageEnVect1.ObjTop[ihObj-2] := iTop;
         ImageEnVect1.ObjWidth[ihObj-2] := iWidth;
         ImageEnVect1.ObjHeight[ihobj-2] := iHeight;

         iLeft := ImageEnVect1.ObjLeft[ihObj-2] + ImageEnVect1.ObjWidth[ihObj-2] + AObjSpacing;
         iTop := AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-1] := iLeft;
         ImageEnVect1.ObjTop[ihObj-1] := iTop;
         ImageEnVect1.ObjWidth[ihObj-1] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-1] := iHeight;

         iTop := (ImageEnVect1.ExtentY div 2) + AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj] := iLeft;
         ImageEnVect1.ObjTop[ihObj] := iTop;
         ImageEnVect1.ObjWidth[ihObj] := iWidth;
         ImageEnVect1.ObjHeight[ihObj] := iHeight;
    end;
    3: begin {4 objects}
         iLeft := AObjSpacing;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 2) - AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-3] := iLeft;
         ImageEnVect1.ObjTop[ihObj-3] := iTop;
         ImageEnVect1.ObjWidth[ihObj-3] := iWidth;
         ImageEnVect1.ObjHeight[ihobj-3] := iHeight;

         iLeft := AObjSpacing;
         iTop := (ImageEnVect1.ExtentY div 2) + AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-2] := iLeft;
         ImageEnVect1.ObjTop[ihObj-2] := iTop;
         ImageEnVect1.ObjWidth[ihObj-2] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-2] := iHeight;

         iLeft := ImageEnVect1.ObjLeft[ihObj-2] + ImageEnVect1.ObjWidth[ihObj-2] + AObjSpacing;
         iTop := AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-1] := iLeft;
         ImageEnVect1.ObjTop[ihObj-1] := iTop;
         ImageEnVect1.ObjWidth[ihObj-1] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-1] := iHeight;

         iTop := ImageEnVect1.ObjTop[ihObj-1] + ImageEnVect1.ObjHeight[ihObj-1] + AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj] := iLeft;
         ImageEnVect1.ObjTop[ihObj] := iTop;
         ImageEnVect1.ObjWidth[ihObj] := iWidth;
         ImageEnVect1.ObjHeight[ihObj] := iHeight;
       end;
    4: begin {5 objects}
         {Object 0}
         iLeft := AObjSpacing;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 2) - AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-4] := iLeft;
         ImageEnVect1.ObjTop[ihObj-4] := iTop;
         ImageEnVect1.ObjWidth[ihObj-4] := iWidth;
         ImageEnVect1.ObjHeight[ihobj-4] := iHeight;

         {Object 1}
         iLeft := AObjSpacing;
         iTop := (ImageEnVect1.ExtentY div 2) + AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-3] := iLeft;
         ImageEnVect1.ObjTop[ihObj-3] := iTop;
         ImageEnVect1.ObjWidth[ihObj-3] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-3] := iHeight;

         {Object 2}
         iLeft := ImageEnVect1.ObjLeft[ihObj-4] + ImageEnVect1.ObjWidth[ihObj-4] + AObjSpacing;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 2) - AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-2] := iLeft;
         ImageEnVect1.ObjTop[ihObj-2] := iTop;
         ImageEnVect1.ObjWidth[ihObj-2] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-2] := iHeight;

         {Object 3}
         iLeft := ImageEnVect1.ObjLeft[ihObj-2];
         iTop := (ImageEnVect1.ExtentY div 2) + AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 4) - AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-1] := iLeft;
         ImageEnVect1.ObjTop[ihObj-1] := iTop;
         ImageEnVect1.ObjWidth[ihObj-1] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-1] := iHeight;

         {Object 4}
         iLeft := ImageEnVect1.ObjLeft[ihObj-1] + ImageEnVect1.ObjWidth[ihObj-1] + AObjSpacing;
         iTop := ImageEnVect1.ObjTop[ihObj-1];
         iWidth := (ImageEnVect1.ExtentX div 4) - AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj] := iLeft;
         ImageEnVect1.ObjTop[ihObj] := iTop;
         ImageEnVect1.ObjWidth[ihObj] := iWidth;
         ImageEnVect1.ObjHeight[ihObj] := iHeight;
    end;
    5: begin {6 objects}
         {Object 0}
         iLeft := AObjSpacing;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 5) - AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-5] := iLeft;
         ImageEnVect1.ObjTop[ihObj-5] := iTop;
         ImageEnVect1.ObjWidth[ihObj-5] := iWidth;
         ImageEnVect1.ObjHeight[ihobj-5] := iHeight;

         {Object 1}
         iLeft := ImageEnVect1.ObjLeft[ihObj-5] + ImageEnVect1.ObjWidth[ihObj-5] + AObjSpacing;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 5) - AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-4] := iLeft;
         ImageEnVect1.ObjTop[ihObj-4] := iTop;
         ImageEnVect1.ObjWidth[ihObj-4] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-4] := iHeight;

         {Object 2}
         iLeft := ImageEnVect1.ObjLeft[ihObj-4] + ImageEnVect1.ObjWidth[ihObj-4] + AObjSpacing;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 5) - AObjSpacing;
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-3] := iLeft;
         ImageEnVect1.ObjTop[ihObj-3] := iTop;
         ImageEnVect1.ObjWidth[ihObj-3] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-3] := iHeight;

         {Object 3}
         iLeft := AObjSpacing;
         iTop := (ImageEnVect1.ExtentY div 2) + AObjSpacing;
         iWidth := (ImageEnVect1.ObjWidth[ihObj-5] * 2) - (AObjSpacing * 3);
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-2] := iLeft;
         ImageEnVect1.ObjTop[ihObj-2] := iTop;
         ImageEnVect1.ObjWidth[ihObj-2] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-2] := iHeight;

         {Object 4}
         iLeft := ImageEnVect1.ObjLeft[ihObj-5] + ImageEnVect1.ObjLeft[ihObj-4] + ImageEnVect1.ObjLeft[ihObj-3] - AObjSpacing*2;
         iTop := AObjSpacing;
         iWidth := (ImageEnVect1.ExtentX div 2) - (AObjSpacing * 5);
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj-1] := iLeft;
         ImageEnVect1.ObjTop[ihObj-1] := iTop;
         ImageEnVect1.ObjWidth[ihObj-1] := iWidth;
         ImageEnVect1.ObjHeight[ihObj-1] := iHeight;

         {Object 5}
         iLeft := ImageEnVect1.ObjLeft[ihObj-1] - AObjSpacing * 6;
         iTop := ImageEnVect1.ObjTop[ihObj-2];
         iWidth := (ImageEnVect1.ExtentX div 2) + (AObjSpacing);
         iHeight := (ImageEnVect1.ExtentY div 2) - AObjSpacing;
         ImageEnVect1.ObjLeft[ihObj] := iLeft;
         ImageEnVect1.ObjTop[ihObj] := iTop;
         ImageEnVect1.ObjWidth[ihObj] := iWidth;
         ImageEnVect1.ObjHeight[ihObj] := iHeight;
    end
    else
    begin

    end;
  end;
  ImageEnVect1.MouseInteractVt := [miObjectSelect];
end;

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

yogiyang

India
727 Posts

Posted - Dec 12 2015 :  03:41:24  Show Profile  Reply
Bill,

Thanks for the code sample.

Now you have got me started

Regards,


Yogi Yang
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: