Пример #1
0
        private void DrawSolidRowGrid(IGraphicsContext graphicsContext, double x, double y)
        {
            graphicsContext.DrawLine(x, y, x + ComputedWidth, y, RuleWidth);
            double yOffset = 0;

            for (int i = 0; i < _rows.Count; ++i)
            {
                double rgs = RuleGapSize;
                if (i == _rows.Count - 1)
                {
                    rgs = 0d;
                }
                yOffset += _rows[i].ComputedHeight;
                graphicsContext.DrawLine(x + rgs, y + yOffset, x + ComputedWidth - rgs, y + yOffset, RuleWidth);
            }
            graphicsContext.DrawLine(x, y, x, y + ComputedHeight, RuleWidth);
            double xOffset = 0;

            for (int i = 0; i < _columns.Count - 1; ++i)
            {
                xOffset += _columns[i].ComputedWidth;
                yOffset  = 0;
                foreach (TableRow row in _rows)
                {
                    graphicsContext.DrawLine(x + xOffset, y + yOffset + RuleGapSize, x + xOffset, y + yOffset + row.ComputedHeight - RuleGapSize, RuleWidth);
                    yOffset += row.ComputedWidth;
                }
            }
            graphicsContext.DrawLine(x + ComputedWidth, y, x + ComputedWidth, y + ComputedHeight, RuleWidth);
        }
Пример #2
0
        private void DrawSolidColumnGrid(IGraphicsContext graphicsContext, double x, double y)
        {
            graphicsContext.DrawLine(x, y, x, y + ComputedHeight, RuleWidth);
            double xOffset = 0;

            for (int i = 0; i < _columns.Count; ++i)
            {
                double rgs = RuleGapSize;
                if (i == _columns.Count - 1)
                {
                    rgs = 0d;
                }
                xOffset += _columns[i].ComputedWidth;
                graphicsContext.DrawLine(x + xOffset, y + rgs, x + xOffset, y + ComputedHeight - rgs, RuleWidth);
            }
            graphicsContext.DrawLine(x, y, x + ComputedWidth, y, RuleWidth);
            double yOffset = 0;

            for (int i = 0; i < _rows.Count - 1; ++i)
            {
                yOffset += _rows[i].ComputedHeight;
                xOffset  = 0;
                foreach (TableColumn column in _columns)
                {
                    graphicsContext.DrawLine(x + RuleGapSize + xOffset, y + yOffset, x + column.ComputedWidth + xOffset - RuleGapSize, y + yOffset);
                    xOffset += column.ComputedWidth;
                }
            }
            graphicsContext.DrawLine(x, y + ComputedHeight, x + ComputedWidth, y + ComputedHeight, RuleWidth);
        }
Пример #3
0
        private void DrawFullGrid(IGraphicsContext graphicsContext, double x, double y)
        {
            graphicsContext.DrawLine(x, y, x, y + ComputedHeight);
            double xOffset = 0;

            foreach (TableColumn column in _columns)
            {
                xOffset += column.ComputedWidth;
                graphicsContext.DrawLine(x + xOffset, y, x + xOffset, y + ComputedHeight, RuleWidth);
            }
            graphicsContext.DrawLine(x, y, x + ComputedWidth, y, RuleWidth);
            double yOffset = 0;

            foreach (TableRow row in _rows)
            {
                yOffset += row.ComputedWidth;
                graphicsContext.DrawLine(x, y + yOffset, x + ComputedWidth, y + yOffset, RuleWidth);
            }
        }
Пример #4
0
        public override void Draw(IGraphicsContext GC)
        {
            Color oldColor = GC.Color;
            Color primary  = Color.Orchid;

            if (!IsNotEmptyString(FromPortName) || !IsNotEmptyString(ToPortName) /* || !IsNotEmptyString (Interface) */)
            {
                primary = Color.Red;
            }

            GC.Color = primary;
            if (Selected)
            {
                GC.Thickness = 5;
            }
            else
            {
                GC.Thickness = 2;
            }
            GC.DrawLine(_From, _To);
            foreach (IPortLinkContactPointGlyph contact in ContactPoints)
            {
                switch (contact.WhichEnd)
                {
                case TransitionContactEnd.From: GC.Thickness = 3; break;

                case TransitionContactEnd.To: GC.Thickness = 5; break;

                default: throw new NotSupportedException("Unknown TransitionContactEnd: " + contact.WhichEnd.ToString());
                }
                IComponentGlyph component = contact.Parent as IComponentGlyph;
                if (component != null)
                {
                    GC.Color = component.ComponentColor;
                    contact.Draw(GC);
                }
                else
                {
                    GC.Color = primary;
                    contact.Draw(GC);
                }
            }
            string s = DisplayText();

            using (Brush brush = new System.Drawing.SolidBrush(Color.Black))
            {
                GC.DrawString(s, brush, 10, new Point((_To.X + _From.X) / 2, (_To.Y + _From.Y) / 2), true);
            }
            GC.Color = oldColor;
        }
