Profile Picture

How do I prevent an image from being resized?

Posted By Robert Sholtes 14 Years Ago
Author
Message
Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
The smart way to do it is to create a custom label. Since custom labels are tricky we have created one for you - it anchors to the bottom side of the shape to which you add it. The label automatically grows to fit the text size and takes into account the shape orientation. Following is the code of the label:

[Serializable]
public class NBottomSideLabel : NLabel
{
#region Constructors

///
/// Default constructor
///

public NBottomSideLabel()
{
}
///
/// Initializer constructor
///

///
///
public NBottomSideLabel(string text, Guid anchorUniqueId)
: base(text, anchorUniqueId)
{
}

#endregion

#region Interface implementations

#region INDiagramElementReferenceHolder overrides

///
/// Provides a filter for the specified id property
///

///
/// For the AnchorUniqueId property this implementation will return the NFilters.TypeNModel filter
///

/// property exposing id, for which to obtain filter
/// filter
public override NFilter GetFilterForReferenceProperty(string property)
{
if (property != "AnchorUniqueId")
throw new ArgumentException("Can only provide filter for the AnchorUniqueId property", "property");

return NFilters.TypeNModel;
}

#endregion

#region INText overrides

///
/// Obtains text paint info in world coordinates
///

/// text for which to obtain paint info
/// result paint info
/// true if paint info was successfully obtained, otherwise false
public override bool GetWorldTextPaintInfo(string text, out NTextPaintInfo info)
{
info = new NTextPaintInfo();

// get the anchor model
NModel anchor = GetAnchorModel(AnchorUniqueId);
if (anchor == null)
return false;

// get model bounds bottom side position in world coordinates
NRectangleF modelBounds = anchor.ModelBounds;
NPointF bottomLeft = new NPointF(modelBounds.X, modelBounds.Bottom);
NPointF bottomRight = new NPointF(modelBounds.Right, modelBounds.Bottom);
NPointF bottomCenter = new NPointF(modelBounds.Center.X, modelBounds.Bottom);

// transform local 2 scene
NMatrix2DF sceneTransform = anchor.SceneTransform;
bottomLeft = sceneTransform.TransformPoint(bottomLeft);
bottomRight = sceneTransform.TransformPoint(bottomRight);
bottomCenter = sceneTransform.TransformPoint(bottomCenter);

// transform scene 2 world
INWorld world = (RootNode as INWorld);
if (world != null)
{
bottomLeft = world.SceneToWorld.TransformPoint(bottomLeft);
bottomRight = world.SceneToWorld.TransformPoint(bottomRight);
bottomCenter = world.SceneToWorld.TransformPoint(bottomCenter);
}

// get the text size in world coordinate using current text style
NSizeF size;
if (MeasureStringInWorld(text, ComposeTextStyle(), out size) == false)
return false;

// determine the rotation angle of the text in world coordinates
float angle = (float)Math.Atan2(bottomRight.Y - bottomLeft.Y, bottomRight.X - bottomLeft.X);

// init the info
info.Origin = new NPointF(
bottomCenter.X + (float)Math.Cos(angle + Math.PI / 2) * (size.Height / 2),
bottomCenter.Y + (float)Math.Sin(angle + Math.PI / 2) * (size.Height / 2));

info.Size = size;
info.Orientation = angle * 180.0f / (float)Math.PI;
info.Mode = PaintTextMode.Flow;

return true;
}

#endregion

#endregion
}

The following code creates a rectangle with this label:

NRectangleShape shape = new NRectangleShape(0, 0, 100, 100);
shape.Labels.RemoveAllChildren();
shape.Labels.AddChild(new NBottomSideLabel("hello there", shape.UniqueId));

Best Regards,
Nevron Support Team



Robert Sholtes
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 10, Visits: 1
That sort of helped. However, I'm getting artifacts appear on the screen if I move the text below the image and then edit or move the image. Let me recap what I'm trying to do so that hopefully I can get a full resolution to the problem so I can stop bugging you guys.

I need to be able to drag and drop a bitmap image into a view with an editable text label beneath the image. Ideally, the text box would resize in response to the change in the text label, keeping itself centered underneath the bitmap image. Also, I would like to be able to have the in-place text editing occur when double-clicking on the text label itself, not the bitmap. Using the example above to move the offset doesn't work because the text fails to draw properly if the offset is placed below the height of the Shape. (Example of this follows.) I was thinking I may need to use an NGroup which has both an NRectangleShape for the bitmap and an NTextShape for the label. In that case, I'm still not sure how best to set up the text label so that it provides the desired behavior.

