### simple.rs example using Color::rgb Source: https://docs.rs/orbclient/latest/orbclient/color/struct.Color.html?search=u32+-%3E+bool This example from examples/simple.rs gets the display size and creates a window, using Color::rgb to set the background. ```rust fn main() { let (width, height) = orbclient::get_display_size().unwrap(); ``` -------------------------------- ### Example: Drawing with GraphicsPath::move_to in examples/simple.rs Source: https://docs.rs/orbclient/latest/orbclient/graphicspath/struct.GraphicsPath.html?search=std%3A%3Avec This example from `examples/simple.rs` demonstrates `move_to` within a full window drawing program. It creates a transparent window, draws gradients, arcs, circles, lines, and uses `move_to` to start a cloud path and a balloon path before stroking them. The example also includes an event loop that prints pixel colors on mouse events. ```rust fn main() { let (width, height) = orbclient::get_display_size().unwrap(); let mut window = Window::new_flags( (width as i32) / 4, (height as i32) / 4, width / 2, height / 2, "TITLE", &[WindowFlag::Transparent], ) .unwrap(); let (win_w, win_h) = (width / 2, height / 2); let start = Instant::now(); // top left -> bottom right window.linear_gradient( 0, 0, win_w / 3, win_h, 0, 0, (win_w / 3) as i32, (win_h / 2) as i32, Color::rgb(128, 128, 128), Color::rgb(255, 255, 255), ); // horizontal gradient window.linear_gradient( (win_w / 3) as i32, 0, win_w / 3, win_h, (win_w / 3) as i32, 0, (2 * win_w / 3) as i32, 0, Color::rgb(128, 255, 255), Color::rgb(255, 255, 255), ); // vertical gradient window.linear_gradient( (2 * win_w / 3) as i32, 0, win_w / 3, win_h, (2 * win_w / 3) as i32, 0, (2 * win_w / 3) as i32, win_h as i32, Color::rgb(0, 128, 0), Color::rgb(255, 255, 255), ); window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255)); window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255)); window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255)); window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0)); window.circle(100, 100, 25, Color::rgb(0, 0, 0)); window.circle(100, 101, -25, Color::rgb(0, 255, 0)); window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80)); window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255)); window.line(0, 0, 200, 200, Color::rgb(255, 0, 0)); window.line(0, 200, 200, 0, Color::rgb(128, 255, 0)); // vertical and horizontal line test window.line(100, 0, 100, 200, Color::rgb(0, 0, 255)); window.line(0, 100, 200, 100, Color::rgb(255, 255, 0)); window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255)); window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255)); // path and bezier curve example draw a cloud let mut cloud_path = GraphicsPath::new(); cloud_path.move_to(170, 80); cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150); cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150); cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100); cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50); cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50); cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80); window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255)); // path and quadratic curve example draw a balloon let mut balloon_path = GraphicsPath::new(); balloon_path.move_to(75, 25); balloon_path.quadratic_curve_to(25, 25, 25, 62); balloon_path.quadratic_curve_to(25, 100, 50, 100); balloon_path.quadratic_curve_to(50, 120, 30, 125); balloon_path.quadratic_curve_to(60, 120, 65, 100); balloon_path.quadratic_curve_to(125, 100, 125, 62); balloon_path.quadratic_curve_to(125, 25, 75, 25); window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255)); window.char(200, 200, '═', Color::rgb(0, 0, 0)); window.char(208, 200, '═', Color::rgb(0, 0, 0)); } ``` -------------------------------- ### Partial main function from simple.rs Source: https://docs.rs/orbclient/latest/orbclient/event/struct.Event.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Partial example from examples/simple.rs (line 143) showing the start of a main function; the rest is not shown on this page. ```rust fn main() { ``` -------------------------------- ### get example Source: https://docs.rs/orbclient/latest/orbclient/event/struct.Event.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the `get` method on a slice. It returns a reference to an element or subslice depending on the index type, or `None` if out of bounds. The example shows both element and range indexing. ```rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### first method example Source: https://docs.rs/orbclient/latest/orbclient/event/struct.Event.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example for the first method, returning the first element or None if empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&10), v.first()); let w: &[i32] = &[]; assert_eq!(None, w.first()); ``` -------------------------------- ### Renderer drawing example with gradients, paths, shapes, and modes Source: https://docs.rs/orbclient/latest/orbclient/renderer/trait.Renderer.html Example from the repository demonstrating various Renderer drawing methods: linear_gradient, arc, circle, wu_circle, line, wu_line, GraphicsPath with bezier_curve_to and quadratic_curve_to, draw_path_stroke, char, getpixel, rect with Mode::Blend and Mode::Overwrite, box_blur, box_shadow, and sync. Includes a PartialEq test for Color and a non-existent pixel getpixel that returns Color(0,0,0,0) without panicking. The code is incomplete at the start (missing window creation) and ends with an unfinished event loop. ```rust width / 2, height / 2, "TITLE", &[WindowFlag::Transparent], ) .unwrap(); let (win_w, win_h) = (width / 2, height / 2); let start = Instant::now(); // top left -> bottom right window.linear_gradient( 0, 0, win_w / 3, win_h, 0, 0, (win_w / 3) as i32, (win_h / 2) as i32, Color::rgb(128, 128, 128), Color::rgb(255, 255, 255), ); // horizontal gradient window.linear_gradient( (win_w / 3) as i32, 0, win_w / 3, win_h, (win_w / 3) as i32, 0, (2 * win_w / 3) as i32, 0, Color::rgb(128, 255, 255), Color::rgb(255, 255, 255), ); // vertical gradient window.linear_gradient( (2 * win_w / 3) as i32, 0, win_w / 3, win_h, (2 * win_w / 3) as i32, 0, (2 * win_w / 3) as i32, win_h as i32, Color::rgb(0, 128, 0), Color::rgb(255, 255, 255), ); window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255)); window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255)); window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255)); window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0)); window.circle(100, 100, 25, Color::rgb(0, 0, 0)); window.circle(100, 101, -25, Color::rgb(0, 255, 0)); window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80)); window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255)); window.line(0, 0, 200, 200, Color::rgb(255, 0, 0)); window.line(0, 200, 200, 0, Color::rgb(128, 255, 0)); // vertical and horizontal line test window.line(100, 0, 100, 200, Color::rgb(0, 0, 255)); window.line(0, 100, 200, 100, Color::rgb(255, 255, 0)); window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255)); window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255)); // path and bezier curve example draw a cloud let mut cloud_path = GraphicsPath::new(); cloud_path.move_to(170, 80); cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150); cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150); cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100); cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50); cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50); cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80); window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255)); // path and quadratic curve example draw a balloon let mut balloon_path = GraphicsPath::new(); balloon_path.move_to(75, 25); balloon_path.quadratic_curve_to(25, 25, 25, 62); balloon_path.quadratic_curve_to(25, 100, 50, 100); balloon_path.quadratic_curve_to(50, 120, 30, 125); balloon_path.quadratic_curve_to(60, 120, 65, 100); balloon_path.quadratic_curve_to(125, 100, 125, 62); balloon_path.quadratic_curve_to(125, 25, 75, 25); window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255)); window.char(200, 200, '═', Color::rgb(0, 0, 0)); window.char(208, 200, '═', Color::rgb(0, 0, 0)); // testing for non existent x,y position : does not panic but returns Color(0,0,0,0) let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10); // testing PartialEq for Color if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) { println!("Testing colors: they are the same!") } else { println!("Testing colors: they are NOT the same!") } //Draw a transparent rectangle over window content // default mode is Blend window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100)); //Draw an opaque rectangle replacing window content window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100)); //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2) window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1)); //Draw a transparent rectangle over window content window.mode().set(Mode::Blend); //set mode to Blend fron now on window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100)); //Draw a blured box over window content window.box_blur(170, 100, 150, 150, 10); //Draw a shadow around a box window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255)); println!( "Drawing took {}ms", (start.elapsed().as_micros() / 100) as f32 / 10.0 ); window.sync(); 'events: loop { ``` -------------------------------- ### Drawing example using orbclient window functions Source: https://docs.rs/orbclient/latest/orbclient/color/struct.Color.html?search=u32+-%3E+bool A comprehensive example demonstrating drawing with orbclient. It draws arcs, circles, lines, paths, text, rectangles, and applies effects like blur and shadow. It also shows setting drawing modes (Blend/Overwrite), getting pixel colors, checking Color equality, and handling events. Note: Overwrite mode and alpha hole may be Orbital-specific. ```rust window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255)); window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0)); window.circle(100, 100, 25, Color::rgb(0, 0, 0)); window.circle(100, 101, -25, Color::rgb(0, 255, 0)); window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80)); window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255)); window.line(0, 0, 200, 200, Color::rgb(255, 0, 0)); window.line(0, 200, 200, 0, Color::rgb(128, 255, 0)); // vertical and horizontal line test window.line(100, 0, 100, 200, Color::rgb(0, 0, 255)); window.line(0, 100, 200, 100, Color::rgb(255, 255, 0)); window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255)); window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255)); ``` ```rust // path and bezier curve example draw a cloud let mut cloud_path = GraphicsPath::new(); cloud_path.move_to(170, 80); cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150); cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150); cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100); cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50); cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50); cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80); window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255)); ``` ```rust // path and quadratic curve example draw a balloon let mut balloon_path = GraphicsPath::new(); balloon_path.move_to(75, 25); balloon_path.quadratic_curve_to(25, 25, 25, 62); balloon_path.quadratic_curve_to(25, 100, 50, 100); balloon_path.quadratic_curve_to(50, 120, 30, 125); balloon_path.quadratic_curve_to(60, 120, 65, 100); balloon_path.quadratic_curve_to(125, 100, 125, 62); balloon_path.quadratic_curve_to(125, 25, 75, 25); window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255)); ``` ```rust window.char(200, 200, '═', Color::rgb(0, 0, 0)); window.char(208, 200, '═', Color::rgb(0, 0, 0)); // testing for non existent x,y position : does not panic but returns Color(0,0,0,0) let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10); // testing PartialEq for Color if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) { println!("Testing colors: they are the same!") } else { println!("Testing colors: they are NOT the same!") } ``` ```rust //Draw a transparent rectangle over window content // default mode is Blend window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100)); //Draw an opaque rectangle replacing window content window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100)); //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2) window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1)); //Draw a transparent rectangle over window content window.mode().set(Mode::Blend); //set mode to Blend fron now on window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100)); ``` ```rust //Draw a blured box over window content window.box_blur(170, 100, 150, 150, 10); //Draw a shadow around a box window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255)); ``` ```rust println!( "Drawing took {}ms", (start.elapsed().as_micros() / 100) as f32 / 10.0 ); window.sync(); 'events: loop { for event in window.events() { match event.to_option() { EventOption::Quit(_quit_event) => break 'events, EventOption::Mouse(evt) => println!( "At position {:?} pixel color is : {:?}", (evt.x, evt.y), window.getpixel(evt.x, evt.y) ), event_option => println!("{:?}", event_option), } } } ``` -------------------------------- ### OrbClient Drawing and Graphics Example Source: https://docs.rs/orbclient/latest/orbclient/renderer/trait.Renderer.html?search=u32+-%3E+bool A comprehensive example demonstrating window creation, gradients, shapes, paths, and color operations. ```rust fn main() { let (width, height) = orbclient::get_display_size().unwrap(); let mut window = Window::new_flags( (width as i32) / 4, (height as i32) / 4, width / 2, height / 2, "TITLE", &[WindowFlag::Transparent], ) .unwrap(); let (win_w, win_h) = (width / 2, height / 2); let start = Instant::now(); // top left -> bottom right window.linear_gradient( 0, 0, win_w / 3, win_h, 0, 0, (win_w / 3) as i32, (win_h / 2) as i32, Color::rgb(128, 128, 128), Color::rgb(255, 255, 255), ); // horizontal gradient window.linear_gradient( (win_w / 3) as i32, 0, win_w / 3, win_h, (win_w / 3) as i32, 0, (2 * win_w / 3) as i32, 0, Color::rgb(128, 255, 255), Color::rgb(255, 255, 255), ); // vertical gradient window.linear_gradient( (2 * win_w / 3) as i32, 0, win_w / 3, win_h, (2 * win_w / 3) as i32, 0, (2 * win_w / 3) as i32, win_h as i32, Color::rgb(0, 128, 0), Color::rgb(255, 255, 255), ); window.arc(100, 100, -25, 1 << 0 | 1 << 2, Color::rgb(0, 0, 255)); window.arc(100, 100, -25, 1 << 1 | 1 << 3, Color::rgb(0, 255, 255)); window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255)); window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0)); window.circle(100, 100, 25, Color::rgb(0, 0, 0)); window.circle(100, 101, -25, Color::rgb(0, 255, 0)); window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80)); window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255)); window.line(0, 0, 200, 200, Color::rgb(255, 0, 0)); window.line(0, 200, 200, 0, Color::rgb(128, 255, 0)); // vertical and horizontal line test window.line(100, 0, 100, 200, Color::rgb(0, 0, 255)); window.line(0, 100, 200, 100, Color::rgb(255, 255, 0)); window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255)); window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255)); // path and bezier curve example draw a cloud let mut cloud_path = GraphicsPath::new(); cloud_path.move_to(170, 80); cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150); cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150); cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100); cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50); cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50); cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80); window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255)); // path and quadratic curve example draw a balloon let mut balloon_path = GraphicsPath::new(); balloon_path.move_to(75, 25); balloon_path.quadratic_curve_to(25, 25, 25, 62); balloon_path.quadratic_curve_to(25, 100, 50, 100); balloon_path.quadratic_curve_to(50, 120, 30, 125); balloon_path.quadratic_curve_to(60, 120, 65, 100); balloon_path.quadratic_curve_to(125, 100, 125, 62); balloon_path.quadratic_curve_to(125, 25, 75, 25); window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255)); window.char(200, 200, '═', Color::rgb(0, 0, 0)); window.char(208, 200, '═', Color::rgb(0, 0, 0)); // testing for non existent x,y position : does not panic but returns Color(0,0,0,0) let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10); // testing PartialEq for Color if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) { println!("Testing colors: they are the same!") } else { println!("Testing colors: they are NOT the same!") } //Draw a transparent rectangle over window content // default mode is Blend window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100)); //Draw an opaque rectangle replacing window content window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on ``` -------------------------------- ### Graphics drawing example in Rust (window.arc, circle, line, path, rect, etc.) Source: https://docs.rs/orbclient/latest/orbclient/color/struct.Color.html?search= A single Rust example (likely from a test or example program) that exercises many drawing primitives: arcs, circles, lines, bezier and quadratic paths (cloud and balloon), characters, pixel inspection, color comparison, rectangle modes (Blend/Overwrite), blur and shadow effects, and the event loop. The example runs inside a function that has access to 'window', 'width', 'height', 'start', and 'Color' types. ```rust window.arc(100, 100, -25, 1 << 4 | 1 << 6, Color::rgb(255, 0, 255)); window.arc(100, 100, -25, 1 << 5 | 1 << 7, Color::rgb(255, 255, 0)); window.circle(100, 100, 25, Color::rgb(0, 0, 0)); window.circle(100, 101, -25, Color::rgb(0, 255, 0)); window.circle(220, 220, -100, Color::rgba(128, 128, 128, 80)); window.wu_circle(150, 220, 100, Color::rgba(255, 0, 0, 255)); window.line(0, 0, 200, 200, Color::rgb(255, 0, 0)); window.line(0, 200, 200, 0, Color::rgb(128, 255, 0)); // vertical and horizontal line test window.line(100, 0, 100, 200, Color::rgb(0, 0, 255)); window.line(0, 100, 200, 100, Color::rgb(255, 255, 0)); window.wu_line(100, 220, 400, 250, Color::rgba(255, 0, 0, 255)); window.line(100, 230, 400, 260, Color::rgba(255, 0, 0, 255)); // path and bezier curve example draw a cloud let mut cloud_path = GraphicsPath::new(); cloud_path.move_to(170, 80); cloud_path.bezier_curve_to(130, 100, 130, 150, 230, 150); cloud_path.bezier_curve_to(250, 180, 320, 180, 340, 150); cloud_path.bezier_curve_to(420, 150, 420, 120, 390, 100); cloud_path.bezier_curve_to(430, 40, 370, 30, 340, 50); cloud_path.bezier_curve_to(320, 5, 250, 20, 250, 50); cloud_path.bezier_curve_to(200, 5, 150, 20, 170, 80); window.draw_path_stroke(cloud_path, Color::rgb(0, 0, 255)); // path and quadratic curve example draw a balloon let mut balloon_path = GraphicsPath::new(); balloon_path.move_to(75, 25); balloon_path.quadratic_curve_to(25, 25, 25, 62); balloon_path.quadratic_curve_to(25, 100, 50, 100); balloon_path.quadratic_curve_to(50, 120, 30, 125); balloon_path.quadratic_curve_to(60, 120, 65, 100); balloon_path.quadratic_curve_to(125, 100, 125, 62); balloon_path.quadratic_curve_to(125, 25, 75, 25); window.draw_path_stroke(balloon_path, Color::rgb(0, 0, 255)); window.char(200, 200, '═', Color::rgb(0, 0, 0)); window.char(208, 200, '═', Color::rgb(0, 0, 0)); // testing for non existent x,y position : does not panic but returns Color(0,0,0,0) let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10); // testing PartialEq for Color if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) { println!("Testing colors: they are the same!") } else { println!("Testing colors: they are NOT the same!") } //Draw a transparent rectangle over window content // default mode is Blend window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100)); //Draw an opaque rectangle replacing window content window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100)); //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2) window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1)); //Draw a transparent rectangle over window content window.mode().set(Mode::Blend); //set mode to Blend fron now on window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100)); //Draw a blured box over window content window.box_blur(170, 100, 150, 150, 10); //Draw a shadow around a box window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255)); println!( "Drawing took {}ms", (start.elapsed().as_micros() / 100) as f32 / 10.0 ); window.sync(); 'events: loop { for event in window.events() { match event.to_option() { EventOption::Quit(_quit_event) => break 'events, EventOption::Mouse(evt) => println!( "At position {:?} pixel color is : {:?}", (evt.x, evt.y), window.getpixel(evt.x, evt.y) ), event_option => println!("{:?}", event_option), } } } } ``` -------------------------------- ### last method example Source: https://docs.rs/orbclient/latest/orbclient/event/struct.Event.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example for the last method, returning the last element or None if empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&30), v.last()); let w: &[i32] = &[]; assert_eq!(None, w.last()); ``` -------------------------------- ### split_first method example Source: https://docs.rs/orbclient/latest/orbclient/event/struct.Event.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example for the split_first method, returning the first element and the rest of the slice, or None if empty. ```rust let x = &[0, 1, 2]; if let Some((first, elements)) = x.split_first() { assert_eq!(first, &0); assert_eq!(elements, &[1, 2]); } ``` -------------------------------- ### Draw characters with window.char in orbclient Source: https://docs.rs/orbclient/latest/orbclient/renderer/trait.Renderer.html?search= Example from examples/simple.rs (line 100) showing how to draw characters using window.char with a specified color. The snippet includes window setup and event handling, and demonstrates drawing characters at positions (200,200) and (208,200). ```rust fn main() { let (width, height) = orbclient::get_display_size().unwrap(); let mut window = Window::new_flags( (width as i32) / 4, (height as i32) / 4, width / 2, height / 2, "TITLE", &[WindowFlag::Transparent], ) .unwrap(); let (win_w, win_h) = (width / 2, height / 2); window.char(200, 200, '═', Color::rgb(0, 0, 0)); window.char(208, 200, '═', Color::rgb(0, 0, 0)); // testing for non existent x,y position : does not panic but returns Color(0,0,0,0) let _non_existent_pixel = window.getpixel(width as i32 + 10, height as i32 + 10); // testing PartialEq for Color if Color::rgb(11, 2, 3) == Color::rgba(1, 2, 3, 100) { println!("Testing colors: they are the same!") } else { println!("Testing colors: they are NOT the same!") } //Draw a transparent rectangle over window content // default mode is Blend window.rect(250, 200, 80, 80, Color::rgba(100, 100, 100, 100)); //Draw an opaque rectangle replacing window content window.mode().set(Mode::Overwrite); // set window drawing mode to Overwrite from now on window.rect(300, 220, 80, 80, Color::rgb(100, 100, 100)); //Draw a hole in the window replacing alpha channel (Only in Orbital, not in SDL2) window.rect(300, 100, 80, 80, Color::rgba(10, 10, 10, 1)); //Draw a transparent rectangle over window content window.mode().set(Mode::Blend); //set mode to Blend fron now on window.rect(200, 230, 80, 80, Color::rgba(100, 100, 100, 100)); //Draw a blured box over window content window.box_blur(170, 100, 150, 150, 10); //Draw a shadow around a box window.box_shadow(170, 100, 150, 150, 0, 0, 20, Color::rgba(0, 0, 0, 255)); println!( "Drawing took {}ms", (start.elapsed().as_micros() / 100) as f32 / 10.0 ); window.sync(); 'events: loop { for event in window.events() { match event.to_option() { EventOption::Quit(_quit_event) => break 'events, EventOption::Mouse(evt) => println!( "At position {:?} pixel color is : {:?}", (evt.x, evt.y), window.getpixel(evt.x, evt.y) ), event_option => println!("{:?}", event_option), } } } } ``` -------------------------------- ### Event Struct Usage Example Source: https://docs.rs/orbclient/latest/orbclient/event/struct.Event.html?search=u32+-%3E+bool Example code demonstrating how to handle events from a window, including quitting, mouse events, and retrieving pixel colors. ```APIDOC ## Event Struct Usage Example ### Description This example shows how to iterate over events from a window, handle quit and mouse events, and retrieve the pixel color at the mouse position. ### Code Example ```rust println!( "Drawing took {}ms", (start.elapsed().as_micros() / 100) as f32 / 10.0 ); window.sync(); 'events: loop { for event in window.events() { match event.to_option() { EventOption::Quit(_quit_event) => break 'events, EventOption::Mouse(evt) => println!( "At position {:?} pixel color is : {:?}", (evt.x, evt.y), window.getpixel(evt.x, evt.y) ), event_option => println!("{:?}", event_option), } } } ``` ``` -------------------------------- ### binary_search_by_key example Source: https://docs.rs/orbclient/latest/orbclient/event/struct.Event.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example for `binary_search_by_key` on a slice of pairs, searching by the second element. Shows found, not found, and multiple-match cases. ```rust let s = [(0, 0), (2, 1), (4, 1), (5, 1), (3, 1), (1, 2), (2, 3), (4, 5), (5, 8), (3, 13), (1, 21), (2, 34), (4, 55)]; assert_eq!(s.binary_search_by_key(&13, |&(a, b)| b), Ok(9)); assert_eq!(s.binary_search_by_key(&4, |&(a, b)| b), Err(7)); assert_eq!(s.binary_search_by_key(&100, |&(a, b)| b), Err(13)); let r = s.binary_search_by_key(&1, |&(a, b)| b); assert!(match r { Ok(1..=4) => true, _ => false, }); ``` -------------------------------- ### element_offset basic usage Source: https://docs.rs/orbclient/latest/orbclient/event/struct.Event.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Basic usage example for `element_offset`, showing how to get the index of an element reference. Returns `None` if the element does not point to the start of an element. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ```