Get stave note position after it is drawn?

385 views
Skip to first unread message

WD

unread,
Aug 7, 2012, 12:06:09 AM8/7/12
to vex...@googlegroups.com
Hullo,

How can I get the XY position of a StaveNote after drawing it? I'd like to draw a green rect over a note to "highlight" it, like below:

  ctx.fillRect(x, y, highlightWidth, highlightHeight);
  ctx.fill();

But I am having trouble working out where to get the position information.

If it helps, I am creating/drawing my notes like this:

    voice = new Vex.Flow.Voice(
      num_beats: 6
      beat_value: 4
      resolution: Vex.Flow.RESOLUTION
    );

    voice.addTickables(staveNotes);

    formatter.joinVoices([ voice ]).format([ voice ], (stave.x + stave.width) - stave.start_x);

    voice.draw(ctx, stave);

Thanks.

Mohit Muthanna

unread,
Aug 10, 2012, 8:07:48 AM8/10/12
to vex...@googlegroups.com
You can iterate over each note and call getYs() for the Y values, getWidth() for the width.

For the X values you need to iterate over the TickContext instances and call getX().

Mohit.
 

Thanks.

--
You received this message because you are subscribed to the Google
Groups "vexflow" group.
To post to this group, send email to vex...@googlegroups.com
To unsubscribe from this group, send email to
vexflow+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/vexflow?hl=en



--
Mohit Muthanna [mohit (at) muthanna (uhuh) com]

madtom1999

unread,
Aug 11, 2012, 3:45:41 AM8/11/12
to vex...@googlegroups.com, mo...@muthanna.com
Can I just add that in Firefox you can use the DOM inspectors in the FireBug and/or Web Developer addons and browse the javascript domains and see the properties of objects including all their JavaScript methods and attributes and source code. Can be very useful in working these things out. Sometimes.
Tom
Reply all
Reply to author
Forward
0 new messages