Ejemplo n.º 1
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            var context = NSGraphicsContext.CurrentContext.GraphicsPort;

            context.SetFillColor(new CGColor(1, 1, 1));           //White
            context.FillRect(dirtyRect);

            for (int i = 1; i < this.Bounds.Size.Height / 10; i++)
            {
                if (i % 10 == 0)
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.3f);
                    colorWithSRGBRed.Set();
                }
                else if (i % 10 == 0)
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.2f);
                    colorWithSRGBRed.Set();
                }
                else
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.1f);
                    colorWithSRGBRed.Set();
                }
                var pointFrom = new PointF(0, (i * GridSize - 0.5f));
                var pointTo   = new PointF(this.Bounds.Size.Width, (i * GridSize - 0.5f));

                NSBezierPath.StrokeLine(pointFrom, pointTo);
            }


            for (int i = 1; i < this.Bounds.Size.Width / 10; i++)
            {
                if (i % 10 == 0)
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.3f);
                    colorWithSRGBRed.Set();
                }
                else if (i % 10 == 0)
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.2f);
                    colorWithSRGBRed.Set();
                }
                else
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.1f);
                    colorWithSRGBRed.Set();
                }
                var pointFrom = new PointF((i * GridSize - 0.5f), 0);
                var pointTo   = new PointF((i * GridSize - 0.5f), this.Bounds.Size.Height);

                NSBezierPath.StrokeLine(pointFrom, pointTo);
            }
        }
Ejemplo n.º 2
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            NSColor.White.Set();
            NSGraphics.RectFill(dirtyRect);

            foreach (ColorRect thisRect in rects)
            {
                if (thisRect.Frame.IntersectsWith(dirtyRect))
                {
                    thisRect.DrawRect(dirtyRect, thisRect == selectedItem);
                }
            }

            // draw a little cross in our view
            NSColor.Black.Set();
            NSBezierPath.StrokeLine(new PointF(-10.0f, 0.0f), new PointF(10.0f, 0.0f));
            NSBezierPath.StrokeLine(new PointF(0.0f, -10.0f), new PointF(0.0f, 10.0f));
        }
Ejemplo n.º 3
0
 private void DrawLine(NSColor color, PointF p1, PointF p2)
 {
     color.Set();
     NSBezierPath.StrokeLine(Invert(p1), Invert(p2));
 }
Ejemplo n.º 4
0
 private void DrawLine(CGContext context, CGColor color, CGPoint p1, CGPoint p2)
 {
     context.SetStrokeColor(color);
     //color.Set();
     NSBezierPath.StrokeLine(Invert(p1), Invert(p2));
 }
Ejemplo n.º 5
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);
            }
        }