Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
Problem with TextVObject - inherit class (from RectangleVObject)
Rank: Newbie
Groups: Guest
Joined: 8/1/2008(UTC) Posts: 3
|
Hello, I want to build my own class (inherit from RectangleVObject). This class comprised follow VObjects (in this order): RectangleVObject (for shadow) (which is the base class) RectangleVObject (for border) ImageVObject (for graphical border) TextVObject (for text shadow) TextVObject (for text) I have made my first steps and there is my first problem. My test class comprised only a RectangleVObject and a TextVObject. If I resize the RectVObject then resizing the text too. The text of TextVobject should be constant. If I create only a TextVObject then I use following line: Code:textVObject.SupportedActions[Aurigma.GraphicsMill.WinControls.VObjectAction.ChangeTextArea].Enabled = true;
and it's the behavior what I wish. Call I this line in my class then have this line no reaction. Is there a way to get this functionality? I can't make the TextVObject to my inherit class because the TextVObject rect (GetVObjectBounds()) can be smaller than RectangleVObject rect. And the first RectangleVObject is that with the control points. [img][/img] Can anybody help me by my problem, please? Sorry for my bad english! Mariser My testing code: Code:
public class FbTextBox : RectangleVObject
{
RectangleVObject _shadowRect;
TextVObject _textRect;
public FbTextBox(System.Drawing.RectangleF rectangle)
: base(rectangle)
{
_shadowRect = new RectangleVObject(0, 0, 1, 1);
_shadowRect.Brush = System.Drawing.Brushes.White;
_shadowRect.Pen = new System.Drawing.Pen(System.Drawing.Color.Gray, 10f);
_shadowRect.Pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
_textRect = new TextVObject();
_textRect.Pen = new System.Drawing.Pen(System.Drawing.Color.Black, 10f);
_textRect.Brush = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
System.Drawing.Font font=new System.Drawing.Font(new FontFamily("Arial"),32);
_textRect.Font = font;
_textRect.Text = "Test";
// this line have no effect
_textRect.SupportedActions[Aurigma.GraphicsMill.WinControls.VObjectAction.ChangeTextArea].Enabled = true;
}
public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper)
{
// das unterste Rechteck zeichnen
base.Draw(renderingRect, g, coordinateMapper);
System.Drawing.RectangleF _thisObjBounds = this.GetVObjectBounds();
// Shadow
System.Drawing.RectangleF _shadowRectBounds = _shadowRect.GetVObjectBounds();
if (!_shadowRectBounds.Equals(_thisObjBounds))
{
System.Drawing.Brush tmpBrush = _shadowRect.Brush;
System.Drawing.Pen tmpPen = _shadowRect.Pen;
// _shadowObjBounds.X += 10;
// _shadowObjBounds.Y += 10;
// _shadowObjBounds.Width -= 20;
_shadowRect = new RectangleVObject(_thisObjBounds);
_shadowRect.Transform = this.Transform;
_shadowRect.Brush = tmpBrush;
_shadowRect.Pen = tmpPen;
}
_shadowRect.Transform = this.Transform;
_shadowRect.Draw(renderingRect, g, coordinateMapper);
// Text
System.Drawing.RectangleF _textRectBounds = _textRect.TextArea;
if (!_textRectBounds.Equals(_thisObjBounds))
{
System.Drawing.Brush tmpBrush = _textRect.Brush;
System.Drawing.Pen tmpPen = _textRect.Pen;
System.Drawing.Font tmpfont = _textRect.Font;
string text = _textRect.Text;
_textRect = new TextVObject(text, tmpfont.Name, 32.0f, _thisObjBounds);
_textRect.Transform = this.Transform;
_textRect.Brush = tmpBrush;
_textRect.Pen = tmpPen;
}
// draw text
_textRect.Transform = this.Transform;
_textRect.Draw(renderingRect, g, coordinateMapper);
}
public System.Drawing.Brush ShadowBrush
{
get { return _shadowRect.Brush; }
set { _shadowRect.Brush = value; }
}
public System.Drawing.Pen ShadowPen
{
get { return _shadowRect.Pen; }
set { _shadowRect.Pen = value; }
}
}
Edited by user Sunday, August 3, 2008 4:14:29 PM(UTC)
| Reason: Not specified mariser attached the following image(s):
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello, I modified a little part of your code which processes text object. Please, check whether this solution is acceptable for you. Actually it is very restricted object. It will not support any operations except move and scale. If you need rotation and skew - you will have to write much more complicated code. In that case you will need to redefine edit designer of your custom object and treat in different way resize of the object itself and resize of the text part. Code:public override void Draw(
System.Drawing.Rectangle renderingRect,
System.Drawing.Graphics g,
ICoordinateMapper coordinateMapper)
{
<<<< skipped >>>>
// Text
System.Drawing.RectangleF objBounds = GetTransformedVObjectBounds();
if (!objBounds.Equals(_textRect.TextArea))
{
_textRect.Transform = new System.Drawing.Drawing2D.Matrix();
_textRect.TextArea = objBounds;
}
// draw text
_textRect.Draw(renderingRect, g, coordinateMapper);
}
|
|
|
|
|
Rank: Newbie
Groups: Guest
Joined: 8/1/2008(UTC) Posts: 3
|
Hello Alex, thank you for your answer. Your modification did'nt work. The text is not visible. I have showing objBounds and the values of X and Y are negativ (x=-50; Y=-50; Width=400; Height=300). On the second call the values are (x=-100; Y=-100; Width=500; Height=400). Code:
System.Drawing.RectangleF objBounds = GetTransformedVObjectBounds();
I have change the line to: Code:
System.Drawing.RectangleF objBounds = GetVObjectBounds();
The text is now visible but there is showing on the left/top corner of my multilayerViewer control (outside of my VObject) I have used this code, not more (only in the text area). Is it right? Code:
// Text
System.Drawing.RectangleF objBounds = GetTransformedVObjectBounds();
if (!objBounds.Equals(_textRect.TextArea))
{
_textRect.Transform = new System.Drawing.Drawing2D.Matrix();
_textRect.TextArea = objBounds;
}
// draw text
_textRect.Draw(renderingRect, g, coordinateMapper);
Have you any idea what I make wrong? Still another question: If I make the height of my TextVObject smaller than the height of text then the text is invisible. Can I avoid this? Better for me is cut the text. Is it possible? Regards Mariser Edited by user Wednesday, August 6, 2008 4:56:16 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hi, Here is full code of the class I used in my test app - please, could you try it and post here results? Maybe I missed something, but it shows text within rectangular border in MultiLayerControl. Code:public class FbTextBox : RectangleVObject
{
RectangleVObject _shadowRect;
TextVObject _textRect;
public FbTextBox(System.Drawing.RectangleF rectangle)
: base(rectangle)
{
_shadowRect = new RectangleVObject(0, 0, 1, 1);
_shadowRect.Brush = System.Drawing.Brushes.White;
_shadowRect.Pen = new System.Drawing.Pen(System.Drawing.Color.Gray, 10f);
_shadowRect.Pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
_textRect = new TextVObject();
_textRect.Pen = new System.Drawing.Pen(System.Drawing.Color.Black, 10f);
_textRect.Brush = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
System.Drawing.Font font = new System.Drawing.Font(new FontFamily("Arial"), 32);
_textRect.Font = font;
_textRect.Text = "Test";
}
public override void Draw(System.Drawing.Rectangle renderingRect,
System.Drawing.Graphics g, ICoordinateMapper coordinateMapper)
{
// das unterste Rechteck zeichnen
base.Draw(renderingRect, g, coordinateMapper);
System.Drawing.RectangleF _thisObjBounds = this.GetVObjectBounds();
// Shadow
System.Drawing.RectangleF _shadowRectBounds =
_shadowRect.GetVObjectBounds();
if (!_shadowRectBounds.Equals(_thisObjBounds))
{
System.Drawing.Brush tmpBrush = _shadowRect.Brush;
System.Drawing.Pen tmpPen = _shadowRect.Pen;
// _shadowObjBounds.X += 10;
// _shadowObjBounds.Y += 10;
// _shadowObjBounds.Width -= 20;
_shadowRect = new RectangleVObject(_thisObjBounds);
_shadowRect.Transform = this.Transform;
_shadowRect.Brush = tmpBrush;
_shadowRect.Pen = tmpPen;
}
_shadowRect.Transform = this.Transform;
_shadowRect.Draw(renderingRect, g, coordinateMapper);
// Text
System.Drawing.RectangleF objBounds =
GetTransformedVObjectBounds();
if (!objBounds.Equals(_textRect.TextArea))
{
_textRect.Transform = new System.Drawing.Drawing2D.Matrix();
_textRect.TextArea = objBounds;
}
// draw text
_textRect.Draw(renderingRect, g, coordinateMapper);
}
public System.Drawing.Brush ShadowBrush
{
get { return _shadowRect.Brush; }
set { _shadowRect.Brush = value; }
}
public System.Drawing.Pen ShadowPen
{
get { return _shadowRect.Pen; }
set { _shadowRect.Pen = value; }
}
}
As for you second question - unfortunately we have no such option on vector objects and now it is necessary to change implementation of the TextVObject to get this behavior. Edited by user Monday, August 11, 2008 6:03:50 PM(UTC)
| Reason: Not specified |
|
|
|
|
Rank: Newbie
Groups: Guest
Joined: 8/1/2008(UTC) Posts: 3
|
Thanks for your help. Your code is working very well.
You have written rotate is not so easy to implement. Is there perhaps a little example code about this?
Best regards mariser
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello,
I have to confirm, that it really complicated task to implement rotation... We have no examples on this, the only thing I can suggest - VectorObject source codes. You use TextVObject and GenericVObjectDesigner classes implementation as start point for your object.
|
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/10/2010(UTC) Posts: 57
Thanks: 1 times
|
How can we also implement alignment of the text in reference to the bounded rectangle here?
eg, if center, the text is in the center of bounded rectangle; if top on vertical and middle horizontal, text is at top and middle horizontal etc.
horizontal : right, left, middle vertical: top, center, bottom
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/10/2010(UTC) Posts: 57
Thanks: 1 times
|
it seems that we figure out how to do this text alignment thing:
TextVObject has .Format.Alignment and .Format.LineAlignment properties to take care of text alignment within the textarea.
|
|
|
|
Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
Problem with TextVObject - inherit class (from RectangleVObject)
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.