Window

Struct Window 

Source
pub struct Window<'a> { /* private fields */ }
Expand description

The core type of the Pronto Graphics library. All drawing and keyboard/mouse interaction happens through an instance of Window. It has to be updated every frame with Window::update for drawings to be rendered and the keyboard/mouse state to be updated.

§Examples

let mut pg = Window::new(800, 600, "Window Title"); // Create window
loop {
    pg.circle((200,200), 50); // Draw to it
    pg.update(); // Update for drawing to appear
}

Implementations§

Source§

impl Window<'_>

Source

pub fn new(width: u32, height: u32, name: &str) -> Self

Create a new window of size (width, height) and with title name. Can be directly drawn to with functions like Window::circle and has to be updated with Window::update.

Examples found in repository?
examples/hello-world.rs (line 10)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn new_fullscreen() -> Self

Create a new fullscreen window. Can be directly drawn to with functions like Window::circle and has to be updated with Window::update.

Source

pub fn update(&mut self)

Has to be called every frame for drawings to appear on the screen and keyboard/mouse to be updated. Note that this function will block for vertical sync.

Examples found in repository?
examples/hello-world.rs (line 114)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn background_color<C: Into<Color>>(&mut self, color: C)

Set the background color of the window. The background color does not reset at the beginning of a new frame. The initial value for the background color is Color::LIGHT_GRAY.

Examples found in repository?
examples/hello-world.rs (line 17)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn fill_color<C: Into<Color>>(&mut self, color: C)

Set the fill color for drawing shapes like Window::circle. The fill color is reset at the beginning of a new frame to a default value of Color::WHITE.

Examples found in repository?
examples/hello-world.rs (line 27)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn outline_color<C: Into<Color>>(&mut self, color: C)

Set the outline color for drawing shapes like Window::circle. The outline color is reset at the beginning of a new frame to a default value of Color::TRANSPARENT.

Source

pub fn line_color<C: Into<Color>>(&mut self, color: C)

Set the line color for drawing lines with Window::line. The line color is reset at the beginning of a new frame to a default value of Color::BLACK.

Examples found in repository?
examples/hello-world.rs (line 102)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn font_color<C: Into<Color>>(&mut self, color: C)

Set the line color for drawing text with Window::text. The font color is reset at the beginning of a new frame to a default value of Color::BLACK.

Examples found in repository?
examples/hello-world.rs (line 75)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn font_size(&mut self, size: u32)

Set the font size for drawing text with Window::text. The font size is reset at the beginning of a new frame to a default value of 16.

Examples found in repository?
examples/hello-world.rs (line 76)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn font(&mut self, font: Option<Font>)

Set the font for drawing text with Window::text. The font does not reset at the beginning of a new frame. Fonts can be loaded with Window::load_font. Initially or if a value of None is passed to this function, a default font built into the library is used (Processing Sans Pro).

§Examples
let mut pg = Window::new_fullscreen();
let my_font = pg.load_font("MyFont.ttf").unwrap();
pg.font(Some(my_font));
loop {
    pg.text((20, 20), "This text is drawn in MyFont.");

    pg.update();
}
Examples found in repository?
examples/hello-world.rs (line 77)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn circle(&mut self, pos: (f32, f32), radius: f32)

Draw a circle at position pos with radius radius. The origin of the circle is at it’s center.

Examples found in repository?
examples/hello-world.rs (line 29)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn rectangle(&mut self, pos: (f32, f32), width: f32, height: f32)

Draw a rectangle at position pos with width and height of (width, height). The origin of the rectangle is at it’s top left.

Source

pub fn square(&mut self, pos: (f32, f32), size: f32)

Draw a square at position pos with a width and height of size. The origin of the square is at it’s top left.

Examples found in repository?
examples/hello-world.rs (line 83)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn texture( &mut self, pos: (f32, f32), texture: Texture, width: f32, height: f32, )

Draw a texture texture at position pos with width and height of (width, height). The origin of the texture is at it’s top left. Textures can be loaded with Window::load_texture.

§Examples
let mut pg = Window::new_fullscreen();
let my_texture = pg.load_texture("my_texture.png").unwrap();
loop {
    pg.texture((100., 250.), my_texture, 100., 150.);

    pg.update();
}
Source

pub fn texture_(&mut self, pos: (f32, f32), texture: Texture, width: f32)

Draw a texture texture at position pos with width of width, and height according to the aspect ratio of the texture. The origin of the texture is at it’s top left. Textures can be loaded with Window::load_texture.

