Esempio n. 1
0
        public void Dispose()
        {
            if (!disposed)
            {
                disposed = true;

                if (scaledChannelSurface != null)
                {
                    scaledChannelSurface.Dispose();
                    scaledChannelSurface = null;
                }

                if (ditheredChannelSurface != null)
                {
                    ditheredChannelSurface.Dispose();
                    ditheredChannelSurface = null;
                }

                if (scaledSelectionMask != null)
                {
                    scaledSelectionMask.Dispose();
                    scaledSelectionMask = null;
                }
            }
        }
Esempio n. 2
0
            public static EffectsManager Load(string file, SurfaceBase surface)
            {
                EffectsManagerSerialized data    = Serializer.Load <EffectsManagerSerialized>(file, Settings.SerializationIsCompressed);
                EffectsManager           manager = new EffectsManager(surface);

                foreach (var effect in data.Effects.Keys)
                {
                    int[] effectCellIndexes = data.Effects[effect];

                    List <Cell> cells = new List <Cell>(effectCellIndexes.Length);

                    foreach (var index in effectCellIndexes)
                    {
                        cells.Add(surface.Cells[index]);
                    }

                    var effectData = new CellEffectData(effect)
                    {
                        Cells = cells
                    };

                    manager._effects.Add(effect, effectData);

                    foreach (var cell in cells)
                    {
                        manager._effectCells.Add(cell, effectData);
                    }
                }

                return(manager);
            }
Esempio n. 3
0
        /// <inheritdoc />
        protected override void OnParentChanged(ScreenObject oldParent, ScreenObject newParent)
        {
            _surfaceParent = newParent as SurfaceBase;
            IsPaused       = _surfaceParent == null;

            if (_surfaceParent != null)
            {
                foreach (var zone in Zones)
                {
                    if (zone.Parent != _surfaceParent)
                    {
                        zone.Parent = _surfaceParent;
                    }
                }

                foreach (var spot in Hotspots)
                {
                    if (spot.Parent != _surfaceParent)
                    {
                        spot.Parent = _surfaceParent;
                    }
                }

                foreach (var entity in Entities)
                {
                    if (entity.Parent != _surfaceParent)
                    {
                        entity.Parent = _surfaceParent;
                    }
                }

                Sync();
            }
        }
Esempio n. 4
0
        private unsafe short CreateDitheredChannelPortSurface(SurfaceBase source)
        {
            int width  = source.Width;
            int height = source.Height;

            try
            {
                switch (imageMode)
                {
                case ImageModes.Gray16:

                    ditheredChannelImageMode = ImageModes.GrayScale;
                    ditheredChannelSurface   = SurfaceFactory.CreateFromImageMode(width, height, ditheredChannelImageMode);

                    for (int y = 0; y < height; y++)
                    {
                        ushort *src = (ushort *)source.GetRowAddressUnchecked(y);
                        byte *  dst = ditheredChannelSurface.GetRowAddressUnchecked(y);
                        for (int x = 0; x < width; x++)
                        {
                            *dst = (byte)((*src * 10) / 1285);

                            src++;
                            dst++;
                        }
                    }
                    break;

                case ImageModes.RGB48:

                    ditheredChannelImageMode = ImageModes.RGB;
                    ditheredChannelSurface   = SurfaceFactory.CreateFromImageMode(width, height, ditheredChannelImageMode);

                    for (int y = 0; y < height; y++)
                    {
                        ushort *src = (ushort *)source.GetRowAddressUnchecked(y);
                        byte *  dst = ditheredChannelSurface.GetRowAddressUnchecked(y);
                        for (int x = 0; x < width; x++)
                        {
                            dst[0] = (byte)((src[0] * 10) / 1285);
                            dst[1] = (byte)((src[1] * 10) / 1285);
                            dst[2] = (byte)((src[2] * 10) / 1285);
                            dst[3] = (byte)((src[3] * 10) / 1285);

                            src += 4;
                            dst += 4;
                        }
                    }

                    break;
                }
            }
            catch (OutOfMemoryException)
            {
                return(PSError.memFullErr);
            }

            return(PSError.noErr);
        }
