Image living on the graphics card that can be used for drawing
Наследование: SFML.System.ObjectBase
Пример #1
0
        public static void MouseMove(MouseEventArgs e, byte i)
        {
            SFML.Graphics.Texture Texture = Graphics.Tex_Button[List[i].Texture];

            // Somente se necessário
            if (e.Button == MouseButtons.Right)
            {
                return;
            }
            if (!List[i].Geral.Habilitado)
            {
                return;
            }

            // Se o mouse não estiver sobre a ferramenta, então não Run o evento
            if (!Tools.IsOverlapping(new Rectangle(List[i].Geral.Position, Graphics.MySize(Texture))))
            {
                List[i].State = States.Normal;
                return;
            }

            // Se o Button já estiver no State normal, isso não é necessário
            if (List[i].State != States.Normal)
            {
                return;
            }

            // Altera o State do Button
            List[i].State = States.Sobrepor;
            Audio.Som.Reproduce(Audio.Sons.Overlap);
        }
Пример #2
0
        protected void DrawTexturedRect(SFMLTexture tex, Rectangle targetRect, float u1 = 0, float v1 = 0, float u2 = 1, float v2 = 1)
        {
            Rectangle rect = Translate(targetRect);

            u1 *= tex.Size.X;
            v1 *= tex.Size.Y;
            u2 *= tex.Size.X;
            v2 *= tex.Size.Y;

            if (m_RenderState.Texture != tex || m_CacheSize + 4 >= CacheSize)
            {
                FlushCache();

                // enable the new texture
                m_RenderState.Texture = tex;
            }

            int right  = rect.X + rect.Width;
            int bottom = rect.Y + rect.Height;

            m_VertexCache[m_CacheSize++] = new Vertex(new Vector2f(rect.X, rect.Y), new Vector2f(u1, v1));
            m_VertexCache[m_CacheSize++] = new Vertex(new Vector2f(right, rect.Y), new Vector2f(u2, v1));
            m_VertexCache[m_CacheSize++] = new Vertex(new Vector2f(right, bottom), new Vector2f(u2, v2));
            m_VertexCache[m_CacheSize++] = new Vertex(new Vector2f(rect.X, bottom), new Vector2f(u1, v2));
        }
Пример #3
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct a set of render states with all its attributes
 /// </summary>
 /// <param name="blendMode">Blend mode to use</param>
 /// <param name="transform">Transform to use</param>
 /// <param name="texture">Texture to use</param>
 /// <param name="shader">Shader to use</param>
 ////////////////////////////////////////////////////////////
 public RenderStates(BlendMode blendMode, Transform transform, Texture texture, Shader shader)
 {
     BlendMode = blendMode;
     Transform = transform;
     Texture = texture;
     Shader = shader;
 }
Пример #4
0
        public static void SliceAndDice(Vector2f startPoint, Vector2f endPoint, Texture victim, out Texture sliceA,
                                        out Texture sliceB, float repeatsX, float repeatsY)
        {
            //startPoint = new Vector2f(ConvertUnits.ToDisplayUnits(startPoint.X),
            //                          ConvertUnits.ToDisplayUnits(startPoint.Y));
            //endPoint =   new Vector2f(ConvertUnits.ToDisplayUnits(endPoint.X),
            //                          ConvertUnits.ToDisplayUnits(endPoint.Y));

            var input = victim.CopyToImage();

            var outputA = new Image((uint)(input.Size.X * repeatsX), (uint)(input.Size.Y * repeatsY), Color.Transparent);
            var outputB = new Image((uint)(input.Size.X * repeatsX), (uint)(input.Size.Y * repeatsY), Color.Transparent);

            for (uint y = 0; y < input.Size.Y * repeatsY; y++)
            {
                for (uint x = 0; x < input.Size.X * repeatsX; x++)
                {
                    var pos = new Vector2f(x, y);
                    var start = new Vector2(startPoint.X, startPoint.Y);
                    var end = new Vector2(endPoint.X, endPoint.Y);
                    var line = end - start;
                    line.Normalize();
                    if (WhichSideOfLine(startPoint, endPoint, pos))
                        outputA.SetPixel(x, y, input.GetPixel(x % input.Size.X, y % input.Size.Y));
                    else
                        outputB.SetPixel(x, y, input.GetPixel(x % input.Size.X, y % input.Size.Y));
                }
            }

            sliceA = new Texture(outputA);
            sliceB = new Texture(outputB);
        }
Пример #5
0
        /// <summary>
        /// Initializes texture from image file data.
        /// </summary>
        /// <param name="texture">Texture to initialize.</param>
        /// <param name="data">Image file as stream.</param>
        public override void LoadTextureStream(Texture texture, System.IO.Stream data)
        {
            if (null == texture)
            {
                return;
            }

            Debug.Print("LoadTextureStream: {0} {1}", texture.Name, texture.RendererData);

            if (texture.RendererData != null)
            {
                FreeTexture(texture);
            }

            SFMLTexture sfTexture;

            try
            {
                sfTexture        = new SFMLTexture(data);
                sfTexture.Smooth = true;
            }
            catch (LoadingFailedException)
            {
                Debug.Print("LoadTextureStream: failed");
                texture.Failed = true;
                return;
            }

            texture.Width        = (int)sfTexture.Size.X;
            texture.Height       = (int)sfTexture.Size.Y;
            texture.RendererData = sfTexture;
            texture.Failed       = false;
        }