§Examples
let mut pg = Window::new_fullscreen();
let my_texture = pg.load_texture("my_texture.png").unwrap();
loop {
    pg.texture_((100., 250.), my_texture, 100.);

    pg.update();
}
Examples found in repository?
examples/hello-world.rs (line 47)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn text(&mut self, pos: (f32, f32), string: &str)

Draw text string at position pos. The default font size is 16 and can be changed with Window::font_size. The default font color is Color::BLACK and can be changed with Window::font_color. Uses the default font built into the library (Processing Sans Pro) or the font set with Window::font.

§Examples
let mut pg = Window::new(720, 480, "Window Title");
loop {
    pg.fill_color(Color::BLACK);
    pg.text((10., 10.), "Hello World!");
    pg.update();
}
Examples found in repository?
examples/hello-world.rs (line 78)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn line(&mut self, from: (f32, f32), to: (f32, f32))

Draw a line from position from to position to. The line’s color is set with Window::line_color.

Examples found in repository?
examples/hello-world.rs (line 105)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn key_pressed(&self, key: Key) -> bool

Whether the keyboard key key is currently held pressed.

§Examples
if pg.key_pressed(Key::SPACE) {
    /*...*/
}
Source

pub fn key_just_pressed(&self, key: Key) -> bool

Whether the keyboard key key has just been pressed in this frame.

§Examples
if pg.key_just_pressed(Key::SPACE) {
    /*...*/
}
Examples found in repository?
examples/hello-world.rs (line 61)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn mouse_pressed(&self, button: Button) -> bool

Whether the mouse button button is currently held pressed.

§Examples
if pg.mouse_pressed(Button::LEFT) {
    /*...*/
}
Examples found in repository?
examples/hello-world.rs (line 51)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn mouse_just_pressed(&self, button: Button) -> bool

Whether the mouse button button has just been pressed in this frame.

§Examples
if pg.mouse_just_pressed(Button::LEFT) {
    /*...*/
}
Source

pub fn mouse_position(&self) -> (f32, f32)

The current mouse position inside the window.

Examples found in repository?
examples/hello-world.rs (line 54)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn mouse_wheel(&self) -> f32

The current cumulative scroll wheel state of the mouse.

Examples found in repository?
examples/hello-world.rs (line 69)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn mouse_wheel_delta(&self) -> f32

How much the scroll wheel has been scrolled in this frame.

Source

pub fn width(&self) -> f32

The width of the window, or the width of the screen in fullscreen mode.

Examples found in repository?
examples/hello-world.rs (line 29)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn height(&self) -> f32

The height of the window, or the height of the screen in fullscreen mode.

Examples found in repository?
examples/hello-world.rs (line 29)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn time(&self) -> f32

The time since the window has been created in seconds.

Examples found in repository?
examples/hello-world.rs (line 33)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn deltatime(&self) -> f32

How much time has passed since the last frame.

Source

pub fn load_texture(&mut self, path: &str) -> Option<Texture>

Load a texture from path path. A return value of None means that the texture could not be loaded. On success, returns a Texture object that can be passed to the Window::texture function to draw the texture to the screen.

§Examples
let mut pg = Window::new_fullscreen();
let my_texture = pg.load_texture("my_texture.png").unwrap();
loop {
    pg.texture_((100., 250.), my_texture, 100.);

    pg.update();
}
Examples found in repository?
examples/hello-world.rs (line 20)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}
Source

pub fn load_font(&mut self, path: &str) -> Option<Font>

Load a font from path path. A return value of None means that the font could not be loaded. On success, returns a Font object that can be passed to the Window::font function to set the font to be used for drawing text with Window::text.

