Ejemplo n.º 1
0
 private void _ThreadMethod()
 {
     for (int i = 0; i < _IDs.Count && _IsRunning; i++)
     {
         using (BooruImage image = _UseImages ? _Booru.GetImage(_IDs[i]) : _Booru.GetThumbnail(_IDs[i]))
         {
             try
             {
                 Texture2D texture = CreateTexture(image);
                 lock (_Textures)
                     _Textures.Add(texture);
                 if (NewTextureLoaded != null)
                 {
                     NewTextureLoaded();
                 }
             }
             catch (Exception ex)
             {
                 if (_IsRunning)
                 {
                     ScreensaverHelper.HandleException(ex);
                 }
             }
         }
     }
     if (LoadingFinished != null && _IDs.Count == _Textures.Count)
     {
         LoadingFinished();
     }
 }
Ejemplo n.º 2
0
 public void Update(GameTime gameTime)
 {
     if (!Finished)
     {
         double elapsed = gameTime.ElapsedGameTime.TotalMilliseconds / 1000;
         _Rad += elapsed * _RotateSpeed / 180 * Math.PI;
         _Y   += elapsed * _FallSpeed;
         if (_SpreadDegrees > 0)
         {
             _X += elapsed * _FallSpeed * Math.Tan(Math.PI / 180 * _SpreadDegrees);
         }
         Finished = _Y - _Limit > _ScrHeight;
     }
     if (!Finished)
     {
         MouseState state      = Mouse.GetState();
         Vector2    scaledSize = new Vector2((float)(_Texture.Width * _Scale), (float)(_Texture.Height * _Scale));
         _MouseInside = ScreensaverHelper.MouseInRotatedRectangle(state, new Vector2((float)_X, (float)_Y), scaledSize, _Rad);
         float maxSize = Math.Max(scaledSize.X, scaledSize.Y);
         if (maxSize < 40 || (_MouseInside && state.LeftButton == ButtonState.Pressed))
         {
             _Scale -= 0.01f;
         }
         Finished = !(_Scale > 0f);
         if (!_MouseRightButtonDown && state.RightButton == ButtonState.Pressed && _MouseInside && RightClick != null)
         {
             RightClick();
         }
         _MouseRightButtonDown = state.RightButton == ButtonState.Pressed;
     }
 }
Ejemplo n.º 3
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            _Booru.Connect(_Options.Server);

            _IDs = _Booru.Search(_Options.Search ?? string.Empty);
            int deleteCount = _IDs.Count - _Options.ImageLimit;

            for (int i = 0; i < deleteCount; i++)
            {
                _IDs.RemoveAt(R.Next(0, _IDs.Count));
            }

            _Cursor     = new Cursor(ScreensaverHelper.Texture2DFromBytes(GraphicsDevice, Properties.Resources.cursor), 1f);
            _Background = new BackgroundBooruTexture(W, H);

            _ImgManager = new ImageManager(R, GraphicsDevice, _Booru, _IDs, _Options.ImageSize, _Options.UseImages);
            _ImgManager.NewTextureLoaded += () =>
            {
                lock (_Textures)
                    if (_Textures.Count < _Options.ImageCount || _Options.ImageCount < 1)
                    {
                        AddNewFBT();
                    }
            };
            //_ImgManager.LoadingFinished += _Booru.Disconnect;

            _ImgManager.Start();
            AddNewFBT();
        }
Ejemplo n.º 4
0
        protected override void Initialize()
        {
            _Booru         = new BooruClient();
            _Textures      = new List <FallingBooruTexture>();
            _Font          = new BitmapFontRenderer(GraphicsDevice);
            _BackgroundHue = R.NextDouble() * 360;

            if (_Options.Debug)
            {
                string  productName = ScreensaverHelper.GetAssemblyAttribute <AssemblyProductAttribute>(x => x.Product);
                Version version     = Assembly.GetExecutingAssembly().GetName().Version;
                _ProductNameAndVersion = string.Format("{0} V{1}", productName, version);
            }

            graphics.PreferredBackBufferWidth       = W;
            graphics.PreferredBackBufferHeight      = H;
            graphics.PreferMultiSampling            = true;
            graphics.SynchronizeWithVerticalRetrace = !_Options.NoVSync;
            graphics.ApplyChanges();
            graphics.ToggleFullScreen();

            if (_Options.FPSLimit > 0)
            {
                TargetElapsedTime = new TimeSpan(10000000L / _Options.FPSLimit);
            }
            else
            {
                IsFixedTimeStep = false;
            }

            IsMouseVisible = false;

            base.Initialize();
        }
