Skip to content

Commit

Permalink
fixing slider and component resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
davispolito committed Oct 31, 2024
1 parent 76eff98 commit e754748
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 261 deletions.
2 changes: 1 addition & 1 deletion assets/default.bitklavierskin
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Knob Mod Amount Arc Thickness": 0.5,
"Knob Mod Meter Arc Size": 39.0,
"Knob Mod Meter Arc Thickness": 3.0,
"Knob Offset": -7.0,
"Knob Offset": 0.0,
"Knob Section Height": 71.0,
"Label Background": "ff3e4245",
"Label Background Height": 18.0,
Expand Down
6 changes: 3 additions & 3 deletions source/interface/ConstructionSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ void ConstructionSite::mouseDown (const juce::MouseEvent& eo)
if (itemToSelect == nullptr)
{
preparationSelector.getLassoSelection().deselectAll();
DBG ("mousedown empty space");
//DBG ("mousedown empty space");
}
else
{
DBG ("mousedown on object");
// DBG ("mousedown on object");
}
addChildComponent (selectorLasso);
selectorLasso.beginLasso (e, &preparationSelector);
Expand Down Expand Up @@ -481,7 +481,7 @@ void ConstructionSite::mouseDown (const juce::MouseEvent& eo)
void ConstructionSite::mouseUp (const juce::MouseEvent& eo)
{
//inLasso = false;
DBG ("mouseupconst");
//DBG ("mouseupconst");
selectorLasso.endLasso();
removeChildComponent (&selectorLasso);
if (edittingComment)
Expand Down
2 changes: 1 addition & 1 deletion source/interface/FullInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void FullInterface::resized() {
int voice_padding = findValue(Skin::kLargePadding);

int main_x = left + 2 * voice_padding;
int top_height = kTopHeight * ratio;
int top_height = kTopHeight * display_scale_;
int section_one_width = 350 * ratio;
int section_two_width = section_one_width;
int audio_width = section_one_width + section_two_width + padding;
Expand Down
5 changes: 4 additions & 1 deletion source/interface/ParameterView/ParametersView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ namespace bitklavier {
paintBorder(g);
paintKnobShadows(g);
paintChildrenBackgrounds(g);
}
for (auto slider : all_sliders_v) {
drawLabelForComponent(g, slider->getName(), slider);
}
}
private:
struct Pimpl;
std::unique_ptr<Pimpl> pimpl;
Expand Down
2 changes: 1 addition & 1 deletion source/interface/Preparations/PreparationSection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Created by Davis Polito on 2/16/24.
// Created by Davis Polito on 2/16/.
//

#include "PreparationSection.h"
Expand Down
97 changes: 9 additions & 88 deletions source/interface/header_section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LogoSection::LogoSection() : SynthSection("logo_section") {
}

void LogoSection::resized() {
int logo_padding_y = kLogoPaddingY * size_ratio_;
int logo_padding_y = kLogoPaddingY;
int logo_height = getHeight() - 2 * logo_padding_y;
int logo_padding_x = (getWidth() - logo_height) / 2;
if (logo_button_)
Expand Down Expand Up @@ -93,67 +93,7 @@ HeaderSection::HeaderSection() : SynthSection("header_section"), tab_offset_(0),
loadButton->setButtonText("load");
loadButton->setLookAndFeel(TextLookAndFeel::instance());
loadButton->addListener(this);
// tab_selector_ = std::make_unique<TabSelector>("tab_selector");
// tab_selector_ = std::make_unique<TabSelector>("tab_selector");
// tab_selector_ = std::make_unique<TabSelector>("tab_selector");
// addAndMakeVisible(tab_selector_.get());
// addOpenGlComponent(tab_selector_->getImageComponent());
// tab_selector_->setSliderStyle(juce::Slider::LinearBar);
// tab_selector_->setRange(0, 3);
// tab_selector_->addListener(this);
// tab_selector_->setNames({"VOICE", "EFFECTS", "MATRIX", "ADVANCED"});
// tab_selector_->setScrollWheelEnabled(false);

// synth_preset_selector_ = std::make_unique<SynthPresetSelector>();
// addSubSection(synth_preset_selector_.get());
// synth_preset_selector_->addListener(this);


// volume_section_ = std::make_unique<VolumeSection>("VOLUME");
// addSubSection(volume_section_.get());
//
// oscilloscope_ = std::make_unique<Oscilloscope>();
// addOpenGlComponent(oscilloscope_.get());
//
// spectrogram_ = std::make_unique<Spectrogram>();
// addOpenGlComponent(spectrogram_.get());
// spectrogram_->setVisible(false);
// spectrogram_->paintBackgroundLines(false);
// spectrogram_->setMinDb(-40.0f);
// spectrogram_->setMaxDb(0.0f);
//
// view_spectrogram_ = std::make_unique<SynthButton>("view_spectrogram");
// addButton(view_spectrogram_.get());
// view_spectrogram_->getGlComponent()->setVisible(false);

// exit_temporary_button_ = std::make_unique<OpenGlShapeButton>("Exit");
// addChildComponent(exit_temporary_button_.get());
// addOpenGlComponent(exit_temporary_button_->getGlComponent());
// exit_temporary_button_->addListener(this);
// exit_temporary_button_->setShape(Paths::exitX());
//
// temporary_tab_ = std::make_unique<PlainTextComponent>("Temporary", "");
// addOpenGlComponent(temporary_tab_.get());
// temporary_tab_->setFontType(PlainTextComponent::kLight);
// temporary_tab_->setJustification(juce::Justification::centredLeft);
//inspectButton = std::make_unique<OpenGlToggleButton>("Inspect the UI");
//inspectButton->setUiButton(false);
//inspectButton->
//addAndMakeVisible(inspectButton.get());
//addChildComponent(inspectButton.get());

// addOpenGlComponent(inspectButton->getGlComponent());
// inspectButton->setText("Inspect");
// // this chunk of code instantiates and opens the melatonin inspector
// inspectButton->onClick = [&] {
// if (!inspector)
// {
// inspector = std::make_unique<melatonin::Inspector> (*this);
// inspector->onClose = [this]() { inspector.reset(); };
// }
//
// inspector->setVisible (true);
// };

setAlwaysOnTop(true);
setSkinOverride(Skin::kHeader);
}
Expand All @@ -163,31 +103,12 @@ void HeaderSection::paintBackground(juce::Graphics& g) {
paintChildrenBackgrounds(g);
g.setColour(findColour(Skin::kBody, true));
int logo_section_width = 32.0 + getPadding();
g.fillRect(0, 0, logo_section_width, getHeight());
g.fillRect(0, 0, logo_section_width, getHeight());

int label_rounding = findValue(Skin::kLabelBackgroundRounding);
//g.setColour(findColour(Skin::kTextComponentBackground, true));
g.setColour(juce::Colours::white);
//g.fillRoundedRectangle(sampleSelector->getBounds().toFloat(), label_rounding);
g.fillRect(100, 50, 100, 100);
paintKnobShadows(g);


//g.saveState();
// juce::Rectangle<int> bounds = getLocalArea(synth_preset_selector_.get(), synth_preset_selector_->getLocalBounds());
// g.reduceClipRegion(bounds);
// g.setOrigin(bounds.getTopLeft());
//synth_preset_selector_->paintBackground(g);
//g.restoreState();

// if (LoadSave::doesExpire()) {
// juce::String countdown = "Beta expires in: " + juce::String(LoadSave::getDaysToExpire()) + " days";
// int countdown_height = volume_section_->getY() + volume_section_->getBuffer();
// g.setFont(Fonts::instance()->proportional_regular().withPointHeight(countdown_height / 2.0f));
// g.setColour(findColour(Skin::kTextComponentText, true));
// g.drawText(countdown, volume_section_->getX(), 0,
// volume_section_->getWidth(), countdown_height, juce::Justification::centred);
// }

}

void HeaderSection::resized() {
Expand All @@ -208,14 +129,14 @@ void HeaderSection::resized() {

int logo_width = findValue(Skin::kModulationButtonWidth);
int label_height = findValue(Skin::kLabelBackgroundHeight);
logo_section_->setBounds(0, -10, logo_width , height );
sampleSelector->setBounds(logo_width + widget_margin, logo_section_->getBottom()/2, 100, label_height);
logo_section_->setBounds(0, 0, logo_width , height );
sampleSelector->setBounds(logo_width + widget_margin, 10, 100, label_height);
sampleSelectText->setBounds(sampleSelector->getBounds());
float label_text_height = findValue(Skin::kLabelHeight);
sampleSelectText->setTextSize(label_text_height);
printButton->setBounds(sampleSelector->getX() + 100, sampleSelector->getY(), 100, 50);
loadButton->setBounds(printButton->getX() + 100, sampleSelector->getY(), 100, 50);
saveButton->setBounds(loadButton->getX() + 100, sampleSelector->getY(), 100, 50);
printButton->setBounds(sampleSelector->getX() + 100, sampleSelector->getY(), 80, 20);
loadButton->setBounds(printButton->getX() + 100, sampleSelector->getY(),80, 20);
saveButton->setBounds(loadButton->getX() + 100, sampleSelector->getY(), 80, 20);
//int logo_width = findValue(Skin::kModulationButtonWidth);
// logo_section_->setBounds(large_padding, 0, logo_width, height);
//inspectButton->setBounds(large_padding, 0, 100, height);
Expand Down
2 changes: 1 addition & 1 deletion source/interface/main_section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void MainSection::resized()
int width = getWidth();
int widget_margin = findValue(Skin::kWidgetMargin);
int large_padding = findValue(Skin::kLargePadding);
constructionSite_->setBounds(large_padding, 0, getDisplayScale() * width + 1500,getDisplayScale() * height + 1500);
constructionSite_->setBounds(large_padding, 0, width + 1500, height + 1500);
//constructionPort.setBounds(large_padding, 0,getDisplayScale()* width, getDisplayScale() * height);
//constructionPort.setBounds(large_padding, 0,width, height);
DBG (":");
Expand Down
6 changes: 5 additions & 1 deletion source/interface/open_gl_background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../synthesis/framework/common.h"
#include "look_and_feel/shaders.h"

OpenGlBackground::OpenGlBackground() : image_shader_(nullptr), vertices_() {
OpenGlBackground::OpenGlBackground() : component_(nullptr),image_shader_(nullptr), vertices_() {
new_background_ = false;
vertex_buffer_ = 0;
triangle_buffer_ = 0;
Expand Down Expand Up @@ -105,6 +105,10 @@ void OpenGlBackground::disableAttributes(juce::OpenGLContext& open_gl_context) {

void OpenGlBackground::render(OpenGlWrapper& open_gl) {
mutex_.lock();
if( component_!=nullptr)
{
OpenGlComponent::setViewPort(component_, component_->getLocalBounds(),open_gl) ;
}
if ((new_background_ || background_.getWidth() == 0) && background_image_.getWidth() > 0) {
new_background_ = false;
background_.loadImage(background_image_);
Expand Down
3 changes: 2 additions & 1 deletion source/interface/open_gl_background.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class OpenGlBackground {
void bind(juce::OpenGLContext& open_gl_context);
void enableAttributes(juce::OpenGLContext& open_gl_context);
void disableAttributes(juce::OpenGLContext& open_gl_context);
void setComponent(juce::Component* component) { component_ = component; }

private:
juce::OpenGLShaderProgram* image_shader_;
Expand All @@ -56,7 +57,7 @@ class OpenGlBackground {

GLuint vertex_buffer_;
GLuint triangle_buffer_;

juce::Component* component_;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OpenGlBackground)
};

102 changes: 51 additions & 51 deletions source/interface/open_gl_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,37 @@ OpenGlComponent::OpenGlComponent(juce::String name) : juce::Component(name), onl
OpenGlComponent::~OpenGlComponent() {
}

bool OpenGlComponent::setViewPort(juce::Component* component, juce::Rectangle<int> bounds, OpenGlWrapper& open_gl) {
FullInterface* top_level = component->findParentComponentOfClass<FullInterface>();
if(top_level == nullptr)
return false;
float scale = open_gl.display_scale;
float resize_scale = top_level->getResizingScale();
float render_scale = 1.0f;
if (scale == 1.0f)
render_scale = open_gl.context.getRenderingScale();

float gl_scale = render_scale * resize_scale;

juce::Rectangle<int> top_level_bounds = top_level->getBounds();
juce::Rectangle<int> global_bounds = getGlobalBounds(component, bounds);
juce::Rectangle<int> visible_bounds = getGlobalVisibleBounds(component, bounds);

// //juce::gl::glViewport(gl_scale * global_bounds.getX(),
// std::ceil(scale * render_scale * top_level_bounds.getHeight()) - gl_scale * global_bounds.getBottom(),
// gl_scale * global_bounds.getWidth(), gl_scale * global_bounds.getHeight());
juce::gl::glViewport(gl_scale * scale * global_bounds.getX(),
(std::ceil(scale * render_scale * top_level_bounds.getHeight()) - gl_scale * scale * global_bounds.getBottom()),
scale * gl_scale * global_bounds.getWidth(), scale * gl_scale * global_bounds.getHeight());

if (visible_bounds.getWidth() <= 0 || visible_bounds.getHeight() <= 0)
return false;

juce::gl::glScissor(gl_scale * scale * global_bounds.getX(),
(std::ceil(scale * render_scale * top_level_bounds.getHeight()) - gl_scale * scale * global_bounds.getBottom()),
scale * gl_scale * global_bounds.getWidth(), scale * gl_scale * global_bounds.getHeight());

return true;
bool OpenGlComponent::setViewPort(Component* component, juce::Rectangle<int> bounds, OpenGlWrapper& open_gl) {
FullInterface* top_level = component->findParentComponentOfClass<FullInterface>();
//DBG("----" + component->getName() + "-----");
if(top_level == nullptr)
return false;
float scale = open_gl.display_scale;
float resize_scale = top_level->getResizingScale();
// float render_scale = 1.0f;
// if (scale == 1.0f)
float render_scale = open_gl.context.getRenderingScale();
//DBG("resize_scale " + juce::String(resize_scale));
float gl_scale = render_scale * resize_scale;
float comp_scale = scale* Component::getApproximateScaleFactorForComponent(component);
auto top_level_bounds = top_level->getBounds();
auto global_bounds = getGlobalBounds(component, bounds);
auto visible_bounds = getGlobalVisibleBounds(component, bounds);
juce::gl::glViewport(comp_scale * global_bounds.getX(),
std::ceil(comp_scale * top_level_bounds.getHeight()) - comp_scale * global_bounds.getBottom(),
comp_scale * global_bounds.getWidth(), comp_scale * global_bounds.getHeight());
//DBG("gl scale" + juce::String(gl_scale));
//DBG("x" + juce::String(global_bounds.getX()));
//DBG("Y pos" + juce::String(std::ceil(render_scale * top_level_bounds.getHeight())) + " - " + juce::String(gl_scale * global_bounds.getBottom()) + " = "
// + juce::String(std::ceil(render_scale * top_level_bounds.getHeight()) - gl_scale * global_bounds.getBottom()));
//DBG(comp_scale);

if (visible_bounds.getWidth() <= 0 || visible_bounds.getHeight() <= 0)
return false;
juce::gl::glScissor(comp_scale * visible_bounds.getX(),
std::ceil( comp_scale * top_level_bounds.getHeight()) - comp_scale * visible_bounds.getBottom(),
comp_scale * visible_bounds.getWidth(), comp_scale * visible_bounds.getHeight());
return true;
}

bool OpenGlComponent::setViewPort(juce::Component* component, OpenGlWrapper& open_gl) {
Expand All @@ -102,26 +102,26 @@ void OpenGlComponent::setScissor(juce::Component* component, OpenGlWrapper& open
}

void OpenGlComponent::setScissorBounds(juce::Component* component, juce::Rectangle<int> bounds, OpenGlWrapper& open_gl) {
if (component == nullptr)
return;

FullInterface* top_level = component->findParentComponentOfClass<FullInterface>();
float scale = open_gl.display_scale;
float resize_scale = top_level->getResizingScale();
float render_scale = 1.0f;
if (scale == 1.0f)
render_scale *= open_gl.context.getRenderingScale();

float gl_scale = render_scale * resize_scale;

juce::Rectangle<int> top_level_bounds = top_level->getBounds();
juce::Rectangle<int> visible_bounds = getGlobalVisibleBounds(component, bounds);

if (visible_bounds.getHeight() > 0 && visible_bounds.getWidth() > 0) {
juce::gl::glScissor(gl_scale * visible_bounds.getX(),
std::ceil(scale * render_scale * top_level_bounds.getHeight()) - gl_scale * visible_bounds.getBottom(),
gl_scale * visible_bounds.getWidth(), gl_scale * visible_bounds.getHeight());
}
if (component == nullptr)
return;

FullInterface* top_level = component->findParentComponentOfClass<FullInterface>();
float scale = open_gl.display_scale;
float resize_scale = top_level->getResizingScale();
// float render_scale = 1.0f;
// if (scale == 1.0f)
float render_scale = open_gl.context.getRenderingScale();

float gl_scale = render_scale * resize_scale;

auto top_level_bounds = top_level->getBounds();
auto visible_bounds = getGlobalVisibleBounds(component, bounds);
float comp_scale = Component::getApproximateScaleFactorForComponent(component);
if (visible_bounds.getHeight() > 0 && visible_bounds.getWidth() > 0) {
juce::gl::glScissor(comp_scale * visible_bounds.getX(),
std::ceil(comp_scale * top_level_bounds.getHeight()) - comp_scale * visible_bounds.getBottom(),
comp_scale * visible_bounds.getWidth(), comp_scale * visible_bounds.getHeight());
}
}

void OpenGlComponent::paintBackground(juce::Graphics& g) {
Expand Down
Loading

0 comments on commit e754748

Please sign in to comment.