Beispiel #1
0
        private void DrawItem(ISnoItem snoItem, IPlayer player)
        {
            var portraitRect = player.PortraitUiElement.Rectangle;

            var itemRect = new System.Drawing.RectangleF(currentX, portraitRect.Y, Hud.Window.Size.Width * ItemRatio, Hud.Window.Size.Width * ItemRatio * 2);

            itemRect.Offset(0, currY);
            if (snoItem.ItemHeight == 1)
            {
                itemRect.Offset(0, currY);
                itemRect.Height /= 2;
            }

            var slotTexture = Hud.Texture.InventorySlotTexture;

            slotTexture.Draw(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height);

            if (Hud.Window.CursorInsideRect(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height))
            {
                var itemName = snoItem.NameLocalized;

                var power     = snoItem.LegendaryPower;
                var powerDesc = "";
                if (power != null)
                {
                    itemName += "\n\n";
                    powerDesc = power.DescriptionLocalized;
                    var patternBegin = powerDesc.IndexOf("{c_magic}");
                    if (patternBegin != -1)
                    {
                        var patternEnd = powerDesc.IndexOf("{/c}") != -1 ? powerDesc.IndexOf("{/c}") + 4 : powerDesc.IndexOf("{/c_magic}") + 10;
                        if (patternEnd != -1)
                        {
                            var toReplace   = powerDesc.Substring(patternBegin, patternEnd - patternBegin);
                            var replacement = toReplace.Contains("%") ? "X%" : "X";
                            powerDesc = powerDesc.Replace(toReplace, replacement);
                        }
                    }
                }

                Hud.Render.SetHint(itemName + powerDesc);
            }

            var backgroundTexture = snoItem.ItemHeight == 2 ? Hud.Texture.InventoryLegendaryBackgroundLarge : Hud.Texture.InventoryLegendaryBackgroundSmall;

            backgroundTexture.Draw(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height);

            var itemTexture = Hud.Texture.GetItemTexture(snoItem);

            if (itemTexture != null)
            {
                itemTexture.Draw(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height);
            }
            currentX += itemRect.Width;
        }
        protected void WireUpDragGestureRecognizer()
        {
            //---- create a new tap gesture
            this._dragGesture = new GestureRecognizer <UIPanGestureRecognizer>();
            //---- wire up the event handler (have to use a selector)
            this._dragGesture.GestureUpdated += (UIPanGestureRecognizer r) => {
                //---- if it's just began, cache the location of the image
                if (r.State == UIGestureRecognizerState.Began)
                {
                    this._originalImageFrame = this.imgDragMe.Frame;
                }

                if (r.State != (UIGestureRecognizerState.Cancelled | UIGestureRecognizerState.Failed
                                | UIGestureRecognizerState.Possible))
                {
                    //---- move the shape by adding the offset to the object's frame
                    System.Drawing.PointF     offset   = r.TranslationInView(this.imgDragMe);
                    System.Drawing.RectangleF newFrame = this._originalImageFrame;
                    newFrame.Offset(offset.X, offset.Y);
                    this.imgDragMe.Frame = newFrame;
                }
            };
            //---- add the gesture recognizer to the view
            this.imgDragMe.AddGestureRecognizer(this._dragGesture.Recognizer);
        }
        private void AddChild(GraphElement child)
        {
            // Remove all holes from the sibling index list. Now the max index
            // number is equal to the size of the children list.
            this.EnsureSequentialSiblingIndex();
            this.needSortChildren = true; // maybe false
            child.siblingIndex    = this.childCount;
            //this.children.Add(child);
            if (this.childCount == this.children.Length)
            {
                GraphElement[] childs;
                if (this.childCount == 0)
                {
                    childs = new GraphElement[4];
                }
                else
                {
                    childs = new GraphElement[2 * this.childCount];
                    Array.Copy(this.children, 0, childs, 0, this.childCount);
                }
                this.children = childs;
            }
            this.children[this.childCount++] = child;

            this.OnChildAdded(child);
            System.Drawing.RectangleF invalid = child.ChildrenBoundingBox();
            invalid.Offset(child.X, child.Y);
            this.Invalidate(invalid);
        }