Пример #5
0
        public override void Draw(IGraphicsContext GC)
        {
            Color oldColor = GC.Color;
            Color primary  = Color.Orchid;

            if (Interface == null || Interface.Trim() == "")
            {
                primary = Color.Red;
            }

            GC.Color = primary;
            if (Selected)
            {
                GC.Thickness = 5;
            }
            else
            {
                GC.Thickness = 2;
            }
            GC.DrawLine(_From, _To);
            foreach (OperationPortLinkContactPointGlyph contact in ContactPoints)
            {
                switch (contact.WhichEnd)
                {
                case TransitionContactEnd.From: GC.Thickness = 3; break;

                case TransitionContactEnd.To: GC.Thickness = 5; break;

                default: throw new NotSupportedException("Unknown TransitionContactEnd: " + contact.WhichEnd.ToString());
                }
                IOperationGlyph operation = contact.Parent as IOperationGlyph;
                if (operation != null)
                {
                    GC.Color = primary;                     // FIXUP: operation.OperationColor;
                    contact.Draw(GC);
                }
                else
                {
                    GC.Color = primary;
                    contact.Draw(GC);
                }
            }
            string s = DisplayText();

            using (Brush brush = new System.Drawing.SolidBrush(Color.Black))
            {
                GC.DrawString(s, brush, 10, new Point((_To.X + _From.X) / 2, (_To.Y + _From.Y) / 2), true);
            }
            GC.Color = oldColor;
        }
        public override void Draw(IGraphicsContext GC)
        {
            Color oldColor = GC.Color;
            Color primary = Color.Orchid;
            if (Interface == null || Interface.Trim () == "")
            {
                primary = Color.Red;
            }

            GC.Color = primary;
            if (Selected)
            {
                GC.Thickness = 5;
            }
            else
            {
                GC.Thickness = 2;
            }
            GC.DrawLine (_From, _To);
            foreach (OperationPortLinkContactPointGlyph contact in ContactPoints)
            {
                switch (contact.WhichEnd)
                {
                    case TransitionContactEnd.From: GC.Thickness = 3; break;
                    case TransitionContactEnd.To: GC.Thickness = 5; break;
                    default: throw new NotSupportedException ("Unknown TransitionContactEnd: " + contact.WhichEnd.ToString ());
                }
                IOperationGlyph operation = contact.Parent as IOperationGlyph;
                if (operation != null)
                {
                    GC.Color = primary; // FIXUP: operation.OperationColor;
                    contact.Draw (GC);
                }
                else
                {
                    GC.Color = primary;
                    contact.Draw (GC);
                }
            }
            string s = DisplayText ();
            using (Brush brush = new System.Drawing.SolidBrush (Color.Black))
            {
                GC.DrawString (s, brush, 10, new Point ((_To.X + _From.X) / 2, (_To.Y + _From.Y) / 2), true);
            }
            GC.Color = oldColor;
        }
 public override void Draw(IGraphicsContext gc)
 {
     if (_SelectionBand.Width > 0 || _SelectionBand.Height > 0)
     {
         if (_DrawDirection)
         {
             gc.Color = Color.LightGray;
             gc.DrawRectangle (_SelectionBand);
             gc.DrawLine (StartPoint, EndPoint, Color.LightGray, Color.DarkGray);
             gc.DrawTrianglePointer (StartPoint, EndPoint, 5, 5);
         }
         else
         {
             gc.Color = Color.Gray;
             gc.DrawRectangle (_SelectionBand);
         }
     }
 }
Пример #8
0
 public override void Draw(IGraphicsContext gc)
 {
     if (_SelectionBand.Width > 0 || _SelectionBand.Height > 0)
     {
         if (_DrawDirection)
         {
             gc.Color = Color.LightGray;
             gc.DrawRectangle(_SelectionBand);
             gc.DrawLine(StartPoint, EndPoint, Color.LightGray, Color.DarkGray);
             gc.DrawTrianglePointer(StartPoint, EndPoint, 5, 5);
         }
         else
         {
             gc.Color = Color.Gray;
             gc.DrawRectangle(_SelectionBand);
         }
     }
 }
