Example #1
0
File: Form1.cs Project: Joxx0r/ATF
        /// <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);

            }
        }
Example #2
0
File: Form1.cs Project: Joxx0r/ATF
        private void DrawState(State state, float scale)
        {
            RectangleF stbound = state.Bound;
            stRect.Rect = stbound;

            // paint state body.
            m_titlebrush.StartPoint = new PointF(0, stbound.Y);
            m_titlebrush.EndPoint = new PointF(0, stbound.Y + TitleBarHeight);
            m_d2dGraphics.FillRoundedRectangle(stRect, m_titlebrush);

            float outlinewidth = 2.0f / scale;

            m_d2dGraphics.DrawRoundedRectangle(stRect, m_brush1, outlinewidth);
            m_d2dGraphics.DrawLine(
                new PointF(stbound.X, stbound.Y + TitleBarHeight),
                new PointF(stbound.Right, stbound.Y + TitleBarHeight),
                m_brush1, outlinewidth);

            // draw state name.
            RectangleF nameRect =
                new RectangleF(stbound.X + 10, stbound.Y, stbound.Width - 20, TitleBarHeight);
            m_d2dGraphics.DrawText(state.Name, m_stateTextFormat, nameRect, m_brush2);
        }