Пример #1
0
        private void HandlePaintBackground(PaintEventArgs e)
        {
            var      bufferImage = new ImageWithDeviceContext(Size);
            Graphics g           = Graphics.FromHdc(bufferImage.Dc);

            DrawBackground(bufferImage);

            int last = LastScrollableItemIndex;

            var mousePos        = _form.PointToClient(Cursor.Position);
            var currentHoverred = mousePos.Y / ItemHeight;

            int relativeIndex = 0;

            for (int i = FirstScrollableItemIndex; i <= last; i++)
            {
                LayeredPopupMenuItem item = Items[i];
                DrawItem(bufferImage, g, item, relativeIndex, currentHoverred == relativeIndex);

                relativeIndex++;
            }

            NativeMethods.BitBlt(e.Graphics.GetHdc(), 0, 0, Width, Height, bufferImage.Dc, 0, 0, CopyPixelOperation.SourceCopy);
            e.Graphics.ReleaseHdc();

            bufferImage.Dispose();
            g.Dispose();
        }
Пример #2
0
        protected virtual void DrawItem(ImageWithDeviceContext destImage, Graphics g, LayeredPopupMenuItem item, int index, bool hovered)
        {
            var bounds = new Rectangle();

            bounds.Width  = Width - (ContentMargin.Right + ContentMargin.Left + ItemContentRight);
            bounds.Height = ItemBackgroundImage.Height;

            bounds.X = ContentMargin.Left;
            bounds.Y = ContentMargin.Top + index * bounds.Height;

            DrawImage(destImage, item, bounds, hovered);

            Rectangle textBounds = bounds;

            textBounds.X      += ItemContent.Left;
            textBounds.Y      += ItemContent.Top;
            textBounds.Width  -= ItemContent.Left + ItemContent.Right + ItemContentRight;
            textBounds.Height -= ItemContent.Top + ItemContent.Bottom;

            DrawText(g, item, textBounds);

            if (hovered && item.HoveredImage != null)
            {
                g.DrawImage(item.HoveredImage, ItemIconLocation.X + bounds.X, ItemIconLocation.Y + bounds.Y);
            }
            else if (item.Image != null)
            {
                g.DrawImage(item.Image, ItemIconLocation.X + bounds.X, ItemIconLocation.Y + bounds.Y);
            }
        }
Пример #3
0
        protected override void Draw(ImageWithDeviceContext destImage)
        {
            base.Draw(destImage);

            if (TextVisible)
            {
                DrawText(Opacity, destImage);
            }
        }
Пример #4
0
        private void DrawText(byte opacity, ImageWithDeviceContext destImage)
        {
            Rectangle textBounds = this.TextBounds;

            TitleRenderer.DrawText(Text, destImage,
                                   textBounds.Location, textBounds.Size,
                                   opacity, TextColorBrush,
                                   StringFormat, Font);
        }
Пример #5
0
        protected override void DrawBackground(ImageWithDeviceContext destImage)
        {
            if (!Enabled)
            {
                base.BackgroundImage = DisabledBackgroundImage;
            }
            else if (_forceState == ButtonState.Hover || (Hovered && !_animationRequested))
            {
                base.BackgroundImage = HoverBackgroundImage;
            }
            else if (_forceState == ButtonState.Pressed)
            {
                base.BackgroundImage = PressedBackgroundImage;
            }
            else
            {
                base.BackgroundImage = BackgroundImage;
            }

            base.DrawBackground(destImage);


            if (_animationRequested)
            {
                byte originalOpacity = Opacity;

                HoverAlpha += HoverSpeed;

                if (HoverAlpha < 0 || HoverAlpha > 255)
                {
                    HoverAlpha = HoverEnd;
                }

                Opacity = (byte)HoverAlpha;

                if (_hoverState == ButtonState.Hover)
                {
                    base.BackgroundImage = HoverBackgroundImage;
                }
                else if (_hoverState == ButtonState.Pressed)
                {
                    base.BackgroundImage = PressedBackgroundImage;
                }

                base.DrawBackground(destImage);

                if (HoverAlpha == HoverEnd)
                {
                    Parent.EndAnimationLoopRequest();
                    _animationRequested = false;
                }

                Opacity = originalOpacity;
            }

            base.BackgroundImage = BackgroundImage;
        }
