/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		public void DrawShadow(NuGenPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Rectangle bounds = paintParams.Bounds;

			int alpha = 0;
			Color baseColor = Color.Black;
			int alphaStep = 5;
			Padding deflatePadding = new Padding(1);

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				NuGenControlPaint.SetGraphicsVeryHighQuality(g);

				using (Pen pen = new Pen(Color.FromArgb(alpha, baseColor)))
				{
					for (int i = 0; i <= _shadowStepCount; i++)
					{
						g.DrawRectangle(pen, bounds);
						pen.Color = Color.FromArgb(alpha += alphaStep, baseColor);
						bounds = NuGenControlPaint.DeflateRectangle(bounds, deflatePadding);

						if (i == 1)
						{
							alphaStep = 10;
						}
					}
				}
			}
		}
Exemplo n.º 2
0
		public void PixelOffsetModeEmptyBlockTest()
		{
			_grfx.PixelOffsetMode = PixelOffsetMode.HighQuality;

			using (NuGenGrfxMode mode = new NuGenGrfxMode(_grfx))
			{
			}

			Assert.AreEqual(PixelOffsetMode.HighQuality, _grfx.PixelOffsetMode);
		}
Exemplo n.º 3
0
		public void SmoothingModeEmptyTest()
		{
			_grfx.SmoothingMode = SmoothingMode.AntiAlias;

			using (NuGenGrfxMode mode = new NuGenGrfxMode(_grfx))
			{
			}

			Assert.AreEqual(SmoothingMode.AntiAlias, _grfx.SmoothingMode);
		}
Exemplo n.º 4
0
		public void PixelOffsetModeTest()
		{
			_grfx.SmoothingMode = SmoothingMode.AntiAlias;

			using (NuGenGrfxMode mode = new NuGenGrfxMode(_grfx))
			{
				_grfx.PixelOffsetMode = PixelOffsetMode.HighSpeed;
			}

			Assert.AreEqual(SmoothingMode.AntiAlias, _grfx.SmoothingMode);
		}
Exemplo n.º 5
0
        /*
         * DrawBorder
         */

        /// <summary>
        /// Draws the border with the specified style.
        /// </summary>
        /// <exception cref="ArgumentNullException"><para><paramref name="g"/> is <see langword="null"/>.</para></exception>
        public static void DrawBorder(Graphics g, Rectangle rect, Color borderColor, NuGenBorderStyle borderStyle)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            if (borderStyle == NuGenBorderStyle.None)
            {
                return;
            }

            using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
            {
                g.SmoothingMode = SmoothingMode.Default;

                if (borderStyle == NuGenBorderStyle.Bump ||
                    borderStyle == NuGenBorderStyle.Etched ||
                    borderStyle == NuGenBorderStyle.Flat ||
                    borderStyle == NuGenBorderStyle.Raised ||
                    borderStyle == NuGenBorderStyle.RaisedInner ||
                    borderStyle == NuGenBorderStyle.RaisedOuter ||
                    borderStyle == NuGenBorderStyle.Sunken ||
                    borderStyle == NuGenBorderStyle.SunkenInner ||
                    borderStyle == NuGenBorderStyle.SunkenOuter)
                {
                    ControlPaint.DrawBorder3D(g, rect, (Border3DStyle)borderStyle);
                }
                else
                {
                    using (SolidBrush sb = new SolidBrush(borderColor))
                        using (Pen p = new Pen(sb))
                        {
                            switch (borderStyle)
                            {
                            case NuGenBorderStyle.Dashed:
                                p.DashStyle = DashStyle.Dash;
                                break;

                            case NuGenBorderStyle.Dotted:
                                p.DashStyle = DashStyle.Dot;
                                break;

                            case NuGenBorderStyle.Solid:
                                p.DashStyle = DashStyle.Solid;
                                break;
                            }

                            g.DrawRectangle(p, new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1));
                        }
                }
            }
        }
		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="paintParams"/> is <see langword="null"/>.</para>
		/// </exception>
		public void DrawTrackButton(NuGenTrackButtonPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Rectangle bounds = paintParams.Bounds;
			NuGenControlState state = paintParams.State;
			TickStyle tickStyle = paintParams.Style;

			Rectangle borderRectangle = NuGenControlPaint.BorderRectangle(bounds);

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.SmoothingMode = SmoothingMode.AntiAlias;

				using (GraphicsPath gp = NuGenSmoothTrackBarRenderer.GetGraphicsPath(borderRectangle, tickStyle))
				{
					/* Background */

					using (
							Brush brush = this.GetBackgroundBrush(
								borderRectangle,
								state == NuGenControlState.Normal || state == NuGenControlState.Focused
									? NuGenControlState.Hot
									: state
							)
						)
					{
						g.FillPath(brush, gp);
					}

					/* Body */

					Rectangle bodyRectangle = Rectangle.Inflate(borderRectangle, 0, -3);

					using (GraphicsPath bgp = NuGenSmoothTrackBarRenderer.GetBodyGraphicsPath(borderRectangle, tickStyle))
					using (Brush brush = this.GetBackgroundBrush(bodyRectangle, state))
					{
						g.FillPath(brush, bgp);
					}

					/* Border */

					using (Pen pen = this.GetBorderPen(state))
					{
						g.DrawPath(pen, gp);
					}
				}
			}
		}
		/*
		 * DrawBorder
		 */

		/// <summary>
		/// Draws the border with the specified style.
		/// </summary>
		/// <exception cref="ArgumentNullException"><para><paramref name="g"/> is <see langword="null"/>.</para></exception>
		public static void DrawBorder(Graphics g, Rectangle rect, Color borderColor, NuGenBorderStyle borderStyle)
		{
			if (g == null)
			{
				throw new ArgumentNullException("g");
			}

			if (borderStyle == NuGenBorderStyle.None)
			{
				return;
			}

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.SmoothingMode = SmoothingMode.Default;

				if (borderStyle == NuGenBorderStyle.Bump
					|| borderStyle == NuGenBorderStyle.Etched
					|| borderStyle == NuGenBorderStyle.Flat
					|| borderStyle == NuGenBorderStyle.Raised
					|| borderStyle == NuGenBorderStyle.RaisedInner
					|| borderStyle == NuGenBorderStyle.RaisedOuter
					|| borderStyle == NuGenBorderStyle.Sunken
					|| borderStyle == NuGenBorderStyle.SunkenInner
					|| borderStyle == NuGenBorderStyle.SunkenOuter)
				{
					ControlPaint.DrawBorder3D(g, rect, (Border3DStyle)borderStyle);
				}
				else
				{
					using (SolidBrush sb = new SolidBrush(borderColor))
					using (Pen p = new Pen(sb))
					{
						switch (borderStyle)
						{
							case NuGenBorderStyle.Dashed:
							p.DashStyle = DashStyle.Dash;
							break;
							case NuGenBorderStyle.Dotted:
							p.DashStyle = DashStyle.Dot;
							break;
							case NuGenBorderStyle.Solid:
							p.DashStyle = DashStyle.Solid;
							break;
						}

						g.DrawRectangle(p, new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1));
					}
				}
			}
		}
		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException"><para><paramref name="paintParams"/> is <see langword="null"/>.</para></exception>
		public void DrawBorder(NuGenPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
				this.DrawRoundBorder(g, NuGenControlPaint.BorderRectangle(paintParams.Bounds), paintParams.State);
			}
		}
		/*
		 * DrawBackground
		 */

		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="paintParams"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public new void DrawBackground(NuGenPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Rectangle bounds = paintParams.Bounds;
			NuGenControlState state = paintParams.State;

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.SmoothingMode = SmoothingMode.AntiAlias;
				g.PixelOffsetMode = PixelOffsetMode.HighQuality;
				this.DrawRoundBackground(g, bounds, state);
			}
		}
				public override void Paint(PaintEventArgs e)
				{
					Graphics g = e.Graphics;

					using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
					using (Pen pen = this.Painter._sketchCanvas.CreatePen())
					{
						this.Painter._sketchCanvas.InitializeGraphics(g);

						foreach (Point[] figure in _firgures)
						{
							if (figure.Length > 1)
							{
								g.DrawLines(pen, figure);
							}
						}
					}
				}
				public override void MouseMove(MouseEventArgs e)
				{
					if (_isDrawing)
					{
						_currentFigure.Add(e.Location);

						using (Graphics g = Graphics.FromHwnd(this.Painter._sketchCanvas._hWnd))
						using (Pen pen = this.Painter._sketchCanvas.CreatePen())
						{
							using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
							{
								this.Painter._sketchCanvas.InitializeGraphics(g);

								int figureCount = _currentFigure.Count;
								g.DrawLine(pen, _currentFigure[figureCount - 1], _currentFigure[figureCount - 2]);
							}
						}
					}
				}
		/*
		 * DrawRadioButton
		 */

		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="paintParams"/> is <see langword="null"/>.</para>
		/// </exception>
		public void DrawRadioButton(NuGenRadioButtonPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Rectangle bounds = paintParams.Bounds;
			NuGenControlState state = paintParams.State;

			this.DrawEllipseBackground(g, bounds, state);

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.SmoothingMode = SmoothingMode.AntiAlias;
				this.DrawEllipseBorder(g, bounds, state);
			}

			if (paintParams.Checked)
			{
				this.DrawRadio(g, bounds, state);
			}
		}
		/*
		 * DrawRadio
		 */

		/// <summary>
		/// </summary>
		/// <param name="g"></param>
		/// <param name="bounds"></param>
		/// <param name="state"></param>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="g"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		private void DrawRadio(Graphics g, Rectangle bounds, NuGenControlState state)
		{
			if (g == null)
			{
				throw new ArgumentNullException("g");
			}

			Debug.Assert(this.ColorManager != null, "this.ColorManager != null");
			bounds.Inflate(-3, -3);
			using (SolidBrush sb = new SolidBrush(this.ColorManager.GetBorderColor(state)))
			{
				using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
				{
					g.SmoothingMode = SmoothingMode.AntiAlias;
					g.FillEllipse(sb, bounds);
				}
			}
		}
		/*
		 * DrawForeground
		 */

		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="paintParams"/> is <see langword="null"/>.</para>
		/// </exception>
		public void DrawForeground(NuGenPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Rectangle bounds = paintParams.Bounds;

			if (bounds.Height > 0 && bounds.Width > 0)
			{
				using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
				{
					g.SmoothingMode = SmoothingMode.AntiAlias;
					this.DrawBackground(paintParams.Graphics, bounds, NuGenControlState.Pressed);
				}
			}
		}
		/*
		 * DrawTabButton
		 */

		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="paintParams"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public void DrawTabButton(NuGenTabButtonPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Rectangle bounds = paintParams.Bounds;
			NuGenControlState currentState = NuGenControlState.Normal;

			/* Helps to draw background properly if the BackColor property is set to Color.Transparent. */
			g.FillRectangle(SystemBrushes.Control, new Rectangle(0, 0, bounds.Width, 2));

			switch (paintParams.State)
			{
				case TabItemState.Disabled:
				{
					currentState = NuGenControlState.Disabled;
					break;
				}
				case TabItemState.Hot:
				{
					currentState = NuGenControlState.Hot;
					break;
				}
				case TabItemState.Selected:
				{
					currentState = NuGenControlState.Pressed;
					break;
				}
				default:
				{
					currentState = NuGenControlState.Normal;
					break;
				}
			}

			Rectangle tweakedRectangle = NuGenControlPaint.BorderRectangle(bounds);

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.SmoothingMode = SmoothingMode.AntiAlias;
				DrawRoundBackground(g, tweakedRectangle, currentState, NuGenRoundRectangleStyle.TopRound);
				DrawRoundBorder(g, tweakedRectangle, currentState, NuGenRoundRectangleStyle.TopRound);
			}

			this.DrawText(
				g, 
				paintParams.TextBounds, 
				currentState, 
				paintParams.Text, 
				paintParams.Font, 
				paintParams.ForeColor, 
				System.Drawing.ContentAlignment.MiddleLeft
			);

			if (paintParams.Image != null)
			{
				this.DrawImage(
					g, 
					paintParams.ImageBounds, 
					currentState, 
					paintParams.Image
				);
			}
		}
Exemplo n.º 16
0
		public void TextRenderingHintTest()
		{
			_grfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

			using (NuGenGrfxMode mode = new NuGenGrfxMode(_grfx))
			{
				_grfx.TextRenderingHint = TextRenderingHint.SystemDefault;
			}

			Assert.AreEqual(TextRenderingHint.ClearTypeGridFit, _grfx.TextRenderingHint);
		}
		/*
		 * DrawShadow
		 */

		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="paintParams"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public void DrawShadow(NuGenPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Rectangle bounds = paintParams.Bounds;

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.SmoothingMode = SmoothingMode.AntiAlias;
				g.PixelOffsetMode = PixelOffsetMode.HighQuality;

				for (int i = 0; i < _shadowColorsCount; i++)
				{
					using (Pen pen = new Pen(_shadowColors[i]))
					{
						NuGenControlPaint.DrawRoundRectangle(g, pen, bounds, _shadowColorsCount - i);
					}

					bounds.Inflate(-1, -1);
				}
			}
		}
		/*
		 * DrawText
		 */

		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException"><paramref name="paintParams"/> is <see langword="null"/>.</exception>
		public new void DrawText(NuGenTextPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

				using (StringFormat sf = new StringFormat())
				{
					sf.Trimming = StringTrimming.EllipsisCharacter;

					base.DrawText(
						paintParams.Graphics,
						paintParams.Bounds,
						paintParams.State,
						paintParams.Text,
						paintParams.Font,
						paintParams.ForeColor,
						sf
					);
				}
			}
		}