예제 #1
0
        public Size Measure(Size constraints)
        {
            if (Dimensions == Size.Empty)
            {
                return(Size.Empty);
            }

            constraints.Width  = Math.Min(constraints.Width, int.MaxValue);
            constraints.Height = Math.Min(constraints.Height, int.MaxValue);

            Frame = new RectangleF(0, 0, 0, 0);
            SizeToFit();

            nfloat width  = Frame.Width;
            nfloat height = Frame.Height;

            double scale = 1;

            if (constraints.Width < width || stretch != UI.ContentStretch.None)
            {
                scale = constraints.Width / width;
            }
            if (constraints.Height < height || stretch != UI.ContentStretch.None)
            {
                scale = Math.Min(scale, constraints.Height / height);
            }

            return(new Size(width * scale, height * scale));
        }
예제 #2
0
        public void Paint(Graphics g)
        {
            if (Visibility != Visibility.Visible || BitmapData == null || BitmapData.GetBytes() == null)
            {
                return;
            }

            BitmapImage.ImageInfo imgInfo;
            var image = BitmapData.CreateImage();

            image.GetImageInfo(out imgInfo);

            var bitmapSize = new Size(imgInfo.Width, imgInfo.Height);

            var dest = new Rect
            {
                Left   = (int)Location.X,
                Top    = (int)Location.Y,
                Right  = (int)(Location.X + Size.Width),
                Bottom = (int)(Location.Y + Size.Height),
            };
            var source = new Rectangle(0, 0, (int)bitmapSize.Width, (int)bitmapSize.Height);

            if (_stretch == ContentStretch.UniformToFill)
            {
                var    ratio  = Size.Width / Size.Height;
                double width  = source.Width;
                double height = source.Height;

                if (width / height < ratio)
                {
                    height = width / ratio;
                }
                else
                {
                    width = height * ratio;
                }

                var xdiff = (source.Width - width) / 2;
                var ydiff = (source.Height - height) / 2;
                source = new Rectangle((int)xdiff, (int)ydiff, (int)width, (int)height);
            }

            double scaleFactorX = 1 / imgInfo.Xdpi * 2540;
            double scaleFactorY = 1 / imgInfo.Ydpi * 2540;
            var    rcScaled     = new Rect
            {
                Left   = (int)(source.X * scaleFactorX),
                Top    = (int)(source.Y * scaleFactorY),
                Right  = (int)((source.X + source.Width) * scaleFactorX),
                Bottom = (int)((source.Y + source.Height) * scaleFactorY),
            };

            // Draw the image, with alpha channel if any
            IntPtr hdcDest = g.GetHdc();

            image.Draw(hdcDest, ref dest, ref rcScaled);
            g.ReleaseHdc(hdcDest);
        }
예제 #3
0
 public void SetLocation(Point location, Size size)
 {
     Width        = (int)size.Width;
     Height       = (int)size.Height;
     _hasMeasured = size.Height > 0 && size.Width > 0;
     FitText();
     Location = location.ToPoint();
 }
예제 #4
0
 public virtual void SetBackground(string imagePath, ContentStretch stretch)
 {
     BackgroundHexCode = null;
     Backer            = new ImageControl {
         Size = Size.ToSize(), Stretch = stretch,
     };
     Backer.Loaded  += (o, ev) => Redraw();
     Backer.FilePath = imagePath;
 }
예제 #5
0
        /// <summary>
        /// Sets the location and size of the control within its parent grid.
        /// This is called by the underlying grid layout system and should not be used in application logic.
        /// </summary>
        /// <param name="location">The X and Y coordinates of the upper left corner of the control.</param>
        /// <param name="size">The width and height of the control.</param>
        public void SetLocation(Point location, Size size)
        {
            var left   = location.X;
            var right  = location.X + MeasuredWidth;
            var top    = location.Y;
            var bottom = location.Y + MeasuredHeight;

            Layout((int)left, (int)top, (int)right, (int)bottom);
        }
