Beginner tutorial question - Graphic drawDashedLine


#1

Hello all.

Apologies if this (and my almost certain future) question is very obvious and novice, I'm just rather new to Juce, code in general, C++, and how to read API's and other documentation.

When attempting to use drawDashedLine as suggested in the Graphics tutorial, I've come across a problem:

The API states that:

void Graphics::drawDashedLine ( const Line< float > &  line,
                                                     const float *  dashLengths,
                                                     int  numDashLengths,
                                                     float  lineThickness = 1.0f,
                                                     int  dashIndexToStartFrom = 0 
                                                    ) const

dashLengths a series of lengths to specify the on/off lengths - e.g. { 4, 5, 6, 7 } will draw a line of 4 pixels, skip 5 pixels, draw 6 pixels, skip 7 pixels, and then repeat.

For the dashLengths parameter I've tried a number of combinations but non work:

g.drawDashedLine (Line<float>(10.0f, 300.0f, 590.0f, 300.0f), {5, 5}, 2, 3.0, 0);

This seems correct to me but throws a 


error C2664: 'void juce::Graphics::drawDashedLine(const juce::Line<float> &,const float *,int,float,int) const' : cannot convert argument 2 from 'initializer-list' to 'const float *'   

g.drawDashedLine (Line<float>(10.0f, 300.0f, 590.0f, 300.0f), float *{5, 5}, 2, 3.0, 0);

This variation says that 'type float is unexpected'

I've tried a number of other things including embedding a PathStrokeType which I couldn't get to work.

 

Thank you.

 


#2

Well, I have not used the function myself and I am far away from beeing a C++ expert. But I don't think you can define an array "on the fly". You should try something along the following lines:

const float myDashLength[] = { 5, 5 };

g.drawDashedLine(Line<float>(10.0f, 300.0f, 590.0f, 300.0f), &myDashLength[0], 2, 3.0, 0);

 


#3

That would indeed be the reason. I tried something similar earlier but didn't state it correctly.

 

Thank you very much.