FillRegion() публичный метод

Fills the interior of a region.
public FillRegion ( Brush brush, Region region ) : void
brush Brush Brush.
region Region Region.
Результат void
        public static void UpDateChargingIcon(double BatteryVoltage, bool OffLine)
        {
            int PercentageBattery = Convert.ToInt32(((BatteryVoltage - UPS_Manager.Properties.Settings.Default.BatteryChargeMin) / ((UPS_Manager.Properties.Settings.Default.BatteryChargeMax - 0.1) - UPS_Manager.Properties.Settings.Default.BatteryChargeMin)) * 100);

            if (PercentageBattery <= 100 && !OffLine)
            {
                System.Drawing.Font       drawFont         = new System.Drawing.Font("Webdings", 70, FontStyle.Regular);
                System.Drawing.Font       drawFont1        = new System.Drawing.Font("Webdings", 85, FontStyle.Bold);
                System.Drawing.SolidBrush DrawBrushEmpty   = new System.Drawing.SolidBrush(System.Drawing.Color.Transparent);
                System.Drawing.SolidBrush DrawBrushSymbol  = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
                System.Drawing.SolidBrush DrawBrushSymbol1 = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                System.Drawing.SolidBrush DrawBrushFull    = new System.Drawing.SolidBrush(System.Drawing.Color.White);

                Bitmap bitmap = new Bitmap(100, 100); // new Bitmap(100, 100);
                System.Drawing.Graphics  graphics      = System.Drawing.Graphics.FromImage(bitmap);
                System.Drawing.Rectangle DrawRectRed   = new Rectangle(0, 100 - PercentageBattery, 100, PercentageBattery);
                System.Drawing.Region    DrawRegionRed = new System.Drawing.Region(DrawRectRed);
                graphics.FillRegion(DrawBrushFull, DrawRegionRed);
                System.Drawing.Rectangle DrawRectGreen   = new Rectangle(0, 0, 100, 100 - PercentageBattery);
                System.Drawing.Region    DrawRegionGreen = new System.Drawing.Region(DrawRectGreen);
                graphics.FillRegion(DrawBrushEmpty, DrawRegionGreen);
                graphics.DrawString("~", drawFont1, DrawBrushSymbol1, -22, -3);
                graphics.DrawString("~", drawFont, DrawBrushSymbol, -8, 0);
                Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());

                UPSNotifyIcon.Icon = createdIcon;
                UPSNotifyIcon.Text = " " + PercentageBattery.ToString() + "%" + System.Environment.NewLine + BatteryVoltage.ToString() + "V";
            }
            else
            {
                UPSNotifyIcon.Icon = Properties.Resources.OnLine;
                UPSNotifyIcon.Text = BatteryVoltage.ToString() + "V";
            }
        }
Пример #2
0
		private void Form1_Paint (object sender, PaintEventArgs e)
		{
			gfx = e.Graphics;

			if (shape1checkBox.Checked && (r1 != null))
				gfx.FillRegion (Brushes.Red, r1);

			if (shape2checkBox.Checked && (r2 != null))
				gfx.FillRegion (Brushes.Green, r2);

			if (shape3checkBox.Checked && (op != null))
				gfx.FillRegion (Brushes.Blue, op);
		}
Пример #3
0
        private void drawFormattedText(string s, Font f, SolidBrush brush, RectangleF drawRect)
        {
            string s1, s2, s3;
            int    i, j, len, r;

            CharacterRange[] ranges        = new CharacterRange[5];
            StringFormat     stringFormat1 = new StringFormat();

            r   = 0;
            len = s.Length;
            i   = s.IndexOf('*');
            while (i != -1)
            {
                j = s.IndexOf('*', i + 1);
                CharacterRange range = new CharacterRange(i, j - i - 1);
                ranges[++r] = range;
                s1          = s.Substring(0, i);             // text before bold
                s2          = s.Substring(i + 1, j - i - 1); // just the bold text
                s3          = s.Substring(j + 1);            // text after the bold
                s           = s1 + s2 + s3;
                i           = s.IndexOf('*');
            }
            stringFormat1.SetMeasurableCharacterRanges(ranges);

            Region[] charRegion = graphics.MeasureCharacterRanges(s,
                                                                  f, drawRect, stringFormat1);

            graphics.DrawString(s, f, brush, drawRect);
            int k;

            for (k = 0; k < charRegion.Length; k++)
            {
                graphics.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Fuchsia)), charRegion[k]);
            }
        }
Пример #4
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;

            Rectangle rect = new Rectangle(20, 20, 100, 100);//绘制一个矩形
            Pen       p1   = new Pen(Color.Red);

            g.DrawRectangle(p1, rect);

            Rectangle rect2 = new Rectangle(70, 70, 100, 100);//绘制一个圆形

            //g.DrawRectangle(p1, rect2);
            g.DrawEllipse(p1, rect2);
            GraphicsPath path = new GraphicsPath();

            path.AddEllipse(rect2);

            Region region = new Region(rect);//设定矩形与圆形的交集区域

            region.Intersect(path);

            Point point1 = new Point(10, 10);//设置颜色渐变起止位置
            Point point2 = new Point(50, 50);
            LinearGradientBrush brush = new LinearGradientBrush(point1, point2, Color.Green, Color.OrangeRed);

            g.FillRegion(brush, region);
        }
Пример #5
0
 public PointDrawer(ref Graphics graph)
 {
     _graph = graph;
     _graph.FillRegion(new SolidBrush(Color.White),_graph.Clip);
     CurrentPos.X = (int) _graph.VisibleClipBounds.Width/2;
     CurrentPos.Y = (int) _graph.VisibleClipBounds.Height/2;
     Redraw(new Point(0,0));
 }
Пример #6
0
        /// <summary>
        /// Draws a shadow around a defined path.
        /// </summary>
        /// <param name="g">The current Graphics handle.</param>
        /// <param name="path">The path which should have a shadow.</param>
        /// <param name="color">The color of the shadow.</param>
        /// <param name="dx">The horizontal shift.</param>
        /// <param name="dy">The vertical shift.</param>
        /// <param name="blur">The blurness.</param>
        public static void DrawShadow(this System.Drawing.Graphics g, GraphicsPath path, Color color, float dx, float dy, float blur)
        {
            var bounds = path.GetBounds();
            var bpw    = blur / (float)bounds.Width / 2f;
            var bph    = blur / (float)bounds.Height / 2f;
            var tdx    = -(float)bounds.Left - (float)bounds.Width / 2f;
            var tdy    = -(float)bounds.Top - (float)bounds.Height / 2f;

            path.Transform(new Matrix(1f, 0f, 0f, 1f, tdx, tdy));
            Region original = new Region(path);

            path.Transform(new Matrix(1f + bpw, 0f, 0f, 1f + bph, dx, dy));
            Region transform = new Region(path);

            transform.Exclude(original);

            var gs = g.Save();

            g.TranslateTransform(-tdx, -tdy);

            if (blur <= 0f)
            {
                g.FillRegion(new SolidBrush(color), transform);
            }
            else
            {
                var lgb = new PathGradientBrush(path);
                lgb.CenterColor    = color;
                lgb.SurroundColors = new Color[] { Color.Transparent };
                var colors    = new Color[3];
                var positions = new float[3];

                for (var i = 0; i < 3; i++)
                {
                    colors[i]    = Color.FromArgb(255 * (2 - i) / 2, color);
                    positions[i] = (2f - i) / 2f;
                }

                lgb.InterpolationColors.Colors    = colors;
                lgb.InterpolationColors.Positions = positions;
                g.FillRegion(lgb, transform);
            }

            g.Restore(gs);
        }
Пример #7
0
        public override void DrawShapeOnGraphics(GraphicsPath shapeAsGraphicsPath, Graphics g)
        {
            styleToDecorate.DrawShapeOnGraphics(shapeAsGraphicsPath, g);

              Region shapeAsRegion = new Region(shapeAsGraphicsPath);
              RectangleF rr = shapeAsRegion.GetBounds(g);
              CreateGradient(rr);
              g.FillRegion(styleToDecorate.fillBrush_, shapeAsRegion);
        }
Пример #8
0
        /// <summary>
        /// Creates a blank image with the given color
        /// </summary>
        /// <param name="imageColor"></param>
        /// <returns></returns>
        public static System.Drawing.Bitmap CreateBlankImage(Brush imageColor, int width, int height)
        {
            System.Drawing.Bitmap newBackground = new System.Drawing.Bitmap(width, height);

            // Fill the whole image with white
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBackground))
                g.FillRegion(imageColor, new Region(new System.Drawing.Rectangle(0, 0, width, height)));

            return(newBackground);
        }
Пример #9
0
		/// <summary>
		/// Fill a rounded rectangle with the specified brush.
		/// </summary>
		/// <param name="g"></param>
		/// <param name="roundRect"></param>
		/// <param name="brush"></param>
		public static void FillRoundedRectangle(Graphics g, RoundedRectangle roundRect, Brush brush)
		{
			Rectangle rectangleBorder;
			rectangleBorder = new Rectangle(roundRect.Rectangle.X, 
				roundRect.Rectangle.Y,
				roundRect.Rectangle.Width - 1,
				roundRect.Rectangle.Height - 1);

			RoundedRectangle roundToDraw = new RoundedRectangle(rectangleBorder, roundRect.RoundValue);
			g.FillRegion(brush, new Region( roundToDraw.ToGraphicsPath() ));
		}
Пример #10
0
        private static Image Combine(string[] files, int row, int col, CancellationToken token)
        {
            Image img = null;

            try
            {
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(files[0]);
                int width  = bitmap.Width * row;  //280 px
                int height = bitmap.Height * col; //400 px
                img = new Bitmap(width, height);

                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img))
                {
                    Rectangle  fillRect   = new Rectangle(0, 0, img.Width, img.Height);
                    SolidBrush tBrush     = new SolidBrush(Color.Transparent);
                    Region     fillRegion = new Region(fillRect);
                    g.FillRegion(tBrush, fillRegion);
                    foreach (string image in files)
                    {
                        g.DrawImage(Image.FromFile(image), new Point(0, 0));
                    }
                    int offsetX = 0;
                    int offsetY = 0;
                    int curr    = 0;
                    for (int i = 0; i < col; i++)
                    {
                        for (int j = 0; j < row; j++)
                        {
                            g.DrawImage(Image.FromFile(files[curr]), new Point(offsetX, offsetY));
                            offsetX += bitmap.Width;
                            curr++;
                        }
                        offsetX  = 0;
                        offsetY += bitmap.Height;
                    }
                    bitmap.Dispose();
                    g.Dispose();
                    if (token.IsCancellationRequested)
                    {
                        return(img);
                    }
                }

                return(img);
            }
            catch (Exception ex)
            {
                if (img != null)
                {
                    img.Dispose();
                }
                throw ex;
            }
        }
Пример #11
0
        /// <summary>
        /// Creates a blank image with the given color
        /// </summary>
        /// <param name="imageColor"></param>
        /// <returns></returns>
        public static Bitmap CreateBlankImage(Brush imageColor, int width, int height)
        {
            Bitmap newBackground = new Bitmap(width, height, PixelFormat.Format24bppRgb);

            // Fill the whole image with white
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBackground))
            {
                g.FillRegion(imageColor, new Region(new Rectangle(0, 0, width, height)));
            }

            return(newBackground);
        }
    protected override void PaintBackground(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle gridBounds)
    {
        base.PaintBackground(graphics, clipBounds, gridBounds);

        if (_DGVHasTransparentBackground)
        {
            //  DataGridView Transparent !
            SolidBrush myBrush  = new SolidBrush(base.Parent.BackColor);    // (Form1 BackColor) veya bir resme boyanabilir.
            Region     rectDest = new Region(new Rectangle(0, 0, base.Width, base.Height));
            graphics.FillRegion(myBrush, rectDest);
        }
    }
Пример #13
0
        public void Draw(Graphics graphics)
        {
            ReInitialize(graphics);

            int innerRadius = (int)(_partitionControl.Owner.InnerRadius);
            int outerRadius = (int)(_partitionControl.Owner.OuterRadius);

            Color color;

            if (_partitionControl.Partition.IsProtected)
                color = Color.LightGoldenrodYellow;
            else
                color = Color.LightGray;

            graphics.FillRegion(new SolidBrush(color), _region);

            Font currentFont = _isSelected ? selectedFont : mountFont;

            graphics.DrawString(
                normalizeMountPoint(_partitionControl.Partition.GetMountPoints()),
                currentFont,
                new SolidBrush(Color.DarkBlue),
                mountTextPoint
                );

            graphics.DrawString(
                SizeFormatter.Format(_partitionControl.Partition.Size),
                sizeFont,
                new SolidBrush(Color.DarkBlue),
                sizeTextPoint
                );

            if (_isSelected)
            {
                if (sharePath == null)
                    graphics.DrawString(Properties.Resources.noSharePath
                            + sharePath,
                        SystemFonts.CaptionFont,
                        new SolidBrush(Color.Red),
                        _partitionControl.Owner.Center.X - outerRadius,
                        _partitionControl.Owner.Center.Y + outerRadius);
                else
                    graphics.DrawString(Properties.Resources.openInExplorer
                            + sharePath,
                        SystemFonts.CaptionFont,
                        new SolidBrush(Color.Red),
                        _partitionControl.Owner.Center.X - outerRadius,
                        _partitionControl.Owner.Center.Y + outerRadius);
            }
        }