Пример #9
0
        public override void Draw(IGraphicsContext GC)
        {
            using (GC.PushGraphicsState())
            {
                bool      isOk;
                bool      usePrimary;
                Color     primary;
                DashStyle dashStyle;
                usePrimary = PrimaryInformation(out isOk, out primary, out dashStyle);
                GC.Color   = primary;
                int thickness = 2;
                if (Selected)
                {
                    thickness = 5;
                }

                Color fromColor;
                Color toColor;
                DrawContactPoints(GC, isOk, usePrimary, primary, out fromColor, out toColor);

                GC.Thickness = thickness;
                GC.DrawLine(_From, _To, fromColor, toColor, dashStyle);

                ArrayList contextList      = GetDisplayTextAsContextList(GC);
                int       startX           = (_To.X + _From.X) / 2;
                int       startY           = (_To.Y + _From.Y) / 2;
                bool      isMoreHorizontal = Math.Abs(_To.X - _From.X) > Math.Abs(_To.Y - _From.Y);
                bool      positiveWidthAdjust;
                bool      positiveHeightAdjust;
                if (isMoreHorizontal)
                {
                    positiveWidthAdjust  = false;
                    positiveHeightAdjust = true;
                }
                else
                {
                    positiveWidthAdjust  = false;
                    positiveHeightAdjust = false;
                }
                GC.DrawString(contextList, new Point(startX, startY), positiveWidthAdjust, positiveHeightAdjust, true);
            }
        }
Пример #10
0
        public override void Draw(IGraphicsContext GC)
        {
            Color oldColor = GC.Color;
            Color primary = Color.Orchid;
            if (!IsNotEmptyString (FromPortName) || !IsNotEmptyString (ToPortName) /* || !IsNotEmptyString (Interface) */)
            {
                primary = Color.Red;
            }

            GC.Color = primary;
            if (Selected)
            {
                GC.Thickness = 5;
            }
            else
            {
                GC.Thickness = 2;
            }
            GC.DrawLine (_From, _To);
            foreach (IPortLinkContactPointGlyph contact in ContactPoints)
            {
                switch (contact.WhichEnd)
                {
                    case TransitionContactEnd.From: GC.Thickness = 3; break;
                    case TransitionContactEnd.To: GC.Thickness = 5; break;
                    default: throw new NotSupportedException ("Unknown TransitionContactEnd: " + contact.WhichEnd.ToString ());
                }
                IComponentGlyph component = contact.Parent as IComponentGlyph;
                if (component != null)
                {
                    GC.Color = component.ComponentColor;
                    contact.Draw (GC);
                }
                else
                {
                    GC.Color = primary;
                    contact.Draw (GC);
                }
            }
            string s = DisplayText ();
            using (Brush brush = new System.Drawing.SolidBrush (Color.Black))
            {
                GC.DrawString (s, brush, 10, new Point ((_To.X + _From.X) / 2, (_To.Y + _From.Y) / 2), true);
            }
            GC.Color = oldColor;
        }
