internal static void PaintBackgroundImage(Graphics g, Rectangle targetRect, Image backgroundImage, eBackgroundImagePosition backgroundImagePosition, int backgroundImageAlpha) { if (backgroundImage == null) return; Rectangle r = targetRect; System.Drawing.Imaging.ImageAttributes imageAtt = null; if (backgroundImageAlpha != 255) { float[][] matrixItems ={ new float[] {1, 0, 0, 0, 0}, new float[] {0, 1, 0, 0, 0}, new float[] {0, 0, 1, 0, 0}, new float[] {0, 0, 0, (float)backgroundImageAlpha/255, 0}, new float[] {0, 0, 0, 0, 1}}; System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(matrixItems); //System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(); //colorMatrix.Matrix33 = 255 - backgroundImageAlpha; imageAtt = new System.Drawing.Imaging.ImageAttributes(); imageAtt.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); } switch (backgroundImagePosition) { case eBackgroundImagePosition.Stretch: { if (imageAtt != null) g.DrawImage(backgroundImage, r, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt); else g.DrawImage(backgroundImage, r, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel); break; } case eBackgroundImagePosition.CenterLeft: case eBackgroundImagePosition.CenterRight: { Rectangle destRect = new Rectangle(r.X, r.Y, backgroundImage.Width, backgroundImage.Height); if (r.Width > backgroundImage.Width && backgroundImagePosition == eBackgroundImagePosition.CenterRight) destRect.X += (r.Width - backgroundImage.Width); destRect.Y += (r.Height - backgroundImage.Height) / 2; if (imageAtt != null) g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt); else g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel); break; } case eBackgroundImagePosition.Center: { Rectangle destRect = new Rectangle(r.X, r.Y, backgroundImage.Width, backgroundImage.Height); if (r.Width > backgroundImage.Width) destRect.X += (r.Width - backgroundImage.Width) / 2; if (r.Height > backgroundImage.Height) destRect.Y += (r.Height - backgroundImage.Height) / 2; if (imageAtt != null) g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt); else g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel); break; } case eBackgroundImagePosition.TopLeft: case eBackgroundImagePosition.TopRight: case eBackgroundImagePosition.BottomLeft: case eBackgroundImagePosition.BottomRight: { Rectangle destRect = new Rectangle(r.X, r.Y, backgroundImage.Width, backgroundImage.Height); if (backgroundImagePosition == eBackgroundImagePosition.TopRight) destRect.X = r.Right - backgroundImage.Width; else if (backgroundImagePosition == eBackgroundImagePosition.BottomLeft) destRect.Y = r.Bottom - backgroundImage.Height; else if (backgroundImagePosition == eBackgroundImagePosition.BottomRight) { destRect.Y = r.Bottom - backgroundImage.Height; destRect.X = r.Right - backgroundImage.Width; } if (imageAtt != null) g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt); else g.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel); break; } case eBackgroundImagePosition.Tile: { if (imageAtt != null) { if (r.Width > backgroundImage.Width || r.Height > backgroundImage.Height) { int x = r.X, y = r.Y; while (y < r.Bottom) { while (x < r.Right) { Rectangle destRect = new Rectangle(x, y, backgroundImage.Width, backgroundImage.Height); if (destRect.Right > r.Right) destRect.Width = destRect.Width - (destRect.Right - r.Right); if (destRect.Bottom > r.Bottom) destRect.Height = destRect.Height - (destRect.Bottom - r.Bottom); g.DrawImage(backgroundImage, destRect, 0, 0, destRect.Width, destRect.Height, GraphicsUnit.Pixel, imageAtt); x += backgroundImage.Width; } x = r.X; y += backgroundImage.Height; } } else { g.DrawImage(backgroundImage, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAtt); } } else { SmoothingMode sm = g.SmoothingMode; g.SmoothingMode = SmoothingMode.None; using (TextureBrush brush = new TextureBrush(backgroundImage)) { brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; g.FillRectangle(brush, r); } g.SmoothingMode = sm; } break; } } }
internal void ApplyStyle(ItemStyle style) { if(style==null) return; m_Alignment=style.Alignment; if(!style.BackColor1.IsEmpty) m_BackColor1=style.BackColor1; if(!style.BackColor2.IsEmpty) m_BackColor2=style.BackColor2; if(style.BackgroundImage!=null) m_BackgroundImage=style.BackgroundImage; if(style.BackgroundImageAlpha!=255) m_BackgroundImageAlpha=style.BackgroundImageAlpha; if(style.BackgroundImagePosition!=eBackgroundImagePosition.Stretch) m_BackgroundImagePosition=style.BackgroundImagePosition; if(style.Border!=eBorderType.None) m_Border=style.Border; if(style.BorderDashStyle!=DashStyle.Solid) m_BorderDashStyle=style.BorderDashStyle; if(!style.BorderColor.IsEmpty) m_BorderColor=style.BorderColor; if(style.BorderSide!=DEFAULT_BORDERSIDE) m_BorderSide=style.BorderSide; if(style.BorderWidth!=1) m_BorderWidth=style.BorderWidth; if(style.Font!=null) m_Font=style.Font; if(!style.ForeColor.IsEmpty) m_ForeColor=style.ForeColor; if(style.LineAlignment!=StringAlignment.Center) m_LineAlignment=style.LineAlignment; if(style.TextTrimming!=StringTrimming.EllipsisCharacter) m_TextTrimming=style.TextTrimming; if(style.WordWrap!=false) m_WordWrap=style.WordWrap; if(style.MarginBottom!=0) m_MarginBottom=style.MarginBottom; if(style.MarginLeft!=0) m_MarginLeft=style.MarginLeft; if(style.MarginRight!=0) m_MarginRight=style.MarginRight; if(style.MarginTop!=0) m_MarginTop=style.MarginTop; if(style.CornerType!=eCornerType.Square) m_CornerType=style.CornerType; if(style.CornerDiameter!=DEFAULT_CORNER_DIAMETER) m_CornerDiameter=style.CornerDiameter; if (style.VerticalText) m_VerticalText = style.VerticalText; if (!style.UseMnemonic) _UseMnemonic = style.UseMnemonic; }
internal void Deserialize(System.Xml.XmlElement styleElement) { m_BackColor1=ColorEx.Empty; if(styleElement.HasAttribute("bc1")) { m_BackColor1.Color=BarFunctions.ColorFromString(styleElement.GetAttribute("bc1")); m_BackColor1.Alpha=System.Xml.XmlConvert.ToByte(styleElement.GetAttribute("bc1a")); } else if(styleElement.HasAttribute("bc1csp")) m_BackColor1.ColorSchemePart=(eColorSchemePart)Enum.Parse(typeof(eColorSchemePart),styleElement.GetAttribute("bc1csp")); m_BackColor2=ColorEx.Empty; if(styleElement.HasAttribute("bc2")) { m_BackColor2.Color=BarFunctions.ColorFromString(styleElement.GetAttribute("bc2")); m_BackColor2.Alpha=System.Xml.XmlConvert.ToByte(styleElement.GetAttribute("bc2a")); } else if(styleElement.HasAttribute("bc2csp")) m_BackColor2.ColorSchemePart=(eColorSchemePart)Enum.Parse(typeof(eColorSchemePart),styleElement.GetAttribute("bc2csp")); m_ForeColor=ColorEx.Empty; if(styleElement.HasAttribute("fc")) { m_ForeColor.Color=BarFunctions.ColorFromString(styleElement.GetAttribute("fc")); m_ForeColor.Alpha=System.Xml.XmlConvert.ToByte(styleElement.GetAttribute("fca")); } else if(styleElement.HasAttribute("fccsp")) m_ForeColor.ColorSchemePart=(eColorSchemePart)Enum.Parse(typeof(eColorSchemePart),styleElement.GetAttribute("fccsp")); m_BorderColor=ColorEx.Empty; if(styleElement.HasAttribute("borderc")) { m_BorderColor.Color=BarFunctions.ColorFromString(styleElement.GetAttribute("borderc")); m_BorderColor.Alpha=System.Xml.XmlConvert.ToByte(styleElement.GetAttribute("borderca")); } else if(styleElement.HasAttribute("bordercsp")) m_BorderColor.ColorSchemePart=(eColorSchemePart)Enum.Parse(typeof(eColorSchemePart),styleElement.GetAttribute("bordercsp")); m_GradientAngle=System.Xml.XmlConvert.ToInt16(styleElement.GetAttribute("ga")); // Load font information if it exists m_Font=null; if(styleElement.HasAttribute("fontname")) { string FontName=styleElement.GetAttribute("fontname"); float FontSize=System.Xml.XmlConvert.ToSingle(styleElement.GetAttribute("fontemsize")); System.Drawing.FontStyle FontStyle=(System.Drawing.FontStyle)System.Xml.XmlConvert.ToInt32(styleElement.GetAttribute("fontstyle")); try { m_Font=new Font(FontName,FontSize,FontStyle); } catch(Exception) { m_Font=null; } } // Load Image m_BackgroundImage=null; foreach(System.Xml.XmlElement xmlElem in styleElement.ChildNodes) { if(xmlElem.Name=="backimage") { m_BackgroundImage=BarFunctions.DeserializeImage(xmlElem); m_BackgroundImagePosition=(eBackgroundImagePosition)System.Xml.XmlConvert.ToInt32(xmlElem.GetAttribute("pos")); m_BackgroundImageAlpha=System.Xml.XmlConvert.ToByte(xmlElem.GetAttribute("alpha")); } } m_WordWrap=false; if(styleElement.HasAttribute("wordwrap")) m_WordWrap=System.Xml.XmlConvert.ToBoolean(styleElement.GetAttribute("wordwrap")); m_Alignment=StringAlignment.Near; if(styleElement.HasAttribute("align")) m_Alignment=(StringAlignment)System.Xml.XmlConvert.ToInt32(styleElement.GetAttribute("align")); m_LineAlignment=StringAlignment.Center; if(styleElement.HasAttribute("valign")) m_LineAlignment=(StringAlignment)System.Xml.XmlConvert.ToInt32(styleElement.GetAttribute("valign")); m_TextTrimming=StringTrimming.EllipsisCharacter; if(styleElement.HasAttribute("trim")) m_TextTrimming=(StringTrimming)System.Xml.XmlConvert.ToInt32(styleElement.GetAttribute("trim")); m_Border=eBorderType.None; if(styleElement.HasAttribute("border")) m_Border=(eBorderType)System.Xml.XmlConvert.ToInt32(styleElement.GetAttribute("border")); m_BorderWidth=1; if(styleElement.HasAttribute("borderw")) m_BorderWidth=System.Xml.XmlConvert.ToInt32(styleElement.GetAttribute("borderw")); m_CornerType=eCornerType.Square; if(styleElement.HasAttribute("cornertype")) m_CornerType=(eCornerType)System.Xml.XmlConvert.ToInt32(styleElement.GetAttribute("cornertype")); m_CornerDiameter=DEFAULT_CORNER_DIAMETER; if(styleElement.HasAttribute("cornerdiameter")) m_CornerDiameter=System.Xml.XmlConvert.ToInt32(styleElement.GetAttribute("cornerdiameter")); }
public void Deserialize(System.Xml.XmlElement xmlThisBar, ItemSerializationContext context) { m_BarDefinitionLoading = true; m_IgnoreAnimation = true; try { LoadCommonProperties(xmlThisBar); this.BackgroundImage = null; foreach (System.Xml.XmlElement xmlElem in xmlThisBar.ChildNodes) { switch (xmlElem.Name) { case "items": { foreach (System.Xml.XmlElement xmlItem in xmlElem.ChildNodes) { BaseItem objItem = context.CreateItemFromXml(xmlItem); m_ItemContainer.SubItems.Add(objItem); context.ItemXmlElement = xmlItem; objItem.Deserialize(context); } break; } case "colorscheme": { m_ColorScheme.Deserialize(xmlElem); break; } case "backimage": { this.BackgroundImage = BarFunctions.DeserializeImage(xmlElem); m_BackgroundImagePosition = (eBackgroundImagePosition)System.Xml.XmlConvert.ToInt32(xmlElem.GetAttribute("pos")); m_BackgroundImageAlpha = System.Xml.XmlConvert.ToByte(xmlElem.GetAttribute("alpha")); break; } } } if ((eDockSide)System.Xml.XmlConvert.ToInt32(xmlThisBar.GetAttribute("dockside")) == eDockSide.None) { // Try to load position if (xmlThisBar.HasAttribute("fpos")) { string s = xmlThisBar.GetAttribute("fpos"); string[] arr = s.Split(','); if (arr.Length == 4) { Rectangle r = new Rectangle(System.Xml.XmlConvert.ToInt32(arr[0]), System.Xml.XmlConvert.ToInt32(arr[1]), System.Xml.XmlConvert.ToInt32(arr[2]), System.Xml.XmlConvert.ToInt32(arr[3])); m_FloatingRect = r; } } if (!System.Xml.XmlConvert.ToBoolean(xmlThisBar.GetAttribute("visible")) || xmlThisBar.HasAttribute("autohide") && System.Xml.XmlConvert.ToBoolean(xmlThisBar.GetAttribute("autohide"))) m_LoadingHideFloating = true; } if (xmlThisBar.HasAttribute("seldocktab")) { int iTab = System.Xml.XmlConvert.ToInt32(xmlThisBar.GetAttribute("seldocktab")); if (iTab >= 0 && iTab < m_ItemContainer.SubItems.Count) { foreach (BaseItem dockItem in m_ItemContainer.SubItems) dockItem.Displayed = false; m_ItemContainer.SubItems[iTab].Displayed = true; } } // Last Thing to do so it is docked properly m_DockLine = System.Xml.XmlConvert.ToInt32(xmlThisBar.GetAttribute("dockline")); if (m_ItemContainer.LayoutType == eLayoutType.DockContainer) RefreshDockTab(true); this.DockSide = (eDockSide)System.Xml.XmlConvert.ToInt32(xmlThisBar.GetAttribute("dockside")); if (m_LoadingHideFloating) m_LoadingHideFloating = false; if (xmlThisBar.HasAttribute("autohide") && context._DesignerHost == null) { base.Visible = false; if (m_ItemContainer.MinWidth > 0) this.Width = m_ItemContainer.MinWidth; if (m_ItemContainer.MinHeight > 0) this.Height = m_ItemContainer.MinHeight; this.AutoHide = true; m_LastDockSiteInfo.DockedWidth = m_ItemContainer.MinWidth; m_LastDockSiteInfo.DockedHeight = m_ItemContainer.MinHeight; } else { if (context._DesignerHost == null) this.Visible = System.Xml.XmlConvert.ToBoolean(xmlThisBar.GetAttribute("visible")); else this.Visible = true; } } finally { m_BarDefinitionLoading = false; } m_TabsRearranged = false; SetupAccessibility(); }