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
138 changes: 138 additions & 0 deletions crates/processing_core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
pub const CORNER: &str = "corner";
pub const CORNERS: &str = "corners";
pub const RADIUS: &str = "radius";
pub const CENTER: &str = "center"; // also the middle mouse button

pub const ROUND: &str = "round"; // caps and joins
pub const SQUARE: &str = "square";
pub const PROJECT: &str = "project";
pub const MITER: &str = "miter";
pub const BEVEL: &str = "bevel";

pub const POLYGON: &str = "polygon";
pub const POINTS: &str = "points";
pub const LINES: &str = "lines";
pub const TRIANGLES: &str = "triangles";
pub const TRIANGLE_FAN: &str = "triangle_fan";
pub const TRIANGLE_STRIP: &str = "triangle_strip";
pub const QUADS: &str = "quads";
pub const QUAD_STRIP: &str = "quad_strip";
pub const LINE_STRIP: &str = "line_strip"; // geometry topology; no begin_shape equivalent

pub const OPEN: &str = "open";
pub const CHORD: &str = "chord";
pub const PIE: &str = "pie";
pub const CLOSE: bool = true;

pub const LEFT: &str = "left";
pub const RIGHT: &str = "right";

pub const NEAREST: &str = "nearest";
pub const CLAMP: &str = "clamp";
pub const REPEAT: &str = "repeat";
pub const MIRROR: &str = "mirror";

pub const SRGB: &str = "srgb";
pub const LINEAR: &str = "linear"; // also the Sampler filter
pub const HSL: &str = "hsl";
pub const HSV: &str = "hsv";
pub const HWB: &str = "hwb";
pub const OKLAB: &str = "oklab";
pub const OKLCH: &str = "oklch";
pub const LAB: &str = "lab";
pub const LCH: &str = "lch";
pub const XYZ: &str = "xyz";

pub const PI: f32 = std::f32::consts::PI;
pub const TWO_PI: f32 = std::f32::consts::TAU;
pub const HALF_PI: f32 = std::f32::consts::FRAC_PI_2;
pub const QUARTER_PI: f32 = std::f32::consts::FRAC_PI_4;
pub const TAU: f32 = std::f32::consts::TAU;
pub const DEG_TO_RAD: f32 = std::f32::consts::PI / 180.0;
pub const RAD_TO_DEG: f32 = 180.0 / std::f32::consts::PI;

// Key codes stay numeric (compared against `key_code`); values must match `key_code_to_u32`.

pub const KEY_A: u32 = 65;
pub const KEY_B: u32 = 66;
pub const KEY_C: u32 = 67;
pub const KEY_D: u32 = 68;
pub const KEY_E: u32 = 69;
pub const KEY_F: u32 = 70;
pub const KEY_G: u32 = 71;
pub const KEY_H: u32 = 72;
pub const KEY_I: u32 = 73;
pub const KEY_J: u32 = 74;
pub const KEY_K: u32 = 75;
pub const KEY_L: u32 = 76;
pub const KEY_M: u32 = 77;
pub const KEY_N: u32 = 78;
pub const KEY_O: u32 = 79;
pub const KEY_P: u32 = 80;
pub const KEY_Q: u32 = 81;
pub const KEY_R: u32 = 82;
pub const KEY_S: u32 = 83;
pub const KEY_T: u32 = 84;
pub const KEY_U: u32 = 85;
pub const KEY_V: u32 = 86;
pub const KEY_W: u32 = 87;
pub const KEY_X: u32 = 88;
pub const KEY_Y: u32 = 89;
pub const KEY_Z: u32 = 90;

pub const KEY_0: u32 = 48;
pub const KEY_1: u32 = 49;
pub const KEY_2: u32 = 50;
pub const KEY_3: u32 = 51;
pub const KEY_4: u32 = 52;
pub const KEY_5: u32 = 53;
pub const KEY_6: u32 = 54;
pub const KEY_7: u32 = 55;
pub const KEY_8: u32 = 56;
pub const KEY_9: u32 = 57;

pub const SPACE: u32 = 32;
pub const QUOTE: u32 = 39;
pub const COMMA: u32 = 44;
pub const MINUS: u32 = 45;
pub const PERIOD: u32 = 46;
pub const SLASH: u32 = 47;
pub const SEMICOLON: u32 = 59;
pub const EQUAL: u32 = 61;
pub const BRACKET_LEFT: u32 = 91;
pub const BACKSLASH: u32 = 92;
pub const BRACKET_RIGHT: u32 = 93;
pub const BACKQUOTE: u32 = 96;

