Skip to main content

Renderer

Trait Renderer 

Source
pub trait Renderer {
Show 34 methods // Required methods fn width(&self) -> u32; fn height(&self) -> u32; fn data(&self) -> &[Color]; fn data_mut(&mut self) -> &mut [Color]; fn sync(&mut self) -> bool; fn update(&mut self) -> bool; fn update_rects(&mut self, rects: &[(i32, i32, u32, u32)]) -> bool; fn mode(&self) -> &Cell<Mode>; // Provided methods fn roi<'a>(&'a self, rect: &Rect) -> ImageRoi<'a> where Self: Sized { ... } fn roi_mut<'a>(&'a mut self, rect: &Rect) -> ImageRoiMut<'a> where Self: Sized { ... } fn pixel(&mut self, x: i32, y: i32, color: Color) { ... } fn arc(&mut self, x0: i32, y0: i32, radius: i32, parts: u8, color: Color) { ... } fn circle(&mut self, x0: i32, y0: i32, radius: i32, color: Color) { ... } fn line4points(&mut self, x0: i32, y0: i32, x: i32, y: i32, color: Color) { ... } fn line( &mut self, argx1: i32, argy1: i32, argx2: i32, argy2: i32, color: Color, ) { ... } fn lines(&mut self, points: &[[i32; 2]], color: Color) { ... } fn draw_path_stroke(&mut self, graphicspath: GraphicsPath, color: Color) { ... } fn char(&mut self, x: i32, y: i32, c: char, color: Color) { ... } fn set(&mut self, color: Color) { ... } fn clear(&mut self) { ... } fn solid_rect(&mut self, rect: &Rect, color: Color) { ... } fn rect(&mut self, x: i32, y: i32, w: u32, h: u32, color: Color) { ... } fn box_blur(&mut self, x: i32, y: i32, w: u32, h: u32, r: i32) { ... } fn box_shadow( &mut self, x: i32, y: i32, w: u32, h: u32, offset_x: i32, offset_y: i32, r: i32, color: Color, ) { ... } fn image( &mut self, start_x: i32, start_y: i32, w: u32, h: u32, data: &[Color], ) { ... } fn image_legacy( &mut self, start_x: i32, start_y: i32, w: u32, h: u32, data: &[Color], ) { ... } fn image_over(&mut self, start: i32, image_data: &[Color]) { ... } fn image_opaque( &mut self, start_x: i32, start_y: i32, w: u32, h: u32, image_data: &[Color], ) { ... } fn image_fast( &mut self, start_x: i32, start_y: i32, w: u32, h: u32, image_data: &[Color], ) { ... } fn linear_gradient( &mut self, rect_x: i32, rect_y: i32, rect_width: u32, rect_height: u32, start_x: i32, start_y: i32, end_x: i32, end_y: i32, start_color: Color, end_color: Color, ) { ... } fn rounded_rect( &mut self, x: i32, y: i32, w: u32, h: u32, radius: u32, filled: bool, color: Color, ) { ... } fn wu_line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: Color) { ... } fn wu_circle(&mut self, x0: i32, y0: i32, radius: i32, color: Color) { ... } fn getpixel(&self, x: i32, y: i32) -> Color { ... }
}
Expand description

The trait to allow rendering code to be placed. All rendering in this trait is done in software.

Required Methods§

Source

fn width(&self) -> u32

Get width

Source

fn height(&self) -> u32

Get height

Source

fn data(&self) -> &[Color]

Access the pixel buffer

Source

fn data_mut(&mut self) -> &mut [Color]

Access the pixel buffer mutably

Source

fn sync(&mut self) -> bool

Update the hardware buffer

Source

fn update(&mut self) -> bool

Update the software buffer

Source

fn update_rects(&mut self, rects: &[(i32, i32, u32, u32)]) -> bool

Update the specified software buffer region (x, y, w, h)

Source

fn mode(&self) -> &Cell<Mode>

Set/get drawing mode

Provided Methods§

Source

fn roi<'a>(&'a self, rect: &Rect) -> ImageRoi<'a>
where Self: Sized,

Source

fn roi_mut<'a>(&'a mut self, rect: &Rect) -> ImageRoiMut<'a>
where Self: Sized,

Source

fn pixel(&mut self, x: i32, y: i32, color: Color)

Draw a pixel

Source

fn arc(&mut self, x0: i32, y0: i32, radius: i32, parts: u8, color: Color)

