1 /**
2 * Copyright © Novelate 2020
3 * License: MIT (https://github.com/Novelate/NovelateEngine/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 * Website: https://novelate.com/
6 * ------
7 * Novelate is a free and open-source visual novel engine and framework written in the D programming language.
8 * It can be used freely for both personal and commercial projects.
9 * ------
10 * Module Description:
11 * A dialogue box is the box that is used to display the dialogues.
12 */
13 module novelate.dialoguebox;
14 
15 import novelate.component;
16 
17 /// A dialogue box component.
18 final class DialogueBox : Component
19 {
20   private:
21   /// The rectangle shape used for the dialogue box.
22   ExternalRectangleShape _rect;
23   /// The color of the dialogue box.
24   Paint _color;
25 
26   public:
27   final:
28   package (novelate)
29   {
30     /// Creates a new dialogue box.
31     this()
32     {
33       super();
34 
35       _rect = new ExternalRectangleShape(FloatVector(cast(float)0, cast(float)0));
36     }
37   }
38 
39   @property
40   {
41     /// Gets the color of the dialogue box.
42     Paint color() { return _color; }
43 
44     /// Sets the color of the dialogue box.
45     void color(Paint newColor)
46     {
47       _color = newColor;
48 
49       _rect.fillColor = _color;
50     }
51   }
52 
53   /// See: Component.render()
54   override void render(ExternalWindow window)
55   {
56     _rect.draw(window);
57   }
58 
59   /// See: Component.refresh()
60   override void refresh(size_t width, size_t height)
61   {
62     import novelate.config;
63 
64     if (width == 800)
65     {
66       super.size = FloatVector(width - (config.defaultDialogueMargin * 2), config.defaultDialogueHeight800);
67     }
68     else if (width == 1024)
69     {
70       super.size = FloatVector(width - (config.defaultDialogueMargin * 2), config.defaultDialogueHeight1024);
71     }
72     else if (width == 1280)
73     {
74       super.size = FloatVector(width - (config.defaultDialogueMargin * 2), config.defaultDialogueHeight1280);
75     }
76 
77     super.position = FloatVector
78     (
79       (width / 2) - (super.width / 2),
80       height - (super.height + config.defaultDialogueMargin)
81     );
82   }
83 
84   /// See: Component.updateSize()
85   override void updateSize()
86   {
87     _rect = new ExternalRectangleShape(FloatVector(cast(float)super.width, cast(float)super.height));
88     _rect.fillColor = _color;
89 
90     updatePosition();
91   }
92 
93   /// See: Component.updatePosition()
94   override void updatePosition()
95   {
96     _rect.position = FloatVector(cast(float)super.x, cast(float)super.y);
97   }
98 }