Example #1
0
        protected void DrawBackgroundImage(PaintEventArgs e, int alpha, string suffix)
        {
            int width = Convert.ToInt32(Math.Ceiling(Width / 16f) * 16);

            using (Bitmap image = (Bitmap)GUIUtilities.VariableSizeImageRoundButton(BackgroundImagePrefix + suffix, "", width))
            {
                if (image == null)
                {
                    if (!this.DesignMode)
                    {
                        Utilities.LogSubError("RoundButton::DrawBackgroundImage failed to load image for suffix = " + suffix);
                    }
                    return;
                }
                if (alpha == 255)
                {
                    e.Graphics.DrawImage(image, new Rectangle(0, 0, Width, Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
                }
                else
                {
                    using (System.Drawing.Imaging.ImageAttributes objAttr = GUIUtilities.GetImageAttrForAlpha(alpha))
                    {
                        e.Graphics.DrawImage(image, new Rectangle(0, 0, Width, Height), objAttr);
                    }
                }
            }
        }
Example #2
0
 protected override void InternalDraw(Canvas gr, DrawResources resources)
 {
     if (resources.Highlight)
     {
         using (var highlight = resources.Graphics.CreateStroke(CurrentHighlightColour, resources.HIGHLIGHTEXTRAWIDTH))
         {
             gr.DrawLines(Vertices, highlight);
             gr.DrawLine(Vertices[3], Vertices[0], highlight);
             //gr.DrawRectangleF(pnHighlight, m_Bounds)
         }
     }
     else
     {
         RectangleF source = new RectangleF(PointF.Empty, m_ImageSize);
         if (!m_Data.Content.IsLightweight && !m_Data.Content.MemoryImage.IsSVG)
         {                // can't remember why, but it was important to specify pixles - but can only apply to actual .net images (not resources or SVG)
             var temp = GraphicsUnit.Pixel;
             source = m_Data.Content.GetNetImage().GetBounds(ref temp);
         }
         if (m_Flip.Width == -1)
         {
             source.X    += m_ImageSize.Width;
             source.Width = -m_ImageSize.Width;
         }
         if (m_Flip.Height == -1)
         {
             source.Y     += m_ImageSize.Height;
             source.Height = -m_ImageSize.Height;
         }
         if (m_Data.Failed)
         {
             using (var red = resources.Graphics.CreateStroke(Color.Red))
             {
                 gr.DrawLine(Vertices[0], Vertices[2], red);
                 gr.DrawLine(Vertices[1], Vertices[2], red);
             }
         }
         else if (resources.FillAlpha < 1150 && !Utilities.Low_Graphics_Safe())
         {
             gr.DrawImage(m_Data.Content.MemoryImage, new[] { Vertices[0], Vertices[1], Vertices[3] }, source, GUIUtilities.GetImageAttrForAlpha(resources.FillAlpha));
         }
         else if (IsOrthogonal())
         {
             //Faster to use this version
             gr.DrawImage(m_Data.Content.MemoryImage, Bounds, source);
         }
         else
         {
             gr.DrawImage(m_Data.Content.MemoryImage, new[] { Vertices[0], Vertices[1], Vertices[3] }, source);
         }
     }
 }