Offset() public method

Adjusts the location of this rectangle by the specified amount.
public Offset ( PointF pos ) : void
pos PointF
return void
        public override void LoadView()
        {
            View = new UIView();
            View.BackgroundColor = UIColor.LightGray;

            RectangleF f = new RectangleF(10,10,300, 44);
            UsernameTextField = new UITextField(f) {
                Placeholder = "Username",
                BorderStyle = UITextBorderStyle.RoundedRect,
                AutocapitalizationType = UITextAutocapitalizationType.None,
                AutocorrectionType = UITextAutocorrectionType.No
            };
            View.AddSubview(UsernameTextField);

            f.Offset(new PointF(0, f.Height + 10));
            PasswordTextField = new UITextField(f) {
                Placeholder = "Password",
                BorderStyle = UITextBorderStyle.RoundedRect,
                SecureTextEntry = true
            };
            View.AddSubview(PasswordTextField);

            f.Offset(new PointF(0, f.Height + 10));
            UIButton button = UIButton.FromType(UIButtonType.RoundedRect);
            button.SetTitle("Login", UIControlState.Normal);
            button.Frame = f;
            button.TouchUpInside += LoginHandler;
            View.AddSubview(button);
        }
Exemplo n.º 2
0
        public static Image ScaleImageTo16x16(Image img, bool bForceNewObject)
        {
            if (img == null) { Debug.Assert(false); return null; }

            int w = img.Width;
            int h = img.Height;
            int sw = 16;
            int sh = 16;

            if ((w == sw) && (h == sh) && !bForceNewObject)
                return img;

            Bitmap bmp = new Bitmap(sw, sh, img.PixelFormat);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                RectangleF rSource = new RectangleF(0, 0, w, h);
                RectangleF rDest = new RectangleF(0, 0, sw, sh);

                // Prevent border drawing bug
                rSource.Offset(-0.5f, -0.5f);

                g.DrawImage(img, rDest, rSource, GraphicsUnit.Pixel);
            }

            return bmp;
        }
Exemplo n.º 3
0
		public override void Render(View3D view, Viewport viewport)
		{
			m_View.Resize(new System.Drawing.Rectangle(0, 0, (int)viewport.Width, (int)viewport.Height), (int)viewport.Width, (int)viewport.Height);

			float x, y, w, h;

			float widthPerImage = (float)(viewport.Width / m_KinectColorImages.Count);
			float heightPerImage = (widthPerImage / 4) * 3;

			RectangleF imageBounds = new RectangleF(0, (viewport.Height - heightPerImage) * 0.5f, widthPerImage, heightPerImage);

			switch (KinectImageMode)
			{
				case KinectImageMode.Color:
					foreach (KinectColorImageTexture color in m_KinectColorImages)
					{
						UiStyleHelper.CovertToVertCoords(imageBounds, m_View.WindowSize, m_View.PixelSize, out x, out y, out w, out h);
						color.Rectangle = new RectangleF(x, y, w, h);

						color.Update();
						color.Render(m_View);

						imageBounds.Offset(widthPerImage, 0);
					}
					break;
				case KinectImageMode.RawDepth:
				case KinectImageMode.DepthBackgroundImage:
				case KinectImageMode.DepthBackgroundRemoved:
					foreach (KinectDepthImageTexture depth in m_KinectDepthImages)
					{
						UiStyleHelper.CovertToVertCoords(imageBounds, m_View.WindowSize, m_View.PixelSize, out x, out y, out w, out h);
						depth.Rectangle = new RectangleF(x, y, w, h);

						switch (KinectImageMode)
						{
							case KinectImageMode.RawDepth:
								depth.ImageType = KinectDepthImageType.RawDepth;
								break;
							case KinectImageMode.DepthBackgroundImage:
								depth.ImageType = KinectDepthImageType.DepthBackgroundImage;
								break;
							case KinectImageMode.DepthBackgroundRemoved:
								depth.ImageType = KinectDepthImageType.DepthBackgroundRemoved;
								break;
							default:
								break;
						}

						depth.Update();
						depth.Render(m_View);

						imageBounds.Offset(widthPerImage, 0);
					}
					break;
				default:
					break;
			}
		}
 internal override bool Hit(PointF p)
 {
     RectangleF r = new RectangleF(p, new SizeF(0,0));
     RectangleF env = new RectangleF(this.mCurrentPoint,new SizeF(10,10));
     env.Offset(-5,-5);
     mHovered = env.Contains(r);
     //Debug.WriteLine("(" + p.X + "," + p.Y + ") c " + "(" + mCurrentPoint.X + ","  + mCurrentPoint.Y +")");
     return mHovered;
 }
        public override void DrawUserHeader(IGUIContext gfx, System.Drawing.RectangleF rect, string UserName)
        {
            gfx.DrawGrayButton(rect);

            if (rect.Width > 4)
            {
                rect.Offset(2, 1);
                rect.Inflate(-2, 0);
                gfx.DrawString(UserName, BaseFont, SummerGUI.Theme.Brushes.Base03, rect, m_UserHeaderFormat);
            }
        }
Exemplo n.º 6
0
 public void Translate(float dx, float dy)
 {
     rgnData.Translate(dx, dy);
     for (int i = 0; i < rects.Length; i++)
     {
         rects[i].Offset(dx, dy);
     }
     if (rects.Length > 0)
     {
         extent.Offset(dx, dy);
     }
 }
Exemplo n.º 7
0
        static void DrawFancyText(string text, Color color, Graphics g, RectangleF rect)
        {
            Font font = new Font("Palatino Linotype", 24, FontStyle.Bold | FontStyle.Italic);

            SizeF actual = g.MeasureString(text, font);
            float scale = Math.Max(actual.Width / (rect.Width * 0.95F), actual.Height / (rect.Height * 0.95F));
            font = new Font(font.FontFamily, font.Size / scale, font.Style);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            float offset = font.Size / 20F;

            StringFormat format = new StringFormat(StringFormat.GenericDefault);
            format.LineAlignment = StringAlignment.Center;
            format.Alignment = StringAlignment.Center;
            rect.Offset(offset, offset);
            g.DrawString(text, font, Brushes.Gray, rect, format);
            rect.Offset(-offset, -offset);
            using (Brush b = new SolidBrush(color))
                g.DrawString(text, font, b, rect, format);

            font.Dispose();
        }
Exemplo n.º 8
0
 public void DrawEllipse(Color color, int x, int y, int width, int height)
 {
     StartDrawing();
     System.Drawing.RectangleF rect = TranslateView(new System.Drawing.RectangleF(x, y, width, height));
     rect.Offset(0.5f, 0.5f);
     rect.Width  -= 1f;
     rect.Height -= 1f;
     context.SetStrokeColor(Generator.Convert(color));
     context.SetLineCap(CGLineCap.Square);
     context.SetLineWidth(1.0F);
     context.StrokeEllipseInRect(rect);
     EndDrawing();
 }
        public static void Draw(Graphics graphics, Pen border, Brush background,
            RectangleF rectangle, float cornerRadius)
        {
            Debug.Assert(rectangle.Height >= (2 * cornerRadius));
            GraphicsPath rectanglePath = new GraphicsPath();
            float halfBorder = border.Width * 0.5f;

            rectangle.Offset(halfBorder, halfBorder);
            rectangle.Height -= border.Width;
            rectangle.Width -= border.Width;

            if (rectangle.Height > (2 * cornerRadius))
            {
                // Top left
                rectanglePath.AddArc(rectangle.Left, rectangle.Top,
                                     cornerRadius * 2, cornerRadius * 2,
                                     180, 90);
                // Top right
                rectanglePath.AddArc(rectangle.Right - (2 * cornerRadius), rectangle.Top,
                                     cornerRadius * 2, cornerRadius * 2,
                                     270, 90);
                // Bottom right
                rectanglePath.AddArc(rectangle.Right - (2 * cornerRadius), rectangle.Bottom - (2 * cornerRadius),
                                     cornerRadius * 2, cornerRadius * 2,
                                     0, 90);
                // Bottom left
                rectanglePath.AddArc(rectangle.Left, rectangle.Bottom - (2 * cornerRadius),
                                     cornerRadius * 2, cornerRadius * 2,
                                     90, 90);
            }
            else
            {
                // Left
                rectanglePath.AddArc(rectangle.Left, rectangle.Top,
                                     cornerRadius * 2, cornerRadius * 2,
                                     90, 180);
                // Right
                rectanglePath.AddArc(rectangle.Right - (2 * cornerRadius), rectangle.Top,
                                     cornerRadius * 2, cornerRadius * 2,
                                     270, 180);
            }
            rectanglePath.CloseFigure();

            graphics.FillPath(background, rectanglePath);
            graphics.DrawPath(border, rectanglePath);

            rectanglePath.Dispose();
        }
 public void ShowDetails(Element element, RectangleF cellFrame)
 {
     cellFrame.Offset(PeriodicTable.Frame.Location);
     detailsView.CellFrame = cellFrame;
     detailsView.Frame = cellFrame;
     detailsView.BackgroundColor = PeriodicCell.GetBackgroundColor(element.GroupName);
     UIView.Animate(1.2, 0, UIViewAnimationOptions.CurveEaseInOut, 
         () => 
         {
             detailsView.Hidden = false;
             detailsView.Alpha = 1;
             detailsView.Frame = this.View.Bounds;
         },
         () => { detailsView.SetNeedsLayout(); }
     );
 }
Exemplo n.º 11
0
        public void ClearSourceOffset()
        {
            if (mySourceOffsetBack.IsEmpty == false)
            {
                foreach (SimpleRectangleTransform item in this)
                {
                    System.Drawing.RectangleF rect = item.SourceRectF;
                    rect.Offset(-mySourceOffsetBack.X, -mySourceOffsetBack.Y);
                    item.SourceRectF = rect;

                    Rectangle rect2 = item._PartialAreaSourceBounds;
                    rect2.Offset(-mySourceOffsetBack.X, -mySourceOffsetBack.Y);
                    item._PartialAreaSourceBounds = rect2;
                }
            }
            mySourceOffsetBack = System.Drawing.Point.Empty;
        }
Exemplo n.º 12
0
        public override RectangleF GetWorldBounds()
        {
            float xmin = float.MaxValue;
            float xmax = float.MinValue;
            float ymin = float.MaxValue;
            float ymax = float.MinValue;

            foreach (var p in this.Points)
            {
                xmin = Math.Min(xmin, p.X);
                xmax = Math.Max(xmax, p.X);
                ymin = Math.Min(ymin, p.Y);
                ymax = Math.Max(ymax, p.Y);
            }

            RectangleF bounds = new RectangleF(xmin, ymin, xmax - xmin, ymax - ymin);
            bounds.Offset(this.Position);
            return bounds;
        }
