Exemplo n.º 1
0
        public static ImageSource GetImage(LineCapExtension join, bool isForEndCap)
        {
            const int    bmpHeight = 24;
            const int    bmpWidth  = 48;
            const double lineWidth = bmpHeight * 0.4;

            if (null == _interopBitmap)
            {
                _interopBitmap = new GdiToWpfBitmap(bmpWidth, bmpHeight);
            }

            using (var grfx = _interopBitmap.BeginGdiPainting())
            {
                grfx.CompositingMode = sdd.CompositingMode.SourceCopy;
                grfx.FillRectangle(System.Drawing.Brushes.Transparent, 0, 0, bmpWidth, bmpHeight);

                var linePen = new System.Drawing.Pen(System.Drawing.Brushes.Black, (float)Math.Ceiling(lineWidth));
                if (isForEndCap)
                {
                    join.SetEndCap(linePen);
                    grfx.DrawLine(linePen, 0, 0.5f * bmpHeight, bmpWidth * (1 - 0.25f), 0.5f * bmpHeight);
                }
                else
                {
                    join.SetStartCap(linePen);
                    grfx.DrawLine(linePen, 0.25f * bmpWidth, 0.5f * bmpHeight, bmpWidth, 0.5f * bmpHeight);
                }
                _interopBitmap.EndGdiPainting();
            }

            var img = new WriteableBitmap(_interopBitmap.WpfBitmap);

            img.Freeze();
            return(img);
        }
Exemplo n.º 2
0
 private void SetDefaultValues()
 {
     foreach (LineCapExtension cap in LineCapExtension.GetRegisteredValues())
     {
         var item = new ImageComboBoxItem(this, cap);
         _cachedItems.Add(cap.Name, item);
         Items.Add(item);
     }
 }
Exemplo n.º 3
0
		/// <summary>
		/// Copies the properties of another instance to this instance.
		/// </summary>
		/// <param name="pen">the PenHolder object to copy</param>
		public void CopyFrom(PenX pen)
		{
			if (object.ReferenceEquals(this, pen))
				return;

			_SetPenVariable(null);

			this._configuredProperties = pen._configuredProperties;
			this._penType = pen.PenType;
			this._alignment = pen.Alignment;

			if (0 != (this._configuredProperties & Configured.Brush))
				this._brush = new BrushX(pen._brush);

			this._color = pen.Color;

			if (null != pen._compoundArray)
				this._compoundArray = (float[])pen.CompoundArray.Clone();
			else
				this._compoundArray = null;

			this._dashPattern = pen._dashPattern; // immutable
			this._dashCap = pen._dashCap;

			this._cachedDashStyle = pen._cachedDashStyle;

			if (null != pen._cachedDashPattern)
				this._cachedDashPattern = (float[])pen._cachedDashPattern.Clone();
			else
				this._cachedDashPattern = null;

			this._cachedDashOffset = pen._cachedDashOffset;

			this._endCap = pen.EndCap;
			this._lineJoin = pen.LineJoin;
			this._miterLimit = pen.MiterLimit;
			this._startCap = pen.StartCap;

			if (null != pen._transformation)
				this._transformation = pen.Transform.Clone();
			else
				this._transformation = null;

			this._width = pen.Width;

			// note: there is an problem with Pen.Clone() : if the Color of the pen
			// was set to a known color, the color of the cloned pen is the same, but no longer a known color
			// therefore we avoid the cloning of the pen here

			// if(m_CachedMode && null!=pen.m_Pen)
			//   _SetPenVariable( (Pen)pen.m_Pen.Clone() );
			// else
			//   _SetPenVariable(null);
		}
Exemplo n.º 4
0
		public PenX(NamedColor c, double width, bool bCachedMode)
		{
			this._penType = PenType.SolidColor;
			_dashPattern = DashPatternListManager.Instance.BuiltinDefaultSolid;
			this._color = c;
			this._width = width;

			this._startCap = LineCapExtension.Flat;
			this._endCap = LineCapExtension.Flat;

			_SetProp(PenX.Configured.IsNotNull, true);
			_SetProp(Configured.Color, NamedColors.Black != c);
			_SetProp(Configured.Width, 1 != width);

			if (bCachedMode)
				_SetPenVariable(new Pen(ToGdi(c), (float)width));
		}