Пример #14
0
        private void doDraw(Graphics g)
        {
            Region baseR = new Region(new Rectangle(0, 0, this.pbParent.Width, this.pbParent.Height));

            foreach (KeyValuePair<String, drawObject> item in drawObjects) {
                if (item.Key.Substring(0, 5) == "table") {
                    baseR.Exclude(Rectangle.Round(item.Value.loc));
                }
            }

            g.FillRegion(new SolidBrush(this.pbParent.BackColor), baseR);

            foreach (KeyValuePair<String, drawObject> item in drawObjects) {
                item.Value.draw(g);
            }
        }
Пример #15
0
        void DrawRegionOperation()
        {
            g = this.CreateGraphics();
            Rectangle rect1 = new Rectangle(100, 100, 120, 120);
            Rectangle rect2 = new Rectangle(70, 70, 120, 120);

            Region rgn1 = new Region(rect1);
            Region rgn2 = new Region(rect2);

            g.DrawRectangle(Pens.Blue, rect1);
            g.DrawRectangle(Pens.Red, rect2);

            switch(rgnOperation)
            {
                case RegionOperation.Union:
                    rgn1.Union(rgn2);
                    break;
                case RegionOperation.Complement:
                    rgn1.Complement(rgn2);
                    break;
                case RegionOperation.Intersect:
                    rgn1.Intersect(rgn2);
                    break;
                case RegionOperation.Exclude:
                    rgn1.Exclude(rgn2);
                    break;
                case RegionOperation.Xor:
                    rgn1.Xor(rgn2);
                    break;
                default:
                    break;

            }

            g.FillRegion(Brushes.Tomato, rgn1);

            g.Dispose();
        }
Пример #16
0
        private void DrawRegionOperations()
        {
            g = this.CreateGraphics();
            // Создаем два прямоугольника
            Rectangle rect1 = new Rectangle(100, 100, 120, 120);
            Rectangle rect2 = new Rectangle(70, 70, 120, 120);
            // Создаем два региона
            Region rgn1 = new Region(rect1);
            Region rgn2 = new Region(rect2);
            // рисуем прямоугольники
            g.DrawRectangle(Pens.Green, rect1);
            g.DrawRectangle(Pens.Black, rect2);

            // обработаем перечисление и вызовем соответствующий метод
            switch (rgnOperation)
            {
                case RegionOperations.Union:
                    rgn1.Union(rgn2);
                    break;
                case RegionOperations.Complement:
                    rgn1.Complement(rgn2);
                    break;
                case RegionOperations.Intersect:
                    rgn1.Intersect(rgn2);
                    break;
                case RegionOperations.Exclude:
                    rgn1.Exclude(rgn2);
                    break;
                case RegionOperations.Xor:
                    rgn1.Xor(rgn2);
                    break;
                default:
                    break;
            }
            // Рисуем регион
            g.FillRegion(Brushes.Blue, rgn1);
            g.Dispose();
        }
Пример #17
0
        private void DrawTabFocusIndicator(GraphicsPath tabpath, int index, System.Drawing.Graphics graphics)
        {
            if (this._FocusTrack && this._TabControl.Focused && index == this._TabControl.SelectedIndex)
            {
                Brush      focusBrush = null;
                RectangleF pathRect   = tabpath.GetBounds();
                Rectangle  focusRect  = Rectangle.Empty;
                switch (this._TabControl.Alignment)
                {
                case TabAlignment.Top:
                    focusRect  = new Rectangle((int)pathRect.X, (int)pathRect.Y, (int)pathRect.Width, 4);
                    focusBrush = new LinearGradientBrush(focusRect, this._FocusColor, SystemColors.Window, LinearGradientMode.Vertical);
                    break;

                case TabAlignment.Bottom:
                    focusRect  = new Rectangle((int)pathRect.X, (int)pathRect.Bottom - 4, (int)pathRect.Width, 4);
                    focusBrush = new LinearGradientBrush(focusRect, SystemColors.ControlLight, this._FocusColor, LinearGradientMode.Vertical);
                    break;

                case TabAlignment.Left:
                    focusRect  = new Rectangle((int)pathRect.X, (int)pathRect.Y, 4, (int)pathRect.Height);
                    focusBrush = new LinearGradientBrush(focusRect, this._FocusColor, SystemColors.ControlLight, LinearGradientMode.Horizontal);
                    break;

                case TabAlignment.Right:
                    focusRect  = new Rectangle((int)pathRect.Right - 4, (int)pathRect.Y, 4, (int)pathRect.Height);
                    focusBrush = new LinearGradientBrush(focusRect, SystemColors.ControlLight, this._FocusColor, LinearGradientMode.Horizontal);
                    break;
                }

                //	Ensure the focus stip does not go outside the tab
                Region focusRegion = new Region(focusRect);
                focusRegion.Intersect(tabpath);
                graphics.FillRegion(focusBrush, focusRegion);
                focusRegion.Dispose();
                focusBrush.Dispose();
            }
        }
Пример #18
0
        public static void DrawDocumentTab(Graphics g, Rectangle rect, Color backColorBegin, Color backColorEnd, Color edgeColor, TabDrawType tabType, bool closed)
        {
            GraphicsPath path = null;
            Region region = null;
            Brush brush = null;
            Pen pen = null;
            brush = new LinearGradientBrush(rect, backColorBegin, backColorEnd, LinearGradientMode.Vertical);
            pen = new Pen(edgeColor, 1.0F);
            path = new GraphicsPath();

            if (tabType == TabDrawType.First)
            {
                path.AddLine(rect.Left + 1, rect.Bottom + 1, rect.Left + rect.Height, rect.Top + 2);
                path.AddLine(rect.Left + rect.Height + 4, rect.Top, rect.Right - 3, rect.Top);
                path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
            }
            else
            {
                if (tabType == TabDrawType.Active)
                {
                    path.AddLine(rect.Left + 1, rect.Bottom + 1, rect.Left + rect.Height, rect.Top + 2);
                    path.AddLine(rect.Left + rect.Height + 4, rect.Top, rect.Right - 3, rect.Top);
                    path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
                }
                else
                {
                    path.AddLine(rect.Left, rect.Top + 6, rect.Left + 4, rect.Top + 2);
                    path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top);
                    path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
                    path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left, rect.Bottom + 1);
                }
            }
            region = new Region(path);
            g.FillRegion(brush, region);
            g.DrawPath(pen, path);
        }
        public bool Draw(Graphics g, ColorEnumStatics colorDef)
        {
            if (gradientPath.PointCount == 0) return false;
            Color[] colors = { colorDef.GetColorFromEnum(finalColor) };
            PathGradientBrush b = new PathGradientBrush(gradientPath);
            b.CenterColor = colorDef.GetColorFromEnum(color);
            b.SurroundColors = colors;

            //SolidBrush b = new SolidBrush(colorDef.GetColorFromEnum(color));

            if ((loc1 is XYIntLocation) && isDrawable)
            {
                g.FillRegion(b, region);

                return true;
            }
            else return false;
        }
Пример #20
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);
        }
      }
    }