If you change the code in the Custom Drag and Drop example, NCustomDragDropUC.cs file, you can see what I'm talking about. If you replace the AdaptBitmap method with the following code, when you drag a Man bitmap onto the view, you will notice that the text doesn't actually appear in the drawing. Now, drag and move the bitmap image, you should see that text artifacts appear on the view.

protected virtual NDrawingDataObject AdaptBitmap(Bitmap bmp)
{
if (bmp == null)
throw new ArgumentNullException("bmp");

// create a rectangle shape with the proper dimensions
// and fill it with the bitmap
NRectangleShape shape = new NRectangleShape(0, 0, bmp.Width, bmp.Height);
shape.Style.FillStyle = new NImageFillStyle(bmp);
shape.Style.TextStyle = new NTextStyle();
shape.Text = "Prove you work";
shape.Style.TextStyle.Offset = new NPointL(0.0f, bmp.Height);
// create a drawing data object, which encapsulates the shape
NDrawingDataObject ddo = new NDrawingDataObject(null, new INDiagramElement[]{shape});
return ddo;
}

Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Robert,

 

Take a look at the following topic: Text Style

 

Here is a simple example for the text offset:

NShape shape1 = factory.CreateShape(FlowChartingShapes.Process);

nDrawingDocument1.ActiveLayer.AddChild(shape1);

shape1.Bounds = new NRectangleF(100, 400, 100, 100);

shape1.Text = "STEP1";

shape1.Style.TextStyle = (NTextStyle)step1.ComposeTextStyle().Clone();

shape1.Style.TextStyle.Offset = new NPointL(0, 100);

 

Hopefully this helps.



Best Regards,
Nevron Support Team



Robert Sholtes
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 10, Visits: 1
RE: Text label offset, I'm confused. When I look at the online documentation, I see a code example like this:

NLabel label = new NLabel();
label.Text = "Offset of the origin point 10";
label.HorizontalMargin = 0;
label.VerticalMargin = 0;
label.TextProps.HorzAlign = HorzAlignNear;
label.TextProps.VertAlign = HorzAlignNear;
label.TextProps.Offset = new NPointL(10, 10);
NChartControl.Labels.Add(label);

However, the NLabel class I see in my code has no such properties like HorizontalMargin, TextProps, etc.

So, I'm at a loss as to how to handle the offset you mention. Sorry to be so dense, but there are a lot of classes to wrap my head around.

Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Robert,

 

Take a look at the help documentation topic: Abilities, Protection and Permissions

 

You can use the following code:

 

// protect a shape from ResizeX and ResizeY

NAbilities protection = shape1.Protection;

protection.ResizeX = true;

protection.ResizeY = true;

shape1.Protection = protection;

 

// hide the shape disabled handles in the view

nDrawingView1.TrackersManager.HideDisabledHandles = true;

 

Regarding your second question – yes, you can position the text label beneath the shape by using the text offset property.



Best Regards,
Nevron Support Team



Robert Sholtes
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 10, Visits: 1
Thanks! I'm assuming that when you say set Shape protection, that's done view the shape.Protection = new NAbilities(...) right?

Now, on to my next question... Is there a way to place the text for a shape beneath the shape rather than within its bounding rect? When using a bitmap for the shape, it would be nice to see the text label beneath, not overriding the bitmap image.

Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hello Robert,

 

You need to set the shape protection - ResizeX and ResizeY. You can also set additional protections to the shapes.

 

To hide the shape handles - from the TrackersManager, set HideDisabledHandles to true.

 

Hopefully this helps. Questions or comments, please feel free.



Best Regards,
Nevron Support Team



Robert Sholtes
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 10, Visits: 1
I need to use fixed-size bitmaps for drawing shapes in my view. I've used the RectangleShape class and set it to show the desired image. However, when a user selects the shape, I'd like to prevent the resize handles from appearing - the shape can be moved but not resized.

I've tried setting most of the TrackersAppearance members to have Size = new NSizeF(0.0F, 0.0F) but can't seem to prevent the resize handles from appearing.





Similar Topics


Reading This Topic