Beispiel #4
0
        private void DrawKanaiItem(ISnoItem snoItem, System.Drawing.RectangleF portraitRect)
        {
            var inventoryRect = Hud.Inventory.InventoryMainUiElement.Rectangle;

            var itemRect = new System.Drawing.RectangleF(currentX, portraitRect.Y, Hud.Window.Size.Width * KanaiRatio, Hud.Window.Size.Width * KanaiRatio * 2);

            itemRect.Offset(0, YOffset);
            if (snoItem.ItemHeight == 1)
            {
                itemRect.Offset(0, YOffset);
                itemRect.Height /= 2;
            }

            var slotTexture = Hud.Texture.InventorySlotTexture;

            slotTexture.Draw(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height);

            if (Hud.Window.CursorInsideRect(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height))
            {
                var description = snoItem.NameLocalized;

                var power = snoItem.LegendaryPower;
                if (power != null)
                {
                    description += "\n\n" + power.DescriptionLocalized;
                }

                Hud.Render.SetHint(description);
            }

            var backgroundTexture = snoItem.ItemHeight == 2 ? Hud.Texture.InventoryLegendaryBackgroundLarge : Hud.Texture.InventoryLegendaryBackgroundSmall;

            backgroundTexture.Draw(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height);

            var itemTexture = Hud.Texture.GetItemTexture(snoItem);

            if (itemTexture != null)
            {
                itemTexture.Draw(itemRect.X, itemRect.Y, itemRect.Width, itemRect.Height);
            }
            currentX += itemRect.Width;
        }
        private void RemoveChild(GraphElement child)
        {
            // When removing elements in the middle of the children list,
            // there will be a "gap" in the list of sibling indexes (0,1,3,4).
            if (!this.holesInSiblingIndex)
            {
                this.holesInSiblingIndex
                    = child.siblingIndex != this.childCount - 1;
            }
            if (this.sequentialOrdering && !this.holesInSiblingIndex)
            {
                //this.children.RemoveAt(child.siblingIndex);
                this.childCount--;
                Array.Copy(this.children, child.siblingIndex + 1,
                           this.children, child.siblingIndex,
                           this.childCount - child.siblingIndex);
                this.children[this.childCount] = null;
            }
            else
            {
                //this.children.Remove(child);
                int i;
                for (i = 0; i < this.childCount; i++)
                {
                    if (this.children[i] == child)
                    {
                        break;
                    }
                }
                if (i < this.childCount)
                {
                    this.childCount--;
                    Array.Copy(this.children, i + 1,
                               this.children, i, this.childCount - i);
                    this.children[this.childCount] = null;
                }
            }
            // NB! Do not use children.RemoveAt(child.siblingIndex) because
            // the child is not guaranteed to be at the index after the list is sorted.
            // (see ensureSortedChildren()).
            child.siblingIndex = -1;

            this.OnChildRemoved(child);
            System.Drawing.RectangleF invalid = child.ChildrenBoundingBox();
            invalid.Offset(child.X, child.Y);
            this.Invalidate(invalid);
        }
Beispiel #6
0
        internal System.Drawing.RectangleF GetScreenBounds()
        {
            if (this.IsRoot || this.ParentElement == null)
            {
                PropState.ScreenBounds = this.Bounds;
            }
            else
            {
                this.ParentElement.UpdateTransforms();

                this.UpdateProps();

                if (!PropState.ScreenBounds.HasValue)
                {
                    tmpBounds = this.Bounds;

                    tmpBounds.Offset(this.RotationCenter.X * this.ScaleVector.X, this.RotationCenter.Y * this.ScaleVector.Y);

                    if (this.ParentElement.TransState.LocationTransform != Matrix.Identity)
                    {
                        tmpVector1.X = tmpBounds.X;
                        tmpVector1.Y = tmpBounds.Y;
                        Vector2.Transform(ref tmpVector1, ref this.ParentElement.TransState.LocationTransform, out tmpVector2);
                        tmpBounds.X = tmpVector2.X;
                        tmpBounds.Y = tmpVector2.Y;
                    }

                    if (this.ParentElement.TransState.ScaleTransform != Matrix.Identity)
                    {
                        Vector2.Transform(ref PropState.Size, ref this.ParentElement.TransState.ScaleTransform, out tmpVector2);
                        tmpBounds.Width  = tmpVector2.X;
                        tmpBounds.Height = tmpVector2.Y;
                    }
                    else
                    {
                        tmpBounds.Width  = PropState.Size.X;
                        tmpBounds.Height = PropState.Size.Y;
                    }

                    PropState.ScreenBounds = tmpBounds;
                }
            }

            return(PropState.ScreenBounds.Value);
        }
        protected void HandleDrag(UIPanGestureRecognizer recognizer)
        {
            // if it's just began, cache the location of the image
            if (recognizer.State == UIGestureRecognizerState.Began)
            {
                originalImageFrame = imgDragMe.Frame;
            }

            if (recognizer.State != (UIGestureRecognizerState.Cancelled | UIGestureRecognizerState.Failed
                                     | UIGestureRecognizerState.Possible))
            {
                // move the shape by adding the offset to the object's frame
                System.Drawing.PointF     offset   = recognizer.TranslationInView(imgDragMe);
                System.Drawing.RectangleF newFrame = originalImageFrame;
                newFrame.Offset(offset.X, offset.Y);
                imgDragMe.Frame = newFrame;
            }
        }