Пример #21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Paints the current <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.
		/// </summary>
		/// <param name="graphics">The <see cref="T:System.Drawing.Graphics"></see> used to
		/// paint the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.</param>
		/// <param name="clipBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// represents the area of the <see cref="T:System.Windows.Forms.DataGridView"></see>
		/// that needs to be repainted.</param>
		/// <param name="cellBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// contains the bounds of the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>
		/// that is being painted.</param>
		/// <param name="rowIndex">The row index of the cell that is being painted.</param>
		/// <param name="cellState">A bitwise combination of
		/// <see cref="T:System.Windows.Forms.DataGridViewElementStates"></see> values that
		/// specifies the state of the cell.</param>
		/// <param name="value">The data of the <see cref="T:System.Windows.Forms.DataGridViewCell">
		/// </see> that is being painted.</param>
		/// <param name="formattedValue">The formatted data of the
		/// <see cref="T:System.Windows.Forms.DataGridViewCell"></see> that is being painted.
		/// </param>
		/// <param name="errorText">An error message that is associated with the cell.</param>
		/// <param name="cellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle">
		/// </see> that contains formatting and style information about the cell.</param>
		/// <param name="advancedBorderStyle">A
		/// <see cref="T:System.Windows.Forms.DataGridViewAdvancedBorderStyle"></see> that
		/// contains border styles for the cell that is being painted.</param>
		/// <param name="paintParts">A bitwise combination of the
		/// <see cref="T:System.Windows.Forms.DataGridViewPaintParts"></see> values that
		/// specifies which parts of the cell need to be painted.</param>
		/// ------------------------------------------------------------------------------------
		protected override void Paint(Graphics graphics, Rectangle clipBounds,
			Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
			object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
			DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
		{
			if (!m_fAllowPaint)
				return;

			// Clear the background
			using (Region background = new Region(cellBounds))
			{
				background.Xor(GetCellContentDisplayRectangle(advancedBorderStyle));
				background.Intersect(clipBounds);
				graphics.FillRegion(SystemBrushes.Window, background);
			}

			// Invalidate the view so that it redraws
			if (m_Control != null)
			{
				Point pt = m_Control.PointToClient(DataGridView.PointToScreen(new Point(clipBounds.X, clipBounds.Y)));
//				Rectangle borderRect = BorderWidths(advancedBorderStyle);
				Rectangle toDraw = new Rectangle(0, 0,
					cellBounds.Width, cellBounds.Height);
				Rectangle clientClip = new Rectangle(pt.X, pt.Y, clipBounds.Width, clipBounds.Height);
				toDraw.Intersect(clientClip);
				m_Control.Invalidate(toDraw, true);
				m_Control.Update();
			}

			// Finally draw the borders
			if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
			{
#if !__MonoCS__
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
#else
				// TODO-Linux: Something possibly DataGridView (but not it seems the ViewControl itself) - if drawing border over this border
				// so to work around this problem just draw border 2 pixel's in - not a great solution :)
				// Need to fix The DataGridView not to do this.
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
				if (cellBounds.Width > 2)
					cellBounds.Inflate(-2, -2);
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
#endif
			}
		}
Пример #22
0
 private void RenderComboBoxBackground(Graphics g, Rectangle rect, Rectangle buttonRect)
 {
     Color color = base.Enabled ? base.BackColor : SystemColors.Control;
     using (SolidBrush brush = new SolidBrush(color))
     {
         buttonRect.Inflate(-1, -1);
         rect.Inflate(-1, -1);
         using (Region region = new Region(rect))
         {
             region.Exclude(buttonRect);
             region.Exclude(this.EditRect);
             g.FillRegion(brush, region);
         }
     }
 }
Пример #23
0
        private void DrawGradient(Graphics g)
        {
            g.PixelOffsetMode = PixelOffsetMode.Half;
            Rectangle gradientRect;

            float gradientAngle;

            switch (this.orientation)
            {
                case Orientation.Horizontal:
                    gradientAngle = 180.0f;
                    break;

                case Orientation.Vertical:
                    gradientAngle = 90.0f;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
            }

            // draw gradient
            gradientRect = ClientRectangle;

            switch (this.orientation)
            {
                case Orientation.Horizontal:
                    gradientRect.Inflate(-triangleHalfLength, -triangleSize + 3);
                    break;

                case Orientation.Vertical:
                    gradientRect.Inflate(-triangleSize + 3, -triangleHalfLength);
                    break;

                default:
                    throw new InvalidEnumArgumentException();
            }

            if (this.customGradient != null && gradientRect.Width > 1 && gradientRect.Height > 1)
            {
                Surface gradientSurface = new Surface(gradientRect.Size);

                using (RenderArgs ra = new RenderArgs(gradientSurface))
                {
                    Utility.DrawColorRectangle(ra.Graphics, ra.Bounds, Color.Transparent, false);

                    if (Orientation == Orientation.Horizontal)
                    {
                        for (int x = 0; x < gradientSurface.Width; ++x)
                        {
                            // TODO: refactor, double buffer, save this computation in a bitmap somewhere
                            double index = (double)(x * (this.customGradient.Length - 1)) / (double)(gradientSurface.Width - 1);
                            int indexL = (int)Math.Floor(index);
                            double t = 1.0 - (index - indexL);
                            int indexR = (int)Math.Min(this.customGradient.Length - 1, Math.Ceiling(index));
                            Color colorL = this.customGradient[indexL];
                            Color colorR = this.customGradient[indexR];

                            double a1 = colorL.A / 255.0;
                            double r1 = colorL.R / 255.0;
                            double g1 = colorL.G / 255.0;
                            double b1 = colorL.B / 255.0;

                            double a2 = colorR.A / 255.0;
                            double r2 = colorR.R / 255.0;
                            double g2 = colorR.G / 255.0;
                            double b2 = colorR.B / 255.0;

                            double at = (t * a1) + ((1.0 - t) * a2);

                            double rt;
                            double gt;
                            double bt;
                            if (at == 0)
                            {
                                rt = 0;
                                gt = 0;
                                bt = 0;
                            }
                            else
                            {
                                rt = ((t * a1 * r1) + ((1.0 - t) * a2 * r2)) / at;
                                gt = ((t * a1 * g1) + ((1.0 - t) * a2 * g2)) / at;
                                bt = ((t * a1 * b1) + ((1.0 - t) * a2 * b2)) / at;
                            }

                            int ap = Utility.Clamp((int)Math.Round(at * 255.0), 0, 255);
                            int rp = Utility.Clamp((int)Math.Round(rt * 255.0), 0, 255);
                            int gp = Utility.Clamp((int)Math.Round(gt * 255.0), 0, 255);
                            int bp = Utility.Clamp((int)Math.Round(bt * 255.0), 0, 255);

                            for (int y = 0; y < gradientSurface.Height; ++y)
                            {
                                ColorBgra src = gradientSurface[x, y];

                                // we are assuming that src.A = 255

                                int rd = ((rp * ap) + (src.R * (255 - ap))) / 255;
                                int gd = ((gp * ap) + (src.G * (255 - ap))) / 255;
                                int bd = ((bp * ap) + (src.B * (255 - ap))) / 255;

                                // TODO: proper alpha blending!
                                gradientSurface[x, y] = ColorBgra.FromBgra((byte)bd, (byte)gd, (byte)rd, 255);
                            }
                        }

                        g.DrawImage(ra.Bitmap, gradientRect, ra.Bounds, GraphicsUnit.Pixel);
                    }
                    else if (Orientation == Orientation.Vertical)
                    {
                        // TODO
                    }
                    else
                    {
                        throw new InvalidEnumArgumentException();
                    }
                }

                gradientSurface.Dispose();
            }
            else
            {
                using (LinearGradientBrush lgb = new LinearGradientBrush(this.ClientRectangle,
                           maxColor, minColor, gradientAngle, false))
                {
                    g.FillRectangle(lgb, gradientRect);
                }
            }

            // fill background
            using (PdnRegion nonGradientRegion = new PdnRegion())
            {
                nonGradientRegion.MakeInfinite();
                nonGradientRegion.Exclude(gradientRect);

                using (SolidBrush sb = new SolidBrush(this.BackColor))
                {
                    g.FillRegion(sb, nonGradientRegion.GetRegionReadOnly());
                }
            }

            // draw value triangles
            for (int i = 0; i < this.vals.Length; i++)
            {
                int pos = ValueToPosition(vals[i]);
                Brush brush;
                Pen pen;

                if (i == highlight) 
                {
                    brush = Brushes.Blue;
                    pen = (Pen)Pens.White.Clone();
                } 
                else 
                {
                    brush = Brushes.Black;
                    pen = (Pen)Pens.Gray.Clone();
                }

                g.SmoothingMode = SmoothingMode.AntiAlias;

                Point a1;
                Point b1;
                Point c1;

                Point a2;
                Point b2;
                Point c2;

                switch (this.orientation)
                {
                    case Orientation.Horizontal:
                        a1 = new Point(pos - triangleHalfLength, 0);
                        b1 = new Point(pos, triangleSize - 1);
                        c1 = new Point(pos + triangleHalfLength, 0);

                        a2 = new Point(a1.X, Height - 1 - a1.Y);
                        b2 = new Point(b1.X, Height - 1 - b1.Y);
                        c2 = new Point(c1.X, Height - 1 - c1.Y);
                        break;

                    case Orientation.Vertical:
                        a1 = new Point(0, pos - triangleHalfLength);
                        b1 = new Point(triangleSize - 1, pos);
                        c1 = new Point(0, pos + triangleHalfLength);

                        a2 = new Point(Width - 1 - a1.X, a1.Y);
                        b2 = new Point(Width - 1 - b1.X, b1.Y);
                        c2 = new Point(Width - 1 - c1.X, c1.Y);
                        break;

                    default:
                        throw new InvalidEnumArgumentException();
                }

                if (this.drawNearNub)
                {
                    g.FillPolygon(brush, new Point[] { a1, b1, c1, a1 });
                }

                if (this.drawFarNub)
                {
                    g.FillPolygon(brush, new Point[] { a2, b2, c2, a2 });
                }

                if (pen != null)
                {
                    if (this.drawNearNub)
                    {
                        g.DrawPolygon(pen, new Point[] { a1, b1, c1, a1 });
                    }

                    if (this.drawFarNub)
                    {
                        g.DrawPolygon(pen, new Point[] { a2, b2, c2, a2 });
                    }

                    pen.Dispose();
                }
            }
        }
Пример #24
0
		protected override void PaintClient(Graphics g, bool imageDataLost)
		{
			float z = Zoom;

			if (mPreviousClientSize != ClientSize)
			{
				if (!mNeedsPlayerRecenter && mCenterOnCoords == Coordinates.NO_COORDINATES)
				{
					if (CenterOnPlayer && IsCenteredOnPlayer(z, mPreviousClientSize))
						mNeedsPlayerRecenter = true;
					else
						CenterOnPix(mPreviousClientSize.Width / 2, mPreviousClientSize.Height / 2, z);
				}
				mPreviousClientSize = ClientSize;
			}

			float zoomedSize = mMapSize * z;
			if (zoomedSize < ClientSize.Width || zoomedSize < ClientSize.Height)
			{
				z = Math.Max(ClientSize.Width / (float)mMapSize, ClientSize.Height / (float)mMapSize);
				if (z > 1)
					z = 1;
				Zoom = z;
				ActualZoom = z;
				zoomedSize = mMapSize * z;
			}

			// Paint Map
			Matrix origTransform = g.Transform;
			g.Clear(Clear);

			float coordPadX = 0, coordPadY = 0;

			if (mCenterOnCoords != Coordinates.NO_COORDINATES)
			{
				CenterOnCoords(mCenterOnCoords, z);
				mCenterOnCoords = Coordinates.NO_COORDINATES;
				mNeedsPlayerRecenter = false;
			}
			else if (mNeedsPlayerRecenter && (ClientMouseButtons & DragButton) == 0)
			{
				mNeedsPlayerRecenter = false;
				if (!PlayerInDungeon)
					CenterOnCoords(mPlayerCoords, z);
			}

			if (ClientSize.Width > zoomedSize)
			{
				// Center horizontally
				mOffset.X = (ClientSize.Width - zoomedSize) / (2 * z);
				coordPadX = mOffset.X * z;
			}
			else if (mOffset.X > 0)
				mOffset.X = 0;
			else if (mOffset.X < (ClientSize.Width - zoomedSize) / z)
				mOffset.X = (ClientSize.Width - zoomedSize) / z;

			if (ClientSize.Height > zoomedSize)
			{
				// Center vertically
				mOffset.Y = (ClientSize.Height - zoomedSize) / (2 * z);
				coordPadY = mOffset.Y * z;
			}
			else if (mOffset.Y > 0)
				mOffset.Y = 0;
			else if (mOffset.Y < (ClientSize.Height - zoomedSize) / z)
				mOffset.Y = (ClientSize.Height - zoomedSize) / z;

			#region Draw Map
			if (z < 1)
			{
				// Lazy load low res map
				if (mDerethMapLowRes == null)
				{
					mDerethMapLowRes = new Bitmap(mZipFile.GetInputStream(mZipFile.GetEntry("lowres.png")));
				}

				float relSize = (float)mDerethMapLowRes.Width / mMapSize;

				if (z / relSize <= 0.5f)
					g.InterpolationMode = InterpolationMode.HighQualityBilinear;
				else
					g.InterpolationMode = InterpolationMode.Bilinear;

				RectangleF srcRect = new RectangleF(-mOffset.X * relSize, -mOffset.Y * relSize,
					ClientSize.Width * relSize / z, ClientSize.Height * relSize / z);
				RectangleF destRect = new RectangleF(0, 0, ClientSize.Width, ClientSize.Height);

				g.DrawImage(mDerethMapLowRes, destRect, srcRect, GraphicsUnit.Pixel);
			}
			else
			{
				float w = ClientSize.Width / z;

				int minTileX = Math.Max((int)(-mOffset.X / mTileSize), 0);
				int minTileY = Math.Max((int)(-mOffset.Y / mTileSize), 0);
				int maxTileX = Math.Min(
					(int)((-mOffset.X + ClientSize.Width / z) / mTileSize), mMaxTile);
				int maxTileY = Math.Min(
					(int)((-mOffset.Y + ClientSize.Height / z) / mTileSize), mMaxTile);

				if (z == 1)
				{
					int offX = (int)mOffset.X, offY = (int)mOffset.Y;
					int dX, dY;
					for (int i = minTileX; i <= maxTileX; i++)
					{
						dX = i * mTileSize + offX;
						for (int j = minTileY; j <= maxTileY; j++)
						{
							dY = j * mTileSize + offY;
							GraphicsUtil.BitBlt(GetTile(i, j), ClientImage, dX, dY);
						}
					}
				}
				else
				{
					g.InterpolationMode = InterpolationMode.NearestNeighbor;
					g.ScaleTransform(z, z);
					float dX, dY;
					for (int i = minTileX; i <= maxTileX; i++)
					{
						dX = i * mTileSize + mOffset.X;
						for (int j = minTileY; j <= maxTileY; j++)
						{
							dY = j * mTileSize + mOffset.Y;
							g.DrawImage(GetTile(i, j), dX, dY);
						}
					}
				}
			}
			#endregion

			g.Transform = origTransform;

			#region Draw Route-Finding Regions
#if false
			float regionZoom = z * mPixPerClick;
			g.ScaleTransform(z, z);
			g.TranslateTransform(mOffset.X + mMapSize / 2.0f - 1.0f, mOffset.Y + mMapSize / 2.0f);
			g.ScaleTransform(mPixPerClick, -mPixPerClick);
			Brush regionFill = new SolidBrush(Color.FromArgb(0x77CC0000));
			Brush innerRegionFill = new SolidBrush(Color.FromArgb(0x77AB10BC));
			RouteFinder.DrawRegions(g, regionFill, innerRegionFill);
			g.Transform = origTransform;
#endif
			#endregion

			Coordinates minCoords = PixToCoords(0, 0, z);
			Coordinates maxCoords = PixToCoords(ClientSize.Width, ClientSize.Height, z);

			#region Draw Coordinates (Part I: Gridlines)
			float lastTickNS = 0, firstTickEW = 0, lastTickEW = 0, firstTickNS = 0;
			RectangleF mapRect = new RectangleF(), insideGutter = new RectangleF();
			Region coordGutter = null;
			string precision = "";
			if (DrawCoords)
			{
				g.SmoothingMode = SmoothingMode.Default;

				if (mCoordTickDelta >= 1)
					precision = "0";
				else if (mCoordTickDelta >= 0.1)
					precision = "0.0";
				else
					precision = "0.00";

				lastTickNS = (float)(Math.Floor(minCoords.NS / mCoordTickDelta) * mCoordTickDelta);
				firstTickEW = (float)(Math.Floor(minCoords.EW / mCoordTickDelta) * mCoordTickDelta);
				lastTickEW = (float)(Math.Ceiling(maxCoords.EW / mCoordTickDelta) * mCoordTickDelta);
				firstTickNS = (float)(Math.Ceiling(maxCoords.NS / mCoordTickDelta) * mCoordTickDelta);

				mapRect = new RectangleF(coordPadX, coordPadY,
				   ClientSize.Width - 2 * coordPadX, ClientSize.Height - 2 * coordPadY);
				insideGutter = new RectangleF(
				   coordPadX + CoordGutterSize,
				   coordPadY + CoordGutterSize,
				   ClientSize.Width - 2 * (CoordGutterSize + coordPadX),
				   ClientSize.Height - 2 * (CoordGutterSize + coordPadY));
				coordGutter = new Region(mapRect);
				coordGutter.Xor(insideGutter);
				g.FillRegion(CoordGutterFill, coordGutter);

				// Draw Gridlines
				for (float ns = firstTickNS, ew = firstTickEW;
						ns <= lastTickNS || ew <= lastTickEW;
						ns += mCoordTickDelta, ew += mCoordTickDelta)
				{
					PointF pos = CoordsToPix(ns, ew, z);
					if (pos.Y > insideGutter.Top && pos.Y < insideGutter.Bottom)
					{
						// Draw horizontal NS gridline
						g.DrawLine(CoordGridline, CoordGutterSize + coordPadX, pos.Y,
							ClientSize.Width - CoordGutterSize - coordPadX - 1, pos.Y);
					}
					if (pos.X > insideGutter.Left && pos.X < insideGutter.Right)
					{
						// Draw vertical EW gridline
						g.DrawLine(CoordGridline, pos.X, CoordGutterSize + coordPadY,
							pos.X, ClientSize.Height - CoordGutterSize - coordPadY - 1);
					}
				}
			}
			#endregion

			#region Draw Locations
			mHotspots.Clear();
			float z2 = (float)(Math.Pow(z / ZoomBase, 0.25));
			if (ShowLocations)
			{
				g.SmoothingMode = SmoothingMode.Default;
				g.InterpolationMode = InterpolationMode.HighQualityBilinear;

				Dictionary<LocationType, List<Location>> visibleLocations
					= new Dictionary<LocationType, List<Location>>();

				foreach (Location loc in mLocDb.Locations.Values)
				{
					if (loc.Coords.NS <= minCoords.NS && loc.Coords.NS >= maxCoords.NS
							&& loc.Coords.EW >= minCoords.EW && loc.Coords.EW <= maxCoords.EW)
					{

						List<Location> addTo;
						LocationType type = loc.Type;
						if ((type & LocationType.AnyPortal) != 0)
						{
							type = LocationType.AnyPortal;
						}
						if (!visibleLocations.TryGetValue(type, out addTo))
						{
							addTo = new List<Location>();
							visibleLocations.Add(type, addTo);
						}
						addTo.Add(loc);
					}
				}

				if (ShowLocationsAllZooms || ZoomFactor >= 5)
				{
					DrawLocationType(visibleLocations, LocationType.NPC, Icons.Map.NPC, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Vendor, Icons.Map.Store, g, z, z2);
				}
				if (ShowLocationsAllZooms || ZoomFactor >= 2)
				{
					DrawLocationType(visibleLocations, LocationType.Village, Icons.Map.Settlement, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Landmark, Icons.Map.PointOfInterest, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.AllegianceHall, Icons.Map.Dungeon, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Bindstone, Icons.Map.Bindstone, g, z, z2);
				}
				if (ShowLocationsAllZooms || ZoomFactor >= -1)
				{
					DrawLocationType(visibleLocations, LocationType.Custom, Icons.Map.PointOfInterest, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Lifestone, Icons.Map.Lifestone, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Dungeon, Icons.Map.Dungeon, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.AnyPortal, Icons.Map.Portal, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.PortalHub, Icons.Map.PortalHub, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Outpost, Icons.Map.TownSmall, g, z, z2);
				}

				DrawLocationType(visibleLocations, LocationType.Town, Icons.Map.Town, g, z, z2);

				//DrawLocationType(visibleLocations, LocationType._StartPoint, Icons.Map.StartPoint, g, z, z2);
				//DrawLocationType(visibleLocations, LocationType._EndPoint, Icons.Map.EndPoint, g, z, z2);

				if (ShowLabels)
				{
					float z3 = (float)(Math.Pow(z / ZoomBase, 0.1));
					Font f = new Font(FontFamily.GenericSerif, Math.Min(8 * z3, 10));
					Font fTown = new Font(FontFamily.GenericSerif, Math.Min(9 * z3, 12), FontStyle.Bold);
					List<RectangleF> usedLabelRects = new List<RectangleF>();

					if (ZoomFactor >= -4)
					{
						LabelLocationType(g, fTown, usedLabelRects, LocationType.Town);
					}
					if (ZoomFactor >= 1)
					{
						LabelLocationType(g, f, usedLabelRects, LocationType.Outpost);
						LabelLocationType(g, f, usedLabelRects, LocationType.PortalHub);
						LabelLocationType(g, f, usedLabelRects, LocationType.AnyPortal);
						LabelLocationType(g, f, usedLabelRects, LocationType.Dungeon);
						LabelLocationType(g, f, usedLabelRects, LocationType.Lifestone);
						LabelLocationType(g, f, usedLabelRects, LocationType.Custom);
					}
					if (ZoomFactor >= 4)
					{
						LabelLocationType(g, f, usedLabelRects, LocationType.Bindstone);
						LabelLocationType(g, f, usedLabelRects, LocationType.AllegianceHall);
						LabelLocationType(g, f, usedLabelRects, LocationType.Landmark);
						LabelLocationType(g, f, usedLabelRects, LocationType.Village);
					}
					//if (ZoomFactor >= 6) {
					//    LabelLocation(g, f, usedLabelRects, LocationType.Vendor);
					//    LabelLocation(g, f, usedLabelRects, LocationType.NPC);
					//}
				}
			}
			#endregion

			#region Draw Route
			if (ShowRoute && mRoute != null && mRoute.Count > 1)
			{
				g.SmoothingMode = SmoothingMode.AntiAlias;
				PointF lastPoint, curPoint = CoordsToPix(mRoute[0].Coords, z);
				for (int i = 1; i < mRoute.Count; i++)
				{
					// Running
					lastPoint = curPoint;
					curPoint = CoordsToPix(mRoute[i].Coords, z);

					double dX = lastPoint.X - curPoint.X;
					double dY = lastPoint.Y - curPoint.Y;
					double dist = Math.Sqrt(dX * dX + dY * dY);
					if (dist >= 5.0)
					{
						g.DrawLine(RouteLineBackground, lastPoint, curPoint);
						g.DrawLine(RouteLine, lastPoint, curPoint);
					}

					// Portals
					if (mRoute[i].HasExitCoords)
					{
						lastPoint = curPoint;
						curPoint = CoordsToPix(mRoute[i].ExitCoords, z);

						dX = lastPoint.X - curPoint.X;
						dY = lastPoint.Y - curPoint.Y;
						dist = Math.Sqrt(dX * dX + dY * dY);
						if (dist >= 5.0)
						{
							//g.DrawLine(RouteLineBackground, lastPoint, curPoint);
							g.DrawLine(RouteLinePortal, lastPoint, curPoint);
						}
					}
				}
			}
			#endregion

			#region Draw Arrow Destination
			PointF ptf = CoordsToPix(mPluginCore.mArrowHud.DestinationCoords, z);
			if (ptf.X >= 0 && ptf.Y >= 0 && ptf.X < ClientSize.Width && ptf.Y < ClientSize.Height)
			{
				float zw = z2 * Icons.Map.ArrowDest2.Width;
				float zh = z2 * Icons.Map.ArrowDest2.Height;
				RectangleF rectf = new RectangleF(ptf.X - zw / 2, ptf.Y - zh / 2, zw, zh);
				g.DrawImage(Icons.Map.ArrowDest2, rectf);
				Rectangle rect = new Rectangle(Point.Truncate(rectf.Location), Size.Ceiling(rectf.Size));
			}
			#endregion

			#region Draw Coordinates (Part II: Labels)
			if (DrawCoords)
			{
				Region clipNS = new Region(new RectangleF(mapRect.X, mapRect.Y + CoordGutterSize, mapRect.Width, mapRect.Height - 2 * CoordGutterSize));
				Region clipEW = new Region(new RectangleF(mapRect.X + CoordGutterSize, mapRect.Y, mapRect.Width - 2 * CoordGutterSize, mapRect.Height));
				Region origClip = g.Clip;

				// Draw Labels
				for (float ns = firstTickNS, ew = firstTickEW;
						ns <= lastTickNS || ew <= lastTickEW;
						ns += mCoordTickDelta, ew += mCoordTickDelta)
				{
					PointF pos = CoordsToPix(ns, ew, z);

					string nsString = Math.Abs(ns).ToString(precision) + (ns >= 0 ? "N" : "S");
					string ewString = Math.Abs(ew).ToString(precision) + (ew >= 0 ? "E" : "W");

					SizeF nsSize = g.MeasureString(nsString, CoordTextFont);
					SizeF ewSize = g.MeasureString(ewString, CoordTextFont);

					g.Clip = clipNS;
					float nsY = pos.Y - nsSize.Width / 2;
					g.DrawString(nsString, CoordTextFont, Brushes.White, coordPadX, nsY, VerticalText);
					g.DrawString(nsString, CoordTextFont, Brushes.White,
						ClientSize.Width - coordPadX - nsSize.Height, nsY, VerticalText);

					g.Clip = coordGutter;
					float ewX = pos.X - ewSize.Width / 2;
					g.DrawString(ewString, CoordTextFont, Brushes.White, ewX, coordPadY);
					g.DrawString(ewString, CoordTextFont, Brushes.White,
						ewX, ClientSize.Height - ewSize.Height - coordPadY);
				}
				g.Clip = origClip;
			}
			#endregion

			PaintSprites(z);

			mPreviousZoomMultiplier = z;
			mLastPaintedPlayerCoords = PlayerCoords;
		}
Пример #25
0
 public void RenderAreas(RequestedTileInformation ti, Graphics g, Way way, RenderInfo ri)
 {
     bool drawOutline = true;
     if (way.WayDataBlocks != null && way.WayDataBlocks.Count > 0)
     {
         foreach (Way.WayData wd in way.WayDataBlocks)
         {
             if (wd.DataBlock[0].CoordBlock.Count > 2)
             {
                 using (GraphicsPath gp = new GraphicsPath())
                 {
                     gp.AddPolygon((from p in wd.DataBlock[0].CoordBlock select new System.Drawing.PointF((float)toRelTileX(p.Longitude, ti.X, ti.Zoom), (float)toRelTileY(p.Latitude, ti.Y, ti.Zoom))).ToArray());
                     if (wd.DataBlock.Count == 1)
                     {
                         g.FillPath(ri.Brush ?? new SolidBrush(Color.Black), gp);
                     }
                     else
                     {
                         GraphicsPath[] gpExclude = new GraphicsPath[wd.DataBlock.Count - 1];
                         for (int i = 0; i < gpExclude.Length; i++)
                         {
                             gpExclude[i] = new GraphicsPath();
                             Way.WayCoordinateBlock cb = wd.DataBlock[i + 1];
                             gpExclude[i].AddPolygon((from p in cb.CoordBlock select new System.Drawing.Point((int)toRelTileX(p.Longitude, ti.X, ti.Zoom), (int)toRelTileY(p.Latitude, ti.Y, ti.Zoom))).ToArray());
                         }
                         Region region = new Region(gp);
                         for (int i = 0; i < gpExclude.Length; i++)
                         {
                             region.Exclude(gpExclude[i]);
                         }
                         g.FillRegion(ri.Brush ?? new SolidBrush(Color.White), region);
                         for (int i = 0; i < gpExclude.Length; i++)
                         {
                             if (drawOutline && ri.Pen != null)
                             {
                                 g.DrawPolygon(ri.Pen, gpExclude[i].PathPoints);
                             }
                             gpExclude[i].Dispose();
                         }
                     }
                     if (drawOutline && ri.Pen != null)
                     {
                         g.DrawPolygon(ri.Pen, gp.PathPoints);
                     }
                 }
             }
         }
     }
 }
Пример #26
0
        /// <summary>
        /// RenderGeometryCollection
        ///     Render a GeometryCollection to Graphics
        /// </summary>
        /// <param name="geo">SqlGeography geo</param>
        /// <param name="table">string layer table</param>
        /// <param name="g">Graphics used to draw to</param>
        /// <param name="id">int record id</param>
        /// <param name="valueFill">Color the fill color style</param>
        private void RenderGeometryCollection(SqlGeography geo, string table, Graphics g, int id, Color valueFill)
        {
            int numGeom = (int)geo.STNumGeometries();
            if (geo.STNumGeometries() > 0)
            {
                for (int j = 1; j <= geo.STNumGeometries(); j++)
                {
                    if (geo.STGeometryN(j).NumRings() > 0)
                    {
                        for (int k = 1; k <= geo.STGeometryN(j).NumRings(); k++)
                        {
                            if (geo.STGeometryN(j).RingN(k).STNumPoints() > 1)
                            {
                                double lon1 = 0.0;
                                Point[] ptArray = new Point[(int)geo.STGeometryN(j).RingN(k).STNumPoints()];
                                for (int m = 1; m <= geo.STGeometryN(j).RingN(k).STNumPoints(); m++)
                                {
                                    double lat = (double)geo.STGeometryN(j).RingN(k).STPointN(m).Lat;
                                    double lon = (double)geo.STGeometryN(j).RingN(k).STPointN(m).Long;

                                    if (m > 1)
                                    {
                                        lon = HemisphereCorrection(lon, lon1, id);
                                    }

                                    LatLongToPixelXY(lat, lon, lvl, out pixelX, out pixelY);
                                    ptArray[m - 1] = new Point(pixelX - nwX, pixelY - nwY);
                                    lon1 = lon;
                                }
                                if (valueFill.Equals(Color.White)) valueFill = ColorFromInt(LayerStyle[table].fill);
                                GraphicsPath extRingRegion = new GraphicsPath();
                                extRingRegion.AddPolygon(ptArray);
                                Region region = new Region(extRingRegion);
                                g.FillRegion(new SolidBrush(valueFill), region);
                                Pen myPen = new Pen(ColorFromInt(LayerStyle[table].stroke));
                                myPen.Width = 1;
                                g.DrawPolygon(myPen, ptArray);
                            }
                        }
                    }
                }
            }
        }
        void FillRegionXor(Graphics g)
        {
            Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));

            // Create the first rectangle and draw it to the screen in black.
            g.DrawRectangle(myPen, regionRect1);
            g.FillRectangle(myBrush, regionRect1);

            myPen.Color = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
            myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);

            // create the second rectangle and draw it to the screen in red.
            g.DrawRectangle(myPen,
                            Rectangle.Round(regionRectF2));
            g.FillRectangle(myBrush, regionRect2);

            // Create a region using the first rectangle.
            Region myRegion = new Region(regionRect1);

            // Get the area of intersection for myRegion when combined with
            // complementRect.
            myRegion.Xor(regionRectF2);

            myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
            myPen.Color = Color.FromArgb(255, 0, 0x33, 0);

            g.FillRegion(myBrush, myRegion);

            title = "FillRegionXor";
        }
        void FillRegionInfinite(Graphics g)
        {
            Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));

            // Create the first rectangle and draw it to the screen in myPen color.
            g.DrawRectangle(myPen, regionRect1);

            // Create a region using the first rectangle.
            Region myRegion = new Region();

            // Fill the region which basically clears the screen to the background color.
            // Take a look at the initialize method of DrawingView.
            // This may set the rectangle to Black depending on the context
            // passed.  On a NSView set WantsLayers and the Layer Background color.
            g.FillRegion(myBrush, myRegion);

            title = "FillInfiniteRegion";
        }
        void FillRegion1(Graphics g)
        {
            Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));

            // Create the first rectangle and draw it to the screen in myPen color.
            g.DrawRectangle(myPen, regionRect1);

            myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
            myPen.Color = Color.FromArgb(255, 0, 0x33, 0);

            // create the second rectangle and draw it to the screen in red.
            g.DrawRectangle(myPen,
                            Rectangle.Round(regionRectF2));

            // Create a region using the first rectangle.
            Region myRegion = new Region(regionRect1);

            // Fill the intersection area of myRegion with blue.
            g.FillRegion(myBrush, myRegion);

            title = "FillRegion1";
        }
        public void TranslateRegion(Graphics g)
        {
            Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));

            // Create the first rectangle and draw it to the screen in blue.
            Rectangle regionRect = new Rectangle(100, 50, 100, 100);
            g.DrawRectangle(myPen, regionRect);
            g.FillRectangle (myBrush, regionRect);

            // Create a region using the first rectangle.
            Region myRegion = new Region(regionRect);

            // Apply the translation to the region.
            myRegion.Translate(150, 100);

            // Fill the transformed region with red and draw it to the screen in red.
            myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
            myPen.Color = Color.FromArgb(255, 0, 0x33, 0);
            g.FillRegion(myBrush, myRegion);

            title = "TranslateRegion";
        }
