createGradientBrush() { bool reverse; reverse = MiscFunctions.GetRightToLeftValue(this.m_buddyFrame); return(this.m_buddyFrame.CaptionBlend.GetLinearGradientBrush(new Rectangle(0, this.Height - this.m_captionHeight, this.Width, this.m_captionHeight), reverse)); }
//=------------------------------------------------------------------= // drawText //=------------------------------------------------------------------= /// <summary> /// Draws teh text for the caption bar. /// </summary> /// /// <param name="g"> /// Where to draw. /// </param> /// /// <param name="in_imgWidth"> /// Width of the image in the caption bar (or zero). /// </param> /// private void drawText(Graphics g, int in_imgWidth) { RectangleF captionTextRect; Color textColor; bool reverse; StringFormat sf; int top; // // No Text? E-Z. // if (string.IsNullOrEmpty(this.m_buddyFrame.Text)) { return; } reverse = MiscFunctions.GetRightToLeftValue(this.m_buddyFrame); top = this.Height - this.m_captionHeight; // // get the bounding rect for the text // if (reverse == false) { captionTextRect = new RectangleF(in_imgWidth + 1, top, this.Width - 6 - COLLAPSE_BUTTON_DIAMETER - in_imgWidth - 1, this.m_captionHeight); } else { captionTextRect = new RectangleF(6 + COLLAPSE_BUTTON_DIAMETER, this.Height - this.m_captionHeight, this.Width - in_imgWidth - 6 - COLLAPSE_BUTTON_DIAMETER, this.m_captionHeight); } // // align the text vertically centered, and then RTL as appropriate // sf = new StringFormat(); sf.FormatFlags = StringFormatFlags.NoWrap; sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; if (MiscFunctions.GetRightToLeftValue(this.m_buddyFrame)) { sf.FormatFlags = sf.FormatFlags | StringFormatFlags.DirectionRightToLeft; } if (this.m_hovering == false) { textColor = this.m_buddyFrame.ForeColor; } else { textColor = Color.Blue; } g.DrawString(this.m_buddyFrame.Text, this.m_buddyFrame.Font, new SolidBrush(textColor), captionTextRect, sf); }
//=--------------------------------------------------------------= // blendFillFromString //=--------------------------------------------------------------= /// <summary> /// Given a string that we serialized out using /// blendFillToString, this function attempts to parse in the /// given input and regenerate a BlendFill object. /// </summary> /// /// <param name="in_bf"> /// What to parse back into a BlendFill. /// </param> /// /// <param name="in_culture"> /// What cultural information to use for this parse. /// </param> /// /// <returns> /// A BlendFill representing the data from the string. /// </returns> /// private static BlendFill blendFillFromString ( string in_bf, CultureInfo in_culture ) { TypeConverter tcc; BlendStyle style; string[] pieces; Color c1, c2; string sep; // // Get the various type converters and culture info we need // if (in_culture == null) { in_culture = CultureInfo.CurrentCulture; } sep = in_culture.TextInfo.ListSeparator; tcc = TypeDescriptor.GetConverter(typeof(Color)); // // Explode the string. Unfortunately, we can't use // String.Split() since we need to preserve ()s around // the colors. // pieces = MiscFunctions.ExplodePreservingSubObjects(in_bf, sep, '(', ')'); if (pieces.Length != 3) { throw new ArgumentException(TaskPaneMain.GetResourceManager().GetString("excBlendFillParse"), "value"); } style = parseBlendStyle(pieces[0]); c1 = (Color)tcc.ConvertFromString(pieces[1]); c2 = (Color)tcc.ConvertFromString(pieces[2]); if ((int)style == -1 || c1.Equals(Color.Empty) || c2.Equals(Color.Empty)) { throw new ArgumentException(TaskPaneMain.GetResourceManager().GetString("excBlendFillParse"), "value"); } return(new BlendFill(style, c1, c2)); }
//=------------------------------------------------------------------= // drawIcon //=------------------------------------------------------------------= // // // Parameters: // Graphics - [in] Graphics Object with which to draw. // // Returns: // Integer - width of the image drawn. /// <summary> /// Draws the Icon/Image for this CaptionBar, provided there /// is one to draw. /// </summary> /// /// <param name="g"> /// Where to draw. /// </param> /// /// <returns> /// Width of the image drawn. /// </returns> /// private int drawIcon(Graphics g) { bool reverse; int w, h; TaskPane tp; Image img; // // If there's no image, this is easy!!! // if (this.m_buddyFrame.Image == null) { return(0); } reverse = MiscFunctions.GetRightToLeftValue(this.m_buddyFrame); // // Get the Image dimensions so we can see if we need to scale or not // tp = (TaskPane)this.m_buddyFrame.Parent; img = this.m_buddyFrame.Image; w = img.Width; h = img.Height; if (w > 32) { w = 32; } if (h > 32) { h = 32; } // // now draw the image in the appropriate place. // if (reverse == false) { g.DrawImage(img, 0, 0, w, h); } else { g.DrawImage(img, this.Width - w - 1, 0, w, h); } return(w); }
//=------------------------------------------------------------------= // drawCollapseButton //=------------------------------------------------------------------= /// <summary> /// Draws the Collapse button for this caption bar, if appropriate. /// </summary> /// private void drawCollapseButton(Graphics g) { System.Drawing.Drawing2D.SmoothingMode sm; Rectangle buttonRect; bool reverse; Point baseLoc; int top; Point pt; Pen p; reverse = MiscFunctions.GetRightToLeftValue(this.m_buddyFrame); // // No CollapseButton? Then we're done. // if (this.m_buddyFrame.CollapseButtonVisible == false) { return; } // // Set up a nice anti-aliased pen with which we will draw this. // sm = g.SmoothingMode; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; p = new Pen(colorCollapseButtonBorder(), 1.5f); // // figure out where to draw the circle. // top = this.Height - this.m_captionHeight; if (reverse == false) { buttonRect = new Rectangle(this.Width - COLLAPSE_BUTTON_DIAMETER - 5, ((int)(top + (this.m_captionHeight - COLLAPSE_BUTTON_DIAMETER) / 2 - 1)), COLLAPSE_BUTTON_DIAMETER, COLLAPSE_BUTTON_DIAMETER); baseLoc = new Point(this.Width - COLLAPSE_BUTTON_DIAMETER - 5, ((int)(top + (this.m_captionHeight - COLLAPSE_BUTTON_DIAMETER) / 2 - 1))); } else { buttonRect = new Rectangle(5, ((int)(top + (this.m_captionHeight - COLLAPSE_BUTTON_DIAMETER) / 2 - 1)), COLLAPSE_BUTTON_DIAMETER, COLLAPSE_BUTTON_DIAMETER); baseLoc = new Point(5, ((int)(top + (this.m_captionHeight - COLLAPSE_BUTTON_DIAMETER) / 2 - 1))); } g.FillEllipse(new SolidBrush(this.m_buddyFrame.CaptionBlend.StartColor), buttonRect); g.DrawEllipse(p, buttonRect); p.Dispose(); // // now draw the little chevrons // if (this.m_buddyFrame.IsExpanded == false) { p = new Pen(colorCollapseButtonChevrons(), 1.5f); pt = new Point(((int)(baseLoc.X + (COLLAPSE_BUTTON_DIAMETER / 2))), ((int)(baseLoc.Y + (COLLAPSE_BUTTON_DIAMETER / 2)))); g.DrawLine(p, pt, new Point(pt.X - 3, pt.Y - 3)); g.DrawLine(p, pt, new Point(pt.X + 3, pt.Y - 3)); pt = new Point(((int)(baseLoc.X + (COLLAPSE_BUTTON_DIAMETER / 2))), ((int)(baseLoc.Y + (COLLAPSE_BUTTON_DIAMETER / 2) + 4))); g.DrawLine(p, pt, new Point(pt.X - 3, pt.Y - 3)); g.DrawLine(p, pt, new Point(pt.X + 3, pt.Y - 3)); } else { p = new Pen(colorCollapseButtonChevrons(), 1.5f); pt = new Point(((int)(baseLoc.X + (COLLAPSE_BUTTON_DIAMETER / 2))), ((int)(baseLoc.Y + (COLLAPSE_BUTTON_DIAMETER / 2) - 4))); g.DrawLine(p, pt, new Point(pt.X - 3, pt.Y + 3)); g.DrawLine(p, pt, new Point(pt.X + 3, pt.Y + 3)); pt = new Point(((int)(baseLoc.X + (COLLAPSE_BUTTON_DIAMETER / 2))), ((int)(baseLoc.Y + (COLLAPSE_BUTTON_DIAMETER / 2)))); g.DrawLine(p, pt, new Point(pt.X - 3, pt.Y + 3)); g.DrawLine(p, pt, new Point(pt.X + 3, pt.Y + 3)); } // // Restore this // g.SmoothingMode = sm; }