| Nick | Data | Język |
|---|---|---|
| hollowone | 04/12/2009 10:17:48 | C# |
Blitter i Framebuffer w SL
- public class GpuSurface
- {
- private WriteableBitmap surfaceBitmap;
- private int width, height;
- public int Width
- {
- get
- {
- return width;
- }
- }
- public int Height
- {
- get
- {
- return height;
- }
- }
- public int[] Pixels
- {
- get
- {
- return surfaceBitmap.Pixels;
- }
- }
- internal WriteableBitmap Bitmap
- {
- get
- {
- return surfaceBitmap;
- }
- }
- public ImageBrush GetImageBrush()
- {
- ImageBrush brush = new ImageBrush();
- brush.ImageSource = this.surfaceBitmap;
- return brush;
- }
- public void Clear(uint rawColor)
- {
- for (int i = 0; i < width * height; i++)
- {
- unchecked
- {
- surfaceBitmap.Pixels[i] = (int)rawColor;
- }
- }
- }
- public void Blit(UIElement element, int xpos, int ypos, float scalex, float scaley, float angle)
- {
- TranslateTransform position = new TranslateTransform();
- ScaleTransform scale = new ScaleTransform();
- RotateTransform rotation = new RotateTransform();
- position.X = xpos;
- position.Y = ypos;
- scale.ScaleX = scalex;
- scale.ScaleY = scaley;
- rotation.Angle = angle;
- TransformGroup transform = new TransformGroup();
- transform.Children.Add(position);
- transform.Children.Add(scale);
- transform.Children.Add(rotation);
- surfaceBitmap.Render(element, transform);
- }
- public void Update()
- {
- surfaceBitmap.Invalidate();
- }
- #region Constructor and Static Creators
- private GpuSurface()
- {
- }
- public static GpuSurface Create(GpuDevice device)
- {
- GpuSurface surface = new GpuSurface();
- surface.surfaceBitmap = new WriteableBitmap(device.BackBuffer.Width,
- device.BackBuffer.Height);
- surface.width = surface.surfaceBitmap.PixelWidth;
- surface.height = surface.surfaceBitmap.PixelHeight;
- return surface;
- }
- public static GpuSurface Create(int width, int height)
- {
- GpuSurface surface = new GpuSurface();
- surface.surfaceBitmap = new WriteableBitmap(width, height);
- surface.width = surface.surfaceBitmap.PixelWidth;
- surface.height = surface.surfaceBitmap.PixelHeight;
- return surface;
- }
- #endregion
- }