SetIcon() public method

Change the window's icon
public SetIcon ( uint width, uint height, byte pixels ) : void
width uint Icon's width, in pixels
height uint Icon's height, in pixels
pixels byte Array of pixels, format must be RGBA 32 bits
return void
Exemplo n.º 1
0
        /// <summary>
        /// Initialize the game. Call once after modifying GameOptions.
        /// </summary>
        public static void Initialize()
        {
            var style = Styles.Titlebar | Styles.Close;
            if (GameOptions.Resizable)
                style |= Styles.Resize;

            size = new Vector2f(GameOptions.Width, GameOptions.Height);
            running = true;

            Window = new RenderWindow(new VideoMode(GameOptions.Width, GameOptions.Height), GameOptions.Caption, style);
            Window.SetFramerateLimit(GameOptions.Framerate);
            Window.SetVerticalSyncEnabled(GameOptions.Vsync);

            if (!string.IsNullOrWhiteSpace(GameOptions.Icon))
            {
                var icon = Assets.LoadTexture(GameOptions.Icon);
                Window.SetIcon(icon.Size.X, icon.Size.Y, icon.CopyToImage().Pixels);
            }

            Framerate = GameOptions.Framerate;

            #region Event Wrappers
            Window.Closed += (sender, args) => Exit(true);
            Window.Resized += (sender, args) => Resize(new Vector2f(args.Width, args.Height));
            Window.MouseButtonPressed += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, true, args.X, args.Y));
            Window.MouseButtonReleased += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, false, args.X, args.Y));
            Window.MouseWheelMoved += (sender, args) => DispatchEvent(new MouseWheelInputArgs(args.Delta, args.X, args.Y));
            Window.MouseMoved += (sender, args) => DispatchEvent(new MouseMoveInputArgs(args.X, args.Y));
            Window.TextEntered += (sender, args) => DispatchEvent(new TextInputArgs(args.Unicode));

            Window.KeyPressed += (sender, args) =>
            {
                if (args.Code == Keyboard.Key.Unknown || KeyStates[(int)args.Code]) // repeated key press
                    return; 
                KeyStates[(int)args.Code] = true;
                DispatchEvent(new KeyInputArgs(args.Code, true, args.Control, args.Shift));
            };

            Window.KeyReleased += (sender, args) =>
            {
                if (args.Code != Keyboard.Key.Unknown)
                    KeyStates[(int)args.Code] = false;
                DispatchEvent(new KeyInputArgs(args.Code, false, args.Control, args.Shift));
            };
            #endregion
        }
Exemplo n.º 2
0
        public Game()
        {
            _mode = new VideoMode(768, 540);
            _title = "Bubble Buster";
            _style = Styles.Close;
            _window = new RenderWindow(_mode, _title, _style);

            System.Drawing.Icon icon = ResourceUtility.GetIconResource("ProjectBubbles.Resources.gamepad.ico");
            if (icon != null) {
                _window.SetIcon((uint) icon.Width, (uint) icon.Height, ResourceUtility.GetPixelBytes(icon.ToBitmap()));
            }

            SetupContent();
            Setup();

            _window.Closed += new EventHandler(OnClose);
            _window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(MousePressed);
        }
Exemplo n.º 3
0
        public static void Initialize()
        {
            var style = Styles.Titlebar | Styles.Close;
            if (GameOptions.Resizable)
                style |= Styles.Resize;

            size = new Vector2f(GameOptions.Width, GameOptions.Height);

            Window = new RenderWindow(new VideoMode(GameOptions.Width, GameOptions.Height), GameOptions.Caption, style);
            Window.SetFramerateLimit(GameOptions.Framerate);
            Window.SetVerticalSyncEnabled(GameOptions.Vsync);

            if (GameOptions.Icon != "")
            {
                Texture texture = Assets.LoadTexture(GameOptions.Icon);
                Window.SetIcon(texture.Size.X, texture.Size.Y, texture.CopyToImage().Pixels);
            }

            Window.Closed += (sender, args) => Window.Close();
            Window.Resized += (sender, args) => Resize(new Vector2f(args.Width, args.Height));
            Window.MouseButtonPressed += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, true, args.X, args.Y));
            Window.MouseButtonReleased += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, false, args.X, args.Y));
            Window.MouseWheelMoved += (sender, args) => DispatchEvent(new MouseWheelInputArgs(args.Delta, args.X, args.Y));
            Window.MouseMoved += (sender, args) => DispatchEvent(new MouseMoveInputArgs(args.X, args.Y));
            Window.TextEntered += (sender, args) => DispatchEvent(new TextInputArgs(args.Unicode));

            Window.KeyPressed += (sender, args) =>
            {
                if (args.Code == Keyboard.Key.Unknown || keyStates[(int)args.Code]) // repeated key press
                    return;
                keyStates[(int)args.Code] = true;
                DispatchEvent(new KeyInputArgs(args.Code, true, args.Control, args.Shift));
            };

            Window.KeyReleased += (sender, args) =>
            {
                if (args.Code != Keyboard.Key.Unknown)
                    keyStates[(int)args.Code] = false;
                DispatchEvent(new KeyInputArgs(args.Code, false, args.Control, args.Shift));
            };
        }
