예제 #1
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            double       actualWidth  = this.ActualWidth;
            double       actualHeight = this.ActualHeight;
            UIElement    uiElement    = this.Parent as UIElement;
            DrawingBrush drawingBrush;

            if (this.ActiveTool != null && uiElement != null)
            {
                drawingBrush = this.ActiveTool.NormalIconBrush;
                if (uiElement.IsMouseOver || this.IsChecked.HasValue && this.IsChecked.Value)
                {
                    drawingBrush = this.ActiveTool.HoverIconBrush;
                }
            }
            else
            {
                drawingBrush = IconMapper.GetDrawingBrushForType(PlatformTypes.Object, false, 24, 24);
            }
            Rect rectangle = new Rect(new Point((double)(((int)actualWidth - 24) / 2), (double)(((int)actualHeight - 24) / 2)), new Size(24.0, 24.0));

            if (drawingBrush != null)
            {
                drawingContext.DrawRectangle((Brush)drawingBrush, (Pen)null, rectangle);
            }
            if (this.ToolCount <= 1)
            {
                return;
            }
            double                x = actualWidth - 1.0;
            double                y = actualHeight - 1.0;
            StreamGeometry        streamGeometry        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.BeginFigure(new Point(x, y), true, true);
            streamGeometryContext.LineTo(new Point(x - 5.0, y), false, false);
            streamGeometryContext.LineTo(new Point(x, y - 5.0), false, false);
            streamGeometryContext.Close();
            streamGeometry.Freeze();
            drawingContext.DrawGeometry(this.ExpansionTriangleBrush, (Pen)null, (System.Windows.Media.Geometry)streamGeometry);
        }
예제 #2
0
        public static DrawingBrush GetDrawingBrushForType(ITypeId type, bool selected, int requestedWidth, int requestedHeight)
        {
            IType type1 = type as IType;

            if (type1 != null)
            {
                List <IconMapper.CachedBrush> list;
                if (!IconMapper.ExtensibleIconCache.TryGetValue(type1.RuntimeType, out list))
                {
                    list = new List <IconMapper.CachedBrush>(1);
                    IconMapper.ExtensibleIconCache.Add(type1.RuntimeType, list);
                }
                bool flag = false;
                foreach (IconMapper.CachedBrush cachedBrush in list)
                {
                    if (cachedBrush.Width == requestedWidth && cachedBrush.Height == requestedHeight)
                    {
                        if (cachedBrush.Brush != null)
                        {
                            return(cachedBrush.Brush);
                        }
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    string resourceName;
                    Stream drawingBrushStream = IconMapper.GetExtensibleDrawingBrushStream(type1.RuntimeType, requestedWidth, requestedHeight, out resourceName);
                    if (drawingBrushStream != null)
                    {
                        DrawingBrush drawingBrushFromStream = IconMapper.CreateDrawingBrushFromStream(drawingBrushStream, resourceName);
                        list.Add(new IconMapper.CachedBrush(requestedWidth, requestedHeight, drawingBrushFromStream));
                        return(drawingBrushFromStream);
                    }
                    list.Add(new IconMapper.CachedBrush(requestedWidth, requestedHeight, (DrawingBrush)null));
                }
            }
            string str1;

            if (!IconMapper.TypeMap.TryGetValue(type.FullName, out str1) && type1 != null)
            {
                Type type2 = type1.RuntimeType;
                while (type2 != (Type)null && !IconMapper.TypeMap.TryGetValue(type2.FullName, out str1))
                {
                    type2 = type2.BaseType;
                    if (type2 == (Type)null)
                    {
                        type2 = type1.PlatformMetadata.ResolveType(PlatformTypes.Object).RuntimeType;
                    }
                }
            }
            if (string.IsNullOrEmpty(str1))
            {
                str1 = "element";
            }
            bool         flag1        = requestedWidth == 12 && requestedHeight == 12;
            string       str2         = flag1 ? "_12x12" : "_24x24";
            string       str3         = selected ? "_on" : "_off";
            string       str4         = "asset_" + str1 + str3;
            string       str5         = str4 + str2;
            DrawingBrush drawingBrush = IconMapper.FindDrawingBrush(str5);

            if (drawingBrush == null && flag1)
            {
                drawingBrush = IconMapper.FindDrawingBrush(str4 + "_24x24");
                IconMapper.IconCache.Add(str5, drawingBrush);
            }
            return(drawingBrush);
        }