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