Пример #6
0
        protected override void DrawBackground(ImageWithDeviceContext destImage)
        {
            DrawColorSchemeOverlay(destImage);

            MaskOut(destImage);

            base.DrawBackground(destImage);

            DrawReflection(BackgroundReflectionImage, destImage, Bounds, Activated, 150, Settings.Settings.ReflectionSpeed);
        }
Пример #7
0
        protected virtual void DrawBackground(ImageWithDeviceContext destImage)
        {
            if (BackgroundImage == null)
            {
                return;
            }

            ImageRenderer.StretchImageWithOutMargin(destImage, RealX, RealY, Size.Width, Size.Height,
                                                    BackgroundImage, 0, BackgroundImage.Width, BackgroundImage.Height,
                                                    BackgroundImageStretchExcludeMargin, Opacity);
        }
Пример #8
0
        protected virtual void Draw(ImageWithDeviceContext destImage)
        {
            if (IsUpdateLocked() || !Visible)
            {
                return;
            }

            DrawBackground(destImage);

            DrawControls(destImage);
        }
Пример #9
0
 protected virtual void DrawControls(ImageWithDeviceContext destImage)
 {
     try
     {
         foreach (LayeredControl c in Controls)
         {
             c.Draw(destImage);
         }
     }
     catch (Exception)
     {
     }
 }
Пример #10
0
        private void DrawImage(IDeviceContext destImage, LayeredPopupMenuItem item, Rectangle bounds, bool hovered)
        {
            ImageWithDeviceContext itemImage = ItemBackgroundImage;

            if (item.Checked || hovered)
            {
                itemImage = ItemHoveredBackgroundImage;
            }

            ImageRenderer.StretchImageWithOutMargin(destImage, bounds.X, bounds.Y, bounds.Width, bounds.Height,
                                                    itemImage, 0, itemImage.Width, itemImage.Height,
                                                    StretchMargin, 255);
        }
Пример #11
0
        private void DrawColorSchemeOverlay(ImageWithDeviceContext destImage)
        {
//            ImageRenderer.StretchImage(destImage, BackgroundColorImageOverlay, Width, Height, ContentRect, !Settings.Settings.Transparency);
            using (var g = Graphics.FromHdc(destImage.GetHdc()))
            {
                Rectangle bounds = new Rectangle(Point.Empty, Size);
                bounds.X       = ContentPadding.Left;
                bounds.Y       = ContentPadding.Top;
                bounds.Width  -= ContentPadding.Right + ContentPadding.Left;
                bounds.Height -= ContentPadding.Bottom + ContentPadding.Top;

                g.FillRectangle(BackgroundColorBrushOverlay, bounds);
            }
        }
Пример #12
0
        protected override void DrawBackground(ImageWithDeviceContext destImage)
        {
            base.DrawBackground(destImage);

            if (Text.Length > 0)
            {
                Rectangle textBounds = Bounds;

                TitleRenderer.DrawText(Text, destImage,
                                       new Point(RealX, RealY), textBounds.Size,
                                       Opacity, TextColorBrush,
                                       StringFormat, Font);
            }
        }
Пример #13
0
        private static ImageWithDeviceContext[] ExtractFramesInImage(ImageWithDeviceContext image, int frameHeight)
        {
            if (frameHeight == 0)
            {
                return(new ImageWithDeviceContext[0]);
            }

            int frames = image.Height / frameHeight;

            var states = new ImageWithDeviceContext[frames];

            for (int i = 0; i < frames; i++)
            {
                states[i] = new ImageWithDeviceContext(new Size(image.Width, frameHeight));
                states[i].BitBltImage(image, new Point(0, frameHeight * i), Point.Empty, new Size(image.Width, frameHeight));
            }
            return(states);
        }