Exemplo n.º 13
0
        /// <summary>
        /// 移动所有的来源矩形
        /// </summary>
        /// <param name="dx">X轴移动量</param>
        /// <param name="dy">Y轴移动量</param>
        /// <param name="Remark">是否记录</param>
        public void OffsetSource(int dx, int dy, bool Remark)
        {
            if (dx != 0 || dy != 0)
            {
                if (Remark)
                {
                    mySourceOffsetBack.Offset(dx, dy);
                }
                foreach (SimpleRectangleTransform item in this)
                {
                    System.Drawing.RectangleF rect = item.SourceRectF;
                    rect.Offset(dx, dy);
                    item.SourceRectF = rect;

                    Rectangle rect2 = item._PartialAreaSourceBounds;
                    rect2.Offset(dx, dy);
                    item._PartialAreaSourceBounds = rect2;
                }//foreach
            }
        }
            public int AddObject(RECTF rect, SCORE confidence, String name, RECTF?parentRect)
            {
                if (parentRect.HasValue)
                {
                    rect.Offset(parentRect.Value.Location);
                }

                var item = new DetectedObject
                {
                    Rect        = rect,
                    Score       = confidence,
                    Name        = name,
                    ParentIndex = -1
                };

                var idx = _Objects.Count;

                _Objects.Add(item);

                return(idx);
            }
Exemplo n.º 15
0
		private void DrawHorizontalTicks(Graphics g, Color color)
		{
			RectangleF ef;
			int num = (base.Maximum / base.TickFrequency) - 1;
			Pen pen = new Pen(color);
			RectangleF ef2 = new RectangleF((float)(ChannelBounds.Left + (ThumbBounds.Width / 2)), (float)(ThumbBounds.Top - 5), 0f, 3f);
			RectangleF ef3 = new RectangleF((float)((ChannelBounds.Right - (ThumbBounds.Width / 2)) - 1), (float)(ThumbBounds.Top - 5), 0f, 3f);
			float x = (ef3.Right - ef2.Left) / ((float)(num + 1));
			if (base.TickStyle != TickStyle.BottomRight)
			{
				g.DrawLine(pen, ef2.Left, ef2.Top, ef2.Right, ef2.Bottom);
				g.DrawLine(pen, ef3.Left, ef3.Top, ef3.Right, ef3.Bottom);
				ef = ef2;
				ef.Height--;
				ef.Offset(x, 1f);
				int num3 = num - 1;
				for (int i = 0; i <= num3; i++)
				{
					g.DrawLine(pen, ef.Left, ef.Top, ef.Left, ef.Bottom);
					ef.Offset(x, 0f);
				}
			}
			ef2.Offset(0f, (float)(ThumbBounds.Height + 6));
			ef3.Offset(0f, (float)(ThumbBounds.Height + 6));
			if (base.TickStyle != TickStyle.TopLeft)
			{
				g.DrawLine(pen, ef2.Left, ef2.Top, ef2.Left, ef2.Bottom);
				g.DrawLine(pen, ef3.Left, ef3.Top, ef3.Left, ef3.Bottom);
				ef = ef2;
				ef.Height--;
				ef.Offset(x, 0f);
				int num5 = num - 1;
				for (int j = 0; j <= num5; j++)
				{
					g.DrawLine(pen, ef.Left, ef.Top, ef.Left, ef.Bottom);
					ef.Offset(x, 0f);
				}
			}
			pen.Dispose();
		}
            public void AddObjects(IEnumerable <RECTI> localRects, string name, RECTF?parentRect)
            {
                _Objects.Clear();

                if (parentRect.HasValue)
                {
                    foreach (var r in localRects)
                    {
                        RECTF rr = r;
                        rr.Offset(parentRect.Value.Location);

                        AddObject(rr, (1, true), name);
                    }
                }
                else
                {
                    foreach (var r in localRects)
                    {
                        AddObject(r, SCORE.Ok, name);
                    }
                }
            }
        //Recipe 2-2 Adding Reorientation Support to the Preceding Subview Example
        public override void WillRotate(UIInterfaceOrientation toInterfaceOrientation, double duration)
        {
            var appRect = new RectangleF();
            appRect.Offset(new PointF(0.0f, 0.0f));
            //Adjust the frame based on the actual orientation
            if(toInterfaceOrientation == UIInterfaceOrientation.LandscapeLeft ||
               toInterfaceOrientation == UIInterfaceOrientation.LandscapeRight)
            {
                appRect.Size = new SizeF(480.0f, 300.0f);
            }
            else
            {
                appRect.Size = new SizeF(320.0f, 460.0f);
            }

            //Resize each subview accordingly
            var offset = -32.0f;
            foreach(var subview in contentView.Subviews)
            {
                var frame = RectangleF.Inflate(appRect, offset, offset);
                subview.Frame = frame;
                offset -= 32.0f;
            }
        }
        public override void LoadView()
        {
            View = new UIView () {
                BackgroundColor = UIColor.LightGray
            };

            RectangleF f = new RectangleF (10, 10, 300, 40);
            DisplayNameLabel = new UILabel(f) {
                Font = UIFont.BoldSystemFontOfSize(20)
            };
            View.AddSubview (DisplayNameLabel);

            f.Offset (new PointF(0, f.Height + 10));
            FullNameLabel = new UILabel (f) {
                TextColor = UIColor.DarkGray
            };
            View.AddSubview (FullNameLabel);

            f.Offset(new PointF(0, f.Height + 10));
            MemberSinceLabel = new UILabel (f) {
                Font = UIFont.ItalicSystemFontOfSize(14)
            };
            View.AddSubview (MemberSinceLabel);
        }