Пример #11
0
        public void Render(IGraphicsContext context)
        {
            // Value range is the size between max and min track bar value.
            // Ex: Min = 50, Max = 150. Value range = 100 + 1 (because we include 50 and 100)
            _valueRange = (Maximum - Minimum) + 1;

            // Get track bar value relative to value range (value - minimum value).
            // Ex: Min = 50, Max = 150, Value = 100. Value relative to value range = 50.
            _valueRelativeToValueRange = Value - Minimum;

            // Draw background
            context.DrawRectangle(new BasicRectangle(0, 0, context.BoundsWidth, context.BoundsHeight), _brushBackground, _penTransparent);

            // Return if value range is zero
            if (_valueRange == 0)
                return;

            // Draw fader track
            float trackX = context.BoundsWidth / 2;
            float trackY = Margin;
            float trackY2 = context.BoundsHeight - Margin;

            // Draw shadow track
            context.DrawLine(new BasicPoint(trackX + 1, trackY + 1), new BasicPoint(trackX + 1, trackY2 + 1), new BasicPen(new BasicBrush(_centerLineShadowColor), 1));

            // Draw track
            context.DrawLine(new BasicPoint(trackX, trackY), new BasicPoint(trackX, trackY2), new BasicPen(new BasicBrush(_centerLineColor), 1));

            // Get the track height (remove margin from top and bottom)            
            _trackHeight = context.BoundsHeight - (Margin * 2);

            // Get tick width
            float tickHeight = _trackHeight / _valueRange;

            // Get the percentage of the value relative to value range (needed to draw the fader).
            // We need to divide the value relative to value range to the value range to get the ratio.
            // Ex: Min = 50, Max = 150, Value = 100. Value relative to value range = 50. Value range = 100. Value ratio = 0.5
            _valueRatio = (_valueRelativeToValueRange / _valueRange);

            // Calculate fader position
            // We need to invert the values (i.e. max is on top, min is bottom)
            //float valueY = (valueRatio * trackHeight) + Margin;            
            float valueY = _trackHeight - (_valueRatio * _trackHeight) + Margin;
            float faderY = valueY + ((tickHeight - FaderHeight) / 2);
            float tickCenterY = valueY + (tickHeight / 2);

            // Create fader rectangle            
            _rectFader = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2), faderY, FaderWidth, FaderHeight);

            //    // Draw tick zone (for debug)
            //    //RectangleF rectTickZone = new RectangleF(valueX, 0, tickWidth, Height);
            //    //g.FillRectangle(Brushes.DarkGray, rectTickZone);            

            var rectFaderShadowTop = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2) + 1, faderY + 1, FaderWidth, 8);
            var rectFaderShadowBottom = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2) + 1, faderY + FaderHeight - 8 + 1, FaderWidth, 8);
            var rectFaderShadowCenter = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2) + 1, faderY + 4 + 1, FaderWidth, FaderHeight - 8);

            context.DrawEllipsis(rectFaderShadowTop, _brushFaderShadowColor, _penTransparent);
            context.DrawEllipsis(rectFaderShadowBottom, _brushFaderShadowColor, _penTransparent);
            context.DrawRectangle(rectFaderShadowCenter, _brushFaderShadowColor, _penTransparent);

            // Draw fader outline (with 8px border)            
            var rectFaderTop = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2), faderY, FaderWidth, 8);
            var rectFaderBottom = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2), faderY + FaderHeight - 8, FaderWidth, 8);
            var rectFaderBottomCenter = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2), faderY + FaderHeight - 10, FaderWidth, 6);
            var rectFaderCenter = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2), faderY + 4, FaderWidth, FaderHeight - 8);

            context.DrawEllipsis(rectFaderTop, _brushFaderGradient, _penTransparent);
            context.DrawEllipsis(rectFaderBottom, _brushFaderShadowColor1, _penTransparent);
            context.DrawRectangle(rectFaderCenter, _brushFaderColor2, _penTransparent);
            context.DrawRectangle(rectFaderBottomCenter, _brushFaderShadowColor1, _penTransparent);

            // Draw fader inside (with 4px border)
            var rectFaderInsideBottom = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2) + 1, faderY + FaderHeight - 8, FaderWidth - 2, 4);
            var rectFaderInsideBottomCenter = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2) + 1, faderY + FaderHeight - 12, FaderWidth - 2, FaderHeight - 24);
            var rectFaderInsideTop = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2) + 1, faderY + 4, FaderWidth - 2, 8);
            var rectFaderInsideTopCenter = new BasicRectangle((context.BoundsWidth / 2) - (FaderWidth / 2) + 1, faderY + 8, FaderWidth - 2, FaderHeight - 24);

            context.DrawEllipsis(rectFaderInsideTop, _brushFaderShadowColor1, _penTransparent);
            context.DrawEllipsis(rectFaderInsideTopCenter, _brushFaderShadowGradient, _penTransparent);
            context.DrawEllipsis(rectFaderInsideBottom, _brushFaderColor2, _penTransparent);
            context.DrawRectangle(rectFaderInsideBottomCenter, _brushFaderColor2, _penTransparent);
            context.DrawLine(new BasicPoint((context.BoundsWidth / 2) - (FaderWidth / 2), tickCenterY), new BasicPoint((context.BoundsWidth / 2) - (FaderWidth / 2) + FaderWidth, tickCenterY), _penMiddleLineColor);
        }