Пример #6
0
        static private void CreateShape(SFML.Graphics.Texture texture, World world)
        {
            // Make collision Geo from bitmap
            // Get pixel data in array​
            byte[] bytes = texture.CopyToImage().Pixels;
            uint[] data  = new uint[texture.Size.X * texture.Size.Y];
            for (int i = 0; i < bytes.Length; i += 4)
            {
                data[i / 4] = BitConverter.ToUInt32(bytes, i);
            }

            Byte myByte = 1;

            List <Vertices> _list = PolygonTools.CreatePolygon(data, (int)texture.Size.X, 0.05f, myByte, true, true);
            Vertices        verts = new Vertices();
            Vector2         scale = ConvertUnits.ToSimUnits(new Vector2(1, 1));

            foreach (Vertices v in _list)
            {
                v.Scale(scale);
                //    v.Translate(ConvertUnits.ToSimUnits(new Vector2(-16, -16)));
                Body body = new Body(world);
                body.SleepingAllowed = false;
                body.UserData        = "wall";
                List <Fixture> fixtures = FixtureFactory.AttachCompoundPolygon(
                    FarseerPhysics.Common.Decomposition.Triangulate.ConvexPartition(SimplifyTools.DouglasPeuckerSimplify(v, 0.05f), TriangulationAlgorithm.Bayazit, false, 0.05f),
                    1, body);
            }
        }
Пример #7
0
 public GResource(string path)
 {
     _path = path;
     _loaded = false;
     _myTexture = null;
     _type = 0;
 }
Пример #8
0
 public GResource(string path, int type)
 {
     _path = path;
     _loaded = false;
     _myTexture = null;
     _type = type;
 }
Пример #9
0
 // Constructor
 public GResource()
 {
     _path = "";
     _loaded = false;
     _myTexture = null;
     _type = 0;
 }
Пример #10
0
 public Explosion(Vector2 position)
 {
     explosionTexture         = new Texture(@"Resources/explosion.png");
     explosionSprite          = new Sprite(explosionTexture, new IntRect(0, 0, spriteSize, spriteSize));
     explosionSprite.Origin   = new SFML.System.Vector2f(spriteSize / 2, spriteSize / 2);
     explosionSprite.Position = new SFML.System.Vector2f(ConvertUnits.ToDisplayUnits(position.X), ConvertUnits.ToDisplayUnits(position.Y));
 }
Пример #11
0
 public void SetImage(string _source, int _imageWidth, int _imageHeight)
 {
     source = _source;
     imageWidth = _imageWidth;
     imageHeight = _imageHeight;
     image = new Texture("./assets/" + source);
 }
Пример #12
0
        protected static bool IsAssetValid(Texture asset)
        {
            if (asset == null || asset.IsDisposed)
                return false;

            return true;
        }
Пример #13
0
        public MainTitleScreen(RenderWindow window)
            : base(window)
        {
            Type = ScreenType.MainTitleScreen;

            base.Init();
               // Gui.AddGameWidget(imb);

            initMenu();

            StraightLineVariableData slvd = new StraightLineVariableData(200F, 100 * 4);
               // slvd.AddKeyData(.25F, 100F);
            slvd.AddKeyData(.5F, 300F);
               // slvd.AddKeyData(.75F, 100F);
            slvd.ComputeData();

            img = new Image(800, 600, new Color(0, 0, 0, 0));
            for (int i = 0; i < slvd.GetCount(); ++i)
            {
               // Log.Cl(slvd.GetData(i));
                img.SetPixel((uint)(100 + i / 4), (uint)slvd.GetData(i), Color.Red);
               // img.SetPixel((uint)(100 + i / 4), (uint)slvd.GetData(i) + 4, Color.Blue);
            }

            tex = new SFML.Graphics.Texture(img);
            spre = new Sprite(tex);

            imb.AddMessage("hoy hoy !");
            imb.OnStopping += new MessageBox.EventHandler(imb_OnStopping);
        }
Пример #14
0
        /// <summary>
        /// Draw the surface directly to the game window.  This will refresh the view,
        /// and Display the surface, as well as clear it if AutoClear is true.
        /// </summary>
        /// <param name="game">The Game to render to.</param>
        public void DrawToWindow(Game game)
        {
            RefreshView();

            Display();

            Drawable drawable = RenderShaders();

            game.Window.Draw(drawable, _states);

            if (_saveNextFrame)
            {
                _saveNextFrame = false;

                var texture = new SFML.Graphics.Texture(game.Window.Size.X, game.Window.Size.Y);
                texture.Update(game.Window);
                var capture = texture.CopyToImage();
                capture.SaveToFile(_saveNameFramePath);
            }

            if (AutoClear)
            {
                Clear(FillColor);
            }
        }
Пример #15
0
        public override void loadContent()
        {
            float logoScale;

            _logoTexture = ResourceManager.getResource<Texture>("logo_1");
            _logoShape = new RectangleShape();
            _logoShape.Texture = _logoTexture;
            _logoShape.Size = new Vector2f(_logoTexture.Size.X, _logoTexture.Size.Y);
            logoScale = Game.window.GetView().Size.X / (float)_logoTexture.Size.X;
            _logoShape.Scale = new Vector2f(logoScale, logoScale);

            _font = ResourceManager.getResource<Font>("immortal_font");
            _options = new List<Text>();
            _options.Add(new Text("New Game", _font, 48));
            _options.Add(new Text("Continue", _font, 48));
            _options.Add(new Text("Options", _font, 48));
            _options.Add(new Text("Exit", _font, 48));

            for (int i = 0; i < _options.Count; i++)
            {
                Text text = _options[i];

                text.Position = new Vector2f(128, i * 48 + _logoShape.Size.Y * _logoShape.Scale.Y + 64);
            }
        }
        public void LoadContent()
        {
            Texture tex = new Texture("Assets/Textures/TitelScreen.png");
            Background = new Sprite(tex);

            Background.Scale = Game.WindowSize / new Vec2f(Background.Texture.Size.X, Background.Texture.Size.Y);
        }
