Skip to content

Commit 3ab8865

Browse files
committed
Docs.
1 parent 2df5e3f commit 3ab8865

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

crates/processing_pyo3/src/graphics.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,13 +807,25 @@ impl Graphics {
807807
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
808808
}
809809

810+
/// Loads an image from a file and returns an Image object.
811+
///
812+
/// The path is relative to the sketch's assets directory.
810813
pub fn load_image(&self, file: &str) -> PyResult<Image> {
811814
match image_load(file) {
812815
Ok(image) => Ok(Image { entity: image }),
813816
Err(e) => Err(PyRuntimeError::new_err(format!("{e}"))),
814817
}
815818
}
816819

820+
/// Draws an image to the screen.
821+
///
822+
/// Optional `d_width` and `d_height` resize the image on screen. If omitted,
823+
/// the image's original dimensions are used.
824+
///
825+
/// Optional `sx`, `sy`, `s_width`, and `s_height` define a sub-region
826+
/// of the source image to draw, specified in pixels.
827+
///
828+
/// Affected by `image_mode()`, `tint()`, and the current transform.
817829
#[pyo3(signature = (source, dx, dy, d_width=None, d_height=None, sx=None, sy=None, s_width=None, s_height=None))]
818830
pub fn image(
819831
&self,
@@ -844,6 +856,10 @@ impl Graphics {
844856
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
845857
}
846858

859+
/// Sets a tint color applied when drawing images.
860+
///
861+
/// Accepts the same color arguments as `fill()`. The tint is multiplied
862+
/// with the image's pixel colors. Use `no_tint()` to remove.
847863
#[pyo3(signature = (*args))]
848864
pub fn tint(&self, args: &Bound<'_, PyTuple>) -> PyResult<()> {
849865
let color = extract_color_with_mode(
@@ -855,11 +871,17 @@ impl Graphics {
855871
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
856872
}
857873

874+
/// Removes the current tint color so images draw without color modification.
858875
pub fn no_tint(&self) -> PyResult<()> {
859876
graphics_record_command(self.entity, DrawCommand::NoTint)
860877
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
861878
}
862879

880+
/// Changes how image position arguments are interpreted.
881+
///
882+
/// - `CORNER` (default) — `dx`, `dy` is the top-left corner.
883+
/// - `CORNERS` — `dx`, `dy` and `d_width`, `d_height` are opposite corners.
884+
/// - `CENTER` — `dx`, `dy` is the center of the image.
863885
pub fn image_mode(&self, mode: u8) -> PyResult<()> {
864886
graphics_record_command(
865887
self.entity,

crates/processing_pyo3/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ mod mewnala {
13761376
graphics!(module).rect(x, y, w, h, tl, tr, br, bl)
13771377
}
13781378

1379+
/// Loads an image from a file and returns an Image object.
13791380
#[pyfunction]
13801381
#[pyo3(pass_module, signature = (image_file))]
13811382
fn load_image(module: &Bound<'_, PyModule>, image_file: &str) -> PyResult<Image> {
@@ -1384,6 +1385,11 @@ mod mewnala {
13841385
graphics.load_image(image_file)
13851386
}
13861387

1388+
/// Draws an image to the screen.
1389+
///
1390+
/// Optional `d_width`/`d_height` resize on screen; defaults to the image's
1391+
/// original dimensions. Optional `sx`/`sy`/`s_width`/`s_height` select a
1392+
/// sub-region of the source image in pixels.
13871393
#[pyfunction]
13881394
#[pyo3(pass_module, signature = (source, dx, dy, d_width=None, d_height=None, sx=None, sy=None, s_width=None, s_height=None))]
13891395
#[allow(clippy::too_many_arguments)]
@@ -1402,18 +1408,25 @@ mod mewnala {
14021408
graphics!(module).image(source, dx, dy, d_width, d_height, sx, sy, s_width, s_height)
14031409
}
14041410

1411+
/// Sets a tint color applied when drawing images.
14051412
#[pyfunction]
14061413
#[pyo3(pass_module, signature = (*args))]
14071414
fn tint(module: &Bound<'_, PyModule>, args: &Bound<'_, PyTuple>) -> PyResult<()> {
14081415
graphics!(module).tint(args)
14091416
}
14101417

1418+
/// Removes the current tint so images draw without color modification.
14111419
#[pyfunction]
14121420
#[pyo3(pass_module)]
14131421
fn no_tint(module: &Bound<'_, PyModule>) -> PyResult<()> {
14141422
graphics!(module).no_tint()
14151423
}
14161424

1425+
/// Changes how image position arguments are interpreted.
1426+
///
1427+
/// - `CORNER` (default) — `dx`, `dy` is the top-left corner.
1428+
/// - `CENTER` — `dx`, `dy` is the center.
1429+
/// - `CORNERS` — `dx`, `dy` and `d_width`, `d_height` are opposite corners.
14171430
#[pyfunction]
14181431
#[pyo3(pass_module)]
14191432
fn image_mode(module: &Bound<'_, PyModule>, mode: u8) -> PyResult<()> {

0 commit comments

Comments
 (0)