Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SDL2Cursor"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="surface">The surface that contains the cursor image.</param>
        /// <param name="hx">The x-coordinate of the cursor's hotspot.</param>
        /// <param name="hy">The y-coordinate of the cursor's hotspot.</param>
        public SDL2Cursor(UltravioletContext uv, Surface2D surface, Int32 hx, Int32 hy)
            : base(uv)
        {
            Contract.Require(surface, nameof(surface));

            uv.ValidateResource(surface);

            if (uv.Platform != UltravioletPlatform.Android && uv.Platform != UltravioletPlatform.iOS)
            {
                this.cursor   = SDL_CreateColorCursor(((SDL2Surface2D)surface).NativePtr, hx, hy);
                this.Width    = surface.Width;
                this.Height   = surface.Height;
                this.HotspotX = hx;
                this.HotspotY = hy;

                if (this.cursor == null)
                {
                    this.Width    = 0;
                    this.Height   = 0;
                    this.HotspotX = 0;
                    this.HotspotY = 0;
                }
            }
            else
            {
                this.cursor = null;
                this.Width  = 0;
                this.Height = 0;
            }
        }
Exemplo n.º 2
0
Arquivo: 2Mic.cs Projeto: azret/mozart
    static void onDrawMicWave(Surface2D Canvas, float phase, Mic32 mic)
    {
        int m       = 10,
            samples = (int)Math.Pow(2, m);

        Canvas.Fill(Canvas._bgColor);

        var data = mic.CH1();

        Debug.Assert(data.Length == samples);

        int linear(float val, float from, float to)
        {
            return((int)(val * to / from));
        }

        Canvas.Line((x, width) => Color.FromArgb(60, 60, 60), (x, width) => {
            int i = linear(x, width, data.Length);
            return(data[i]);
        });

        Canvas.Line((x, width) => Color.Orange, (x, width) => {
            int i = linear(x, width, data.Length);
            return(SigQ.f(Shapes.Harris(i, data.Length)
                          * data[i]) - 0.5);
        });

        double duration
            = Math.Round(samples / (double)mic.Hz, 4);

        Canvas.TopLeft  = $"{samples} @ {mic.Hz}Hz = {duration}s";
        Canvas.TopRight = $"{phase:N3}s";
    }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public override void SaveAsJpeg(Surface2D surface, Stream stream)
        {
            Contract.Require(surface, nameof(surface));
            Contract.Require(stream, nameof(stream));

            Save(surface, stream, Bitmap.CompressFormat.Jpeg);
        }
Exemplo n.º 4
0
        public OpenGLCursor(UltravioletContext uv, Surface2D surface, Int32 hx, Int32 hy)
            : base(uv)
        {
            Contract.Require(surface, nameof(surface));

            uv.ValidateResource(surface);

            if (AreCursorsSupported(uv))
            {
                this.cursor   = SDL.CreateColorCursor(((OpenGLSurface2D)surface).Native, hx, hy);
                this.Width    = surface.Width;
                this.Height   = surface.Height;
                this.HotspotX = hx;
                this.HotspotY = hy;

                if (this.cursor == null)
                {
                    this.Width    = 0;
                    this.Height   = 0;
                    this.HotspotX = 0;
                    this.HotspotY = 0;
                }
            }
            else
            {
                this.cursor = null;
                this.Width  = 0;
                this.Height = 0;
            }
        }
