Example #1
0
        public bool GetCheerEmote(string name, int cheer, bool light, out LazyLoadedImage outemote, out string outcolor)
        {
            CheerEmote      emote;
            LazyLoadedImage emoteimage;
            string          color;

            outemote = null;
            outcolor = null;

            if (CheerEmotes.TryGetValue(name.ToUpper(), out emote))
            {
                bool ret = emote.GetCheerEmote(cheer, light, out emoteimage, out color);
                outemote = emoteimage;
                outcolor = color;
                return(ret);
            }
            return(false);
        }
Example #2
0
        public void HandleAnimatedTwitchEmote(LazyLoadedImage emote, ChatterinoImage image)
        {
            if (image != null)
            {
                ChatterinoImage img      = image;
                bool            animated = false;
                lock (img) {
                    animated = img.IsAnimated;
                }

                if (animated)
                {
                    try
                    {
                        int   frameCount         = img.GetFrameCount();
                        int[] frameDuration      = new int[frameCount];
                        int   totaldelay         = 0;
                        int   currentFrame       = 0;
                        int   currentFrameOffset = 0;
                        int   num = 0;
                        num = img.GetFrameDuration(0);
                        if (num <= 1)
                        {
                            num = 10;
                        }
                        frameDuration[0] = num - 1;
                        totaldelay       = num;
                        for (int i = 1; i < frameCount; i++)
                        {
                            num = img.GetFrameDuration(i);

                            if (num <= 1)
                            {
                                num = 10;
                            }
                            frameDuration[i] = frameDuration[i - 1] + num;
                            totaldelay      += num;
                        }
                        emote.IsAnimated       = true;
                        emote.HandleAnimation += (int offset) =>
                        {
                            currentFrameOffset = offset % totaldelay;

                            int oldCurrentFrame = currentFrame;

                            currentFrame = 0;

                            int index = Array.BinarySearch(frameDuration, currentFrameOffset);
                            if (index >= 0)
                            {
                                currentFrame = index;
                            }
                            else
                            {
                                currentFrame = ~index;
                                if (currentFrame >= frameCount)
                                {
                                    currentFrame = 0;
                                }
                            }

                            if (oldCurrentFrame != currentFrame)
                            {
                                lock (img)
                                {
                                    img.SelectActiveFrame(currentFrame);
                                }
                            }
                        };
                    }
                    catch (Exception e) {
                        this.log(e.ToString());
                    }
                }
            }
        }
Example #3
0
        public static void ShowToolTip(Point point, string text, string imgurl, LazyLoadedImage tooltipimage, bool force = false)
        {
            //if (force || WindowFocused || (EmoteList?.ContainsFocus ?? false))

            try
            {
                lock (tooltiplock) {
                    if (ToolTip == null)
                    {
                        ToolTip = new Controls.ToolTip()
                        {
                            Enabled = false
                        };
                    }
                }

                lock (ToolTip) {
                    ToolTip.TooltipText = text;
                }
                if (AppSettings.ShowEmoteTooltip && !String.IsNullOrEmpty(imgurl) && (ToolTip.Image == null || !ToolTip.Image.Url.Equals(imgurl)))
                {
                    LazyLoadedImage img;
                    if (tooltipimage != null)
                    {
                        img = tooltipimage;
                    }
                    else
                    {
                        img     = new LazyLoadedImage();
                        img.Url = imgurl;
                    }
                    img.ImageLoaded += (s, e) => {
                        lock (ToolTip) {
                            point = calcTooltipLocation(point);
                            if (ToolTip.Location != point)
                            {
                                ToolTip.Location = point;
                            }
                            ToolTip.redraw();
                        }
                    };
                    lock (ToolTip) {
                        ToolTip.Image = img;
                    }
                }
                else if (String.IsNullOrEmpty(imgurl))
                {
                    lock (ToolTip) {
                        ToolTip.Image = null;
                    }
                }
                lock (ToolTip) {
                    if (!ToolTip.Visible)
                    {
                        ToolTip.Show();
                        SetWindowPos(ToolTip.Handle.ToInt32(), HWND_TOPMOST,
                                     ToolTip.Left, ToolTip.Top, ToolTip.Width, ToolTip.Height,
                                     SWP_NOACTIVATE);
                    }

                    point = calcTooltipLocation(point);

                    if (ToolTip.Location != point)
                    {
                        ToolTip.Location = point;
                    }
                }
            } catch (Exception e) {
                GuiEngine.Current.log("exception loading tooltip " + e.ToString());
            }
        }
Example #4
0
 public void HandleAnimatedTwitchEmote(LazyLoadedImage emote)
 {
 }
Example #5
0
        public void HandleAnimatedTwitchEmote(LazyLoadedImage emote)
        {
            if (emote.Image != null)
            {
                var img = (Image)emote.Image;

                var animated = ImageAnimator.CanAnimate(img);

                if (animated)
                {
                    try
                    {
                        var dimension          = new FrameDimension(img.FrameDimensionsList[0]);
                        var frameCount         = img.GetFrameCount(dimension);
                        var frameDuration      = new int[frameCount];
                        var currentFrame       = 0;
                        var currentFrameOffset = 0;

                        var times = img.GetPropertyItem(0x5100).Value;
                        var frame = 0;
                        for (var i = 0; i < frameCount; i++)
                        {
                            var num = BitConverter.ToInt32(times, 4 * frame);

                            if (num == 0)
                            {
                                frameDuration[i] = 4;
                            }
                            else
                            {
                                frameDuration[i] = num;
                            }
                        }
                        emote.IsAnimated = true;

                        Console.WriteLine("new gif emote " + emote.Name);

                        App.GifEmoteFramesUpdating += (s, e) =>
                        {
                            currentFrameOffset += 3;

                            var oldCurrentFrame = currentFrame;

                            while (true)
                            {
                                if (currentFrameOffset > frameDuration[currentFrame])
                                {
                                    currentFrameOffset -= frameDuration[currentFrame];
                                    currentFrame        = (currentFrame + 1) % frameCount;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            if (oldCurrentFrame != currentFrame)
                            {
                                lock (img)
                                {
                                    img.SelectActiveFrame(dimension, currentFrame);
                                }
                            }
                        };
                    }
                    catch { }
                }
                App.TriggerEmoteLoaded();
            }
        }
Example #6
0
        public void HandleAnimatedTwitchEmote(LazyLoadedImage emote, Image image)
        {
            if (image != null)
            {
                Image img = (Image)image;

                bool animated = ImageAnimator.CanAnimate(img);

                if (animated)
                {
                    try
                    {
                        FrameDimension dimension          = new FrameDimension(img.FrameDimensionsList[0]);
                        int            frameCount         = img.GetFrameCount(dimension);
                        int[]          frameDuration      = new int[frameCount];
                        int            currentFrame       = 0;
                        int            currentFrameOffset = 0;

                        PropertyItem framedelay = img.GetPropertyItem(0x5100);
                        Byte[]       times      = framedelay.Value;
                        int          num        = 0;
                        for (int i = 0; i < frameCount; i++)
                        {
                            num = BitConverter.ToInt32(times, 4 * i);

                            if (num <= 1)
                            {
                                frameDuration[i] = 10;
                            }
                            else
                            {
                                frameDuration[i] = num;
                            }
                        }
                        emote.IsAnimated = true;

                        emote.HandleAnimation += () =>
                        {
                            currentFrameOffset += 3;

                            var oldCurrentFrame = currentFrame;

                            while (true)
                            {
                                if (currentFrameOffset > frameDuration[currentFrame])
                                {
                                    currentFrameOffset -= frameDuration[currentFrame];
                                    currentFrame        = (currentFrame + 1) % frameCount;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            if (oldCurrentFrame != currentFrame)
                            {
                                lock (img)
                                {
                                    img.SelectActiveFrame(dimension, currentFrame);
                                }
                            }
                        };
                    }
                    catch (Exception e) {
                        this.log(e.ToString());
                    }
                }
            }
        }