Пример #12
0
        public void Render(IGraphicsContext context)
        {
            // Value range is the size between max and min track bar value.
            // Ex: Min = 50, Max = 150. Value range = 100 + 1 (because we include 50 and 100)
            _valueRange = (Maximum - Minimum) + 1;

            // Get track bar value relative to value range (value - minimum value).
            // Ex: Min = 50, Max = 150, Value = 100. Value relative to value range = 50.            
            _valueRelativeToValueRange = Value - Minimum;

            // Draw background
            context.DrawRectangle(new BasicRectangle(0, 0, context.BoundsWidth, context.BoundsHeight), _brushBackground, _penTransparent);

            // Return if value range is zero
            if (_valueRange == 0)
                return;

            // Draw fader track
            float trackX = Margin; // add margin from left
            float trackX2 = context.BoundsWidth - Margin; // add margin from right
            float trackY = context.BoundsHeight / 2; // right in the center

            context.DrawLine(new BasicPoint(trackX + 1, trackY + 1), new BasicPoint(trackX2 + 1, trackY + 1), _penCenterLineShadow);
            context.DrawLine(new BasicPoint(trackX, trackY), new BasicPoint(trackX2, trackY), _penCenterLine);

            // Get the track width (remove margin from left and right)
            _trackWidth = context.BoundsWidth - (Margin * 2);

            // Get tick width
            float tickWidth = _trackWidth / _valueRange;

            // Get the percentage of the value relative to value range (needed to draw the fader).
            // We need to divide the value relative to value range to the value range to get the ratio.
            // Ex: Min = 50, Max = 150, Value = 100. Value relative to value range = 50. Value range = 100. Value ratio = 0.5
            _valueRatio = (_valueRelativeToValueRange / _valueRange);

            // Get the value X coordinate by multiplying the value ratio to the track bar width (removed 3 pixels from left
            // and right). Add margin from left.
            float valueX = (_valueRatio * _trackWidth) + Margin; // this gives the LEFT x for our zone
            float faderX = valueX + ((tickWidth - FaderWidth) / 2);
            float tickCenterX = valueX + (tickWidth / 2);

            // Create fader rectangle
            _rectFader = new BasicRectangle(faderX, (context.BoundsHeight / 2) - (FaderHeight / 2), FaderWidth, FaderHeight);

            //// Draw tick zone (for debug)
            ////RectangleF rectTickZone = new RectangleF(valueX, 0, tickWidth, Height);
            ////g.FillRectangle(Brushes.DarkGray, rectTickZone);            

            // Draw fader outline (with 8px border)
            //var rectFaderLeft = new BasicRectangle(faderX, (context.BoundsHeight / 2) - (FaderHeight / 2), 8, FaderHeight);
            //var rectFaderRight = new BasicRectangle(faderX + FaderWidth - 8, (context.BoundsHeight / 2) - (FaderHeight / 2), 8, FaderHeight);
            var rectFaderCenter = new BasicRectangle(faderX + 4, (context.BoundsHeight / 2) - (FaderHeight / 2), FaderWidth - 8, FaderHeight);

            //context.DrawEllipsis(rectFaderLeft, new BasicGradientBrush(_faderColor1, _faderColor, 90), new BasicPen());
            //context.DrawEllipsis(rectFaderLeft, new BasicGradientBrush(new BasicColor(255, 0, 0), new BasicColor(0, 0, 255), 90), new BasicPen());
            //context.DrawEllipsis(rectFaderRight, new BasicGradientBrush(_faderColor1, _faderColor, 90), new BasicPen());
            //context.DrawEllipsis(rectFaderRight, new BasicGradientBrush(new BasicColor(0, 255, 0), new BasicColor(255, 0, 255), 90), new BasicPen());
            context.DrawEllipsis(rectFaderCenter, _brushFaderColor2, _penShadowColor1);
            //context.DrawEllipsis(rectFaderCenter, new BasicBrush(_faderColor), new BasicPen());

            // Draw fader inside (with 4px border)
            //var rectFaderInsideLeft = new BasicRectangle(faderX + 2, (context.BoundsHeight / 2) - (FaderHeight / 2) + 2, 4, FaderHeight - 4);
            //var rectFaderInsideRight = new BasicRectangle(faderX + FaderWidth - 6, (context.BoundsHeight / 2) - (FaderHeight / 2) + 2, 4, FaderHeight - 4);
            //context.DrawEllipsis(rectFaderInsideLeft, new BasicGradientBrush(_faderShadowColor, _faderShadowColor, 90), new BasicPen());
            //context.DrawEllipsis(rectFaderInsideRight, new BasicGradientBrush(_faderShadowColor, _faderShadowColor, 90), new BasicPen());
            
            context.DrawLine(new BasicPoint(tickCenterX, (context.BoundsHeight / 2) - (FaderHeight / 2)), new BasicPoint(tickCenterX, (context.BoundsHeight / 2) - (FaderHeight / 2) + FaderHeight), _penShadowColor1);
        }