Ejemplo n.º 5
0
        public string GetUsage()
        {
            StringBuilder sb = new StringBuilder();

            string  productName = ScreensaverHelper.GetAssemblyAttribute <AssemblyProductAttribute>(x => x.Product);
            Version version     = Assembly.GetExecutingAssembly().GetName().Version;

            sb.AppendFormat("{0} V{1}", productName, version);
            sb.AppendLine();
            string copyright = ScreensaverHelper.GetAssemblyAttribute <AssemblyCopyrightAttribute>(x => x.Copyright);

            sb.Append(copyright);
            sb.AppendLine();
            sb.AppendLine();

            sb.AppendLine("  -s, --server <srv>[:prt] Server to connect to [localhost]");
            sb.AppendLine("  -u, --username <un>      Username for auto login");
            sb.AppendLine("  -p, --password <pw>      Password for auto login");
            sb.AppendLine("  -q  --search <str>       Search string [All posts]");
            sb.AppendLine("  -l  --image-limit <n>    Download max. n images [500]");
            //sb.AppendLine("  -f  --fps-limit <n>      Limit the FPS to n, (0 = unlimited) [60]");
            //sb.AppendLine("  -v  --no-vsync           Disable VSync");
            sb.AppendLine("  -i  --use-images         Use images instead of thumbnails");
            sb.AppendLine("  -d  --debug              Show debug information");
            sb.AppendLine("  -m  --image-size <n>     Image size [300]");
            sb.AppendLine("  -c  --image-count <n>    Show n images on screen [15]");
            sb.AppendLine("All switches are optional");

            sb.AppendLine();
            return(sb.ToString());
        }
Ejemplo n.º 6
0
        private Texture2D CreateTexture(BooruImage Image)
        {
            double sideLength = 0;

            lock (_R)
                sideLength = _MaxSideLength * (_R.NextDouble() + 0.5) + 0.5;
            using (BooruImage smallImage = Image.CreateThumbnail((int)sideLength, false))
                return(ScreensaverHelper.Texture2DFromBitmap(_GD, smallImage.Bitmap));
        }
Ejemplo n.º 7
0
        public void SetBooruImage(GraphicsDevice GD, BooruImage Image)
        {
            Dispose();
            _Texture = ScreensaverHelper.Texture2DFromBytes(GD, Image.Bytes);
            float   num        = Math.Max(_Screen.X / _Texture.Width, _Screen.Y / _Texture.Height);
            Vector2 resultSize = new Vector2(_Texture.Width * num, _Texture.Height * num);

            _DrawRectangle = new Rectangle(
                0 - (int)((resultSize.X - _Screen.X) / 2 + 0.5),
                0 - (int)((resultSize.Y - _Screen.Y) / 2 + 0.5),
                (int)resultSize.X, (int)resultSize.Y);
        }
Ejemplo n.º 8
0
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            lock (_Textures)
                for (int i = _Textures.Count - 1; !(i < 0); i--)
                {
                    FallingBooruTexture texture = _Textures[i];
                    texture.Update(gameTime);
                    if (texture.Finished)
                    {
                        _Textures.RemoveAt(i);
                        AddNewFBT();
                    }
                }

            if (!_Background.IsBackgroundAvailable)
            {
                _BackgroundHue += 1 / 20;
                if (_BackgroundHue > 360)
                {
                    _BackgroundHue -= 360;
                }
                _BackgroundColor = ScreensaverHelper.ColorFromHSV(_BackgroundHue, 0.9, 0.15);
            }

            MouseState mState = Mouse.GetState();

            _Cursor.Update(gameTime, mState);

            if (mState.MiddleButton == ButtonState.Pressed)
            {
                _BackgroundID = _IDs[R.Next(0, _IDs.Count)];
                _Background.SetBooruImage(GraphicsDevice, _Booru.GetImage(_BackgroundID));
            }

            base.Update(gameTime);
        }
Ejemplo n.º 9
0
        public static int Main(string[] args)
        {
            BooruSCR game = null;

            try
            {
                if (Helper.IsWindows() || Helper.IsUnix())
                {
                    Options options = new Options();
                    if (Parser.Default.ParseArguments(args, options))
                    {
                        game = new BooruSCR(options);
                        game.Run();
                        return(0);
                    }
                    else
                    {
                        throw new Exception("Error while parsing arguments");
                    }
                }
                else
                {
                    throw new PlatformNotSupportedException();
                }
            }
            catch (Exception ex)
            {
                ScreensaverHelper.HandleException(ex);
                return(1);
            }
            finally
            {
                if (game != null)
                {
                    game.Dispose();
                }
            }
        }