Exemplo n.º 19
0
        public void draw(Graphics g, PointF autoScrollPosition)
        {
            Pen pen;
            Brush brush;
            if (selected)
            {
                pen = tabela.ItemBorderSelectedPen;
                brush = tabela.ItemTextSelectedBrush;
            }
            else
            {
                pen = tabela.ItemBorderPen;
                brush = tabela.ItemTextBrush;
            }
            Font f = tabela.ItemFont;
            Font fBold = tabela.ItemBoldFont;
            Font fVrednostPreskoka = tabela.VrednostPreskokaFont;

            RectangleF rect = new RectangleF(location, size);
            rect.Offset(autoScrollPosition.X, autoScrollPosition.Y);

            g.FillRectangle(tabela.ItemBackroundBrush, rect);

            string number = broj.ToString() + '.';

            if (cutted)
            {
                g.DrawRectangle(tabela.EraseBorderPen, rect.X, rect.Y, rect.Width, rect.Height);
                DashStyle style = pen.DashStyle;
                pen.DashStyle = DashStyle.Dot;
                g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                pen.DashStyle = style;
            }
            else
            {
                g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
            }
            g.DrawString(number, f, brush, (RectangleF)rect);

            if (element != null)
            {
                string naziv = element.Naziv;
                if (naziv != "")
                    naziv += '\n';
                naziv += element.EngleskiNaziv;
                string nazivGim = element.NazivPoGimnasticaru;

                float nazivHeigth = 0.0f;
                // TODO2: Probaj da razdvojis srpski i engleski naziv (linijom ili malim razmakom)
                if (naziv != "")
                {
                    float xNaziv = rect.X + g.MeasureString(number + new String(' ', 3), f).Width;
                    nazivHeigth = g.MeasureString(
                        naziv, f, new SizeF(rect.Right - xNaziv, rect.Height)).Height;
                    RectangleF nazivRect = new RectangleF(xNaziv, rect.Y,
                        rect.Right - xNaziv, nazivHeigth);
                    g.DrawString(naziv, f, brush, nazivRect);
                }
                float nazivGimHeigth = 0.0f;
                if (nazivGim != "")
                {
                    nazivGim = "(" + nazivGim + ")";
                    nazivGimHeigth = g.MeasureString(nazivGim, fBold, rect.Size).Height;
                    nazivGimHeigth *= 2;
                    RectangleF nazivGimRect = new RectangleF(rect.X, rect.Y + nazivHeigth,
                        rect.Width, nazivGimHeigth);
                    StringFormat fmt = new StringFormat();
                    fmt.Alignment = StringAlignment.Center;
                    fmt.LineAlignment = StringAlignment.Center;
                    g.DrawString(nazivGim, fBold, brush, nazivGimRect, fmt);
                }

                if (Image != null)
                {
                    float textHeigth = nazivHeigth + nazivGimHeigth;
                    PointF imageTopLeft = new PointF(rect.Left, rect.Top + textHeigth);
                    SizeF imageSize = new SizeF(rect.Width, rect.Height - textHeigth);
                    RectangleF imageRect = new RectangleF(imageTopLeft, imageSize);
                    float hRedukcija =
                        imageRect.Width - imageRect.Width * Slika.ProcenatRedukcije / 100f;
                    float vRedukcija =
                        imageRect.Height - imageRect.Height * Slika.ProcenatRedukcije / 100f;
                    imageRect.Inflate(- hRedukcija / 2, - vRedukcija / 2);
                    imageRect.Inflate(-Math.Max(imageRect.Width / 50, 1),
                        -Math.Max(imageRect.Height / 50, 1));
                    if (selected)
                        PictureBoxPlus.scaleImageIsotropically(g, SelectedImage, imageRect);
                    else
                        PictureBoxPlus.scaleImageIsotropically(g, Image, imageRect);
                }

                RectangleF vaRect = RectangleF.Empty;
                if (element.Sprava == Sprava.Preskok && element.VrednostPreskoka != null)
                {
                    string vrednost = element.VrednostPreskoka.ToString();
                    SizeF vrednostSize = g.MeasureString(vrednost, fVrednostPreskoka);
                    PointF vrednostLoc = new PointF(rect.X, rect.Bottom - vrednostSize.Height);
                    vaRect = new RectangleF(vrednostLoc, vrednostSize);
                    //g.DrawRectangle(pen, vaRect.X, vaRect.Y, vaRect.Width, vaRect.Height);
                    g.DrawString(vrednost, fVrednostPreskoka, brush, vaRect);
                }

                if (element.Varijante.Count > 0)
                {
                    string va = "VA";
                    SizeF vaSize = g.MeasureString(va, f);
                    PointF vaLoc;
                    if (vaRect != RectangleF.Empty)
                        vaLoc = new PointF(vaRect.Right, rect.Bottom - vaSize.Height);
                    else
                        vaLoc = new PointF(rect.X, rect.Bottom - vaSize.Height);
                    vaRect = new RectangleF(vaLoc, vaSize);
                    g.DrawRectangle(pen, vaRect.X, vaRect.Y, vaRect.Width, vaRect.Height);
                    g.DrawString(va, f, brush, vaRect);
                }

                if (element.VideoKlipovi.Count > 0)
                {
                    string vi = "VI";
                    SizeF viSize = g.MeasureString(vi, f);
                    PointF viLoc;
                    if (vaRect != RectangleF.Empty)
                        viLoc = new PointF(vaRect.Right, rect.Bottom - viSize.Height);
                    else
                        viLoc = new PointF(rect.X, rect.Bottom - viSize.Height);
                    RectangleF viRect = new RectangleF(viLoc, viSize);
                    g.DrawRectangle(pen, viRect.X, viRect.Y, viRect.Width, viRect.Height);
                    g.DrawString(vi, f, brush, viRect);
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Method that find the node for which the expander was triggered
        /// </summary>
        /// <param name="node"> the node to be checked</param>
        /// <param name="nodeLevel"> the level of the node</param>
        /// <param name="crtExpanderRow"> the row associated with the node</param>
        /// <param name="insideClickPoint">the location inside the structure where de mouse was clicked</param>
        /// <param name="parentIsExpanded">true if parent node is expanded, false otherwhise</param>
        /// <returns></returns>
        private Node RecursiveExpanderCheck(Node node, int nodeLevel, ref int crtExpanderRow,
			Point insideClickPoint, bool parentIsExpanded)
        {
            int cY = rowHeight * crtExpanderRow + nodesDrawingTopPosition - location.Y + TITLE_OFFSET;
            RectangleF rowRectangleToCheck = new RectangleF(LEFT_PADDING, cY, EXPANDER_SIZE, EXPANDER_SIZE);

            if (!node.IsLeaf) {

                if (node.Parent != null && node.Parent.IsExpanded) {
                    rowRectangleToCheck.Offset(nodeLevel * TAB_NOD_SIZE, 0);
                }

                if (rowRectangleToCheck.Contains(insideClickPoint))
                    return node;

                foreach (Node childNode in node.Nodes) {
                    Node ndr = null;
                    if (parentIsExpanded) {
                        crtExpanderRow++;
                    }
                    ndr = RecursiveExpanderCheck(childNode, nodeLevel + 1, ref crtExpanderRow,
                        insideClickPoint, parentIsExpanded && childNode.IsExpanded);
                    if (ndr != null)
                        return ndr;
                }
            }
            return null;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Invokes the <see cref="E:System.Windows.Forms.Control.Paint"/>-event.
        /// </summary>
        /// <param name="pe">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event arguments.</param>
        protected override void OnPaint(PaintEventArgs pe)
        {
            try
            {
                if (_dragging)
                {
                    if (_activeTool == Tools.ZoomWindow || _activeTool == Tools.QueryBox ||
                        (_shiftButtonDragRectangleZoom && (Control.ModifierKeys & Keys.Shift) != Keys.None))
                    {
                        //Reset image to normal view
                        lock (_paintImageLocker)
                        {
                            var patch = ((Bitmap)_image).Clone(pe.ClipRectangle, PixelFormat.DontCare);
                            pe.Graphics.DrawImageUnscaled(patch, pe.ClipRectangle);
                            patch.Dispose();
                        }

                        //Draw selection rectangle
                        if (_rectangle.Width > 0 && _rectangle.Height > 0)
                        {
                            pe.Graphics.FillRectangle(_rectangleBrush, _rectangle);
                            var border = new Rectangle(_rectangle.X + (int) _rectanglePen.Width/2,
                                                             _rectangle.Y + (int) _rectanglePen.Width/2,
                                                             _rectangle.Width - (int) _rectanglePen.Width,
                                                             _rectangle.Height - (int) _rectanglePen.Width);
                            pe.Graphics.DrawRectangle(_rectanglePen, border);
                        }
                    }
                    else if (_activeTool == Tools.Pan || _activeTool == Tools.ZoomIn || _activeTool == Tools.ZoomOut ||
                             _activeTool == Tools.DrawLine || _activeTool == Tools.DrawPolygon)
                    {
                        if (_map.Envelope.Equals(_imageEnvelope))
                        {
                            lock (_paintImageLocker)
                            {
                                pe.Graphics.DrawImageUnscaled(_image, 0, 0);
                            }
                        }
                        else
                        {
                            PointF ul;

                            lock (_imageEnvelope)
                            {
                                lock (_paintImageLocker)
                                {
                                    ul = _map.WorldToImage(_imageEnvelope.TopLeft());
                                    var lr = _map.WorldToImage(_imageEnvelope.BottomRight());

                                    pe.Graphics.DrawImage(_image, RectangleF.FromLTRB(ul.X, ul.Y, lr.X, lr.Y));
                                }
                            }
                            if ((Math.Abs(ul.X) > 50 || Math.Abs(ul.Y) > 50) && !_isRefreshing)
                            {
                                //update the image we're dragging
                                int generation = ++_imageGeneration;
                                var bbox = _map.Envelope;
                            }
                        }
                    }
                    else if (_activeTool == Tools.ZoomIn || _activeTool == Tools.ZoomOut)
                    {
                        var rect = new RectangleF(0, 0, _map.Size.Width, _map.Size.Height);

                        if (_map.Zoom/_scaling < _map.MinimumZoom)
                            _scaling = (float) Math.Round(_map.Zoom/_map.MinimumZoom, 4);

                        if (_previewMode == PreviewModes.Best)
                            _scaling *= 3;

                        rect.Width *= _scaling;
                        rect.Height *= _scaling;

                        rect.Offset(_map.Size.Width/2f - rect.Width/2, _map.Size.Height/2f - rect.Height/2);


                        pe.Graphics.DrawImage(_dragImage, rect);
                    }
                }
                else if (_image != null && _image.PixelFormat != PixelFormat.Undefined)
                {
                    {
                        lock (_paintImageLocker)
                        {
                            if (_map.Envelope.Equals(_imageEnvelope))
                            {
                                pe.Graphics.DrawImageUnscaled(_image, 0, 0);
                            }
                            else
                            {
                                var ul = _map.WorldToImage(_imageEnvelope.TopLeft());
                                var lr = _map.WorldToImage(_imageEnvelope.BottomRight());
                                pe.Graphics.DrawImage(_image, RectangleF.FromLTRB(ul.X, ul.Y, lr.X, lr.Y));
                            }
                        }
                    }
                }


                //Draws current line or polygon (Draw Line or Draw Polygon tool)
                if (_pointArray != null)
                {
                    if (_pointArray.Count == 1)
                    {
                        var p1 = Map.WorldToImage(_pointArray[0]);
                        var p2 = Map.WorldToImage(_pointArray[1]);
                        pe.Graphics.DrawLine(new Pen(Color.Gray, 2F), p1, p2);
                    }
                    else
                    {
                        PointF[] pts = new PointF[_pointArray.Count];
                        for (int i = 0; i < pts.Length; i++)
                            pts[i] = Map.WorldToImage(_pointArray[i]);

                        if (_activeTool == Tools.DrawPolygon)
                        {
                            Color c = Color.FromArgb(127, Color.Gray);
                            pe.Graphics.FillPolygon(new SolidBrush(c), pts);
                            pe.Graphics.DrawPolygon(new Pen(Color.Gray, 2F), pts);
                        }
                        else
                        {
                            if (pts.Length > 0)
                            pe.Graphics.DrawLines(new Pen(Color.Gray, 2F), pts);
                        }
                    }
                }

                base.OnPaint(pe);

                /*Draw Floating Map-Decorations*/
                if (_map != null && _map.Decorations != null)
                {
                    foreach (Rendering.Decoration.IMapDecoration md in _map.Decorations)
                    {
                        md.Render(pe.Graphics, _map);
                    }
                }
            }
            catch (Exception ee)
            {
                Logger.Error(ee);
            }
        }
Exemplo n.º 22
0
        public static void MenuPanelPaint(Graphics g, RectangleF area)
        {
            g.SmoothingMode = SmoothingMode.HighQuality;

              // In order to perfectly draw the gradient exactly how we want it we have to use
              // inter-pixel coordinates.
              area.Offset(-0.5f, -0.5f);

              ColorBlend blend = new ColorBlend();
              if (Conversions.InHighContrastMode())
            blend.Colors = new Color[] {
              Color.FromArgb(0xff, 0xff, 0xff, 0xff),
              Color.FromArgb(0xff, 0xff, 0xff, 0xff)
            };
              else
            blend.Colors = new Color[] {
              Color.FromArgb(0xff, 0xd6, 0xdc, 0xe5),
              Color.FromArgb(0xff, 0xc2, 0xcb, 0xda),
              Color.FromArgb(0xff, 0xad, 0xba, 0xce),
              Color.FromArgb(0xff, 0xad, 0xba, 0xce)
            };

              blend.Positions = new float[] { 0, 0.2f, 0.45f, 1 };

              using (LinearGradientBrush gradientBrush = new LinearGradientBrush(
            new RectangleF(0, 0, 1, area.Height),
            Color.Black, Color.White, LinearGradientMode.Vertical))
              {
            gradientBrush.InterpolationColors = blend;
            g.FillRectangle(gradientBrush, area);
              }

              // Bottom line
              using (Pen pen = new Pen(Color.FromArgb(0xff, 0x99, 0xa7, 0xb3)))
            g.DrawLine(pen, area.Left, area.Bottom - 0.5f, area.Right - 1, area.Bottom - 0.5f);

              // Left + Right border gradient.
              using (LinearGradientBrush gradientBrush = new LinearGradientBrush(
            new RectangleF(0, 0, 1, area.Bottom),
            Color.FromArgb(0xff, 0x92, 0x9b, 0xa2), Color.FromArgb(0xff, 0x99, 0xa7, 0xb3), LinearGradientMode.Vertical))
              {
            using (Pen pen = new Pen(gradientBrush, 1))
            {
              g.DrawLine(pen, 0, area.Top, 0, area.Bottom);
              g.DrawLine(pen, area.Right - 0.5f, area.Top, area.Right - 0.5f, area.Bottom);
            }
              }
        }
Exemplo n.º 23
0
        internal void DoPrintPage(
            IWin32Window owner,
            LabelParam label_param,
            string strStyle,
            PrintPageEventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (e.Cancel == true)
                return;

            bool bTestingGrid = false;
            if (StringUtil.IsInList("TestingGrid", strStyle) == true)
                bTestingGrid = true;


            int nYCount = 0;
            int nXCount = 0;

            double PageWidth = label_param.PageWidth;
            double PageHeight = label_param.PageHeight;
#if NO
            if (label_param.Landscape == true)
            {
                double nTemp = PageHeight;
                PageHeight = PageWidth;
                PageWidth = nTemp;
            }
#endif
#if NO
            if (e.PageSettings.Landscape == true)
            {
                double nTemp = PageHeight;
                PageHeight = PageWidth;
                PageWidth = nTemp;
            }
#endif

            int nPageWidth = e.PageBounds.Width;    // PageBounds 中已经是按照 Landscape 处理过的方向了
            if (PageWidth != 0)
                nPageWidth = (int)PageWidth;

            int nPageHeight = e.PageBounds.Height;
            if (PageHeight != 0)
                nPageHeight = (int)PageHeight;

            DecimalPadding PageMargins = RotatePadding(label_param.PageMargins, 
                e.PageSettings.Landscape);  // label_param.Landscape
#if NO
            // 垂直方向的个数
            nYCount = (e.PageBounds.Height - label_param.PageMargins.Top - label_param.PageMargins.Bottom)
                / label_param.Height;
            // 水平方向的个数
            nXCount = (e.PageBounds.Width - label_param.PageMargins.Left - label_param.PageMargins.Right)
            / label_param.Width;
#endif
            // 垂直方向的个数
            nYCount = (int)
                (
                (double)(nPageHeight - PageMargins.Top - PageMargins.Bottom)
                / (double)label_param.LabelHeight
                );
            // 水平方向的个数
            nXCount = (int)
                (
                (double)(nPageWidth - PageMargins.Left - PageMargins.Right)
                / (double)label_param.LabelWidth
                );

            int from = 0;
            int to = 0;
            bool bOutput = true;
            // 如果 e.PageSettings.PrinterSettings.FromPage == 0,会被当作打印第一页
            if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages
                && e.PageSettings.PrinterSettings.FromPage >= 1)
            {
                from = e.PageSettings.PrinterSettings.FromPage;
                to = e.PageSettings.PrinterSettings.ToPage;

                // 交换,保证from为小
                if (from > to)
                {
                    int temp = to;
                    to = from;
                    from = temp;
                }

                if (this.m_nPageNo == 0)
                {
                    this.m_nPageNo = from;

                    Debug.Assert(this.m_nPageNo >= 1, "");
                    long nLabelCount = (nXCount * nYCount) * (this.m_nPageNo - 1);

                    // 从文件中跳过这么多label的内容行
                    for (int i = 0; i < nLabelCount; i++)
                    {
                        List<string> lines = null;
                        nRet = this.GetLabelLines(out lines,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;

                        if (nRet == 1)
                        {
                            e.Cancel = true;
                            return;
                        }
                    }
                }

                /*
                if (this.m_nPageNo >= from
                    && this.m_nPageNo <= to)
                {
                    bOutput = true;
                }
                else
                {
                    bOutput = false;
                }
                 * */
            }
            else
            {
                if (this.m_nPageNo == 0)
                    this.m_nPageNo = 1; // 一般性的初始化
            }


            // 加快运行速度
            float nXDelta = e.PageSettings.PrintableArea.Left;
            float nYDelta = e.PageSettings.PrintableArea.Top;

            /*
            if (this.PrintController.IsPreview == true)
            {
                nXDelta = 0;
                nYDelta = 0;
            }
             * */

            if (this.OriginAtMargins == true
                || this.PreviewMode == true)   // false
            {
                // true 如果图形起始于页面边距。否则起始于可打印区域
                nXDelta = 0;
                nYDelta = 0;
            }

            if (this.OriginPoint != null)
            {
                nXDelta -= this.OriginPoint.X;
                nYDelta -= this.OriginPoint.Y;
            }

#if NO
            float nPrintableWidth = e.PageSettings.PrintableArea.Width;
            float nPrintableHeight = e.PageSettings.PrintableArea.Height;
#endif


            if (this.IsDesignMode)
            {
#if NO
                Pen pen = new Pen(Color.Blue, (float)1);

                e.Graphics.DrawRectangle(pen,
                    0 + 1 - nXDelta,
                    0 + 1 - nYDelta,
                    e.PageBounds.Width - 2,
                    e.PageBounds.Height - 2);

                pen.Dispose();
#endif
                // 绘制整个纸张背景 白色
                using (Brush brushBack = new SolidBrush(Color.White))
                {
                    RectangleF rectPaper = new RectangleF(0 + 1 - nXDelta,
                        0 + 1 - nYDelta,
                        e.PageBounds.Width - 2,
                        e.PageBounds.Height - 2);
                    e.Graphics.FillRectangle(brushBack, rectPaper);
                }

#if NO
                // 绘制配置文件的页面区域
                if (PageHeight > 0 && PageWidth > 0)
                {
                    using (Brush brushBack = new SolidBrush(Color.FromArgb(128, Color.LightYellow)))
                    {
                        RectangleF rectPaper = new RectangleF(0 - nXDelta,
                            0 - nYDelta,
                            (float)PageWidth,
                            (float)PageHeight);
                        e.Graphics.FillRectangle(brushBack, rectPaper);
                    }
                }
#endif
            }

            // 绘制可打印区域
            // 鲜红色
            if (bTestingGrid == true && bOutput == true)
            {
                float nXOffs = 0;
                float nYOffs = 0;

                // 如果为正式打印,左上角(0,0)已经就是可以打印区域的左上角
                // 如果为preview模式,则左上角要向右向下移动,才能模拟出显示效果

#if NO
                if (this.OriginAtMargins == true
                    || this.PreviewMode == true)
                {
                    nXOffs = e.PageSettings.PrintableArea.Left;
                    nYOffs = e.PageSettings.PrintableArea.Top;
                }
#endif


                if (this.OriginPoint != null)
                {
                    nXOffs += this.OriginPoint.X;
                    nYOffs += this.OriginPoint.Y;
                }

                RectangleF rect = RotateRectangle(e.PageSettings.PrintableArea,
                    e.PageSettings.Landscape);  // label_param.Landscape

                if (this.OriginAtMargins == true
    || this.PreviewMode == true)
                {
                }
                else
                {
                    rect.X = 0;
                    rect.Y = 0;
                }

                rect.Offset(nXOffs, nYOffs);

                using (Pen pen = new Pen(Color.Red, (float)1))
                {
                    DrawFourAngel(
    e.Graphics,
    pen,
    rect,
    50);    // 半英寸
                }
            }

            // 加入变换
            e.Graphics.TranslateTransform(-nXDelta, -nYDelta);
            nXDelta = 0;
            nYDelta = 0;

            if (label_param.RotateDegree != 0)
            {
                float x_offs, y_offs;
                CenterMove(label_param.RotateDegree,
            (float)label_param.PageWidth,  // e.PageBounds.Width,
            (float)label_param.PageHeight, // e.PageBounds.Height,
            out x_offs,
            out y_offs);
                e.Graphics.TranslateTransform(x_offs, y_offs);
                e.Graphics.RotateTransform((float)label_param.RotateDegree);
            }

            if (this.IsDesignMode)
            {
                // 绘制配置文件的页面区域
                if (PageHeight > 0 && PageWidth > 0)
                {
                    using (Brush brushBack = new SolidBrush(Color.FromArgb(128, Color.LightYellow)))
                    {
                        RectangleF rectPaper = new RectangleF(0 - nXDelta,
                            0 - nYDelta,
                            (float)PageWidth,
                            (float)PageHeight);
                        e.Graphics.FillRectangle(brushBack, rectPaper);
                    }
                }
            }

            // 绘制内容区域边界(也就是排除了页面边空的中间部分)
            // 淡绿色
            if (bTestingGrid == true && bOutput == true)
            {
                using (Pen pen = new Pen(Color.FromArgb(0, 100, 0), (float)2)) // 3
                {

#if NO
                e.Graphics.DrawRectangle(pen,
                    PageMargins.Left - nXDelta,
                    PageMargins.Top - nYDelta,
                    e.PageBounds.Width - PageMargins.Left - PageMargins.Right,
                    e.PageBounds.Height - PageMargins.Top - PageMargins.Bottom);
#endif
                    e.Graphics.DrawRectangle(pen,
        (float)PageMargins.Left - nXDelta,
        (float)PageMargins.Top - nYDelta,
        (float)nPageWidth - (float)PageMargins.Left - (float)PageMargins.Right,
        (float)nPageHeight - (float)PageMargins.Top - (float)PageMargins.Bottom);

                }
            }

            bool bEOF = false;

            float y = (float)PageMargins.Top;
            // 每一行的循环
            for (int i = 0; i < nYCount; i++)
            {
                bool bDisplay = true;
                if (this.IsDesignMode == true)
                {
                    RectangleF rectLine = new RectangleF(
    (float)0 - nXDelta,
    (float)y - nYDelta,
    (float)label_param.LabelWidth * nXCount,
    (float)label_param.LabelHeight);
                    if (rectLine.Top > e.Graphics.ClipBounds.Bottom)
                    {
                        // Debug.WriteLine("break line loop at " + i.ToString());
                        break;  // 当前行在剪裁区域的下方,可以中断循环了
                    }
                    if (rectLine.IntersectsWith(e.Graphics.ClipBounds) == false)
                    {
                        // Debug.WriteLine("skip line " + i.ToString());
                        bDisplay = false;
                    }
                }
                float x = (float)PageMargins.Left;
                // 每一列的循环
                for (int j = 0; j < nXCount; j++)
                {
                    List<string> lines = null;
                    nRet = this.GetLabelLines(out lines,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    if (nRet == 1)
                        bEOF = true;

                    if (bOutput == true  && bDisplay == true)
                    {
                        // 标签
                        RectangleF rectLabel = new RectangleF(
    (float)x - nXDelta,
    (float)y - nYDelta,
    (float)label_param.LabelWidth,
    (float)label_param.LabelHeight);

                        if (rectLabel.Left > e.Graphics.ClipBounds.Right)
                        {
                            // Debug.WriteLine("break label loop at i=" + i.ToString() + " j=" + j.ToString());
                            // 当前标签在剪裁区域的右方,可以不要显示后面的标签了
                            bDisplay = false;
                        }

                        if (this.IsDesignMode == false
                            || rectLabel.IntersectsWith(e.Graphics.ClipBounds) == true)
                        {
                            // Debug.WriteLine("i="+i.ToString()+" j="+j.ToString()+" rectLabel = "+rectLabel.ToString()+", clipbounds " + e.Graphics.ClipBounds.ToString());
                            // 标签内容区域
                            RectangleF rectContent = new RectangleF(
                                    (float)x + (float)label_param.LabelPaddings.Left - nXDelta,
                                    (float)y + (float)label_param.LabelPaddings.Top - nYDelta,
                                    (float)label_param.LabelWidth - (float)label_param.LabelPaddings.Left - (float)label_param.LabelPaddings.Right - 1,
                                    (float)label_param.LabelHeight - (float)label_param.LabelPaddings.Top - (float)label_param.LabelPaddings.Bottom - 1);


                            // 绘制标签边界
                            // 灰色
                            if (bTestingGrid == true)
                            {
                                // 标签白色背景
                                if (this.IsDesignMode == true)
                                {
                                    using (Brush brushBack = new SolidBrush(Color.FromArgb(200, Color.White)))
                                    {
                                        e.Graphics.FillRectangle(brushBack, rectLabel);
                                    }
                                }

                                // 标签边界
                                using (Pen pen = new Pen(Color.FromArgb(200, 200, 200), this.IsDesignMode ? (float)0.5 : (float)1))
                                {
                                    e.Graphics.DrawRectangle(pen,
                                        rectLabel.X,
                                        rectLabel.Y,
                                        rectLabel.Width,
                                        rectLabel.Height);
#if NO
                            e.Graphics.DrawRectangle(pen,
                                x - nXDelta,
                                y - nYDelta,
                                (float)label_param.LabelWidth,
                                (float)label_param.LabelHeight);
#endif

                                }


                                // 绘制标签内部文字区域边界
                                // 淡红色

                                using (Pen pen = new Pen(Color.FromArgb(255, 200, 200), this.IsDesignMode ? (float)0.5 : (float)1))
                                {
                                    e.Graphics.DrawRectangle(pen,
                                        rectContent.X,
                                        rectContent.Y,
                                        rectContent.Width,
                                        rectContent.Height);
#if NO
                            e.Graphics.DrawRectangle(pen,
                                (float)x + (float)label_param.LabelPaddings.Left - nXDelta,
                                (float)y + (float)label_param.LabelPaddings.Top - nYDelta,
                                (float)label_param.LabelWidth - (float)label_param.LabelPaddings.Left - (float)label_param.LabelPaddings.Right - 1,
                                (float)label_param.LabelHeight - (float)label_param.LabelPaddings.Top - (float)label_param.LabelPaddings.Bottom - 1);
#endif

                                }
                            }

#if NO
                        RectangleF clip = new RectangleF((float)x + (float)label_param.LabelPaddings.Left - nXDelta,
    (float)y + (float)label_param.LabelPaddings.Top - nYDelta,
    (float)label_param.LabelWidth - (float)label_param.LabelPaddings.Left - (float)label_param.LabelPaddings.Right,
    (float)label_param.LabelHeight - (float)label_param.LabelPaddings.Top - (float)label_param.LabelPaddings.Bottom);
#endif

                            using (Region old_clip = e.Graphics.Clip)
                            {
                                e.Graphics.IntersectClip(rectContent);

                                float y0 = 0;
                                for (int k = 0; k < lines.Count; k++)
                                {
                                    string strText = lines[k];

                                    LineFormat format = null;
                                    if (k < label_param.LineFormats.Count)
                                        format = label_param.LineFormats[k];

                                    Font this_font = null;
                                    bool bIsBarcodeFont = false;
                                    if (format != null && format.Font != null)
                                    {
                                        this_font = format.Font;
                                        bIsBarcodeFont = format.IsBarcodeFont;
                                    }
                                    else
                                    {
                                        this_font = label_param.Font;
                                        bIsBarcodeFont = label_param.IsBarcodeFont;
                                    }

                                    if (bIsBarcodeFont == true && string.IsNullOrEmpty(strText) == false)
                                        strText = "*" + strText + "*";

                                    float nLineHeight = this_font.GetHeight(e.Graphics);

                                    RectangleF rect = new RectangleF((float)x + (float)label_param.LabelPaddings.Left - nXDelta,
                                        (float)y + (float)label_param.LabelPaddings.Top + y0 - nYDelta,
                                        (float)label_param.LabelWidth - (float)label_param.LabelPaddings.Left - (float)label_param.LabelPaddings.Right,
                                        nLineHeight);

                                    bool bAbsLocation = false;
                                    // 行格式的 start 和 offset
                                    if (format != null)
                                    {
                                        if (double.IsNaN(format.StartX) == false)
                                            rect.X = (float)format.StartX;
                                        if (double.IsNaN(format.StartY) == false)
                                        {
                                            rect.Y = (float)format.StartY;
                                            bAbsLocation = true;    // Y 绝对定位后,行高度不参与累计
                                        }
                                        rect.Offset((float)format.OffsetX, (float)format.OffsetY);

                                        y0 += (float)format.OffsetY;    // Y 偏移后,累计值也跟着调整

                                    }

                                    StringFormat s_format = new StringFormat();
                                    if (format != null)
                                    {
                                        if (format.Align == "right")
                                            s_format.Alignment = StringAlignment.Far;
                                        else if (format.Align == "center")
                                            s_format.Alignment = StringAlignment.Center;
                                        else
                                            s_format.Alignment = StringAlignment.Near;

                                        s_format.Trimming = StringTrimming.EllipsisCharacter;
                                        // s_format.LineAlignment = StringAlignment.Center;
                                    }

                                    if (format != null && string.IsNullOrEmpty(format.BackColor) == false)
                                    {
                                        using (Brush brush = new SolidBrush(GetColor(format.BackColor)))
                                        {
                                            e.Graphics.FillRectangle(brush, rect);
                                        }
                                    }

                                    {
                                        Brush brushText = null;

                                        if (format != null && string.IsNullOrEmpty(format.ForeColor) == false)
                                        {
                                            brushText = new SolidBrush(GetColor(format.ForeColor));
                                        }
                                        else
                                            brushText = System.Drawing.Brushes.Black;

                                        e.Graphics.DrawString(strText,
                                            this_font,
                                            brushText,
                                            rect,
                                            s_format);

                                        if (brushText != System.Drawing.Brushes.Black)
                                            brushText.Dispose();
                                    }


                                    // 文字行区域边界
                                    // 黑色点
                                    if (bTestingGrid == true && label_param.LineSep > 0)
                                    {
                                        using (Pen pen = new Pen(Color.Black, (float)1))
                                        {
                                            // pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;

#if NO
                                            e.Graphics.DrawRectangle(pen,
                                                rect.Left,
                                                rect.Top,
                                                rect.Width,
                                                rect.Height);
#endif
                                            pen.DashPattern = new float[] { 1F, 3F, 1F, 3F };
                                            e.Graphics.DrawLine(pen,
                                                new PointF(rect.Left, rect.Top),
                                                new PointF(rect.Right, rect.Top)
                                                );
                                            e.Graphics.DrawLine(pen,
                                                new PointF(rect.Left + 2, rect.Bottom),
                                                new PointF(rect.Right, rect.Bottom)
                                                );
                                        }
                                    }

                                    if (bAbsLocation == false)
                                        y0 += nLineHeight + (float)label_param.LineSep;
                                }

                                e.Graphics.Clip = old_clip;
                            } // end of using clip

                        } // end if IntersectsWith



                    } // end if bOutput == true


                    x += (float)label_param.LabelWidth;
                }

            CONTINUE_LINE:
                y += (float)label_param.LabelHeight;
            }

            // If more lines exist, print another page.
            if (bEOF == false)
            {
                if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)
                {
                    if (this.m_nPageNo >= to)
                    {
                        e.HasMorePages = false;
                        return;
                    }
                }
            }
            else
            {
                e.HasMorePages = false;
                return;
            }

            this.m_nPageNo++;
            e.HasMorePages = true;
            return;
        ERROR1:
            MessageBox.Show(owner, strError);
        }
Exemplo n.º 24
0
        protected virtual void DrawText(Graphics g)
        {
            RectangleF layoutRect =
                new RectangleF(0, 0, this.Width,
                    this.Height - ButtonShadowOffset);

            int LabelShadowOffset = 1;

            StringFormat fmt = new StringFormat();
            fmt.Alignment = StringAlignment.Center;
            fmt.LineAlignment = StringAlignment.Center;

            // Draw the shadow below the label
            layoutRect.Offset(0, LabelShadowOffset);
            SolidBrush textShadowBrush = new SolidBrush(Color.Gray);
            g.DrawString(Text, Font, textShadowBrush, layoutRect, fmt);
            textShadowBrush.Dispose();

            // and the label itself
            layoutRect.Offset(0, -LabelShadowOffset);
            SolidBrush brushFiller = new SolidBrush(Color.Black);
            g.DrawString(Text, Font, brushFiller, layoutRect, fmt);
            brushFiller.Dispose();
        }
Exemplo n.º 25
0
        /// <summary>
        /// Computes the layout of all visible text spans and stores them the 
        /// member variable 'visibleLines'. This includes a final partial item on the end.
        /// </summary>
        /// <param name="g"></param>
        protected void ComputeLayout(Graphics g)
        {
            float cyLine = GetLineHeight();
            this.visibleLines = new SortedList<float, LayoutLine>();
            SizeF szClient = new SizeF(ClientSize);
            var rcLine = new RectangleF(0, 0, szClient.Width, cyLine);

            // Get the lines.
            int cVisibleLines = (int) Math.Ceiling(szClient.Height / cyLine);
            var lines = model != null ? model.GetLineSpans(cVisibleLines) : new LineSpan[0];
            int iLine = 0;
            while (rcLine.Top < szClient.Height &&
                   iLine < lines.Length)
            {
                var line = lines[iLine];
                var ll = new LayoutLine(line.Position) {
                    Extent = rcLine,
                    Spans = ComputeSpanLayouts(line.TextSpans, rcLine, g)
                };
                this.visibleLines.Add(rcLine.Top, ll);
                ++iLine;
                rcLine.Offset(0, cyLine);
            }
        }
Exemplo n.º 26
0
 public void Offset(float dx, float dy)
 {
     myBounds.Offset(dx, dy);
     this.UpdateSate();
 }
Exemplo n.º 27
0
		/// <summary>
		/// Callback routine for word-by-word text processing
		/// </summary>
		/// <param name="text">Text word as 'plain-text'</param>
		/// <param name="dest">Text word's rectangle</param>
		/// <param name="hint">DrawTextHint object</param>
		internal void ___TextCallback(string text, RectangleF dest, DrawTextHint hint)
		{

			if ( hint == null )
				return;

			dest.Offset(hint.rect.Location);
			AddText(hint.TextID++, dest, text, hint.crText, hint.Font, hint.Format, false, hint.RotationAngle, false);

		}
Exemplo n.º 28
0
		private void MapImage_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (_Map != null)
			{

				ICoordinate p = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));

				if (MouseMove != null)
					MouseMove(p, e);

				if (Image != null && e.Location != mousedrag && !mousedragging && e.Button == MouseButtons.Left)
				{
					mousedragImg = this.Image.Clone() as Image;
					mousedragging = true;
				}

				if (mousedragging)
				{
					if (MouseDrag != null)
						MouseDrag(p, e);

					if (this.ActiveTool == Tools.Pan)
					{
						System.Drawing.Image img = new System.Drawing.Bitmap(this.Size.Width, this.Size.Height);
						System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img);
						g.Clear(Color.Transparent);
						g.DrawImageUnscaled(mousedragImg, new System.Drawing.Point(e.Location.X - mousedrag.X, e.Location.Y - mousedrag.Y));
						g.Dispose();
						this.Image = img;
					}
					else if (this.ActiveTool == Tools.ZoomIn || this.ActiveTool == Tools.ZoomOut)
					{
						System.Drawing.Image img = new System.Drawing.Bitmap(this.Size.Width, this.Size.Height);
						System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img);
						g.Clear(Color.Transparent);
						float scale = 0;
						if (e.Y - mousedrag.Y < 0) //Zoom out
							scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
						else //Zoom in
							scale = 1 + (e.Y - mousedrag.Y) * 0.1f;
						RectangleF rect = new RectangleF(0, 0, this.Width, this.Height);
						if (_Map.Zoom / scale < _Map.MinimumZoom)
							scale = (float)Math.Round(_Map.Zoom / _Map.MinimumZoom, 4);
						rect.Width *= scale;
						rect.Height *= scale;
						rect.Offset(this.Width / 2 - rect.Width / 2, this.Height / 2 - rect.Height / 2);
						g.DrawImage(mousedragImg, rect);
						g.Dispose();
						this.Image = img;
						if (MapZooming != null)
							MapZooming(scale);
					}
				}
			}
		}