Пример #13
0
        public void Render(IGraphicsContext context)
        {
            Frame = new BasicRectangle(0, 0, context.BoundsWidth, context.BoundsHeight);
            var rectBackground = new BasicRectangle(0, 0, context.BoundsWidth, context.BoundsHeight);
            //context.DrawRectangle(rectBackground, _brushBackground, _penTransparent);

            const float padding = 2;
            const float checkPadding = padding + 4;
            var rectForeground = new BasicRectangle(padding, padding, context.BoundsWidth - (padding * 2), context.BoundsHeight - (padding * 2));
            context.DrawRectangle(rectForeground, _brushTransparent, _penBorder);

            if (_value)
            {
                context.DrawLine(new BasicPoint(checkPadding, checkPadding), new BasicPoint(context.BoundsWidth - checkPadding, context.BoundsHeight - checkPadding), _penForeground);
                context.DrawLine(new BasicPoint(context.BoundsWidth - checkPadding, checkPadding), new BasicPoint(checkPadding, context.BoundsHeight - checkPadding), _penForeground);
            }
        }
Пример #14
0
 public virtual void DrawLine(Point point1, Point point2, Color color, int thickness) => GraphicsContext.DrawLine(Surface, point1, point2, color, thickness);
        public override void Draw(IGraphicsContext GC)
        {
            using (GC.PushGraphicsState ())
            {
                bool isOk;
                bool usePrimary;
                Color primary;
                DashStyle dashStyle;
                usePrimary = PrimaryInformation (out isOk, out primary, out dashStyle);
                GC.Color = primary;
                int thickness = 2;
                if (Selected)
                {
                    thickness = 5;
                }

                Color fromColor;
                Color toColor;
                DrawContactPoints (GC, isOk, usePrimary, primary, out fromColor, out toColor);

                GC.Thickness = thickness;
                GC.DrawLine (_From, _To, fromColor, toColor, dashStyle);

                ArrayList contextList = GetDisplayTextAsContextList (GC);
                int startX = (_To.X + _From.X) / 2;
                int startY = (_To.Y + _From.Y) / 2;
                bool isMoreHorizontal = Math.Abs (_To.X - _From.X) > Math.Abs (_To.Y - _From.Y);
                bool positiveWidthAdjust;
                bool positiveHeightAdjust;
                if (isMoreHorizontal)
                {
                    positiveWidthAdjust = false;
                    positiveHeightAdjust = true;
                }
                else
                {
                    positiveWidthAdjust = false;
                    positiveHeightAdjust = false;
                }
                GC.DrawString (contextList, new Point (startX, startY), positiveWidthAdjust, positiveHeightAdjust, true);

            }
        }
Пример #16
0
 public void Draw(IGraphicsContext gc, Typeface normal, Typeface bold, Brush brush)
 {
     gc.DrawLine(x1, y1, x2, y2, brush, lineWidth);
 }
