Tutorial questions - drawing a dashed line


#1

Hello, I'm fairly new to JUCE and C++ but I've taken a break from my normal C++ studies (Standard Library) to play with the more colorful JUCE.

 

So anyways here I am doing this Graphics class tutorial and I'm having the time of my life drawing text and making them diffrent colors and then I move on drawing lines and get to the excercise and see the following:

~~ExerciseExplore other types of lines. Can you figure out how to draw dashed lines, or arrows? Hint: have a look at the Graphics class documentation.

So I'm looking at the documentation and in all my studies of programing I get stumped on these. I see these when attempting to figure out how to use CooCox and a STM32F4-Discovery board. I still don't understand....I'm hoping to get a break down on this and maby understand these as some are simple to figure out while other are not so easy.

 

Please help break down this info from http://learn.juce.com/doc/tutorial_graphics_class.php

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

~~Draws a dashed line using a custom set of dash-lengths. Parameters line the line to draw 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. numDashLengths the number of elements in the array (this must be an even number). lineThickness the thickness of the line to draw dashIndexToStartFrom the index in the dash-length array to use for the first segment See alsoPathStrokeType::createDashedStroke

 

so the first bit of confusion is this.

 

I understand the author made a template function in the graphics class.

so in my situation I would begin the code as such g.drawDashedLine (I'm confused on this part)(const Line<float>, const float* dashLengths, int numDashLength, Float LineThickness = 1.0f, int dashIndexToStartFrom = 0) const 

example code will help me a bit. Thanks I know I should know my C++ better....crying

 

 

 

 

 


#2

What exactly don't you get? Is it the parameters dashLengths and numDashLengths? If so, it's just an array you pass in with alternating lengths. So you just create an array with the values of alternating lengths. Pretty simple, right? If you want each dash to be the same length, I guess you could just use array with 1 value. Then for numDashLengths you just pass in the size of that array. Everything else is pretty straightforward in my opinion. Maybe you could tell us what in particular you're having trouble with.


#3

Here's how we draw hysteresis on one of our plug-ins:

 


    float dashPattern[2];
    dashPattern[0] = 8.0;
    dashPattern[1] = 8.0;
    g.setColour(thresholdColor);
    g.drawDashedLine(Line<float>(8, scaledHysteresis, getWidth()*2 - 2, scaledHysteresis), dashPattern, 2, 2.0);
 


#4

Thank you guys for your info. I was able to get it.

 

Jordan, I was mainly confused with the ~~const Line< float > & line.  I suppose its just a matter of time and tears....