Skip to content

Commit

Permalink
Force keyboard focus on parm dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
asb2m10 committed Sep 29, 2024
1 parent a84649d commit b4c7053
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Source/DXComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void LcdDisplay::setSystemMsg(String msg) {

void LcdDisplay::paint(Graphics &g) {
g.setColour (Colours::white);
g.drawText (paramMsg,
g.drawFittedText(paramMsg,
0, 0, 140, 14,
Justification::centred, false);
}
Expand Down
21 changes: 11 additions & 10 deletions Source/DXLookNFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Typeface::Ptr DXLookNFeel::getTypefaceForFont(const Font &) {
void DXLookNFeel::drawRotarySlider( Graphics &g, int x, int y, int width, int height, float sliderPosProportional,
float rotaryStartAngle, float rotaryEndAngle, Slider &slider ) {
if ( imageKnob.isNull() ) {
LookAndFeel_V3::drawRotarySlider(g, x, y, width, height, sliderPosProportional, rotaryStartAngle, rotaryEndAngle, slider);
LookAndFeel_V4::drawRotarySlider(g, x, y, width, height, sliderPosProportional, rotaryStartAngle, rotaryEndAngle, slider);
return;
}

Expand All @@ -296,7 +296,7 @@ void DXLookNFeel::drawRotarySlider( Graphics &g, int x, int y, int width, int he

void DXLookNFeel::drawToggleButton(Graphics& g, ToggleButton& button, bool isMouseOverButton, bool isButtonDown) {
if ( imageSwitch.isNull() ) {
LookAndFeel_V3::drawToggleButton(g, button, isMouseOverButton, isButtonDown);
LookAndFeel_V4::drawToggleButton(g, button, isMouseOverButton, isButtonDown);
return;
}

Expand All @@ -305,7 +305,7 @@ void DXLookNFeel::drawToggleButton(Graphics& g, ToggleButton& button, bool isMou
if( lb )
{
if( imageSwitchLighted.isNull() ) {
LookAndFeel_V3::drawToggleButton(g, button, isMouseOverButton, isButtonDown);
LookAndFeel_V4::drawToggleButton(g, button, isMouseOverButton, isButtonDown);
return;
}
g.drawImage(imageSwitchLighted, 0, 0, 48, 26, 0, button.getToggleState() ? 0 : 26, 48, 26);
Expand All @@ -317,23 +317,24 @@ void DXLookNFeel::drawToggleButton(Graphics& g, ToggleButton& button, bool isMou

void DXLookNFeel::drawButtonBackground(Graphics &g, Button &button, const Colour& backgroundColour, bool isMouseOverButton, bool isButtonDown) {
if ( imageButton.isNull() ) {
LookAndFeel_V3::drawButtonBackground(g, button, backgroundColour, isMouseOverButton, isButtonDown);
LookAndFeel_V4::drawButtonBackground(g, button, backgroundColour, isMouseOverButton, isButtonDown);
return;
}

int w = button.getWidth();

int l = button.getHeight();

// dx, dy, dw, dl, sx, sy, sw, sl
g.drawImage(imageButton, 0, 0, 3, 30, 0, isButtonDown ? 30 : 0, 3, 30);
g.drawImage(imageButton, 3, 0, w-6, 30, 3, isButtonDown ? 30 : 0, 44, 30);
g.drawImage(imageButton, w-3, 0, 3, 30, 47, isButtonDown ? 30 : 0, 47, 30);
g.drawImage(imageButton, 0, 0, 3, l, 0, isButtonDown ? 30 : 0, 3, 30);
g.drawImage(imageButton, 3, 0, w-6, l, 3, isButtonDown ? 30 : 0, 44, 30);
g.drawImage(imageButton, w-3, 0, 3, l, 47, isButtonDown ? 30 : 0, 47, 30);
}

void DXLookNFeel::drawLinearSlider (Graphics& g, int x, int y, int width, int height,
float sliderPos, float minSliderPos, float maxSliderPos,
const Slider::SliderStyle style, Slider& slider) {
if ( imageSlider.isNull() ) {
LookAndFeel_V3::drawLinearSliderThumb(g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
LookAndFeel_V4::drawLinearSliderThumb(g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
return;
}

Expand All @@ -351,7 +352,7 @@ void DXLookNFeel::positionComboBoxText(ComboBox& box, Label& label) {
return;
}

LookAndFeel_V3::positionComboBoxText(box, label);
LookAndFeel_V4::positionComboBoxText(box, label);
}

Colour DXLookNFeel::fillColour = Colour(77,159,151);
Expand Down
32 changes: 21 additions & 11 deletions Source/ParamDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

//[Headers] You can add your own extra header files here...
#include "Dexed.h"
#include "DXComponents.h"
//[/Headers]

#include "ParamDialog.h"
Expand All @@ -33,7 +34,7 @@ ParamDialog::ParamDialog ()
//[Constructor_pre] You can add your own custom stuff here..
//[/Constructor_pre]

pitchRangeDn.reset (new juce::Slider ("pitchRangeDn"));
pitchRangeDn.reset (new DXSlider ("pitchRangeDn"));
addAndMakeVisible (pitchRangeDn.get());
pitchRangeDn->setExplicitFocusOrder (2);
pitchRangeDn->setRange (0, 48, 1);
Expand All @@ -43,7 +44,7 @@ ParamDialog::ParamDialog ()

pitchRangeDn->setBounds (264, 16, 72, 24);

pitchStep.reset (new juce::Slider ("pitchStep"));
pitchStep.reset (new DXSlider ("pitchStep"));
addAndMakeVisible (pitchStep.get());
pitchStep->setExplicitFocusOrder (3);
pitchStep->setRange (0, 12, 1);
Expand Down Expand Up @@ -75,7 +76,7 @@ ParamDialog::ParamDialog ()

sysexOut->setBounds (104, 280, 224, 24);

sysexChl.reset (new juce::Slider ("sysexChl"));
sysexChl.reset (new DXSlider ("sysexChl"));
addAndMakeVisible (sysexChl.get());
sysexChl->setExplicitFocusOrder (9);
sysexChl->setRange (1, 16, 1);
Expand Down Expand Up @@ -107,7 +108,7 @@ ParamDialog::ParamDialog ()

showKeyboard->setBounds (264, 96, 56, 24);

whlRange.reset (new juce::Slider ("whlRange"));
whlRange.reset (new DXSlider ("whlRange"));
addAndMakeVisible (whlRange.get());
whlRange->setExplicitFocusOrder (10);
whlRange->setRange (0, 99, 1);
Expand All @@ -117,7 +118,7 @@ ParamDialog::ParamDialog ()

whlRange->setBounds (448, 16, 72, 24);

ftRange.reset (new juce::Slider ("ftRange"));
ftRange.reset (new DXSlider ("ftRange"));
addAndMakeVisible (ftRange.get());
ftRange->setExplicitFocusOrder (14);
ftRange->setRange (0, 99, 1);
Expand All @@ -127,7 +128,7 @@ ParamDialog::ParamDialog ()

ftRange->setBounds (448, 56, 72, 24);

brRange.reset (new juce::Slider ("brRange"));
brRange.reset (new DXSlider ("brRange"));
addAndMakeVisible (brRange.get());
brRange->setExplicitFocusOrder (18);
brRange->setRange (0, 99, 1);
Expand All @@ -137,7 +138,7 @@ ParamDialog::ParamDialog ()

brRange->setBounds (448, 96, 72, 24);

atRange.reset (new juce::Slider ("atRange"));
atRange.reset (new DXSlider ("atRange"));
addAndMakeVisible (atRange.get());
atRange->setExplicitFocusOrder (22);
atRange->setRange (0, 99, 1);
Expand Down Expand Up @@ -284,7 +285,7 @@ ParamDialog::ParamDialog ()

transposeScale->setBounds (592, 240, 56, 30);

mpePBRange.reset (new juce::Slider ("mpePBRange"));
mpePBRange.reset (new DXSlider ("mpePBRange"));
addAndMakeVisible (mpePBRange.get());
mpePBRange->setExplicitFocusOrder (32);
mpePBRange->setRange (0, 96, 1);
Expand Down Expand Up @@ -312,7 +313,7 @@ ParamDialog::ParamDialog ()
juce::Image(), 1.000f, juce::Colour (0x00000000));
transposeHelp->setBounds (500, 245, 20, 20);

pitchRangeUp.reset (new juce::Slider ("pitchRangeUp"));
pitchRangeUp.reset (new DXSlider ("pitchRangeUp"));
addAndMakeVisible (pitchRangeUp.get());
pitchRangeUp->setExplicitFocusOrder (1);
pitchRangeUp->setRange (0, 48, 1);
Expand Down Expand Up @@ -349,8 +350,6 @@ ParamDialog::ParamDialog ()
//[Constructor] You can add your own custom stuff here..
pitchRangeUp->setEnabled(pitchStep->getValue() == 0);
pitchRangeDn->setEnabled(pitchStep->getValue() == 0);
pitchRangeUp->grabKeyboardFocus();


StringArray input;
input.add("None");
Expand Down Expand Up @@ -434,6 +433,9 @@ ParamDialog::ParamDialog ()
mpeEnabled->setWantsKeyboardFocus(true);
transposeHelp->setWantsKeyboardFocus(true);
scalingFactor->setWantsKeyboardFocus(true);

setWantsKeyboardFocus(true);
startTimer(100);
//[/Constructor]
}

Expand Down Expand Up @@ -478,6 +480,7 @@ ParamDialog::~ParamDialog()


//[Destructor]. You can add your own custom destruction code here..
stopTimer();
//[/Destructor]
}

Expand Down Expand Up @@ -1203,6 +1206,13 @@ void ParamDialog::setIsStandardTuning( bool b )
resetTuningButton->setEnabled( ! b );
}

// Force the internal component dialog to have keyboard focus. Ugly, but it is
// the only way I have found (including on the JUCE forum).
void ParamDialog::timerCallback() {
stopTimer();
grabKeyboardFocus();
}

//[/MiscUserCode]


Expand Down
4 changes: 3 additions & 1 deletion Source/ParamDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
class ParamDialog : public Component,
public juce::Slider::Listener,
public juce::ComboBox::Listener,
public juce::Button::Listener
public juce::Button::Listener,
Timer
{
public:
//==============================================================================
Expand All @@ -63,6 +64,7 @@ class ParamDialog : public Component,
void setGeneralCallback(std::function<void(ParamDialog *)> gc ) { general_callback_ = gc; }

void setIsStandardTuning(bool s);
void timerCallback() override;
//[/UserMethods]

void paint (juce::Graphics& g) override;
Expand Down

0 comments on commit b4c7053

Please sign in to comment.