MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / main

Function main

draw/examples/texture.rs:9–41  ·  view source on GitHub ↗

Simple example that displays a canvas window and renders an image from a png file

()

Source from the content-addressed store, hash-verified

7/// Simple example that displays a canvas window and renders an image from a png file
8///
9pub fn main() {
10 // 'with_2d_graphics' is used to support operating systems that can't run event loops anywhere other than the main thread
11 with_2d_graphics(|| {
12 // Load a png file
13 let flo_bytes: &[u8] = include_bytes!["flo_drawing_on_window.png"];
14
15 // Create a window
16 let canvas = create_drawing_window("Flo drawing on a window");
17
18 // Render the png to the window
19 canvas.draw(|gc| {
20 // Clear the canvas and set up the coordinates
21 gc.clear_canvas(Color::Rgba(1.0, 1.0, 1.0, 1.0));
22 gc.canvas_height(1000.0);
23 gc.center_region(0.0, 0.0, 1000.0, 1000.0);
24
25 // Set up the texture
26 let (flo_w, flo_h) = gc.load_texture(TextureId(0), io::Cursor::new(flo_bytes)).unwrap();
27
28 let ratio = (flo_w as f32)/(flo_h as f32);
29 let height = 1000.0 / ratio;
30 let y_pos = (1000.0-height)/2.0;
31
32 // Draw a rectangle...
33 gc.new_path();
34 gc.rect(0.0, y_pos, 1000.0, y_pos+height);
35
36 // Fill with the texture we just loaded
37 gc.fill_texture(TextureId(0), 0.0, y_pos+height as f32, 1000.0, y_pos);
38 gc.fill();
39 });
40 });
41}

Callers

nothing calls this directly

Calls 12

with_2d_graphicsFunction · 0.85
create_drawing_windowFunction · 0.85
clear_canvasMethod · 0.80
canvas_heightMethod · 0.80
center_regionMethod · 0.80
load_textureMethod · 0.80
new_pathMethod · 0.80
rectMethod · 0.80
fill_textureMethod · 0.80
TextureIdClass · 0.50
drawMethod · 0.45
fillMethod · 0.45

Tested by

no test coverage detected