Пример #14
0
        private void DrawReflection(ImageWithDeviceContext ReflectionImage, ImageWithDeviceContext destImage, Rectangle WindowBounds, bool Active, byte InActiveReflection, double RefSpeed)
        {
            if (ReflectionImage == null)
            {
                return;
            }

            Point srcLocation  = new Point(ContentPadding.Left + (int)(WindowBounds.X / RefSpeed), ContentPadding.Top + (int)(WindowBounds.Y / RefSpeed));
            Point destLocation = new Point(ContentPadding.Left, ContentPadding.Top);

            if (srcLocation.X < 0)
            {
                destLocation.X = (srcLocation.X * -1) + ContentPadding.Left;
                srcLocation.X  = 0;
            }
            if (srcLocation.Y < 0)
            {
                destLocation.Y = (srcLocation.Y * -1) + ContentPadding.Top;
                srcLocation.Y  = 0;
            }

            //>> 1 change the size of the reflection image to the max window track size
            //LeftPositionOnScreen >>>>>>>> WindowScreen
            //LeftPositionOnImage  >>>>>>>> MaxWindowTrackWidth

            Size reflectionSize = WindowBounds.Size;

            reflectionSize.Width  -= (ContentPadding.Right + destLocation.X);
            reflectionSize.Height -= (ContentPadding.Bottom + destLocation.Y);

            //BitBlt(ReflectionImage.Buffer.Image.DC, 0, 0, _
            //                ReflectionSize.Width, ReflectionSize.Height, _
            //           ReflectionImage.Image.DC, SrcLocation.X, SrcLocation.Y, _
            //                CopyPixelOperation.SourceCopy)

            //ReflectionImage.MaskOut(ReflectionImage.Buffer.Image, Active, WindowBounds.Width)

            //AlphaBlend(BorderImage.Buffer.Image.DC, DestLocation.X, DestLocation.Y, _
            //                ReflectionSize.Width, ReflectionSize.Height, _
            //           ReflectionImage.Buffer.Image.DC, 0, 0, _
            //                ReflectionSize.Width, ReflectionSize.Height, Blend)

            destImage.AlphaBlendImage(ReflectionImage, srcLocation, destLocation, reflectionSize, Active ? (byte)255 : InActiveReflection);
        }
Пример #15
0
        protected override void Draw(ImageWithDeviceContext destImage)
        {
            try {
                if (IconBitmap != null)
                {
                    Rectangle drawBounds = default(Rectangle);
                    drawBounds.Size = Size;

                    _iconBuffer.Graphics.Clear(Color.Transparent);
                    _iconBuffer.Graphics.DrawImage(IconBitmap, drawBounds);

                    drawBounds.Location = new Point(RealX, RealY);
                    Graphics g = Graphics.FromHdc(destImage.GetHdc());
                    g.DrawImage(_iconBuffer.Image, drawBounds);
                    g.Dispose();
                    destImage.ReleaseHdc();
                }
            } catch (Exception) {
            }
        }
Пример #16
0
 protected virtual void DrawBackground(ImageWithDeviceContext bufferImage)
 {
     ImageRenderer.StretchImageWithOutMargin(bufferImage, 0, 0, Width, Height, BackgroundImage, 0,
                                             BackgroundImage.Width, BackgroundImage.Height, StretchMargin, 255);
 }
Пример #17
0
 private void MaskOut(ImageWithDeviceContext destImage)
 {
     ImageRenderer.MaskOutCorners(destImage,
                                 Width, SkinElement.FrameSize, SkinElement.MaskOutBitmap,
                                 SkinElement.StretchPadding, SkinElement.MaskOutColor, SkinElement.GetStateYPosition(Activated));
 }
Пример #18
0
        private void DrawReflection(ImageWithDeviceContext ReflectionImage, ImageWithDeviceContext destImage, Rectangle WindowBounds, bool Active, byte InActiveReflection, double RefSpeed)
        {
            if (ReflectionImage == null)
                return;

            Point srcLocation = new Point(ContentPadding.Left + (int)(WindowBounds.X / RefSpeed), ContentPadding.Top + (int)(WindowBounds.Y / RefSpeed));
            Point destLocation = new Point(ContentPadding.Left, ContentPadding.Top);

            if (srcLocation.X < 0)
            {
                destLocation.X = (srcLocation.X * -1) + ContentPadding.Left;
                srcLocation.X = 0;
            }
            if (srcLocation.Y < 0)
            {
                destLocation.Y = (srcLocation.Y * -1) + ContentPadding.Top;
                srcLocation.Y = 0;
            }

            //>> 1 change the size of the reflection image to the max window track size
            //LeftPositionOnScreen >>>>>>>> WindowScreen
            //LeftPositionOnImage  >>>>>>>> MaxWindowTrackWidth

            Size reflectionSize = WindowBounds.Size;
            reflectionSize.Width -= (ContentPadding.Right + destLocation.X);
            reflectionSize.Height -= (ContentPadding.Bottom + destLocation.Y);

            //BitBlt(ReflectionImage.Buffer.Image.DC, 0, 0, _
            //                ReflectionSize.Width, ReflectionSize.Height, _
            //           ReflectionImage.Image.DC, SrcLocation.X, SrcLocation.Y, _
            //                CopyPixelOperation.SourceCopy)

            //ReflectionImage.MaskOut(ReflectionImage.Buffer.Image, Active, WindowBounds.Width)

            //AlphaBlend(BorderImage.Buffer.Image.DC, DestLocation.X, DestLocation.Y, _
            //                ReflectionSize.Width, ReflectionSize.Height, _
            //           ReflectionImage.Buffer.Image.DC, 0, 0, _
            //                ReflectionSize.Width, ReflectionSize.Height, Blend)

            destImage.AlphaBlendImage(ReflectionImage, srcLocation, destLocation, reflectionSize, Active ? (byte)255 : InActiveReflection);
        }
Пример #19
0
        private void DrawColorSchemeOverlay(ImageWithDeviceContext destImage)
        {
            //            ImageRenderer.StretchImage(destImage, BackgroundColorImageOverlay, Width, Height, ContentRect, !Settings.Settings.Transparency);
            using (var g = Graphics.FromHdc(destImage.GetHdc()))
            {
                Rectangle bounds = new Rectangle(Point.Empty, Size);
                bounds.X = ContentPadding.Left;
                bounds.Y = ContentPadding.Top;
                bounds.Width -= ContentPadding.Right + ContentPadding.Left;
                bounds.Height -= ContentPadding.Bottom + ContentPadding.Top;

                g.FillRectangle(BackgroundColorBrushOverlay, bounds);
            }
        }
Пример #20
0
        protected override void DrawBackground(ImageWithDeviceContext destImage)
        {
            DrawColorSchemeOverlay(destImage);

                MaskOut(destImage);

                base.DrawBackground(destImage);

                DrawReflection(BackgroundReflectionImage, destImage, Bounds, Activated, 150, Settings.Settings.ReflectionSpeed);
        }
Пример #21
0
 private void MaskOut(ImageWithDeviceContext destImage)
 {
     ImageRenderer.MaskOutCorners(destImage,
                                  Width, SkinElement.FrameSize, SkinElement.MaskOutBitmap,
                                  SkinElement.StretchPadding, SkinElement.MaskOutColor, SkinElement.GetStateYPosition(Activated));
 }
Пример #22
0
        public SkinElement GetSkinElement(string ID)
        {
            if (!Exists(ID)) return null;

            var element = new SkinElement();

            element.ID = ID;

            if (_skinIniFile.Exists(ID, SkinKeys.ImageFile))
            {
                var imageFile = GetImageFile(ID);
                var framesNumber = _skinIniFile.GetValue(ID, SkinKeys.FramesNumber, 2);

                var image = new ImageWithDeviceContext(imageFile);
                element.Frames = ExtractFramesInImage(image, image.Height / framesNumber);

                var directoryPath = Path.GetDirectoryName(imageFile);
                if (directoryPath != null)
                {
                    var fileName = Path.GetFileNameWithoutExtension(imageFile) + "MaskOut.png";
                    fileName = Path.Combine(directoryPath, fileName);

                    if (File.Exists(fileName))
                    {
                        element.MaskOutBitmap = new ImageWithDeviceContext(fileName);
                    }
                }
            }

            if (_skinIniFile.Exists(ID, SkinKeys.Sizing)) element.StretchPadding = GetRect(ID, SkinKeys.Sizing);
            if (_skinIniFile.Exists(ID, SkinKeys.Content)) element.ContentPadding = GetRect(ID, SkinKeys.Content);

            if (_skinIniFile.Exists(ID, SkinKeys.Edges)) element.NormalEdges = GetRect(ID, SkinKeys.Edges);
            if (_skinIniFile.Exists(ID, SkinKeys.MaxEdges)) element.MaxEdges = GetRect(ID, SkinKeys.MaxEdges);
            if (_skinIniFile.Exists(ID, SkinKeys.ElementAlignment)) element.ElementAlign = GetAlignment(ID, SkinKeys.ElementAlignment);

            if (_skinIniFile.Exists(ID, SkinKeys.BackColor)) element.BackColor = GetColor(ID, SkinKeys.BackColor);

            if (_skinIniFile.Exists(ID, SkinKeys.TextColor)) element.NormalTextBrush = GetColorBrush(ID, SkinKeys.TextColor);
            if (_skinIniFile.Exists(ID, SkinKeys.MaxTextColor)) element.MaxTextBrush = GetColorBrush(ID, SkinKeys.MaxTextColor);
            if (_skinIniFile.Exists(ID, SkinKeys.TextAlignment)) element.TextAlign = GetAlignment(ID, SkinKeys.TextAlignment);

            if (_skinIniFile.Exists(ID, SkinKeys.Font))
            {
                element.Font = GetFont(ID);
                element.TextFormat = new StringFormat(StringFormat.GenericTypographic)
                {
                    FormatFlags = StringFormatFlags.NoWrap,
                    Trimming = StringTrimming.EllipsisCharacter
                };
            }

            return element;
        }