Exemplo n.º 4
0
        private void LoadWindow()
        {
            // Determine settings
            var vmode = new VideoMode(
                (uint)Settings.ReadInt("Video", "ResX", 1024),
                (uint)Settings.ReadInt("Video", "ResY", 600),
                24);
            bool fscreen = Settings.ReadInt("Video", "Fullscreen", 0) == 1;
            bool vsync = Settings.ReadInt("Video", "VSync", 1) == 1;

            // Setup the new window
            window = new RenderWindow(vmode, "FTL: Overdrive", fscreen ? Styles.Fullscreen : Styles.Close, new ContextSettings(24, 8, 8));
            window.SetVisible(true);
            window.SetVerticalSyncEnabled(vsync);
            window.MouseMoved += new EventHandler<MouseMoveEventArgs>(window_MouseMoved);
            window.Closed += new EventHandler(window_Closed);
            window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(window_MouseButtonPressed);
            window.MouseButtonReleased += new EventHandler<MouseButtonEventArgs>(window_MouseButtonReleased);
            window.KeyPressed += new EventHandler<KeyEventArgs>(window_KeyPressed);
            window.KeyReleased += new EventHandler<KeyEventArgs>(window_KeyReleased);
            window.TextEntered += new EventHandler<TextEventArgs>(window_TextEntered);

            // Init UI
            Canvas = new UI.Canvas();
            var screenrect = Util.ScreenRect(window.Size.X, window.Size.Y, 1.77778f);
            Canvas.X = screenrect.Left;
            Canvas.Y = screenrect.Top;
            Canvas.Width = screenrect.Width;
            Canvas.Height = screenrect.Height;

            // Load icon
            using (var bmp = new System.Drawing.Bitmap(Resource("img/exe_icon.bmp")))
            {
                byte[] data = new byte[bmp.Width * bmp.Height * 4];
                int i = 0;
                for (int y = 0; y < bmp.Height; y++)
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        var c = bmp.GetPixel(x, y);
                        data[i++] = c.R;
                        data[i++] = c.G;
                        data[i++] = c.B;
                        data[i++] = c.A;
                    }
                window.SetIcon((uint)bmp.Width, (uint)bmp.Height, data);
            }
        }
Exemplo n.º 5
0
        public static void Run()
        {
            Sound.Loop("music/seaponies");

            window = new RenderWindow(videomode, title, Styles.Default);

            window.Closed += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized += new EventHandler<SizeEventArgs>(OnResized);

            window.SetIcon(48, 48, new Image("data/tilesheets/pinktaffy48.png").Pixels);

            Sprite titleScreen = new Sprite(new Texture(new Image("data/tilesheets/title.png")));

            lastTick = DateTime.Now;

            View originView = new View(new Vector2f(400, 300), new Vector2f(800, 600));

            DateTime starttime = DateTime.Now;

            while (window.IsOpen())
            {

                if (TotalTaffies != 0 && StaticResources.State.Candies >= TotalTaffies){
                    var t = (DateTime.Now - starttime).TotalMilliseconds/1000;
                    System.Windows.Forms.MessageBox.Show("You win! Time: " + t);
                    System.IO.File.AppendAllText("scores.txt", t + "\n");
                   Environment.Exit(0);
                }

                DeltaTimeMS = (DateTime.Now - lastTick).TotalMilliseconds;

                if (DeltaTimeMS < MSPF)
                {
                    System.Threading.Thread.Sleep((int)(MSPF - DeltaTimeMS));
                    DeltaTimeMS = MSPF;
                }

                lastTick = DateTime.Now;

                window.DispatchEvents();

                window.SetView(originView);
                window.Draw(StaticResources.State.Background);

                switch (mode)
                {
                    case ExecMode.Title:
                        window.Draw(titleScreen);
                        break;
                    case ExecMode.Intro:
                        StaticResources.State.Tick();
                        DialogIfDialog();
                        break;
                    case ExecMode.Main:
                        StaticResources.State.Tick();

                        if (StaticResources.State.MainCharacter != null){
                            window.SetView(StaticResources.State.MainCharacter.View);
                            //window.SetTitle(StaticResources.State.MainCharacter.Position.ToString());
                        }

                        foreach (SeaPonyDash.Actor a in StaticResources.State.Actors)
                        {
                            if (!a.Hidden && a.OnScreen)
                            {
                                //if (a.Type == ActorType.Taffy)
                                //{
                                //    Sprite b = new Sprite(a.Sprite);
                                //    b.Position = a.Position;
                                //    b.TextureRect = new IntRect(0, 0, 64, 64);
                                //    //works
                                //    window.Draw(b);
                                //}
                                //shows nothing on all but a few of the taffy sprites
                                window.Draw(new Sprite(a.Sprite) { Position = a.Position, TextureRect = a.Sprite.TextureRect });
                                //System.Windows.Forms.MessageBox.Show(a.Sprite.Position.ToString() + " " + a.Frame.ToXml() + " " + a.Animation.ToXml());
                            }
                            else
                            {
                            }
                        }

                        window.SetView(originView);

                        Text txt = new Text("Taffies: " + StaticResources.State.Candies + " / " + (TotalTaffies), StaticResources.CelestiaRedux);
                        txt.CharacterSize = 30;

                        DialogIfDialog();

                        window.Draw(txt);

                        if (StaticResources.State.MainCharacter != null)
                            window.SetView(StaticResources.State.MainCharacter.View);

                        break;
                    case ExecMode.End:

                        break;
                }

                window.Display();
            }
        }
