public ScreeningLabel(CGRect frame, Screening screening, bool withDay = false) : base(frame)
 {
     Initialize();
     _screening    = screening;
     Font          = NSFont.BoldSystemFontOfSize(ScreeningControl.FontSize);
     Editable      = false;
     Bordered      = false;
     StringValue   = _screening.ToScreeningLabelString(withDay);
     LineBreakMode = NSLineBreakMode.TruncatingMiddle;
     ColorView.SetScreeningColor(_screening, this);
     NeedsDisplay = true;
 }
Пример #2
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            // Use Core Graphic routines to draw our UI
            using (CGContext context = NSGraphicsContext.CurrentContext.GraphicsPort)
            {
                // Fill the screening color.
                CGPath path  = new CGPath();
                CGRect frame = new CGRect(0, 0, base.Frame.Width, base.Frame.Height);
                path.AddRect(frame);
                ColorView.SetScreeningColor(_screening, context);
                context.AddPath(path);
                context.DrawPath(CGPathDrawingMode.Fill);

                // Draw screening information.
                context.TranslateCTM(2, ScreeningsView.VerticalTextOffset);
                context.SetTextDrawingMode(CGTextDrawingMode.Fill);
                ColorView.SetScreeningColor(_screening, context, true);
                CTStringAttributes attrs = new CTStringAttributes();
                attrs.ForegroundColorFromContext = true;
                attrs.Font = ScreeningControl.StandardFont;
                var      textPosition = new CGPoint(0, _lineHeight);
                string[] lines        = _screening.ToScreeningLabelString().Split('\n');
                foreach (var line in lines)
                {
                    context.TextPosition = textPosition;
                    var attributedString = new NSAttributedString(line, attrs);
                    using (var textLine = new CTLine(attributedString))
                    {
                        textLine.Draw(context);
                    }
                    textPosition.Y -= _lineHeight;
                }
            }
            NeedsDisplay = true;
        }