Example #1
0
        public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
        {
            CCLog.Logger = (format, args) =>
            {
                System.Diagnostics.Debug.WriteLine(format, args);
            };

            application.ContentRootDirectory = "Content";
            var windowSize = mainWindow.WindowSizeInPixels;

            var desiredWidth  = 1024.0f;
            var desiredHeight = 768.0f;

            // This will set the world bounds to be (0,0, w, h)
            // CCSceneResolutionPolicy.ShowAll will ensure that the aspect ratio is preserved
            CCScene.SetDefaultDesignResolution(desiredWidth, desiredHeight, CCSceneResolutionPolicy.ShowAll);

            // Determine whether to use the high or low def versions of our images
            // Make sure the default texel to content size ratio is set correctly
            // Of course you're free to have a finer set of image resolutions e.g (ld, hd, super-hd)
            if (desiredWidth < windowSize.Width)
            {
                application.ContentSearchPaths.Add("hd");
                CCSprite.DefaultTexelToContentSizeRatio = 2.0f;
            }
            else
            {
                application.ContentSearchPaths.Add("ld");
                CCSprite.DefaultTexelToContentSizeRatio = 1.0f;
            }

            var scene = new CCScene(mainWindow);

            // Create your demo here
            var testLayer = new TextureFill();

            scene.AddChild(testLayer);

            mainWindow.RunWithScene(scene);
        }
Example #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                FillBase result    = null;
                string   className = (string)value;
                switch (className)
                {
                case "Solid":
                    result = new SolidFill();
                    break;

                case "LinearGradient":
                    result = new LinearGradientFill();
                    break;

                case "PathGradient":
                    result = new PathGradientFill();
                    break;

                case "Hatch":
                    result = new HatchFill();
                    break;

                case "Glass":
                    result = new GlassFill();
                    break;

                case "Texture":
                    result = new TextureFill();
                    break;
                }
                return(result);
            }
            return(base.ConvertFrom(context, culture, value));
        }
Example #3
0
 public RenderContext()
 {
     QuadBatch      = new QuadBatch();
     PrimitiveBatch = new PrimitiveBatch();
     TextureFill    = new TextureFill();
 }
Example #4
0
        public void SimpleVG(GraphicsDevice device)
        {
            ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f));

            // We first create all needed fills.
            SolidFill solidFill = new SolidFill();

            solidFill.Colour = Colour.LightBlue;


            GradientFill graFill = GradientFill.CreateGradient(
                new Colour[] { new Colour(13, 185, 242, 255), new Colour(191, 234, 21, 255),
                               new Colour(112, 62, 193, 255), new Colour(255, 242, 81, 255) },
                new float[] { 0.30f, 0.60f }, new Vector2f(1, 1));


            TextureFill texFill = new TextureFill(CreateSampleTexture());

            RadialFill radFill = new RadialFill(new Vector2f(0.75f, 0.75f), 0.15f, Colour.White, Colour.Black);

            Quad2f rect  = new Quad2f(Vector2f.Zero, new Vector2f(0.5f, 0), new Vector2f(0.5f, 0.5f), new Vector2f(0.0f, 0.5f));
            Quad2f rect2 = new Quad2f(new Vector2f(0.5f, 0.5f), new Vector2f(1, 0.5f), new Vector2f(1, 1), new Vector2f(0.5f, 1.0f));


            bool exit = false;

            device.SwapChain.Window.Closed += delegate(Window w) { exit = true; };

            float a = 0;

            while (!exit)
            {
                device.SwapChain.Window.DoEvents();

                using (DeviceLock l = device.Lock())
                {
                    device.Clear(device.SwapChain, Colour.Green);

                    device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height));

                    // We render.
                    canvas.Begin(CanvasRenderFlags.None);


                    canvas.FillShape(solidFill, rect, null);
                    canvas.FillShape(radFill, rect2, null);
                    canvas.Transform = new LinearTransform(
                        new Math.Matrix.Matrix4x4f(Math.MathHelper.Cos(a), -Math.MathHelper.Sin(a), 0, 0,
                                                   Math.MathHelper.Sin(a), Math.MathHelper.Cos(a), 0, 0,
                                                   0, 0, 1, 0,
                                                   0, 0, 0, 1));
                    canvas.FillShape(graFill, rect, null);
                    canvas.FillShape(texFill, rect2, null);



                    canvas.End();
                }


                Console.WriteLine("FPS: {0}\nTrig Count: {1}", device.DevicePerformance.CurrentFPS,
                                  device.DevicePerformance.MaxTrianglesPerFrame);

                a += 0.003f;

                device.SwapChain.Present();
            }

            texFill.Texture.Dispose();
        }