예제 #6
0
        /// <summary>
        /// Sets the location and size of the control within its parent grid.
        /// This is called by the underlying grid layout system and should not be used in application logic.
        /// </summary>
        /// <param name="location">The X and Y coordinates of the upper left corner of the control.</param>
        /// <param name="size">The width and height of the control.</param>
        public void SetLocation(Point location, Size size)
        {
            var left   = location.X;
            var top    = location.Y;
            var right  = left + size.Width;
            var bottom = top + size.Height;

            Layout((int)left, (int)top, (int)right, (int)bottom);
        }
예제 #7
0
 public Size Measure(Size constraints)
 {
     if (constraints.Width > 0 && !double.IsInfinity(constraints.Width))
     {
         SetWidth((int)constraints.Width);
     }
     this.MeasureView(constraints);
     return(new Size(constraints.Width, MeasuredHeight));
 }
예제 #8
0
        /// <summary>
        /// Sets the location and size of the control within its parent grid.
        /// This is called by the underlying grid layout system and should not be used in application logic.
        /// </summary>
        /// <param name="location">The X and Y coordinates of the upper left corner of the control.</param>
        /// <param name="size">The width and height of the control.</param>
        public void SetLocation(Point location, Size size)
        {
            Location = location;
            Size     = size;
            var par = Parent as GridControl;

            if (par != null)
            {
                par.Redraw();
            }
        }
예제 #9
0
        public static Size MeasureView(this IElement view, Size constraints)
        {
            var nativeView = DroidFactory.GetNativeObject <View>(view, nameof(view));

            if (nativeView == null)
            {
                return(new Size());
            }
            nativeView.Measure(View.MeasureSpec.MakeMeasureSpec(GetMeasureSpec(constraints.Width),
                                                                view.HorizontalAlignment == HorizontalAlignment.Stretch ? MeasureSpecMode.Exactly : MeasureSpecMode.AtMost),
                               View.MeasureSpec.MakeMeasureSpec(GetMeasureSpec(constraints.Height), MeasureSpecMode.Unspecified));
            return(new Size(nativeView.MeasuredWidth, nativeView.MeasuredHeight));
        }
예제 #10
0
        public void FitText()
        {
            if (!_hasMeasured)
            {
                return;
            }
            const string ellipsisChars = "... ";
            var          constraints   = Size.ToSize();
            Size         s             = CoreDll.MeasureString(" " + _title + " ", Font.ToFont(), constraints, false, true) + _margins;

            // control is large enough to display the whole text
            if (s.Width <= Width)
            {
                return;
            }

            int    len = 0;
            int    seg = _title.Length;
            string fit = string.Empty;

            // find the longest string that fits into the control boundaries using bisection method
            while (seg > 1)
            {
                seg -= seg / 2;

                int left  = len + seg;
                int right = _title.Length;

                if (left > right)
                {
                    continue;
                }

                // build and measure a candidate string with ellipsis
                string tst = " " + _title.Substring(0, left).TrimEnd() + ellipsisChars;

                s = CoreDll.MeasureString(tst, Font.ToFont(), constraints, false, true) + _margins;

                // candidate string fits into control boundaries,
                // try a longer string
                // stop when seg <= 1
                if (s.Width <= Width)
                {
                    len += seg;
                    fit  = tst;
                }
            }

            base.Text = len == 0 ? ellipsisChars : fit;
        }
예제 #11
0
        public Size Measure(Size constraints)
        {
            var frame = Frame;

            constraints.Width  = Math.Min(constraints.Width, int.MaxValue);
            constraints.Height = Math.Min(constraints.Height, int.MaxValue);
            Frame = new CGRect(CGPoint.Empty, new CGSize((float)constraints.Width, (float)constraints.Height));
            SizeToFit();

            var size = new Size(Frame.Width, Frame.Height);

            Frame = frame;
            return(size);
        }
