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 dsfml.graphics : RectangleShape, Color, RenderWindow; 16 import dsfml.system : Vector2f; 17 18 import novelate.component; 19 20 /// A dialogue box component. 21 final class DialogueBox : Component 22 { 23 private: 24 /// The rectangle shape used for the dialogue box. 25 RectangleShape _rect; 26 /// The color of the dialogue box. 27 Color _color; 28 29 public: 30 final: 31 package (novelate) 32 { 33 /// Creates a new dialogue box. 34 this() 35 { 36 super(); 37 38 _rect = new RectangleShape(Vector2f(cast(float)0, cast(float)0)); 39 } 40 } 41 42 @property 43 { 44 /// Gets the color of the dialogue box. 45 Color color() { return _color; } 46 47 /// Sets the color of the dialogue box. 48 void color(Color newColor) 49 { 50 _color = newColor; 51 52 _rect.fillColor = _color; 53 } 54 } 55 56 /// See: Component.render() 57 override void render(RenderWindow window) 58 { 59 window.draw(_rect); 60 } 61 62 /// See: Component.refresh() 63 override void refresh(size_t width, size_t height) 64 { 65 import novelate.config; 66 67 if (width == 800) 68 { 69 super.size = Vector2f(width - (config.defaultDialogueMargin * 2), config.defaultDialogueHeight800); 70 } 71 else if (width == 1024) 72 { 73 super.size = Vector2f(width - (config.defaultDialogueMargin * 2), config.defaultDialogueHeight1024); 74 } 75 else if (width == 1280) 76 { 77 super.size = Vector2f(width - (config.defaultDialogueMargin * 2), config.defaultDialogueHeight1280); 78 } 79 80 super.position = Vector2f 81 ( 82 (width / 2) - (super.width / 2), 83 height - (super.height + config.defaultDialogueMargin) 84 ); 85 } 86 87 /// See: Component.updateSize() 88 override void updateSize() 89 { 90 _rect = new RectangleShape(Vector2f(cast(float)super.width, cast(float)super.height)); 91 _rect.fillColor = _color; 92 93 updatePosition(); 94 } 95 96 /// See: Component.updatePosition() 97 override void updatePosition() 98 { 99 _rect.position = Vector2f(cast(float)super.x, cast(float)super.y); 100 } 101 }