Esempio n. 5
0
 private void init()
 {
     initConfig();
     this.terrain        = initTerrain();
     this.surface        = initSurface();
     this.surfaceRiver   = new SurfaceRiverOasis(config);
     this.surfaceGeneric = new SurfaceGeneric(config, this.surface.getTopPixel(), this.surface.getFillerPixel());
 }
Esempio n. 6
0
        public override void Draw(ControlsConsole console, SurfaceBase hostSurface)
        {
            hostSurface.DefaultForeground = FillStyle.Foreground;
            hostSurface.DefaultBackground = FillStyle.Background;
            hostSurface.Fill(hostSurface.DefaultForeground, hostSurface.DefaultBackground, FillStyle.Glyph, null);

            if (!(console is Window window))
            {
                return;
            }

            hostSurface.DrawBox(new Rectangle(0, 0, hostSurface.Width, hostSurface.Height), new Cell(BorderStyle.Foreground,
                                                                                                     BorderStyle.Background, 0), null, BorderLineStyle);

            // Draw title
            var adjustedText  = "";
            var adjustedWidth = hostSurface.Width - 2;

            TitleAreaLength = 0;
            TitleAreaX      = 0;

            if (!string.IsNullOrEmpty(window.Title))
            {
                if (window.Title.Length > adjustedWidth)
                {
                    adjustedText = window.Title.Substring(0, window.Title.Length - (window.Title.Length - adjustedWidth));
                }
                else
                {
                    adjustedText = window.Title;
                }
            }

            if (!string.IsNullOrEmpty(adjustedText))
            {
                TitleAreaLength = adjustedText.Length;

                if (window.TitleAlignment == HorizontalAlignment.Left)
                {
                    TitleAreaX = 1;
                }

                else if (window.TitleAlignment == HorizontalAlignment.Center)
                {
                    TitleAreaX = ((adjustedWidth - adjustedText.Length) / 2) + 1;
                }

                else
                {
                    TitleAreaX = hostSurface.Width - 1 - adjustedText.Length;
                }

                hostSurface.Print(TitleAreaX, TitleAreaY, adjustedText, TitleStyle);
            }
        }
Esempio n. 7
0
        ParseCommandBase CustomParseCommand(string command, string parameters, ColoredGlyph[] glyphString,
                                            SurfaceBase surface, ParseCommandStacks commandStacks)
        {
            switch (command)
            {
            case "t":
                return(new ParseCommandRetext(parameters));

            default:
                return(null);;
            }
        }
Esempio n. 8
0
        public DrawCallSurface(SurfaceBase surface, Point position, bool pixelPositioned)
        {
            if (pixelPositioned)
            {
                Position = position.ToVector2();
            }
            else
            {
                Position = surface.Font.GetWorldPosition(position).ToVector2();
            }

            Surface = surface;
        }
Esempio n. 9
0
        public void Draw(SurfaceBase area, ref DrawEventArgs args)
        {
            brush = Brushes.White;
            path  = new Path(FillMode.Winding);
            path.AddRectangle(new PointD(0.0, 0.0), args.AreaSize);
            path.End();
            args.Context.Fill(path, brush);
            path.Dispose();

            SizeD graphSize = GraphSize(args.AreaSize);

            brush = Brushes.Black;
            path  = new Path(FillMode.Winding);
            path.NewFigure(xOffLeft, yOffTop);
            path.LineTo(xOffLeft, yOffTop + graphSize.Height);
            path.LineTo(xOffLeft + graphSize.Width, yOffTop + graphSize.Height);
            path.End();
            args.Context.Stroke(path, brush, strokeOptions);
            path.Dispose();

            Matrix matrix = Matrix.SetIdentity();

            matrix.Translate(xOffLeft, yOffTop);
            args.Context.Transform(matrix);

            brush = (SolidBrush)colorPicker.Color;
            double a = brush.Color.A;

            brush = new SolidBrush(new Color(brush.Color.R, brush.Color.G, brush.Color.B, brush.Color.A / 2.0));
            path  = ConstructGraph(graphSize, true);
            args.Context.Fill(path, brush);
            path.Dispose();

            path  = ConstructGraph(graphSize, false);
            brush = new SolidBrush(new Color(brush.Color.R, brush.Color.G, brush.Color.B, a));
            args.Context.Stroke(path, brush, strokeOptions);
            path.Dispose();

            if (curPt != -1)
            {
                PointD[] pts = PointLocations(graphSize);

                path = new Path(FillMode.Winding);
                path.NewFigureWithArc(pts[curPt], 5, 0, 6.23, false);
                path.End();
                args.Context.Fill(path, brush);

                path.Dispose();
            }
        }
