From: Ian Jackson Date: Fri, 15 Apr 2022 19:17:57 +0000 (+0100) Subject: dice: Use bespoke outline path for surround (selection) X-Git-Tag: otter-1.1.0~556 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=cb6aeac08c835e273470ae56c76a5a7d610162de;p=otter.git dice: Use bespoke outline path for surround (selection) Signed-off-by: Ian Jackson --- diff --git a/src/dice.rs b/src/dice.rs index 4f8b6a50..e64bb5f4 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -54,7 +54,7 @@ struct Die { itemname: String, labels: IndexVec, // if .len()==1, always use [0] image: Arc, // if image.nfaces()==1, always use face 0 - outline: CircleShape, + surround_outline: CircleShape, cooldown_radius: f64, cooldown_time: Duration, } @@ -139,7 +139,7 @@ impl PieceSpec for Spec { } else { throw!(SpecError::InvalidSizeScale) }; - let outline = CircleShape { diam: radius * 2. }; + let surround_outline = CircleShape { diam: radius * 2. }; let cooldown_radius = radius + COOLDOWN_EXTRA_RADIUS; let cooldown_time = { @@ -188,7 +188,7 @@ impl PieceSpec for Spec { .into(); let our_occ_image = Arc::new(Die { - nfaces, cooldown_time, cooldown_radius, outline, + nfaces, cooldown_time, cooldown_radius, surround_outline, itemname: itemname.clone(), image: image_occ_image, labels: index_vec![occ_label.into()], @@ -199,7 +199,7 @@ impl PieceSpec for Spec { }; let die = Die { - nfaces, cooldown_time, cooldown_radius, outline, + nfaces, cooldown_time, cooldown_radius, surround_outline, itemname, labels, image: image.into() }; @@ -255,8 +255,16 @@ impl Die { #[dyn_upcast] impl OutlineTrait for Die { + // We have done our own adjustable radius adjustment, so we + // apply that to surround_outline's outline_path, rather than its + // surround_path. + #[throws(IE)] + fn surround_path(&self) -> Html { self.surround_outline.outline_path(1.0)? } + delegate! { - to self.outline { + to self.image { + // `outline_path` won't be called at all, + // since we provide `surround_path` fn outline_path(&self, scale: f64) -> Result; fn thresh_dragraise(&self) -> Result, IE>; fn bbox_approx(&self) -> Result; diff --git a/src/gamestate.rs b/src/gamestate.rs index 405b53b0..70971e5b 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -154,6 +154,7 @@ pub trait OutlineTrait: Debug + Sync + Send + 'static { // This is used: // 1. To generate the path for SimpleShape's renderings // 2. This call here in the default impl of surround_path + // 3. Things that use an Outline to represent a surround (eg dice.rs) fn outline_path(&self, scale: f64) -> Result; // Used for the piece selection outline fn surround_path(&self) -> Result {