Пример #17
0
 public EmoteBubble(string emote, Actor parent)
 {
     this.emote = emote.ToLower();
     this.parent = parent;
     this.texture = Content.GetTexture("emote_" + emote +".png");
     life = 60 * 4;
 }
Пример #18
0
        public TileMap(int width, int height, Texture texture)
        {
            Width = width;
            Height = height;

            var lastTile = texture == null ? ushort.MaxValue : (ushort)((texture.Size.X / GameOptions.TileSize) * (texture.Size.Y / GameOptions.TileSize) - 1);

            tiles = new Tile[width, height];

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    tiles[x, y].Index = lastTile;
                    tiles[x, y].Solid = false;
                }
            }

            var chunkWidth = (width / GameOptions.TileChunkSize) + 1;
            var chunkHeight = (height / GameOptions.TileChunkSize) + 1;

            chunks = new Chunk[chunkWidth, chunkHeight];

            for (var y = 0; y < chunkHeight; y++)
            {
                for (var x = 0; x < chunkWidth; x++)
                {
                    chunks[x, y] = new Chunk(x, y, tiles, texture);
                }
            }
        }
Пример #19
0
 static HWSurfaceInstance()
 {
     _atlas = new RenderTexture(_aw, _ah);
     _atlastex = _atlas.Texture;
     _batch = new SpriteBatch(_atlas);
     _batch.SetBlendMode(BlendMode.None);
 }
Пример #20
0
        // [omeg] added, pixelData are in RGBA format
        public override void LoadTextureRaw(Texture texture, byte[] pixelData)
        {
            if (null == texture)
            {
                return;
            }

            Debug.Print("LoadTextureRaw: {0}", texture.RendererData);

            if (texture.RendererData != null)
            {
                FreeTexture(texture);
            }

            SFMLTexture sfTexture;

            try
            {
                var img = new Image((uint)texture.Width, (uint)texture.Height, pixelData); // SFML Image
                sfTexture        = new SFMLTexture(img);
                sfTexture.Smooth = true;
                img.Dispose();
            }
            catch (LoadingFailedException)
            {
                Debug.Print("LoadTextureRaw: failed");
                texture.Failed = true;
                return;
            }

            texture.RendererData = sfTexture;
            texture.Failed       = false;
        }
Пример #21
0
        public static void load_batch_textures(string folder)
        {
            //Debug.Log("Loading textures from folder " + folder);
            Debug.StartLogGroup();

                DirectoryInfo dir = new DirectoryInfo(folder);

                if (dir.Exists)
                {

                    FileInfo[] bmpfiles = dir.GetFiles("*.bmp", System.IO.SearchOption.AllDirectories);
                    FileInfo[] pngfiles = dir.GetFiles("*.png", System.IO.SearchOption.AllDirectories);
                    FileInfo[] files = new FileInfo[bmpfiles.Length + pngfiles.Length];

                    bmpfiles.CopyTo(files, 0);
                    pngfiles.CopyTo(files, bmpfiles.Length);

                    if (files.Length > 0) FileWatch.add_folder(folder);

                    for (int f = 0; f < files.Length; f++)
                    {
                        Texture tex = new Texture();
                        tex.assign_path(files[f].FullName);
                        textures.Add(tex.identifier, tex);
                    }
                }

            Debug.EndLogGroup();
        }
Пример #22
0
 public bool ReloadTexture(string path)
 {
     _texture = new Texture(path);
     _path = path;
     _loaded = (_texture == null) ? false : true;
     return _loaded;
 }
Пример #23
0
 public Sprite(string name, int type)
 {
     _path = name;
     _type = type;
     _texture = new Texture(name);
     _loaded = (_texture == null) ? false : true;
 }
Пример #24
0
 internal CircleWave(double gameTime, Vector2f midPos, Texture text, int x)
     : base(midPos, gameTime, 5.0f, text)
 {
     start = gameTime;
     ratio = 1.0 * text.Size.Y / text.Size.X;
     var = x;
 }
Пример #25
0
        public Player(Vector2f _position, String _file, GameWorld _world)
        {
            create(_position, _file, 1);
            mWorld      = _world;

            mEntityType = EntityType.Player;
            mHealth     = 100;
            mSegment    = 10;

            mInvicible = false;
            mOnce      = false;
            mTimer     = new Stopwatch();

            mShoot     = new Stopwatch();
            mShoot.Start();

            for (int i = 0; i < 11; i++)
            {
                Texture tex = new Texture("resources/health/health" + i + ".png");
                mHealthBar[i] = new Sprite(tex);

                Vector2f pos = new Vector2f();
                pos.X -= 17f;
                pos.Y -= 10f;
                mHealthBar[i].Position = mPosition - pos;
            }
        }