Esempio n. 10
0
        public DesertHillsBiome()
        {
            Id          = 17;
            Name        = "Desert Hills";
            Temperature = 2.0f;
            Downfall    = 0.0f;
            MinHeight   = 0.2f;
            MaxHeight   = 0.7f;

            SurfaceBlock = 12; //Sand
            SoilBlock    = 24; //Sandstone

            Terrain = new DesertHillsTerrain(10f, 80f, 68f, 200f);
            Surface = new SurfaceBase(Config, new Sand(), new Sandstone());
        }
Esempio n. 11
0
        public static Matrix GetPositionTransform(this SurfaceBase surface, Point position, bool usePixelPositioning = false)
        {
            Point worldLocation;

            if (usePixelPositioning)
            {
                worldLocation = position;
            }
            else
            {
                worldLocation = new Point(position.X * surface.Font.Size.X, position.Y * surface.Font.Size.Y);
            }

            return(Matrix.CreateTranslation(worldLocation.X, worldLocation.Y, 0f));
        }
Esempio n. 12
0
        public DesertBiome()
        {
            Id           = 2;
            Name         = "Desert";
            Temperature  = 2.0f;
            Downfall     = 0.0f;
            MinHeight    = 0.1f;
            MaxHeight    = 0.2f;
            SurfaceBlock = 12;
            SoilBlock    = 24;


            Terrain = new DesertTerrain();
            Surface = new SurfaceBase(Config, new Sand(), new Sandstone());
        }
Esempio n. 13
0
        public BeachBiome()
        {
            Id          = 16;
            Name        = "Beach";
            Temperature = 0.8f;
            Downfall    = 0.4f;
            MinHeight   = 0f;
            MaxHeight   = 0.1f;
            Terrain     = new BeachTerrain();
            Surface     = new SurfaceBase(Config, new Sand(), new Sandstone())
            {
            };

            Type = BiomeType.Beach | BiomeType.Land;
        }
Esempio n. 14
0
        public void Draw(SurfaceBase surface, ref DrawEventArgs e)
        {
            brush = Brushes.White;
            path  = new Path(FillMode.Winding);
            path.AddRectangle(0.0, 0.0, e.SurfaceSize.Width, e.SurfaceSize.Height);
            path.End();
            e.Context.Fill(path, brush);
            path.Dispose();

            GraphSize(e.SurfaceSize.Width, e.SurfaceSize.Height, out double graphWidth, out double graphHeight);

            brush = Brushes.Black;
            path  = new Path(FillMode.Winding);
            path.NewFigure(xoffLeft, yoffTop);
            path.LineTo(xoffLeft, yoffTop + graphHeight);
            path.LineTo(xoffLeft + graphWidth, yoffTop + graphHeight);
            path.End();
            e.Context.Stroke(path, brush, strokeOptions);
            path.Dispose();

            Matrix matrix = Matrix.SetIdentity();

            matrix.Translate(xoffLeft, yoffTop);
            e.Context.Transform(matrix);

            brush = (SolidBrush)colorPicker.Color;
            double a = brush.Color.A;

            brush.Color = new Color(brush.Color.R, brush.Color.G, brush.Color.B, brush.Color.A / 2);
            path        = ConstructGraph(graphWidth, graphHeight, true);
            e.Context.Fill(path, brush);
            path.Dispose();

            path        = ConstructGraph(graphWidth, graphHeight, false);
            brush.Color = new Color(brush.Color.R, brush.Color.G, brush.Color.B, a);
            e.Context.Stroke(path, brush, strokeOptions);
            path.Dispose();

            if (_currentPoint != -1)
            {
                PointLocations(graphWidth, graphHeight, out double[] xs, out double[] ys);
                path = new Path(FillMode.Winding);
                path.NewFigureWithArc(xs[_currentPoint], ys[_currentPoint], 5, 0, 6.23, false);
                path.End();
                e.Context.Fill(path, brush);
                path.Dispose();
            }
        }