예제 #12
0
 public void SetLocation(Point location, Size size)
 {
     Frame = new RectangleF((float)location.X, (float)location.Y, (float)size.Width, (float)size.Height);
     if (stretch == UI.ContentStretch.None)
     {
         if (Frame.Width < Dimensions.Width || Frame.Height < Dimensions.Height)
         {
             ContentMode = UIViewContentMode.ScaleAspectFit;
         }
         else
         {
             ContentMode = UIViewContentMode.Center;
         }
     }
 }
예제 #13
0
        /// <summary>
        /// Sets the location and size of the control within its parent grid.
        /// This is called by the underlying grid layout system and should not be used in application logic.
        /// </summary>
        /// <param name="location">The X and Y coordinates of the upper left corner of the control.</param>
        /// <param name="size">The width and height of the control.</param>
        public void SetLocation(Point location, Size size)
        {
            var left   = location.X;
            var right  = location.X + size.Width;
            var top    = location.Y;
            var bottom = location.Y + size.Height;

            Layout((int)left, (int)top, (int)right, (int)bottom);

            var widthSpec  = MeasureSpec.MakeMeasureSpec((int)size.Width, MeasureSpecMode.Exactly);
            var heightSpec = MeasureSpec.MakeMeasureSpec((int)size.Height, MeasureSpecMode.Exactly);

            _button.Measure(widthSpec, heightSpec);
            _button.Layout(-Padding, -Padding, (int)size.Width + Padding, (int)size.Height + Padding);
        }
예제 #14
0
        protected override void OnResize(EventArgs e)
        {
            var t = CompactFactory.MetricStopwatch.ElapsedTicks;

            if (Parent == null || Width == _width)
            {
                return;
            }
            var minSize = new Size(MinWidth, MinHeight);
            var maxSize = new Size(MaxWidth, MaxHeight);
            var size    = this.PerformLayout(minSize, maxSize);

            if (Backer != null && Backer.Size != size)
            {
                Backer.Size = size;
                if (CellBitmap != null)
                {
                    var bit = CellBitmap;
                    Bitmaps.Remove(this);
                    bit.Dispose();
                    mem -= Width * Height * 4;
                }
            }

            if (size.ToSize() == Size)
            {
                Debug.WriteLine(string.Format("Unnecessary resize at {0}", size));
                return;
            }
            Debug.WriteLine(string.Format("Resize {0} -> {1}", Size.ToSize(), size));

            if (Size.Height != (int)size.Height)
            {
                Size = size.ToSize();
                if (Parent != null && Parent.Parent is SmoothListbox)
                {
                    ((SmoothListbox)Parent.Parent).LayoutItems(this);
                }
            }
            else
            {
                Size = size.ToSize();
            }

            _width = Size.Width;

            Debug.WriteLineIf(CompactFactory.MetricStopwatch.IsRunning, string.Format("[{1}] Grid resize took {0}ms", new TimeSpan(CompactFactory.MetricStopwatch.ElapsedTicks - t).TotalMilliseconds, CompactFactory.MetricStopwatch.ElapsedMilliseconds));
        }
예제 #15
0
        public Size Measure(Size constraints)
        {
            var originalSize = Dimensions;

            if (constraints.Height < .001)
            {
                return(originalSize);
            }

            Size imageSize;
            var  ratio = originalSize.Width / originalSize.Height;

            if (_stretch == ContentStretch.None)
            {
                double width = originalSize.Width, height = originalSize.Height;

                if (constraints.Height > 0 && originalSize.Height > constraints.Height)
                {
                    height = constraints.Height;
                    width  = height * ratio;
                }

                if (constraints.Width > 0 && width > constraints.Width)
                {
                    width  = constraints.Width;
                    height = width / ratio;
                }

                imageSize = new Size(width, height);
            }
            else
            {
                imageSize = constraints;
            }

            if (imageSize.Height > int.MaxValue)
            {
                imageSize.Height = imageSize.Width / ratio;
            }

            if (imageSize.Width > int.MaxValue)
            {
                imageSize.Width = imageSize.Height * ratio;
            }

            return(imageSize);
        }
