예제 #1
0
 public void DrawLine(BasicPoint point, BasicPoint point2, BasicPen pen)
 {
     _context.SetSourceRGB(pen.Brush.Color.R / 255f, pen.Brush.Color.G / 255f, pen.Brush.Color.B / 255f);
     _context.LineTo(point.X, point.Y);
     _context.LineTo(point2.X, point2.Y);
     _context.LineWidth = pen.Thickness;
     _context.Stroke();
 }
예제 #2
0
 private void CreateDrawingResources()
 {
     ColorBackground = new BasicColor(32, 40, 46);
     ColorForeground = new BasicColor(231, 76, 60);
     _brushBackground = new BasicBrush(ColorBackground);
     _brushForeground = new BasicBrush(ColorForeground);
     _penTransparent = new BasicPen();
 }
예제 #3
0
		public void DrawLine(BasicPoint point, BasicPoint point2, BasicPen pen)
		{
			CoreGraphicsHelper.DrawLine(Context, new List<PointF>(){ GenericControlHelper.ToPoint(point), GenericControlHelper.ToPoint(point2) }, GenericControlHelper.ToColor(pen.Brush.Color).CGColor, pen.Thickness, true, false);
		}
예제 #4
0
 private void CreateDrawingResources()
 {
     _penTransparent = new BasicPen();
     _penShadowColor1 = new BasicPen(new BasicBrush(_theme.FaderShadowColor), 1);
     _penCenterLine = new BasicPen(new BasicBrush(_theme.CenterLineColor), 1);
     _penCenterLineShadow = new BasicPen(new BasicBrush(_theme.CenterLineShadowColor), 1);
     _brushBackground = new BasicBrush(_theme.BackgroundColor);
     _brushFaderColor2 = new BasicBrush(_theme.FaderColor);
 }
예제 #5
0
		public void DrawPath(BasicPath path, BasicBrush brush, BasicPen pen)
		{
		}
예제 #6
0
 public void DrawEllipsis(BasicRectangle rectangle, BasicBrush brush, BasicPen pen)
 {
     _context.DrawEllipse(GenericControlHelper.ToSolidColorBrush(brush), GenericControlHelper.ToPen(pen), GenericControlHelper.ToPoint(rectangle.Center()), rectangle.Width / 2, rectangle.Height / 2);
 }
예제 #7
0
 public void DrawLine(BasicPoint point, BasicPoint point2, BasicPen pen)
 {
     _context.DrawLine(GenericControlHelper.ToPen(pen), GenericControlHelper.ToPoint(point), GenericControlHelper.ToPoint(point2));
 }
예제 #8
0
        private void DrawCell(IGraphicsContext context, int row, int col, AudioFile audioFile, DrawCellState state)
        {
            var rect = new BasicRectangle();
            var brush = new BasicBrush();
            var brushGradient = new BasicGradientBrush();
            var penTransparent = new BasicPen();
            var column = _songCache.ActiveColumns[col];
            if (column.Visible)
            {
                if (column.Title == "Now Playing")
                {
                    // Draw now playing icon
                    if ((_mode == SongGridViewMode.AudioFile && audioFile != null && audioFile.Id == _nowPlayingAudioFileId) ||
                        (_mode == SongGridViewMode.Playlist && _items[row].PlaylistItemId == _nowPlayingPlaylistItemId))
                    {
                        // Which size is the minimum? Width or height?                    
                        int availableWidthHeight = column.Width - 4;
                        if (_songCache.LineHeight <= column.Width)
                            availableWidthHeight = _songCache.LineHeight - 4;
                        else
                            availableWidthHeight = column.Width - 4;

                        // Calculate the icon position                                
                        float iconNowPlayingX = ((column.Width - availableWidthHeight) / 2) + state.OffsetX - HorizontalScrollBar.Value;
                        float iconNowPlayingY = state.OffsetY + ((_songCache.LineHeight - availableWidthHeight) / 2);

                        // Create NowPlaying rect (MUST be in integer)                    
                        _rectNowPlaying = new BasicRectangle((int)iconNowPlayingX, (int)iconNowPlayingY, availableWidthHeight, availableWidthHeight);
                        state.NowPlayingSongFound = true;

                        // Draw outer circle
                        brushGradient = new BasicGradientBrush(_theme.NowPlayingIndicatorBackgroundColor, _theme.NowPlayingIndicatorBackgroundColor, _timerAnimationNowPlayingCount % 360);
                        context.DrawEllipsis(_rectNowPlaying, brushGradient, penTransparent);

                        // Draw inner circle
                        rect = new BasicRectangle((int)iconNowPlayingX + 4, (int)iconNowPlayingY + 4, availableWidthHeight - 8, availableWidthHeight - 8);
                        brush = new BasicBrush(_theme.NowPlayingBackgroundColor);
                        context.DrawEllipsis(rect, brush, penTransparent);
                    }
                }
                else if (column.Title == "Album Cover")
                {
                    DrawAlbumCoverZone(context, row, audioFile, state);
                }
                else if (audioFile != null)
                {
                    // Print value depending on type
                    var propertyInfo = audioFile.GetType().GetProperty(column.FieldName);
                    if (propertyInfo != null)
                    {
                        string value = string.Empty;
                        try
                        {
                            if (propertyInfo.PropertyType.FullName == "System.String")
                            {
                                value = propertyInfo.GetValue(audioFile, null).ToString();
                            }
                            else if (propertyInfo.PropertyType.FullName.Contains("Int64") &&
                                propertyInfo.PropertyType.FullName.Contains("Nullable"))
                            {
                                long? longValue = (long?)propertyInfo.GetValue(audioFile, null);
                                if (longValue.HasValue)
                                    value = longValue.Value.ToString();
                            }
                            else if (propertyInfo.PropertyType.FullName.Contains("DateTime") &&
                                propertyInfo.PropertyType.FullName.Contains("Nullable"))
                            {
                                DateTime? dateTimeValue = (DateTime?)propertyInfo.GetValue(audioFile, null);
                                if (dateTimeValue.HasValue)
                                    value = dateTimeValue.Value.ToShortDateString() + " " + dateTimeValue.Value.ToShortTimeString();
                            }
                            else if (propertyInfo.PropertyType.FullName.Contains("System.UInt32"))
                            {
                                uint uintValue = (uint)propertyInfo.GetValue(audioFile, null);
                                value = uintValue.ToString();
                            }
                            else if (propertyInfo.PropertyType.FullName.Contains("System.Int32"))
                            {
                                int intValue = (int)propertyInfo.GetValue(audioFile, null);
                                value = intValue.ToString();
                            }
                            else if (propertyInfo.PropertyType.FullName.Contains("Sessions.Sound.AudioFileFormat"))
                            {
                                AudioFileFormat theValue = (AudioFileFormat)propertyInfo.GetValue(audioFile, null);
                                value = theValue.ToString();
                            }
                        }
                        catch
                        {
                            // Do nothing
                        }

                        //// The last column always take the remaining width
                        //int columnWidth = column.Width;
                        //if (b == _songCache.ActiveColumns.Count - 1)
                        //{
                        //    // Calculate the remaining width
                        //    int columnsWidth = 0;
                        //    for (int c = 0; c < _songCache.ActiveColumns.Count - 1; c++)
                        //    {
                        //        columnsWidth += _songCache.ActiveColumns[c].Width;
                        //    }
                        //    //columnWidth = (int) (Frame.Width - columnsWidth + HorizontalScrollBar.Value);
                        //}

                        // Display text
                        rect = new BasicRectangle(state.OffsetX - HorizontalScrollBar.Value + 2, state.OffsetY + (_theme.Padding / 2), _songCache.ActiveColumns[col].Width, _songCache.LineHeight - _theme.Padding + 2);
                        //stringFormat.Trimming = StringTrimming.EllipsisCharacter;
                        //stringFormat.Alignment = StringAlignment.Near;

                        // Use bold for ArtistName and DiscTrackNumber
                        if (column.FieldName == "ArtistName" || column.FieldName == "DiscTrackNumber")
                            context.DrawText(value, rect, _theme.TextColor, _theme.FontNameBold, _theme.FontSize);
                        else
                            context.DrawText(value, rect, _theme.TextColor, _theme.FontName, _theme.FontSize);
                    }
                }

                state.OffsetX += column.Width;
            }
        }