Пример #23
0
        public SkinElement GetSkinElement(string ID)
        {
            if (!Exists(ID))
            {
                return(null);
            }

            var element = new SkinElement();

            element.ID = ID;

            if (_skinIniFile.Exists(ID, SkinKeys.ImageFile))
            {
                var imageFile    = GetImageFile(ID);
                var framesNumber = _skinIniFile.GetValue(ID, SkinKeys.FramesNumber, 2);

                var image = new ImageWithDeviceContext(imageFile);
                element.Frames = ExtractFramesInImage(image, image.Height / framesNumber);

                var directoryPath = Path.GetDirectoryName(imageFile);
                if (directoryPath != null)
                {
                    var fileName = Path.GetFileNameWithoutExtension(imageFile) + "MaskOut.png";
                    fileName = Path.Combine(directoryPath, fileName);

                    if (File.Exists(fileName))
                    {
                        element.MaskOutBitmap = new ImageWithDeviceContext(fileName);
                    }
                }
            }

            if (_skinIniFile.Exists(ID, SkinKeys.Sizing))
            {
                element.StretchPadding = GetRect(ID, SkinKeys.Sizing);
            }
            if (_skinIniFile.Exists(ID, SkinKeys.Content))
            {
                element.ContentPadding = GetRect(ID, SkinKeys.Content);
            }

            if (_skinIniFile.Exists(ID, SkinKeys.Edges))
            {
                element.NormalEdges = GetRect(ID, SkinKeys.Edges);
            }
            if (_skinIniFile.Exists(ID, SkinKeys.MaxEdges))
            {
                element.MaxEdges = GetRect(ID, SkinKeys.MaxEdges);
            }
            if (_skinIniFile.Exists(ID, SkinKeys.ElementAlignment))
            {
                element.ElementAlign = GetAlignment(ID, SkinKeys.ElementAlignment);
            }

            if (_skinIniFile.Exists(ID, SkinKeys.BackColor))
            {
                element.BackColor = GetColor(ID, SkinKeys.BackColor);
            }

            if (_skinIniFile.Exists(ID, SkinKeys.TextColor))
            {
                element.NormalTextBrush = GetColorBrush(ID, SkinKeys.TextColor);
            }
            if (_skinIniFile.Exists(ID, SkinKeys.MaxTextColor))
            {
                element.MaxTextBrush = GetColorBrush(ID, SkinKeys.MaxTextColor);
            }
            if (_skinIniFile.Exists(ID, SkinKeys.TextAlignment))
            {
                element.TextAlign = GetAlignment(ID, SkinKeys.TextAlignment);
            }

            if (_skinIniFile.Exists(ID, SkinKeys.Font))
            {
                element.Font       = GetFont(ID);
                element.TextFormat = new StringFormat(StringFormat.GenericTypographic)
                {
                    FormatFlags = StringFormatFlags.NoWrap,
                    Trimming    = StringTrimming.EllipsisCharacter
                };
            }

            return(element);
        }
Пример #24
0
        private static ImageWithDeviceContext[] ExtractFramesInImage(ImageWithDeviceContext image, int frameHeight)
        {
            if (frameHeight == 0)
                return new ImageWithDeviceContext[0];

            int frames = image.Height / frameHeight;

            var states = new ImageWithDeviceContext[frames];

            for (int i = 0; i < frames; i++)
            {
                states[i] = new ImageWithDeviceContext(new Size(image.Width, frameHeight));
                states[i].BitBltImage(image, new Point(0, frameHeight * i), Point.Empty, new Size(image.Width, frameHeight));
            }
            return states;
        }