Exemplo n.º 29
0
        public void Paint(ChartPaintEventArgs e)
        {
            var g = e.Graphics;
                var chart = e.Chart;

                // dragging outline / trail
                if (DraggedRect != RectangleF.Empty)
                    g.DrawRectangle(Pens.Red, DraggedRect);

                // insertion indicator line
                if (Row != int.MinValue)
                {
                    float y = e.Chart._ChartRowToChartCoord(Row) + e.Chart.BarHeight / 2.0f;
                    g.DrawLine(Pens.CornflowerBlue, new PointF(0, y), new PointF(e.Chart.Width, y));
                }

                // tool tip
                if (_mToolTipMouse != Point.Empty && _mToolTipText != string.Empty)
                {
                    var size = g.MeasureString(_mToolTipText, chart.Font).ToSize();
                    var tooltiprect = new RectangleF(_mToolTipMouse, size);
                    tooltiprect.Offset(0, -tooltiprect.Height);
                    var textstart = new PointF(tooltiprect.Left, tooltiprect.Top);
                    tooltiprect.Inflate(5, 5);
                    g.FillRectangle(Brushes.LightYellow, tooltiprect);
                    g.DrawString(_mToolTipText, chart.Font, Brushes.Black, textstart);
                }
        }
Exemplo n.º 30
0
        public static void DrawBlueShirt(RectangleF frame, float shirtAngle, float shirtScaleFactor)
        {
            //// General Declarations
            var context = UIGraphics.GetCurrentContext();

            //// Color Declarations
            var blueShirtBase = UIColor.FromRGBA(0.173f, 0.435f, 0.702f, 1.000f);
            var blueShirtBaseRGBA = new float[4];
            blueShirtBase.GetRGBA(out blueShirtBaseRGBA[0], out blueShirtBaseRGBA[1], out blueShirtBaseRGBA[2], out blueShirtBaseRGBA[3]);

            var blueShirtStroke = UIColor.FromRGBA((blueShirtBaseRGBA[0] * 0.7f + 0.3f), (blueShirtBaseRGBA[1] * 0.7f + 0.3f), (blueShirtBaseRGBA[2] * 0.7f + 0.3f), (blueShirtBaseRGBA[3] * 0.7f + 0.3f));

            //// Shadow Declarations
            var blueShirtShadow = blueShirtBase.CGColor;
            var blueShirtShadowOffset = new SizeF(2.1f, 2.1f);
            var blueShirtShadowBlurRadius = 3.0f;

            //// shirtBezier Drawing
            context.SaveState();
            context.TranslateCTM(frame.GetMinX() + 61.94f, frame.GetMinY() + 59.36f);
            context.RotateCTM(-shirtAngle * (float)Math.PI / 180.0f);
            context.ScaleCTM(shirtScaleFactor, shirtScaleFactor);

            UIBezierPath shirtBezierPath = new UIBezierPath();
            shirtBezierPath.MoveTo(new PointF(-27.46f, -43.29f));
            shirtBezierPath.AddCurveToPoint(new PointF(-11.8f, -30.19f), new PointF(-27.46f, -43.29f), new PointF(-15.62f, -33.38f));
            shirtBezierPath.AddLineTo(new PointF(-10.9f, -30.19f));
            shirtBezierPath.AddCurveToPoint(new PointF(-10.59f, -29.78f), new PointF(-10.8f, -30.05f), new PointF(-10.7f, -29.92f));
            shirtBezierPath.AddCurveToPoint(new PointF(10.42f, -29.78f), new PointF(-4.79f, -22.48f), new PointF(4.62f, -22.48f));
            shirtBezierPath.AddCurveToPoint(new PointF(10.74f, -30.19f), new PointF(10.53f, -29.92f), new PointF(10.63f, -30.05f));
            shirtBezierPath.AddCurveToPoint(new PointF(11.8f, -30.19f), new PointF(10.74f, -30.19f), new PointF(11.13f, -30.19f));
            shirtBezierPath.AddCurveToPoint(new PointF(27.46f, -43.29f), new PointF(15.62f, -33.38f), new PointF(27.46f, -43.29f));
            shirtBezierPath.AddLineTo(new PointF(48.92f, -10.09f));
            shirtBezierPath.AddLineTo(new PointF(32.09f, 3.99f));
            shirtBezierPath.AddCurveToPoint(new PointF(27.12f, -3.69f), new PointF(32.09f, 3.99f), new PointF(30.0f, 0.76f));
            shirtBezierPath.AddCurveToPoint(new PointF(27.12f, 43.29f), new PointF(27.12f, 17.36f), new PointF(27.12f, 43.29f));
            shirtBezierPath.AddLineTo(new PointF(-27.46f, 43.29f));
            shirtBezierPath.AddCurveToPoint(new PointF(-27.46f, -3.18f), new PointF(-27.46f, 43.29f), new PointF(-27.46f, 17.78f));
            shirtBezierPath.AddCurveToPoint(new PointF(-32.09f, 3.99f), new PointF(-30.16f, 1.0f), new PointF(-32.09f, 3.99f));
            shirtBezierPath.AddLineTo(new PointF(-48.92f, -10.09f));
            shirtBezierPath.AddLineTo(new PointF(-27.46f, -43.29f));
            shirtBezierPath.ClosePath();
            context.SaveState();
            context.SetShadowWithColor(blueShirtShadowOffset, blueShirtShadowBlurRadius, blueShirtShadow);
            blueShirtBase.SetFill();
            shirtBezierPath.Fill();
            context.RestoreState();

            blueShirtStroke.SetStroke();
            shirtBezierPath.LineWidth = 8.0f;
            shirtBezierPath.Stroke();

            context.RestoreState();

            //// Text Drawing
            context.SaveState();
            context.TranslateCTM(frame.GetMinX() + 62.0f, frame.GetMinY() + 61.95f);
            context.RotateCTM(-shirtAngle * (float)Math.PI / 180.0f);
            context.ScaleCTM(shirtScaleFactor, shirtScaleFactor);

            RectangleF textRect = new RectangleF(-24.7f, -25.61f, 50.0f, 50.0f);
            var textPath = UIBezierPath.FromRect(textRect);
            UIColor.Red.SetStroke();
            textPath.LineWidth = 1.0f;
            textPath.Stroke();
            {
                var textContent = "?";
                UIColor.White.SetFill();
                var textFont = UIFont.FromName("HelveticaNeue-Bold", 36.0f);
                textRect.Offset(0.0f, (textRect.Height - new NSString(textContent).StringSize(textFont, textRect.Size).Height) / 2.0f);
                new NSString(textContent).DrawString(textRect, textFont, UILineBreakMode.WordWrap, UITextAlignment.Center);
            }

            context.RestoreState();
        }