Пример #31
0
        private void DrawTabFocusIndicator(GraphicsPath tabpath, int index, Graphics graphics)
        {
            if (this._FocusTrack && this._TabControl.Focused && index == this._TabControl.SelectedIndex)
            {
                Brush focusBrush = null;
                RectangleF pathRect = tabpath.GetBounds();
                Rectangle focusRect = Rectangle.Empty;
                switch (this._TabControl.Alignment)
                {
                    case TabAlignment.Top:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, (int)pathRect.Width, 4);
                        focusBrush = new LinearGradientBrush(focusRect, this._FocusColor, SystemColors.Window, LinearGradientMode.Vertical);
                        break;
                    case TabAlignment.Bottom:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Bottom - 4, (int)pathRect.Width, 4);
                        focusBrush = new LinearGradientBrush(focusRect, SystemColors.ControlLight, this._FocusColor, LinearGradientMode.Vertical);
                        break;
                    case TabAlignment.Left:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, 4, (int)pathRect.Height);
                        focusBrush = new LinearGradientBrush(focusRect, this._FocusColor, SystemColors.ControlLight, LinearGradientMode.Horizontal);
                        break;
                    case TabAlignment.Right:
                        focusRect = new Rectangle((int)pathRect.Right - 4, (int)pathRect.Y, 4, (int)pathRect.Height);
                        focusBrush = new LinearGradientBrush(focusRect, SystemColors.ControlLight, this._FocusColor, LinearGradientMode.Horizontal);
                        break;
                }

                //	Ensure the focus stip does not go outside the tab
                Region focusRegion = new Region(focusRect);
                focusRegion.Intersect(tabpath);
                graphics.FillRegion(focusBrush, focusRegion);
                focusRegion.Dispose();
                focusBrush.Dispose();
            }
        }
        private void PaintControl(Graphics g, Rectangle clipRectangle)
        {
            if ( g == null ) return;
            if ( clipRectangle == null || clipRectangle.IsEmpty ) return;

            float distRing1 = -(this.Width * 5) / 100;          // 5%
            float distRing2 = -(this.Width * 10) / 100;         // 10%
            float distArcRing = -(this.Width * 4) / 100;        // 4%
            float distInnerCircle = -(this.Width * 30) / 100;   // 30%

            RectangleF externalRing1 = RectangleF.Inflate(this.ClientRectangle, distRing1, distRing1);
            RectangleF externalRing2 = RectangleF.Inflate(this.ClientRectangle, distRing2, distRing2);
            RectangleF innerEllipseRing = RectangleF.Inflate(this.ClientRectangle, distInnerCircle, distInnerCircle);
            RectangleF progressArcRing = RectangleF.Inflate(this.ClientRectangle, distArcRing, distArcRing);

            using ( var smoothDrawing = new SmoothDrawing(g) )
            using ( var progressCircleBrush = new SolidBrush(ProgressColor) )
            {
                // Set smooth drawing
                g.SmoothingMode = SmoothingMode.AntiAlias;

                // Paint inner circular progress
                PaintProgress(g, progressCircleBrush, innerEllipseRing, externalRing2);

                // Draw progress arc
                using ( var penProgressArc = new Pen(ProgressColor, 3.0f) )
                {
                    float progressAngle = 0;
                    if ( Style == ProgressBarStyle.Marquee )
                        progressAngle = 360 * CalcScaledValue(_marqueeValue);
                    else
                        progressAngle = 360 * ScaledValue;

                    try
                    {
                        g.DrawArc(penProgressArc, progressArcRing, 270, progressAngle);
                    }
                    catch { }
                }

                // Draw the circular extenal ring
                using ( GraphicsPath p1 = new GraphicsPath() )
                {
                    p1.AddEllipse(externalRing1);

                    using ( Region r1 = new Region(p1) )
                    using ( GraphicsPath p2 = new GraphicsPath() )
                    {

                        p2.AddEllipse(externalRing2);
                        r1.Exclude(p2);
                        g.FillRegion(Brushes.WhiteSmoke, r1);
                    }
                }

                // Draw the ring border
                g.DrawEllipse(Pens.White, externalRing1);
                g.DrawEllipse(Pens.White, externalRing2);

                // Draw the inner Ellipse
                g.FillEllipse(Brushes.WhiteSmoke, innerEllipseRing);
                g.DrawEllipse(Pens.White, innerEllipseRing);

                if ( Style != ProgressBarStyle.Marquee )
                {
                    // Draw the the progress percent
                    using ( System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat() )
                    {
                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                        drawFormat.Alignment = StringAlignment.Center;
                        drawFormat.LineAlignment = StringAlignment.Center;
                        string percentString = this.Value.ToString() + "%";
                        g.DrawString(percentString, this.Font, progressCircleBrush, this.ClientRectangle, drawFormat);
                    }
                }

            }
        }