Beispiel #8
0
 public override void OnLayout(IGUIContext ctx, System.Drawing.RectangleF bounds)
 {
     bounds.Offset(0, OffsetY);
     base.OnLayout(ctx, bounds);
 }
 public static System.Drawing.RectangleF Offset(this System.Drawing.RectangleF rect, Vector2 offset)
 {
     rect.Offset(offset.X, offset.Y); return(rect);
 }
Beispiel #10
0
        public void DrawTextLayout()
        {
            {
                using var font = new Font(20);
                using var bmp  = new Bitmap(620, 600);
                using var g    = Graphics.FromImage(bmp);

                var text = "Hello Future! 你好,未来!";

                var sf   = new StringFormat();
                var rect = new RectangleF(5, 5, 200, 80);
                for (int i = 0; i < 3; i++)
                {
                    var rectX = rect;
                    for (int j = 0; j < 3; j++)
                    {
                        g.DrawRectangle(Color.Black, 1f, rectX);
                        sf.Alignment     = (StringAlignment)i;
                        sf.LineAlignment = (StringAlignment)j;
                        g.DrawString(text, font, Color.Red, rectX, sf);

                        rectX.Offset(200 + 5, 0);
                    }

                    rect.Offset(0, rect.Height + 10);
                }

                using var fs = File.OpenWrite(OutFile);
                bmp.Save(fs, ImageFormat.Jpeg);
                fs.Close();
            }

            //----以下System.Drawing对比----
            {
                using var font = new System.Drawing.Font("PingFang SC", 15);
                var points = font.SizeInPoints;
                var height = font.Height;

                using var bmp   = System.Drawing.Bitmap.FromFile(OutFile);
                using var g     = System.Drawing.Graphics.FromImage(bmp);
                using var pen   = new System.Drawing.Pen(System.Drawing.Color.Black, 1);
                using var brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

                var text = "Hello Future! 你好,未来!";

                var sf   = new System.Drawing.StringFormat();
                var rect = new System.Drawing.RectangleF(5, 305, 200, 80);
                for (int i = 0; i < 3; i++)
                {
                    var rectX = rect;
                    for (int j = 0; j < 3; j++)
                    {
                        g.DrawRectangle(pen, rectX.X, rectX.Y, rectX.Width, rectX.Height);

                        sf.Alignment     = (System.Drawing.StringAlignment)i;
                        sf.LineAlignment = (System.Drawing.StringAlignment)j;
                        g.DrawString(text, font, brush, rectX, sf);

                        rectX.Offset(200 + 5, 0);
                    }

                    rect.Offset(0, rect.Height + 10);
                }

                using var fs = File.OpenWrite(OutFile);
                bmp.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
Beispiel #11
0
        void FeedListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if (this.View == View.Tile)
            {
                Feed feed = (Feed) e.Item.Tag;

                // draw the background and focus rectangle for selected and non-selected states
                e.DrawBackground();
                if (e.Item.Selected)
                {
                    e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds);
                    ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
                }

                // draw icon
                int newX = e.Bounds.Left;
                /*
                System.Drawing.Image img = this.imageList.Images[e.Item.ImageKey];
                if (img != null)
                {
                    int x = e.Bounds.Left;
                    int y = e.Bounds.Top;
                    e.Graphics.DrawImage(img, x, y);
                    newX = e.Bounds.Left + img.Width + this.Margin.Right;
                    img.Dispose();
                }
                 * */

                // draw main text
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, e.Bounds.Top, e.Bounds.Right - newX, e.Item.Font.Height);
                System.Drawing.StringFormat sf = new System.Drawing.StringFormat();
                sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter;
                sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip;
                System.Drawing.SolidBrush foreBrush = new System.Drawing.SolidBrush(e.Item.ForeColor);
                using (foreBrush)
                {
                    e.Graphics.DrawString(feed.Name,
                        e.Item.Font,
                        foreBrush,
                        rect,
                        sf);
                }

                // draw subitems
                System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb());
                System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor);
                using (subBrush)
                {
                    for (int i = 1; i < this.Columns.Count; i++)
                    {
                        if (i < e.Item.SubItems.Count)
                        {
                            rect.Offset(0, e.Item.Font.Height);
                            e.Graphics.DrawString(e.Item.SubItems[i].Text,
                                e.Item.Font,
                                subBrush,
                                rect,
                                sf);
                        }
                    }
                }
            }
            else
            {
                e.DrawDefault = true;
            }
        }
        void HistoryListView_DrawItem(object sender, DrawListViewItemEventArgs e)

        {
            if (e.ItemIndex < 0)
            {
                return;
            }



            if (this.View == View.Tile)

            {
                // draw the background and focus rectangle for selected and non-selected states

                if (this.SelectedIndices.Contains(e.ItemIndex))

                {
                    e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds);

                    ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
                }

                else

                {
                    e.DrawBackground();
                }



                // draw icon

                PastNotification pn = (PastNotification)e.Item.Tag;

                int newX = e.Bounds.Left;

                if (pn != null)

                {
                    System.Drawing.Image img = PastNotificationManager.GetImage(pn);

                    using (img)

                    {
                        if (img != null)

                        {
                            int x = e.Bounds.Left + 1;

                            int y = e.Bounds.Top + 1;

                            e.Graphics.DrawImage(img, x, y);

                            newX = e.Bounds.Left + img.Width + this.Margin.Right;
                        }
                    }
                }



                // draw main text

                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, e.Bounds.Top, e.Bounds.Right - newX, e.Item.Font.Height);

                System.Drawing.StringFormat sf = new System.Drawing.StringFormat();

                sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter;

                sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip;

                System.Drawing.SolidBrush foreBrush = new System.Drawing.SolidBrush(e.Item.ForeColor);

                string text = e.Item.Text.Replace("\r", " - ");

                using (foreBrush)

                {
                    e.Graphics.DrawString(text,

                                          e.Item.Font,

                                          foreBrush,

                                          rect,

                                          sf);
                }



                // draw subitems

                System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb());

                System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor);

                using (subBrush)

                {
                    for (int i = 1; i < this.Columns.Count; i++)

                    {
                        if (i < e.Item.SubItems.Count)

                        {
                            text = e.Item.SubItems[i].Text.Replace("\r", " - ");

                            rect.Offset(0, e.Item.Font.Height);

                            e.Graphics.DrawString(text,

                                                  e.Item.Font,

                                                  subBrush,

                                                  rect,

                                                  sf);
                        }
                    }
                }
            }

            else

            {
                // DO NOT call e.DrawDefault or the DrawSubItem event will not be fired

                //e.DrawDefault = true;
            }
        }
