Struct simple_pixels::Context

source ·
pub struct Context<'a> { /* private fields */ }
Expand description

An object that holds the app’s global state.

Implementations§

source§

impl<'a> Context<'a>

source

pub fn width(&self) -> u32

Display width.

Does not account for dpi scale.

source

pub fn height(&self) -> u32

Display height.

Does not account for dpi scale.

source

pub fn dpi_scale(&self) -> f32

The dpi scaling factor (window pixels to framebuffer pixels). See https://docs.rs/miniquad/0.3.16/miniquad/conf/index.html#high-dpi-rendering for details.

Always 1.0 if high_dpi in Config is set to false.

source

pub fn delta_time(&self) -> Duration

Time passed between previous and current frame.

source

pub fn clear_color(&mut self, color: RGBA8)

Set clear/background color.

The buffer isn’t cleared automatically, use Context::clear() for that.

source

pub fn get_key_state(&self, key: KeyCode) -> Option<InputState>

Returns current input state of a key or None if it isn’t held.

Note that InputState::Released means that the key has just been released, not that it isn’t held.

source

pub fn is_key_down(&self, key: KeyCode) -> bool

Returns true if a key is down.

source

pub fn is_key_pressed(&self, key: KeyCode) -> bool

Returns true if a key has just been pressed.

source

pub fn is_key_released(&self, key: KeyCode) -> bool

Returns true if a key has just been released.

source

pub fn get_key_mods(&self) -> KeyMods

Returns currently held key modifiers.

source

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

Returns current mouse position.

Note that it does not account for dpi scale.

source

pub fn get_mouse_pos_int(&self) -> (i32, i32)

Returns current mouse position rounded to the nearest integer.

Note that it does not account for dpi scale.

source

pub fn get_mouse_button_state(&self, button: MouseButton) -> Option<InputState>

Returns current input state of a mouse button or None if it isn’t held.

Note that InputState::Released means that the key has just been released, not that it isn’t held.

source

pub fn is_mouse_button_down(&self, button: MouseButton) -> bool

Returns true if a mouse button is down.

source

pub fn is_mouse_button_pressed(&self, button: MouseButton) -> bool

Returns true if a mouse button has just been pressed.

source

pub fn is_mouse_button_released(&self, button: MouseButton) -> bool

Returns true if a mouse button has just been released.

source

pub fn quit(&mut self)

Quit the application.

source

pub fn show_mouse(&mut self, shown: bool)

Show or hide the mouse cursor.

source

pub fn set_mouse_cursor(&mut self, cursor_icon: CursorIcon)

Set the mouse cursor icon.

source

pub fn set_fullscreen(&mut self, fullscreen: bool)

Set window to fullscreen or not.

source

pub fn get_clipboard(&mut self) -> Option<String>

Get current OS clipboard value.

source

pub fn set_clipboard(&mut self, data: &str)

Save value to OS clipboard.

source

pub fn set_window_size(&mut self, new_width: u32, new_height: u32)

Set the application’s window size.

Note that it clears the screen buffer with the current Context::clear_color(), because it needs to be resized as well.

source

pub fn clear(&mut self)

Clear the screen buffer with the current Context::clear_color().

source

pub fn draw_pixel(&mut self, x: i32, y: i32, color: RGBA8)

Draw a pixels at (x, y).

Does nothing if the position is outside the screen.

source

pub fn draw_rect( &mut self, x: i32, y: i32, width: u32, height: u32, color: RGBA8 )

Draw a colored rectangle.

Does not panic if a part of the rectangle isn’t on screen, just draws the part that is.

source

pub fn draw_pixels( &mut self, x: i32, y: i32, width: u32, height: u32, pixels: &[RGBA8], opts: BlitOptions )

Fills a rectangle with provided pixels (row-major order).

Does not panic if a part of the rectangle isn’t on screen, just draws the part that is.

source

pub fn draw_screen(&mut self, pixels: &[RGBA8], opts: BlitOptions)

Fills the entire screen buffer at once.

Does not panic if a part of the rectangle isn’t on screen, just draws the part that is.

source

pub fn get_draw_buffer(&self) -> &[RGBA8]

Returns the screen buffer.

source

pub fn get_mut_draw_buffer(&mut self) -> &mut [RGBA8]

Returns the screen buffer.

Can be used for drawing.

source

pub fn set_filter_mode(&mut self, filter: FilterMode)

Sets the filter mode.

The default one is nearest.

Trait Implementations§

source§

impl<'a> Buffer<RGBA<u8>> for Context<'a>

source§

fn width(&self) -> u32

Buffer width
source§

fn height(&self) -> u32

Buffer height
source§

fn get(&self, x: u32, y: u32) -> &RGBA8

Get a value at (x, y). This function must not panic when x < self.width() && y < self.height() (unless you want blit functions to panic). It will not be called with values outside of that range.
source§

impl<'a> BufferMut<RGBA<u8>> for Context<'a>

source§

fn get_mut(&mut self, x: u32, y: u32) -> &mut RGBA8

Get a mutable value at (x, y). This function must not panic when x < self.width() && y < self.height() (unless you want blit functions to panic). It will not be called with values outside of that range.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Context<'a>

§

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

§

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

§

impl<'a> Unpin for Context<'a>

§

impl<'a> !UnwindSafe for Context<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

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

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

Performs the conversion.