简体   繁体   English

号码线压缩和对接控件

[英]Number line compression and docking controls

Hi Mathmeticians out there. 嗨,数学家在那里。

I am a little stumped and I was wondering if there was any sort of algorithm that could help me. 我有些困惑,我想知道是否有任何算法可以帮助我。

First the conceptual problem, Lets say I have a bunch of boxes that lie along an X axis. 首先是概念问题,可以说我有一堆沿着X轴放置的盒子。 I want to be able to choose an arbitrary point A on the axis and have everything on the left scaled to 95% of its original width and position and to compensate, everything on the right will have to be scaled to 105%. 我希望能够在轴上选择任意点A,并将左侧的所有内容缩放到其原始宽度和位置的95%,并进行补偿,右侧的所有内容都必须缩放到105%。 The width of the resulting boxes is easy to calculate since it is the original width times the scale. 结果框的宽度很容易计算,因为它是原始宽度乘以比例尺。 The problem I am having is how to calculate the gap which has now been created at point A so that I can shift the second part left to close that gap. 我遇到的问题是如何计算现在在点A处创建的间隙,以便我可以向左移动第二部分以缩小该间隙。

在此处输入图片说明

Furthermore, I would like to not only select a point A, but also a B and C, etc.. as well and be able to close their gaps likewise. 此外,我不仅要选择一个点A,而且还要选择一个B和C等,并且同样可以缩小它们之间的距离。

--The real reason I am asking-- -我要问的真正原因-

Now for the actual problem (in case anyone else out there has gone through this.) I have a control in a C# Winforms app that was made by some programmer before I got here. 现在针对实际问题(以防万一其他人已经解决了这个问题。)我在C#Winforms应用程序中有一个控件,该控件是在我到达这里之前由某些程序员制作的。 The control can contain any number of child controls that each have their own relative coordinates as a percentage of the Width or Height (ie A control with a relative X coordinate of 0.5 will be placed halfway across the parent container. 该控件可以包含任意数量的子控件,每个子控件都有自己的相对坐标(以宽度或高度的百分比表示)(即,相对X坐标为0.5的控件将放置在父容器的中间。

We desperately need to support multiple monitors and the problem that I am having is that if you dock a control or toolbar next to our proprietary control then the ClientRectangle is smaller so it shifts around the child borders like so 我们非常需要支持多个监视器,而我遇到的问题是,如果将控件或工具栏停靠在我们专有控件的旁边,则ClientRectangle会变小,因此它会像这样围绕子边框移动

在此处输入图片说明

My boss doesn't like that the lines shift over monitor boundaries and wants me to only mess with the lines on the same monitor where the window was docked. 我的老板不喜欢线条在监视器边界上移动,而是希望我只弄乱固定窗口的同一台监视器上的线条。 I have been able to get 90% of the way using the concept above, but I can't seem to get the re-spacing calculation right. 使用上面的概念,我已经能够获得90%的方法,但是我似乎无法正确计算重新调整间距。

Here is a Mathematical model of what I think for calculating the gap. 这是我对计算差距的看法的数学模型。

Let's say that you have a starting point A, and lets define it as xA. 假设您有一个起点A,并将其定义为xA。

Now, let's define the boxes 现在,让我们定义盒子

//Box{x0,x1}
Boxes = {[B1]{0,100},[B2]{100,200},[B3]{200,400},[B4]{400,450},[B5]{450,700}}

Now we have 5 boxes on the X axis. 现在,我们在X轴上有5个框。

Let's define; 让我们定义;

A = xA = 370;
TotalLength = 700;

If you divide 700 by 2, that makes 350 which makes the mid point, and 370 is bigger than the mid point value. 如果将700除以2,则得到350,这就是中点,而370大于中点值。 So that is being said, in this case you would need to shift the elements on the left to right. 也就是说,在这种情况下,您需要将元素从左向右移动。 The calculation of the gap is as the following; 间隙的计算如下。

IF(Midpoint < A)
    Gap = ((A- Midpoint) * 100 ) / TotalLength //This is the gap in percent
ELSE
    Gap = ((Midpoint - A) * 100) / TotalLength 

This way, you can find the gap. 这样,您可以找到差距。 The Axis you need to shift towards will need to be decided based on the point you are selecting, if the selected point less than the Mid point then shift to right, if higher shift to left (to the positive axis route). 需要移动的轴将取决于您选择的点,如果选定的点小于中点,则向右移动,如果向左移动(向正轴路线),则向右移动。

I hope this helps. 我希望这有帮助。

Thank you for your help Surgeon. 谢谢您对外科医生的帮助。 Unfortunately I wasn't able to find a solution using your method. 不幸的是,我无法使用您的方法找到解决方案。 On the bright side, I was able to find a solution. 从好的方面来说,我能够找到解决方案。 The trick was to treat the X coordinate as the width between the Client Rectangle's left edge and the X coordinate's position and calculate it similarly to the child width. 技巧是将X坐标视为“客户矩形”的左边缘与X坐标位置之间的宽度,并与子宽度类似地进行计算。

For more specifics, here's the algorithm I have come up with for dealing with the docking problem: 有关更多细节,这是我为处理对接问题而想出的算法:

var clientOriginalWidth = what the width of the Client rectangle would be without docks
var clientCompressedWidth = the width of the client now

//Calculate the Compression Ratio for each screen as follows
foreach(var screen in Screens){
  var widthOfClientRectOnScreenNow = how much of the client rectangle is on this screen
  var widthOfClientRectOnScreenWithoutDocks = how much of the client rectangle was on the screen before the docks were there
  var compressionRatio = (widthOfClientRectOnScreenNow / clientCompressedWidth) / 
                     (widthOfClientRectOnScreenWithoutDocks / clientOriginalWidth);

  //Assuming control.xScale and control.widthScale are initially 0
  foreach(var control in ParentControl){
     var controlBounds = where the control was when the client was full width
     if(controlBounds.X > screen.right){
        var percentOfXPositionOnScreen = screen.right - screen.left / control.x;
        controlBounds.xScale += percentOfPositionOnScreen * compressionRatio;
     }
     else if(control.X > screen.left){
       var percentOfXPositionOnScreen = control.x - screen.left / control.x;
       controlBounds.xScale += percentOfPositionOnScreen * compressionRatio;
     }

     if(screen.intersects(controlBounds){
       var percentControlIsOnScreen = what percent of the control's width was on this screen
       control.widthScale += percentControlIsOnScreen * compressionRatio;
     }
  }
}

The position is then found by multiplying the original X coordinate by the scale (same for the width). 然后通过将原始X坐标乘以比例尺(与宽度相同)来找到位置。 Once the docks are removed, recalculate the scale. 卸下底座后,请重新计算比例尺。 When all docks are removed, the scale should be 1. 卸下所有扩展坞后,比例应为1。

I have left out some specifics to make it more of a generalized algorithm, but one should be able to work through this on their own system. 我遗漏了一些细节,使其更像是一种通用算法,但是应该可以在自己的系统上完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM