internal D2dRadialGradientBrush(D2dGraphics owner, PointF center, PointF gradientOriginOffset, float radiusX, float radiusY, params D2dGradientStop[] gradientStops) : base(owner) { m_center = center; m_gradientOriginOffset = gradientOriginOffset; m_radiusX = radiusX; m_radiusY = radiusY; m_gradientStops = new D2dGradientStop[gradientStops.Length]; Array.Copy(gradientStops, m_gradientStops, m_gradientStops.Length); Create();//to-do: it's dangerous to call a virtual method in a constructor; derived class may not be properly initialized! }
internal D2dLinearGradientBrush(D2dGraphics owner, PointF pt1, PointF pt2, D2dGradientStop[] gradientStops, D2dExtendMode extendMode, D2dGamma gamma) : base(owner) { m_start = pt1; m_end = pt2; m_gradientStops = new D2dGradientStop[gradientStops.Length]; Array.Copy(gradientStops, m_gradientStops, m_gradientStops.Length); m_gamma = gamma; m_extendMode = extendMode; Create();//to-do: it's dangerous to call a virtual method in a constructor; derived class may not be properly initialized! }
/// <summary> /// Creates a D2dLinearGradientBrush that contains the specified gradient stops, /// extend mode, and gamma interpolation. has no transform, and has a base opacity of 1.0.</summary> /// <param name="pt1">A System.Drawing.PointF structure that represents the starting point of the /// linear gradient</param> /// <param name="pt2">A System.Drawing.PointF structure that represents the endpoint of the linear gradient</param> /// <param name="gradientStops">An array of D2dGradientStop structures that describe the colors in the brush's gradient /// and their locations along the gradient line</param> /// <param name="extendMode">The behavior of the gradient outside the [0,1] normalized range</param> /// <param name="gamma">The space in which color interpolation between the gradient stops is performed</param> /// <returns>A new instance of D2dLinearGradientBrush</returns> public D2dLinearGradientBrush CreateLinearGradientBrush( PointF pt1, PointF pt2, D2dGradientStop[] gradientStops, D2dExtendMode extendMode, D2dGamma gamma) { return new D2dLinearGradientBrush(this, pt1, pt2, gradientStops, extendMode, gamma); }
/// <summary> /// Create shared resources using D2dFactory</summary> private void CreateSharedResources() { // create few solid color bruhes. m_brush1 = D2dFactory.CreateSolidBrush(Color.FromArgb(128, Color.Blue)); m_brush2 = D2dFactory.CreateSolidBrush(Color.Black); m_brush3 = D2dFactory.CreateSolidBrush(Color.Black); // create linear gradient brush for painting complex state (state samples). // copied from state machine editor. Color stateColor1 = System.Drawing.Color.FromArgb(142, 182, 243); float retain = 0.75f; int stred = (int)(stateColor1.R * retain); int stgreen = (int)(stateColor1.G * retain); int stblue = (int)(stateColor1.B * retain); Color stateColor2 = Color.FromArgb(stred, stgreen, stblue); D2dGradientStop[] gradstops = { new D2dGradientStop(stateColor1, 0), new D2dGradientStop(stateColor2, 1.0f), new D2dGradientStop(Color.WhiteSmoke, 1), }; m_titlebrush = D2dFactory.CreateLinearGradientBrush(gradstops); m_darkenBrush = D2dFactory.CreateLinearGradientBrush( new D2dGradientStop(Color.FromArgb(0, 0, 0, 0), 0.0f), new D2dGradientStop(Color.FromArgb(100, 0, 0, 0), 1.0f)); // create text format object for rendering the State name in the State Machine mode // note that D2dTextFormat is like System.Drawing.StringFormat but it has font too. float fontsize = 12; m_stateTextFormat = D2dFactory.CreateTextFormat("Trebuchet MS", D2dFontWeight.Bold , D2dFontStyle.Normal, D2dFontStretch.Normal, fontsize, ""); m_stateTextFormat.WordWrapping = D2dWordWrapping.NoWrap; m_stateTextFormat.TextAlignment = D2dTextAlignment.Leading; m_stateTextFormat.ParagraphAlignment = D2dParagraphAlignment.Center; D2dTrimming trimming = new D2dTrimming(); trimming.Delimiter = 0; trimming.DelimiterCount = 0; trimming.Granularity = D2dTrimmingGranularity.Character; m_stateTextFormat.Trimming = trimming; // create few states SizeF stSize = new SizeF(96, 96); for (int i = 0; i < 5; i++) { State st = new State(); st.Bound.Location = new PointF(i * stSize.Width + (i + 1) * 50, (i + 1) * stSize.Height / 3); st.Bound.Size = stSize; st.Name = "State_" + i.ToString(); m_states.Add(st); } m_states[2].Name = "long state name"; m_states[2].Bound.Width = stSize.Width + 30; // rounded rectangle for drawing state body. stRect.RadiusX = 14; stRect.RadiusY = 14; // create bitmap resources string level = Application.StartupPath + "\\Resources\\Level1.png"; m_bmp = D2dFactory.CreateBitmap(level); m_emptyBmp = D2dFactory.CreateBitmap(400, 400); Bitmap bmp = m_emptyBmp.GdiBitmap; Graphics g = Graphics.FromImage(bmp); g.Clear(Color.Blue); g.DrawLine(Pens.Yellow, new Point(0, 0), new Point(bmp.Width, bmp.Height)); m_emptyBmp.Update(); // create bitmap brush m_bmpBrush = D2dFactory.CreateBitmapBrush(m_bmp); m_bmpBrush.ExtendModeX = D2dExtendMode.Wrap; m_bmpBrush.ExtendModeY = D2dExtendMode.Wrap; m_bmpBrush.InterpolationMode = D2dBitmapInterpolationMode.NearestNeighbor; // create text format object for various test modes m_generalTextFormat = D2dFactory.CreateTextFormat("Calibri" , D2dFontWeight.Bold, D2dFontStyle.Normal, D2dFactory.FontSizeToPixel(16)); m_generalTextFormat.WordWrapping = D2dWordWrapping.NoWrap; // generate some random color. Random r = new Random(7373); for (int i = 0; i < 3000; i++) { int red = r.Next(255); int green = r.Next(255); int blue = r.Next(255); m_colors.Add(Color.FromArgb(red, green, blue)); } D2dGradientStop[] radGradstops = new D2dGradientStop[3]; D2dGradientStop[] linearGradstops = new D2dGradientStop[4]; D2dGradientStop[] linearGradstops2 = new D2dGradientStop[2]; for (int i = 0; i < 60; i++) { Color c1 = m_colors[i]; Color c2 = Color.FromArgb(c1.R / 2, c1.G / 2, c1.B / 2); radGradstops[0] = new D2dGradientStop(Color.FromArgb(255, c1), 0); radGradstops[1] = new D2dGradientStop(Color.FromArgb(240, c2), 0.94f); radGradstops[2] = new D2dGradientStop(Color.FromArgb(255, c1), 1.0f); D2dRadialGradientBrush radbrush = D2dFactory.CreateRadialGradientBrush(radGradstops); m_radialBrushes.Add(radbrush); linearGradstops[0] = new D2dGradientStop(Color.FromArgb(0, c1), 0); linearGradstops[1] = new D2dGradientStop(Color.FromArgb(200, c2), 0.7f); linearGradstops[2] = new D2dGradientStop(Color.FromArgb(255, c2), 0.90f); linearGradstops[3] = new D2dGradientStop(Color.FromArgb(255, c1), 1.0f); D2dLinearGradientBrush linearBrush = D2dFactory.CreateLinearGradientBrush(linearGradstops); m_linearBrushes.Add(linearBrush); linearGradstops2[0] = new D2dGradientStop(Color.FromArgb(255, Color.White), 0); linearGradstops2[1] = new D2dGradientStop(Color.FromArgb(0, c1), 1.0f); D2dLinearGradientBrush linearBrush2 = D2dFactory.CreateLinearGradientBrush(linearGradstops2); m_linearBrushes2.Add(linearBrush2); } }