static FontExtensions()
        {
            string fontsDirPath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
            string fontPath     = fontsDirPath + @"\" + @"arial.ttf";

            Font = new SFML.Graphics.Font(fontPath);
        }
Пример #2
0
        public Button(string textToShow, SFML.Graphics.Font font, SFML.System.Vector2f position, SFML.Graphics.Texture normal, SFML.Graphics.Texture highlighted, SFML.Graphics.Texture pressed)
        {
            text     = textToShow;
            sfmlText = new SFML.Graphics.Text(text, font);
            sfmlText.OutlineThickness = 1;
            sfmlText.OutlineColor     = SFML.Graphics.Color.Black;
            normalTXT      = normal;
            highlightedTXT = highlighted;
            pressedTXT     = pressed;

            sprite          = new SFML.Graphics.Sprite(normalTXT);
            sprite.Position = position;
        }
Пример #3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // No managed objects to dispose.
                }

                MeasureContainer.Dispose();
                SfmlFont.Dispose();

                _disposed = true;
            }
        }
Пример #4
0
        public void StartLoad()
        {
            if (NativeFont != null)
            {
                Unload();
            }

            LoadState = LoadStates.Loading;

            try {
                NativeFont = new SFML.Graphics.Font(Path);
            } catch (Exception) {
                LoadState = LoadStates.Failed;
            }

            LoadState = LoadStates.Active;
        }
Пример #5
0
        public Font(Font font)
        {
            font.EnsureNotDisposed();

            SfmlFont         = new SfmlFont(font.SfmlFont);
            MeasureContainer = new SfmlText();

            CharacterSize    = font.CharacterSize;
            CharacterSpacing = font.CharacterSpacing;
            LineSpacing      = font.LineSpacing;
            OutlineThickness = font.OutlineThickness;

            Bold          = font.Bold;
            Italic        = font.Italic;
            Underline     = font.Underline;
            Strikethrough = font.Strikethrough;
        }
        public EntitySpawnSelectButton(EntityTemplate entityTemplate, string templateName,
                                       IResourceManager resourceManager)
        {
            _resourceManager = resourceManager;

            var spriteNameParam = entityTemplate.GetBaseSpriteParamaters().FirstOrDefault();
            string SpriteName = "";
            if (spriteNameParam != null)
            {
                SpriteName = spriteNameParam.GetValue<string>();
            }
            string ObjectName = entityTemplate.Name;

            associatedTemplate = entityTemplate;
            associatedTemplateName = templateName;

            objectSprite = _resourceManager.GetSprite(SpriteName);

            font = _resourceManager.GetFont("CALIBRI");
            name = new TextSprite("Label" + SpriteName, "Name", font);
            name.Color = Color.Black;
            name.Text = ObjectName;
        }
Пример #7
0
        public EntitySpawnSelectButton(EntityTemplate entityTemplate, string templateName,
                                       IResourceManager resourceManager)
        {
            _resourceManager = resourceManager;

            var    spriteNameParam = entityTemplate.GetBaseSpriteParamaters().FirstOrDefault();
            string SpriteName      = "";

            if (spriteNameParam != null)
            {
                SpriteName = spriteNameParam.GetValue <string>();
            }
            string ObjectName = entityTemplate.Name;

            associatedTemplate     = entityTemplate;
            associatedTemplateName = templateName;

            objectSprite = _resourceManager.GetSprite(SpriteName);

            font       = _resourceManager.GetFont("CALIBRI");
            name       = new TextSprite("Label" + SpriteName, "Name", font);
            name.Color = Color.Black;
            name.Text  = ObjectName;
        }