Beispiel #13
0
		internal System.Drawing.RectangleF GetScreenBounds()
		{
			if (this.IsRoot || this.ParentElement == null)
			{
                PropState.ScreenBounds = this.Bounds;
			}
			else
			{
                this.ParentElement.UpdateTransforms();

                this.UpdateProps();

                if (!PropState.ScreenBounds.HasValue)
                {
                    tmpBounds = this.Bounds;

                    tmpBounds.Offset(this.RotationCenter.X * this.ScaleVector.X, this.RotationCenter.Y * this.ScaleVector.Y);

                    if (this.ParentElement.TransState.LocationTransform != Matrix.Identity)
                    {
                        tmpVector1.X = tmpBounds.X;
                        tmpVector1.Y = tmpBounds.Y;
                        Vector2.Transform(ref tmpVector1, ref this.ParentElement.TransState.LocationTransform, out tmpVector2);
                        tmpBounds.X = tmpVector2.X;
                        tmpBounds.Y = tmpVector2.Y;
                    }

                    if (this.ParentElement.TransState.ScaleTransform != Matrix.Identity)
                    {
                        Vector2.Transform(ref PropState.Size, ref this.ParentElement.TransState.ScaleTransform, out tmpVector2);
                        tmpBounds.Width = tmpVector2.X;
                        tmpBounds.Height = tmpVector2.Y;
                    }
                    else
                    {
                        tmpBounds.Width = PropState.Size.X;
                        tmpBounds.Height = PropState.Size.Y;
                    }

                    PropState.ScreenBounds = tmpBounds;
                }
            }
			
			return PropState.ScreenBounds.Value;
		}
        void FeedListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if (this.View == View.Tile)
            {
                Feed feed = (Feed)e.Item.Tag;

                // draw the background and focus rectangle for selected and non-selected states
                e.DrawBackground();
                if (e.Item.Selected)
                {
                    e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds);
                    ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
                }

                // draw icon
                int newX = e.Bounds.Left;

                /*
                 * System.Drawing.Image img = this.imageList.Images[e.Item.ImageKey];
                 * if (img != null)
                 * {
                 *  int x = e.Bounds.Left;
                 *  int y = e.Bounds.Top;
                 *  e.Graphics.DrawImage(img, x, y);
                 *  newX = e.Bounds.Left + img.Width + this.Margin.Right;
                 *  img.Dispose();
                 * }
                 * */

                // draw main text
                System.Drawing.RectangleF   rect = new System.Drawing.RectangleF(newX, e.Bounds.Top, e.Bounds.Right - newX, e.Item.Font.Height);
                System.Drawing.StringFormat sf   = new System.Drawing.StringFormat();
                sf.Trimming    = System.Drawing.StringTrimming.EllipsisCharacter;
                sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip;
                System.Drawing.SolidBrush foreBrush = new System.Drawing.SolidBrush(e.Item.ForeColor);
                using (foreBrush)
                {
                    e.Graphics.DrawString(feed.Name,
                                          e.Item.Font,
                                          foreBrush,
                                          rect,
                                          sf);
                }

                // draw subitems
                System.Drawing.Color      subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb());
                System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor);
                using (subBrush)
                {
                    for (int i = 1; i < this.Columns.Count; i++)
                    {
                        if (i < e.Item.SubItems.Count)
                        {
                            rect.Offset(0, e.Item.Font.Height);
                            e.Graphics.DrawString(e.Item.SubItems[i].Text,
                                                  e.Item.Font,
                                                  subBrush,
                                                  rect,
                                                  sf);
                        }
                    }
                }
            }
            else
            {
                e.DrawDefault = true;
            }
        }
        void ForwardListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if (this.View == View.Tile)
            {
                int checkBoxAreaWidth = CHECKBOX_PADDING + CHECKBOX_SIZE + CHECKBOX_PADDING;
                System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(e.Bounds.X + checkBoxAreaWidth, e.Bounds.Top, e.Bounds.Width - checkBoxAreaWidth, e.Bounds.Height);

                // update information
                DestinationBase fc = (DestinationBase)e.Item.Tag;
                string display = Escape(fc.Display);
                string address = Escape(fc.AddressDisplay);
                string additional = Escape(fc.AdditionalDisplayInfo);
                string tooltip = String.Format("{0}\r\n{1}{2}", fc.Display, fc.AddressDisplay, (!String.IsNullOrEmpty(fc.AdditionalDisplayInfo) ? String.Format("\r\n{0}", fc.AdditionalDisplayInfo) : null));
                e.Item.ToolTipText = tooltip;
                // NOTE: dont set the .Text or .SubItem properties here - it causes an erratic exception

                bool drawEnabled = ShouldDrawEnabled(fc);
                bool selected = this.SelectedIndices.Contains(e.ItemIndex);

                // draw the background for selected states
                if(drawEnabled && selected)
                {
                    e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds);
                }
                else
                {
                    e.DrawBackground();
                }

                // draw the focus rectangle
                if (selected)
                    ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);

                // draw icon
                int newX = bounds.X;
                DestinationBase db = e.Item.Tag as DestinationBase;
                if (db != null)
                {
                    System.Drawing.Image img = db.GetIcon();

                    // size
                    if (img.Width > IMAGE_SIZE)
                    {
                        System.Drawing.Image resized = new System.Drawing.Bitmap(IMAGE_SIZE, IMAGE_SIZE);
                        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(resized);
                        using (g)
                        {
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.DrawImage(img, 0, 0, IMAGE_SIZE, IMAGE_SIZE);
                        }
                        img = resized;
                    }

                    if (img != null)
                    {
                        int x = bounds.X;
                        int y = bounds.Top;
                        if (drawEnabled)
                            e.Graphics.DrawImage(img, new System.Drawing.Rectangle(x, y, img.Width, img.Height));
                        else
                            ControlPaint.DrawImageDisabled(e.Graphics, img, x, y, System.Drawing.Color.Transparent);
                        newX += IMAGE_SIZE + this.Margin.Right;
                    }
                }

                // offset the text vertically a bit so it lines up with the icon better
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, bounds.Top, bounds.Right - newX, e.Item.Font.Height);
                rect.Offset(0, 4);

                // draw main text
                System.Drawing.Color textColor = (drawEnabled ? e.Item.ForeColor : System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb()));
                System.Drawing.StringFormat sf = new System.Drawing.StringFormat();
                sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter;
                sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip;
                System.Drawing.SolidBrush textBrush = new System.Drawing.SolidBrush(textColor);
                using (textBrush)
                {
                    e.Graphics.DrawString(display,
                        e.Item.Font,
                        textBrush,
                        rect,
                        sf);
                }

                // draw additional information text
                System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb());
                System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor);
                using (subBrush)
                {
                    // draw address display (line 2)
                    rect.Offset(0, e.Item.Font.Height);
                    e.Graphics.DrawString(address,
                        e.Item.Font,
                        subBrush,
                        rect,
                        sf);

                    // draw additional display (line 3)
                    rect.Offset(0, e.Item.Font.Height);
                    e.Graphics.DrawString(additional,
                        e.Item.Font,
                        subBrush,
                        rect,
                        sf);
                }

                // draw checkbox
                System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
                if (fc.Enabled)
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal;
                else
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
                CheckBoxRenderer.DrawCheckBox(e.Graphics, new System.Drawing.Point(e.Bounds.Left + CHECKBOX_PADDING, e.Bounds.Top + CHECKBOX_PADDING), state);
            }
            else
            {
                e.DrawDefault = true;
            }
        }
