예제 #1
0
파일: Brushes.cs 프로젝트: mhusen/Eto
		static SolidBrush GetBrush (Color color)
		{
			var cache = Platform.Instance.Cache<BrushKey, SolidBrush>(cacheKey);
			SolidBrush brush;
			lock (cache) {
				var key = new BrushKey (color.ToArgb ());
				if (!cache.TryGetValue (key, out brush)) {
					brush = new SolidBrush (color);
					cache.Add (key, brush);
				}
			}
			return brush;
		}
예제 #2
0
		static Brush GetBrush (Color color, Generator generator)
		{
			var cache = generator.Cache<BrushKey, Brush>(cacheKey);
			Brush brush;
			lock (cache) {
				var key = new BrushKey (color.ToArgb ());
				if (!cache.TryGetValue (key, out brush)) {
					brush = new SolidBrush (color, generator);
					cache.Add (key, brush);
				}
			}
			return brush;
		}
예제 #3
0
파일: Pens.cs 프로젝트: alexandrebaker/Eto
		static Pen GetPen (Generator generator, Color color, float thickness = 1f, DashStyle dashStyle = null)
		{
			var cache = generator.Cache<PenKey, Pen> (cacheKey);
			Pen pen;
			lock (cache) {
				var key = new PenKey (color.ToArgb (), thickness, dashStyle);
				if (!cache.TryGetValue (key, out pen)) {
					pen = new Pen (color, thickness, generator);
					if (dashStyle != null) pen.DashStyle = dashStyle;
					cache.Add (key, pen);
				}
			}
			return pen;
		}
예제 #4
0
		/// <summary>
		/// Sets the pixel color at the specified coordinates.
		/// </summary>
		/// <param name="x">The x coordinate of the pixel to set.</param>
		/// <param name="y">The y coordinate of the pixel to set.</param>
		/// <param name="color">Color to set the pixel to.</param>
		public unsafe override void SetPixel(int x, int y, Color color)
		{
			var pos = (byte*)Data;
			pos += x * BytesPerPixel + y * ScanWidth;

			var col = TranslateArgbToData(color.ToArgb());
			if (BytesPerPixel == 4)
			{
				*((int*)pos) = col;
			}
			else if (BytesPerPixel == 3)
			{
				*(pos++) = (byte)(col & 0xFF);
				*(pos++) = (byte)((col >> 8) & 0xFF);
				*(pos++) = (byte)((col >> 16) & 0xFF);
			}
			else
				throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "This PixelFormat is not supported by SetPixel. Must be 3 or 4 bytes per pixel"));
		}