Пример #17
0
        private void DrawAlbumCoverZone(IGraphicsContext context, int row, AudioFile audioFile2, DrawCellState state)
        {
            var pen = new BasicPen();
            var penTransparent = new BasicPen();
            var brushGradient = new BasicGradientBrush();
            var item = _items[row];
            //string albumTitle = audioFile != null ? audioFile.AlbumTitle : state.CurrentAlbumTitle; // if this is an empty row, keep last album title

            // Check for an album title change (or the last item of the grid)
            if (state.CurrentAlbumArtKey == item.AlbumArtKey)
                return;

            state.CurrentAlbumArtKey = item.AlbumArtKey;

            int albumCoverStartIndex = 0;
            int albumCoverEndIndex = 0;

            // For displaying the album cover, we need to know how many songs of the same album are bundled together
            // Start by getting the start index
            for (int c = row; c > 0; c--)
            {
                var previousItem = _items[c];
                if (previousItem.AlbumArtKey != item.AlbumArtKey)
                {
                    albumCoverStartIndex = c + 1;
                    break;
                }
            }

            // Find the end index
            for (int c = row + 1; c < _items.Count; c++)
            {
                var nextItem = _items[c];

                // If the album title is different, this means we found the next album title
                if (nextItem.AlbumArtKey != item.AlbumArtKey)
                {
                    albumCoverEndIndex = c - 1;
                    break;
                }
                // If this is the last item of the grid...
                else if (c == _items.Count - 1)
                {
                    albumCoverEndIndex = c;
                    break;
                }
            }

            var audioFile = _items[albumCoverStartIndex].AudioFile;

            // Calculate y and height
            int scrollbarOffsetY = (_startLineNumber * _songCache.LineHeight) - VerticalScrollBar.Value;
            int y = ((albumCoverStartIndex - _startLineNumber) * _songCache.LineHeight) + _songCache.LineHeight + scrollbarOffsetY;

            // Calculate the height of the album cover zone (+1 on end index because the array is zero-based)
            int linesToCover = Math.Min(MinimumRowsPerAlbum, (albumCoverEndIndex + 1 - albumCoverStartIndex));
            int albumCoverZoneHeight = linesToCover * _songCache.LineHeight;
            int heightWithPadding = Math.Min(albumCoverZoneHeight - (_theme.Padding * 2), _songCache.ActiveColumns[0].Width - (_theme.Padding * 2));

            // Make sure the height is at least zero (not necessary to draw anything!)
            if (albumCoverZoneHeight > 0)
            {
                // Draw album cover background
                var rectAlbumCover = new BasicRectangle(0 - HorizontalScrollBar.Value, y, _songCache.ActiveColumns[0].Width, albumCoverZoneHeight);
                brushGradient = new BasicGradientBrush(_theme.AlbumCoverBackgroundColor, _theme.AlbumCoverBackgroundColor, 90);
                context.DrawRectangle(rectAlbumCover, brushGradient, penTransparent);

                // Measure available width for text
                int widthAvailableForText = _columns[0].Width - (_theme.Padding * 2);

                // Display titles depending on if an album art was found
                var rectAlbumCoverArt = new BasicRectangle();
                var rectAlbumTitleText = new BasicRectangle();
                var rectArtistNameText = new BasicRectangle();
                var sizeAlbumTitle = new BasicRectangle();
                var sizeArtistName = new BasicRectangle();
                bool useAlbumArtOverlay = false;
                bool displayArtistNameAndAlbumTitle = false;

                // Try to extract image from cache
                IBasicImage imageAlbumCover = null;
                SongGridViewImageCache cachedImage = null;
                try
                {
                    cachedImage = _imageCache.FirstOrDefault(x => x.Key == item.AlbumArtKey);
                }
                catch (Exception ex)
                {
                    Tracing.Log(ex);
                }

                if (cachedImage != null)
                    imageAlbumCover = cachedImage.Image;

                // Album art not found in cache; try to find an album cover in one of the file
                if (cachedImage == null)
                {
                    try
                    {
                        // Check if the album cover is already in the pile
                        bool albumCoverFound = false;
                        foreach (var arg in _workerUpdateAlbumArtPile)
                        {
                            // Match by file path
                            if (arg.AudioFile.FilePath.ToUpper() == audioFile.FilePath.ToUpper())
                            {
                                albumCoverFound = true;
                            }
                        }

                        // Add to the pile only if the album cover isn't already in it
                        if (!albumCoverFound)
                        {
                            // Add item to update album art worker pile
                            var arg = new SongGridViewBackgroundWorkerArgument();
                            arg.AudioFile = audioFile;
                            arg.LineIndex = row;
                            arg.RectAlbumArt = new BasicRectangle(0, 0, heightWithPadding, heightWithPadding);
                            _workerUpdateAlbumArtPile.Add(arg);
                        }
                    }
                    catch(Exception ex)
                    {
                        Console.WriteLine("SongGridViewControl - Failed to load cache image: {0}" , ex);
                    }
                }

                // There are at least two lines; is there an album cover to display?
                if (imageAlbumCover == null)
                {
                    // There is no album cover to display; display only text.
                    // Set string format
                    //stringFormat.Alignment = StringAlignment.Center;
                    //stringFormat.Trimming = StringTrimming.EllipsisWord;

                    sizeArtistName = context.MeasureText(audioFile.ArtistName, new BasicRectangle(0, 0, widthAvailableForText, heightWithPadding), _theme.FontNameAlbumArtTitle, _theme.FontSize + 2);
                    sizeAlbumTitle = context.MeasureText(audioFile.AlbumTitle, new BasicRectangle(0, 0, widthAvailableForText, heightWithPadding), _theme.FontNameAlbumArtSubtitle, _theme.FontSize);

                    // Display the album title at the top of the zome
                    rectArtistNameText = new BasicRectangle(_theme.Padding - HorizontalScrollBar.Value, y + _theme.Padding, widthAvailableForText, heightWithPadding);
                    rectAlbumTitleText = new BasicRectangle(_theme.Padding - HorizontalScrollBar.Value, y + _theme.Padding + sizeArtistName.Height, widthAvailableForText, heightWithPadding);
                    displayArtistNameAndAlbumTitle = true;
                    useAlbumArtOverlay = true;
                }
                else
                {
                    // There is an album cover to display with more than 2 lines.
                    // Set string format
                    //stringFormat.Alignment = StringAlignment.Near;
                    //stringFormat.Trimming = StringTrimming.EllipsisWord;

                    float widthRemainingForText = _columns[0].Width - (_theme.Padding * 3) - heightWithPadding;
                    sizeArtistName = context.MeasureText(audioFile.ArtistName, new BasicRectangle(0, 0, widthRemainingForText, heightWithPadding), _theme.FontNameAlbumArtTitle, _theme.FontSize + 2);
                    sizeAlbumTitle = context.MeasureText(audioFile.AlbumTitle, new BasicRectangle(0, 0, widthRemainingForText, heightWithPadding), _theme.FontNameAlbumArtSubtitle, _theme.FontSize);

                    // Try to center the cover art + padding + max text width
                    //float maxWidth = Math.Max(sizeArtistName.Width, sizeAlbumTitle.Width);
                    float albumCoverX = _theme.Padding - 2; // (_columns[0].Width - heightWithPadding - _theme.Padding - _theme.Padding - maxWidth) / 2;
                    float artistNameY = _theme.Padding + 1; // (albumCoverZoneHeight - sizeArtistName.Height - sizeAlbumTitle.Height) / 2;

                    // Display the album title at the top of the zome
                    rectArtistNameText = new BasicRectangle(albumCoverX + heightWithPadding + _theme.Padding - HorizontalScrollBar.Value, y + artistNameY, widthRemainingForText, heightWithPadding);
                    rectAlbumTitleText = new BasicRectangle(albumCoverX + heightWithPadding + _theme.Padding - HorizontalScrollBar.Value, y + artistNameY + sizeArtistName.Height + (_theme.Padding / 8f), widthRemainingForText, heightWithPadding);
                    rectAlbumCoverArt = new BasicRectangle(albumCoverX - HorizontalScrollBar.Value, y + _theme.Padding, heightWithPadding, heightWithPadding);
                    displayArtistNameAndAlbumTitle = widthRemainingForText > 20;
                    useAlbumArtOverlay = true;
                }

                // Display album cover
                if (imageAlbumCover != null)
                    context.DrawImage(rectAlbumCoverArt, new BasicRectangle(0, 0, imageAlbumCover.ImageSize.Width, imageAlbumCover.ImageSize.Height), imageAlbumCover.Image);
                    //context.DrawImage(rectAlbumCoverArt, new BasicRectangle(0, 0, rectAlbumCoverArt.Width, rectAlbumCoverArt.Height), imageAlbumCover.Image);

//                if (useAlbumArtOverlay)
//                {
//                    // Draw artist name and album title background
//                    var rectArtistNameBackground = new BasicRectangle(rectArtistNameText.X - (_theme.Padding / 2), rectArtistNameText.Y - (_theme.Padding / 4), sizeArtistName.Width + _theme.Padding, sizeArtistName.Height + (_theme.Padding / 2));
//                    var rectAlbumTitleBackground = new BasicRectangle(rectAlbumTitleText.X - (_theme.Padding / 2), rectAlbumTitleText.Y - (_theme.Padding / 4), sizeAlbumTitle.Width + _theme.Padding, sizeAlbumTitle.Height + (_theme.Padding / 2));
//                    var brushTextBackground = new BasicBrush(new BasicColor(0, 0, 0, 30));
//                    context.DrawRectangle(rectArtistNameBackground, brushTextBackground, penTransparent);
//                    context.DrawRectangle(rectAlbumTitleBackground, brushTextBackground, penTransparent);
//                }

                if (displayArtistNameAndAlbumTitle)
                {
                    context.DrawText(audioFile.ArtistName, rectArtistNameText, _theme.HeaderTextColor, _theme.FontNameAlbumArtTitle, _theme.FontSize + 2);
                    context.DrawText(audioFile.AlbumTitle, rectAlbumTitleText, _theme.HeaderTextColor, _theme.FontNameAlbumArtSubtitle, _theme.FontSize);
                }

                // Draw horizontal line to distinguish albums
                // Part 1: Draw line over grid
                pen = new BasicPen(new BasicBrush(new BasicColor(180, 180, 180)), 1);
                context.DrawLine(new BasicPoint(_columns[0].Width, y), new BasicPoint(Frame.Width, y), pen);

                // Part 2: Draw line over album art zone, in a lighter color
                pen = new BasicPen(new BasicBrush(new BasicColor(115, 115, 115)), 1);
                context.DrawLine(new BasicPoint(0, y), new BasicPoint(_columns[0].Width, y), pen);
            }
        }