Implement paintRowBackground and paintCell
Thursday 6 August 2020
We're going to build on our minimal implementation of that data model, and go ahead and actually write the code to draw the cells.
We've got two functions that we need to deal with here - paintRowBackground and paintCell.
1. In PlaylistComponent.cpp we can add this to the paintRowBackground function:
void PlaylistComponent::paintRowBackground(juce::Graphics& g,We have given it a variable g and we are changing the colour if a row is selected.
int rowNumber,
int width,
int height,
bool rowIsSelected)
{
if (rowIsSelected)
{
g.fillAll(juce::Colours::orange);
}
else
{
g.fillAll(juce::Colours::darkgrey);
}
}
2. The next step, now we have drawn the background, is to draw the cell itself. Here is the function code:
void PlaylistComponent::paintCell(juce::Graphics& g,Again we added a variable g in the function arguments.
int rowNumber,
int columnId,
int width,
int height,
bool rowIsSelected)
{
g.drawText (trackTitles[rowNumber],
2,
0,
width - 4,
height,
juce::Justification::centredLeft,
true);
}
3. When you compile and build you can see the track names in two columns. We'll get rid of the second column because we don't need it. So we can delete
tableComponent.getHeader().addColumn("Artist", 2, 400);and we can also add a few more tracks too:
trackTitles.push_back("Track 3");
trackTitles.push_back("Track 4");
trackTitles.push_back("Track 5");
trackTitles.push_back("Track 6");
When you build and compile you will see the track names appear in the box.
More posts in cpp
- Add a component ID and converting between ints and strings
- Implement a play button and add a listener
- Implement paintRowBackground and paintCell
- Add a vector to store a list of files
- Add a TableListBox
- Create a PlaylistComponent in the Projucer project
- Threads
- Implement a timer
- Add getPosition and setPosition functions
- Refactor DJAudioPlayer to use app-scope formatManager
- Draw the thumbnail
- Hook up the load button to trigger the AudioThumbnail load
- The AudioThumbnail class in the API
- Creating a new component - WaveformDisplay
- Implementing drag and drop triggers
- Use a MixerAudioSource to play more than one file at a time
- Implement the listener interfaces to DeckGUI
- Creating a DeckGUI class
- setPosition control
- Implementing setGain and setSpeed
- Add audio playback functionality
- Writing the DJAudioPlayer class
- Creating a new JUCE class with Projucer
- Refactoring our code
- Using ResamplingAudioPlayer to implement variable speed playback
- Add stop, start and volume functionality
- Add a file chooser
- Audio file playback in JUCE
- Realtime sound synthesis in JUCE
- Adding a slider listener
- Introduction to event listeners
- Macros
- Inheritance
- Adding a GUI widget to the JUCE app
- Introduction to JUCE