Struct passpartout_printer::easel::Easel
source · [−]pub struct Easel {
pub mouse: Enigo,
pub mouse_wait: Duration,
pub easel_coords: EaselCoords,
pub orientation: Orientation,
pub brush_size: i32,
pub current_color: PaletteColor,
pub current_tool: Tool,
}
Expand description
A structure keeping track of the current state of the easel and provides means to change the state of the easel via mouse clicks.
Fields
mouse: Enigo
The object for manipulating the mouse.
mouse_wait: Duration
The amount of time to wait between mouse moves and clicks.
easel_coords: EaselCoords
A mapping of where elements of the easel are in screen coordinates.
orientation: Orientation
The current orientation of the easel: landscape or portrait.
brush_size: i32
The current brush size.
current_color: PaletteColor
The active color of the brush.
current_tool: Tool
The active tool for drawing.
Implementations
sourceimpl Easel
impl Easel
sourcepub fn new(
path: String,
mouse: Enigo,
mouse_wait: Duration
) -> Result<Easel, Box<dyn Error>>
pub fn new(
path: String,
mouse: Enigo,
mouse_wait: Duration
) -> Result<Easel, Box<dyn Error>>
Create a new easel. When creating a new easel, it’s important to set the mouse wait properly. If you start seeing lines being drawn from the easel towards the color palette, you likely need to increase the mouse wait time.
Initial experimentation has shown that, regardless of FPS, anything lower than 6 ms causes the game to not recognize that the mouse button has been released and will make many, many mistakes in drawing.
Arguments
path
: Path to the JSON file containing the coordinates of easel elements in-game.mouse
: An Enigo structure used to manipulate the mouse position.mouse_wait
: The time to wait between mouse operations.
sourcepub fn change_orientation(&mut self)
pub fn change_orientation(&mut self)
Toggles the orientation of the easel.
sourcepub fn change_tool(&mut self, tool: Tool)
pub fn change_tool(&mut self, tool: Tool)
Changes the current tool.
sourcepub fn get_bounds(&self) -> (Coord, Coord)
pub fn get_bounds(&self) -> (Coord, Coord)
Returns the current bounds of the easel in screen coordinates.
sourcepub fn change_color(&mut self, color: &PaletteColor)
pub fn change_color(&mut self, color: &PaletteColor)
Changes from the current color to the desired color. Does nothing if the current color is the same as the desired color.
sourcepub fn change_brush_size(&mut self, brush_size: i32)
pub fn change_brush_size(&mut self, brush_size: i32)
Changes the brush size in fixed steps by clicking on the brushes to increase or decrease the size.
Arguments
brush_size
- The size from 0 toNUM_BRUSH_STEPS
to change the brush size to.
Example
use enigo::*;
use passpartout_printer::easel::Easel;
use std::time::Duration;
use std::error::Error;
let mut easel = Easel::new("coords.json".into(), Enigo::new(), Duration::from_millis(6))?;
easel.change_brush_size(0); // shrinks the brush to its minimum size
sourcepub fn draw_line(
&mut self,
start_line: Coord,
end_line: Coord,
color: &PaletteColor
) -> Result<(), Box<dyn Error>>
pub fn draw_line(
&mut self,
start_line: Coord,
end_line: Coord,
color: &PaletteColor
) -> Result<(), Box<dyn Error>>
Draws a line on the easel of the particular color.
Arguments
start_line
: The starting point of the line in image coordinates.end_line
: The end point of the line in image coordinates.color
: The color of the line.
Example
use passpartout_printer::{
easel::Easel,
coords::Coord,
colors::PaletteColor,
};
use enigo::*;
use std::time::Duration;
use image::Rgba;
use std::error::Error;
// Draw a black diagonal line from the upper-left corner
// 100 pixels away.
let mut easel = Easel::new("coords.json".into(), Enigo::new(), Duration::from_millis(6))?;
let color = PaletteColor::Black;
let start = Coord::new(0, 0);
let end = Coord::new(100, 100);
easel.draw_line(start, end, &color);
sourcepub fn draw_shape(
&mut self,
points: &[Coord],
color: &PaletteColor,
close_shape: bool,
fill: bool
) -> Result<(), Box<dyn Error>>
pub fn draw_shape(
&mut self,
points: &[Coord],
color: &PaletteColor,
close_shape: bool,
fill: bool
) -> Result<(), Box<dyn Error>>
Draws an arbitrary shape to the easel. This draws the shape as one continuous stroke.
Arguments
points
: The points defining the polygon.color
: The color of the shape.close_shape
: Whether or not to connect the first and last points.fill
: Whether or not to fill the shape. Implies close_shape.
Auto Trait Implementations
impl RefUnwindSafe for Easel
impl Send for Easel
impl Sync for Easel
impl Unpin for Easel
impl UnwindSafe for Easel
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more