예제 #16
0
        public Size Measure(Size constraints)
        {
            var    originalSize = Dimensions;
            var    ratio        = originalSize.Width / originalSize.Height;
            double width        = Math.Min(originalSize.Width, constraints.Width);
            double height       = Math.Min(originalSize.Height, constraints.Height);

            if (width / height < ratio)
            {
                height = width / ratio;
            }
            else
            {
                width = height * ratio;
            }

            return(new Size(width, height));
        }
예제 #17
0
파일: Label.cs 프로젝트: Zebra/iFactr-iOS
        public Size Measure(Size constraints)
        {
            if (string.IsNullOrEmpty(Text))
            {
                return(Size.Empty);
            }

            constraints.Width  = Math.Min(constraints.Width, int.MaxValue);
            constraints.Height = Math.Min(constraints.Height, int.MaxValue);

            var lineHeight = Lines > 0 ? base.Font.LineHeight * Lines : int.MaxValue;

            var size = CGSize.Empty;

            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                size = MeasureString(Text, new CGSize((float)constraints.Width, lineHeight)).Size;
            }

            return(new Size((double)size.Width, Math.Min((double)size.Height, constraints.Height)));
        }
예제 #18
0
        /// <summary>
        /// Handles the TextChanged event of the Label control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="TextChangedEventArgs"/> instance containing the event data.</param>
        private void Label_TextChanged(object sender, TextChangedEventArgs e)
        {
            var old          = StringValue;
            var ellipsized   = _text != base.Text && base.Text != null && base.Text.EndsWith(Ellipsis);
            var infinitySize = new Size(double.PositiveInfinity, double.PositiveInfinity);

            if (!ellipsized && StringValue != base.Text)
            {
                _constraints = infinitySize;
                _text        = base.Text;
                StringValue  = Text;
            }

            this.RequestResize();

            if (old == StringValue)
            {
                return;
            }
            this.RaiseEvent("ValueChanged", new ValueChangedEventArgs <string>(old, StringValue));
            this.OnPropertyChanged("Text");
            this.OnPropertyChanged("StringValue");
        }
예제 #19
0
 public void SetLocation(Point location, Size size)
 {
     Frame = new CGRect((float)location.X, (float)location.Y, (float)size.Width, (float)size.Height);
 }
