|
11 | 11 | mod glfw; |
12 | 12 | mod graphics; |
13 | 13 |
|
14 | | -use graphics::{Graphics, get_graphics, get_graphics_mut}; |
15 | | -use pyo3::{exceptions::PyRuntimeError, prelude::*}; |
| 14 | +use graphics::{Graphics, Image, get_graphics, get_graphics_mut}; |
| 15 | +use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyTuple}; |
16 | 16 |
|
17 | 17 | use std::env; |
18 | 18 |
|
19 | 19 | #[pymodule] |
20 | 20 | fn processing(m: &Bound<'_, PyModule>) -> PyResult<()> { |
21 | 21 | m.add_class::<Graphics>()?; |
| 22 | + m.add_class::<Image>()?; |
22 | 23 | m.add_function(wrap_pyfunction!(size, m)?)?; |
23 | 24 | m.add_function(wrap_pyfunction!(run, m)?)?; |
24 | 25 | m.add_function(wrap_pyfunction!(background, m)?)?; |
@@ -98,8 +99,13 @@ fn run(module: &Bound<'_, PyModule>) -> PyResult<()> { |
98 | 99 |
|
99 | 100 | #[pyfunction] |
100 | 101 | #[pyo3(pass_module, signature = (*args))] |
101 | | -fn background(module: &Bound<'_, PyModule>, args: Vec<f32>) -> PyResult<()> { |
102 | | - get_graphics(module)?.background(args) |
| 102 | +fn background(module: &Bound<'_, PyModule>, args: &Bound<'_, PyTuple>) -> PyResult<()> { |
| 103 | + let first = args.get_item(0)?; |
| 104 | + if first.is_instance_of::<Image>() { |
| 105 | + get_graphics(module)?.background_image(first.extract::<Image>()?) |
| 106 | + } else { |
| 107 | + get_graphics(module)?.background(args.extract()?) |
| 108 | + } |
103 | 109 | } |
104 | 110 |
|
105 | 111 | #[pyfunction] |
@@ -150,6 +156,6 @@ fn rect( |
150 | 156 |
|
151 | 157 | #[pyfunction] |
152 | 158 | #[pyo3(pass_module, signature = (image_file))] |
153 | | -fn image(module: &Bound<'_, PyModule>, image_file: &str) -> PyResult<()> { |
| 159 | +fn image(module: &Bound<'_, PyModule>, image_file: &str) -> PyResult<Image> { |
154 | 160 | get_graphics(module)?.image(image_file) |
155 | 161 | } |
0 commit comments