Browse Source

Drawing and selection of bones

master
Macoy Madson 1 year ago
parent
commit
b533363b95
  1. 21
      data/TestPuppet.svg
  2. 9
      src/NanoSVG.cake
  3. 37
      src/VectorPuppetShow.cake

21
data/TestPuppet.svg

@ -25,11 +25,11 @@
borderopacity="1.0"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:zoom="1.1775363"
inkscape:cx="228.35976"
inkscape:cy="649.97768"
inkscape:zoom="2.3550726"
inkscape:cx="101.40112"
inkscape:cy="632.54192"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:current-layer="layer2"
showgrid="false"
units="px"
inkscape:pagecheckerboard="false"
@ -46,7 +46,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
@ -218,4 +218,15 @@
rx="26.762945"
ry="16.273668" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Skeleton">
<path
style="fill:none;stroke:#000000;stroke-width:1.03187497;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="M 113.13257,68.485575 69.65461,67.474459 24.828498,67.586806 16.739576,67.699151"
id="Bone_Right_Arm"
inkscape:connector-curvature="0"
inkscape:label="Bone_Right_Arm" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

9
src/NanoSVG.cake

@ -16,6 +16,15 @@
(token-splice-rest body tokens)))
(return true))
(defmacro each-path-in-svg-shape (shape any path-name symbol &rest body array)
(tokenize-push output
(c-for (var (token-splice path-name) (addr NSVGpath)
(path (token-splice shape) > paths))
(token-splice path-name)
(set (token-splice path-name) (path (token-splice path-name) > next))
(token-splice-rest body tokens)))
(return true))
(forward-declare (struct NSVGshape))
;; This isn't 100% accurate I think, but does seem to make containment likely

37
src/VectorPuppetShow.cake

@ -274,6 +274,43 @@
(var hovered-shape-id-buffer (array 1024 char) (array 0))
(var hovered-write-head (addr char) hovered-shape-id-buffer)
(each-shape-in-svg-image puppet-image shape
(when (= 0 (strncmp (path shape > id) "Bone_" 5))
(each-path-in-svg-shape shape current-path
(var state int 0)
(each-in-range (* 2 (path current-path > npts)) point-index
(var point-width (const int) 15)
(var point-rect SDL_Rect
(array (- (type-cast (at point-index (path current-path > pts)) int)
(/ point-width 2))
(- (type-cast (at (+ 1 point-index) (path current-path > pts)) int)
(/ point-width 2))
point-width point-width))
(var is-control-point bool (!= 0 (mod point-index 6)))
(if is-control-point
(SDL_SetRenderDrawColor renderer 10 100 10 255)
(SDL_SetRenderDrawColor renderer 230 10 10 255))
;; Selection coloring
(when (and (>= mouse-x (field point-rect x))
(>= mouse-y (field point-rect y))
(< mouse-x (+ (field point-rect x)
(field point-rect w)))
(< mouse-y (+ (field point-rect y)
(field point-rect h))))
(set hovered-write-head
(+ hovered-write-head
(snprintf hovered-write-head
(- (array-size hovered-shape-id-buffer)
(- hovered-write-head hovered-shape-id-buffer))
(? (!= hovered-shape-id-buffer hovered-write-head)
", %s[%d]" "%s[%d]")
(path shape > id) (/ point-index 2))))
(SDL_SetRenderDrawColor renderer 10 230 10 255))
(SDL_RenderDrawRect renderer (addr point-rect))
(incr point-index)))
(continue))
(var sized-bounds (array 4 int) (array 0))
(nanosvg-get-shape-bounds-with-stroke-int shape sized-bounds)
(var shape-bounds SDL_Rect

Loading…
Cancel
Save