예제 #20
0
        /// <summary>
        /// Measure the view and its content to determine the measured width and the measured height.
        /// This method is invoked by <see cref="View.Measure"/> and should be overriden by subclasses to provide accurate and efficient measurement of their contents.
        /// </summary>
        /// <param name="widthMeasureSpec">Horizontal space requirements as imposed by the parent. The requirements are encoded with <see cref="View.MeasureSpec"/>.</param>
        /// <param name="heightMeasureSpec">Vertical space requirements as imposed by the parent. The requirements are encoded with <see cref="View.MeasureSpec"/>.</param>
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int  parentHeight;
            int  parentWidth;
            View frame      = null;
            var  fragmentId = ((Parent as BaseFragment)?.Stack as FragmentHistoryStack)?.FragmentId;

            if (fragmentId != null)
            {
                frame = DroidFactory.MainActivity.FindViewById <FrameLayout>(fragmentId.Value);
            }
            else
            {
                frame = base.Parent as View;
            }

            if (frame != null)
            {
                parentWidth  = frame.MeasuredWidth;
                parentHeight = (int)(frame.MeasuredHeight / DroidFactory.DisplayScale);
            }
            else
            {
                var metrics = new DisplayMetrics();
                DroidFactory.MainActivity.WindowManager.DefaultDisplay.GetMetrics(metrics);
                parentWidth  = (int)(metrics.WidthPixels * .6);
                parentHeight = (int)(parentWidth * .75);
            }

            var basicGrid = !(this is GridCell) && !(this is Grid);

            if (MinWidth < 1)
            {
                MinWidth = parentWidth;
            }
            if (MaxWidth < MinWidth)
            {
                MaxWidth = MinWidth;
            }
            if (basicGrid && MinHeight < 1 && parentHeight > 0)
            {
                MinHeight = parentHeight;
            }
            if (MaxHeight < 1 && parentHeight > 0)
            {
                MaxHeight = basicGrid ? parentHeight : double.PositiveInfinity;
            }

            var size = new Size(MeasuredWidth, MeasuredHeight);

            if (MinWidth < 0 || MinHeight < 0 || MaxWidth < 0 || MaxHeight < 0)
            {
                SetMeasuredDimension(ResolveSize((int)size.Width, widthMeasureSpec), ResolveSize((int)size.Height, heightMeasureSpec));
                return;
            }

            if (ResizeRequested ||
                size.Width < MinWidth || size.Height < MinHeight * DroidFactory.DisplayScale ||
                size.Width > MaxWidth || size.Height > MaxHeight * DroidFactory.DisplayScale)
            {
                var minSize = new Size(Math.Min(MaxWidth, MinWidth), Math.Min(MinHeight, MaxHeight));
                var maxSize = new Size(Math.Max(MaxWidth, MinWidth), Math.Max(MinHeight, MaxHeight));
                size            = this.PerformLayout(minSize, maxSize);
                ResizeRequested = false;
            }
            SetMeasuredDimension(ResolveSize((int)size.Width, widthMeasureSpec), ResolveSize((int)size.Height, heightMeasureSpec));
            DroidFactory.ShowKeyboard(TextBase.CurrentFocus);
        }
예제 #21
0
 public void SetLocation(UI.Point location, Size size)
 {
     base.Width  = (int)size.Width;
     base.Height = (int)size.Height;
     Location    = location.ToPoint();
 }
예제 #22
0
 public Size Measure(Size constraints)
 {
     return(new Size(constraints.Width, Math.Min((int)constraints.Height, Height)));
 }
예제 #23
0
        public Size Measure(Size constraints)
        {
            if (string.IsNullOrEmpty(FilePath))
            {
                return(new Size());
            }
            var originalSize = Dimensions;

            if (originalSize == new Size(1, 1))
            {
                return(originalSize);
            }

            if (constraints.Height < .001)
            {
                return(new Size(MeasuredWidth, MeasuredHeight));
            }

            Size imageSize;
            var  ratio = originalSize.Width / originalSize.Height;

            if (_stretch != ContentStretch.Fill)
            {
                double width = originalSize.Width, height = originalSize.Height;

                if (constraints.Height > 0 && originalSize.Height > constraints.Height)
                {
                    height = constraints.Height;
                    width  = height * ratio;
                }

                if (constraints.Width > 0 && width > constraints.Width)
                {
                    width  = constraints.Width;
                    height = width / ratio;
                }

                double scale;
                switch (_stretch)
                {
                case ContentStretch.Uniform:
                    scale = Math.Min(constraints.Width / width, constraints.Height / height);
                    break;

                case ContentStretch.UniformToFill:
                    scale = Math.Max(constraints.Width / width, constraints.Height / height);
                    break;

                default:
                    scale = 1;
                    break;
                }

                imageSize = new Size(width * scale, height * scale);
            }
            else
            {
                imageSize = constraints;
            }

            if (imageSize.Height > int.MaxValue)
            {
                imageSize.Height = imageSize.Width / ratio;
            }

            if (imageSize.Width > int.MaxValue)
            {
                imageSize.Width = imageSize.Height * ratio;
            }

            this.MeasureView(imageSize);
            return(imageSize);
        }
예제 #24
0
 public Size Measure(Size constraints)
 {
     return(this.MeasureView(constraints));
 }
예제 #25
0
 public static System.Drawing.Size ToSize(this Size size)
 {
     return(new System.Drawing.Size((int)size.Width, (int)size.Height));
 }
