There is quite a lot of code. I am struggling with syntax a bit as well which isn’t helping. I think/hope I’ve put in all the recommendations. I started with the GUI template and have left that as is and just added:
MainComponent::MainComponent()
{
setSize (600, 400);
addAndMakeVisible(new VFOComponent(0,0,0,0,getWidth(),getHeight()));
}
Here is the vfo.h file.
//==============================================================================
// Defines
#define MHZ_FONT 30.0f
#define KHZ_FONT 30.0f
#define HZ_FONT 20.0f
#define MHZ_COLOR Colours::white
#define KHZ_COLOR Colours::white
#define HZ_COLOR Colours::orange
#define RX 0
#define TX 1
/*
A VFO Digit component
*/
class VFODigit : public Label
{
public:
//==============================================================================
VFODigit(String text, Colour colour, float size);
~VFODigit();
//==============================================================================
void paint(Graphics&) override;
void resized() override;
private:
//==============================================================================
// State variables
//==============================================================================
// Method prototypes
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VFODigit)
};
//==============================================================================
/*
Multi-instance VFO component
*/
class VFOComponent : public Component
{
public:
//==============================================================================
VFOComponent(int p_vfo_type, int p_vfo_id, int x, int y, int w, int h);
~VFOComponent();
//==============================================================================
void paint(Graphics&) override;
void resized() override;
private:
//==============================================================================
// State variables
int vfo_type = RX; // RX|TX
int vfo_id = 0; // Numerical id of VFO instance
int freq_int = 0; // Last frequence increment in MHz
int current_freq = 0; // Current frequency in MHz
// Map for lookup of increments
std::map<String, float> freq_inc_map {
{String("100MHz"), 100.0f},
{String("10MHz"), 10.0f},
{String("1MHz"), 1.0f},
{String("100KHz"), 0.1f},
{String("10KHz"), 0.01f},
{String("1KH"), 0.001f},
{String("100Hz"), 0.0001f},
{String("10Hz"), 0.00001f},
{String("1H"), 0.000001f},
};
// Grid to hold VFO digits
Grid grid;
Grid& ref_grid = grid;
// Digits
VFODigit *d_100MHz;
VFODigit *d_10MHz;
VFODigit *d_1MHz;
VFODigit *d_100KHz;
VFODigit *d_10KHz;
VFODigit *d_1KHz;
VFODigit *d_100Hz;
VFODigit *d_10Hz;
VFODigit *d_1Hz;
//==============================================================================
// Method prototypes
void add_digits(Grid &grid);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VFOComponent)
};
and the vfo.cpp file:
//==============================================================================
// Constructor/Destructor
VFOComponent::VFOComponent(int p_vfo_type, int p_vfo_id, int x, int y, int w, int h)
{
// Local vars
vfo_type = p_vfo_type;
vfo_id = p_vfo_id;
// Bounds given by caller to position within callers container
setBounds(x, y, w, h);
}
VFOComponent::~VFOComponent()
{
}
//==============================================================================
// GUI Events
void VFOComponent::paint(Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll(Colours::darkgrey);
}
void VFOComponent::resized()
{
// This is called when the VFOComponent is resized.
add_digits(ref_grid);
grid.performLayout(getLocalBounds());
}
//==============================================================================
// Private
void VFOComponent::add_digits(Grid &thegrid) {
// Create digits
d_100MHz = new VFODigit( String("0"), MHZ_COLOR, MHZ_FONT );
addAndMakeVisible(d_100MHz);
d_10MHz = new VFODigit(String("0"), MHZ_COLOR, MHZ_FONT);
addAndMakeVisible(d_10MHz);
d_1MHz = new VFODigit(String("0"), MHZ_COLOR, MHZ_FONT);
addAndMakeVisible(d_1MHz);
d_100KHz = new VFODigit(String("0"), KHZ_COLOR, KHZ_FONT);
addAndMakeVisible(d_100KHz);
d_10KHz = new VFODigit(String("0"), KHZ_COLOR, KHZ_FONT);
addAndMakeVisible(d_10KHz);
d_1KHz = new VFODigit(String("0"), KHZ_COLOR, KHZ_FONT);
addAndMakeVisible(d_1KHz);
d_100Hz = new VFODigit(String("0"), HZ_COLOR, HZ_FONT);
addAndMakeVisible(d_100Hz);
d_10Hz = new VFODigit(String("0"), HZ_COLOR, HZ_FONT);
addAndMakeVisible(d_10Hz);
d_1Hz = new VFODigit(String("0"), HZ_COLOR, HZ_FONT);
addAndMakeVisible(d_1Hz);
// Add digits in one horizontal row
using Track = Grid::TrackInfo;
thegrid.templateRows = { Track(1_fr) };
thegrid.templateColumns = { Track(1_fr), Track(1_fr), Track(1_fr), Track(1_fr), Track(1_fr), Track(1_fr), Track(1_fr), Track(1_fr), Track(1_fr) };
thegrid.items = {
GridItem(d_100MHz),
GridItem(d_10MHz),
GridItem(d_1MHz),
GridItem(d_100KHz),
GridItem(d_10KHz),
GridItem(d_1KHz),
GridItem(d_100Hz),
GridItem(d_10Hz),
GridItem(d_1Hz)
};
thegrid.justifyItems = Grid::JustifyItems::stretch;
thegrid.rowGap = Grid::Px::Px(10.0f);
thegrid.columnGap = Grid::Px::Px(10.0f);
}
//==============================================================================
// A VFO Digit
//==============================================================================
VFODigit::VFODigit(String text, Colour colour, float size) {
// Create a digit ready to add to the grid
setText(text, dontSendNotification);
setJustificationType(Justification::centred);
setColour(Label::textColourId, colour);
setFont(Font(size, Font::bold));
};
VFODigit::~VFODigit() {
}
void VFODigit::paint(Graphics& g) {
g.fillAll(Colours::blue);
};
void VFODigit::resized() {
};