예제 #1
0
 public void redraw()
 {
     image = _image?.Image;
     calcSize();
     Invalidate();
     Update();
 }
예제 #2
0
 public SettingsTabPage(string text, ChatterinoImage image, bool selected)
 {
     Text           = text;
     this.image     = image;
     Visible        = true;
     this.Location  = new Point(0, 0);
     this.Size      = new Size(200, 30);
     this.BackColor = Color.FromArgb(64, 64, 64);
     this.selected  = selected;
     Invalidate();
 }
예제 #3
0
        public ChatterinoImage ReadImageFromStream(MemoryStream stream)
        {
            try
            {
                return(ChatterinoImage.FromStream(stream));
            }
            catch (Exception e) {
                log(e.ToString());
            }

            return(null);
        }
예제 #4
0
        public ChatterinoImage DrawImageBackground(ChatterinoImage image, HSLColor color)
        {
            var img = image;

            var bitmap = new Bitmap(img.Width, img.Height);

            using (var g = Graphics.FromImage(bitmap))
            {
                g.Clear(color.ToColor());
                img.DrawImage(g, 0, 0, img.Width, img.Height);
            }

            return(new ChatterinoImage(bitmap));
        }
예제 #5
0
        public ChatterinoImage ScaleImage(ChatterinoImage image, double scale)
        {
            var img = image;

            int w = (int)(img.Width * scale), h = (int)(img.Height * scale);

            var newImage = new Bitmap(w, h);

            using (var graphics = Graphics.FromImage(newImage))
            {
                graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                img.DrawImage(graphics, 0, 0, w, h);
            }

            return(new ChatterinoImage(newImage));
        }
예제 #6
0
        public CommonSize GetImageSize(ChatterinoImage image)
        {
            if (image == null)
            {
                return(new CommonSize());
            }
            else
            {
                try
                {
                    return(new CommonSize(image.Width, image.Height));
                }
                catch (Exception e) {
                    log("error getting image size: " + e.ToString());
                }

                return(new CommonSize(16, 16));
            }
        }
예제 #7
0
 public void FreezeImage(ChatterinoImage img)
 {
 }
예제 #8
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());
                    }
                }
            }
        }
예제 #9
0
        //public static void DrawGifEmotes(object graphics, Common.Message message, Selection selection, int currentLine)
        public static void DrawGifEmotes(object graphics, List <GifEmoteState> gifEmotes, Selection selection)
        {
            var g = (Graphics)graphics;

            var spaceWidth =
                GuiEngine.Current.MeasureStringSize(App.UseDirectX ? null : g, FontType.Medium, " ").Width;

            foreach (var state in gifEmotes)
            {
                Brush backgroundBrush;

                if ((state.HighlightType & HighlightType.Highlighted) == HighlightType.Highlighted)
                {
                    backgroundBrush = App.ColorScheme.ChatBackgroundHighlighted;
                }
                else if ((state.HighlightType & HighlightType.Highlighted) == HighlightType.UsernameHighlighted)
                {
                    backgroundBrush = App.ColorScheme.ChatBackgroundUsernameHighlighted;
                }
                else if ((state.HighlightType & HighlightType.Resub) == HighlightType.Resub)
                {
                    backgroundBrush = App.ColorScheme.ChatBackgroundResub;
                }
                else
                {
                    backgroundBrush = App.ColorScheme.ChatBackground;
                }

                if (state.Words.Count > 1)
                {
                    g.Clip = new Region(new Rectangle(state.X, state.Y, state.Width, state.Height));
                }

                g.FillRectangle(backgroundBrush, state.X, state.Y,
                                state.Width, state.Height);

                foreach (var word in state.Words)
                {
                    switch (word.Type)
                    {
                    case SpanType.Text:
                        break;

                    case SpanType.LazyLoadedImage:
                        ChatterinoImage img = (word.Value as LazyLoadedImage)?.Image as ChatterinoImage;

                        if (img != null)
                        {
                            lock (img) {
                                img.DrawImage(g, word.X + state.MessageXOffset,
                                              word.Y + state.MessageYOffset, word.Width, word.Height);
                            }
                        }
                        break;
                        //    case SpanType.Image:
                        //        g.DrawImage((Image)word.Value, word.X + state.MessageXOffset, word.Y + state.MessageYOffset, word.Width, word.Height);
                        //        break;
                        //}
                    }
                }

                if (state.Disabled)
                {
                    g.FillRectangle(
                        new SolidBrush(Color.FromArgb(172,
                                                      (App.ColorScheme.ChatBackground as SolidBrush)?.Color ?? Color.Black)),
                        state.X, state.Y, state.Width + spaceWidth,
                        state.Height);
                }

                if (state.Selected)
                {
                    g.FillRectangle(_selectionBrush, state.X, state.Y,
                                    state.Width, state.Height);
                }
                if (state.Words.Count > 1)
                {
                    g.ResetClip();
                }
            }
        }