Beispiel #16
0
        /// <summary>
        /// 打印指定页面
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">绘图操作对象</param>
        /// <param name="MainClipRect">主剪切矩形</param>
        /// <param name="UseMargin">是否启用页边距</param>
        public override void DrawPage(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle MainClipRect,
            bool UseMargin)
        {
            //XPageSettings pageSettings = myPage.PageSettings;
            int LeftMargin   = 0;
            int TopMargin    = 0;
            int RightMargin  = 0;
            int BottomMargin = 0;

            if (UseMargin)
            {
                LeftMargin   = (int)myPage.ViewLeftMargin;
                TopMargin    = (int)myPage.ViewTopMargin;
                RightMargin  = (int)myPage.ViewRightMargin;
                BottomMargin = (int)myPage.ViewBottomMargin;
            }

            this.OnBeforeDrawPage(myPage, g);
            IntPtr          hdc = g.GetHdc();
            DeviceCapsClass dcc = new DeviceCapsClass(hdc);

            g.ReleaseHdc();

            DomDocument   document = (DomDocument)this.Document;
            XPageSettings ps       = myPage.PageSettings;

            if (ps == null)
            {
                ps = document.PageSettings;
            }
            g.PageUnit = document.DocumentGraphicsUnit;
            System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty;
            if (this.PageHeadText != null)
            {
                // 绘制标题文本
                g.DrawString(
                    this.PageHeadText,
                    System.Windows.Forms.Control.DefaultFont,
                    System.Drawing.Brushes.Red,
                    20,
                    20,
                    System.Drawing.StringFormat.GenericDefault);
            }
            float printableAreaOffsetX = (float)GraphicsUnitConvert.Convert(
                this.PrintableAreaOffset.X / 100.0,
                System.Drawing.GraphicsUnit.Inch,
                document.DocumentGraphicsUnit);
            float printableAreaOffsetY = (float)GraphicsUnitConvert.Convert(
                this.PrintableAreaOffset.Y / 100.0,
                System.Drawing.GraphicsUnit.Inch,
                document.DocumentGraphicsUnit);

            float headerHeight    = Math.Max(ps.ViewHeaderHeight, document.Header.Height);
            int   headerHeightFix = 0;

            if (document.Header.Height > ps.ViewHeaderHeight - 10)
            {
                headerHeightFix = ( int )(document.Header.Height - (ps.ViewHeaderHeight - 10));
            }
            if (this.DrawHead)
            {
                // 绘制页眉
                g.ResetTransform();
                g.ResetClip();
                ClipRect = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPage.Width,
                    (int)headerHeight);

                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    ps.ViewHeaderDistance - printableAreaOffsetY);

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

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Header);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
                g.ResetClip();
                g.ResetTransform();
            }

            // 绘制页面正文
            ClipRect = new System.Drawing.Rectangle(
                0,
                myPage.Top,
                myPage.Width,
                myPage.Height);

            if (!MainClipRect.IsEmpty)
            {
                ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect);
            }
            if (!ClipRect.IsEmpty)
            {
                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    TopMargin - myPage.Top + headerHeightFix - printableAreaOffsetY);

                //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.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 );

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Body);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);

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

            if (this.DrawFooter)
            {
                // 绘制页脚
                g.ResetClip();
                g.ResetTransform();
                int   documentHeight = myPage.DocumentHeight;
                float footerHeight   = Math.Max(document.Footer.Height, ps.ViewFooterHeight);
                ClipRect = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPage.Width,
                    (int)footerHeight);
                int dy = 0;

                dy = (int)(myPage.ViewPaperHeight
                           - ps.ViewFooterDistance - document.Footer.Height);

                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    dy - printableAreaOffsetY);

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

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Footer);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            } //if( this.bolDrawFooter )
        }     //public void DrawPage()
        void HistoryListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if (e.ItemIndex < 0) return;

            if (this.View == View.Tile)
            {
                // draw the background and focus rectangle for selected and non-selected states
                if (this.SelectedIndices.Contains(e.ItemIndex))
                {
                    e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds);
                    ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
                }
                else
                {
                    e.DrawBackground();
                }

                // draw icon
                PastNotification pn = (PastNotification)e.Item.Tag;
                int newX = e.Bounds.Left;
                if (pn != null)
                {
                    System.Drawing.Image img = PastNotificationManager.GetImage(pn);
                    using (img)
                    {
                        if (img != null)
                        {
                            int x = e.Bounds.Left + 1;
                            int y = e.Bounds.Top + 1;
                            e.Graphics.DrawImage(img, x, y);
                            newX = e.Bounds.Left + img.Width + this.Margin.Right;
                        }
                    }
                }

                // draw main text
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, e.Bounds.Top, e.Bounds.Right - newX, e.Item.Font.Height);
                System.Drawing.StringFormat sf = new System.Drawing.StringFormat();
                sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter;
                sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip;
                System.Drawing.SolidBrush foreBrush = new System.Drawing.SolidBrush(e.Item.ForeColor);
                string text = e.Item.Text.Replace("\r", " - ");
                using (foreBrush)
                {
                    e.Graphics.DrawString(text,
                        e.Item.Font,
                        foreBrush,
                        rect,
                        sf);
                }

                // draw subitems
                System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb());
                System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor);
                using (subBrush)
                {
                    for (int i = 1; i < this.Columns.Count; i++)
                    {
                        if (i < e.Item.SubItems.Count)
                        {
                            text = e.Item.SubItems[i].Text.Replace("\r", " - ");
                            rect.Offset(0, e.Item.Font.Height);
                            e.Graphics.DrawString(text,
                                e.Item.Font,
                                subBrush,
                                rect,
                                sf);
                        }
                    }
                }
            }
            else
            {
                // DO NOT call e.DrawDefault or the DrawSubItem event will not be fired
                //e.DrawDefault = true;
            }
        }
        void ForwardListView_DrawItem(object sender, DrawListViewItemEventArgs e)

        {
            if (this.View == View.Tile)

            {
                int checkBoxAreaWidth = CHECKBOX_PADDING + CHECKBOX_SIZE + CHECKBOX_PADDING;

                System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(e.Bounds.X + checkBoxAreaWidth, e.Bounds.Top, e.Bounds.Width - checkBoxAreaWidth, e.Bounds.Height);



                // update information

                DestinationBase fc = (DestinationBase)e.Item.Tag;

                string display = Escape(fc.Display);

                string address = Escape(fc.AddressDisplay);

                string additional = Escape(fc.AdditionalDisplayInfo);

                string tooltip = String.Format("{0}\r\n{1}{2}", fc.Display, fc.AddressDisplay, (!String.IsNullOrEmpty(fc.AdditionalDisplayInfo) ? String.Format("\r\n{0}", fc.AdditionalDisplayInfo) : null));

                e.Item.ToolTipText = tooltip;

                // NOTE: dont set the .Text or .SubItem properties here - it causes an erratic exception



                bool drawEnabled = ShouldDrawEnabled(fc);

                bool selected = this.SelectedIndices.Contains(e.ItemIndex);



                // draw the background for selected states

                if (drawEnabled && selected)

                {
                    e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds);
                }

                else

                {
                    e.DrawBackground();
                }



                // draw the focus rectangle

                if (selected)
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
                }



                // draw icon

                int newX = bounds.X;

                DestinationBase db = e.Item.Tag as DestinationBase;

                if (db != null)

                {
                    System.Drawing.Image img = db.GetIcon();



                    // size

                    if (img.Width > IMAGE_SIZE)

                    {
                        System.Drawing.Image resized = new System.Drawing.Bitmap(IMAGE_SIZE, IMAGE_SIZE);

                        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(resized);

                        using (g)

                        {
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                            g.DrawImage(img, 0, 0, IMAGE_SIZE, IMAGE_SIZE);
                        }

                        img = resized;
                    }



                    if (img != null)

                    {
                        int x = bounds.X;

                        int y = bounds.Top;

                        if (drawEnabled)
                        {
                            e.Graphics.DrawImage(img, new System.Drawing.Rectangle(x, y, img.Width, img.Height));
                        }

                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, img, x, y, System.Drawing.Color.Transparent);
                        }

                        newX += IMAGE_SIZE + this.Margin.Right;
                    }
                }



                // offset the text vertically a bit so it lines up with the icon better

                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, bounds.Top, bounds.Right - newX, e.Item.Font.Height);

                rect.Offset(0, 4);



                // draw main text

                System.Drawing.Color textColor = (drawEnabled ? e.Item.ForeColor : System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb()));

                System.Drawing.StringFormat sf = new System.Drawing.StringFormat();

                sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter;

                sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip;

                System.Drawing.SolidBrush textBrush = new System.Drawing.SolidBrush(textColor);

                using (textBrush)

                {
                    e.Graphics.DrawString(display,

                                          e.Item.Font,

                                          textBrush,

                                          rect,

                                          sf);
                }



                // draw additional information text

                System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb());

                System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor);

                using (subBrush)

                {
                    // draw address display (line 2)

                    rect.Offset(0, e.Item.Font.Height);

                    e.Graphics.DrawString(address,

                                          e.Item.Font,

                                          subBrush,

                                          rect,

                                          sf);



                    // draw additional display (line 3)

                    rect.Offset(0, e.Item.Font.Height);

                    e.Graphics.DrawString(additional,

                                          e.Item.Font,

                                          subBrush,

                                          rect,

                                          sf);
                }



                // draw checkbox

                System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;

                if (fc.Enabled)
                {
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal;
                }

                else
                {
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
                }

                CheckBoxRenderer.DrawCheckBox(e.Graphics, new System.Drawing.Point(e.Bounds.Left + CHECKBOX_PADDING, e.Bounds.Top + CHECKBOX_PADDING), state);
            }

            else

            {
                e.DrawDefault = true;
            }
        }