Exemplo n.º 5
0
        private static void CreateThePixel(UltravioletContext uv)
        {
            var surface = Surface2D.Create(1, 1, SurfaceOptions.Default);

            surface.SetData(new Color[] { Color.White });
            pixel = Texture2D.CreateTexture(surface.Pixels, 1, 1, surface.BytesPerPixel, TextureOptions.Default);
        }
        /// <summary>
        /// Processes a single file which has all of the layers of the surface within it.
        /// </summary>
        private Surface3D ProcessSingleFile(ContentManager manager, IContentProcessorMetadata metadata, PlatformNativeSurface input)
        {
            var mdat        = metadata.As <SDL2Surface3DProcessorMetadata>();
            var srgbEncoded = mdat.SrgbEncoded ?? manager.Ultraviolet.Properties.SrgbDefaultForSurface3D;

            // Layers must be square. Validate our dimensions.
            var layerHeight = input.Height;
            var layerWidth  = layerHeight;
            var layerCount  = input.Width / layerWidth;

            if (input.Width % layerWidth != 0)
            {
                throw new InvalidDataException(SDL2Strings.SurfaceMustHaveSquareLayers);
            }

            // Create surfaces for each of our layers.
            using (var mainSurface = Surface2D.Create(input))
            {
                mainSurface.SrgbEncoded = srgbEncoded;

                var resultOpts = srgbEncoded ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor;
                var result     = new SDL2Surface3D(manager.Ultraviolet, layerWidth, layerHeight, layerCount, mainSurface.BytesPerPixel, resultOpts);
                for (int i = 0; i < layerCount; i++)
                {
                    var layerSurface = mainSurface.CreateSurface(new Rectangle(i * layerWidth, 0, layerWidth, layerHeight));
                    result.SetLayer(i, layerSurface, true);
                }
                return(result);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes the font texture atlas for the current ImGui context.
        /// </summary>
        private void InitFontTextureAtlas()
        {
            unsafe
            {
                var io = ImGui.GetIO();

                io.Fonts.GetTexDataAsRGBA32(out var textureData,
                                            out var textureWidth, out var textureHeight, out var textureBytesPerPixel);

                var srgb = Ultraviolet.GetGraphics().Capabilities.SrgbEncodingEnabled;

                var surfaceOptions = srgb ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor;
                var surface        = Surface2D.Create(textureWidth, textureHeight, surfaceOptions);
                surface.SetRawData((IntPtr)textureData, 0, 0, textureWidth * textureHeight);
                surface.Flip(SurfaceFlipDirection.Vertical);

                var textureOptions = TextureOptions.ImmutableStorage | (srgb ? TextureOptions.SrgbColor : TextureOptions.LinearColor);
                var texture        = Texture2D.CreateTexture(textureWidth, textureHeight, textureOptions);
                texture.SetData(surface);

                fontAtlasID = Textures.Register(texture);

                io.Fonts.SetTexID(new IntPtr(fontAtlasID));
                io.Fonts.ClearTexData();
            }
        }
        /// <inheritdoc/>
        public override Texture3D CreateTexture(Boolean unprocessed)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.Ensure(IsComplete, SDL2Strings.SurfaceIsNotComplete);

            EnsureAllLayersMatchSrgbEncoding();

            var copysurfs = new Surface2D[Depth];
            var surfsdata = new IntPtr[Depth];

            try
            {
                var flipdir = unprocessed ? SurfaceFlipDirection.None :
                              (Ultraviolet.GetGraphics().Capabilities.FlippedTextures ? SurfaceFlipDirection.Vertical : SurfaceFlipDirection.None);

                for (int i = 0; i < copysurfs.Length; i++)
                {
                    copysurfs[i] = layers[i].CreateSurface();
                    copysurfs[i].FlipAndProcessAlpha(flipdir, false, Color.Magenta);
                    surfsdata[i] = (IntPtr)((SDL2Surface2D)copysurfs[i]).NativePtr->pixels;
                }

                var options = TextureOptions.ImmutableStorage | (SrgbEncoded ? TextureOptions.SrgbColor : TextureOptions.LinearColor);
                return(Texture3D.CreateTexture(surfsdata, Width, Height, BytesPerPixel, options));
            }
            finally
            {
                foreach (var copysurf in copysurfs)
                {
                    copysurf?.Dispose();
                }
            }
        }
Exemplo n.º 9
0
        /// <inheritdoc/>
        public override void SaveAsPng(Surface2D surface, Stream stream)
        {
            Contract.Require(surface, nameof(surface));
            Contract.Require(stream, nameof(stream));

            Save(surface, stream, ImageFormat.Png);
        }
Exemplo n.º 10
0
        /// <inheritdoc/>
        public override void SetLayer(Int32 layer, Surface2D surface, Boolean transferOwnership = false)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.EnsureRange(layer >= 0, nameof(layer));

            if (surface != null)
            {
                if (surface.Width != Width)
                {
                    throw new ArgumentException(UltravioletStrings.IncompatibleSurfaceLayer);
                }
                if (surface.Height != Height)
                {
                    throw new ArgumentException(UltravioletStrings.IncompatibleSurfaceLayer);
                }
                if (surface.BytesPerPixel != BytesPerPixel)
                {
                    throw new ArgumentException(UltravioletStrings.IncompatibleSurfaceLayer);
                }
            }

            this.layers[layer]         = surface;
            this.layerOwnership[layer] = transferOwnership;
            this.isComplete            = !this.layers.Contains(null);
        }