Draw a piece of an arc. Negative radius will fill in the inside

Examples found in repository?
examples/simple.rs (line 62)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn circle(&mut self, x0: i32, y0: i32, radius: i32, color: Color)

Draw a circle. Negative radius will fill in the inside

Examples found in repository?
examples/simple.rs (line 66)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn line4points(&mut self, x0: i32, y0: i32, x: i32, y: i32, color: Color)

Source

fn line(&mut self, argx1: i32, argy1: i32, argx2: i32, argy2: i32, color: Color)

Draw a line

Examples found in repository?
examples/simple.rs (line 70)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn lines(&mut self, points: &[[i32; 2]], color: Color)

Source

fn draw_path_stroke(&mut self, graphicspath: GraphicsPath, color: Color)

Draw a path (GraphicsPath)

Examples found in repository?
examples/simple.rs (line 87)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn char(&mut self, x: i32, y: i32, c: char, color: Color)

Draw a character, using the loaded font

Examples found in repository?
examples/simple.rs (line 100)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn set(&mut self, color: Color)

Set entire window to a color

Examples found in repository?
examples/rect_bench.rs (line 23)
18fn main() {
19    let mut window = Window::new(10, 10, 1000, 800, "RECTANGLE BENCHMARK").unwrap();
20
21    let alpha = 250;
22
23    time!("set", { window.set(Color::rgb(255, 255, 255)) });
24
25    time!("rect 800x800", {
26        window.rect(0, 0, 800, 800, Color::rgba(0, 0, 255, alpha))
27    });
28
29    time!("rect 400x400", {
30        window.rect(0, 0, 400, 400, Color::rgba(0, 255, 0, alpha))
31    });
32
33    time!("rect 200x200", {
34        window.rect(0, 0, 200, 200, Color::rgba(255, 0, 0, alpha))
35    });
36
37    time!("sync", {
38        window.update();
39    });
40
41    'events: loop {
42        for event in window.events() {
43            #[allow(clippy::single_match)]
44            match event.to_option() {
45                EventOption::Quit(_quit_event) => break 'events,
46                _ => (),
47            }
48        }
49    }
50}
More examples
Hide additional examples
examples/image_bench.rs (line 27)
22fn main() {
23    //let (width, height) = orbclient::get_display_size().unwrap();
24
25    let mut window = Window::new(10, 10, 800, 600, "IMAGE BENCHMARK").unwrap();
26
27    window.set(Color::rgb(255, 255, 255));
28
29    //create image data : a green square
30    let data = vec![Color::rgba(100, 200, 10, 3); 412500];
31    let mut data2 = vec![Color::rgba(200, 100, 10, 3); 412500];
32    let mut data3 = vec![Color::rgba(10, 100, 100, 3); 412500];
33    let mut data4 = vec![Color::rgba(10, 100, 200, 3); 800 * 400];
34
35    //draw image benchmarking
36    println!("Benchmarking implementations to draw an image on window:");
37
38    time!("image_legacy", {
39        for _i in 0..TIMES {
40            window.image_legacy(15, 15, 750, 550, &data[..]);
41        }
42    });
43
44    time!("image_over", {
45        for _i in 0..TIMES {
46            window.image_over(50, &data4[..]);
47        }
48    });
49
50    time!("image_fast", {
51        for _i in 0..TIMES {
52            window.image_fast(20, 20, 750, 550, &data2[..]);
53        }
54    });
55
56    time!("image_opaque", {
57        for _i in 0..TIMES {
58            window.image_opaque(30, 30, 750, 550, &data3[..]);
59        }
60    });
61
62    time!("image_roi_mut_blend", {
63        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
64        for _i in 0..TIMES {
65            ImageRef::from_renderer(&mut window)
66                .roi_mut(&Rect::new(40, 40, 750, 550))
67                .blend(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
68        }
69    });
70
71    time!("image_roi_mut_blit_mask", {
72        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
73        for _i in 0..TIMES {
74            ImageRef::from_renderer(&mut window)
75                .roi_mut(&Rect::new(40, 40, 750, 550))
76                .blit_mask(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
77        }
78    });
79
80    time!("image_roi_mut_blit", {
81        let data3_roi = ImageRef::from_data(750, 550, &mut data3[..]);
82        for _i in 0..TIMES {
83            ImageRef::from_renderer(&mut window)
84                .roi_mut(&Rect::new(50, 50, 750, 550))
85                .blit(&data3_roi.roi(&Rect::new(0, 0, 750, 550)));
86        }
87    });
88
89    time!("image_roi_mut_blit_over", {
90        let data4_roi = ImageRef::from_data(800, 400, &mut data4[..]);
91        for _i in 0..TIMES {
92            ImageRef::from_renderer(&mut window)
93                // .roi_mut(&Rect::new(10, 120, 790, 400)) // to test blit_over does not trigger
94                .roi_mut(&Rect::new(0, 120, 800, 400))
95                .blit(&data4_roi.roi(&Rect::new(0, 0, 800, 400)));
96        }
97    });
98
99    println!("------------------------------------------------");
100
101    window.sync();
102
103    'events: loop {
104        for event in window.events() {
105            match event.to_option() {
106                EventOption::Quit(_quit_event) => break 'events,
107                EventOption::Mouse(evt) => println!(
108                    "At position {:?} pixel color is : {:?}",
109                    (evt.x, evt.y),
110                    window.getpixel(evt.x, evt.y)
111                ),
112                event_option => println!("{:?}", event_option),
113            }
114        }
115    }
116}
Source

fn clear(&mut self)

Sets the whole window to black

Source

fn solid_rect(&mut self, rect: &Rect, color: Color)

Draw a solid rectangle

Source

fn rect(&mut self, x: i32, y: i32, w: u32, h: u32, color: Color)

Examples found in repository?
examples/rect_bench.rs (line 26)
18fn main() {
19    let mut window = Window::new(10, 10, 1000, 800, "RECTANGLE BENCHMARK").unwrap();
20
21    let alpha = 250;
22
23    time!("set", { window.set(Color::rgb(255, 255, 255)) });
24
25    time!("rect 800x800", {
26        window.rect(0, 0, 800, 800, Color::rgba(0, 0, 255, alpha))
27    });
28
29    time!("rect 400x400", {
30        window.rect(0, 0, 400, 400, Color::rgba(0, 255, 0, alpha))
31    });
32
33    time!("rect 200x200", {
34        window.rect(0, 0, 200, 200, Color::rgba(255, 0, 0, alpha))
35    });
36
37    time!("sync", {
38        window.update();
39    });
40
41    'events: loop {
42        for event in window.events() {
43            #[allow(clippy::single_match)]
44            match event.to_option() {
45                EventOption::Quit(_quit_event) => break 'events,
46                _ => (),
47            }
48        }
49    }
50}
More examples
Hide additional examples
examples/simple.rs (line 115)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn box_blur(&mut self, x: i32, y: i32, w: u32, h: u32, r: i32)

