Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows;
|
---|
6 |
|
---|
7 | namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints
|
---|
8 | {
|
---|
9 | /// <summary>
|
---|
10 | /// Represents a constraint, which limits the maximal size of <see cref="Viewport"/>'s Visible property.
|
---|
11 | /// </summary>
|
---|
12 | public class MaximalSizeConstraint : ViewportConstraint
|
---|
13 | {
|
---|
14 | /// <summary>
|
---|
15 | /// Initializes a new instance of the <see cref="MaximalSizeConstraint"/> class.
|
---|
16 | /// </summary>
|
---|
17 | public MaximalSizeConstraint() { }
|
---|
18 |
|
---|
19 | /// <summary>
|
---|
20 | /// Initializes a new instance of the <see cref="MaximalSizeConstraint"/> class with the given maximal size of Viewport's Visible.
|
---|
21 | /// </summary>
|
---|
22 | /// <param name="maxSize">Maximal size of Viewport's Visible.</param>
|
---|
23 | public MaximalSizeConstraint(double maxSize)
|
---|
24 | {
|
---|
25 | MaxSize = maxSize;
|
---|
26 | }
|
---|
27 |
|
---|
28 | private double maxSize = 1000;
|
---|
29 | /// <summary>
|
---|
30 | /// Gets or sets the maximal size of Viewport's Visible.
|
---|
31 | /// The default value is 1000.0.
|
---|
32 | /// </summary>
|
---|
33 | /// <value>The size of the max.</value>
|
---|
34 | public double MaxSize
|
---|
35 | {
|
---|
36 | get { return maxSize; }
|
---|
37 | set
|
---|
38 | {
|
---|
39 | if (maxSize != value)
|
---|
40 | {
|
---|
41 | maxSize = value;
|
---|
42 | RaiseChanged();
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | /// <summary>
|
---|
48 | /// Applies the specified old data rect.
|
---|
49 | /// </summary>
|
---|
50 | /// <param name="oldDataRect">The old data rect.</param>
|
---|
51 | /// <param name="newDataRect">The new data rect.</param>
|
---|
52 | /// <param name="viewport">The viewport.</param>
|
---|
53 | /// <returns></returns>
|
---|
54 | public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport)
|
---|
55 | {
|
---|
56 | bool decreasing = newDataRect.Width < oldDataRect.Width || newDataRect.Height < oldDataRect.Height;
|
---|
57 | if (!decreasing && (newDataRect.Width > maxSize || newDataRect.Height > maxSize))
|
---|
58 | return oldDataRect;
|
---|
59 |
|
---|
60 | return newDataRect;
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.