Exemplo n.º 11
0
        /// <inheritdoc/>
        public override void SaveAsJpeg(Surface2D surface, Stream stream)
        {
            Contract.Require(surface, "surface");
            Contract.Require(stream, "stream");

            Save(surface, stream, ImageFormat.Jpeg);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a new instance of the <see cref="Cursor"/> class.
        /// </summary>
        /// <param name="surface">The <see cref="Surface2D"/> that contains the cursor image.</param>
        /// <param name="hx">The x-coordinate of the cursor's hotspot.</param>
        /// <param name="hy">The y-coordinate of the cursor's hotspot.</param>
        /// <returns>The instance of <see cref="Cursor"/> that was created.</returns>
        public static Cursor Create(Surface2D surface, Int32 hx, Int32 hy)
        {
            Contract.Require(surface, nameof(surface));

            var uv = UltravioletContext.DemandCurrent();

            return(uv.GetFactoryMethod <CursorFactory>()(uv, surface, hx, hy));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Saves the specified surface as an image with the specified format.
        /// </summary>
        /// <param name="surface">The surface to save.</param>
        /// <param name="stream">The stream to which to save the surface data.</param>
        /// <param name="format">The format with which to save the image.</param>
        private void Save(Surface2D surface, Stream stream, ImageFormat format)
        {
            var data = new Color[surface.Width * surface.Height];

            surface.GetData(data);

            Save(data, surface.Width, surface.Height, stream, format);
        }
Exemplo n.º 14
0
        void initSurface()
        {
            max = new Vector3(path.BoundingBox.Max.X + diameter, path.BoundingBox.Max.Y + diameter, path.BoundingBox.Max.Z);
            min = new Vector3(path.BoundingBox.Min.X - diameter, path.BoundingBox.Min.Y - diameter, path.BoundingBox.Min.Z);


            surface = Surface2DBuilder <AbmachPoint> .Build(new BoundingBox(min, max), meshSize);
        }
Exemplo n.º 15
0
 protected override void OnInitialized()
 {
     UsePlatformSpecificFileSource();
     _frameBuffer     = Texture2D.CreateTexture(_width * _scale, _height * _scale);
     _canvas          = Surface2D.Create(_width * _scale, _height * _scale);
     this.spriteBatch = SpriteBatch.Create();
     base.OnInitialized();
 }
Exemplo n.º 16
0
        public void init()
        {
            min      = new Vector3(-1, -1, 0);
            max      = new Vector3(1, 1, 0);
            meshSize = .005;

            surface = Surface2DBuilder <AbmachPoint> .Build(new BoundingBox(min, max), meshSize);
        }
Exemplo n.º 17
0
        /// <inheritdoc/>
        public override void SetData(Surface2D surface)
        {
            if (willNotBeSampled)
            {
                throw new NotSupportedException(OpenGLStrings.RenderBufferWillNotBeSampled);
            }

            texture.SetData(surface);
        }
Exemplo n.º 18
0
        /// <inheritdoc/>
        public override void Blit(Surface2D dst, Rectangle dstRect)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.Require(dst, nameof(dst));

            Ultraviolet.ValidateResource(dst);

            BlitInternal(this, new Rectangle(0, 0, Width, Height), (SDL2Surface2D)dst, dstRect);
        }
Exemplo n.º 19
0
        /// <inheritdoc/>
        public override void Blit(Surface2D dst, Point2 position, SurfaceFlipDirection direction)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.Require(dst, nameof(dst));

            Ultraviolet.ValidateResource(dst);

            BlitInternal(this, (SDL2Surface2D)dst, position, direction);
        }