Пример #8
0
        static void Main(string[] args)
        {
            int width  = 1920;
            int height = 1080;

            SFML.Graphics.RenderWindow w = new SFML.Graphics.RenderWindow(
                new SFML.Window.VideoMode((uint)width, (uint)height),
                System.Reflection.Assembly.GetExecutingAssembly().FullName,
                SFML.Window.Styles.Default,
                new SFML.Window.ContextSettings()
            {
                AntialiasingLevel = 8
            });
            w.Resized             += new EventHandler <SFML.Window.SizeEventArgs>(w_Resized);
            w.Closed              += new EventHandler(w_Closed);
            w.MouseButtonPressed  += new EventHandler <SFML.Window.MouseButtonEventArgs>(w_MouseButtonPressed);
            w.MouseMoved          += new EventHandler <SFML.Window.MouseMoveEventArgs>(w_MouseMoved);
            w.MouseButtonReleased += new EventHandler <SFML.Window.MouseButtonEventArgs>(w_MouseButtonReleased);
            w.MouseWheelMoved     += W_MouseWheelMoved;

            SFML.Graphics.Font font = new SFML.Graphics.Font("fonts/FontAwesome.otf");

            List <SFML.Window.Vector2f> foods = new List <SFML.Window.Vector2f>();
            int tick = 0;

            while (w.IsOpen())
            {
                while (foods.Count < 25)
                {
                    foods.Add(new SFML.Window.Vector2f(_rand.Next(0, width), _rand.Next(0, height)));
                }
                while (fishies.Count < 10)
                {
                    Fish fish = new FishSpikingNN(_rand.Next(0, width), _rand.Next(0, height))
                    {
                        Food  = 100000,
                        Angle = _rand.Next(0, 360)
                    };
                    fishies.Add(fish);
                }

                for (int i = 0; i < fishies.Count;)
                {
                    Fish fish = fishies[i];

                    Fish   closestFish = null;
                    double closestDist = double.MaxValue;
                    foreach (var fishOther in fishies)
                    {
                        if (fish != fishOther)
                        {
                            double dist = Utils.Distance(fish.X, fish.Y, fishOther.X, fishOther.Y);
                            if (dist < closestDist)
                            {
                                closestDist = dist;
                                closestFish = fishOther;
                            }
                        }
                    }
                    if (closestFish != null)
                    {
                        fish.SetEye(closestFish.GetLightColor());
                        fish.SetProximity((int)closestDist);
                    }
                    else
                    {
                        fish.SetEye(Color.Black);
                        fish.SetProximity(int.MaxValue);
                    }

                    SFML.Window.Vector2f?foodEaten   = null;
                    SFML.Window.Vector2f?foodSmelled = null;
                    int minFoodDist = int.MaxValue;
                    foreach (var food in foods)
                    {
                        double distWithFood = Utils.Distance(food.X, food.Y, fish.X, fish.Y);
                        if (distWithFood < minFoodDist)
                        {
                            minFoodDist = (int)distWithFood;
                            foodSmelled = food;
                        }
                        if (distWithFood < Fish.FishSize + FoodSize + Fish.FishThickness)
                        {
                            foodEaten = food;
                            break;
                        }
                    }
                    if (foodEaten.HasValue)
                    {
                        fish.Food += 1000;
                        foods.Remove(foodEaten.Value);
                    }
                    fish.SetFood(fish.Food - 1);
                    fish.SetSmell(minFoodDist);
                    if (fish.Food >= Fish.ReproductionFoodPercent * Fish.FishMaxFood)
                    {
                        fish.Food -= (int)(Fish.ReproductionFoodUsage * Fish.FishMaxFood);
                        Fish child = new FishSpikingNN(_rand.Next(0, width), _rand.Next(0, height))
                        {
                            Food  = 100000,
                            Angle = _rand.Next(0, 360)
                        };
                        child.SetGeneticCode(NeuralNetwork.SpikingNetwork.MutateGeneticCode(fish.GetGeneticCode(), .1d));
                        fishies.Add(child);
                    }

                    if (fish.Food == 0)
                    {
                        fishies.Remove(fish);
                    }
                    else
                    {
                        i++;
                    }
                }

                foreach (var fish in fishies)
                {
                    fish.Tick();
                    fish.X = Math.Min(Math.Max(0d, fish.X), width);
                    fish.Y = Math.Min(Math.Max(0, fish.Y), height);
                }

                if (framerate == 0 || tick % framerate == 0)
                {
                    w.DispatchEvents();
                    w.Clear(new SFML.Graphics.Color(Color.CornflowerBlue.R, Color.CornflowerBlue.G, Color.CornflowerBlue.B));
                    w.Draw(new SFML.Graphics.Text(framerate.ToString(), font)
                    {
                        Position = new SFML.Window.Vector2f(25f, 25f)
                    });
                    foreach (var fish in fishies)
                    {
                        foreach (var drawable in fish.Render())
                        {
                            w.Draw(drawable);
                        }
                    }
                    foreach (var food in foods)
                    {
                        w.Draw(new SFML.Graphics.CircleShape(FoodSize)
                        {
                            FillColor = SFML.Graphics.Color.Green,
                            Origin    = new SFML.Window.Vector2f(FoodSize / 2f, FoodSize / 2f),
                            Position  = food
                        });
                    }
                    w.Draw(new SFML.Graphics.RectangleShape(new SFML.Window.Vector2f(width, height))
                    {
                        FillColor        = SFML.Graphics.Color.Transparent,
                        OutlineThickness = 5f,
                        OutlineColor     = SFML.Graphics.Color.Black
                    });
                    w.Display();
                }

                System.Threading.Thread.Sleep(0);
                tick++;
            }
        }
