当前位置: 首页>>代码示例>>C#>>正文


C# Rect.OffsetTo方法代码示例

本文整理汇总了C#中Android.Graphics.Rect.OffsetTo方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.OffsetTo方法的具体用法?C# Rect.OffsetTo怎么用?C# Rect.OffsetTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Graphics.Rect的用法示例。


在下文中一共展示了Rect.OffsetTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: drawPlaces

        private void drawPlaces(Canvas canvas, double pixelsPerDegree, double offset) 
        {
            try
            {
                if (OrientationManager.HasLocation && NearbyPlaces != null)
                {
                    lock (NearbyPlaces)
                    {
                        var userLocation = OrientationManager.Location;
                        var latitude1 = userLocation.Latitude;
                        var longitude1 = userLocation.Longitude;

                        _allBounds.Clear();


                        // Loop over the list of nearby places (those within 10 km of the user's current
                        // location), and compute the relative bearing from the user's location to the
                        // place's location. This determines the position on the compass view where the
                        // pin will be drawn.
                        foreach (var place in NearbyPlaces)
                        {
                            var latitude2 = place.Latitiude;
                            var longitude2 = place.Longitude;
                            var bearing = MathUtils.getBearing(latitude1, longitude1, latitude2, longitude2);

                            var name = place.Name;
                            var distanceKm = MathUtils.getDistance(latitude1, longitude1, latitude2, longitude2);
                            var text = this.Context.Resources.GetString(
                                Resource.String.place_text_format, name, _distanceFormat.Format(distanceKm));

                            // Measure the text and offset the text bounds to the location where the text
                            // will finally be drawn.
                            var textBounds = new Rect();
                            _placePaint.GetTextBounds(text, 0, text.Length, textBounds);
                            textBounds.OffsetTo((int)(offset + bearing * pixelsPerDegree
                                    + PLACE_PIN_WIDTH / 2 + PLACE_TEXT_MARGIN), canvas.Height / 2
                                    - (int)PLACE_TEXT_HEIGHT);

                            // Extend the bounds rectangle to include the pin icon and a small margin
                            // to the right of the text, for the overlap calculations below.
                            textBounds.Left -= (int)(PLACE_PIN_WIDTH + PLACE_TEXT_MARGIN);
                            textBounds.Right += (int)PLACE_TEXT_MARGIN;

                            // This loop attempts to find the best vertical position for the string by
                            // starting at the bottom of the display and checking to see if it overlaps
                            // with any other labels that were already drawn. If there is an overlap, we
                            // move up and check again, repeating this process until we find a vertical
                            // position where there is no overlap, or when we reach the limit on
                            // overlapping place names.
                            bool intersects;
                            var numberOfTries = 0;
                            do
                            {
                                intersects = false;
                                numberOfTries++;
                                textBounds.Offset(0, (int)-(PLACE_TEXT_HEIGHT + PLACE_TEXT_LEADING));

                                foreach (var existing in _allBounds)
                                {
                                    if (Rect.Intersects(existing, textBounds))
                                    {
                                        intersects = true;
                                        break;
                                    }
                                }
                            } while (intersects && numberOfTries <= MAX_OVERLAPPING_PLACE_NAMES);

                            // Only draw the string if it would not go high enough to overlap the compass
                            // directions. This means some places may not be drawn, even if they're nearby.
                            if (numberOfTries <= MAX_OVERLAPPING_PLACE_NAMES)
                            {
                                _allBounds.Add(textBounds);

                                canvas.DrawBitmap(_placeBitmap, (float)(offset + bearing * pixelsPerDegree - PLACE_PIN_WIDTH / 2), textBounds.Top + 2, _paint);
                                canvas.DrawText(
                                    text,
                                    (float)(offset + bearing * pixelsPerDegree + PLACE_PIN_WIDTH / 2 + PLACE_TEXT_MARGIN),
                                    (float)(textBounds.Top + PLACE_TEXT_HEIGHT),
                                    _placePaint);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Debug("Exception", e.Message);
            }
        }
开发者ID:42Spikes,项目名称:F2S,代码行数:89,代码来源:CompassView.cs


注:本文中的Android.Graphics.Rect.OffsetTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。