summaryrefslogtreecommitdiff
path: root/src/dialogbox.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-07-24 05:54:49 -0500
committertom barrett <spalf0@gmail.com>2019-07-24 05:54:49 -0500
commit7d2c0954cd95bdabcb7ecf26f9225382ab078289 (patch)
treec6b140c1e73ff27f8ab340f68024210215dcb708 /src/dialogbox.rs
parentc25884efd8d1a239c88dbafd7a0e12eca3c7401b (diff)
dialog box
Diffstat (limited to 'src/dialogbox.rs')
-rw-r--r--src/dialogbox.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/dialogbox.rs b/src/dialogbox.rs
new file mode 100644
index 0000000..1f6415b
--- /dev/null
+++ b/src/dialogbox.rs
@@ -0,0 +1,61 @@
+use ggez::conf::Conf;
+use ggez::graphics::{
+ self, DrawMode, DrawParam, Font, Mesh, MeshBuilder, Rect, Scale, Text, TextFragment,
+};
+use ggez::nalgebra::Point2;
+use ggez::{Context, GameResult};
+
+use crate::constants;
+
+pub struct DialogBox {
+ mesh: Mesh,
+ text: Text,
+ conf: Conf,
+ pub visible: bool,
+}
+
+impl DialogBox {
+ pub fn new(context: &mut Context) -> DialogBox {
+ let conf = Conf::new();
+ let font = Font::new(context, "/fonts/SONORM__.ttf").unwrap();
+
+ DialogBox {
+ text: Text::new(
+ TextFragment::new("Ave !")
+ .font(font)
+ .scale(Scale::uniform(40.0)),
+ ),
+ mesh: MeshBuilder::new()
+ .rectangle(
+ DrawMode::fill(),
+ Rect::new(
+ conf.window_mode.width * 0.10,
+ 2.5 * conf.window_mode.height / 4.0,
+ conf.window_mode.width * 0.80,
+ conf.window_mode.height / 4.0,
+ ),
+ constants::PURPLE,
+ )
+ .build(context)
+ .unwrap(),
+ visible: false,
+ conf,
+ }
+ }
+
+ pub fn draw(&self, context: &mut Context) -> GameResult {
+ if self.visible {
+ graphics::draw(context, &self.mesh, DrawParam::default())?;
+ graphics::draw(
+ context,
+ &self.text,
+ DrawParam::default().dest(Point2::new(
+ self.conf.window_mode.width * 0.11,
+ 2.6 * self.conf.window_mode.height / 4.0,
+ )),
+ )?;
+ }
+
+ Ok(())
+ }
+}