Exemple #1
0
        public static ShapeDescriptor DrawRectangularOutline(Vector2 position,
                                                             Size size, int borderSize, Color borderColor,
                                                             BorderStyle style, Border borders)
        {
            switch (style)
            {
            case BorderStyle.Raised:
                return(DrawRectangularOutline(position, size,
                                              Color.FromArgb(255, ColorOperator.Scale(borderColor, lightShadeFactor)),
                                              Color.FromArgb(255, ColorOperator.Scale(borderColor, darkShadeFactor)),
                                              borderSize, borders));

            case BorderStyle.Sunken:
                return(DrawRectangularOutline(position, size,
                                              Color.FromArgb(255, ColorOperator.Scale(borderColor, darkShadeFactor)),
                                              Color.FromArgb(255, ColorOperator.Scale(borderColor, lightShadeFactor)),
                                              borderSize, borders));

            case BorderStyle.Flat:
            default:
                return(DrawRectangularOutline(position, size,
                                              borderColor, borderColor,
                                              borderSize, borders));
            }
        }
Exemple #2
0
        /// <summary>
        /// Shades a rectangle right to left using the specified color.
        /// </summary>
        /// <param name="color">The color.</param>
        /// <returns>An array of ints containing the color of each vertex (0: top left 1: top right 2: bottomLeft 3: bottom right</returns>
        public static int[] ShadeRightToLeft(Color color)
        {
            int colorTopLeft     = Color.FromArgb(color.A, ColorOperator.Scale(color, darkShadeFactor)).ToArgb();
            int colorTopRight    = color.ToArgb();
            int colorBottomLeft  = colorTopLeft;
            int colorBottomRight = colorTopRight;

            return(new int[] { colorTopLeft, colorTopRight, colorBottomLeft, colorBottomRight });
        }
Exemple #3
0
        /// <summary>
        /// Draws a right trapezoidal outline.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="size">The size.</param>
        /// <param name="triangleWidth">Width of the triangle.</param>
        /// <param name="isTriangleUpside">Ff set to <c>true</c> the triangle will be upside.</param>
        /// <param name="color">The color.</param>
        /// <param name="borderSize">Size of the border.</param>
        /// <param name="borderColor">Color of the border.</param>
        /// <param name="style">The style.</param>
        /// <param name="rectangleBorders">The rectangle borders.</param>
        /// <param name="triangleBorders">The triangle borders.</param>
        /// <returns>A right trapezoidal outline ShapeDescriptor object.</returns>
        public static ShapeDescriptor DrawRightTrapezoidalOutline(Vector2 position, Size size,
                                                                  int triangleWidth, bool isTriangleUpside, Color color,
                                                                  int borderSize, Color borderColor,
                                                                  BorderStyle style, Border rectangleBorders,
                                                                  Border triangleBorders)
        {
            Vector2 topLeft   = position;
            Size    innerSize = new Size(size.Width - borderSize, size.Height - borderSize);

            ShapeDescriptor sTriangleSide     = ShapeDescriptor.Empty;
            ShapeDescriptor sTriangleBase     = ShapeDescriptor.Empty;
            ShapeDescriptor sRectangleOutline =
                DrawRectangularOutline(topLeft, size, borderSize, borderColor, style,
                                       rectangleBorders);

            if (isTriangleUpside)
            {
                if ((triangleBorders & Border.Right) == Border.Right)
                {
                    sTriangleSide = DrawLine(borderSize,
                                             Color.FromArgb(255, ColorOperator.Scale(borderColor, lightShadeFactor)),
                                             new Vector2(topLeft.X + size.Width, position.Y + (borderSize / 2)),
                                             new Vector2(topLeft.X + size.Width + triangleWidth,
                                                         topLeft.Y + size.Height - (borderSize / 2)));
                }

                if ((triangleBorders & Border.Bottom) == Border.Bottom)
                {
                    sTriangleBase =
                        DrawRectangle(new Vector2(topLeft.X + size.Width, topLeft.Y + size.Height - borderSize),
                                      new Size(triangleWidth, borderSize),
                                      Color.FromArgb(255, ColorOperator.Scale(borderColor, darkShadeFactor)));
                }
            }
            else
            {
                if ((triangleBorders & Border.Left) == Border.Left)
                {
                    sTriangleSide = DrawLine(borderSize,
                                             Color.FromArgb(255, ColorOperator.Scale(borderColor, darkShadeFactor)),
                                             new Vector2(topLeft.X + innerSize.Width,
                                                         position.Y + size.Height - (borderSize / 2)),
                                             new Vector2(topLeft.X + innerSize.Width + triangleWidth,
                                                         position.Y + (borderSize / 2)));
                }


                if ((triangleBorders & Border.Top) == Border.Top)
                {
                    sTriangleBase = DrawRectangle(new Vector2(topLeft.X + innerSize.Width - borderSize, topLeft.Y),
                                                  new Size(triangleWidth, borderSize),
                                                  Color.FromArgb(255, ColorOperator.Scale(borderColor, lightShadeFactor)));
                }
            }

            return(ShapeDescriptor.Join(sRectangleOutline, sTriangleSide, sTriangleBase));
        }