Пример #33
0
        // While still in design this function draws directly to the component.
        // Once design is complete it will paint to a image, then the image painted to the component for a little speed boost.
        private void DrawKillCircles(Graphics g, Kill kKill, KillDisplayDetails kddKillDetails) {

            PointF pntLineStart = new PointF((float)kKill.KillerLocation.X, (float)kKill.KillerLocation.Y);
            PointF pntLineEnd = new PointF((float)kKill.VictimLocation.X, (float)kKill.VictimLocation.Y);
            PointF pntLineHalfway = new PointF(pntLineStart.X - (pntLineStart.X - pntLineEnd.X) / 2, pntLineStart.Y - (pntLineStart.Y - pntLineEnd.Y) / 2 - 3);
            PointF pntLineHalfway2 = new PointF(pntLineStart.X - (pntLineStart.X - pntLineEnd.X) / 2, pntLineStart.Y - (pntLineStart.Y - pntLineEnd.Y) / 2 - 4);

            LinearGradientBrush killBrush = this.GetKillColour(this.KillColours, kKill, kddKillDetails);

            GraphicsPath gpKillCircles = new GraphicsPath();
            gpKillCircles.AddEllipse(new Rectangle(kKill.KillerLocation.X - this.ErrorRadius, kKill.KillerLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2));
            gpKillCircles.AddEllipse(new Rectangle(kKill.VictimLocation.X - this.ErrorRadius, kKill.VictimLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2));
            gpKillCircles.FillMode = FillMode.Winding;

            //GraphicsPath gpKill = new GraphicsPath();
            GraphicsPath gpKill = (GraphicsPath)gpKillCircles.Clone();
            gpKill.AddClosedCurve(new PointF[] { pntLineStart, pntLineHalfway, pntLineEnd, pntLineHalfway2 });
            //gpKill.AddEllipse(new Rectangle(kKill.KillerLocation.X - this.ErrorRadius, kKill.KillerLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2));
            //gpKill.AddEllipse(new Rectangle(kKill.VictimLocation.X - this.ErrorRadius, kKill.VictimLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2));
            gpKill.FillMode = FillMode.Winding;

            GraphicsPath gpKillOutline = (GraphicsPath)gpKill.Clone();
            //GraphicsPath gpKillOutline = new GraphicsPath(gpKill.PathPoints, gpKill.PathTypes);
            Matrix gpKillMatrix = new Matrix();
            gpKillOutline.Widen(this.m_pTwoWidth, gpKillMatrix, 0.01F);

            Region reKillOutline = new Region(gpKillOutline);
            reKillOutline.Exclude(gpKill);
            reKillOutline.Exclude(gpKillCircles);

            Region reKill = new Region(gpKill);
            reKill.Union(gpKillCircles);

            //Region reKillDropshadow = new Region(gpKill);
            //reKillDropshadow.Union(gpKillCircles);
            //reKillDropshadow.Union(reKillOutline);
            //reKillDropshadow.Translate(0.4F, 1.0F);

            if (reKill.IsVisible(this.ClientPointToGame(this.PointToClient(Cursor.Position))) == true) {
                kddKillDetails.IsMouseOver = true;
                kddKillDetails.Opacity = 1.0F;
            }
            else {
                kddKillDetails.IsMouseOver = false;
            }

            //g.FillRegion(new SolidBrush(Color.FromArgb((int)(64.0F * kddKillDetails.Opacity), Color.Black)), reKillDropshadow);
            g.FillRegion(killBrush, reKill);
            g.FillRegion(new SolidBrush(Color.FromArgb((int)(255.0F * kddKillDetails.Opacity), Color.Black)), reKillOutline);

            if (this.LoadedMapImagePack != null) {

                Image imgDeathIcon = null;
                if (kKill.Headshot == true) {
                    imgDeathIcon = this.LoadedMapImagePack.CompensateImageRotation(this.LoadedMapImagePack.GetIcon("Headshot"));
                }
                else {
                    imgDeathIcon = this.LoadedMapImagePack.CompensateImageRotation(this.LoadedMapImagePack.GetIcon("Death"));
                }

                if (imgDeathIcon != null) {
                    ColorMatrix colormatrix = new ColorMatrix();
                    colormatrix.Matrix00 = 1.0F;
                    colormatrix.Matrix11 = 1.0F;
                    colormatrix.Matrix22 = 1.0F;
                    colormatrix.Matrix33 = kddKillDetails.Opacity;
                    colormatrix.Matrix44 = 1.0F;
                    ImageAttributes imgattr = new ImageAttributes();
                    imgattr.SetColorMatrix(colormatrix);

                    Rectangle destRect = new Rectangle((int)pntLineEnd.X - 12, (int)pntLineEnd.Y - 12, 24, 24);
                    g.DrawImage(imgDeathIcon, destRect, 0, 0, imgDeathIcon.Width, imgDeathIcon.Height, GraphicsUnit.Pixel, imgattr);

                    imgattr.Dispose();
                    imgDeathIcon.Dispose();
                }
            }

            this.DrawMapText(g, kKill.Victim.SoldierName, kKill.VictimLocation, 16, kddKillDetails.Opacity);
            this.DrawMapText(g, kKill.Killer.SoldierName, kKill.KillerLocation, 16, kddKillDetails.Opacity);

            killBrush.Dispose();
            gpKillCircles.Dispose();
            gpKill.Dispose();
            gpKillOutline.Dispose();
            gpKillMatrix.Dispose();
            reKill.Dispose();
        }
