chiark / gitweb /
rework trait outline etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Jul 2020 14:20:49 +0000 (15:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Jul 2020 14:20:49 +0000 (15:20 +0100)
src/gamestate.rs
src/pieces.rs

index b614abc2e29529cffd770be857b6119528e7e5d9..a96d6e9b5d165bf015a14be1cd9fda19ff718d5a 100644 (file)
@@ -66,7 +66,8 @@ pub struct LogEntry {
 
 pub trait Piece : Send + Debug {
   fn svg_piece(&self, pri : &PieceRenderInstructions) -> String;
-  fn svg_select(&self, pri : &PieceRenderInstructions) -> String;
+  fn outline_path(&self, pri : &PieceRenderInstructions) -> String;
+  fn surround_path(&self, pri : &PieceRenderInstructions) -> String;
   fn svg_x_ids(&self) -> VisiblePieceIdSvgIds;
   fn svg_x_defs(&self, pri : &PieceRenderInstructions) -> String;
   fn thresh_dragraise(&self, pri : &PieceRenderInstructions)
@@ -140,9 +141,9 @@ impl PieceState {
            pri.id_piece(),
            dragraise,
            pr.p.svg_piece(&pri)).unwrap();
-    write!(defs, r##"<g id="{}" stroke="black" fill="none">{}</g>"##,
+    write!(defs, r##"<path id="{}" stroke="black" fill="none" d="{}"/>"##,
            pri.id_select(),
-           pr.p.svg_select(&pri)).unwrap();
+           pr.p.surround_path(&pri)).unwrap();
     write!(defs, "{}", pr.p.svg_x_defs(&pri)).unwrap();
     defs
   }
index eef2404744a0bd04c90d0f742f4e0d776762c15b..47093ddc17ac456387227a75d747577d3354d837 100644 (file)
@@ -82,22 +82,29 @@ eprintln!("rescaled by {}: {} as {}",scale,&input,&out);
 
 impl Piece for SimpleShape {
   fn svg_piece(&self, pri : &PieceRenderInstructions) -> String {
-    format!(r##"<use fill="{}" href="#{}"/>"##,
-            self.colours[pri.face],
-            pri.id_x("base"))
+    format!(r##"<path fill="{}" d="{}"/>"##,
+            self.colours[pri.face], self.path)
   }
-  fn thresh_dragraise(&self, _pri : &PieceRenderInstructions)
-                      -> Option<Coord> {
-    Some(self.approx_dia / 2)
+  fn outline_path(&self, _pri : &PieceRenderInstructions) -> String {
+    self.path.clone()
+  }
+  fn surround_path(&self, _pri : &PieceRenderInstructions) -> String {
+    self.scaled_path.clone()
   }
+  /*
   fn svg_select(&self, pri : &PieceRenderInstructions) -> String {
     format!(r##"<g transform="scale({})"><use href="#{}"/></g>"##,
             SELECT_SCALE,
             pri.id_x("base"))
   }
+*/
+  fn thresh_dragraise(&self, _pri : &PieceRenderInstructions)
+                      -> Option<Coord> {
+    Some(self.approx_dia / 2)
+  }
   fn svg_x_ids(&self) -> VisiblePieceIdSvgIds { &["base"] }
-  fn svg_x_defs(&self, pri : &PieceRenderInstructions) -> String {
-    format!(r#"<path id={} d="{}"></path>"#, pri.id_x("base"), self.path)
+  fn svg_x_defs(&self, _pri : &PieceRenderInstructions) -> String {
+    "".to_owned()
   }
   fn describe_html(&self, face : Option<FaceId>) -> String {
     if let Some(face) = face {