Exemple #4
0
        /// <summary>
        /// This callback function will be called at the end of every frame to perform all the
        /// rendering calls for the scene, and it will also be called if the window needs to be
        /// repainted. After this function has returned, the sample framework will call
        /// Device.Present to display the contents of the next buffer in the swap chain
        /// </summary>
        public void OnFrameRender(Device device, double appTime, float elapsedTime)
        {
            bool beginSceneCalled = false;

            // Clear the render target and the zbuffer
            device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, unchecked ((int)0x8C003F3F), 1.0f, 0);
            try {
                device.BeginScene();
                beginSceneCalled = true;

                // Render the arrows so the user can visually see the light direction
                ColorValue arrowColor = LightColor;
                lightControl.OnRender(arrowColor, camera.ViewMatrix, camera.ProjectionMatrix, camera.EyeLocation);

                if (nif != null)
                {
                    // Update the effects now
                    Vector3 ldir = lightControl.LightDirection;
                    Vector3 edir = -camera.EyeVector;
                    Vector3 hdir = ldir + edir;
                    hdir.Normalize();
                    float[] dir = new float[] { ldir.X, ldir.Y, ldir.Z };
                    effect.SetValue(ehLightDir, dir);
                    effect.SetValue(ehLightCol, ColorOperator.Scale(LightColor, lightScale));
                    effect.SetValue(egAmbCol, ColorOperator.Scale(AmbientLightColor, ambLightScale));
                    effect.SetValue(ehViewProj, camera.ViewMatrix * camera.ProjectionMatrix);
                    dir = new float[] { camera.EyeLocation.X, camera.EyeLocation.Y, camera.EyeLocation.Z };
                    effect.SetValue(ehEyePos, dir);
                    dir = new float[] { edir.X, edir.Y, edir.Z };
                    effect.SetValue(ehEyeVec, dir);
                    dir = new float[] { hdir.X, hdir.Y, hdir.Z };
                    effect.SetValue(ehHalfVec, dir);

                    // Apply the technique contained in the effect
                    if (currentSubset == -1)
                    {
                        nif.Render();
                    }
                    else
                    {
                        nif.RenderSubset(currentSubset);
                    }
                }

                // Show frame rate and help, etc
                RenderText(appTime);

                // Show UI
                hud.OnRender(elapsedTime);
                sampleUi.OnRender(elapsedTime);
            } finally {
                if (beginSceneCalled)
                {
                    device.EndScene();
                }
            }
        }
Exemple #5
0
        public override void CreateShape()
        {
            base.CreateShape();
            buttonDescriptor   = ShapeDescriptor.ComputeShape(this, Shape.Rectangle);
            triangleDescriptor =
                Shapes.DrawEquilateralTriangle(triangleLeftVertexAbsolutePosition, DefaultTriangleSideLength,
                                               ColorOperator.Scale(Color.Black, 0.5f), false, false);
            buttonDescriptor.Depth   = depth;
            triangleDescriptor.Depth = Depth.AsChildOf(depth);

            shapeDescriptors[0] = buttonDescriptor;
            shapeDescriptors[1] = triangleDescriptor;
        }