Пример #26
0
        public Menu()
            : base()
        {
            hoverCursor = Content.GetTexture("cursorHover.png");
            defaultCursor = Content.GetTexture("cursorPointer.png");
            currentCursor = defaultCursor;
            char1 = new Animation(Content.GetTexture("idle.png"), 4, 0, 0, true);
            char2 = new Animation(Content.GetTexture("char2_idle.png"), 4, 0, 0, true);
            shader = new RenderStates(new Shader(null, "Content/bgPrlx.frag"));

            rectConnect = new RectangleShape()
            {
                Size = new Vector2f(150, 30),
                Position = new Vector2f(-25, 70)
            };
            rectIP = new RectangleShape()
            {
                Size = new Vector2f(150, 20),
                Position = new Vector2f(-25, 40)
            };
            rectUsername = new RectangleShape()
            {
                Size = new Vector2f(150, 20),
                Position = new Vector2f(-25, 10)
            };

            MainGame.window.TextEntered += TextEnteredEvent;
        }
Пример #27
0
        public override void loadContent()
        {
            _bigButtonTexture = new Texture("resources/ui/inter_level_screen/button.png");

            addScreenComponent(
                new BigLabeledButtonComponent(
                    this,
                    _bigButtonTexture,
                    new Vector2f(32, 32),
                    "Skills",
                    new Color(10, 180, 10, 255),
                    () => { openSkillsMenu(); }));

            addScreenComponent(
                new BigLabeledButtonComponent(
                    this,
                    _bigButtonTexture,
                    new Vector2f(32, 164),
                    "Group",
                    new Color(10, 10, 180, 255),
                    () => { Console.WriteLine("open group menu"); }));

            addScreenComponent(
                new BigLabeledButtonComponent(
                    this,
                    _bigButtonTexture,
                    new Vector2f(32, 296),
                    "Continue",
                    new Color(180, 10, 10, 255),
                    () => { continueGame(); }));
        }
Пример #28
0
        public override void LoadTexture(Texture texture)
        {
            if (texture == null)
            {
                return;
            }

            if (texture.RendererData != null)
            {
                FreeTexture(texture);
            }

            try
            {
                var sfTexture = new SFMLTexture(texture.Name)
                {
                    Smooth = true
                };
                texture.Width        = (int)sfTexture.Size.X;
                texture.Height       = (int)sfTexture.Size.Y;
                texture.RendererData = sfTexture;
                texture.Failed       = false;
            }
            catch (LoadingFailedException)
            {
                Debug.Print("LoadTexture: failed");
                texture.Failed = true;
            }
        }
Пример #29
0
 /// <summary>
 /// Creates a new CluwneSprite with a specified portion of the Texture
 /// </summary>
 /// <param name="texture"> Texture to draw </param>
 /// <param name="rectangle"> What part of the Texture to use </param>
 public CluwneSprite(string key, Texture texture, IntRect rectangle)
     : base(texture,rectangle)
 {
     Key = key;
     Position = new Vector2(X, Y);
     Size = new Vector2(Width, Height);
 }
Пример #30
0
        protected void DrawTexturedRect(SFMLTexture tex, Rectangle rect, float u1 = 0, float v1 = 0, float u2 = 1, float v2 = 1)
        {
            rect = Translate(rect);

            u1 *= tex.Size.X;
            v1 *= tex.Size.Y;
            u2 *= tex.Size.X;
            v2 *= tex.Size.Y;

            if (_renderState.Texture != tex || _cacheSize + 4 >= CacheSize)
            {
                FlushCache();

                // enable the new texture
                _renderState.Texture = tex;
            }

            var right  = rect.X + rect.Width;
            var bottom = rect.Y + rect.Height;

            _vertices[_cacheSize++] = new Vertex(new Vector2f(rect.X, rect.Y), new Vector2f(u1, v1));
            _vertices[_cacheSize++] = new Vertex(new Vector2f(right, rect.Y), new Vector2f(u2, v1));
            _vertices[_cacheSize++] = new Vertex(new Vector2f(right, bottom), new Vector2f(u2, v2));
            _vertices[_cacheSize++] = new Vertex(new Vector2f(rect.X, bottom), new Vector2f(u1, v2));
        }
Пример #31
0
        public ClassSelectorComponent(Screen screen, Texture upArrowTexture, Texture downArrowTexture, Texture classSelectorTexture, List<Texture> classTextures, Vector2f position)
            : base(screen)
        {
            _position = position;
            _classTextures = classTextures;

            _upArrow = new RectangleShape();
            _upArrow.Position = position + new Vector2f(0f, -42f);
            _upArrow.Origin = new Vector2f(8f, 8f);
            _upArrow.Texture = upArrowTexture;
            _upArrow.Size = new Vector2f(16f, 16f);

            _classSelector = new RectangleShape();
            _classSelector.Position = position;
            _classSelector.Origin = new Vector2f(32f, 32f);
            _classSelector.Texture = classSelectorTexture;
            _classSelector.Size = new Vector2f(64f, 64f);

            _classIcon = new RectangleShape();
            _classIcon.Position = position;
            _classIcon.Origin = new Vector2f(32f, 32f);
            _classIcon.Texture = _classTextures[(int)_selectedClass];
            _classIcon.Size = new Vector2f(64f, 64f);

            _downArrow = new RectangleShape();
            _downArrow.Position = position + new Vector2f(0f, 42f);
            _downArrow.Origin = new Vector2f(8f, 8f);
            _downArrow.Texture = downArrowTexture;
            _downArrow.Size = new Vector2f(16f, 16f);
        }