Exemplo n.º 20
0
        /// <inheritdoc/>
        public override void Blit(Rectangle srcRect, Surface2D dst, Rectangle dstRect)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.Require(dst, nameof(dst));

            Ultraviolet.ValidateResource(dst);

            BlitInternal(this, srcRect, (SDL2Surface2D)dst, dstRect);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Imports a new surface 2D into the content system
        /// </summary>
        public static bool Import(Stream surfaceStream,
                                  string setAssetName,
                                  string setPackageName,
                                  string originalInputFile,
                                  out Surface2D importedAsset)
        {
            if (originalInputFile == null)
            {
                throw new ArgumentNullException(nameof(originalInputFile));
            }

            importedAsset = null;

            // Create asset and package names
            string assetName   = setAssetName;
            string packageName = setPackageName;

            Package packageToSaveIn = null;

            assetName = Path.ChangeExtension(assetName, ".surface2d");

            if (AlkaronCoreGame.Core.PackageManager.DoesPackageExist(packageName))
            {
                packageToSaveIn = AlkaronCoreGame.Core.PackageManager.LoadPackage(packageName, false);
            }
            else
            {
                packageToSaveIn = AlkaronCoreGame.Core.PackageManager.CreatePackage(packageName,
                                                                                    Path.Combine(AlkaronCoreGame.Core.ContentDirectory, packageName));
            }

            if (packageToSaveIn == null)
            {
                AlkaronCoreGame.Core.Log("Unable to create or find the package for this asset");
                return(false);
            }

            try
            {
                // Import existing file and convert it to the new format
                Texture2D newTex = Texture2D.FromStream(AlkaronCoreGame.Core.GraphicsDevice, surfaceStream);

                Surface2D surface2D = new Surface2D(newTex);
                surface2D.OriginalFilename = originalInputFile;
                surface2D.Name             = assetName;

                packageToSaveIn.StoreAsset(surface2D);
            }
            catch (Exception ex)
            {
                AlkaronCoreGame.Core.Log("Failed to import Surface2D: " + ex.ToString());
                return(false);
            }

            return(true);
        }
        /// <inheritdoc/>
        public override void SaveAsJpeg(Surface2D surface, Stream stream)
        {
            Contract.Require(surface, nameof(surface));
            Contract.Require(stream, nameof(stream));

            var data = new Color[surface.Width * surface.Height];

            surface.GetData(data);

            Save(data, surface.Width, surface.Height, stream, img => img.AsJPEG());
        }
Exemplo n.º 23
0
        /// <inheritdoc/>
        public override void SaveAsJpeg(Surface2D surface, Stream stream)
        {
            Contract.Require(surface, "surface");
            Contract.Require(stream, "stream");

            var data = new Color[surface.Width * surface.Height];

            surface.GetData(data);

            Save(data, surface.Width, surface.Height, stream, asPng: false);
        }
Exemplo n.º 24
0
        /// <inheritdoc/>
        public override void SetData(Surface2D surface)
        {
            Contract.Require(surface, nameof(surface));
            Contract.EnsureNotDisposed(this, Disposed);

            if (surface.Width != Width || surface.Height != Height)
            {
                throw new ArgumentException(UltravioletStrings.BufferIsWrongSize);
            }

            SetRawDataInternal(0, null, surface.Pixels, 0, Width * Height * surface.BytesPerPixel);
        }