Пример #34
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Paints the current <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.
		/// </summary>
		/// <param name="graphics">The <see cref="T:System.Drawing.Graphics"></see> used to
		/// paint the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.</param>
		/// <param name="clipBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// represents the area of the <see cref="T:System.Windows.Forms.DataGridView"></see>
		/// that needs to be repainted.</param>
		/// <param name="cellBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// contains the bounds of the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>
		/// that is being painted.</param>
		/// <param name="rowIndex">The row index of the cell that is being painted.</param>
		/// <param name="cellState">A bitwise combination of
		/// <see cref="T:System.Windows.Forms.DataGridViewElementStates"></see> values that
		/// specifies the state of the cell.</param>
		/// <param name="value">The data of the <see cref="T:System.Windows.Forms.DataGridViewCell">
		/// </see> that is being painted.</param>
		/// <param name="formattedValue">The formatted data of the
		/// <see cref="T:System.Windows.Forms.DataGridViewCell"></see> that is being painted.
		/// </param>
		/// <param name="errorText">An error message that is associated with the cell.</param>
		/// <param name="cellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle">
		/// </see> that contains formatting and style information about the cell.</param>
		/// <param name="advancedBorderStyle">A
		/// <see cref="T:System.Windows.Forms.DataGridViewAdvancedBorderStyle"></see> that
		/// contains border styles for the cell that is being painted.</param>
		/// <param name="paintParts">A bitwise combination of the
		/// <see cref="T:System.Windows.Forms.DataGridViewPaintParts"></see> values that
		/// specifies which parts of the cell need to be painted.</param>
		/// ------------------------------------------------------------------------------------
		protected override void Paint(Graphics graphics, Rectangle clipBounds,
			Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
			object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
			DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
		{
			if (!m_fAllowPaint)
				return;

			// Clear the background
			Region background = new Region(cellBounds);
			background.Xor(GetCellContentDisplayRectangle(advancedBorderStyle));
			background.Intersect(clipBounds);
			graphics.FillRegion(SystemBrushes.Window, background);

			// Invalidate the view so that it redraws
			if (m_Control != null)
			{
				Point pt = m_Control.PointToClient(DataGridView.PointToScreen(new Point(clipBounds.X, clipBounds.Y)));
				Rectangle borderRect = BorderWidths(advancedBorderStyle);
				Rectangle toDraw = new Rectangle(0, 0,
					cellBounds.Width, cellBounds.Height);
				Rectangle clientClip = new Rectangle(pt.X, pt.Y, clipBounds.Width, clipBounds.Height);
				toDraw.Intersect(clientClip);
				m_Control.Invalidate(toDraw, true);
				m_Control.Update();
			}

			// Finally draw the borders
			if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
		}
        public static void UpDateIcons(double BatteryVoltage, bool OffLine, bool Mute, bool TestInProgress)
        {
            if (!TestInProgress)
            {
                if (!ModuleMain.DrainBattery.Enabled)
                {
                    ModuleMain.DrainBattery.Enabled = true;
                }
            }
            else
            {
                if (ModuleMain.DrainBattery.Enabled)
                {
                    ModuleMain.DrainBattery.Enabled = false;
                }
            }


            if (!Mute)
            {
                if (ModuleMain.MuteBeeper.Text != "Enable Beeper")
                {
                    ModuleMain.MuteBeeper.Text = "Enable Beeper";
                }
            }
            else
            {
                if (ModuleMain.MuteBeeper.Text != "Mute Beeper")
                {
                    ModuleMain.MuteBeeper.Text = "Mute Beeper";
                }
            }

            if (OffLine)
            {
                IconCalcPS.PSInfo.GetBatteryPercentage(BatteryVoltage);


                string PerSentStr = IconCalcPS.PSInfo.BatteryPercentage.ToString();

                if (IconCalcPS.PSInfo.BatteryPercentage < 100)
                {
                    if (IconCalcPS.PSInfo.BatteryPercentage < 10)
                    {
                        if (IconCalcPS.PSInfo.BatteryPercentage < 1)
                        {
                            PerSentStr = "   ";
                        }
                        else
                        {
                            PerSentStr = "  " + PerSentStr;
                        }
                    }
                    else
                    {
                        PerSentStr = " " + PerSentStr;
                    }
                }

                System.Drawing.Font       drawFont       = new System.Drawing.Font("Consolas", 70, FontStyle.Bold);
                System.Drawing.SolidBrush DrawBrushRed   = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
                System.Drawing.SolidBrush DrawBrushGreen = new System.Drawing.SolidBrush(System.Drawing.Color.Lime);
                System.Drawing.SolidBrush DrawBrushWhite = new System.Drawing.SolidBrush(System.Drawing.Color.White);

                int    PercentageBattery1         = IconCalcPS.PSInfo.BatteryPercentage1;
                Bitmap bitmap1                    = new Bitmap(100, 100);
                System.Drawing.Graphics graphics1 = System.Drawing.Graphics.FromImage(bitmap1);
                //graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                System.Drawing.Rectangle DrawRectRed1   = new Rectangle(0, 100 - PercentageBattery1, 100, PercentageBattery1);
                System.Drawing.Region    DrawRegionRed1 = new System.Drawing.Region(DrawRectRed1);
                graphics1.FillRegion(DrawBrushGreen, DrawRegionRed1);
                System.Drawing.Rectangle DrawRectGreen1   = new Rectangle(0, 0, 100, 100 - PercentageBattery1);
                System.Drawing.Region    DrawRegionGreen1 = new System.Drawing.Region(DrawRectGreen1);
                graphics1.FillRegion(DrawBrushRed, DrawRegionGreen1);
                graphics1.DrawString(PerSentStr[0].ToString(), drawFont, DrawBrushWhite, 4, 1);
                Icon createdIcon1 = Icon.FromHandle(bitmap1.GetHicon());
                UPSNotifyIcon1.Icon = createdIcon1;


                int    PercentageBattery2         = IconCalcPS.PSInfo.BatteryPercentage2;
                Bitmap bitmap2                    = new Bitmap(100, 100);
                System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap2);
                //graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                System.Drawing.Rectangle DrawRectRed2   = new Rectangle(0, 100 - PercentageBattery2, 100, PercentageBattery2);
                System.Drawing.Region    DrawRegionRed2 = new System.Drawing.Region(DrawRectRed2);
                graphics2.FillRegion(DrawBrushGreen, DrawRegionRed2);
                System.Drawing.Rectangle DrawRectGreen2   = new Rectangle(0, 0, 100, 100 - PercentageBattery2);
                System.Drawing.Region    DrawRegionGreen2 = new System.Drawing.Region(DrawRectGreen2);
                graphics2.FillRegion(DrawBrushRed, DrawRegionGreen2);
                graphics2.DrawString(PerSentStr[1].ToString(), drawFont, DrawBrushWhite, 4, 1);
                Icon createdIcon2 = Icon.FromHandle(bitmap2.GetHicon());
                UPSNotifyIcon2.Icon = createdIcon2;


                int    PercentageBattery3         = IconCalcPS.PSInfo.BatteryPercentage3;
                Bitmap bitmap3                    = new Bitmap(100, 100);
                System.Drawing.Graphics graphics3 = System.Drawing.Graphics.FromImage(bitmap3);
                //graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                System.Drawing.Rectangle DrawRectRed3   = new Rectangle(0, 100 - PercentageBattery3, 100, PercentageBattery3);
                System.Drawing.Region    DrawRegionRed3 = new System.Drawing.Region(DrawRectRed3);
                graphics3.FillRegion(DrawBrushGreen, DrawRegionRed3);
                System.Drawing.Rectangle DrawRectGreen3   = new Rectangle(0, 0, 100, 100 - PercentageBattery3);
                System.Drawing.Region    DrawRegionGreen3 = new System.Drawing.Region(DrawRectGreen3);
                graphics3.FillRegion(DrawBrushRed, DrawRegionGreen3);
                graphics3.DrawString(PerSentStr[2].ToString(), drawFont, DrawBrushWhite, 4, 1);
                Icon createdIcon3 = Icon.FromHandle(bitmap3.GetHicon());
                UPSNotifyIcon3.Icon = createdIcon3;


                int    PercentageBattery4         = IconCalcPS.PSInfo.BatteryPercentage4;
                Bitmap bitmap4                    = new Bitmap(100, 100);
                System.Drawing.Graphics graphics4 = System.Drawing.Graphics.FromImage(bitmap4);
                //graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                System.Drawing.Rectangle DrawRectRed4   = new Rectangle(0, 100 - PercentageBattery4, 100, PercentageBattery4);
                System.Drawing.Region    DrawRegionRed4 = new System.Drawing.Region(DrawRectRed4);
                graphics4.FillRegion(DrawBrushGreen, DrawRegionRed4);
                System.Drawing.Rectangle DrawRectGreen4   = new Rectangle(0, 0, 100, 100 - PercentageBattery4);
                System.Drawing.Region    DrawRegionGreen4 = new System.Drawing.Region(DrawRectGreen4);
                graphics4.FillRegion(DrawBrushRed, DrawRegionGreen4);
                graphics4.DrawString("%", drawFont, DrawBrushWhite, 0, 2);
                Icon createdIcon4 = Icon.FromHandle(bitmap4.GetHicon());
                UPSNotifyIcon4.Icon = createdIcon4;


                UPSNotifyIcon4.Visible = true;
                UPSNotifyIcon3.Visible = true;
                UPSNotifyIcon2.Visible = true;
                UPSNotifyIcon1.Visible = true;
                UPSNotifyIcon.Icon     = Properties.Resources.UtilityFailed;
                UPSNotifyIcon.Text     = "";
            }
            else
            {
                UPSNotifyIcon1.Visible = false;
                UPSNotifyIcon2.Visible = false;
                UPSNotifyIcon3.Visible = false;
                UPSNotifyIcon4.Visible = false;
                UpDateChargingIcon(BatteryVoltage, OffLine);
            }
        }
Пример #36
0
        /// <summary>
        /// The draw tab focus indicator.
        /// </summary>
        /// <param name="brush">
        /// The brush.
        /// </param>
        /// <param name="tabpath">
        /// The tabpath.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <param name="graphics">
        /// The graphics.
        /// </param>
        private void DrawTabFocusIndicator(Brush brush, GraphicsPath tabpath, int index, Graphics graphics)
        {
            if (this.Focused && index == this.SelectedIndex)
            {
                RectangleF pathRect = tabpath.GetBounds();
                Rectangle focusRect = Rectangle.Empty;
                switch (this.Alignment)
                {
                    case TabAlignment.Top:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, (int)pathRect.Width, this.IndicatorWidth);
                        break;
                    case TabAlignment.Bottom:
                        focusRect = new Rectangle(
                            (int)pathRect.X,
                            (int)pathRect.Bottom - this.IndicatorWidth,
                            (int)pathRect.Width,
                            this.IndicatorWidth);
                        break;
                    case TabAlignment.Left:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, this.IndicatorWidth, (int)pathRect.Height);
                        break;
                    case TabAlignment.Right:
                        focusRect = new Rectangle(
                            (int)pathRect.Right - this.IndicatorWidth,
                            (int)pathRect.Y,
                            this.IndicatorWidth,
                            (int)pathRect.Height);
                        break;
                }

                // 	Ensure the focus stip does not go outside the tab
                using (var focusRegion = new Region(focusRect))
                {
                    focusRegion.Intersect(tabpath);
                    graphics.FillRegion(brush, focusRegion);
                }
            }
        }