Exemplo n.º 6
0
        public static void set_window(uint w = 0, uint h = 0, bool fullscreen = false)
        {
            if (w == 0 || h == 0)
            {
                if (fullscreen)
                {
                    w = desktop_w;
                    h = desktop_h;
                }
                else
                {
                    w = last_windowed_w;
                    h = last_windowed_h;
                    if (w == 0) w = desktop_w;
                    if (h == 0) h = desktop_h;
                    if (w > desktop_w) w = desktop_w;
                    if (h > desktop_h) h = desktop_h;
                }
            }

            _fullscreen = fullscreen;

            if (!fullscreen)
            {
                last_windowed_h = h; last_windowed_w = w;
            }

            Debug.Log("Setting window to: " + w + " x " + h + (fullscreen ? " FULLSCREEN " : ""), Debug.priorities.normal);

            if (win != null) win.Close();

            screen_w = w;
            screen_h = h;

            Pipeline.main_window.force_resize(w, h);

            Styles style = fullscreen ?
                Styles.Fullscreen
                :
                Styles.Titlebar | Styles.Close;

            win = new RenderWindow(new SFML.Window.VideoMode(w, h), Application.title, style);

            win.Closed += new EventHandler(Session.on_close_signal);
            win.KeyPressed += new EventHandler<KeyEventArgs>(Input.Events.on_key_press);
            win.KeyReleased += new EventHandler<KeyEventArgs>(Input.Events.on_key_depress);
            win.MouseMoved += new EventHandler<MouseMoveEventArgs>(Input.Events.on_mouse_move);
            win.MouseWheelMoved += new EventHandler<MouseWheelEventArgs>(Input.Events.on_mouse_wheel);
            win.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(Input.Events.on_key_press);
            win.MouseButtonReleased += new EventHandler<MouseButtonEventArgs>(Input.Events.on_key_depress);

            Graphics.Pipeline.on_resolution_change();

            Debug.Log("Window set!", Debug.priorities.normal);

            if (_selected_icon != null)
                win.SetIcon(64, 64, _selected_icon.image.Pixels);
        }
