Exemple #1
0
    public override void Paint(Graphics g) {
      base.Paint(g);

      g.SmoothingMode = SmoothingMode.HighQuality;

      using (Pen pen = new Pen(lineColor, lineWidth)) {

        SizeF titleSize = g.MeasureString(this.Title, ArtPalette.DefaultBoldFont, Rectangle.Width - 45);
        titleSize.Height += 10; //add spacing
        SizeF subtitleSize = g.MeasureString(this.Subtitle, ArtPalette.DefaultFont, Rectangle.Width - 45);
        subtitleSize.Height += 5; //add spacing
        if (this.Title == this.Subtitle || string.IsNullOrEmpty(this.Subtitle)) subtitleSize = new SizeF(0, 0);

        if ((int)titleSize.Height + (int)subtitleSize.Height != Rectangle.Height) {
          headerHeight = (int)titleSize.Height + (int)subtitleSize.Height;
          this.UpdateLabels();
        }

        GraphicsPath path = new GraphicsPath();
        path.AddArc(Rectangle.X, Rectangle.Y, 20, 20, -180, 90);
        path.AddLine(Rectangle.X + 10, Rectangle.Y, Rectangle.X + Rectangle.Width - 10, Rectangle.Y);
        path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y, 20, 20, -90, 90);
        path.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + 10, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height - 10);
        path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y + Rectangle.Height - 20, 20, 20, 0, 90);
        path.AddLine(Rectangle.X + Rectangle.Width - 10, Rectangle.Y + Rectangle.Height, Rectangle.X + 10, Rectangle.Y + Rectangle.Height);
        path.AddArc(Rectangle.X, Rectangle.Y + Rectangle.Height - 20, 20, 20, 90, 90);
        path.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height - 10, Rectangle.X, Rectangle.Y + 10);
        //shadow
        if (ArtPalette.EnableShadows) {
          Region darkRegion = new Region(path);
          darkRegion.Translate(5, 5);
          g.FillRegion(ArtPalette.ShadowBrush, darkRegion);
        }
        //background
        g.FillPath(Brush, path);

        using (LinearGradientBrush gradientBrush = new LinearGradientBrush(Rectangle.Location, new Point(Rectangle.X + Rectangle.Width, Rectangle.Y), this.Color, Color.White)) {
          Region gradientRegion = new Region(path);
          g.FillRegion(gradientBrush, gradientRegion);
        }

        if (!this.Collapsed) {
          TextStyle textStyle = new TextStyle(Color.Black, new Font("Arial", 7), StringAlignment.Near, StringAlignment.Near);
          StringFormat stringFormat = textStyle.StringFormat;
          stringFormat.Trimming = StringTrimming.EllipsisWord;
          stringFormat.FormatFlags = StringFormatFlags.LineLimit;
          Rectangle rect;

          const int verticalHeaderSpacing = 5;
          Point separationLineStart = new Point(Rectangle.X + 25, Rectangle.Y + headerHeight - verticalHeaderSpacing);
          Point separationLineEnd = new Point(Rectangle.X + Rectangle.Width - 25, Rectangle.Y + headerHeight - verticalHeaderSpacing);
          using (LinearGradientBrush brush = new LinearGradientBrush(separationLineStart, separationLineEnd, Color.Black, Color.White)) {
            using (Pen separationLinePen = new Pen(brush)) {
              g.DrawLine(separationLinePen, separationLineStart, separationLineEnd);
            }
          }


          for (int i = 0; i < this.labels.Count; i++) {
            rect = new Rectangle(Rectangle.X + 25, Rectangle.Y + headerHeight + i * (LABEL_HEIGHT + LABEL_SPACING), LABEL_WIDTH, LABEL_HEIGHT);
            g.DrawString(textStyle.GetFormattedText(this.labels[i]), textStyle.Font, textStyle.GetBrush(), rect, stringFormat);
          }
        }

        //the border
        g.DrawPath(pen, path);

        //the title
        g.DrawString(this.Title, ArtPalette.DefaultBoldFont, Brushes.Black,
                     new Rectangle(Rectangle.X + 25, Rectangle.Y + 5,
                                   Rectangle.Width - 45, Rectangle.Height - 5 - (int)subtitleSize.Height));

        //the subtitle
        if (this.Title != this.Subtitle || string.IsNullOrEmpty(this.Subtitle)) {
          g.DrawString(this.Subtitle, ArtPalette.DefaultFont, Brushes.Black,
                       new Rectangle(Rectangle.X + 25, Rectangle.Y + (int)titleSize.Height -5 ,
                                     Rectangle.Width - 45, Rectangle.Height - 5));
        }


        //the material
        foreach (IShapeMaterial material in Children)
          material.Paint(g);

        //the connectors
        if (this.ShowConnectors) {
          foreach (IConnector t in Connectors)
            t.Paint(g);
        }
      }
    }
    /// <summary>
    /// Initializes a new instance of the <see cref="T:FolderMaterial"/> class.
    /// </summary>
    /// <param name="title">The title.</param>
    /// <param name="entries">The entries.</param>
    public FolderMaterial(string title, string[] entries)
      : this(title) {
      myTextStyle = new TextStyle(
          Color.Black,
          new Font("Arial", 10),
          StringAlignment.Near,
          StringAlignment.Near);
      IconLabelMaterial label;
      for (int k = 0; k < entries.Length; k++) {
        label = new IconLabelMaterial("Resources.Text.png", entries[k]);

        // We attach our ITextStyle to items when they're added to the
        // collection.
        mEntries.Add(label);
      }
      Collapse();
    }
    /// <summary>
    /// Initializes a new instance of the <see cref="T:FolderMaterial"/> class.
    /// </summary>
    /// <param name="title">The title.</param>
    /// <param name="entries">The entries.</param>
    /// <param name="defaultIconLocation">The default icon location.</param>
    public FolderMaterial(
        string title,
        string[] entries,
        string defaultIconLocation)
      : this(title) {
      IconLabelMaterial label;
      myTextStyle = new TextStyle(
           Color.Black,
           new Font("Arial", 10),
           StringAlignment.Near,
           StringAlignment.Near);

      for (int k = 0; k < entries.Length; k++) {
        label = new IconLabelMaterial(entries[k], defaultIconLocation);
        mEntries.Add(label);
      }
      Collapse();

      myTextStyle.TextStyleChanged +=
          new TextStyleChangedEventHandler(HandleTextStyleChanged);
    }
    ///<summary>
    ///Default constructor
    ///</summary>
    public FolderMaterial(string title)
      : base() {
      myTextStyle = new TextStyle(
          Color.Black,
          new Font("Arial", 10),
          StringAlignment.Near,
          StringAlignment.Near);
      mEntries = new CollectionBase<IShapeMaterial>();
      mEntries.OnItemAdded +=
          new EventHandler<CollectionEventArgs<IShapeMaterial>>(
          mEntries_OnItemAdded);

      Gliding = false;
      Resizable = true;

      plusminus = new SwitchIconMaterial(SwitchIconType.PlusMinus);
      plusminus.TextStyle = myTextStyle;
      plusminus.Transform(new Rectangle(0, 0, 16, 16));
      plusminus.Visible = true;
      plusminus.Gliding = false;
      plusminus.OnExpand += new EventHandler(plusminus_OnExpand);
      plusminus.OnCollapse += new EventHandler(plusminus_OnCollapse);


      header = new ClickableLabelMaterial();
      header.TextStyle = myTextStyle;
      header.Transform(new Rectangle(0, 0, 100, HeaderHeight));
      header.Text = title;
      header.Gliding = false;
      header.Visible = true;
      header.Resizable = true;
    }