Esempio n. 15
0
        public ColdBeachBiome()
        {
            Id          = 26;
            Name        = "Cold Beach";
            Temperature = 0.05f;
            Downfall    = 0.3f;
            MinHeight   = 0f;
            MaxHeight   = 0.025f;

            Terrain = new BeachTerrain();
            Surface = new SurfaceBase(Config, new Sand(), new Sandstone())
            {
            };

            Type = BiomeType.Beach | BiomeType.Cold | BiomeType.Land;
        }
Esempio n. 16
0
        public StoneBeachBiome()
        {
            Id          = 25;
            Name        = "Stone Beach";
            Temperature = 0.2f;
            Downfall    = 0.3f;
            MinHeight   = 0.1f;
            MaxHeight   = 0.8f;

            Terrain = new BeachTerrain();
            Surface = new SurfaceBase(Config, new Gravel(), new Sandstone())
            {
            };

            Type = BiomeType.Beach | BiomeType.Cold | BiomeType.Land;
        }
Esempio n. 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChannelPortsSuite"/> class.
        /// </summary>
        /// <param name="filterImageProvider">The filter image provider.</param>
        /// <param name="imageMode">The image mode.</param>
        /// <exception cref="ArgumentNullException"><paramref name="filterImageProvider"/> is null.</exception>
        public unsafe ChannelPortsSuite(IFilterImageProvider filterImageProvider, ImageModes imageMode)
        {
            if (filterImageProvider == null)
            {
                throw new ArgumentNullException(nameof(filterImageProvider));
            }

            this.filterImageProvider = filterImageProvider;
            this.imageMode           = imageMode;
            readPixelsProc           = new ReadPixelsProc(ReadPixelsProc);
            writeBasePixelsProc      = new WriteBasePixelsProc(WriteBasePixels);
            readPortForWritePortProc = new ReadPortForWritePortProc(ReadPortForWritePort);
            scaledChannelSurface     = null;
            ditheredChannelSurface   = null;
            scaledSelectionMask      = null;
            disposed = false;
        }