예제 #9
0
 public static Pen ToPen(BasicPen pen)
 {
     var basicPen = new Pen(ToSolidColorBrush(pen.Brush), pen.Thickness);
     basicPen.Freeze();
     return basicPen;
 }
예제 #10
0
        private void DrawDebugInformation(IGraphicsContext context)
        {
            // Display debug information if enabled
            if (_displayDebugInformation)
            {
                // Build debug string
                var sbDebug = new StringBuilder();
                sbDebug.AppendLine("Line Count: " + _items.Count.ToString());
                sbDebug.AppendLine("Line Height: " + _songCache.LineHeight.ToString());
                sbDebug.AppendLine("Lines Fit In Height: " + _songCache.NumberOfLinesFittingInControl.ToString());
                sbDebug.AppendLine("Total Width: " + _songCache.TotalWidth);
                sbDebug.AppendLine("Total Height: " + _songCache.TotalHeight);
                sbDebug.AppendLine("Scrollbar Offset Y: " + _songCache.ScrollBarOffsetY);
                sbDebug.AppendLine("HScrollbar Maximum: " + HorizontalScrollBar.Maximum.ToString());
                sbDebug.AppendLine("HScrollbar LargeChange: " + HorizontalScrollBar.LargeChange.ToString());
                sbDebug.AppendLine("HScrollbar Value: " + HorizontalScrollBar.Value.ToString());
                sbDebug.AppendLine("VScrollbar Maximum: " + VerticalScrollBar.Maximum.ToString());
                sbDebug.AppendLine("VScrollbar LargeChange: " + VerticalScrollBar.LargeChange.ToString());
                sbDebug.AppendLine("VScrollbar Value: " + VerticalScrollBar.Value.ToString());

                // Measure string
                //stringFormat.Trimming = StringTrimming.Word;
                //stringFormat.LineAlignment = StringAlignment.Near;
                //SizeF sizeDebugText = g.MeasureString(sbDebug.ToString(), fontDefault, _columns[0].Width - 1, stringFormat);
                var sizeDebugText = context.MeasureText(sbDebug.ToString(), new BasicRectangle(0, 0, _columns[0].Width, 40), _theme.FontName, _theme.FontSize);
                var rect = new BasicRectangle(0, 0, _columns[0].Width - 1, sizeDebugText.Height);

                // Draw background
                var brush = new BasicBrush(new BasicColor(200, 0, 0));
                var penTransparent = new BasicPen();
                context.DrawRectangle(rect, brush, penTransparent);

                // Draw string
                context.DrawText(sbDebug.ToString(), rect, new BasicColor(255, 255, 255), _theme.FontName, _theme.FontSize);
            }
        }