Пример #32
0
        public ButtonControl(Font font, uint size, Texture button, Texture hover, Texture press)
        {
            left = new RectangleShape();
            middle = new RectangleShape();
            right = new RectangleShape();

            left.Texture = button;
            middle.Texture = button;
            right.Texture = button;

            left.TextureRect = new IntRect(0, 0, (int)button.Size.X / 2 - 1, (int)button.Size.Y);
            middle.TextureRect = new IntRect((int)button.Size.X / 2 - 1, 0, 2, (int)button.Size.Y);
            right.TextureRect = new IntRect((int)button.Size.X / 2 + 1, 0, (int)button.Size.X / 2, (int)button.Size.Y);

            text = new TextControl(font, size) { TextAlignment = Alignment.MiddleCenter, Bold = true };
            text.BackgroundColor = Color.Transparent;

            IsHovered = false;
            IsPressed = false;
            ClickYOffset = 4.0f;

            buttonTexture = button;
            hoverTexture = hover;
            pressedTexture = press;
        }
Пример #33
0
        public Edge()
            : base("edge post-effect")
        {
            // Create the off-screen surface
            mySurface = new RenderTexture(800, 600);
            mySurface.Smooth = true;

            // Load the textures
            myBackgroundTexture = new Texture("resources/sfml.png");
            myBackgroundTexture.Smooth = true;
            myEntityTexture = new Texture("resources/devices.png");
            myEntityTexture.Smooth = true;

            // Initialize the background sprite
            myBackgroundSprite = new Sprite(myBackgroundTexture);
            myBackgroundSprite.Position = new Vector2f(135, 100);

            // Load the moving entities
            myEntities = new Sprite[6];
            for (int i = 0; i < myEntities.Length; ++i)
            {
                myEntities[i] = new Sprite(myEntityTexture, new IntRect(96 * i, 0, 96, 96));
            }

            // Load the shader
            myShader = new Shader(null, "resources/edge.frag");
            myShader.SetParameter("texture", Shader.CurrentTexture);
        }
Пример #34
0
        public static bool CreateShadows()
        {

            Image img = spriteSheet.Texture.CopyToImage();

            for (uint k = 0; k < img.Size.X; k++)
                for (uint j = 0; j < img.Size.Y; j++)
                {
                    Color c = img.GetPixel(k, j);
                    if (c.A == 255)
                    {
                        Color d = new Color();
                        d.A = 40;
                        d.R = d.G = d.B = 0;
                        img.SetPixel(k, j, d);
                    }
                }

            Texture tex = new Texture(img);
            Sprite tempsprite = new Sprite();
            tempsprite.Texture = tex;

            shadowSpriteSheet = new RenderTexture(textureSize, textureSize);
            shadowSpriteSheet.Draw(tempsprite);
            shadowSpriteSheet.Display();

            shadowSprite.Texture = shadowSpriteSheet.Texture;

            img.Dispose();
            tempsprite.Dispose();
            tex.Dispose();

            return true;
        }
Пример #35
0
        public BigLabeledButtonComponent(Screen screen, Texture buttonTexture, Vector2f position, string text, Color buttonColor, Action onClick)
            : base(screen)
        {
            _buttonTexture = buttonTexture;
            _position = position;
            _buttonColor = buttonColor;
            _selectedColor = new Color(
                (byte)Math.Min(255, (int)_buttonColor.R + 50),
                (byte)Math.Min(255, (int)_buttonColor.G + 50),
                (byte)Math.Min(255, (int)_buttonColor.B + 50),
                255);
            _onClick = onClick;
            _font = ResourceManager.getResource<Font>("immortal_font");

            // Initialize button shape
            _buttonShape = new RectangleShape();
            _buttonShape.Texture = _buttonTexture;
            _buttonShape.Position = position;
            _buttonShape.Size = new Vector2f(_buttonShape.Texture.Size.X, _buttonShape.Texture.Size.Y);
            _buttonShape.FillColor = _buttonColor;

            // Initialize text
            _firstLetter = new Text(text.Substring(0, 1), _font, 72);
            _firstLetter.Position = position + new Vector2f(30, 0);
            _firstLetter.Color = Color.White;
            _firstLetterShadow = new Text(_firstLetter.DisplayedString, _font, 72);
            _firstLetterShadow.Position = _firstLetter.Position + new Vector2f(3, 3);
            _firstLetterShadow.Color = Color.Black;
            _word = new Text(text.Substring(1, text.Length - 1), _font, 48);
            _word.Position = _firstLetter.Position + new Vector2f(_firstLetter.GetLocalBounds().Width + 4, 13);
            _word.Color = Color.White;
            _wordShadow = new Text(_word.DisplayedString, _font, 48);
            _wordShadow.Position = _word.Position + new Vector2f(3, 3);
            _wordShadow.Color = Color.Black;
        }
Пример #36
0
 public static Sprite LoadSprite(string fileName, Vector2f scale)
 {
     Image image = new Image(fileName);
     Texture texture = new Texture(image);
     Sprite sprite = new Sprite(texture) { Scale = scale };
     return sprite;
 }
Пример #37
0
        public Editor()
        {
            InitializeComponent();

            _instance = this;

            _changeMade = false;

            _curGame = new Game();

            _newGame = new NewGame();

            _IO = new IO();

            _newMap = new NewMap();

            _globalFont = new SFML.Graphics.Font("Georgia.ttf");

            _block = new Texture("block.png");

            _projectDirectory = new ProjectDirectory();

            _mapViewFormList = new List<MapViewerForm>();

            _actorManager = new ActorManagerForm();

            _gameRunner = new GameRunner(_curGame);

            _viewSwitch = new ViewSwitch();

            _viewVariable = new ViewVariable();

            DisableTool();
        }
