1 
 2 // =================================
 3 // Copyright (c) 2024 Seppo Laakko
 4 // Distributed under the MIT license
 5 // =================================
 6 
 7 using System;
 8 
 9 namespace System.Windows
10 {
11     public class Buffer : GraphicsObject
12     {
13         public Buffer(const Size& size_System.Windows.Graphics& graphics_) : 
14             size(size_)bitmap(size.wsize.hgraphics_)graphics(null)
15         {
16             auto result = System.Windows.Graphics.FromImage(bitmap);
17             if (result.Error())
18             {
19                 SetErrorId(graphics->GetErrorId());
20                 return;
21             }
22             graphics.Reset(new Graphics(Rvalue(result.Value())));
23             if (graphics->Error())
24             {
25                 SetErrorId(graphics->GetErrorId());
26                 return;
27             }
28         }
29         public inline const Size& GetSize() const
30         {
31             return size;
32         }
33         public inline System.Windows.Graphics& BitmapGraphics()
34         {
35             return *graphics;
36         }
37         public inline System.Windows.Bitmap& GetBitmap() const
38         {
39             return bitmap;
40         }
41         [nodiscard]
42         public Result<bool> Draw(System.Windows.Graphics& graphics)
43         {
44             if (Error())
45             {
46                 return Result<bool>(ErrorId(GetErrorId()));
47             }
48             PointF topLeftCorner;
49             auto result = graphics.DrawImage(bitmaptopLeftCorner);
50             if (result.Error())
51             {
52                 return Result<bool>(ErrorId(result.GetErrorId()));
53             }
54             return Result<bool>(true);
55         }
56         private Size size;
57         private Bitmap bitmap;
58         private UniquePtr<System.Windows.Graphics> graphics;
59     }