Rank: Advanced Member
Groups: Guest
Joined: 8/2/2003(UTC) Posts: 876
Thanks: 2 times Was thanked: 27 time(s) in 27 post(s)
|
The CompositeVObject is designed to be created internally (when the user selects multiple VObjects). If you really need to have composite objects (like two images like in your example), more correct way would be to implement your own VObject implementation. Here is an example of implementation of a custom VObject which contains two images displayed one next to another. Code: class TwoImageVObject : Aurigma.GraphicsMill.WinControls.VObject
{
private Aurigma.GraphicsMill.WinControls.ImageVObject _image1;
private Aurigma.GraphicsMill.WinControls.ImageVObject _image2;
private Aurigma.GraphicsMill.WinControls.IDesigner _editDesigner;
private int _distance = 10;
public Aurigma.GraphicsMill.WinControls.ImageVObject Image1
{
get { return _image1; }
set { _image1 = value; }
}
public Aurigma.GraphicsMill.WinControls.ImageVObject Image2
{
get { return _image2; }
set { _image2 = value; }
}
public TwoImageVObject(Aurigma.GraphicsMill.Bitmap bitmap1, Aurigma.GraphicsMill.Bitmap bitmap2, bool scaleToActualSize, float x, float y) :
base()
{
_image1 = new Aurigma.GraphicsMill.WinControls.ImageVObject(bitmap1, scaleToActualSize, x , y);
_image2 = new Aurigma.GraphicsMill.WinControls.ImageVObject(bitmap2, scaleToActualSize, x, y);
}
public override RectangleF GetVObjectBounds()
{
RectangleF image1Bounds = _image1.GetVObjectBounds();
RectangleF image2Bounds = _image2.GetVObjectBounds();
return new RectangleF(image1Bounds.X, image1Bounds.Y, image1Bounds.Width + image2Bounds.Width + _distance, image1Bounds.Height);
}
public override RectangleF GetTransformedVObjectBounds()
{
RectangleF image1Bounds = _image1.GetTransformedVObjectBounds();
RectangleF image2Bounds = _image2.GetTransformedVObjectBounds();
return new RectangleF(image1Bounds.X, image1Bounds.Y, image1Bounds.Width + image2Bounds.Width + _distance, image1Bounds.Height);
}
public override bool HitTest(PointF point, float precisionDelta)
{
return _image1.HitTest(point, precisionDelta) | _image2.HitTest(point, precisionDelta);
}
public override System.Drawing.Drawing2D.Matrix Transform
{
get {
return _image1.Transform;
}
set {
_image1.Transform = value;
UpdateTransform();
}
}
public override Aurigma.GraphicsMill.WinControls.IDesigner Designer
{
get {
if (_editDesigner == null)
_editDesigner = new Aurigma.GraphicsMill.WinControls.GenericVObjectEditDesigner(this);
return _editDesigner;
}
}
private void UpdateTransform()
{
_image2.Transform = _image1.Transform.Clone();
PointF secondImagePosition = new Point(_distance + (int)_image1.GetVObjectBounds().Width, 0);
_image2.Transform.Translate(secondImagePosition.X, 0); ;
}
public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, Aurigma.GraphicsMill.WinControls.ICoordinateMapper coordinateMapper)
{
UpdateTransform();
_image1.Draw(renderingRect, g, coordinateMapper);
_image2.Draw(renderingRect, g, coordinateMapper);
}
}
Here is an example of its usage: Code: TwoImageVObject twoImage = new TwoImageVObject(
new Aurigma.GraphicsMill.Bitmap(@"C:\Temp\ocean-1.jpg"),
new Aurigma.GraphicsMill.Bitmap(@"C:\Temp\ocean-2.jpg"),
true, 10f, 20f);
multiLayerViewer1.Layers[0].VObjects.Add(twoImage);
If you need to modify TwoImageVObject to change images layout, first of all, modify UpdateTransform method (which "shifts" the second image relatively to the first one) and methods which return VObject bounds. Hope this helps.
|