Exemplo n.º 31
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            try
            {
                if (_dragging)
                {
                    if (_activeTool == Tools.ZoomWindow || _activeTool == Tools.Query || (_shiftButtonDragRectangleZoom && (Control.ModifierKeys & Keys.Shift) != Keys.None))
                    {
                        //Reset image to normal view
                        Bitmap patch = (_image as Bitmap).Clone(pe.ClipRectangle, PixelFormat.DontCare);
                        pe.Graphics.DrawImageUnscaled(patch, pe.ClipRectangle);
                        patch.Dispose();

                        //Draw selection rectangle
                        if (_rectangle.Width > 0 && _rectangle.Height > 0)
                        {
                            pe.Graphics.FillRectangle(_rectangleBrush, _rectangle);
                            Rectangle border = new Rectangle(_rectangle.X + (int)_rectanglePen.Width / 2, _rectangle.Y + (int)_rectanglePen.Width / 2, _rectangle.Width - (int)_rectanglePen.Width, _rectangle.Height - (int)_rectanglePen.Width);
                            pe.Graphics.DrawRectangle(_rectanglePen, border);
                        }
                    }
                    else if (_activeTool == Tools.Pan || _activeTool == Tools.ZoomIn || _activeTool == Tools.ZoomOut || _activeTool == Tools.DrawLine || _activeTool == Tools.DrawPolygon)
                    {
                        if (_map.Envelope.Equals(_imageBoundingBox))
                        {
                            pe.Graphics.DrawImageUnscaled(_image, 0, 0);
                        }
                        else
                        {
                            PointF ul = PointF.Empty;
                            PointF lr = PointF.Empty;

                            lock (_imageBoundingBox)
                            {
                                ul = _map.WorldToImage(_imageBoundingBox.TopLeft);
                                lr = _map.WorldToImage(_imageBoundingBox.BottomRight);

                                pe.Graphics.DrawImage(_image, RectangleF.FromLTRB(ul.X, ul.Y, lr.X, lr.Y));
                            }
                            if ((Math.Abs(ul.X) > 50 || Math.Abs(ul.Y) > 50) && !_isRefreshing)
                            {
                                //update the image we're dragging
                                int generation = ++_imageGeneration;
                                BoundingBox bbox = _map.Envelope;
                                //new Thread(new ThreadStart(
                                //    delegate
                                //    {
                                //        _isRefreshing = true;
                                //        GetImagesAsync(bbox);
                                //        GetImagesAsyncEnd(new GetImageEndResult { Tool = null, bbox = bbox, generation = generation });
                                //        _isRefreshing = false;
                                //    })).Start();
                            }
                        }
                    }
                    else if (_activeTool == Tools.ZoomIn || _activeTool == Tools.ZoomOut)
                    {
                        RectangleF rect = new RectangleF(0, 0, _map.Size.Width, _map.Size.Height);

                        if (_map.Zoom / _scaling < _map.MinimumZoom)
                            _scaling = (float)Math.Round(_map.Zoom / _map.MinimumZoom, 4);

                        if (_previewMode == PreviewModes.Best)
                            _scaling *= 3;

                        rect.Width *= _scaling;
                        rect.Height *= _scaling;

                        rect.Offset(_map.Size.Width / 2f - rect.Width / 2, _map.Size.Height / 2f - rect.Height / 2);

                        pe.Graphics.DrawImage(_dragImage, rect);
                    }
                }
                else if (_image != null && _image.PixelFormat != PixelFormat.Undefined)
                {
                    //if (/*_dragEndPoint != null &&*/ _dragEndPoint.X != 0 && _dragEndPoint.Y != 0 && _dragEndPoint != _dragStartPoint)
                    //{
                    //    pe.Graphics.DrawImageUnscaled(_dragImage,
                    //                                  _previewMode == PreviewModes.Best
                    //                                      ? new Point(
                    //                                            -_map.Size.Width + _dragEndPoint.X - _dragStartPoint.X,
                    //                                            -_map.Size.Height + _dragEndPoint.Y - _dragStartPoint.Y)
                    //                                      : new Point(_dragEndPoint.X - _dragStartPoint.X,
                    //                                                  _dragEndPoint.Y - _dragStartPoint.Y));
                    //}
                    //else
                    {

                        if (_map.Envelope.Equals(_imageBoundingBox))
                        {
                            pe.Graphics.DrawImageUnscaled(_image, 0, 0);
                        }
                        else
                        {
                            PointF ul = _map.WorldToImage(_imageBoundingBox.TopLeft);
                            PointF lr = _map.WorldToImage(_imageBoundingBox.BottomRight);
                            pe.Graphics.DrawImage(_image, RectangleF.FromLTRB(ul.X, ul.Y, lr.X, lr.Y));
                        }
                    }
                }


                //Draws current line or polygon (Draw Line or Draw Polygon tool)
                if (_pointArray != null)
                {
                    if (_pointArray.GetUpperBound(0) == 1)
                    {
                        PointF p1 = Map.WorldToImage(_pointArray[0]);
                        PointF p2 = Map.WorldToImage(_pointArray[1]);
                        pe.Graphics.DrawLine(new Pen(Color.Gray, 2F), p1, p2);
                    }
                    else
                    {
                        PointF[] pts = new PointF[_pointArray.Length];
                        for (int i = 0; i < pts.Length; i++)
                            pts[i] = Map.WorldToImage(_pointArray[i]);

                        if (_activeTool == Tools.DrawPolygon)
                        {
                            Color c = Color.FromArgb(127, Color.Gray);
                            pe.Graphics.FillPolygon(new SolidBrush(c), pts);
                            pe.Graphics.DrawPolygon(new Pen(Color.Gray, 2F), pts);
                        }
                        else
                            pe.Graphics.DrawLines(new Pen(Color.Gray, 2F), pts);
                    }
                }


                base.OnPaint(pe);

                /*Draw Floating Map-Decorations*/
                if (_map != null && _map.Decorations != null)
                {
                    foreach (SharpMap.Rendering.Decoration.IMapDecoration md in _map.Decorations)
                    {
                        md.Render(pe.Graphics, _map);
                    }
                }
            }
            catch (Exception ee)
            {
                Debug.WriteLine(ee.Message);
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// 打印指定页面
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">绘图操作对象</param>
        /// <param name="MainClipRect">主剪切矩形</param>
        /// <param name="PrintHead">是否打印页眉</param>
        /// <param name="PrintTail">是否打印页脚</param>
        public virtual void DrawPage(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle MainClipRect,
            bool UseMargin)
        {
            int LeftMargin   = 0;
            int TopMargin    = 0;
            int RightMargin  = 0;
            int BottomMargin = 0;

            if (UseMargin)
            {
                LeftMargin   = myPages.LeftMargin;
                TopMargin    = myPages.TopMargin;
                RightMargin  = myPages.RightMargin;
                BottomMargin = myPages.BottomMargin;
            }

            this.OnBeforeDrawPage(myPage, g);

            g.PageUnit = myDocument.DocumentGraphicsUnit;
            System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty;
            if (this.bolDrawHead)
            {
                if (myPages.HeadHeight > 0)
                {
                    g.ResetTransform();
                    g.ResetClip();

                    ClipRect = new System.Drawing.Rectangle(0, 0, myPage.Width, myPages.HeadHeight);
                    g.TranslateTransform(LeftMargin, TopMargin);

                    g.SetClip(new System.Drawing.Rectangle(
                                  ClipRect.Left,
                                  ClipRect.Top,
                                  ClipRect.Width + 1,
                                  ClipRect.Height + 1));

                    myDocument.DrawHead(g, ClipRect);
                    //DesignPaintEventArgs e = new DesignPaintEventArgs(g, ClipRect);
                    //myDocument.RefreshView(e);
                }
                g.ResetClip();
                g.ResetTransform();
            }

            ClipRect = new System.Drawing.Rectangle(
                0,
                myPages.Top,
                myPage.Width,
                myPages.Height);

            if (!MainClipRect.IsEmpty)
            {
                ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect);
            }
            if (!ClipRect.IsEmpty)
            {
                g.TranslateTransform(
                    LeftMargin,
                    TopMargin - myPage.Top + myPages.HeadHeight);

                //System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath();
                //clipPath.AddRectangle( ClipRect );
                //g.SetClip( clipPath );

                //g.TranslateTransform( myPages.LeftMargin , myPages.TopMargin - myPage.Top + myPages.HeadHeight );

                System.Drawing.RectangleF rect = DrawerUtil.FixClipBounds(
                    g,
                    ClipRect.Left,
                    ClipRect.Top,
                    ClipRect.Width,
                    ClipRect.Height);

                rect.Offset(-4, -4);
                //rect.Offset(-4, -100);
                rect.Width  = rect.Width + 8;
                rect.Height = rect.Height + 8;
                g.SetClip(rect);

//				System.Drawing.RectangleF rect2 = g.ClipBounds ;
//				if( rect.Top < rect2.Top )
//				{
//					float dy = rect2.Top - rect.Top ;
//					rect.Y = rect.Y - dy * 2 ;
//					rect.Height = rect.Height + dy * 4 ;
//				}
//				g.SetClip( rect );

                myDocument.DrawDocument(g, ClipRect);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            }

            if (this.bolDrawFooter)
            {
                if (myPages.FooterHeight > 0)
                {
                    g.ResetClip();
                    g.ResetTransform();

                    ClipRect = new System.Drawing.Rectangle(
                        0,
                        myPages.DocumentHeight - myPages.FooterHeight,
                        myPage.Width,
                        myPages.FooterHeight);

                    int dy = 0;
                    if (UseMargin)
                    {
                        dy = myPages.PaperHeight - myPages.BottomMargin - myPages.DocumentHeight;
                    }
                    else
                    {
                        dy = myPages.PaperHeight - myPages.BottomMargin - myPages.DocumentHeight - myPages.TopMargin;
                    }
                    g.TranslateTransform(
                        LeftMargin,
                        dy);

                    g.SetClip(new System.Drawing.Rectangle(
                                  ClipRect.Left,
                                  ClipRect.Top,
                                  ClipRect.Width + 1,
                                  ClipRect.Height + 1));

                    myDocument.DrawFooter(g, ClipRect);
                    //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                    //myDocument.RefreshView( e );
                }
            } //if( this.bolDrawFooter )
        }     //public void DrawPage()