Пример #38
0
 public static void PrecacheTexture(string what)
 {
     if (textures.ContainsKey(what)) { return; }
     string thePath = Path.Combine(RootDirectory, what);
     Texture theTex = new Texture(thePath);
     textures.Add(what, theTex);
 }
Пример #39
0
        /// <summary>
        /// initializes a new Enemy
        /// </summary>
        /// <param name="direction">the direction to the texture as a string</param>
        /// <param name="sPosition">start position</param>
        public Enemy(string direction, Vector2f sPosition)
        {
            textur = new Texture(direction);
            sprite = new Sprite(textur);

            sprite.Position = sPosition;
        }
Пример #40
0
        public void InitDeviceResources()
        {
            FPS_Clock = Stopwatch.StartNew();

            //RenderingFont = new SFML.Graphics.Font(System.IO.Path.Combine(Methods.ProgramPaths.FontsDirectory, "sonic2system.ttf"));
            //RenderingFontBold = new SFML.Graphics.Font(System.IO.Path.Combine(Methods.ProgramPaths.FontsDirectory, "sonic2system.ttf"));

            txb = new Bitmap(1, 1);
            using (Graphics g = Graphics.FromImage(txb))
                g.Clear(Color.White);

            tcircleb = new Bitmap(9, 9);
            using (Graphics g = Graphics.FromImage(tcircleb))
                g.FillEllipse(Brushes.White, new Rectangle(0, 0, 9, 9));

            tecircleb = new Bitmap(14, 14);
            using (Graphics g = Graphics.FromImage(tecircleb))
                g.DrawEllipse(new Pen(Brushes.White), new Rectangle(0, 0, 13, 13));

            hcursorb = new Bitmap(32, 32);
            using (Graphics g = Graphics.FromImage(hcursorb))
                Cursors.NoMoveHoriz.Draw(g, new Rectangle(0, 0, 32, 32));
            MakeGray(hcursorb);

            vcursorb = new Bitmap(32, 32);
            using (Graphics g = Graphics.FromImage(vcursorb))
                Cursors.NoMoveVert.Draw(g, new Rectangle(0, 0, 32, 32));
            MakeGray(vcursorb);

            hvcursorb = new Bitmap(32, 32);
            using (Graphics g = Graphics.FromImage(hvcursorb))
                Cursors.NoMove2D.Draw(g, new Rectangle(0, 0, 32, 32));
            MakeGray(hvcursorb);

            tx       = FromBitmap(txb);
            tcircle  = FromBitmap(tcircleb);
            tecircle = FromBitmap(tecircleb);
            hcursor  = FromBitmap(hcursorb);
            vcursor  = FromBitmap(vcursorb);
            hvcursor = FromBitmap(hvcursorb);

            void MakeGray(Bitmap image)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    for (int y = 0; y < image.Height; y++)
                    {
                        if (image.GetPixel(x, y).Name == "ffffffff")
                        {
                            image.SetPixel(x, y, Color.Transparent);
                        }
                        else if (image.GetPixel(x, y).Name == "ff000000")
                        {
                            image.SetPixel(x, y, Color.Gray);
                        }
                    }
                }
            }
        }
Пример #41
0
 public TexelsAtlas(SFML.Graphics.Texture atlas, ushort offsetX, ushort offsetY, ushort width, ushort height)
 {
     this.Texture = atlas;
     this.OffsetX = offsetX;
     this.OffsetY = offsetY;
     this.Height  = height;
     this.Width   = width;
 }
Пример #42
0
        /// <summary>
        /// Creates a SadConsole font using an existing image.
        /// </summary>
        /// <param name="fontImage">The image for the font.</param>
        /// <param name="glyphWidth">The width of each glyph.</param>
        /// <param name="glyphHeight">The height of each glyph.</param>
        /// <param name="totalColumns">Glyph columns in the font texture, defaults to 16.</param>
        /// <param name="glyphPadding">Pixels between each glyph, defaults to 0.</param>
        public FontMaster(Texture2D fontImage, int glyphWidth, int glyphHeight, int totalColumns = 16, int glyphPadding = 0)
        {
            Image        = fontImage;
            GlyphWidth   = glyphWidth;
            GlyphHeight  = glyphHeight;
            Columns      = totalColumns;
            GlyphPadding = glyphPadding;

            ConfigureRects();
        }
Пример #43
0
        public PixelCollider(Texture texture, params int[] tags)
        {
            this.texture = texture.SFMLTexture;
            collideImage = this.texture.CopyToImage();

            Width  = this.texture.Size.X;
            Height = this.texture.Size.Y;

            AddTag(tags);
        }
Пример #44
0
        /// <summary>
        /// After the font has been loaded, (with the <see cref="FilePath"/>, <see cref="GlyphHeight"/>, and <see cref="GlyphWidth"/> fields filled out) this method will create the actual texture.
        /// </summary>
        public void Generate()
        {
#if SFML
            Image = new Texture2D(FilePath);
#elif MONOGAME
            using (System.IO.Stream fontStream = System.IO.File.OpenRead(FilePath))
                Image = Texture2D.FromStream(Engine.Device, fontStream);
#endif
            ConfigureRects();
        }
Пример #45
0
        /// <summary>
        /// Creates a pixel collider.
        /// </summary>
        /// <param name="source">The source image to create the collider from.</param>
        /// <param name="tags">The tags to register the collider with.</param>
        public PixelCollider(string source, params int[] tags)
        {
            texture      = Textures.Load(source);
            collideImage = texture.CopyToImage();

            Width  = texture.Size.X;
            Height = texture.Size.Y;

            AddTag(tags);
        }
