still in dev pyglet_rs

This commit is contained in:
shenjack 2023-03-28 19:23:41 +08:00
parent 1e4fcb48e9
commit 2abd346059
4 changed files with 35 additions and 8 deletions

View File

@ -14,10 +14,35 @@ if TYPE_CHECKING:
def get_version_str() -> str: ...
class Sprite_rs(EventDispatcher):
...
class Sprite_rs(EventDispatcher): ...
class Vector2_rs: ...
class Vector3_rs: ...
class Vector4_rs: ...
class Matrix3_rs: ...
class Matrix4_rs: ...
def patch_sprite():
from pyglet import sprite
sprite.Sprite = Sprite_rs
def patch_vector():
from pyglet import math
math.Vector2 = Vector2_rs
math.Vector3 = Vector3_rs
math.Vector4 = Vector4_rs
def patch_matrix():
from pyglet import math
math.Matrix3 = Matrix3_rs
math.Matrix4 = Matrix4_rs
def patch_all():
patch_sprite()
patch_vector()
patch_matrix()

View File

@ -22,5 +22,7 @@ fn get_version_str() -> String {
fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(get_version_str, m)?)?;
m.add_class::<sprite::Sprite>()?;
// vector
m.add_class::<pymath::python_class::PyVector2>()?;
Ok(())
}

View File

@ -12,27 +12,27 @@ pub mod python_class {
use crate::math::matrix::{Matrix3, Matrix4};
use crate::math::vector::{Vector2, Vector3, Vector4, VectorTrait};
#[pyclass(name = "Vector2")]
#[pyclass(name = "Vector2_rs")]
pub struct PyVector2 {
pub data: Vector2,
}
#[pyclass(name = "Vector3")]
#[pyclass(name = "Vector3_rs")]
pub struct PyVector3 {
pub data: Vector3,
}
#[pyclass(name = "Vector4")]
#[pyclass(name = "Vector4_rs")]
pub struct PyVector4 {
pub data: Vector4,
}
#[pyclass(name = "Matrix3")]
#[pyclass(name = "Matrix3_rs")]
pub struct PyMatrix3 {
pub data: Matrix3,
}
#[pyclass(name = "Matrix4")]
#[pyclass(name = "Matrix4_rs")]
pub struct PyMatrix4 {
pub data: Matrix4,
}

View File

@ -8,7 +8,7 @@
use pyo3::intern;
use pyo3::prelude::*;
use pyo3::types::PyDict;
// use pyo3::types::PyDict;
/// Instance of an on-screen image
/// See the module documentation for usage.