Is possible do C++: public override UIElement Child
C# is
How do same in С++?
Code: Select all
public override UIElement Child
{
get { return base.Child; }
set
{
if (value != null && value != this.Child)
this.Initialize(value);
base.Child = value;
}
}
Re: Is possible do C++: public override UIElement Child
Could you please indicate the base class you are trying to extend? We expose the following virtual functions in Visual:
Code: Select all
/// Gets the number of child elements for the Visual
/// \remarks Each visual implementation will decide how to store visual children
virtual uint32_t GetVisualChildrenCount() const;
/// Returns the specified Visual in the parent VisualCollection
/// \remarks Each visual implementation will decide how to store visual children
virtual Visual* GetVisualChild(uint32_t index) const;
Re: Is possible do C++: public override UIElement Child
I try extend Border like this:
Code: Select all
// https://stackoverflow.com/questions/741956/pan-zoom-image
public class ZoomBorder : Border
{
public override UIElement Child
{
get { return base.Child; }
set
{
if (value != null && value != this.Child)
this.Initialize(value);
base.Child = value;
}
}
public void Initialize(UIElement element)
{
this.child = element;
if (child != null)
{
TransformGroup group = new TransformGroup();
ScaleTransform st = new ScaleTransform();
group.Children.Add(st);
TranslateTransform tt = new TranslateTransform();
group.Children.Add(tt);
child.RenderTransform = group;
child.RenderTransformOrigin = new Point(0.0, 0.0);
this.MouseWheel += ChildMouseWheel;
this.MouseLeftButtonDown += ChildMouseLeftButtonDown;
this.MouseLeftButtonUp += ChildMouseLeftButtonUp;
this.MouseMove += ChildMouseMove;
this.PreviewMouseRightButtonDown += new MouseButtonEventHandler(
ChildPreviewMouseRightButtonDown);
}
}
public void Reset()
{
if (child != null)
{
// reset zoom
var st = GetScaleTransform(child);
st.ScaleX = 1.0;
st.ScaleY = 1.0;
// reset pan
var tt = GetTranslateTransform(child);
tt.X = 0.0;
tt.Y = 0.0;
}
}
private void ChildMouseWheel(object sender, MouseWheelEventArgs e)
{
if (child != null)
{
var st = GetScaleTransform(child);
var tt = GetTranslateTransform(child);
double zoom = e.Delta > 0 ? 1.3 : 1 / 1.3;
Point relative = e.GetPosition(child);
double absoluteX;
double absoluteY;
absoluteX = relative.X * st.ScaleX + tt.X;
absoluteY = relative.Y * st.ScaleY + tt.Y;
st.ScaleX *= zoom;
st.ScaleY *= zoom;
tt.X = absoluteX - relative.X * st.ScaleX;
tt.Y = absoluteY - relative.Y * st.ScaleY;
}
}
private void ChildMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (child != null)
{
var tt = GetTranslateTransform(child);
start = e.GetPosition(this);
origin = new Point(tt.X, tt.Y);
this.Cursor = Cursors.Hand;
child.CaptureMouse();
}
}
private void ChildMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (child != null)
{
child.ReleaseMouseCapture();
this.Cursor = Cursors.Arrow;
}
}
private void ChildPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
this.Reset();
}
private void ChildMouseMove(object sender, MouseEventArgs e)
{
if (child != null)
{
if (child.IsMouseCaptured)
{
var tt = GetTranslateTransform(child);
Vector v = start - e.GetPosition(this);
tt.X = origin.X - v.X;
tt.Y = origin.Y - v.Y;
}
}
}
private TranslateTransform GetTranslateTransform(UIElement element)
{
return (TranslateTransform)((TransformGroup)element.RenderTransform)
.Children.First(tr => tr is TranslateTransform);
}
private ScaleTransform GetScaleTransform(UIElement element)
{
return (ScaleTransform)((TransformGroup)element.RenderTransform)
.Children.First(tr => tr is ScaleTransform);
}
private UIElement child = null;
private Point origin;
private Point start;
}
Re: Is possible do C++: public override UIElement Child
I see Child functions not virtual, i cant override its by simple virtual func.
Code: Select all
/// Gets or sets child element
//@{
UIElement* GetChild() const;
void SetChild(UIElement* child);
//@}
-
sfernandez
Site Admin
- Posts: 3109
- Joined:
Re: Is possible do C++: public override UIElement Child
Hi, the Decorator provides a virtual method for Child property changes, so you can override it to register/unregister any event handlers you want on the child:
Code: Select all
void ZoomBorder::OnChildChanged(UIElement* oldChild, UIElement* newChild) override
{
if (oldChild != nullptr) { // unregister events... }
if (newChild != nullptr) { // register events... }
}
Re: Is possible do C++: public override UIElement Child
I second that question but this time for the Unity C# side. The UIElement Child is defined like that so I cannot override it:
Setting this function as virtual solves it but I'm not sure it has potential side effects? On my end everything else seems to work fine.
And I don't see a virtual method for Child property changes in the C# decorator class...
Code: Select all
public UIElement Child {
set {
NoesisGUI_PINVOKE.Decorator_Child_set(swigCPtr, UIElement.getCPtr(value));
}
get {
IntPtr cPtr = NoesisGUI_PINVOKE.Decorator_Child_get(swigCPtr);
return (UIElement)Noesis.Extend.GetProxy(cPtr, false);
}
}
And I don't see a virtual method for Child property changes in the C# decorator class...
-
sfernandez
Site Admin
- Posts: 3109
- Joined:
Re: Is possible do C++: public override UIElement Child
If you call the base class getter/setter in your override it won't cause problems. The limitation about making it just virtual (without more code on our C++/C# bindings) is that any call in C++ code to Decorator::GetChild() won't call the override in the C#, but if you are only overriding it for the setter it will be safe.Setting this function as virtual solves it but I'm not sure it has potential side effects?
Could you please create a ticket about this?I don't see a virtual method for Child property changes in the C# decorator class
Who is online
Users browsing this forum: Google [Bot] and 11 guests