|
1 | 1 | use crate::messages::input_mapper::utility_types::misc::ActionKeys; |
2 | 2 | use crate::messages::layout::utility_types::widget_prelude::*; |
3 | 3 | use derivative::*; |
4 | | -use glam::DVec2; |
5 | 4 | use graphene_core::Color; |
6 | 5 | use graphene_core::raster::curve::Curve; |
| 6 | +use graphene_std::transform::ReferencePoint; |
7 | 7 | use graphite_proc_macros::WidgetBuilder; |
8 | 8 |
|
9 | 9 | #[derive(Clone, Derivative, serde::Serialize, serde::Deserialize, WidgetBuilder, specta::Type)] |
@@ -411,100 +411,18 @@ pub struct CurveInput { |
411 | 411 |
|
412 | 412 | #[derive(Clone, Default, Derivative, serde::Serialize, serde::Deserialize, WidgetBuilder, specta::Type)] |
413 | 413 | #[derivative(Debug, PartialEq)] |
414 | | -pub struct PivotInput { |
| 414 | +pub struct ReferencePointInput { |
415 | 415 | #[widget_builder(constructor)] |
416 | | - pub position: PivotPosition, |
| 416 | + pub value: ReferencePoint, |
417 | 417 |
|
418 | 418 | pub disabled: bool, |
419 | 419 |
|
420 | 420 | // Callbacks |
421 | 421 | #[serde(skip)] |
422 | 422 | #[derivative(Debug = "ignore", PartialEq = "ignore")] |
423 | | - pub on_update: WidgetCallback<PivotInput>, |
| 423 | + pub on_update: WidgetCallback<ReferencePointInput>, |
424 | 424 |
|
425 | 425 | #[serde(skip)] |
426 | 426 | #[derivative(Debug = "ignore", PartialEq = "ignore")] |
427 | 427 | pub on_commit: WidgetCallback<()>, |
428 | 428 | } |
429 | | - |
430 | | -#[derive(Clone, Copy, serde::Serialize, serde::Deserialize, Debug, Default, PartialEq, Eq, specta::Type)] |
431 | | -pub enum PivotPosition { |
432 | | - #[default] |
433 | | - None, |
434 | | - TopLeft, |
435 | | - TopCenter, |
436 | | - TopRight, |
437 | | - CenterLeft, |
438 | | - Center, |
439 | | - CenterRight, |
440 | | - BottomLeft, |
441 | | - BottomCenter, |
442 | | - BottomRight, |
443 | | -} |
444 | | - |
445 | | -impl From<&str> for PivotPosition { |
446 | | - fn from(input: &str) -> Self { |
447 | | - match input { |
448 | | - "None" => PivotPosition::None, |
449 | | - "TopLeft" => PivotPosition::TopLeft, |
450 | | - "TopCenter" => PivotPosition::TopCenter, |
451 | | - "TopRight" => PivotPosition::TopRight, |
452 | | - "CenterLeft" => PivotPosition::CenterLeft, |
453 | | - "Center" => PivotPosition::Center, |
454 | | - "CenterRight" => PivotPosition::CenterRight, |
455 | | - "BottomLeft" => PivotPosition::BottomLeft, |
456 | | - "BottomCenter" => PivotPosition::BottomCenter, |
457 | | - "BottomRight" => PivotPosition::BottomRight, |
458 | | - _ => panic!("Failed parsing unrecognized PivotPosition enum value '{input}'"), |
459 | | - } |
460 | | - } |
461 | | -} |
462 | | - |
463 | | -impl From<PivotPosition> for Option<DVec2> { |
464 | | - fn from(input: PivotPosition) -> Self { |
465 | | - match input { |
466 | | - PivotPosition::None => None, |
467 | | - PivotPosition::TopLeft => Some(DVec2::new(0., 0.)), |
468 | | - PivotPosition::TopCenter => Some(DVec2::new(0.5, 0.)), |
469 | | - PivotPosition::TopRight => Some(DVec2::new(1., 0.)), |
470 | | - PivotPosition::CenterLeft => Some(DVec2::new(0., 0.5)), |
471 | | - PivotPosition::Center => Some(DVec2::new(0.5, 0.5)), |
472 | | - PivotPosition::CenterRight => Some(DVec2::new(1., 0.5)), |
473 | | - PivotPosition::BottomLeft => Some(DVec2::new(0., 1.)), |
474 | | - PivotPosition::BottomCenter => Some(DVec2::new(0.5, 1.)), |
475 | | - PivotPosition::BottomRight => Some(DVec2::new(1., 1.)), |
476 | | - } |
477 | | - } |
478 | | -} |
479 | | - |
480 | | -impl From<DVec2> for PivotPosition { |
481 | | - fn from(input: DVec2) -> Self { |
482 | | - const TOLERANCE: f64 = 1e-5_f64; |
483 | | - if input.y.abs() < TOLERANCE { |
484 | | - if input.x.abs() < TOLERANCE { |
485 | | - return PivotPosition::TopLeft; |
486 | | - } else if (input.x - 0.5).abs() < TOLERANCE { |
487 | | - return PivotPosition::TopCenter; |
488 | | - } else if (input.x - 1.).abs() < TOLERANCE { |
489 | | - return PivotPosition::TopRight; |
490 | | - } |
491 | | - } else if (input.y - 0.5).abs() < TOLERANCE { |
492 | | - if input.x.abs() < TOLERANCE { |
493 | | - return PivotPosition::CenterLeft; |
494 | | - } else if (input.x - 0.5).abs() < TOLERANCE { |
495 | | - return PivotPosition::Center; |
496 | | - } else if (input.x - 1.).abs() < TOLERANCE { |
497 | | - return PivotPosition::CenterRight; |
498 | | - } |
499 | | - } else if (input.y - 1.).abs() < TOLERANCE { |
500 | | - if input.x.abs() < TOLERANCE { |
501 | | - return PivotPosition::BottomLeft; |
502 | | - } else if (input.x - 0.5).abs() < TOLERANCE { |
503 | | - return PivotPosition::BottomCenter; |
504 | | - } else if (input.x - 1.).abs() < TOLERANCE { |
505 | | - return PivotPosition::BottomRight; |
506 | | - } |
507 | | - } |
508 | | - PivotPosition::None |
509 | | - } |
510 | | -} |
0 commit comments