Exemplo n.º 7
0
        //MAIN()
        static void Main(string[] args)
        {
            dominosposition = new List<Vector2f>();
            GameDomino = new Domino_NormalRules();
            GameDomino.start_game();

            dominoAi.DominoAI DominoAi = new dominoAi.DominoAI();
            DominoAi.set_game(GameDomino);

            renderalldominos = new MySFML.RenderAllDominos();

            path_ImageBlockDomino = "resources/blockdomino.png";
            if (!File.Exists(path_ImageBlockDomino))
            {
                Console.WriteLine("ImageBlockDomino not founded");
                return;
            }
            renderalldominos.set_image(new Image(path_ImageBlockDomino));

            String path_ImageBackground = "resources/background.png";
            if (!File.Exists(path_ImageBackground))
            {
                Console.WriteLine("background not founded");
                return;
            }
            Image imagebackground = new Image(path_ImageBackground);
            Texture texturebackground = new Texture(imagebackground);
            texturebackground.Repeated = true;
            Sprite background = new Sprite(texturebackground, new IntRect(0,0,(int)WidthWindow, (int)HeightWindow));

            String path_icon = "resources/icon.png";
            if (!File.Exists(path_icon))
            {
                Console.WriteLine("path_icon not founded");
                return;
            }
            Image image_icon = new Image(path_icon);

            path_Font = "resources/font.ttf";
            if (!File.Exists(path_Font))
            {
                Console.WriteLine("Font not founded");
                return;
            }
            Text score = new Text("Dupa", new Font(path_Font));

             path_image_button = "resources/button151x54.png";
            if (!File.Exists(path_image_button))
            {
                Console.WriteLine("Image button not founded");
                return;
            }
            //left BUTTON
            left = new MySFML.MyButton();
            left.load_image(new Image(path_image_button), "left side", new Font(path_Font));
            left.set_position(new Vector2f(WidthWindow - 200, 350));

            //right BUTTON
            right = new MySFML.MyButton();
            right.load_image(new Image(path_image_button), "right side", new Font(path_Font));
            right.set_position(new Vector2f(WidthWindow - 200, 404));

            //draw BUTTON
            draw = new MySFML.MyButton();
            draw.load_image(new Image(path_image_button), "draw domino", new Font(path_Font));
            draw.set_position(new Vector2f(WidthWindow - 200, 458));

            //restart BUTTON
            restart = new MySFML.MyButton();
            restart.load_image(new Image(path_image_button), "restart" , new Font(path_Font));
            restart.set_position(new Vector2f(WidthWindow - 200, 512));

            score.Color = Color.Black;
            score.CharacterSize = 20;
            score.Position += new Vector2f(WidthWindow - 200, 100);

            ContextSettings contextSettings = new ContextSettings();
            contextSettings.DepthBits = 32;

            RenderWindow window = new RenderWindow(new VideoMode((uint)WidthWindow, (uint)HeightWindow), "Domino Game", Styles.Default, contextSettings);
            window.SetVerticalSyncEnabled(true);

            window.SetIcon(32, 32, image_icon.Pixels);

            window.Closed += new EventHandler(closed_action);
            window.KeyPressed += new EventHandler<KeyEventArgs>(key_pressed);
            window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(mouse_pressed);

            window.SetFramerateLimit(60);
            bool openWindow = new bool();
            openWindow = true;
            windowcapture = new Texture(window.Capture());
            score.Color = Color.White;
            while (window.IsOpen() && openWindow)
            {
                try
                {
                    DominoAi.play();

                }
                catch (Exception e)
                {
                    //break;
                }

                if (GameDomino.test_game() == -2)
                {
                    openWindow = false;
                };
                window.DispatchEvents();

                //Points and infromation;
                score.DisplayedString = String.Format("Time game left: {0} \nScore Player1: {1}\nScore Player2: {2}",
                    GameDomino.get_global_time_end(),
                    GameDomino.get_points_player1(),
                    GameDomino.get_points_player2());

                /////////////Draw a dominos player and computer//////////
                window.Clear(Color.Yellow);
                window.Draw(background);
                draw_player1(window);
                draw_player2(window);
                draw_onboard(window);

                window.Draw(left.draw());
                window.Draw(right.draw());
                window.Draw(draw.draw());
                window.Draw(restart.draw());
                window.Draw(score);

                window.Display();

                if (openWindow == false)
                {
                    windowcapture = new Texture(window.Capture());
                }

            }
            //window.Close();
            //window = new RenderWindow(new VideoMode((uint)WidthWindow, (uint)HeightWindow), "Domino Game", Styles.Default, contextSettings);
            //window.Closed += new EventHandler(closed_action);
            //window.KeyPressed += new EventHandler<KeyEventArgs>(key_pressed);
            //window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(mouse_pressed);

            System.Diagnostics.Stopwatch start = new System.Diagnostics.Stopwatch();
            start.Start();
            Text winner = new Text(GameDomino.Type_Winner().ToString(),new Font(path_Font), 30);
            winner.Color = Color.Red;
            while (window.IsOpen())
            {
                window.DispatchEvents();

                window.Draw(new Sprite(windowcapture));

                if (start.ElapsedMilliseconds > 100)
                {
                    winner.Position += new Vector2f(1, 4);
                    if(winner.Position.Y > HeightWindow)
                        winner.Position = new Vector2f(-1, -4);
                }

                window.Draw(winner);
                window.Display();
            }
        }