Ejemplo n.º 1
0
        public override void DrawRect(CoreGraphics.CGRect dirtyRect)
        {
            NSColor.Brown.Set();
            NSGraphics.FrameRect(Bounds);

            string s = value.ToString();
            NSMutableAttributedString attributes = new NSMutableAttributedString(value.ToString());

            attributes.AddAttribute(NSStringAttributeKey.Font, NSFont.FromFontName("Helvetica", 96), new NSRange(0, s.Length));
            attributes.AddAttribute(NSStringAttributeKey.ForegroundColor, NSColor.Brown, new NSRange(0, s.Length));
            attributes.DrawAtPoint(new CoreGraphics.CGPoint(10, 10));
        }
Ejemplo n.º 2
0
        private void OnPaint()
        {
            int          textHeight = (int)(this.Frame.Height / 15);
            var          objects    = new object [] { NSFont.FromFontName("Menlo", textHeight) };
            var          keys       = new object [] { "Helvetica" };
            NSDictionary txtFont    = NSDictionary.FromObjectsAndKeys(objects, keys);

            if ((theData != null) && (theData.Count > 0))
            {
                // calculate sizes
                int colWidth = (int)(this.Frame.Width / (theData.Count + 2));
                int maxval   = 1;
                foreach (KeyValuePair <string, int> dp in theData)
                {
                    maxval = (dp.Value > maxval) ? dp.Value : maxval;
                }
                int    baseline         = (int)(2 * textHeight);
                float  heightMultiplier = ((float)this.Frame.Height - (4 * textHeight)) / maxval;
                CGSize stringSize       = textSize(maxval.ToString(), txtFont);
                int    lxpos            = colWidth - (int)stringSize.Width - 10;
                int    lypos            = (int)(baseline + (heightMultiplier * maxval) - (stringSize.Height / 2));
                DrawString(maxval.ToString(), txtFont, NSColor.Black, lxpos, lypos);


                NSColor.Black.Set();
                NSBezierPath.StrokeLine(new CGPoint(colWidth, baseline), new CGPoint(colWidth * (theData.Count + 1), baseline));
                NSBezierPath.StrokeLine(new CGPoint(colWidth, baseline), new CGPoint(colWidth, baseline + (heightMultiplier * maxval)));
                NSBezierPath.StrokeLine(new CGPoint(colWidth - 5, baseline + (heightMultiplier * maxval)), new CGPoint(colWidth, baseline + (heightMultiplier * maxval)));

                DrawString(title, txtFont, NSColor.Black, 5, lypos + (int)stringSize.Height);

                int colPos = 0;
                foreach (KeyValuePair <string, int> dp in theData)
                {
                    colPos += colWidth;
                    int colCentre = colPos + colWidth / 2;
                    stringSize = textSize(dp.Key, txtFont);
                    lxpos      = colCentre - (int)(stringSize.Width / 2);
                    lypos      = baseline - -textHeight - textHeight / 4;
                    DrawString(dp.Key, txtFont, NSColor.Black, lxpos, lypos);
                    if (dp.Value > 0)
                    {
                        CGRect colRect = new CGRect(colPos, baseline, colWidth - 1, heightMultiplier * dp.Value);
                        NSColor.Blue.Set();
                        NSGraphics.RectFill(colRect);
                        NSColor.Black.Set();
                        NSGraphics.FrameRect(colRect);

                        //e.Graphics.FillRectangle(Brushes.Blue, colPos, baseline - heightMultiplier * dp.Value, colWidth - 1, heightMultiplier * dp.Value);
                    }
                }
            }
            else
            {
                CGSize stringSize = textSize("Ay", txtFont);
                int    lypos      = (int)this.Frame.Height - 2 * (int)stringSize.Height;
                if (title != null)
                {
                    DrawString(title, txtFont, NSColor.Black, 5, lypos + (int)stringSize.Height);
                }
                DrawString("No data to display", txtFont, NSColor.Black, 5, lypos + 2 * (int)stringSize.Height);
            }
        }
Ejemplo n.º 3
0
 public override void DrawRect(CoreGraphics.CGRect dirtyRect)
 {
     NSColor.Red.Set();
     NSGraphics.FrameRect(Bounds);
 }