Esempio n. 18
0
        public MesaPlateauBiome()
        {
            Id          = 39;
            Name        = "Mesa Plateau";
            Temperature = 2.0f;
            Downfall    = 0.0f;
            MinHeight   = 1.5f;
            MaxHeight   = 0.025f;

            //   SurfaceBlock = 12; //Surface = Red Sand
            //  SurfaceMetadata = 1;

            //  SoilBlock = 179; //Soil = Red Sandstone
            Terrain = new MesaPlateauTerrain(67);
            Surface = new SurfaceBase(Config, new Sand()
            {
                SandType = "red"
            }, new RedSandstone());
        }
        public override void RenderCells(SurfaceBase surfacePreCast, bool force = false)
        {
            PaletteSurface surface = (PaletteSurface)surfacePreCast;

            if (surface.IsDirty || force)
            {
                if (surface.Tint.A != 255)
                {
                    CellPalette cell;
                    Color       background;
                    Color       foreground;


                    if (surface.DefaultBackground.A != 0)
                    {
                        Global.SpriteBatch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphRects[surface.Font.SolidGlyphIndex], surface.DefaultBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.2f);
                    }

                    for (int i = 0; i < surface.RenderCells.Length; i++)
                    {
                        cell = (CellPalette)surface.RenderCells[i];

                        if (cell.IsVisible)
                        {
                            background = palette[cell.BackgroundIndex];
                            foreground = palette[cell.ForegroundIndex];

                            if (background != Color.Transparent && background != surface.DefaultBackground)
                            {
                                Global.SpriteBatch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphRects[surface.Font.SolidGlyphIndex], background, 0f, Vector2.Zero, SpriteEffects.None, 0.3f);
                            }

                            if (foreground != Color.Transparent)
                            {
                                Global.SpriteBatch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphRects[cell.Glyph], foreground, 0f, Vector2.Zero, cell.Mirror, 0.4f);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 20
0
        public void MouseEvent(SurfaceBase surface, ref MouseEventArgs e)
        {
            GraphSize(e.SurfaceSize.Width, e.SurfaceSize.Height, out double graphWidth, out double graphHeight);
            PointLocations(graphWidth, graphHeight, out double[] xs, out double[] ys);

            int i;

            for (i = 0; i < 10; i++)
            {
                if (InPoint(e.Point.X, e.Point.Y, xs[i], ys[i]))
                {
                    break;
                }
            }
            if (i == 10)
            {
                i = -1;
            }
            _currentPoint = i;
            surface.QueueRedrawAll();
        }
Esempio n. 21
0
            public static void Save(EffectsManager effectsManager, SurfaceBase surface, string file)
            {
                EffectsManagerSerialized data = new EffectsManagerSerialized();

                data.Effects = new Dictionary <ICellEffect, int[]>(effectsManager._effects.Count);
                List <Cell> currentCells = new List <Cell>(surface.Cells);

                foreach (var effectData in effectsManager._effects.Values)
                {
                    List <int> effectCellPositions = new List <int>(effectData.Cells.Count);

                    foreach (var cell in effectData.Cells)
                    {
                        effectCellPositions.Add(currentCells.IndexOf(cell));
                    }

                    data.Effects.Add(effectData.Effect, effectCellPositions.ToArray());
                }

                SadConsole.Serializer.Save(data, file, Settings.SerializationIsCompressed);
            }
Esempio n. 22
0
        static void Main(string[] args)
        {
            var exit = "";

            Console.Title           = "rOBOt";
            Console.OutputEncoding  = System.Text.Encoding.Unicode;
            Console.ForegroundColor = ConsoleColor.Green;
            DrawGame           paintSurface      = new DrawGame();
            SurfaceBase        surfaceDimensions = new SurfaceBase();
            Questionaries      questionary       = new Questionaries();
            List <Coordinates> dangerCoordinates = new List <Coordinates>();

            Console.WriteLine(Tittle.MartianRobot);
            Console.ResetColor();
            Thread.Sleep(50);

            surfaceDimensions = questionary.DefineSurface();

            while (exit != "E")
            {
                paintSurface.Paint(surfaceDimensions, dangerCoordinates, null, null, null);

                Console.SetCursorPosition(5, 24);
                Console.WriteLine("Enter to continue. For Exit type `E`:");
                exit = Console.ReadLine().ToString().ToUpper();
                Console.Clear();
            }

            Console.WriteLine($"Danger coordinates:");
            Console.WriteLine($"--------");
            foreach (var dangerUbication in dangerCoordinates)
            {
                Console.WriteLine($"X: {dangerUbication.XPosition}, Y: {dangerUbication.YPosition} ");
            }

            Thread.Sleep(6000);
            CloseProgram.Close();
        }
Esempio n. 23
0
        public void MouseEvent(SurfaceBase area, ref MouseEventArgs args)
        {
            SizeD graphSize = GraphSize(args.AreaSize);

            PointD[] pts = PointLocations(graphSize);

            int i;

            for (i = 0; i < 10; i++)
            {
                if (InPoint(args.Point, pts[i]))
                {
                    break;
                }
            }

            if (i == 10)
            {
                i = -1;
            }

            curPt = i;
            area.QueueRedrawAll();
        }
Esempio n. 24
0
        private static unsafe void FillChannelData(int channel, PixelMemoryDesc *destiniation, SurfaceBase source, VRect srcRect, ImageModes mode)
        {
            byte *dstPtr = (byte *)destiniation->data.ToPointer();
            int   stride = destiniation->rowBits / 8;
            int   bpp    = destiniation->colBits / 8;
            int   offset = destiniation->bitOffset / 8;

            switch (mode)
            {
            case ImageModes.GrayScale:

                for (int y = srcRect.top; y < srcRect.bottom; y++)
                {
                    byte *src = source.GetPointAddressUnchecked(srcRect.left, y);
                    byte *dst = dstPtr + (y * stride) + offset;
                    for (int x = srcRect.left; x < srcRect.right; x++)
                    {
                        *dst = *src;

                        src++;
                        dst += bpp;
                    }
                }

                break;

            case ImageModes.RGB:

                for (int y = srcRect.top; y < srcRect.bottom; y++)
                {
                    byte *src = source.GetPointAddressUnchecked(srcRect.left, y);
                    byte *dst = dstPtr + (y * stride) + offset;
                    for (int x = srcRect.left; x < srcRect.right; x++)
                    {
                        switch (channel)
                        {
                        case PSConstants.ChannelPorts.Red:
                            *dst = src[2];
                            break;

                        case PSConstants.ChannelPorts.Green:
                            *dst = src[1];
                            break;

                        case PSConstants.ChannelPorts.Blue:
                            *dst = src[0];
                            break;

                        case PSConstants.ChannelPorts.Alpha:
                            *dst = src[3];
                            break;
                        }
                        src += 4;
                        dst += bpp;
                    }
                }

                break;

            case ImageModes.CMYK:

                for (int y = srcRect.top; y < srcRect.bottom; y++)
                {
                    byte *src = source.GetPointAddressUnchecked(srcRect.left, y);
                    byte *dst = dstPtr + (y * stride) + offset;
                    for (int x = srcRect.left; x < srcRect.right; x++)
                    {
                        switch (channel)
                        {
                        case PSConstants.ChannelPorts.Cyan:
                            *dst = src[0];
                            break;

                        case PSConstants.ChannelPorts.Magenta:
                            *dst = src[1];
                            break;

                        case PSConstants.ChannelPorts.Yellow:
                            *dst = src[2];
                            break;

                        case PSConstants.ChannelPorts.Black:
                            *dst = src[3];
                            break;
                        }
                        src += 4;
                        dst += bpp;
                    }
                }

                break;

            case ImageModes.Gray16:

                for (int y = srcRect.top; y < srcRect.bottom; y++)
                {
                    ushort *src = (ushort *)source.GetPointAddressUnchecked(srcRect.left, y);
                    ushort *dst = (ushort *)(dstPtr + (y * stride) + offset);
                    for (int x = srcRect.left; x < srcRect.right; x++)
                    {
                        *dst = *src;

                        src++;
                        dst += bpp;
                    }
                }

                break;

            case ImageModes.RGB48:

                for (int y = srcRect.top; y < srcRect.bottom; y++)
                {
                    ushort *src = (ushort *)source.GetPointAddressUnchecked(srcRect.left, y);
                    ushort *dst = (ushort *)(dstPtr + (y * stride) + offset);
                    for (int x = srcRect.left; x < srcRect.right; x++)
                    {
                        switch (channel)
                        {
                        case PSConstants.ChannelPorts.Red:
                            *dst = src[2];
                            break;

                        case PSConstants.ChannelPorts.Green:
                            *dst = src[1];
                            break;

                        case PSConstants.ChannelPorts.Blue:
                            *dst = src[0];
                            break;

                        case PSConstants.ChannelPorts.Alpha:
                            *dst = src[3];
                            break;
                        }
                        src += 4;
                        dst += bpp;
                    }
                }

                break;
            }
        }
 public override void Render(SurfaceBase surface, bool force = false)
 {
     base.Render(surface, true);
 }
Esempio n. 26
0
 public bool KeyEvent(SurfaceBase surface, ref KeyEventArgs args) => false;
Esempio n. 27
0
 public void DragBroken(SurfaceBase surface)
 {
 }
Esempio n. 28
0
 public void MouseCrossed(SurfaceBase surface, MouseCrossedEventArgs args)
 {
 }
Esempio n. 29
0
        public ParseCommandBlink(string parameters, ColoredGlyph[] glyphString, ParseCommandStacks commandStack, SurfaceBase surfaceEditor)
        {
            string[] parametersArray = parameters.Split(':');

            if (parametersArray.Length == 2)
            {
                Speed = double.Parse(parametersArray[1], CultureInfo.InvariantCulture);
            }

            if (parametersArray.Length >= 1 && parametersArray[0] != "")
            {
                Counter = int.Parse(parametersArray[0], CultureInfo.InvariantCulture);
            }
            else
            {
                Counter = -1;
            }

            // Try sync with surface editor
            if (surfaceEditor != null)
            {
                var effects = surfaceEditor.Effects.GetEffects();
                if (effects != null)
                {
                    var existingBlinks = new List <SadConsole.Effects.ICellEffect>(effects);

                    foreach (var item in existingBlinks)
                    {
                        if (item is CustomBlinkEffect)
                        {
                            if (Speed == ((CustomBlinkEffect)item).BlinkSpeed)
                            {
                                BlinkEffect = (CustomBlinkEffect)item;
                            }

                            break;
                        }
                    }
                }
            }

            // Failed, look within this parse for existing
            if (BlinkEffect == null)
            {
                foreach (var item in glyphString)
                {
                    if (item.Effect != null && item.Effect is CustomBlinkEffect)
                    {
                        if (Speed == ((CustomBlinkEffect)item.Effect).BlinkSpeed)
                        {
                            BlinkEffect = (CustomBlinkEffect)item.Effect;
                        }
                    }
                }
            }


            if (BlinkEffect == null)
            {
                BlinkEffect = new CustomBlinkEffect()
                {
                    BlinkSpeed = Speed
                }
            }
            ;

            commandStack.TurnOnEffects = true;

            // No exceptions, set the type
            CommandType = CommandTypes.Effect;
        }
Esempio n. 30
0
        private unsafe short ReadPixelsProc(IntPtr port, PSScaling *scaling, VRect *writeRect, PixelMemoryDesc *destination, VRect *wroteRect)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.ChannelPorts, string.Format("port: {0}, rect: {1}", port.ToString(), DebugUtils.PointerToString(writeRect)));
#endif

            if (scaling == null || writeRect == null || destination == null)
            {
                return(PSError.paramErr);
            }

            if (destination->depth != 8 && destination->depth != 16)
            {
                return(PSError.errUnsupportedDepth);
            }

            // The offsets must be aligned to a System.Byte.
            if ((destination->bitOffset % 8) != 0)
            {
                return(PSError.errUnsupportedBitOffset);
            }

            if ((destination->colBits % 8) != 0)
            {
                return(PSError.errUnsupportedColBits);
            }

            if ((destination->rowBits % 8) != 0)
            {
                return(PSError.errUnsupportedRowBits);
            }

            int channel = port.ToInt32();

            if (channel < PSConstants.ChannelPorts.Gray || channel > PSConstants.ChannelPorts.SelectionMask)
            {
                return(PSError.errUnknownPort);
            }

            VRect srcRect = scaling->sourceRect;
            VRect dstRect = scaling->destinationRect;

            int         srcWidth    = srcRect.right - srcRect.left;
            int         srcHeight   = srcRect.bottom - srcRect.top;
            int         dstWidth    = dstRect.right - dstRect.left;
            int         dstHeight   = dstRect.bottom - dstRect.top;
            bool        isSelection = channel == PSConstants.ChannelPorts.SelectionMask;
            SurfaceBase source      = filterImageProvider.Source;

            if ((source.BitsPerChannel == 8 || isSelection) && destination->depth == 16)
            {
                return(PSError.errUnsupportedDepthConversion); // converting 8-bit image data to 16-bit is not supported.
            }

            if (isSelection)
            {
                if (srcWidth == dstWidth && srcHeight == dstHeight)
                {
                    FillSelectionMask(destination, filterImageProvider.Mask, srcRect);
                }
                else if (dstWidth < srcWidth || dstHeight < srcHeight) // scale down
                {
                    if ((scaledSelectionMask == null) || scaledSelectionMask.Width != dstWidth || scaledSelectionMask.Height != dstHeight)
                    {
                        if (scaledSelectionMask != null)
                        {
                            scaledSelectionMask.Dispose();
                            scaledSelectionMask = null;
                        }

                        try
                        {
                            scaledSelectionMask = new SurfaceGray8(dstWidth, dstHeight);
                            scaledSelectionMask.FitSurface(filterImageProvider.Mask);
                        }
                        catch (OutOfMemoryException)
                        {
                            return(PSError.memFullErr);
                        }
                    }

                    FillSelectionMask(destination, scaledSelectionMask, dstRect);
                }
                else if (dstWidth > srcWidth || dstHeight > srcHeight) // scale up
                {
                    if ((scaledSelectionMask == null) || scaledSelectionMask.Width != dstWidth || scaledSelectionMask.Height != dstHeight)
                    {
                        if (scaledSelectionMask != null)
                        {
                            scaledSelectionMask.Dispose();
                            scaledSelectionMask = null;
                        }

                        try
                        {
                            scaledSelectionMask = new SurfaceGray8(dstWidth, dstHeight);
                            scaledSelectionMask.FitSurface(filterImageProvider.Mask);
                        }
                        catch (OutOfMemoryException)
                        {
                            return(PSError.memFullErr);
                        }
                    }

                    FillSelectionMask(destination, scaledSelectionMask, dstRect);
                }
            }
            else
            {
                ImageModes mode = imageMode;

                if (source.BitsPerChannel == 16 && destination->depth == 8)
                {
                    if (ditheredChannelSurface == null)
                    {
                        short err = CreateDitheredChannelPortSurface(source);
                        if (err != PSError.noErr)
                        {
                            return(err);
                        }
                    }
                    mode = ditheredChannelImageMode;
                }

                if (srcWidth == dstWidth && srcHeight == dstHeight)
                {
                    FillChannelData(channel, destination, ditheredChannelSurface ?? source, srcRect, mode);
                }
                else if (dstWidth < srcWidth || dstHeight < srcHeight) // scale down
                {
                    if ((scaledChannelSurface == null) || scaledChannelSurface.Width != dstWidth || scaledChannelSurface.Height != dstHeight)
                    {
                        if (scaledChannelSurface != null)
                        {
                            scaledChannelSurface.Dispose();
                            scaledChannelSurface = null;
                        }

                        try
                        {
                            scaledChannelSurface = SurfaceFactory.CreateFromImageMode(dstWidth, dstHeight, mode);
                            scaledChannelSurface.FitSurface(ditheredChannelSurface ?? source);
                        }
                        catch (OutOfMemoryException)
                        {
                            return(PSError.memFullErr);
                        }
                    }

                    FillChannelData(channel, destination, scaledChannelSurface, dstRect, mode);
                }
                else if (dstWidth > srcWidth || dstHeight > srcHeight) // scale up
                {
                    if ((scaledChannelSurface == null) || scaledChannelSurface.Width != dstWidth || scaledChannelSurface.Height != dstHeight)
                    {
                        if (scaledChannelSurface != null)
                        {
                            scaledChannelSurface.Dispose();
                            scaledChannelSurface = null;
                        }

                        try
                        {
                            scaledChannelSurface = SurfaceFactory.CreateFromImageMode(dstWidth, dstHeight, mode);
                            scaledChannelSurface.FitSurface(ditheredChannelSurface ?? source);
                        }
                        catch (OutOfMemoryException)
                        {
                            return(PSError.memFullErr);
                        }
                    }

                    FillChannelData(channel, destination, scaledChannelSurface, dstRect, mode);
                }
            }

            if (wroteRect != null)
            {
                *wroteRect = dstRect;
            }

            return(PSError.noErr);
        }