Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions crates/processing_pyo3/examples/background_image.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from processing import *

i = None

def setup():
global i
size(800, 600)
i = image("images/logo.png")


def draw():
global i
background(220, 100, 24)
# i = image("images/logo.png")
background(i)


Expand Down
15 changes: 7 additions & 8 deletions crates/processing_pyo3/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ impl Drop for Surface {
}

#[pyclass]
#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct Image {
entity: Entity,
}

// TODO: we lose the image if this is implemented, meaning that the image is getting dropped prematurely
// impl Drop for Image {
// fn drop(&mut self) {
// let _ = image_destroy(self.entity);
// }
// }
impl Drop for Image {
fn drop(&mut self) {
let _ = image_destroy(self.entity);
}
}

#[pyclass(unsendable)]
pub struct Graphics {
Expand Down Expand Up @@ -84,7 +83,7 @@ impl Graphics {
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn background_image(&self, image: Image) -> PyResult<()> {
pub fn background_image(&self, image: &Image) -> PyResult<()> {
graphics_record_command(self.entity, DrawCommand::BackgroundImage(image.entity))
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_pyo3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn run(module: &Bound<'_, PyModule>) -> PyResult<()> {
fn background(module: &Bound<'_, PyModule>, args: &Bound<'_, PyTuple>) -> PyResult<()> {
let first = args.get_item(0)?;
if first.is_instance_of::<Image>() {
get_graphics(module)?.background_image(first.extract::<Image>()?)
get_graphics(module)?.background_image(&*first.extract::<PyRef<Image>>()?)
} else {
get_graphics(module)?.background(args.extract()?)
}
Expand Down