§Examples
let mut pg = Window::new_fullscreen();
let my_font = pg.load_font("MyFont.ttf").unwrap();
pg.font(Some(my_font));
loop {
    pg.text((20, 20), "This text is drawn in MyFont.");

    pg.update();
}
Examples found in repository?
examples/hello-world.rs (line 23)
7fn main() {
8    // Create a new Pronto Graphics window, all drawing happens through this object.
9    // The window's drawable area will be of size 800 by 600, and the window title will be "Hello World".
10    let mut pg = Window::new(800, 600, "Hello World");
11
12    // Alternatively, we can create a full screen window.
13    // let mut pg = Window::new_fullscreen();
14
15    // Set the background color for our window.
16    // At the beginning of each frame, the window is cleared with this color.
17    pg.background_color((0x11, 0x11, 0x11));
18
19    // Load a texture from a file.
20    let texture = pg.load_texture("examples/test_texture.png").unwrap();
21
22    // Load a font from a file.
23    let font = pg.load_font("examples/Whisper-Regular.ttf").unwrap();
24
25    loop {
26        // Set the fill color for drawing shapes to blue.
27        pg.fill_color(Color::BLUE);
28        // Draw a circle in the middle of the window (width/2, height/2) with a radius of 64 pixels.
29        pg.circle((pg.width() / 2., pg.height() / 2.), 64.);
30
31        {
32            let pos = (
33                0.5 * pg.width() + 128. * pg.time().cos(),
34                0.5 * pg.height() + 128. * pg.time().sin(),
35            );
36
37            // Set the fill color to #CCCCCC, i.e. a light grey.
38            pg.fill_color((0xCC, 0xCC, 0xCC));
39            // Draw a circle at position `pos` with a radius of 16 pixels.
40            pg.circle(pos, 16.);
41        }
42
43        // Draw our texture at position `(10, 10)` with a width of 100 pixels.
44        // The texture's height will be deduced from the texture's aspect ratio.
45        // I.e. the texture is not distorted.
46        // If we want to set the height ourselves, we have to use `pg.texture(...)` (Note the missing `_`)
47        pg.texture_((10., 10.), texture, 150.);
48
49        // React to the the left mouse button being pressed.
50        // As long as the button is held down, the code inside the `if` is executed.
51        if pg.mouse_pressed(Button::LEFT) {
52            // Set the fill color to blue, but with it's alpha set to 127, i.e. half-transparent.
53            pg.fill_color(Color::GREEN.with_alpha(127));
54            pg.circle(pg.mouse_position(), 16.);
55        }
56
57        // React to the `SPACE` key having just been pressed this very frame.
58        // The code inside the if will only be executed once every time you press the key.
59        // I.e. Holding the key down will _not_ cause "Action!" to be printed every frame.
60        // If we want to react to a held down key, we have to use `pg.key_pressed(...)`
61        if pg.key_just_pressed(Key::SPACE) {
62            println!("Action!");
63        }
64
65        // React to the mouse wheel having been scrolled.
66        // `pg.mouse_wheel()` will give you a cumulative amount of scrolling across frames.
67        // If you want to know whether the scroll wheel has been scrolled in the current frame,
68        // use `pg.mouse_wheel_delta()` instead.
69        if pg.mouse_wheel() > 0. {
70            pg.fill_color(Color::GREEN);
71        } else {
72            pg.fill_color(Color::RED);
73        }
74
75        pg.font_color(Color::GREEN);
76        pg.font_size(40);
77        pg.font(Some(font));
78        pg.text((300., 50.), "Salutations!");
79
80        // Draw a square with side lengths of 25 pixels.
81        // Depending on what fill color has last been set above,
82        // this square will either be green or red.
83        pg.square((50., 300.), 25.);
84
85        {
86            let pos = (
87                pg.width() - 200.,
88                50. + ((50. * pg.time()) % (pg.height() - 130.)),
89            );
90
91            // Set the font color to a lovely pink of #EE4488.
92            pg.font_color((0xEE, 0x44, 0x88));
93            // Set the font size to 30 pixels.
94            pg.font_size(30);
95            // Set the font to the default font.
96            pg.font(None);
97            // Draw the string "Greetings!" as position `pos`.
98            pg.text(pos, "Greetings!");
99        }
100
101        // Set the line color from HSB, with the hue rotating through the colors.
102        pg.line_color(Color::from_hsb((60. * pg.time()) % 360., 1., 1.));
103
104        // Draw a bunch of lines.
105        pg.line((50., 500.), (50., 450.));
106        pg.line((50., 450.), (100., 500.));
107        pg.line((100., 475. + 25. * (5. * pg.time()).sin()), (150., 450.));
108
109        // At the end of our frame, we have to update the window
110        // for our drawings to appear on the screen and for the keyboard/mouse
111        // states to be updated.
112        // If your window ever is blank or looks glitchy, make sure you haven't forgotten
113        // to call `pg.update()` at the end of your `loop`.
114        pg.update();
115    }
116}

Auto Trait Implementations§

§

impl<'a> Freeze for Window<'a>

§

impl<'a> RefUnwindSafe for Window<'a>

§

impl<'a> !Send for Window<'a>

§

impl<'a> !Sync for Window<'a>

§

impl<'a> Unpin for Window<'a>

§

impl<'a> UnwindSafe for Window<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.