Exemple #6
0
        public static ShapeDescriptor DrawEquilateralTriangle(Vector2 leftVertex, float sideLength, Color color,
                                                              bool isShaded, bool isTriangleUpside)
        {
            CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[3];
            Color shaded;
            float heightOffset = (float)(sideLength / 2 * Math.Sqrt(3));

            int col1 = color.ToArgb();
            int col2;

            if (isShaded)
            {
                shaded = Color.FromArgb(color.A, ColorOperator.Scale(color, darkShadeFactor));
                col2   = shaded.ToArgb();
            }
            else
            {
                col2 = col1;
            }

            vertices[0] = new CustomVertex.TransformedColored(leftVertex.X, leftVertex.Y, 0, 1, col2);
            vertices[1] = new CustomVertex.TransformedColored(leftVertex.X + sideLength, leftVertex.Y, 0, 1, col2);

            int[] indices = new int[3];

            if (isTriangleUpside)
            {
                heightOffset *= -1;
                indices[0]    = 0;
                indices[1]    = 1;
                indices[2]    = 2;
            }
            else
            {
                indices[0] = 2;
                indices[1] = 0;
                indices[2] = 1;
            }

            vertices[2] =
                new CustomVertex.TransformedColored(leftVertex.X + sideLength / 2, leftVertex.Y + heightOffset, 0, 1, col1);


            return(new ShapeDescriptor(1, vertices, indices));
        }
Exemple #7
0
        /// <summary>
        /// This callback function will be called at the end of every frame to perform all the
        /// rendering calls for the scene, and it will also be called if the window needs to be
        /// repainted. After this function has returned, the sample framework will call
        /// Device.Present to display the contents of the next buffer in the swap chain
        /// </summary>
        public unsafe void OnFrameRender(Device device, double appTime, float elapsedTime)
        {
            bool beginSceneCalled = false;

            // Clear the render target and the zbuffer
            device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, unchecked ((int)0x8C003F3F), 1.0f, 0);
            try
            {
                device.BeginScene();
                beginSceneCalled = true;

                Vector3 *   pLightDir     = stackalloc Vector3[MaxNumberLights];
                ColorValue *pLightDiffuse = stackalloc ColorValue[MaxNumberLights];

                // Render the arrows so the user can visually see the light direction
                for (int i = 0; i < numberActiveLights; i++)
                {
                    ColorValue arrowColor = (i == activeLight) ? YellowColor : WhiteColor;
                    lightControl[i].OnRender(arrowColor, camera.ViewMatrix, camera.ProjectionMatrix, camera.EyeLocation);
                    // Get the light direction and color
                    pLightDir[i]     = lightControl[i].LightDirection;
                    pLightDiffuse[i] = ColorOperator.Scale(WhiteColor, lightScale);
                }

                Matrix worldMatrix = worldFix * camera.WorldMatrix;
                // Update the effects now
                effect.SetValue("g_LightDir", pLightDir, sizeof(Vector3) * MaxNumberLights);
                effect.SetValue("g_LightDiffuse", pLightDiffuse, sizeof(ColorValue) * MaxNumberLights);

                // Update the effect's variables.  Instead of using strings, it would
                // be more efficient to cache a handle to the parameter by calling
                // Effect.GetParameter
                effect.SetValue("worldViewProjection", worldMatrix * camera.ViewMatrix * camera.ProjectionMatrix);
                effect.SetValue("worldMatrix", worldMatrix);
                effect.SetValue("appTime", (float)appTime);

                effect.SetValue("g_MaterialDiffuseColor", WhiteColor);
                effect.SetValue("g_nNumLights", numberActiveLights);

                // Render the scene with this technique as defined in the .fx file
                switch (numberActiveLights)
                {
                case 1: effect.Technique = "RenderSceneWithTexture1Light"; break;

                case 2: effect.Technique = "RenderSceneWithTexture2Light"; break;

                case 3: effect.Technique = "RenderSceneWithTexture3Light"; break;
                }

                // Apply the technique contained in the effect
                int passes = effect.Begin(0);
                for (int pass = 0; pass < passes; pass++)
                {
                    effect.BeginPass(pass);

                    // The effect interface queues up the changes and performs them
                    // with the CommitChanges call. You do not need to call CommitChanges if
                    // you are not setting any parameters between the BeginPass and EndPass.
                    // effect.CommitChanges() );

                    // Render the mesh with the applied technique
                    mesh.DrawSubset(0);
                    effect.EndPass();
                }
                effect.End();

                // Show frame rate and help, etc
                RenderText(appTime);

                // Show UI
                hud.OnRender(elapsedTime);
                sampleUi.OnRender(elapsedTime);
            }
            finally
            {
                if (beginSceneCalled)
                {
                    device.EndScene();
                }
            }
        }