Exemplo n.º 33
0
        /// <summary>
        /// Computes the layout of all visible text spans and stores them the 
        /// member variable 'visibleLines'. This includes a final partial item on the end.
        /// </summary>
        /// <param name="g"></param>
        protected void ComputeLayout(Graphics g)
        {
            GetStyleStack().PushStyle(StyleClass);
            this.visibleLines = new SortedList<float, LayoutLine>();
            SizeF szClient = new SizeF(ClientSize);
            var rcLine = new RectangleF(0, 0, szClient.Width, 0);

            // Get the lines.
            object oldPos = null;
            var m = model ?? new EmptyEditorModel();
            oldPos = model.CurrentPosition;
            var lines = m.GetLineSpans(1);
            while (rcLine.Top < szClient.Height && 
                   lines != null && lines.Length == 1)
            {
                var line = lines[0];
                float cyLine = MeasureLineHeight(line);
                rcLine.Height = cyLine;
                var ll = new LayoutLine(line.Position) { 
                    Extent = rcLine,
                    Spans = ComputeSpanLayouts(line.TextSpans, rcLine, g)
                };
                this.visibleLines.Add(rcLine.Top, ll);
                lines = m.GetLineSpans(1);
                rcLine.Offset(0, cyLine);
            }
            GetStyleStack().PopStyle();
            model.MoveToLine(oldPos, 0);
        }
        public override void LayoutSubviews()
        {
            base.LayoutSubviews ();

            ImageView.Frame = new RectangleF(10, 10, 50, 50);
            TextLabel.Frame = new RectangleF(70, 10, 240, 20);

            var detailsFrame = new RectangleF(TextLabel.Frame.Location, TextLabel.Frame.Size);
            detailsFrame.Offset(0, 25);
            detailsFrame.Height = CalculatePostHeight() - 45;
            DetailTextLabel.Frame = detailsFrame;
        }
