Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line x2-y2 #33

Open
batuhancengiz opened this issue Mar 27, 2024 · 6 comments
Open

Line x2-y2 #33

batuhancengiz opened this issue Mar 27, 2024 · 6 comments

Comments

@batuhancengiz
Copy link

Hello,

I want to find x2-y2 position of line as point and with left + width and top + height couldn't get the correct x2-y2 values. Any ideas to find that?

@batuhancengiz
Copy link
Author

batuhancengiz commented Mar 27, 2024

image

Actually I want to achieve that when I drag the switch element, line should also be dragged according to base element. But top right corner of line should be fixed all the time. Can you explain how can I do this please?

@mircea21S
Copy link
Owner

Hi,

So, first thing, I recommend you read this page from the Wiki ItemContainer Overview, also there's a link pointing to how I implemented something similar to what you've described inside my demo, with Adorners (Adorner Usage), maybe you can clone/download the repo and play around with the demo. Is not fully working, but for a Line drawn with Scale=(1,1) (normally) the resize works as you described. Making it work with another ScaleTransform requires a bit more calculations.

In the first comment, you said that calculating (X2, Y2) coordinates you couldn't get the correct values. In general, when calculating that, you should have in mind 2 things: the BoundingRectangle described in the Wiki (linked that above); and the ScaleTransform value or the "Scaling". And go on from here as (Top, Left) point might not be where you expect and you might need to add or subtract from Width or Height. Basically, you need to know where the "Switch element" is positioned relative to the (Top, Left) of the BoundingRectangle of the Line and then you can easily get the correct (X2, Y2) values.

I hope this can help you getting your correct value and the desired behavior. I don't know the details of implementation about that "Switch element", so that's what I can say so far. It's quite tricky working with Transformations and calculating stuff, I know😅, take a look at the ResizeAdorner.cs class inside RichCanvasDemo and especially at the methods ArrangeOverride() and GetDesiredTransform().

@batuhancengiz
Copy link
Author

Thank you for your answer! As you know resizing with adorner just possible two aches for example this picture.
image

But I need that line resizing 360 degree. Is this possible also to resize around 360 degree in your implementation or not?

@mircea21S
Copy link
Owner

In my implementation resizing 360 degree is not possible, but it can definitely be implemented. You can debug and try to find a solution and understand how it's working now and how you can achieve it for other ScalTransform values.

@batuhancengiz
Copy link
Author

batuhancengiz commented Mar 29, 2024

Thank you for your message, I read and I guess, I understand the logic of adorner/drawing classes and tried something like that:

internal void OnMouseMove(Point delta)
        {
            foreach (var index in ParentCurrentItem.ChildrenIndexes)
            {
                var container = (RichItemContainer)_context.ItemContainerGenerator.ContainerFromIndex(index);
                ScaleTransform scaleTransform = container.ScaleTransform;

                container.Left += delta.X;
                container.Top += delta.Y;

                double width = container.X2 - container.Left;
                double height = container.Y2 - container.Top;

                container.Width = width == 0 ? 1 : Math.Abs(width);
                container.Height = height == 0 ? 1 : Math.Abs(height);

                if (scaleTransform != null)
                {
                    if (width < 0 && scaleTransform.ScaleX == 1)
                    {
                        scaleTransform.ScaleX = -1;
                    }

                    if (height < 0 && scaleTransform.ScaleY == 1)
                    {
                        scaleTransform.ScaleY = -1;
                    }

                    if (height > 0 && scaleTransform.ScaleY == -1)
                    {
                        scaleTransform.ScaleY = 1;
                    }
                    if (width > 0 && scaleTransform.ScaleX == -1)
                    {
                        scaleTransform.ScaleX = 1;
                    }
                }
            }
        }

2024-03-29-15-13-40

X2-Y2 of container is actually x2-y2 position of line. I set this according to Mouse Position when draw is ended.
But still it doesn't move the way as I want to, so do you have any idea to solve this?

@mircea21S
Copy link
Owner

Hi!

I will try to give you a piece of code that works when I find some time to do this.
The delta Top, Left position needs to be set relative to the ScaleTransform, also the width and height which are needed for X2,Y2 (some thoughts just from a quick look).

I'm thinking of adding this as a feature to the library in the future. It is probably doable.

Sorry for not being able to come with a response now. I will try to come back asap.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants