public void SizeTrackerNegativeTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(-5, -10));
			Assert.AreEqual(0.5, sizeTracker.Ratio);

			sizeTracker.Width = 20;
			Assert.AreEqual(40, sizeTracker.Height);
		}
		public void SizeTrackerDoNotMaintainAspectRatioTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(800, 600), false);

			sizeTracker.Height = 480;
			Assert.AreEqual(800, sizeTracker.Width);

			sizeTracker.Width = 100;
			Assert.AreEqual(480, sizeTracker.Height);
		}
		public void SizeTrackerEmptyTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(Size.Empty);
			Assert.AreEqual(1.0, sizeTracker.Ratio);
			
			sizeTracker.Height = 0;
			sizeTracker.Width = 0;
			Assert.AreEqual(1.0, sizeTracker.Ratio);

			sizeTracker.Width = 5;
			Assert.AreEqual(1.0, sizeTracker.Ratio);
		}
		public void SizeTrackerEventTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(800, 600));
			SizeTrackerEventSink eventSink = new SizeTrackerEventSink(sizeTracker);

			eventSink.ExpectedWidth = 640;
			eventSink.ExpectedHeight = 480;
			eventSink.ExpectedHeightChangedCallsCount = 1;
			eventSink.ExpectedWidthChangedCallsCount = 0;

			sizeTracker.Width = 640;
			Assert.AreEqual(new Size(640, 480), sizeTracker.Size);

			eventSink.Verify();
		}
		/*
		 * SetResolutionFromImage
		 */

		/// <summary>
		/// Sets the initial resolution that is displayed on the UI.
		/// </summary>
		/// <param name="image">Specifies the <see cref="T:Image"/> to set the initial resolution upon.</param>
		public void SetResolutionFromImage(Image image)
		{
			Size size = Size.Empty;

			if (image != null)
			{
				size = image.Size;
			}

			this.SizeTracker = new NuGenRatioSizeTracker(size);
			this.SizeTracker.HeightChanged += sizeTracker_HeightChanged;
			this.SizeTracker.WidthChanged += sizeTracker_WidthChanged;
			this._widthNumeric.Value = size.Width;
			this._heightNumeric.Value = size.Height;

			this.Enabled = size != Size.Empty;
		}
Example #6
0
        /*
         * SetResolutionFromImage
         */

        /// <summary>
        /// Sets the initial resolution that is displayed on the UI.
        /// </summary>
        /// <param name="image">Specifies the <see cref="T:Image"/> to set the initial resolution upon.</param>
        public void SetResolutionFromImage(Image image)
        {
            Size size = Size.Empty;

            if (image != null)
            {
                size = image.Size;
            }

            this.SizeTracker = new NuGenRatioSizeTracker(size);
            this.SizeTracker.HeightChanged += sizeTracker_HeightChanged;
            this.SizeTracker.WidthChanged  += sizeTracker_WidthChanged;
            this._widthNumeric.Value        = size.Width;
            this._heightNumeric.Value       = size.Height;

            this.Enabled = size != Size.Empty;
        }
		public void SizeTrackerMaintainAspectRatioTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(800, 600));

			Assert.AreEqual(800.0 / 600.0, sizeTracker.Ratio);

			sizeTracker.Height = 480;
			Assert.AreEqual(640, sizeTracker.Size.Width);

			sizeTracker.Width = 1280;
			Assert.AreEqual(960, sizeTracker.Size.Height);

			sizeTracker.Height = 240;
			Assert.AreEqual(320, sizeTracker.Size.Width);

			sizeTracker.Width = 100;
			Assert.AreEqual(75, sizeTracker.Size.Height);
		}
			public SizeTrackerEventSink(NuGenRatioSizeTracker sizeTracker)
			{
				if (sizeTracker == null)
				{
					throw new ArgumentNullException("sizeTracker");
				}

				this.sizeTracker = sizeTracker;

				this.sizeTracker.HeightChanged += delegate
				{
					this.expectedHeight.Actual = this.sizeTracker.Height;
					this.expectedWidth.Actual = this.sizeTracker.Width;
					this.expectedHeightChangedCallsCount.Inc();
				};

				this.sizeTracker.WidthChanged += delegate
				{
					this.expectedWidth.Actual = this.sizeTracker.Width;
					this.expectedHeight.Actual = this.sizeTracker.Width;
					this.expectedWidthChangedCallsCount.Inc();
				};
			}
		public void SizeTrackerDoNotMaintainAspectRatioEventTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(800, 600), false);
			SizeTrackerEventSink eventSink = new SizeTrackerEventSink(sizeTracker);

			eventSink.ExpectedHeightChangedCallsCount = 0;
			eventSink.ExpectedWidthChangedCallsCount = 0;

			sizeTracker.Height = 800;
			Assert.AreEqual(new Size(800, 800), sizeTracker.Size);

			sizeTracker.Width = 480;
			Assert.AreEqual(new Size(480, 800), sizeTracker.Size);

			eventSink.Verify();
		}