Exemplo n.º 35
0
    } // end of function MeasureStructure

    /*
    protected void MeasureBackground()
    {

      float distanceXL = 0; // left distance bounds-text
      float distanceXR = 0; // right distance text-bounds
      float distanceYU = 0;   // upper y distance bounding rectangle-string
      float distanceYL = 0; // lower y distance

      if(this.m_BackgroundStyle!=BackgroundStyle.None)
      {
        // the distance to the sides should be like the character n
        distanceXL = 0.5f*m_WidthOfOne_n; // left distance bounds-text
        distanceXR = distanceXL; // right distance text-bounds
        distanceYU = m_cyBaseDescent;   // upper y distance bounding rectangle-string
        distanceYL = 0; // lower y distance

        // add some additional distance in case of special backgrounds
        switch(this.m_BackgroundStyle)
        {
          case BackgroundStyle.Shadow:
            distanceXR += this.m_ShadowLength; // the shadow extends to the right
            distanceYL += this.m_ShadowLength; // and to the lower bound
            break;
          case BackgroundStyle.DarkMarbel:
            distanceXL += this.m_ShadowLength; // darkmarbel has a rim of a Shadowlen
            distanceXR += this.m_ShadowLength; // to all sides
            distanceYU += this.m_ShadowLength;
            distanceYL += this.m_ShadowLength;
            break;
        }
      }

      SizeF size = new SizeF(m_TextWidth+distanceXL+distanceXR,m_TextHeight+distanceYU+distanceYL);

      
      float xanchor=0;
      float yanchor=0;
      if(m_XAnchorType==XAnchorPositionType.Center)
        xanchor = size.Width/2.0f;
      else if(m_XAnchorType==XAnchorPositionType.Right)
        xanchor = size.Width;

      if(m_YAnchorType==YAnchorPositionType.Center)
        yanchor = size.Height/2.0f;
      else if(m_YAnchorType==YAnchorPositionType.Bottom)
        yanchor = size.Height;
      
      this.m_Bounds = new RectangleF(new PointF(-xanchor,-yanchor),size);
      this.m_TextOffset = new PointF(distanceXL,distanceYU);
    }
     */

    protected void MeasureBackground(Graphics g)
    {

      float distanceXL = 0; // left distance bounds-text
      float distanceXR = 0; // right distance text-bounds
      float distanceYU = 0;   // upper y distance bounding rectangle-string
      float distanceYL = 0; // lower y distance

      
      if (this._background != null)
      {
        // the distance to the sides should be like the character n
        distanceXL = 0.25f * _widthOfOne_n; // left distance bounds-text
        distanceXR = distanceXL; // right distance text-bounds
        distanceYU = _cyBaseDescent;   // upper y distance bounding rectangle-string
        distanceYL = 0; // lower y distance
      }
      
      SizeF size = new SizeF(_cachedTextWidth + distanceXL + distanceXR, _cachedTextHeight + distanceYU + distanceYL);
      _cachedExtendedTextBounds = new RectangleF(PointF.Empty, size);
      RectangleF textRectangle = new RectangleF(new PointF(-distanceXL, -distanceYU), size);

      if (this._background != null)
      {
        RectangleF backgroundRect = this._background.MeasureItem(g, textRectangle);
        _cachedExtendedTextBounds.Offset(textRectangle.X - backgroundRect.X, textRectangle.Y - backgroundRect.Y);

        size = backgroundRect.Size;
        distanceXL = -backgroundRect.Left;
        distanceXR = backgroundRect.Right - _cachedTextWidth;
        distanceYU = -backgroundRect.Top;
        distanceYL = backgroundRect.Bottom - _cachedTextHeight;
      }

      float xanchor = 0;
      float yanchor = 0;
      if (_xAnchorType == XAnchorPositionType.Center)
        xanchor = size.Width / 2.0f;
      else if (_xAnchorType == XAnchorPositionType.Right)
        xanchor = size.Width;

      if (_yAnchorType == YAnchorPositionType.Center)
        yanchor = size.Height / 2.0f;
      else if (_yAnchorType == YAnchorPositionType.Bottom)
        yanchor = size.Height;

      this._bounds = new RectangleF(new PointF(-xanchor, -yanchor), size);
      this._cachedTextOffset = new PointF(distanceXL, distanceYU);
      
    }