Пример #46
0
        public Background(string texture, Vector2D position, Vector2D push)
        {
            this.push     = push;
            this.pushRate = 0.15f;

            this.position = position;

            this.texture = GeneralTextureManager.GetTexture(texture);
            this.sprite  = new Sprite(this.texture);
        }
Пример #47
0
        public override void DrawTexturedRect(Texture t, Rectangle targetRect, float u1 = 0, float v1 = 0, float u2 = 1, float v2 = 1)
        {
            SFMLTexture tex = t.RendererData as SFMLTexture;

            if (null == tex)
            {
                DrawMissingImage(targetRect);
                return;
            }

            DrawTexturedRect(tex, targetRect, u1, v1, u2, v2);
        }
Пример #48
0
        public SfmlRenderer(RenderWindow window, CommonResource resource, bool highResolution)
        {
            sfmlWindow = window;
            palette    = resource.Palette;

            colors = InitColors(palette);

            sfmlWindowWidth  = (int)window.Size.X;
            sfmlWindowHeight = (int)window.Size.Y;

            if (highResolution)
            {
                screen            = new DrawScreen(resource.Wad, 640, 400);
                sfmlTextureWidth  = 512;
                sfmlTextureHeight = 1024;
            }
            else
            {
                screen            = new DrawScreen(resource.Wad, 320, 200);
                sfmlTextureWidth  = 256;
                sfmlTextureHeight = 512;
            }

            sfmlTextureData = new byte[4 * screen.Width * screen.Height];

            try
            {
                sfmlTexture = new SFML.Graphics.Texture((uint)sfmlTextureWidth, (uint)sfmlTextureHeight);
                sfmlSprite  = new SFML.Graphics.Sprite(sfmlTexture);
            }
            catch (Exception e)
            {
                Dispose();
                ExceptionDispatchInfo.Capture(e).Throw();
            }

            sfmlSprite.Position = new Vector2f(0, 0);
            sfmlSprite.Rotation = 90;
            var scaleX = (float)sfmlWindowWidth / screen.Width;
            var scaleY = (float)sfmlWindowHeight / screen.Height;

            sfmlSprite.Scale = new Vector2f(scaleY, -scaleX);

            sfmlStates = new RenderStates(BlendMode.None);

            menu            = new MenuRenderer(resource.Wad, screen);
            threeD          = new ThreeDRenderer(resource, screen);
            statusBar       = new StatusBarRenderer(resource.Wad, screen);
            intermission    = new IntermissionRenderer(resource.Wad, screen);
            openingSequence = new OpeningSequenceRenderer(resource.Wad, screen, this);
            autoMap         = new AutoMapRenderer(screen);
        }
Пример #49
0
        public override void FreeTexture(Texture texture)
        {
            SFMLTexture tex = texture.RendererData as SFMLTexture;

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

            Debug.Print("FreeTexture: {0}", texture.Name);

            texture.RendererData = null;
        }
Пример #50
0
        public override System.Drawing.Color PixelColor(Texture texture, uint x, uint y, System.Drawing.Color defaultColor)
        {
            SFMLTexture tex = texture.RendererData as SFMLTexture;

            if (tex == null)
            {
                return(defaultColor);
            }
            var   img   = tex.CopyToImage();
            Color pixel = img.GetPixel(x, y);

            return(System.Drawing.Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B));
        }
Пример #51
0
        public void Dispose()
        {
            if (sfmlSprite != null)
            {
                sfmlSprite.Dispose();
                sfmlSprite = null;
            }

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

            Console.WriteLine("SFML resources are disposed.");
        }
Пример #52
0
 public Window()
 {
     Texture           = new SFML.Graphics.Texture("Data/Sprites/Window.png");
     Program.OnUpdate += () => { if (Active)
                                 {
                                     Update();
                                 }
     };
     Program.OnDraw += () => { if (Active)
                               {
                                   Draw();
                               }
     };
     Program.Window.MouseButtonPressed  += Window_MouseButtonPressed;
     Program.Window.MouseButtonReleased += Window_MouseButtonReleased;
 }
Пример #53
0
        public void Dispose()
        {
            Console.WriteLine("Shutdown renderer.");

            if (this.sfmlSprite != null)
            {
                this.sfmlSprite.Dispose();
                this.sfmlSprite = null;
            }

            if (this.sfmlTexture != null)
            {
                this.sfmlTexture.Dispose();
                this.sfmlTexture = null;
            }
        }
Пример #54
0
 public Animation(string fileName, IntRect spriteSize, uint numberOfSprites, float singleImageTime = 0.3f)
 {
     _spriteList      = new List <SmartSprite>();
     _order           = new List <int>();
     SingleImageTime  = singleImageTime;
     _currentTime     = singleImageTime;
     _currentPosition = 0;
     SFML.Graphics.Texture text = JamUtilities.TextureManager.GetTextureFromFileName(fileName);
     for (int i = 0; i < numberOfSprites; i++)
     {
         //System.Console.WriteLine(i);
         IntRect     rect = new IntRect(i * spriteSize.Width, 0, spriteSize.Width, spriteSize.Height);
         SmartSprite spr  = new SmartSprite(text, rect);
         _spriteList.Add(spr);
         _order.Add(i);
     }
 }