Exemplo n.º 25
0
        private static PlotModel Surf2DModel(Surface2D surf)
        {
            var plotModel1 = new PlotModel
            {
                PlotType         = PlotType.Cartesian,
                Title            = surf.Title,
                Subtitle         = surf.Subtitle,
                SubtitleFontSize = 10,
                TitleFont        = "Tahoma",
                TitleFontSize    = 12,
                DefaultFont      = "Tahoma",
                IsLegendVisible  = false
            };

            var linearColorAxis1 = new LinearColorAxis
            {
                Title              = surf.ZAxisTitle,
                Unit               = surf.ZUnit,
                Position           = AxisPosition.Right,
                AxisDistance       = 5.0,
                InvalidNumberColor = OxyColors.Transparent,
                Palette            = OxyPalettes.Jet(256)
            };

            plotModel1.Axes.Add(linearColorAxis1);

            var linearAxis1 = new LinearAxis
            {
                MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139),
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139),
                MinorGridlineStyle = LineStyle.Solid,
                Position           = AxisPosition.Bottom,
                Title = surf.XAxisTitle,
                Unit  = surf.XUnit
            };

            plotModel1.Axes.Add(linearAxis1);
            var linearAxis2 = new LinearAxis
            {
                MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139),
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139),
                MinorGridlineStyle = LineStyle.Solid,
                Title = surf.YAxisTitle,
                Unit  = surf.YUnit
            };

            plotModel1.Axes.Add(linearAxis2);

            return(plotModel1);
        }
        /// <summary>
        /// Processes a collection of files, each of which represents a separate layer of the surface.
        /// </summary>
        private Surface3D ProcessMultipleFiles(ContentManager manager, IContentProcessorMetadata metadata, PlatformNativeSurface input, String filename)
        {
            var mdat        = metadata.As <SDL2Surface3DProcessorMetadata>();
            var srgbEncoded = mdat.SrgbEncoded ?? manager.Ultraviolet.Properties.SrgbDefaultForSurface3D;

            var layer0     = input.CreateCopy();
            var layers     = new Dictionary <Int32, String>();
            var layerIndex = 1;

            var extension = Path.GetExtension(metadata.AssetFileName);
            var directory = (metadata.AssetPath == null) ? String.Empty : Path.GetDirectoryName(metadata.AssetPath);

            if (!String.IsNullOrEmpty(directory))
            {
                var assetsInDirectory = manager.GetAssetFilePathsInDirectory(directory);
                while (true)
                {
                    var layerAsset = assetsInDirectory.Where(x => String.Equals(Path.GetFileName(x),
                                                                                $"{filename}_{layerIndex}{extension}", StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
                    if (layerAsset == null)
                    {
                        break;
                    }

                    layerAsset = ResolveDependencyAssetPath(metadata, Path.GetFileName(layerAsset));

                    layers[layerIndex] = layerAsset;
                    layerIndex++;
                }
            }

            var surfaceOpts = srgbEncoded ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor;
            var surface     = new SDL2Surface3D(manager.Ultraviolet, layer0.Width, layer0.Height, 1 + layers.Count, layer0.BytesPerPixel, surfaceOpts);

            var surfaceLayer0 = Surface2D.Create(layer0);

            surfaceLayer0.SrgbEncoded = srgbEncoded;
            surface.SetLayer(0, surfaceLayer0, true);

            for (int i = 0; i < layers.Count; i++)
            {
                var layerAsset = layers[1 + i];
                metadata.AddAssetDependency(layerAsset);

                var layerSurface = manager.Load <Surface2D>(layerAsset, metadata.AssetDensity, false, metadata.IsLoadedFromSolution);
                layerSurface.SrgbEncoded = srgbEncoded;
                surface.SetLayer(1 + i, layerSurface, true);
            }

            return(surface);
        }
        /// <inheritdoc/>
        public override void SetData(Surface2D surface)
        {
            Contract.Require(surface, nameof(surface));
            Contract.EnsureNotDisposed(this, Disposed);

            if (surface.Width != Width || surface.Height != Height)
            {
                throw new ArgumentException(UltravioletStrings.BufferIsWrongSize);
            }

            var nativesurf = ((SDL2.Graphics.SDL2Surface2D)surface).NativePtr;

            SetRawDataInternal(0, null, (IntPtr)nativesurf->pixels, 0, Width * Height * nativesurf->format->BytesPerPixel);
        }
Exemplo n.º 28
0
        /// <inheritdoc/>
        public override Surface2D LoadIcon()
        {
            var bundle = NSBundle.MainBundle;

            if (bundle == null)
            {
                return(null);
            }

            var icon = default(NSImage);

            try
            {
                try
                {
                    if (String.Equals(Path.GetExtension(bundle.BundlePath), ".app", StringComparison.OrdinalIgnoreCase))
                    {
                        icon = NSWorkspace.SharedWorkspace.IconForFile(bundle.BundlePath);
                        if (icon == null)
                        {
                            throw new InvalidOperationException();
                        }
                    }
                    else
                    {
                        using (var stream = typeof(UltravioletContext).Assembly.GetManifestResourceStream("TwistedLogik.Ultraviolet.uv.ico"))
                        {
                            icon = NSImage.FromStream(stream);
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                    return(null);
                }

                using (var source = new OSXSurfaceSource(icon))
                {
                    return(Surface2D.Create(source));
                }
            }
            finally
            {
                if (icon != null)
                {
                    icon.Dispose();
                }
            }
        }
        /// <inheritdoc/>
        public override Texture2D Process(ContentManager manager, IContentProcessorMetadata metadata, PlatformNativeSurface input)
        {
            var caps        = manager.Ultraviolet.GetGraphics().Capabilities;
            var mdat        = metadata.As <OpenGLTexture2DProcessorMetadata>();
            var srgbEncoded = mdat.SrgbEncoded ?? manager.Ultraviolet.Properties.SrgbDefaultForTexture2D;
            var surfOptions = srgbEncoded ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor;

            using (var surface = Surface2D.Create(input, surfOptions))
            {
                var flipdir = manager.Ultraviolet.GetGraphics().Capabilities.FlippedTextures ? SurfaceFlipDirection.Vertical : SurfaceFlipDirection.None;
                surface.FlipAndProcessAlpha(flipdir, mdat.PremultiplyAlpha, mdat.Opaque ? null : (Color?)Color.Magenta);

                return(surface.CreateTexture(unprocessed: true));
            }
        }
Exemplo n.º 30
0
        public ChartPlot(HeatMapSeries map, Surface2D surf)
        {
            InitializeComponent();
            plotView1.Model = Surf2DModel(surf);
            plotView1.Model.Series.Add(map);

            switch (surf.SurfType)
            {
            case Surface2D.SurfaceType.Pseudosections:
                Text = $"Pseudosections [{surf.Title}]";
                break;

            case Surface2D.SurfaceType.Surface:
                Text = $"2D Surface [{surf.Title}]";
                break;
            }
        }
Exemplo n.º 31
0
        protected override void OnBegin(Canvas.ResolvedContext target, Retention retention)
        {
            Contract.Assert(_ActiveBrush == null);

            _Watch.Reset();
            _Watch.Start();

            _IsBrushInvalid = true;

            _TargetSurface = (Surface2D)target.Surface2D;

            _TargetSurface.AcquireLock();

            _Drawer.Begin(target);

            OnSetBrush(Color.Black);
        }
Exemplo n.º 32
0
        protected override void OnEnd()
        {
            try
            {
                try
                {
                    _Drawer.End();
                }
                finally
                {
                    _TargetSurface.ReleaseLock();

                    _ActiveBrush = null;
                    _TargetSurface = null;
                }
            }
            finally
            {
                _Watch.Stop();

                _FrameDuration.Value += _Watch.Elapsed;
            }
        }