Пример #37
0
        /// <summary>
        /// Paints the shape on the canvas
        /// </summary>
        /// <param name="g"></param>
        ///

        public override void Paint(System.Drawing.Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle toggleNode = Rectangle.Empty;             //the [+] [-]

            Point[] pts = new Point[12]
            {
                new Point(rectangle.X, rectangle.Y),                        //0
                new Point(rectangle.X + bshift, rectangle.Y),               //1
                new Point(rectangle.Right - bshift, rectangle.Y),           //2
                new Point(rectangle.Right, rectangle.Y),                    //3
                new Point(rectangle.Right, rectangle.Y + bshift),           //4
                new Point(rectangle.Right, rectangle.Bottom - bshift),      //5
                new Point(rectangle.Right, rectangle.Bottom),               //6
                new Point(rectangle.Right - bshift, rectangle.Bottom),      //7
                new Point(rectangle.X + bshift, rectangle.Bottom),          //8
                new Point(rectangle.X, rectangle.Bottom),                   //9
                new Point(rectangle.X, rectangle.Bottom - bshift),          //10
                new Point(rectangle.X, rectangle.Y + bshift),               //11
            };
            path = new GraphicsPath();
            path.AddBezier(pts[11], pts[0], pts[0], pts[1]);
            path.AddLine(pts[1], pts[2]);
            path.AddBezier(pts[2], pts[3], pts[3], pts[4]);
            path.AddLine(pts[4], pts[5]);
            path.AddBezier(pts[5], pts[6], pts[6], pts[7]);
            path.AddLine(pts[7], pts[8]);
            path.AddBezier(pts[8], pts[9], pts[9], pts[10]);
            path.AddLine(pts[10], pts[11]);
            path.CloseFigure();
            region = new Region(path);

            shapeBrush = new LinearGradientBrush(rectangle, this.shapeColor, Color.WhiteSmoke, 0f);

            // start Draw Shadow
            shadow = region.Clone();
            shadow.Translate(5, 5);


            //add the amount of children
            if (childNodes.Count > 0)
            {
                plus = " [" + childNodes.Count + "]";
            }
            else
            {
                plus = "";
            }

            g.FillRegion(new SolidBrush(Color.Gainsboro), shadow);
            //g.DrawPath(new Pen(Color.Gainsboro,1), shadow);
            //End Draw Shadow

            g.FillRegion(shapeBrush, region);



            if (hovered || isSelected)
            {
                pen = thickPen;
            }
            else
            {
                pen = blackPen;
            }

            g.DrawPath(pen, path);

            if (text != string.Empty)
            {
                g.DrawString(text + plus, font, Brushes.Black, rectangle.X + 5, rectangle.Y + 5);
            }



            //draw the [+] expansion shape
            if (childNodes.Count > 0)
            {
                switch (site.LayoutDirection)
                {
                case TreeDirection.Vertical:
                    toggleNode = new Rectangle(Left + this.Width / 2 - 5, Bottom, 10, 10);
                    break;

                case TreeDirection.Horizontal:
                    toggleNode = new Rectangle(Right, Top + Height / 2 - 5, 10, 10);
                    break;
                }


                //Draw [ ]
                g.FillRectangle(new SolidBrush(Color.White), toggleNode);
                g.DrawRectangle(blackPen, toggleNode);

                //Draw -
                g.DrawLine(blackPen, (toggleNode.X + 2), (toggleNode.Y + (toggleNode.Height / 2)), (toggleNode.X + (toggleNode.Width - 2)), (toggleNode.Y + (toggleNode.Height / 2)));

                if (!this.Expanded)
                {
                    //Draw |
                    g.DrawLine(blackPen, (toggleNode.X + (toggleNode.Width / 2)), (toggleNode.Y + 2), (toggleNode.X + (toggleNode.Width / 2)), (toggleNode.Y + (toggleNode.Height - 2)));
                }
            }
        }
        private static void WriteUrlOnImage(Graphics g2, string myLocalLink, int URLExtraHeight, int widthsize)
        {
            // Backfill URL paint location
            var whiteBrush = new SolidBrush(Color.White);
            var fillRect = new Rectangle(0, 0, widthsize, URLExtraHeight + 2);
            var fillRegion = new Region(fillRect);
            g2.FillRegion(whiteBrush, fillRegion);

            var drawBrushURL = new SolidBrush(Color.Black);
            var drawFont = new Font("Arial", 12);
            var drawFormat = new StringFormat {FormatFlags = StringFormatFlags.FitBlackBox};

            g2.DrawString(myLocalLink, drawFont, drawBrushURL, 0, 0, drawFormat);
        }
        protected virtual void DrawTabs(Graphics gfx, int nIndex)
        {
            var currentTab = GetTabRect(nIndex);

            /* Eğer ilk tabın indisi 0 ise Rectangle'ın Left location değerini belirtilen oranda artırıyoruz.
            Aynı zamanda Tab genişliğinide gene belirlenen oran kadar küçültüyoruz. */
            if (nIndex == 0)
            {
                currentTab.X += _tabHOffset;
                currentTab.Width -= _tabHOffset;
            }

            currentTab.Y = _alignments == TabAlignments.Top ? currentTab.Y + 3 : currentTab.Y - 4;

            if (nIndex == SelectedIndex)
            {
                var rect = ClientRectangle;
                var tabArea = DisplayRectangle;

                rect.Inflate(-1, -1);
                tabArea.Inflate(Value - 1, Value - 1);

                DashStyle borderStyle;
                switch (_borderStyle)
                {
                    case ControlBorderStyle.Dashed:
                        borderStyle = DashStyle.Dash;
                        break;

                    case ControlBorderStyle.Dotted:
                        borderStyle = DashStyle.Dot;
                        break;

                    default:
                        borderStyle = DashStyle.Solid;
                        break;
                }

                var closeImg = GetCloseTabImage();
                LinearGradientBrush pathBrush = null;
                switch (_alignments)
                {
                    case TabAlignments.Top:

                        if (((TabPageEx)SelectedTab).IsClosable)
                        {
                            conditionRectangleArray[0] = new Rectangle // Object Initializer
                            {
                                X = currentTab.Right - (closeImg.Width + 5),
                                Y = (currentTab.Height - closeImg.Height) / 2 + 5,
                                Width = closeImg.Width,
                                Height = closeImg.Height,
                            };
                        }
                        else
                        {
                            conditionRectangleArray[0] = new Rectangle // Object Initializer
                            {
                                X = currentTab.Right + 5,
                                Y = currentTab.Height / 2 + 5,
                                Width = 0,
                                Height = 0,
                            };
                        }

                        using (var pen1 = new Pen(colorArray[2]))
                        using (var gp = new GraphicsPath())
                        {
                            pen1.DashStyle = borderStyle;
                            if (!_conditionBooleanArray[1] && _conditionBooleanArray[2])
                            {
                                // Create an open figure
                                gp.AddLine(rect.Left, tabArea.Top - 4, currentTab.Left, tabArea.Top - 4);
                                gp.AddLine(currentTab.Left, currentTab.Top, currentTab.Right - 1, currentTab.Top);
                                gp.AddLine(currentTab.Right - 1, tabArea.Top - 4, rect.Right, tabArea.Top - 4);
                                gp.AddLine(rect.Right, rect.Bottom, rect.Left, rect.Bottom);
                                gp.CloseFigure();

                                using (var reg = new Region(gp))
                                {
                                    reg.Exclude(tabArea);
                                    pathBrush = new LinearGradientBrush(gp.GetBounds(), _tabGradient.ColorStart, _tabGradient.ColorEnd, _tabGradient.GradientStyle);
                                    var bl = new Blend(2) { Factors = new[] { 0.3F, 1.0F }, Positions = new[] { 0.0F, 1.0F } };
                                    pathBrush.Blend = bl;
                                    gfx.FillRegion(pathBrush, reg);
                                }
                            }
                            else
                            {
                                // Create an open figure
                                gp.AddLine(rect.Left, tabArea.Top, rect.Left, tabArea.Top - 4);
                                gp.AddLine(currentTab.Left, tabArea.Top - 4, currentTab.Left, currentTab.Top);
                                gp.AddLine(currentTab.Right - 1, currentTab.Top, currentTab.Right - 1, tabArea.Top - 4);
                                gp.AddLine(rect.Right, tabArea.Top - 4, rect.Right, tabArea.Top);
                                gp.CloseFigure();

                                pathBrush = new LinearGradientBrush(gp.GetBounds(), _tabGradient.ColorStart, _tabGradient.ColorEnd, _tabGradient.GradientStyle);
                                var bl = new Blend(2) { Factors = new[] { 0.3F, 1.0F }, Positions = new[] { 0.0F, 1.0F } };
                                pathBrush.Blend = bl;
                                gfx.FillPath(pathBrush, gp);
                            }

                            if (_tabStyles == TabStyle.OfficeXp)
                            {
                                gp.Reset();
                                gp.AddLine(currentTab.Left, currentTab.Top + 3, currentTab.Left, currentTab.Top);
                                gp.AddLine(currentTab.Right - 1, currentTab.Top, currentTab.Right - 1, currentTab.Top + 3);
                                gp.CloseFigure();

                                var graphicsMode = gfx.SmoothingMode;
                                using (var brush = new LinearGradientBrush(gp.GetBounds(), Color.OrangeRed, Color.SandyBrown, LinearGradientMode.Vertical))
                                {
                                    gfx.SmoothingMode = SmoothingMode.AntiAlias;
                                    var bl = new Blend(2) { Factors = new[] { 0.1F, 1.0F }, Positions = new[] { 0.0F, 1.0F } };
                                    brush.Blend = bl;

                                    gfx.FillPath(brush, gp);
                                }

                                gfx.SmoothingMode = graphicsMode;
                            }

                            gp.Reset();
                            if (nIndex == 0 && _tabHOffset <= -1)
                                gp.AddLine(currentTab.Left, tabArea.Top - 4, currentTab.Left, tabArea.Top);
                            else
                                gp.AddLine(rect.Left, tabArea.Top - 4, currentTab.Left, tabArea.Top - 4);

                            gp.AddLine(currentTab.Left, currentTab.Top, currentTab.Right - 1, currentTab.Top);
                            gp.AddLine(currentTab.Right - 1, tabArea.Top - 4, rect.Right - 1, tabArea.Top - 4);

                            // Create another figure
                            gp.StartFigure();
                            if (!_conditionBooleanArray[1] && _conditionBooleanArray[2])
                            {
                                var innerRct = tabArea;
                                innerRct.Width -= 1;
                                innerRct.Height -= 1;
                                gp.AddRectangle(innerRct);
                            }
                            else
                                gp.AddLine(rect.Left, tabArea.Top, rect.Right - 1, tabArea.Top);
                            gfx.DrawPath(pen1, gp);

                            // Draw tab close image.
                            if (((TabPageEx)SelectedTab).IsClosable && conditionButtonStateArray[0] == ButtonState.Normal)
                            {
                                using (var attributes = new ImageAttributes())
                                {
                                    var map = new[]
                                    {
                                        new ColorMap {OldColor = Color.White, NewColor = Color.Transparent},
                                        new ColorMap {OldColor = Color.Black, NewColor = colorArray[3]}
                                    };

                                    attributes.SetRemapTable(map);
                                    gfx.DrawImage(closeImg, conditionRectangleArray[0], 0, 0, closeImg.Width, closeImg.Height, GraphicsUnit.Pixel, attributes);
                                }
                            }
                            else if (((TabPageEx)SelectedTab).IsClosable)
                                gfx.DrawImageUnscaled(closeImg, conditionRectangleArray[0]);

                            closeImg.Dispose();
                        }
                        break;

                    case TabAlignments.Bottom:

                        if (((TabPageEx)SelectedTab).IsClosable)
                        {
                            conditionRectangleArray[0] = new Rectangle // Object Initializer
                            {
                                X = currentTab.Right - (closeImg.Width + 5),
                                Y = currentTab.Top + (currentTab.Height - closeImg.Height) / 2 + 2,
                                Width = closeImg.Width,
                                Height = closeImg.Height,
                            };
                        }
                        else
                        {
                            conditionRectangleArray[0] = new Rectangle // Object Initializer
                            {
                                X = currentTab.Right + (closeImg.Width + 5),
                                Y = currentTab.Top + (currentTab.Height + closeImg.Height) / 2 + 2,
                                Width = closeImg.Width,
                                Height = closeImg.Height,
                            };
                        }

                        using (var pen1 = new Pen(colorArray[2]))
                        using (var gp = new GraphicsPath())
                        {
                            pen1.DashStyle = borderStyle;
                            if (!_conditionBooleanArray[1] && _conditionBooleanArray[2])
                            {
                                // Create an open figure
                                gp.AddLine(rect.Left, tabArea.Bottom + 3, currentTab.Left, tabArea.Bottom + 3);
                                gp.AddLine(currentTab.Left, currentTab.Bottom, currentTab.Right - 1, currentTab.Bottom);
                                gp.AddLine(currentTab.Right - 1, tabArea.Bottom + 3, rect.Right, tabArea.Bottom + 3);
                                gp.AddLine(rect.Right, rect.Top, rect.Left, rect.Top);
                                gp.CloseFigure();

                                using (var reg = new Region(gp))
                                {
                                    reg.Exclude(tabArea);
                                    pathBrush = new LinearGradientBrush(gp.GetBounds(), _tabGradient.ColorEnd, _tabGradient.ColorStart, _tabGradient.GradientStyle);
                                    var bl = new Blend(2) { Factors = new[] { 0.3F, 1.0F }, Positions = new[] { 0.0F, 1.0F } };
                                    pathBrush.Blend = bl;
                                    gfx.FillRegion(pathBrush, reg);
                                }
                            }
                            else
                            {
                                // Create an open figure
                                gp.AddLine(rect.Left, tabArea.Bottom - 1, rect.Left, tabArea.Bottom + 3);
                                gp.AddLine(currentTab.Left, tabArea.Bottom + 3, currentTab.Left, currentTab.Bottom);
                                gp.AddLine(currentTab.Right - 1, currentTab.Bottom, currentTab.Right - 1, tabArea.Bottom + 3);
                                gp.AddLine(rect.Right, tabArea.Bottom + 3, rect.Right, tabArea.Bottom - 1);
                                gp.CloseFigure();

                                pathBrush = new LinearGradientBrush(gp.GetBounds(), _tabGradient.ColorEnd, _tabGradient.ColorStart, _tabGradient.GradientStyle);
                                var bl = new Blend(2) { Factors = new[] { 0.3F, 1.0F }, Positions = new[] { 0.0F, 1.0F } };
                                pathBrush.Blend = bl;
                                gfx.FillPath(pathBrush, gp);
                            }

                            if (_tabStyles == TabStyle.OfficeXp)
                            {
                                gp.Reset();
                                gp.AddLine(currentTab.Left, currentTab.Bottom - 3, currentTab.Left, currentTab.Bottom);
                                gp.AddLine(currentTab.Right - 1, currentTab.Bottom, currentTab.Right - 1, currentTab.Bottom - 3);
                                gp.CloseFigure();

                                var graphicsMode = gfx.SmoothingMode;
                                using (var brush = new LinearGradientBrush(gp.GetBounds(), Color.SandyBrown, Color.OrangeRed, LinearGradientMode.Vertical))
                                {
                                    gfx.SmoothingMode = SmoothingMode.AntiAlias;
                                    var bl = new Blend(2) { Factors = new[] { 0.3F, 1.0F }, Positions = new[] { 0.0F, 1.0F } };
                                    brush.Blend = bl;
                                    gfx.FillPath(brush, gp);
                                }

                                gfx.SmoothingMode = graphicsMode;
                            }

                            gp.Reset();
                            if (nIndex == 0 && _tabHOffset <= -1)
                                gp.AddLine(currentTab.Left, tabArea.Bottom - 1, currentTab.Left, currentTab.Bottom - 1);
                            else
                                gp.AddLine(rect.Left, tabArea.Bottom + 3, currentTab.Left, tabArea.Bottom + 3);

                            gp.AddLine(currentTab.Left, currentTab.Bottom, currentTab.Right - 1, currentTab.Bottom);
                            gp.AddLine(currentTab.Right - 1, tabArea.Bottom + 3, rect.Right - 1, tabArea.Bottom + 3);

                            // Create another figure
                            gp.StartFigure();
                            if (!_conditionBooleanArray[1] && _conditionBooleanArray[2])
                            {
                                var innerRct = tabArea;
                                innerRct.Width -= 1;
                                innerRct.Height -= 1;
                                gp.AddRectangle(innerRct);
                            }
                            else
                                gp.AddLine(rect.Left, tabArea.Bottom - 1, rect.Right - 1, tabArea.Bottom - 1);

                            gfx.DrawPath(pen1, gp);

                            // Draw tab close image.
                            if (((TabPageEx)SelectedTab).IsClosable && conditionButtonStateArray[0] == ButtonState.Normal)
                            {
                                using (var attributes = new ImageAttributes())
                                {
                                    var map = new[]
                                    {
                                        new ColorMap {OldColor = Color.White, NewColor = Color.Transparent},
                                        new ColorMap {OldColor = Color.Black, NewColor = colorArray[3]}
                                    };

                                    attributes.SetRemapTable(map);
                                    gfx.DrawImage(closeImg, conditionRectangleArray[0], 0, 0, closeImg.Width, closeImg.Height, GraphicsUnit.Pixel, attributes);
                                }
                            }
                            else if (((TabPageEx)SelectedTab).IsClosable)
                                gfx.DrawImageUnscaled(closeImg, conditionRectangleArray[0]);

                            closeImg.Dispose();
                        }
                        break;
                }

                if (pathBrush != null) pathBrush.Dispose();
                else throw new NullReferenceException("pathBrush didn't get initialized");
            }
            else
            {
                if (_conditionBooleanArray[5])
                {
                    // Draw 3D Border Line for between tab pages.
                    using (var tabBorder = new Custom3DBorder(gfx))
                    {
                        if (nIndex > SelectedIndex && nIndex != TabCount - 1)
                        {
                            if (_alignments == TabAlignments.Top)
                                tabBorder.Draw3DLine(currentTab.Right, currentTab.Top + 3, currentTab.Right, currentTab.Bottom - 11, ThreeDStyle.Groove, 1);
                            else
                                tabBorder.Draw3DLine(currentTab.Right, currentTab.Bottom - 5, currentTab.Right, currentTab.Top + 13, ThreeDStyle.Groove, 1);
                        }
                        else if (nIndex < SelectedIndex && nIndex != 0)
                        {
                            if (_alignments == TabAlignments.Top)
                                tabBorder.Draw3DLine(currentTab.Left, currentTab.Top + 3, currentTab.Left, currentTab.Bottom - 11, ThreeDStyle.Groove, 1);
                            else
                                tabBorder.Draw3DLine(currentTab.Left, currentTab.Bottom - 5, currentTab.Left, currentTab.Top + 13, ThreeDStyle.Groove, 1);
                        }
                    }
                }
            }

            //Draw Tab's Icon Image at the ImageList.
            if (ImageList != null && !TabPages[nIndex].ImageIndex.Equals(-1))
            {
                if (TabPages[nIndex].ImageIndex <= ImageList.Images.Count - 1)
                {
                    var img = ImageList.Images[TabPages[nIndex].ImageIndex];
                    Rectangle currentImgRct;

                    if (_alignments == TabAlignments.Top)
                    {
                        currentImgRct = new Rectangle //Object Initializer
                        {
                            X = currentTab.X + 5,
                            Y = (currentTab.Height - img.Height) / 2 + 4,
                            Width = img.Width,
                            Height = img.Height
                        };

                        currentTab = new Rectangle
                        {
                            X = currentTab.X + 5 + img.Width,
                            Y = currentTab.Y,
                            Width = currentTab.Width - (5 + img.Width),
                            Height = currentTab.Height
                        };
                    }
                    else
                    {
                        currentImgRct = new Rectangle //Object Initializer
                        {
                            X = currentTab.X + 5,
                            Y = currentTab.Bottom - (img.Height + 6),
                            Width = img.Width,
                            Height = img.Height
                        };

                        currentTab = new Rectangle
                        {
                            X = currentTab.X + 5 + img.Width,
                            Y = currentTab.Y + 5,
                            Width = currentTab.Width - (5 + img.Width),
                            Height = currentTab.Height - 5
                        };
                    }

                    gfx.DrawImageUnscaled(img, currentImgRct);
                    img.Dispose();
                }
            }
            else
            {
                if (_alignments == TabAlignments.Top)
                {
                    currentTab = new Rectangle
                    {
                        X = currentTab.X + 5,
                        Y = currentTab.Y,
                        Width = currentTab.Width - 5,
                        Height = currentTab.Height
                    };
                }
                else
                {
                    currentTab = new Rectangle
                    {
                        X = currentTab.X + 5,
                        Y = currentTab.Y + 5,
                        Width = currentTab.Width - 5,
                        Height = currentTab.Height - 5
                    };
                }
            }

            //Draw Text on the Tabs
            using (var brush = new SolidBrush(TabPages[nIndex].Enabled ? (nIndex == SelectedIndex ? _tabGradient.TabPageSelectedTextColor : _tabGradient.TabPageTextColor) : Color.Gray))
            {
                using (var format = new StringFormat(StringFormatFlags.LineLimit))
                {
                    format.Trimming = StringTrimming.EllipsisCharacter;
                    format.HotkeyPrefix = HotkeyPrefix.Show;
                    if (((TabPageEx)SelectedTab).IsClosable)
                    {
                        if (nIndex == SelectedIndex)
                        {
                            currentTab.Width -= conditionRectangleArray[0].Width;
                            format.Alignment = StringAlignment.Near;
                        }
                        else
                        {
                            if (_conditionBooleanArray[5] || nIndex == 0)
                            {
                                currentTab.X -= 5;
                                currentTab.Width += 5;
                                format.Alignment = StringAlignment.Center;
                            }
                            else
                            {
                                currentTab.X += 8;
                                currentTab.Width -= 8;
                            }
                        }
                    }
                    else
                    {
                        format.Alignment = StringAlignment.Center;
                    }

                    format.LineAlignment = StringAlignment.Center;

                    var currentFont = TabPages[nIndex].Font;
                    if (nIndex == SelectedIndex)
                        currentFont = new Font(currentFont, _tabGradient.SelectedTabFontStyle);

                    gfx.DrawString(TabPages[nIndex].Text, currentFont, brush, currentTab, format);
                }
            }
        }
