1 module poison.ui.controls.picturebox;
2 
3 import poison.ui.picture;
4 import poison.ui.sprite;
5 import poison.ui.container;
6 
7 import poison.core : Point, Size;
8 
9 /// A container for a picture.
10 class PictureBox : Container {
11   public:
12   /**
13   * Creates a new picture box.
14   * Params:
15   *   name =        The name of the pictue box.
16   *   imageFile =   The image file to load into the picture.
17   *   layers =      The amount of layers the picture box has.
18   */
19   this(string name, string imageFile, size_t layers = 1) {
20     auto picture = new Picture(imageFile);
21     picture.finalize();
22 
23     this(name, picture, layers);
24   }
25 
26   /**
27   * Creates a new picture box.
28   * Params:
29   *   name =        The name of the pictue box.
30   *   picture =     The picture to initialize with.
31   *   layers =      The amount of layers the picture box has.
32   */
33   this(string name, Picture picture, size_t layers) {
34     assert(picture !is null);
35     super(name, layers);
36 
37     super.graphics.backgroundPicture = picture;
38     size = super.graphics.backgroundPicture.size;
39 
40     addSelector("picturebox");
41   }
42 
43   @property {
44     /// Gets the picture.
45     Picture picture() { return super.graphics.backgroundPicture; }
46 
47     /// Gets the position of the picturebox.
48     override Point position() { return super.position; }
49 
50     /// Sets the position of the picturebox.
51     override void position(Point newPosition) {
52       super.graphics.backgroundPicture.position = newPosition;
53 
54       super.position = newPosition;
55     }
56   }
57 }