Examples found in repository?
examples/simple.rs (line 129)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn box_shadow( &mut self, x: i32, y: i32, w: u32, h: u32, offset_x: i32, offset_y: i32, r: i32, color: Color, )

Examples found in repository?
examples/simple.rs (line 132)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn image(&mut self, start_x: i32, start_y: i32, w: u32, h: u32, data: &[Color])

Display an image

Source

fn image_legacy( &mut self, start_x: i32, start_y: i32, w: u32, h: u32, data: &[Color], )

Examples found in repository?
examples/image_bench.rs (line 40)
22fn main() {
23    //let (width, height) = orbclient::get_display_size().unwrap();
24
25    let mut window = Window::new(10, 10, 800, 600, "IMAGE BENCHMARK").unwrap();
26
27    window.set(Color::rgb(255, 255, 255));
28
29    //create image data : a green square
30    let data = vec![Color::rgba(100, 200, 10, 3); 412500];
31    let mut data2 = vec![Color::rgba(200, 100, 10, 3); 412500];
32    let mut data3 = vec![Color::rgba(10, 100, 100, 3); 412500];
33    let mut data4 = vec![Color::rgba(10, 100, 200, 3); 800 * 400];
34
35    //draw image benchmarking
36    println!("Benchmarking implementations to draw an image on window:");
37
38    time!("image_legacy", {
39        for _i in 0..TIMES {
40            window.image_legacy(15, 15, 750, 550, &data[..]);
41        }
42    });
43
44    time!("image_over", {
45        for _i in 0..TIMES {
46            window.image_over(50, &data4[..]);
47        }
48    });
49
50    time!("image_fast", {
51        for _i in 0..TIMES {
52            window.image_fast(20, 20, 750, 550, &data2[..]);
53        }
54    });
55
56    time!("image_opaque", {
57        for _i in 0..TIMES {
58            window.image_opaque(30, 30, 750, 550, &data3[..]);
59        }
60    });
61
62    time!("image_roi_mut_blend", {
63        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
64        for _i in 0..TIMES {
65            ImageRef::from_renderer(&mut window)
66                .roi_mut(&Rect::new(40, 40, 750, 550))
67                .blend(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
68        }
69    });
70
71    time!("image_roi_mut_blit_mask", {
72        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
73        for _i in 0..TIMES {
74            ImageRef::from_renderer(&mut window)
75                .roi_mut(&Rect::new(40, 40, 750, 550))
76                .blit_mask(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
77        }
78    });
79
80    time!("image_roi_mut_blit", {
81        let data3_roi = ImageRef::from_data(750, 550, &mut data3[..]);
82        for _i in 0..TIMES {
83            ImageRef::from_renderer(&mut window)
84                .roi_mut(&Rect::new(50, 50, 750, 550))
85                .blit(&data3_roi.roi(&Rect::new(0, 0, 750, 550)));
86        }
87    });
88
89    time!("image_roi_mut_blit_over", {
90        let data4_roi = ImageRef::from_data(800, 400, &mut data4[..]);
91        for _i in 0..TIMES {
92            ImageRef::from_renderer(&mut window)
93                // .roi_mut(&Rect::new(10, 120, 790, 400)) // to test blit_over does not trigger
94                .roi_mut(&Rect::new(0, 120, 800, 400))
95                .blit(&data4_roi.roi(&Rect::new(0, 0, 800, 400)));
96        }
97    });
98
99    println!("------------------------------------------------");
100
101    window.sync();
102
103    'events: loop {
104        for event in window.events() {
105            match event.to_option() {
106                EventOption::Quit(_quit_event) => break 'events,
107                EventOption::Mouse(evt) => println!(
108                    "At position {:?} pixel color is : {:?}",
109                    (evt.x, evt.y),
110                    window.getpixel(evt.x, evt.y)
111                ),
112                event_option => println!("{:?}", event_option),
113            }
114        }
115    }
116}
Source

fn image_over(&mut self, start: i32, image_data: &[Color])

Display an image overwriting a portion of window starting at given line : very quick!!

Examples found in repository?
examples/image_bench.rs (line 46)
22fn main() {
23    //let (width, height) = orbclient::get_display_size().unwrap();
24
25    let mut window = Window::new(10, 10, 800, 600, "IMAGE BENCHMARK").unwrap();
26
27    window.set(Color::rgb(255, 255, 255));
28
29    //create image data : a green square
30    let data = vec![Color::rgba(100, 200, 10, 3); 412500];
31    let mut data2 = vec![Color::rgba(200, 100, 10, 3); 412500];
32    let mut data3 = vec![Color::rgba(10, 100, 100, 3); 412500];
33    let mut data4 = vec![Color::rgba(10, 100, 200, 3); 800 * 400];
34
35    //draw image benchmarking
36    println!("Benchmarking implementations to draw an image on window:");
37
38    time!("image_legacy", {
39        for _i in 0..TIMES {
40            window.image_legacy(15, 15, 750, 550, &data[..]);
41        }
42    });
43
44    time!("image_over", {
45        for _i in 0..TIMES {
46            window.image_over(50, &data4[..]);
47        }
48    });
49
50    time!("image_fast", {
51        for _i in 0..TIMES {
52            window.image_fast(20, 20, 750, 550, &data2[..]);
53        }
54    });
55
56    time!("image_opaque", {
57        for _i in 0..TIMES {
58            window.image_opaque(30, 30, 750, 550, &data3[..]);
59        }
60    });
61
62    time!("image_roi_mut_blend", {
63        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
64        for _i in 0..TIMES {
65            ImageRef::from_renderer(&mut window)
66                .roi_mut(&Rect::new(40, 40, 750, 550))
67                .blend(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
68        }
69    });
70
71    time!("image_roi_mut_blit_mask", {
72        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
73        for _i in 0..TIMES {
74            ImageRef::from_renderer(&mut window)
75                .roi_mut(&Rect::new(40, 40, 750, 550))
76                .blit_mask(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
77        }
78    });
79
80    time!("image_roi_mut_blit", {
81        let data3_roi = ImageRef::from_data(750, 550, &mut data3[..]);
82        for _i in 0..TIMES {
83            ImageRef::from_renderer(&mut window)
84                .roi_mut(&Rect::new(50, 50, 750, 550))
85                .blit(&data3_roi.roi(&Rect::new(0, 0, 750, 550)));
86        }
87    });
88
89    time!("image_roi_mut_blit_over", {
90        let data4_roi = ImageRef::from_data(800, 400, &mut data4[..]);
91        for _i in 0..TIMES {
92            ImageRef::from_renderer(&mut window)
93                // .roi_mut(&Rect::new(10, 120, 790, 400)) // to test blit_over does not trigger
94                .roi_mut(&Rect::new(0, 120, 800, 400))
95                .blit(&data4_roi.roi(&Rect::new(0, 0, 800, 400)));
96        }
97    });
98
99    println!("------------------------------------------------");
100
101    window.sync();
102
103    'events: loop {
104        for event in window.events() {
105            match event.to_option() {
106                EventOption::Quit(_quit_event) => break 'events,
107                EventOption::Mouse(evt) => println!(
108                    "At position {:?} pixel color is : {:?}",
109                    (evt.x, evt.y),
110                    window.getpixel(evt.x, evt.y)
111                ),
112                event_option => println!("{:?}", event_option),
113            }
114        }
115    }
116}
Source

fn image_opaque( &mut self, start_x: i32, start_y: i32, w: u32, h: u32, image_data: &[Color], )

Display an image using non transparent method

Examples found in repository?
examples/image_bench.rs (line 58)
22fn main() {
23    //let (width, height) = orbclient::get_display_size().unwrap();
24
25    let mut window = Window::new(10, 10, 800, 600, "IMAGE BENCHMARK").unwrap();
26
27    window.set(Color::rgb(255, 255, 255));
28
29    //create image data : a green square
30    let data = vec![Color::rgba(100, 200, 10, 3); 412500];
31    let mut data2 = vec![Color::rgba(200, 100, 10, 3); 412500];
32    let mut data3 = vec![Color::rgba(10, 100, 100, 3); 412500];
33    let mut data4 = vec![Color::rgba(10, 100, 200, 3); 800 * 400];
34
35    //draw image benchmarking
36    println!("Benchmarking implementations to draw an image on window:");
37
38    time!("image_legacy", {
39        for _i in 0..TIMES {
40            window.image_legacy(15, 15, 750, 550, &data[..]);
41        }
42    });
43
44    time!("image_over", {
45        for _i in 0..TIMES {
46            window.image_over(50, &data4[..]);
47        }
48    });
49
50    time!("image_fast", {
51        for _i in 0..TIMES {
52            window.image_fast(20, 20, 750, 550, &data2[..]);
53        }
54    });
55
56    time!("image_opaque", {
57        for _i in 0..TIMES {
58            window.image_opaque(30, 30, 750, 550, &data3[..]);
59        }
60    });
61
62    time!("image_roi_mut_blend", {
63        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
64        for _i in 0..TIMES {
65            ImageRef::from_renderer(&mut window)
66                .roi_mut(&Rect::new(40, 40, 750, 550))
67                .blend(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
68        }
69    });
70
71    time!("image_roi_mut_blit_mask", {
72        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
73        for _i in 0..TIMES {
74            ImageRef::from_renderer(&mut window)
75                .roi_mut(&Rect::new(40, 40, 750, 550))
76                .blit_mask(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
77        }
78    });
79
80    time!("image_roi_mut_blit", {
81        let data3_roi = ImageRef::from_data(750, 550, &mut data3[..]);
82        for _i in 0..TIMES {
83            ImageRef::from_renderer(&mut window)
84                .roi_mut(&Rect::new(50, 50, 750, 550))
85                .blit(&data3_roi.roi(&Rect::new(0, 0, 750, 550)));
86        }
87    });
88
89    time!("image_roi_mut_blit_over", {
90        let data4_roi = ImageRef::from_data(800, 400, &mut data4[..]);
91        for _i in 0..TIMES {
92            ImageRef::from_renderer(&mut window)
93                // .roi_mut(&Rect::new(10, 120, 790, 400)) // to test blit_over does not trigger
94                .roi_mut(&Rect::new(0, 120, 800, 400))
95                .blit(&data4_roi.roi(&Rect::new(0, 0, 800, 400)));
96        }
97    });
98
99    println!("------------------------------------------------");
100
101    window.sync();
102
103    'events: loop {
104        for event in window.events() {
105            match event.to_option() {
106                EventOption::Quit(_quit_event) => break 'events,
107                EventOption::Mouse(evt) => println!(
108                    "At position {:?} pixel color is : {:?}",
109                    (evt.x, evt.y),
110                    window.getpixel(evt.x, evt.y)
111                ),
112                event_option => println!("{:?}", event_option),
113            }
114        }
115    }
116}
Source

fn image_fast( &mut self, start_x: i32, start_y: i32, w: u32, h: u32, image_data: &[Color], )

Examples found in repository?
examples/image_bench.rs (line 52)
22fn main() {
23    //let (width, height) = orbclient::get_display_size().unwrap();
24
25    let mut window = Window::new(10, 10, 800, 600, "IMAGE BENCHMARK").unwrap();
26
27    window.set(Color::rgb(255, 255, 255));
28
29    //create image data : a green square
30    let data = vec![Color::rgba(100, 200, 10, 3); 412500];
31    let mut data2 = vec![Color::rgba(200, 100, 10, 3); 412500];
32    let mut data3 = vec![Color::rgba(10, 100, 100, 3); 412500];
33    let mut data4 = vec![Color::rgba(10, 100, 200, 3); 800 * 400];
34
35    //draw image benchmarking
36    println!("Benchmarking implementations to draw an image on window:");
37
38    time!("image_legacy", {
39        for _i in 0..TIMES {
40            window.image_legacy(15, 15, 750, 550, &data[..]);
41        }
42    });
43
44    time!("image_over", {
45        for _i in 0..TIMES {
46            window.image_over(50, &data4[..]);
47        }
48    });
49
50    time!("image_fast", {
51        for _i in 0..TIMES {
52            window.image_fast(20, 20, 750, 550, &data2[..]);
53        }
54    });
55
56    time!("image_opaque", {
57        for _i in 0..TIMES {
58            window.image_opaque(30, 30, 750, 550, &data3[..]);
59        }
60    });
61
62    time!("image_roi_mut_blend", {
63        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
64        for _i in 0..TIMES {
65            ImageRef::from_renderer(&mut window)
66                .roi_mut(&Rect::new(40, 40, 750, 550))
67                .blend(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
68        }
69    });
70
71    time!("image_roi_mut_blit_mask", {
72        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
73        for _i in 0..TIMES {
74            ImageRef::from_renderer(&mut window)
75                .roi_mut(&Rect::new(40, 40, 750, 550))
76                .blit_mask(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
77        }
78    });
79
80    time!("image_roi_mut_blit", {
81        let data3_roi = ImageRef::from_data(750, 550, &mut data3[..]);
82        for _i in 0..TIMES {
83            ImageRef::from_renderer(&mut window)
84                .roi_mut(&Rect::new(50, 50, 750, 550))
85                .blit(&data3_roi.roi(&Rect::new(0, 0, 750, 550)));
86        }
87    });
88
89    time!("image_roi_mut_blit_over", {
90        let data4_roi = ImageRef::from_data(800, 400, &mut data4[..]);
91        for _i in 0..TIMES {
92            ImageRef::from_renderer(&mut window)
93                // .roi_mut(&Rect::new(10, 120, 790, 400)) // to test blit_over does not trigger
94                .roi_mut(&Rect::new(0, 120, 800, 400))
95                .blit(&data4_roi.roi(&Rect::new(0, 0, 800, 400)));
96        }
97    });
98
99    println!("------------------------------------------------");
100
101    window.sync();
102
103    'events: loop {
104        for event in window.events() {
105            match event.to_option() {
106                EventOption::Quit(_quit_event) => break 'events,
107                EventOption::Mouse(evt) => println!(
108                    "At position {:?} pixel color is : {:?}",
109                    (evt.x, evt.y),
110                    window.getpixel(evt.x, evt.y)
111                ),
112                event_option => println!("{:?}", event_option),
113            }
114        }
115    }
116}
Source

fn linear_gradient( &mut self, rect_x: i32, rect_y: i32, rect_width: u32, rect_height: u32, start_x: i32, start_y: i32, end_x: i32, end_y: i32, start_color: Color, end_color: Color, )

Draw a linear gradient in a rectangular region

Examples found in repository?
examples/simple.rs (lines 24-35)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn rounded_rect( &mut self, x: i32, y: i32, w: u32, h: u32, radius: u32, filled: bool, color: Color, )

Draw a rect with rounded corners

Source

fn wu_line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: Color)

Draws antialiased line

Examples found in repository?
examples/simple.rs (line 75)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn wu_circle(&mut self, x0: i32, y0: i32, radius: i32, color: Color)

Draws antialiased circle

Examples found in repository?
examples/simple.rs (line 69)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}
Source

fn getpixel(&self, x: i32, y: i32) -> Color

Gets pixel color at x,y position

Examples found in repository?
examples/image_bench.rs (line 110)
22fn main() {
23    //let (width, height) = orbclient::get_display_size().unwrap();
24
25    let mut window = Window::new(10, 10, 800, 600, "IMAGE BENCHMARK").unwrap();
26
27    window.set(Color::rgb(255, 255, 255));
28
29    //create image data : a green square
30    let data = vec![Color::rgba(100, 200, 10, 3); 412500];
31    let mut data2 = vec![Color::rgba(200, 100, 10, 3); 412500];
32    let mut data3 = vec![Color::rgba(10, 100, 100, 3); 412500];
33    let mut data4 = vec![Color::rgba(10, 100, 200, 3); 800 * 400];
34
35    //draw image benchmarking
36    println!("Benchmarking implementations to draw an image on window:");
37
38    time!("image_legacy", {
39        for _i in 0..TIMES {
40            window.image_legacy(15, 15, 750, 550, &data[..]);
41        }
42    });
43
44    time!("image_over", {
45        for _i in 0..TIMES {
46            window.image_over(50, &data4[..]);
47        }
48    });
49
50    time!("image_fast", {
51        for _i in 0..TIMES {
52            window.image_fast(20, 20, 750, 550, &data2[..]);
53        }
54    });
55
56    time!("image_opaque", {
57        for _i in 0..TIMES {
58            window.image_opaque(30, 30, 750, 550, &data3[..]);
59        }
60    });
61
62    time!("image_roi_mut_blend", {
63        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
64        for _i in 0..TIMES {
65            ImageRef::from_renderer(&mut window)
66                .roi_mut(&Rect::new(40, 40, 750, 550))
67                .blend(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
68        }
69    });
70
71    time!("image_roi_mut_blit_mask", {
72        let data2_roi = ImageRef::from_data(750, 550, &mut data2[..]);
73        for _i in 0..TIMES {
74            ImageRef::from_renderer(&mut window)
75                .roi_mut(&Rect::new(40, 40, 750, 550))
76                .blit_mask(&data2_roi.roi(&Rect::new(0, 0, 750, 550)));
77        }
78    });
79
80    time!("image_roi_mut_blit", {
81        let data3_roi = ImageRef::from_data(750, 550, &mut data3[..]);
82        for _i in 0..TIMES {
83            ImageRef::from_renderer(&mut window)
84                .roi_mut(&Rect::new(50, 50, 750, 550))
85                .blit(&data3_roi.roi(&Rect::new(0, 0, 750, 550)));
86        }
87    });
88
89    time!("image_roi_mut_blit_over", {
90        let data4_roi = ImageRef::from_data(800, 400, &mut data4[..]);
91        for _i in 0..TIMES {
92            ImageRef::from_renderer(&mut window)
93                // .roi_mut(&Rect::new(10, 120, 790, 400)) // to test blit_over does not trigger
94                .roi_mut(&Rect::new(0, 120, 800, 400))
95                .blit(&data4_roi.roi(&Rect::new(0, 0, 800, 400)));
96        }
97    });
98
99    println!("------------------------------------------------");
100
101    window.sync();
102
103    'events: loop {
104        for event in window.events() {
105            match event.to_option() {
106                EventOption::Quit(_quit_event) => break 'events,
107                EventOption::Mouse(evt) => println!(
108                    "At position {:?} pixel color is : {:?}",
109                    (evt.x, evt.y),
110                    window.getpixel(evt.x, evt.y)
111                ),
112                event_option => println!("{:?}", event_option),
113            }
114        }
115    }
116}
More examples
Hide additional examples
examples/simple.rs (line 104)
7fn main() {
8    let (width, height) = orbclient::get_display_size().unwrap();
9
10    let mut window = Window::new_flags(
11        (width as i32) / 4,
12        (height as i32) / 4,
13        width / 2,
14        height / 2,
15        "TITLE",
16        &[WindowFlag::Transparent],
17    )
18    .unwrap();
19
20    let (win_w, win_h) = (width / 2, height / 2);
21
22    let start = Instant::now();
23    // top left -> bottom right
24    window.linear_gradient(
25        0,
26        0,
27        win_w / 3,
28        win_h,
29        0,
30        0,
31        (win_w / 3) as i32,
32        (win_h / 2) as i32,
33        Color::rgb(128, 128, 128),
34        Color::rgb(255, 255, 255),
35    );
36    // horizontal gradient
37    window.linear_gradient(
38        (win_w / 3) as i32,
39        0,
40        win_w / 3,
41        win_h,
42        (win_w / 3) as i32,
43        0,
44        (2 * win_w / 3) as i32,
45        0,
46        Color::rgb(128, 255, 255),
47        Color::rgb(255, 255, 255),
48    );
49    // vertical gradient
50    window.linear_gradient(
51        (2 * win_w / 3) as i32,
52        0,
53        win_w / 3,
54        win_h,
55        (2 * win_w / 3) as i32,
56        0,
57        (2 * win_w / 3) as i32,
58        win_h as i32,
59        Color::rgb(0, 128, 0),
60        Color::rgb(255, 255, 255),
61    );
62    window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255));
63    window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255));
64    window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255));
65    window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0));
66    window.circle(100, 100, 25, Color::rgb(0, 0, 0));
67    window.circle(100, 101, -25, Color::rgb(0, 255, 0));
68    window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80));
69    window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255));
70    window.line(0, 0, 200, 200, Color::rgb(255, 0, 0));
71    window.line(0, 200, 200, 0, Color::rgb(128, 255, 0));
72    // vertical and horizontal line test
73    window.line(100, 0, 100, 200, Color::rgb(0, 0, 255));
74    window.line(0, 100, 200, 100, Color::rgb(255, 255, 0));
75    window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255));
76    window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255));
77
78    // path and bezier curve example draw a cloud
79    let mut cloud_path = GraphicsPath::new();
80    cloud_path.move_to(170, 80);
81    cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150);
82    cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150);
83    cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100);
84    cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50);
85    cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50);
86    cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80);
87    window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255));
88
89    // path and quadratic curve example draw a balloon
90    let mut balloon_path = GraphicsPath::new();
91    balloon_path.move_to(75, 25);
92    balloon_path.quadratic_curve_to(25, 25, 25, 62);
93    balloon_path.quadratic_curve_to(25, 100, 50, 100);
94    balloon_path.quadratic_curve_to(50, 120, 30, 125);
95    balloon_path.quadratic_curve_to(60, 120, 65, 100);
96    balloon_path.quadratic_curve_to(125, 100, 125, 62);
97    balloon_path.quadratic_curve_to(125, 25, 75, 25);
98    window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255));
99
100    window.char(200, 200, '═', Color::rgb(0, 0, 0));
101    window.char(208, 200, '═', Color::rgb(0, 0, 0));
102
103    // testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
104    let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10);
105
106    // testing PartialEq for Color
107    if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) {
108        println!("Testing colors: they are the same!")
109    } else {
110        println!("Testing colors: they are NOT the same!")
111    }
112
113    //Draw a transparent rectangle over window content
114    // default mode is Blend
115    window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100));
116
117    //Draw an opaque rectangle replacing window content
118    window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on
119    window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100));
120
121    //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2)
122    window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1));
123
124    //Draw a transparent rectangle over window content
125    window.mode().set(Mode::Blend); //set mode to Blend fron now on
126    window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100));
127
128    //Draw a blured box over window content
129    window.box_blur(170, 100, 150, 150, 10);
130
131    //Draw a shadow around a box
132    window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255));
133
134    println!(
135        "Drawing took {}ms",
136        (start.elapsed().as_micros() / 100) as f32 / 10.0
137    );
138
139    window.sync();
140
141    'events: loop {
142        for event in window.events() {
143            match event.to_option() {
144                EventOption::Quit(_quit_event) => break 'events,
145                EventOption::Mouse(evt) => println!(
146                    "At position {:?} pixel color is : {:?}",
147                    (evt.x, evt.y),
148                    window.getpixel(evt.x, evt.y)
149                ),
150                event_option => println!("{:?}", event_option),
151            }
152        }
153    }
154}

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Renderer for Image

Source§

impl Renderer for ImageAligned

Available on crate feature std only.
Source§

impl Renderer for Surface

Source§

impl Renderer for Window

Source§

impl<'a> Renderer for ImageRef<'a>