Пример #40
0
        private void HighlightString(Graphics g, PageText dtext, RectangleF r, Font f, StringFormat sf)
        {
            if (_HighlightText == null || _HighlightText.Length == 0)
                return;         // nothing to highlight
            bool bhighlightItem = dtext == _HighlightItem ||
                    (_HighlightItem != null && dtext.HtmlParent == _HighlightItem);
            if (!(_HighlightAll || bhighlightItem))
                return;         // not highlighting all and not on current highlight item

            string hlt = _HighlightCaseSensitive ? _HighlightText : _HighlightText.ToLower();
            string text = _HighlightCaseSensitive ? dtext.Text : dtext.Text.ToLower();

            if (text.IndexOf(hlt) < 0)
                return;         // string not in text

            StringFormat sf2 = null;
            try
            {
                // Create a CharacterRange array with the highlight location and length
                // Handle multiple occurences of text
                List<CharacterRange> rangel = new List<CharacterRange>();
                int loc = text.IndexOf(hlt);
                int hlen = hlt.Length;
                int len = text.Length;
                while (loc >= 0)
                {
                    rangel.Add(new CharacterRange(loc, hlen));
                    if (loc + hlen < len)  // out of range of text
                        loc = text.IndexOf(hlt, loc + hlen);
                    else
                        loc = -1;
                }

                if (rangel.Count <= 0)      // we should have gotten one; but
                    return;

                CharacterRange[] ranges = rangel.ToArray();

                // Construct a new StringFormat object.
                sf2 = sf.Clone() as StringFormat;

                // Set the ranges on the StringFormat object.
                sf2.SetMeasurableCharacterRanges(ranges);

                // Get the Regions to highlight by calling the
                // MeasureCharacterRanges method.
                if (r.Width <= 0 || r.Height <= 0)
                {
                    SizeF ts = g.MeasureString(dtext.Text, f);
                    r.Height = ts.Height;
                    r.Width = ts.Width;
                }
                Region[] charRegion = g.MeasureCharacterRanges(dtext.Text, f, r, sf2);

                // Fill in the region using a semi-transparent color to highlight
                foreach (Region rg in charRegion)
                {
                    Color hl = bhighlightItem ? _HighlightItemColor : _HighlightAllColor;
                    g.FillRegion(new SolidBrush(Color.FromArgb(50, hl)), rg);
                }
            }
            catch { }   // if highlighting fails we don't care; need to continue
            finally
            {
                if (sf2 != null)
                    sf2.Dispose();
            }
        }
        public void TransformRegion(Graphics g)
        {
            Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));

            // Create the first rectangle and draw it to the screen in blue.
            Rectangle regionRect = new Rectangle(100, 50, 100, 100);
            g.DrawRectangle(myPen, regionRect);
            g.FillRectangle (myBrush, regionRect);

            // Create a region using the first rectangle.
            Region myRegion = new Region(regionRect);

            // Create a transform matrix and set it to have a 45 degree

            // rotation.
            Matrix transformMatrix = new Matrix();
            transformMatrix.RotateAt(45, new Point(100, 50));

            // Apply the transform to the region.
            myRegion.Transform(transformMatrix);

            // Fill the transformed region with red and draw it to the screen
            // in color.
            myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
            myPen.Color = Color.FromArgb(255, 0, 0x33, 0);
            g.FillRegion(myBrush, myRegion);

            title = "TransformRegion";
        }