예제 #11
0
        private void DrawRows(IGraphicsContext context)
        {
            var state = new DrawCellState();
            BasicGradientBrush brushGradient = null;
            var penTransparent = new BasicPen();    

            // Calculate how many lines must be skipped because of the scrollbar position
            _startLineNumber = Math.Max((int) Math.Floor((double) VerticalScrollBar.Value/(double) (_songCache.LineHeight)), 0);

            // Check if the total number of lines exceeds the number of icons fitting in height
            _numberOfLinesToDraw = 0;
            if (_startLineNumber + _songCache.NumberOfLinesFittingInControl > _items.Count)
            {
                // There aren't enough lines to fill the screen
                _numberOfLinesToDraw = _items.Count - _startLineNumber;
            }
            else
            {
                // Fill up screen 
                _numberOfLinesToDraw = _songCache.NumberOfLinesFittingInControl;
            }

            // Add one line for overflow; however, make sure we aren't adding a line without content 
            if (_startLineNumber + _numberOfLinesToDraw + 1 <= _items.Count)
                _numberOfLinesToDraw++;

            // Loop through lines
            for (int a = _startLineNumber; a < _startLineNumber + _numberOfLinesToDraw; a++)
            {                
                // Calculate offsets, widths and other variants
                state.OffsetX = 0;
                state.OffsetY = (a * _songCache.LineHeight) - VerticalScrollBar.Value + _songCache.LineHeight; // compensate for scrollbar position
                int albumArtColumnWidth = _columns[0].Visible ? _columns[0].Width : 0;
                int lineBackgroundWidth = (int) (Frame.Width + HorizontalScrollBar.Value - albumArtColumnWidth);
                if (VerticalScrollBar.Visible)
                    lineBackgroundWidth -= VerticalScrollBar.Width;

                // Check conditions to determine background color
                var audioFile = _items[a].AudioFile;
                var colorBackground1 = _theme.BackgroundColor;
                var colorBackground2 = _theme.BackgroundColor;
                if ((_mode == SongGridViewMode.AudioFile && audioFile != null && audioFile.Id == _nowPlayingAudioFileId) || 
                    (_mode == SongGridViewMode.Playlist && _items[a].PlaylistItemId == _nowPlayingPlaylistItemId))
                {
                    colorBackground1 = _theme.NowPlayingBackgroundColor;
                    colorBackground2 = _theme.NowPlayingBackgroundColor;
                }

                if (_items[a].IsSelected)
                {
                    colorBackground1 = _theme.SelectedBackgroundColor;
                    colorBackground2 = _theme.SelectedBackgroundColor;

//                    // Use darker color
//                    byte diff = 4;
//                    colorBackground1 = new BasicColor(255,
//                        (byte)((colorBackground1.R - diff < 0) ? 0 : colorBackground1.R - diff),
//                        (byte)((colorBackground1.G - diff < 0) ? 0 : colorBackground1.G - diff),
//                        (byte)((colorBackground1.B - diff < 0) ? 0 : colorBackground1.B - diff));
//                    colorBackground2 = new BasicColor(255,
//                        (byte)((colorBackground2.R - diff < 0) ? 0 : colorBackground2.R - diff),
//                        (byte)((colorBackground2.G - diff < 0) ? 0 : colorBackground2.G - diff),
//                        (byte)((colorBackground2.B - diff < 0) ? 0 : colorBackground2.B - diff));
                }

                //// Check if mouse is over item
                //if (items[a].IsMouseOverItem)
                //{
                //    // Use lighter color
                //    int diff = 20;
                //    colorBackground1 = Color.FromArgb(255,
                //        (colorBackground1.R + diff > 255) ? 255 : colorBackground1.R + diff,
                //        (colorBackground1.G + diff > 255) ? 255 : colorBackground1.G + diff,
                //        (colorBackground1.B + diff > 255) ? 255 : colorBackground1.B + diff);
                //    colorBackground2 = Color.FromArgb(255,
                //        (colorBackground2.R + diff > 255) ? 255 : colorBackground2.R + diff,
                //        (colorBackground2.G + diff > 255) ? 255 : colorBackground2.G + diff,
                //        (colorBackground2.B + diff > 255) ? 255 : colorBackground2.B + diff);
                //}

                //// Check conditions to determine background color
                //if ((_mode == SongGridViewMode.AudioFile && audioFile.Id == _nowPlayingAudioFileId) ||
                //    (_mode == SongGridViewMode.Playlist && _items[a].PlaylistItemId == _nowPlayingPlaylistItemId))
                //{
                //    colorNowPlaying1 = colorBackground1;
                //    colorNowPlaying2 = colorBackground2;
                //}

                // Draw row background
                var rectBackground = new BasicRectangle(albumArtColumnWidth - HorizontalScrollBar.Value, state.OffsetY, lineBackgroundWidth, _songCache.LineHeight + 1);
                brushGradient = new BasicGradientBrush(colorBackground1, colorBackground2, 90);
                context.DrawRectangle(rectBackground, brushGradient, penTransparent);

                // Loop through columns                
                for (int b = 0; b < _songCache.ActiveColumns.Count; b++)
                {
                    DrawCell(context, a, b, audioFile, state);
                }
            }

            // If no songs are playing, set the current now playing rectangle as "empty"
            if (!state.NowPlayingSongFound)
                _rectNowPlaying = new BasicRectangle(0, 0, 1, 1);
        }