Exemplo n.º 36
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            try
            {
                if (_dragging)
                {
                    if (_activeTool == Tools.ZoomWindow || _activeTool == Tools.Query || (_shiftButtonDragRectangleZoom && (Control.ModifierKeys & Keys.Shift) != Keys.None))
                    {
                        //Reset image to normal view
                        Bitmap patch = _dragImage.Clone(pe.ClipRectangle, PixelFormat.DontCare);
                        pe.Graphics.DrawImageUnscaled(patch, pe.ClipRectangle);
                        patch.Dispose();

                        //Draw selection rectangle
                        if (_rectangle.Width > 0 && _rectangle.Height > 0)
                        {
                            pe.Graphics.FillRectangle(_rectangleBrush, _rectangle);
                            Rectangle border = new Rectangle(_rectangle.X + (int)_rectanglePen.Width / 2, _rectangle.Y + (int)_rectanglePen.Width / 2, _rectangle.Width - (int)_rectanglePen.Width, _rectangle.Height - (int)_rectanglePen.Width);
                            pe.Graphics.DrawRectangle(_rectanglePen, border);
                        }
                    }
                    else if (_activeTool == Tools.Pan)
                    {
                        pe.Graphics.DrawImageUnscaled(_dragImage,
                                                      _previewMode == PreviewModes.Best
                                                          ? new Point(
                                                                -_map.Size.Width + _dragEndPoint.X - _dragStartPoint.X,
                                                                -_map.Size.Height + _dragEndPoint.Y - _dragStartPoint.Y)
                                                          : new Point(_dragEndPoint.X - _dragStartPoint.X,
                                                                      _dragEndPoint.Y - _dragStartPoint.Y));
                    }
                    else if (_activeTool == Tools.ZoomIn || _activeTool == Tools.ZoomOut)
                    {
                        RectangleF rect = new RectangleF(0, 0, _map.Size.Width, _map.Size.Height);

                        if (_map.Zoom / _scaling < _map.MinimumZoom)
                            _scaling = (float)Math.Round(_map.Zoom / _map.MinimumZoom, 4);

                        //System.Diagnostics.Debug.WriteLine("Scaling: " + m_Scaling);

                        if (_previewMode == PreviewModes.Best)
                            _scaling *= 3;

                        rect.Width *= _scaling;
                        rect.Height *= _scaling;

                        rect.Offset(_map.Size.Width / 2f - rect.Width / 2, _map.Size.Height / 2f - rect.Height / 2);

                        pe.Graphics.DrawImage(_dragImage, rect);
                    }
                }
                else if (_image != null && _image.PixelFormat != PixelFormat.Undefined)
                {
                    if (/*_dragEndPoint != null &&*/ _dragEndPoint.X != 0 && _dragEndPoint.Y != 0 && _dragEndPoint != _dragStartPoint)
                    {
                        pe.Graphics.DrawImageUnscaled(_dragImage,
                                                      _previewMode == PreviewModes.Best
                                                          ? new Point(
                                                                -_map.Size.Width + _dragEndPoint.X - _dragStartPoint.X,
                                                                -_map.Size.Height + _dragEndPoint.Y - _dragStartPoint.Y)
                                                          : new Point(_dragEndPoint.X - _dragStartPoint.X,
                                                                      _dragEndPoint.Y - _dragStartPoint.Y));
                    }
                    else
                    {
                        pe.Graphics.DrawImageUnscaled(_image, 0, 0);

                        //Draws current line or polygon (Draw Line or Draw Polygon tool)
                        if (_pointArray != null)
                        {
                            if (_pointArray.GetUpperBound(0) == 1)
                            {
                                pe.Graphics.DrawLine(new Pen(Color.Gray, 2F), _pointArray[0], _pointArray[1]);
                            }
                            else
                            {
                                if (_activeTool == Tools.DrawPolygon)
                                {
                                    Color c = Color.FromArgb(127, Color.Gray);
                                    pe.Graphics.FillPolygon(new SolidBrush(c), _pointArray);
                                    pe.Graphics.DrawPolygon(new Pen(Color.Gray, 2F), _pointArray);
                                }
                                else
                                    pe.Graphics.DrawLines(new Pen(Color.Gray, 2F), _pointArray);
                            }
                        }
                    }
                }
                else
                    base.OnPaint(pe);

                /*Draw Floating Map-Decorations*/
                if (_map != null && _map.Decorations != null)
                {
                    foreach (SharpMap.Rendering.Decoration.IMapDecoration md in _map.Decorations)
                    {
                        md.Render(pe.Graphics, _map);
                    }
                }
            }
            catch (Exception ee)
            {
                Debug.WriteLine(ee.Message);
            }
        }
Exemplo n.º 37
0
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                if (ImageListView.View == Manina.Windows.Forms.View.Thumbnails)
                {
                    Size itemPadding = new Size(4, 4);

                    // Paint background
                    using (Brush bItemBack = new SolidBrush(item.BackColor))
                    {
                        g.FillRectangle(bItemBack, bounds);
                    }
                    if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
                        (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
                    {
                        using (Brush bSelected = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.Highlight), Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bSelected, bounds, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Brush bGray64 = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.GrayText), Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bGray64, bounds, 4);
                        }
                    }
                    if (((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Brush bHovered = new LinearGradientBrush(bounds, Color.FromArgb(8, SystemColors.Highlight), Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bHovered, bounds, 4);
                        }
                    }

                    // Draw the image
                    Image img = item.ThumbnailImage;
                    if (img != null)
                    {
                        Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize), 0.0f, 50.0f);
                        g.DrawImage(img, pos);
                        // Draw image border
                        if (Math.Min(pos.Width, pos.Height) > 32)
                        {
                            using (Pen pGray128 = new Pen(Color.FromArgb(128, Color.Gray)))
                            {
                                g.DrawRectangle(pGray128, pos);
                            }
                            using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                            {
                                g.DrawRectangle(pWhite128, Rectangle.Inflate(pos, -1, -1));
                            }
                        }

                        // Draw item text
                        int lineHeight = CaptionFont.Height;
                        RectangleF rt;
                        using (StringFormat sf = new StringFormat())
                        {
                            rt = new RectangleF(bounds.Left + 2 * itemPadding.Width + ImageListView.ThumbnailSize.Width,
                                bounds.Top + itemPadding.Height + (Math.Max(ImageListView.ThumbnailSize.Height, mTextHeight) - mTextHeight) / 2,
                                mTileWidth, lineHeight);
                            sf.Alignment = StringAlignment.Near;
                            sf.FormatFlags = StringFormatFlags.NoWrap;
                            sf.LineAlignment = StringAlignment.Center;
                            sf.Trimming = StringTrimming.EllipsisCharacter;
                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                g.DrawString(item.Text, CaptionFont, bItemFore, rt, sf);
                            }
                            using (Brush bItemDetails = new SolidBrush(Color.Gray))
                            {
                                rt.Offset(0, 1.5f * lineHeight);
                                if (!string.IsNullOrEmpty(item.FileType))
                                {
                                    g.DrawString(item.GetSubItemText(ColumnType.FileType),
                                        ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);
                                }
                                if (item.Dimensions != Size.Empty || item.Resolution != SizeF.Empty)
                                {
                                    string text = "";
                                    if (item.Dimensions != Size.Empty)
                                        text += item.GetSubItemText(ColumnType.Dimensions) + " pixels ";
                                    if (item.Resolution != SizeF.Empty)
                                        text += item.Resolution.Width + " dpi";
                                    g.DrawString(text, ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);
                                }
                                if (item.FileSize != 0)
                                {
                                    g.DrawString(item.GetSubItemText(ColumnType.FileSize),
                                        ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);
                                }
                                if (item.DateModified != DateTime.MinValue)
                                {
                                    g.DrawString(item.GetSubItemText(ColumnType.DateModified),
                                        ImageListView.Font, bItemDetails, rt, sf);
                                }
                            }
                        }
                    }

                    // Item border
                    using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                    {
                        Utility.DrawRoundedRectangle(g, pWhite128, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
                    }
                    if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(Color.FromArgb(128, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.None)
                    {
                        using (Pen pGray64 = new Pen(Color.FromArgb(64, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Pen pHighlight64 = new Pen(Color.FromArgb(64, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    // Focus rectangle
                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        ControlPaint.DrawFocusRectangle(g, bounds);
                    }
                }
                else
                    base.DrawItem(g, item, state, bounds);
            }
 public static void DrawStringDisabled(Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     layoutRectangle.Offset(1f, 1f);
     using (SolidBrush brush = new SolidBrush(LightLight(color)))
     {
         graphics.DrawString(s, font, brush, layoutRectangle, format);
         layoutRectangle.Offset(-1f, -1f);
         color = Dark(color);
         brush.Color = color;
         graphics.DrawString(s, font, brush, layoutRectangle, format);
     }
 }
Exemplo n.º 39
0
 protected override void Paint(PPaintContext paintContext)
 {
     paintContext.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
     if (shadowRendering && base.Text != null && base.TextBrush != null && base.Font != null)
     {
         Graphics g = paintContext.Graphics;
         float renderedFontSize = base.Font.SizeInPoints * paintContext.Scale;
         if(paintContext.Scale >= 1)
             if (renderedFontSize >= PUtil.GreekThreshold && renderedFontSize < PUtil.MaxFontSize)
             {
                 RectangleF shadowbounds = new RectangleF();
                 shadowbounds = Bounds;
                 shadowbounds.Offset(1, 1);
                 StringFormat stringformat = new StringFormat();
                 stringformat.Alignment = base.TextAlignment;
                 g.DrawString(base.Text, base.Font, black, shadowbounds, stringformat);
             }
     }
     base.Paint(paintContext);
 }