예제 #26
0
 Size IElement.Measure(Size constraints)
 {
     return(this.MeasureView(constraints));
 }
예제 #27
0
        /// <summary>
        /// Calculates and returns an appropriate width and height value for the contents of the control.
        /// This is called by the underlying grid layout system and should not be used in application logic.
        /// </summary>
        /// <param name="constraints">The size that the control is limited to.</param>
        /// <returns>The label size, given a width constraint and a measured height.</returns>
        public Size Measure(Size constraints)
        {
            if (string.IsNullOrEmpty(StringValue))
            {
                return(new Size());
            }

            if (_constraints == constraints)
            {
                return(new Size(MeasuredWidth, MeasuredHeight));
            }

            _constraints = constraints;
            var height        = _constraints.Height > int.MaxValue ? int.MaxValue : (int)Math.Ceiling(_constraints.Height);
            var width         = _constraints.Width > int.MaxValue ? int.MaxValue : (int)Math.Ceiling(_constraints.Width);
            var measuredWidth = 0;

            // Do not resize if the view does not have dimensions or there is no text
            if (string.IsNullOrEmpty(StringValue) || height <= 0 || width <= 0 || TextSize <= 0)
            {
                if (Text != string.Empty)
                {
                    SetText(string.Empty, BufferType.Normal);
                }
                _measuredLines = 0;
            }
            else
            {
                // modified: make a copy of the original TextPaint object for measuring
                // (apparently the object gets modified while measuring, see also the
                // docs for TextView.getPaint() (which states to access it read-only)
                var paint = new TextPaint(Paint)
                {
                    TextSize = TextSize,
                };
                // Measure using a static layout
                var layout = new StaticLayout(StringValue, paint, width, Layout.Alignment.AlignNormal, 1.0f, 0, true);

                float totalWidth = 0;

                // If we had reached our minimum text size and still don't fit, append an ellipsis
                if (layout.Height > height || _maxLineCount > 0 && layout.LineCount > _maxLineCount)
                {
                    var ellipsisWidth = Paint.MeasureText(Ellipsis);
                    var addEllipsis   = false;
                    int lastLineIndex;

                    if (height == int.MaxValue)
                    {
                        lastLineIndex = Math.Max(layout.LineCount - 1, 0);
                    }
                    else
                    {
                        lastLineIndex = Math.Max(layout.GetLineForVertical(height) - 1, 0);
                        if (lastLineIndex < layout.LineCount - 1)
                        {
                            addEllipsis = true;
                        }
                    }

                    if (_maxLineCount > 0 && lastLineIndex > _maxLineCount - 1)
                    {
                        lastLineIndex = _maxLineCount - 1;
                        addEllipsis   = true;
                    }

                    _measuredLines = lastLineIndex + 1;
                    var ellipsizeIndex     = layout.GetLineEnd(lastLineIndex);
                    var lastLineStartIndex = layout.GetLineStart(lastLineIndex);
                    ellipsizeIndex = lastLineStartIndex + (int)Math.Ceiling((ellipsizeIndex - lastLineStartIndex) * 1.4);
                    if (StringValue.Length < ellipsizeIndex)
                    {
                        ellipsizeIndex = StringValue.Length;
                        addEllipsis    = false;
                    }
                    var text = StringValue.Substring(lastLineStartIndex, ellipsizeIndex - lastLineStartIndex).TrimEnd();
                    totalWidth = Paint.MeasureText(text) + (addEllipsis ? ellipsisWidth : 0);

                    // Trim characters off until we have enough room to draw the ellipsis
                    while (width < totalWidth && text != string.Empty)
                    {
                        addEllipsis = true;
                        text        = StringValue.Substring(lastLineStartIndex, --ellipsizeIndex - lastLineStartIndex);
                        totalWidth  = Paint.MeasureText(text) + ellipsisWidth;
                    }

                    if (addEllipsis)
                    {
                        text = StringValue.Substring(0, ellipsizeIndex).TrimEnd() + Ellipsis;
                        if (text != Text)
                        {
                            SetText(text, BufferType.Normal);
                        }
                    }
                }
                else if (base.Text != StringValue)
                {
                    SetText(StringValue, BufferType.Normal);
                    _measuredLines = layout.LineCount;
                }
                else
                {
                    _measuredLines = layout.LineCount;
                }

                // Some devices try to auto adjust line spacing, so force default line spacing
                // and invalidate the layout as a side effect
                SetLineSpacing(0, 1.0f);

                for (var i = 0; i < _measuredLines; i++)
                {
                    var lineWidth = layout.GetLineWidth(i);
                    if (lineWidth > totalWidth)
                    {
                        totalWidth = lineWidth;
                    }
                }
                measuredWidth = (int)Math.Ceiling(totalWidth);
            }

            var size = this.MeasureView(constraints);

            return(new Size(measuredWidth, size.Height));
        }