pub const ESCAPE: u32 = 256;
pub const ENTER: u32 = 257;
pub const TAB: u32 = 258;
pub const BACKSPACE: u32 = 259;
pub const INSERT: u32 = 260;
pub const DELETE: u32 = 261;
pub const UP: u32 = 265;
pub const DOWN: u32 = 264;
pub const LEFT_ARROW: u32 = 263;
pub const RIGHT_ARROW: u32 = 262;
pub const PAGE_UP: u32 = 266;
pub const PAGE_DOWN: u32 = 267;
pub const HOME: u32 = 268;
pub const END: u32 = 269;

pub const SHIFT: u32 = 340;
pub const CONTROL: u32 = 341;
pub const ALT: u32 = 342;
pub const SUPER: u32 = 343;

pub const F1: u32 = 290;
pub const F2: u32 = 291;
pub const F3: u32 = 292;
pub const F4: u32 = 293;
pub const F5: u32 = 294;
pub const F6: u32 = 295;
pub const F7: u32 = 296;
pub const F8: u32 = 297;
pub const F9: u32 = 298;
pub const F10: u32 = 299;
pub const F11: u32 = 300;
pub const F12: u32 = 301;
1 change: 1 addition & 0 deletions crates/processing_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod config;
pub mod constants;
pub mod error;

use std::cell::RefCell;
Expand Down
96 changes: 96 additions & 0 deletions crates/processing_pyo3/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use processing::prelude::BlendMode;
use processing::prelude::constants as c;
use pyo3::prelude::*;
use pyo3::types::PyModule;

use crate::PyBlendMode;

macro_rules! add {
($m:expr, $($name:ident),+ $(,)?) => {
$( $m.add(stringify!($name), c::$name)?; )+
};
}

pub fn register(m: &Bound<'_, PyModule>) -> PyResult<()> {
add!(m, ROUND, SQUARE, PROJECT, MITER, BEVEL);
add!(
m,
POLYGON,
POINTS,
LINES,
TRIANGLES,
TRIANGLE_FAN,
TRIANGLE_STRIP,
QUADS,
QUAD_STRIP,
LINE_STRIP
);
add!(m, CORNER, CORNERS, CENTER, RADIUS);
add!(m, OPEN, CHORD, PIE, CLOSE);
add!(m, LEFT, RIGHT);
add!(m, NEAREST, CLAMP, REPEAT, MIRROR);
add!(m, SRGB, LINEAR, HSL, HSV, HWB, OKLAB, OKLCH, LAB, LCH, XYZ);
add!(
m, PI, TWO_PI, HALF_PI, QUARTER_PI, TAU, DEG_TO_RAD, RAD_TO_DEG
);

add!(
m, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L,
KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y,
KEY_Z
);
add!(
m, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9
);
add!(
m,
SPACE,
QUOTE,
COMMA,
MINUS,
PERIOD,
SLASH,
SEMICOLON,
EQUAL,
BRACKET_LEFT,
BACKSLASH,
BRACKET_RIGHT,
BACKQUOTE
);
add!(
m,
ESCAPE,
ENTER,
TAB,
BACKSPACE,
INSERT,
DELETE,
UP,
DOWN,
LEFT_ARROW,
RIGHT_ARROW,
PAGE_UP,
PAGE_DOWN,
HOME,
END
);
add!(m, SHIFT, CONTROL, ALT, SUPER);
add!(m, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12);

// Objects rather than strings, passed straight to blend_mode().
m.add("BLEND", PyBlendMode::from_preset(BlendMode::Blend))?;
m.add("ADD", PyBlendMode::from_preset(BlendMode::Add))?;
m.add("SUBTRACT", PyBlendMode::from_preset(BlendMode::Subtract))?;
m.add("DARKEST", PyBlendMode::from_preset(BlendMode::Darkest))?;
m.add("LIGHTEST", PyBlendMode::from_preset(BlendMode::Lightest))?;
m.add(
"DIFFERENCE",
PyBlendMode::from_preset(BlendMode::Difference),
)?;
m.add("EXCLUSION", PyBlendMode::from_preset(BlendMode::Exclusion))?;
m.add("MULTIPLY", PyBlendMode::from_preset(BlendMode::Multiply))?;
m.add("SCREEN", PyBlendMode::from_preset(BlendMode::Screen))?;
m.add("REPLACE", PyBlendMode::from_preset(BlendMode::Replace))?;

Ok(())
}
Loading
Loading