Пример #9
0
 /// <summary>
 ///     Creates a new font by copying from another font.
 /// </summary>
 /// <param name="font">The font to copy.</param>
 public Font(Font font)
 {
     SFMLFont = new SFont(font.SFMLFont);
 }
Пример #10
0
 /// <summary>
 ///     Creates a font by reading from a stream.
 /// </summary>
 public Font(Stream stream)
 {
     SFMLFont = new SFont(stream);
 }
Пример #11
0
 internal Font(SFont font)
 {
     SFMLFont = font;
 }
Пример #12
0
 public Font(byte[] data)
 {
     SFMLFont = new SFont(data);
 }
Пример #13
0
 public Font(string filePath)
 {
     SfmlFont         = new SfmlFont(filePath);
     MeasureContainer = new SfmlText();
 }
Пример #14
0
        private static ExitCode ShowWidget()
        {
            if (!MiGfx.Components.Register())
            {
                ErrorMessage = "Unable to register MiGfx components";
                return(ExitCode.InitFail);
            }

            LoadSettings();

            SFML.Graphics.Texture ptr = Theme.PointerTexture,
                                  bg  = Theme.BackgroundTexture,
                                  ico = Theme.DefaultIcon;
            SFML.Graphics.Font fnt    = Theme.Font;

            if (ptr == null)
            {
                ErrorMessage = "Unable to load pointer texture from \"" + Theme.PointerPath + "\"";
                return(ExitCode.OnLoadFail);
            }
            if (bg == null)
            {
                ErrorMessage = "Unable to load background texture from \"" + Theme.BackgroundPath + "\"";
                return(ExitCode.OnLoadFail);
            }
            if (ico == null)
            {
                ErrorMessage = "Unable to load default icon texture from \"" + Theme.DefaultIconPath + "\"";
                return(ExitCode.OnLoadFail);
            }
            if (fnt == null)
            {
                ErrorMessage = "Unable to load font from \"" + Theme.TextStyle.FontPath + "\"";
                return(ExitCode.OnLoadFail);
            }

            Vector2u cellsize;
            {
                uint csize = GetCellSize();

                cellsize.X = csize;
                cellsize.Y = FolderSettings.DisplayType == IconDisplayType.IconOnly ?
                             csize : csize / 3 * 4;
            }

            WindowSettings settings = new WindowSettings()
            {
                Width  = (cellsize.X * FolderSettings.GridCells.X) + (uint)(ptr.Size.X * Theme.PointerScale.X),
                Height = (cellsize.Y * FolderSettings.GridCells.Y) + 3
            };

            VideoMode desk = VideoMode.DesktopMode;

            while (settings.Width > desk.Width)
            {
                if (FolderSettings.GridCells.X == 1)
                {
                    break;
                }

                FolderSettings.GridCells -= new Vector2u(1, 0);
                settings.Width            = (cellsize.X * FolderSettings.GridCells.X) + (uint)(ptr.Size.X * Theme.PointerScale.X);
            }
            while (settings.Height > desk.Height)
            {
                if (FolderSettings.GridCells.Y == 1)
                {
                    break;
                }

                FolderSettings.GridCells -= new Vector2u(0, 1);
                settings.Height           = (cellsize.Y * FolderSettings.GridCells.Y) + 3;
            }

            if (InitialMousePosition.X + settings.Width + 20 >= desk.Width)
            {
                PointerDirection = MiGfx.Direction.Right;
            }
            else
            {
                PointerDirection = MiGfx.Direction.Left;
            }

            ExitCode e = ExitCode.UnexpectedFail;

            using (WidgetWindow window = new WidgetWindow(settings))
                e = window.Run <WidgetState>();

            SaveSettings();

            if (e != ExitCode.Success)
            {
                ErrorMessage = string.Format("Popcon Widget failed!\nExitCode: {0}", e.ToString());
            }

            return(e);
        }
Пример #15
0
        void Initialize(string str, object font, int size)
        {
            if (size < 0) throw new ArgumentException("Font size must be greater than 0.");

            if (font is string) {
                if ((string)font == "") {
                    this.font = Fonts.DefaultFont;
                }
                else {
                    this.font = Fonts.Load((string)font);
                }
            }
            else {
                Fonts.Load((Stream)font);
            }

            text = new SFML.Graphics.Text(str, this.font, (uint)size);
            String = str;
            Name = "Text";

            SFMLDrawable = text;
        }