예제 #12
0
        private void DrawHeader(IGraphicsContext context)
        {
            var rect = new BasicRectangle();
            var pen = new BasicPen();
            var penTransparent = new BasicPen();
            var brushGradient = new BasicGradientBrush(_theme.HeaderBackgroundColor, _theme.HeaderBackgroundColor, 90);

            // Draw header (for some reason, the Y must be set -1 to cover an area which isn't supposed to be displayed)
            var rectBackgroundHeader = new BasicRectangle(0, -1, Frame.Width, _songCache.LineHeight + 1);
            context.DrawRectangle(rectBackgroundHeader, brushGradient, penTransparent);

            // Loop through columns
            int offsetX = 0;
            for (int b = 0; b < _songCache.ActiveColumns.Count; b++)
            {
                var column = _songCache.ActiveColumns[b];
                if (column.Visible)
                {
                    // The last column always take the remaining width
                    int columnWidth = column.Width;
                    if (b == _songCache.ActiveColumns.Count - 1)
                    {
                        // Calculate the remaining width
                        int columnsWidth = 0;
                        for (int c = 0; c < _songCache.ActiveColumns.Count - 1; c++)
                            columnsWidth += _songCache.ActiveColumns[c].Width;
                        columnWidth = (int) (Frame.Width - columnsWidth + HorizontalScrollBar.Value);
                    }

                    // Check if mouse is over this column header
                    if (column.IsMouseOverColumnHeader)
                    {
                        // Draw header (for some reason, the Y must be set -1 to cover an area which isn't supposed to be displayed)                        
                        rect = new BasicRectangle(offsetX - HorizontalScrollBar.Value, -1, column.Width, _songCache.LineHeight + 1);
                        brushGradient = new BasicGradientBrush(_theme.MouseOverHeaderBackgroundColor, _theme.MouseOverHeaderBackgroundColor, 90);
                        context.DrawRectangle(rect, brushGradient, penTransparent);
                    }
                    else if (column.IsUserMovingColumn)
                    {
                        // Draw header (for some reason, the Y must be set -1 to cover an area which isn't supposed to be displayed)                        
                        rect = new BasicRectangle(offsetX - HorizontalScrollBar.Value, -1, column.Width, _songCache.LineHeight + 1);
                        brushGradient = new BasicGradientBrush(new BasicColor(0, 0, 255), new BasicColor(0, 255, 0), 90);
                        context.DrawRectangle(rect, brushGradient, penTransparent);
                    }

                    // Check if the header title must be displayed
                    if (_songCache.ActiveColumns[b].IsHeaderTitleVisible)
                    {
                        // Display title                
                        var rectTitle = new BasicRectangle(offsetX - HorizontalScrollBar.Value + 2, _theme.Padding / 2, column.Width, _songCache.LineHeight - _theme.Padding + 2);
                        //stringFormat.Trimming = StringTrimming.EllipsisCharacter;
                        context.DrawText(column.Title, rectTitle, _theme.HeaderTextColor, _theme.FontNameBold, _theme.FontSize);
                    }

                    // Draw column separator line; determine the height of the line
                    int columnHeight = (int) Frame.Height;

                    // Determine the height of the line; if the items don't fit the control height...
                    if (_items.Count < _songCache.NumberOfLinesFittingInControl)
                    {
                        // Set height as the number of items (plus header)
                        columnHeight = (_items.Count + 1) * _songCache.LineHeight;
                    }

                    // Draw column line
                    //g.DrawLine(Pens.DarkGray, new Point(offsetX + column.Width - HorizontalScrollBar.Value, 0), new Point(offsetX + column.Width - HorizontalScrollBar.Value, columnHeight));

                    // Check if the column is ordered by
                    if (column.FieldName == _orderByFieldName && !String.IsNullOrEmpty(column.FieldName))
                    {
                        // Create triangle points,,,
                        var ptTriangle = new BasicPoint[3];

                        // ... depending on the order by ascending value
                        int triangleWidthHeight = 8;
                        int trianglePadding = (_songCache.LineHeight - triangleWidthHeight) / 2;
                        if (_orderByAscending)
                        {
                            // Create points for ascending
                            ptTriangle[0] = new BasicPoint(offsetX + column.Width - triangleWidthHeight - (triangleWidthHeight / 2) - HorizontalScrollBar.Value, trianglePadding);
                            ptTriangle[1] = new BasicPoint(offsetX + column.Width - triangleWidthHeight - HorizontalScrollBar.Value, _songCache.LineHeight - trianglePadding);
                            ptTriangle[2] = new BasicPoint(offsetX + column.Width - triangleWidthHeight - triangleWidthHeight - HorizontalScrollBar.Value, _songCache.LineHeight - trianglePadding);
                        }
                        else
                        {
                            // Create points for descending
                            ptTriangle[0] = new BasicPoint(offsetX + column.Width - triangleWidthHeight - (triangleWidthHeight / 2) - HorizontalScrollBar.Value, _songCache.LineHeight - trianglePadding);
                            ptTriangle[1] = new BasicPoint(offsetX + column.Width - triangleWidthHeight - HorizontalScrollBar.Value, trianglePadding);
                            ptTriangle[2] = new BasicPoint(offsetX + column.Width - triangleWidthHeight - triangleWidthHeight - HorizontalScrollBar.Value, trianglePadding);
                        }

                        // Draw triangle
                        pen = new BasicPen(new BasicBrush(new BasicColor(255, 0, 0)), 1);
                    }

                    // Increment offset by the column width
                    offsetX += column.Width;
                }
            }

            // Display column move marker
            if (IsColumnMoving)
            {
                // Draw marker
                pen = new BasicPen(new BasicBrush(new BasicColor(255, 0, 0)), 1);
                context.DrawRectangle(new BasicRectangle(_columnMoveMarkerX - HorizontalScrollBar.Value, 0, 1, Frame.Height), new BasicBrush(), pen);
            }
        }
예제 #13
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);
            }
        }
예제 #14
0
		public void SetPen(BasicPen pen)
		{
			Context.SetStrokeColor(GenericControlHelper.ToColor(pen.Brush.Color).CGColor);
			Context.SetLineWidth(pen.Thickness);
		}
예제 #15
0
 public void DrawPath(BasicPath path, BasicBrush brush, BasicPen pen)
 {
     throw new NotImplementedException();
 }