Пример #55
0
        public void initLevel(ref World world, ref EnemyContainer eContrainer, ref Player player, ref CollectableContainer collectables)
        {
            world        = new World(new Vector2(0, 0));
            eContrainer  = new EnemyContainer(world);
            collectables = new CollectableContainer(world);
            Level level = getNextLevel();

            TileSpriteList = new List <Drawable>();
            CreateShape(new SFML.Graphics.Texture(level.AlphaTexture), world);
            SFML.Graphics.Texture tilemap = new SFML.Graphics.Texture(level.TilemapImage);
            test = new TiledSharp.TmxMap(level.TMX);
            var myTileset = test.Tilesets[level.Tilesetname];
            Map newMap    = new Map(test.Width, test.Height, test.TileWidth);

            this.Map = newMap;
            parseTileLayer(tilemap);
            parseObjectLayer(world, eContrainer, ref player, collectables);
        }
Пример #56
0
        public static System.Drawing.Bitmap ConvertTextureToBitmap(SFML.Graphics.Texture texture)
        {
            var image  = texture.CopyToImage();
            var size   = image.Size;
            var bitmap = new System.Drawing.Bitmap((int)size.X, (int)size.Y,
                                                   System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            for (var x = 0; x < size.X; ++x)
            {
                for (var y = 0; y < size.Y; ++y)
                {
                    var p = image.GetPixel((uint)x, (uint)y);
                    bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(p.A, p.R, p.G, p.B));
                }
            }

            return(bitmap);
        }
Пример #57
0
        public static void MouseUp(MouseEventArgs e, byte Index)
        {
            SFML.Graphics.Texture Texture = Graphics.Tex_Button[List[Index].Texture];

            // Somente se necessário
            if (!List[Index].Geral.Habilitado)
            {
                return;
            }
            if (!Tools.IsOverlapping(new Rectangle(List[Index].Geral.Position, Graphics.MySize(Texture))))
            {
                return;
            }

            // Altera o State do Button
            Audio.Som.Reproduce(Audio.Sons.Click);
            List[Index].State = States.Sobrepor;

            // Executa o evento
            Run(List[Index].Geral.Name);
        }
Пример #58
0
        public static void MouseDown(MouseEventArgs e, byte Index)
        {
            SFML.Graphics.Texture Texture = Graphics.Tex_Button[List[Index].Texture];

            // Somente se necessário
            if (e.Button == MouseButtons.Right)
            {
                return;
            }
            if (!List[Index].Geral.Habilitado)
            {
                return;
            }

            // Se o mouse não estiver sobre a ferramenta, então não Run o evento
            if (!Tools.IsOverlapping(new Rectangle(List[Index].Geral.Position, Graphics.MySize(Texture))))
            {
                return;
            }

            // Altera o State do Button
            List[Index].State = States.Clique;
        }
Пример #59
0
        public SfmlRenderer(Config config, RenderWindow window, CommonResource resource)
        {
            try
            {
                Console.Write("Initialize renderer: ");

                this.config = config;

                config.video_gamescreensize  = Math.Clamp(config.video_gamescreensize, 0, this.MaxWindowSize);
                config.video_gammacorrection = Math.Clamp(config.video_gammacorrection, 0, this.MaxGammaCorrectionLevel);

                this.sfmlWindow = window;
                this.palette    = resource.Palette;

                this.sfmlWindowWidth  = (int)window.Size.X;
                this.sfmlWindowHeight = (int)window.Size.Y;

                if (config.video_highresolution)
                {
                    this.screen            = new DrawScreen(640, 400);
                    this.sfmlTextureWidth  = 512;
                    this.sfmlTextureHeight = 1024;
                }
                else
                {
                    this.screen            = new DrawScreen(320, 200);
                    this.sfmlTextureWidth  = 256;
                    this.sfmlTextureHeight = 512;
                }

                this.sfmlTextureData = new byte[4 * this.screen.Width * this.screen.Height];

                this.sfmlTexture = new Texture((uint)this.sfmlTextureWidth, (uint)this.sfmlTextureHeight);
                this.sfmlSprite  = new Sprite(this.sfmlTexture);

                this.sfmlSprite.Position = new Vector2f(0, 0);
                this.sfmlSprite.Rotation = 90;
                var scaleX = (float)this.sfmlWindowWidth / this.screen.Width;
                var scaleY = (float)this.sfmlWindowHeight / this.screen.Height;
                this.sfmlSprite.Scale = new Vector2f(scaleY, -scaleX);

                this.sfmlStates = new RenderStates(BlendMode.None);

                this.menu            = new MenuRenderer(this.screen);
                this.threeD          = new ThreeDRenderer(resource, this.screen, config.video_gamescreensize);
                this.statusBar       = new StatusBarRenderer(this.screen);
                this.intermission    = new IntermissionRenderer(this.screen);
                this.openingSequence = new OpeningSequenceRenderer(this.screen, this);
                this.autoMap         = new AutoMapRenderer(this.screen);
                this.finale          = new FinaleRenderer(resource, this.screen);

                this.pause = Patch.FromWad("M_PAUSE");

                var scale = this.screen.Width / 320;
                this.wipeBandWidth = 2 * scale;
                this.wipeBandCount = this.screen.Width / this.wipeBandWidth + 1;
                this.wipeHeight    = this.screen.Height / scale;
                this.wipeBuffer    = new byte[this.screen.Data.Length];

                this.palette.ResetColors(SfmlRenderer.gammaCorrectionParameters[config.video_gammacorrection]);

                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                this.Dispose();
                ExceptionDispatchInfo.Throw(e);
            }
        }
Пример #60
0
 public TexelsTexture(SFML.Graphics.Texture texture) => this.Texture = texture;