Beispiel #1
0
        // create a task for loading the next image
        System.Threading.Tasks.Task LoadNextImage(ImageVoteWidget widget)
        {
            this.BeginLoading(widget);

            var task = new System.Threading.Tasks.Task(async() => {
                // get images until it is a valid image
                Image image = null;
                while (image == null)
                {
                    image = await this.ImageLoader.NextImage();
                }

                System.Threading.SpinWait.SpinUntil(() => !widget.IsFading);

                // update image in gui thread
                BooruApp.BooruApplication.TaskRunner.StartTaskMainThread("Change image", () => {
                    widget.Image = image;
                    image.Release();
                    this.FinishLoading();
                });
            });

            task.Start();
            return(task);
        }
Beispiel #2
0
        void BeginLoading(ImageVoteWidget widget)
        {
            if (this.nLoadingImages == 0)
            {
                // prevent interaction
                this.Sensitive = false;
            }

            widget.IsPaused = true;

            this.nLoadingImages++;
            this.LoadSpinner.Visible = true;
        }
Beispiel #3
0
        // mark the content of one widget as the winner over the other one
        public void Winner(ImageVoteWidget winnerWidget)
        {
            if (winnerWidget == LeftImage)
            {
                LeftImage.Image.Win(RightImage.Image);
            }
            else
            {
                RightImage.Image.Win(LeftImage.Image);
            }

            this.LeftImage.Opponent  = null;
            this.RightImage.Opponent = null;

            this.LoadNextImages();
        }
Beispiel #4
0
        VoteTab(Builder builder, IntPtr handle) : base(builder, handle)
        {
            this.ImageLoader = new RandomImageLoader();

            // create voting widgets
            LeftImage                = ImageVoteWidget.Create();
            LeftImage.OnSkipImage   += Skip;
            LeftImage.OnImageWinner += Winner;

            RightImage                = ImageVoteWidget.Create();
            RightImage.OnSkipImage   += Skip;
            RightImage.OnImageWinner += Winner;

            // reorder things
            this.VoteWidgetOld.Remove(this.CenterButtonBox);
            this.VoteWidgetOld.PackStart(LeftImage, true, true, 0);
            this.VoteWidgetOld.PackStart(this.CenterButtonBox, false, false, 0);
            this.VoteWidgetOld.PackStart(RightImage, true, true, 0);

            // be insensitive until database is loaded
            this.Sensitive = false;

            BooruApp.BooruApplication.EventCenter.DatabaseLoadStarted   += OnDatabaseLoadStarted;
            BooruApp.BooruApplication.EventCenter.DatabaseLoadSucceeded += OnDatabaseLoadSucceeded;
            BooruApp.BooruApplication.EventCenter.FullscreenToggled     += OnFullscreenToggled;

            // filter image types
            foreach (var e in Enum.GetValues(typeof(BooruImageType)))
            {
                this.ImageTypeCombo.Append(e.ToString(), e.ToString());
            }
            this.ImageTypeCombo.ActiveId = BooruImageType.Image.ToString();

            this.ImageTypeCombo.Changed += (sender, e) => {
                this.ImageLoader.SetFilter((BooruImageType)Enum.Parse(typeof(BooruImageType), this.ImageTypeCombo.ActiveId));
                this.Skip(this.LeftImage);
                this.Skip(this.RightImage);
            };
        }
Beispiel #5
0
 // load next image for widget, without voting
 public void Skip(ImageVoteWidget widget)
 {
     LoadNextImage(widget);
 }