예제 #16
0
        private void RequestBitmapInternal(Object stateInfo)
        {
            // Use this instead of a task, this guarantees to execute in another thread
            //Console.WriteLine("WaveFormRenderingService - RequestBitmap - boundsBitmap: {0} boundsWaveForm: {1} zoom: {2}", boundsBitmap, boundsWaveForm, zoom);
            var request = stateInfo as WaveFormBitmapRequest;
            IMemoryGraphicsContext context;
            try
            {
                //Console.WriteLine("WaveFormRenderingService - Creating image cache...");
                context = _memoryGraphicsContextFactory.CreateMemoryGraphicsContext(request.BoundsBitmap.Width, request.BoundsBitmap.Height);
                if (context == null)
                {
                    Console.WriteLine("Error initializing image cache context!");
					return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while creating image cache context: " + ex.Message);
                return;
            }

			IBasicImage imageCache;
			try
			{
			    float x1 = 0;
                float x2 = 0;
                float leftMin = 0;
                float leftMax = 0;
                float rightMin = 0;
                float rightMax = 0;
                float mixMin = 0;
                float mixMax = 0;
                int historyIndex = 0;
                int historyCount = _waveDataCache.Count;
                float lineWidth = 0;
                int nHistoryItemsPerLine = 0;
                const float desiredLineWidth = 0.5f;
                WaveDataMinMax[] subset = null;

                // Find out how many samples are represented by each line of the wave form, depending on its width.
                // For example, if the history has 45000 items, and the control has a width of 1000px, 45 items will need to be averaged by line.
                float lineWidthPerHistoryItem = request.BoundsWaveForm.Width / (float)historyCount;

                // Check if the line width is below the desired line width
                if (lineWidthPerHistoryItem < desiredLineWidth)
                {
                    // Try to get a line width around 0.5f so the precision is good enough and no artifacts will be shown.
                    while (lineWidth < desiredLineWidth)
                    {
                        // Increment the number of history items per line
                        //Console.WriteLine("Determining line width (lineWidth: " + lineWidth.ToString() + " desiredLineWidth: " + desiredLineWidth.ToString() + " nHistoryItemsPerLine: " + nHistoryItemsPerLine.ToString() + " lineWidthPerHistoryItem: " + lineWidthPerHistoryItem.ToString());
                        nHistoryItemsPerLine++;
                        lineWidth += lineWidthPerHistoryItem;
                    }
                    nHistoryItemsPerLine--;
                    lineWidth -= lineWidthPerHistoryItem;
                }
                else
                {
                    // The lines are larger than 0.5 pixels.
                    lineWidth = lineWidthPerHistoryItem;
                    nHistoryItemsPerLine = 1;
                }

                float heightToRenderLine = 0;
                if (request.DisplayType == WaveFormDisplayType.Stereo)
                    heightToRenderLine = (request.BoundsWaveForm.Height / 4);
                else
                    heightToRenderLine = (request.BoundsWaveForm.Height / 2);

                context.DrawRectangle(new BasicRectangle(0, 0, request.BoundsBitmap.Width + 2, request.BoundsBitmap.Height), _brushBackground, _penTransparent);

                // The pen cannot be cached between refreshes because the line width changes every time the width changes
                //context.SetLineWidth(0.2f);
                var penWaveForm = new BasicPen(new BasicBrush(_colorWaveForm), lineWidth);
                context.SetPen(penWaveForm);

                float startLine = ((int)Math.Floor(request.BoundsBitmap.X / lineWidth)) * lineWidth;
                historyIndex = (int) ((startLine / lineWidth) * nHistoryItemsPerLine);

                //Console.WriteLine("WaveFormRenderingService - startLine: {0} boundsWaveForm.Width: {1} nHistoryItemsPerLine: {2} historyIndex: {3}", startLine, boundsWaveForm.Width, nHistoryItemsPerLine, historyIndex);
                //List<float> roundValues = new List<float>();
                float lastLine = startLine + request.BoundsBitmap.Width;
                if (request.BoundsWaveForm.Width - request.BoundsBitmap.X < request.BoundsBitmap.Width)
                    lastLine = request.BoundsWaveForm.Width;

                //context.DrawText(string.Format("{0:0.0}", startLine), new BasicPoint(1, request.BoundsBitmap.Height - 10), new BasicColor(255, 255, 255), "Roboto Bold", 10 * context.Density);
                //context.DrawText(string.Format("{0:0.0}", lastLine), new BasicPoint(1, request.BoundsBitmap.Height - 22), new BasicColor(255, 255, 255), "Roboto Bold", 10 * context.Density);
                //context.DrawText(string.Format("{0:0.0}", request.BoundsBitmap.X), new BasicPoint(1, request.BoundsBitmap.Height - 34), new BasicColor(255, 255, 255), "Roboto Bold", 10 * context.Density);
                //context.DrawText(string.Format("{0:0.0}", request.BoundsWaveForm.Width), new BasicPoint(1, request.BoundsBitmap.Height - 46), new BasicColor(255, 255, 255), "Roboto Bold", 10 * context.Density);
                //context.DrawText(string.Format("{0}", request.BoundsBitmap.X), new BasicPoint(1, request.BoundsBitmap.Height - 20), new BasicColor(255, 255, 255), "Roboto Bold", 10 * context.Density);
                //context.DrawText(string.Format("{0:0.0}", request.Zoom), new BasicPoint(1, request.BoundsBitmap.Height - 10), new BasicColor(255, 255, 255), "Roboto Bold", 10 * context.Density);

                for (float i = startLine; i < lastLine; i += lineWidth)
                {
                    #if MACOSX
                    // On Mac, the pen needs to be set every time we draw or the color might change to black randomly (weird?)
                    context.SetPen(penWaveForm);
                    #endif

                    // COMMENTED possible solution for varying line widths rendering problem
                    // Round to 0.5
                    //i = (float)Math.Round(i * 2) / 2;
                    //float iRound = (float)Math.Round(i);
                    //float iRound = (float)Math.Round(i * 2) / 2;
                    //float iRound = (float)Math.Round(i * 4) / 4;

                    //                        // If this value has already been drawn, skip it (this happens because of the rounding, and this fixes a visual bug)
                    //                        if(roundValues.Contains(iRound))
                    //                        {
                    //                            // Increment the history index; pad the last values if the count is about to exceed
                    //                            if (historyIndex < historyCount - 1)
                    //                                historyIndex += nHistoryItemsPerLine;                         
                    //                            continue;
                    //                        }
                    //                        else
                    //                        {
                    //                            roundValues.Add(iRound);
                    //                        }

                    // Determine the maximum height of a line (+/-)
                    //Console.WriteLine("WaveForm - Rendering " + i.ToString() + " (rnd=" + iRound.ToString() + ") on " + widthAvailable.ToString());

                    // Determine x position
                    //                        x1 = iRound; //i;
                    //                        x2 = iRound; //i;
                    x1 = i - startLine;
                    x2 = i - startLine;
                    if (nHistoryItemsPerLine > 1)
                    {
                        if (historyIndex + nHistoryItemsPerLine > historyCount)
                        {
                            // Create subset with remaining data
                            subset = new WaveDataMinMax[historyCount - historyIndex];
                            _waveDataCache.CopyTo(historyIndex, subset, 0, historyCount - historyIndex);
                        }
                        else
                        {
                            subset = new WaveDataMinMax[nHistoryItemsPerLine];
                            _waveDataCache.CopyTo(historyIndex, subset, 0, nHistoryItemsPerLine);
                        }

                        leftMin = AudioTools.GetMinPeakFromWaveDataMaxHistory(subset.ToList(), nHistoryItemsPerLine, ChannelType.Left);
                        leftMax = AudioTools.GetMaxPeakFromWaveDataMaxHistory(subset.ToList(), nHistoryItemsPerLine, ChannelType.Left);
                        rightMin = AudioTools.GetMinPeakFromWaveDataMaxHistory(subset.ToList(), nHistoryItemsPerLine, ChannelType.Right);
                        rightMax = AudioTools.GetMaxPeakFromWaveDataMaxHistory(subset.ToList(), nHistoryItemsPerLine, ChannelType.Right);
                        mixMin = AudioTools.GetMinPeakFromWaveDataMaxHistory(subset.ToList(), nHistoryItemsPerLine, ChannelType.Mix);
                        mixMax = AudioTools.GetMaxPeakFromWaveDataMaxHistory(subset.ToList(), nHistoryItemsPerLine, ChannelType.Mix);
                    }
                    else
                    {
                        leftMin = _waveDataCache[historyIndex].leftMin;
                        leftMax = _waveDataCache[historyIndex].leftMax;
                        rightMin = _waveDataCache[historyIndex].rightMin;
                        rightMax = _waveDataCache[historyIndex].rightMax;
                        mixMin = _waveDataCache[historyIndex].mixMin;
                        mixMax = _waveDataCache[historyIndex].mixMax;
                    }

                    float leftMaxHeight = leftMax * heightToRenderLine;
                    float leftMinHeight = leftMin * heightToRenderLine;
                    float rightMaxHeight = rightMax * heightToRenderLine;
                    float rightMinHeight = rightMin * heightToRenderLine;
                    float mixMaxHeight = mixMax * heightToRenderLine;
                    float mixMinHeight = mixMin * heightToRenderLine;

                    //Console.WriteLine("WaveFormRenderingService - line: {0} x1: {1} x2: {2} historyIndex: {3} historyCount: {4} width: {5}", i, x1, x2, historyIndex, historyCount, boundsWaveForm.Width);
                    if (request.DisplayType == WaveFormDisplayType.LeftChannel ||
                        request.DisplayType == WaveFormDisplayType.RightChannel ||
                        request.DisplayType == WaveFormDisplayType.Mix)
                    {
                        // Calculate min/max line height
                        float minLineHeight = 0;
                        float maxLineHeight = 0;

                        // Set mib/max
                        if (request.DisplayType == WaveFormDisplayType.LeftChannel)
                        {
                            minLineHeight = leftMinHeight;
                            maxLineHeight = leftMaxHeight;
                        }
                        else if (request.DisplayType == WaveFormDisplayType.RightChannel)
                        {
                            minLineHeight = rightMinHeight;
                            maxLineHeight = rightMaxHeight;
                        }
                        else if (request.DisplayType == WaveFormDisplayType.Mix)
                        {
                            minLineHeight = mixMinHeight;
                            maxLineHeight = mixMaxHeight;
                        }

                        // Positive Max Value - Draw positive value (y: middle to top)                   
						context.StrokeLine(new BasicPoint(x1, heightToRenderLine), new BasicPoint(x2, heightToRenderLine - maxLineHeight));
                        // Negative Max Value - Draw negative value (y: middle to height)
						context.StrokeLine(new BasicPoint(x1, heightToRenderLine), new BasicPoint(x2, heightToRenderLine + (-minLineHeight)));
                    }
                    else if (request.DisplayType == WaveFormDisplayType.Stereo)
                    {
                        // LEFT Channel - Positive Max Value - Draw positive value (y: middle to top)
                        context.StrokeLine(new BasicPoint(x1, heightToRenderLine), new BasicPoint(x2, heightToRenderLine - leftMaxHeight));
                        // LEFT Channel - Negative Max Value - Draw negative value (y: middle to height)
                        context.StrokeLine(new BasicPoint(x1, heightToRenderLine), new BasicPoint(x2, heightToRenderLine + (-leftMinHeight)));
                        // RIGHT Channel - Positive Max Value (Multiply by 3 to get the new center line for right channel) - Draw positive value (y: middle to top)
                        context.StrokeLine(new BasicPoint(x1, (heightToRenderLine * 3)), new BasicPoint(x2, (heightToRenderLine * 3) - rightMaxHeight));
                        // RIGHT Channel - Negative Max Value - Draw negative value (y: middle to height)
                        context.StrokeLine(new BasicPoint(x1, (heightToRenderLine * 3)), new BasicPoint(x2, (heightToRenderLine * 3) + (-rightMinHeight)));
                    }

                    // Increment the history index; pad the last values if the count is about to exceed
                    if (historyIndex < historyCount - 1)
                        historyIndex += nHistoryItemsPerLine;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while creating image cache: " + ex.Message);
            }
            finally
            {
                // Get image from context (at this point, we are sure the image context has been initialized properly)
				//Console.WriteLine("WaveFormRenderingService - Rendering image to memory...");
                context.Close();
                imageCache = context.RenderToImageInMemory();
            }

			//Console.WriteLine("WaveFormRenderingService - Created image successfully.");
            //stopwatch.Stop();
            //Console.WriteLine("WaveFormRenderingService - Created image successfully in {0} ms.", stopwatch.ElapsedMilliseconds);
			OnGenerateWaveFormBitmapEnded(new GenerateWaveFormEventArgs()
			{
				//AudioFilePath = audioFile.FilePath,
                OffsetX = request.BoundsBitmap.X,
				Zoom = request.Zoom,
                Width = context.BoundsWidth,
				DisplayType = request.DisplayType,
				Image = imageCache
			});
        }
예제 #17
0
 public void SetPen(BasicPen pen)
 {
     _currentPen = GenericControlHelper.ToPen(pen);
 }
예제 #18
0
 private void CreateDrawingResources()
 {
     _penTransparent = new BasicPen();
     _brushBackground = new BasicBrush(_colorBackground);
 }
예제 #19
0
        public void DrawRectangle(BasicRectangle rectangle, BasicBrush brush, BasicPen pen)
        {
            if(brush is BasicGradientBrush)
                _context.DrawRectangle(GenericControlHelper.ToLinearGradientBrush((BasicGradientBrush)brush), GenericControlHelper.ToPen(pen), GenericControlHelper.ToRect(rectangle));

            _context.DrawRectangle(GenericControlHelper.ToSolidColorBrush(brush), GenericControlHelper.ToPen(pen), GenericControlHelper.ToRect(rectangle));
        }
예제 #20
0
        private void CreateDrawingResources()
        {
            FontSize = 12;
            FontFace = "Roboto Light";
            LetterFontSize = 10;
            LetterFontFace = "Roboto";
            Frame = new BasicRectangle();

            _penTransparent = new BasicPen();
            _penCursorLine = new BasicPen(new BasicBrush(_cursorColor), 1);
            _penSecondaryCursorLine = new BasicPen(new BasicBrush(_secondaryCursorColor), 1);
            _penMarkerLine = new BasicPen(new BasicBrush(_markerCursorColor), 1);
            _penLoopLine = new BasicPen(new BasicBrush(_loopCursorColor), 1);
            _penSelectedMarkerLine = new BasicPen(new BasicBrush(_markerSelectedCursorColor), 1);
            _brushLoopBackground = new BasicBrush(_loopBackgroundColor);
            _brushMarkerBackground = new BasicBrush(_markerBackgroundColor);
            _brushSelectedMarkerBackground = new BasicBrush(_markerSelectedCursorColor);
        }
예제 #21
0
 public void DrawEllipsis(BasicRectangle rectangle, BasicBrush brush, BasicPen pen)
 {            
 }
예제 #22
0
 public void DrawRectangle(BasicRectangle rectangle, BasicBrush brush, BasicPen pen)
 {
     // TODO: Add outline
     var paint = new Paint
     {
         AntiAlias = true,
         Color = GenericControlHelper.ToColor(brush.Color)
     };
     paint.SetStyle(Paint.Style.Fill);
     if (brush is BasicGradientBrush)
     {
         var gradientBrush = (BasicGradientBrush) brush;
         paint.SetShader(new LinearGradient(gradientBrush.StartPoint.X, gradientBrush.StartPoint.Y, gradientBrush.EndPoint.X, gradientBrush.EndPoint.Y, GenericControlHelper.ToColor(gradientBrush.Color2), GenericControlHelper.ToColor(gradientBrush.Color), Shader.TileMode.Mirror));
     }
     _canvas.DrawRect(GenericControlHelper.ToRect(rectangle), paint);
 }
예제 #23
0
 public void DrawRectangle(BasicRectangle rectangle, BasicBrush brush, BasicPen pen)
 {
     _context.SetSourceRGB(brush.Color.R / 255f, brush.Color.G / 255f, brush.Color.B / 255f);
     _context.Rectangle(GenericControlHelper.ToRect(rectangle));
     _context.Fill();
 }
예제 #24
0
 public void DrawLine(BasicPoint point, BasicPoint point2, BasicPen pen)
 {
     var paint = new Paint
     {
         AntiAlias = true,
         Color = GenericControlHelper.ToColor(pen.Brush.Color),
         StrokeWidth = pen.Thickness * Density
     };
     paint.SetStyle(Paint.Style.Fill);
     _canvas.DrawLine(point.X, point.Y, point2.X, point2.Y, paint);
 }
예제 #25
0
		public void SetPen(BasicPen pen)
		{
		}
예제 #26
0
 public void SetPen(BasicPen pen)
 {
     TryToCreatePaint();
     _currentPaint.Color = GenericControlHelper.ToColor(pen.Brush.Color);
     _currentPaint.StrokeWidth = pen.Thickness;
 }
예제 #27
0
 private void CreateDrawingResources()
 {
     _penTransparent = new BasicPen();
     _penMiddleLineColor = new BasicPen(new BasicBrush(_faderMiddleLineColor), 1);
     _brushBackground = new BasicBrush(_backgroundColor);
     _brushFaderShadowColor = new BasicBrush(_faderShadowColor);
     _brushFaderGradient = new BasicGradientBrush(_faderColor1, _faderColor2, 90);
     _brushFaderColor2 = new BasicBrush(_faderColor2);
     _brushFaderShadowColor1 = new BasicBrush(_faderShadowColor1);
     _brushFaderShadowGradient = new BasicGradientBrush(_faderShadowColor1, _faderShadowColor2, 90);
 }
예제 #28
0
 private void CreateDrawingResources()
 {
     ColorBackground = new BasicColor(32, 40, 46);
     ColorForeground = new BasicColor(230, 237, 242);//174, 196, 212);
     ColorBorder = new BasicColor(83, 104, 119);
     _brushBackground = new BasicBrush(ColorBackground);
     _brushForeground = new BasicBrush(ColorForeground);
     _brushBorder = new BasicBrush(ColorBorder);
     _brushTransparent = new BasicBrush(new BasicColor(0, 0, 0, 0));
     _penBorder = new BasicPen(_brushBorder, 2);
     _penForeground = new BasicPen(_brushForeground, 2);
     _penTransparent = new BasicPen();
 }
예제 #29
0
        public void Render(IGraphicsContext context)
        {
            lock (_locker)
            {
                if (_brushBackground == null)
                {
                    _brushBackground = new BasicBrush(_backgroundColor);
                    _penTransparent = new BasicPen();
                    _penBorder = new BasicPen(new BasicBrush(_borderColor), 1);
                    _rectText = context.MeasureText("12345:678.90", new BasicRectangle(0, 0, Frame.Width, Frame.Height), "HelveticaNeue", 10);
                }
            }

            _density = context.Density;
            Frame = new BasicRectangle(0, 0, context.BoundsWidth, context.BoundsHeight);
            context.DrawRectangle(new BasicRectangle(0, 0, context.BoundsWidth, context.BoundsHeight), _brushBackground, _penTransparent);
            if (_audioFile == null || _audioFileLength == 0)
                return;

            // Check if scale type needs to be updated
            if (_lastWidth != ContentSize.Width)
            {
                _lastWidth = ContentSize.Width;
                CalculateScale(context.Density);
            }

            // Draw scale borders
            //Console.WriteLine("WaveFormScaleView - scaleType: {0} totalMinutes: {1} totalSeconds: {2} totalMinutesScaled: {3} totalSecondsScaled: {4}", scaleType.ToString(), totalMinutes, totalSeconds, totalMinutesScaled, totalSecondsScaled);
            context.SetPen(_penBorder);
            context.StrokeLine(new BasicPoint(0, ContentSize.Height - 1), new BasicPoint(ContentSize.Width, ContentSize.Height - 1));

            int firstVisibleIndex = (int)Math.Floor(ContentOffset.X / _tickWidth);
            int lastVisibleIndex = firstVisibleIndex + (int)Math.Floor(context.BoundsWidth / _tickWidth);
            float tickX = -ContentOffset.X + (firstVisibleIndex * _tickWidth);
            int majorTickIndex = (int)Math.Ceiling(firstVisibleIndex / 10f);
            //for (int a = firstVisibleIndex; a < _tickCount; a++)
            for (int a = firstVisibleIndex; a < lastVisibleIndex; a++)
            {
                // Ignore ticks out of bounds
                bool isMajorTick = ((a % 10) == 0);
                if (tickX >= 0 && tickX <= Frame.Width)
                {
                    //Console.WriteLine("####> WaveFormView - Scale - tick {0} x: {1} isMajorTick: {2} tickCount: {3}", a, tickX, isMajorTick, tickCount);

                    if(isMajorTick)
                        //    //context.DrawLine(new BasicPoint(tickX, context.BoundsHeight - (context.BoundsHeight / 1.25f)), new BasicPoint(tickX, context.BoundsHeight), _penMajorTick);
                        context.StrokeLine(new BasicPoint(tickX, 0), new BasicPoint(tickX, ContentSize.Height - 1));
                    else
                        context.StrokeLine(new BasicPoint(tickX, ContentSize.Height - (ContentSize.Height / 6) - 1), new BasicPoint(tickX, ContentSize.Height - 1));

                    if (isMajorTick)
                    {
                        // Draw dashed traversal line for major ticks
                        context.StrokeLine(new BasicPoint(tickX, ContentSize.Height - 1), new BasicPoint(tickX, ContentSize.Height - 1));

                        // Determine major scale text
                        int minutes = 0;
                        int seconds = 0;
                        switch (_scaleType)
                        {
                            case WaveFormScaleType._10minutes:
                                minutes = majorTickIndex * 10;
                                seconds = 0;
                                break;
                            case WaveFormScaleType._5minutes:
                                minutes = majorTickIndex * 5;
                                seconds = 0;
                                break;
                            case WaveFormScaleType._2minutes:
                                minutes = majorTickIndex * 2;
                                seconds = 0;
                                break;
                            case WaveFormScaleType._1minute:
                                minutes = majorTickIndex;
                                seconds = 0;
                                break;
                            case WaveFormScaleType._30seconds:
                                minutes = (int)Math.Floor(majorTickIndex / _scaleMultiplier);
                                seconds = (majorTickIndex % _scaleMultiplier == 0) ? 0 : 30;
                                break;
                            case WaveFormScaleType._10seconds:
                                minutes = (int)Math.Floor(majorTickIndex / _scaleMultiplier);
                                seconds = ((int)Math.Floor(majorTickIndex % _scaleMultiplier)) * 10;
                                break;
                            case WaveFormScaleType._5seconds:
                                minutes = (int)Math.Floor(majorTickIndex / _scaleMultiplier);
                                seconds = ((int)Math.Floor(majorTickIndex % _scaleMultiplier)) * 5;
                                break;
                            case WaveFormScaleType._1second:
                                minutes = (int)Math.Floor(majorTickIndex / _scaleMultiplier);
                                seconds = (int)Math.Floor(majorTickIndex % _scaleMultiplier);
                                break;
                        }

                        // Draw text at every major tick (minute count)
                        string scaleMajorTitle = string.Format("{0}:{1:00}", minutes, seconds);                    
                        //float y = ContentSize.Height - (ContentSize.Height/12f) - _rectText.Height - (0.5f * context.Density);                    
                        float y = 3 * context.Density;//ContentSize.Height - _rectText.Height - (10 * context.Density); 
						context.DrawText(scaleMajorTitle, new BasicPoint(tickX + (4 * context.Density), y), _textColor, FontFace, FontSize);
                    }
                }
                
                if(isMajorTick)
                    majorTickIndex++;

                tickX += _tickWidth;
            }
        }
예제 #30
0
		public void DrawRectangle(BasicRectangle rectangle, BasicBrush brush, BasicPen pen)
		{
			CoreGraphicsHelper.FillRect(Context, GenericControlHelper.ToRect(rectangle), GenericControlHelper.ToColor(brush.Color).CGColor);
			// TODO: Add outline
		}