예제 #28
0
        public Size Measure(Size constraints)
        {
            var measure = CoreDll.MeasureString(" " + _title + " ", Font.ToFont(), constraints, false, true) + _margins;

            return(new Size(measure.Width, Math.Max(measure.Height, 33 * CompactFactory.Instance.DpiScale)));
        }
예제 #29
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (_forceLayout)
            {
                var minSize = new Size(MinWidth, MinHeight);
                var maxSize = new Size(MaxWidth, MaxHeight);
                var size    = this.PerformLayout(minSize, maxSize).ToSize();
                _forceLayout = false;

                if (size != Size)
                {
                    Size   = size;
                    _width = size.Width;
                    return;
                }
            }

            var backgroundView = Parent.Parent as SmoothListbox;

            if (backgroundView == null || backgroundView.BackgroundBitmap == null)
            {
                if (InitializeBitmap())
                {
                    using (var g = Graphics.FromImage(CellBitmap))
                    {
                        if (BackgroundHexCode != null)
                        {
                            g.Clear(new Color(BackgroundHexCode).ToColor());
                        }
                        else if (Backer != null)
                        {
                            Backer.Paint(g);
                        }
                        else
                        {
                            g.Clear(CompactFactory.Instance.Style.LayerItemBackgroundColor.ToColor());
                        }
                        Draw(g);
                    }
                }

                if (CellBitmap != null)
                {
                    e.Graphics.DrawImage(CellBitmap, 0, 0);
                }
            }
            else
            {
                //Transparent cells
                var rect = new Rectangle(0, 0, Width, Height);
                if (backgroundView.BackgroundBitmap != null)
                {
                    var backgroundRect = new Rectangle(0, Top + backgroundView.Controls[0].Top, Width, Height);
                    e.Graphics.DrawImage(backgroundView.BackgroundBitmap, rect, backgroundRect, GraphicsUnit.Pixel);
                }

                if (InitializeBitmap())
                {
                    _imageAttr = new ImageAttributes();
                    _imageAttr.SetColorKey(System.Drawing.Color.Transparent, System.Drawing.Color.Transparent);

                    using (var grp = Graphics.FromImage(CellBitmap))
                    {
                        grp.Clear(System.Drawing.Color.Transparent);
                        Draw(grp);
                    }
                }
                e.Graphics.DrawImage(CellBitmap, rect, 0, 0, Width, Height, GraphicsUnit.Pixel, _imageAttr);
            }
        }
예제 #30
0
 /// <summary>
 /// Calculates and returns an appropriate width and height value for the contents of the control.
 /// This is called by the underlying grid layout system and should not be used in application logic.
 /// </summary>
 /// <param name="constraints">The size that the control is limited to.</param>
 /// <returns>The label size, given a width constraint and a measured height.</returns>
 public Size Measure(Size constraints)
 {
     return(this.PerformLayout(new Size(MeasuredWidth, MeasuredHeight / DroidFactory.DisplayScale), constraints));
 }