Great job guys ![]()
Noticed small thing that if child components have been rotated (via an affine transform), i don’t get same behaviour with d2d renderer vs Software renderer, with d2d component get like ‘cliped’, not sure if there is something special to do maybe…
here quick vid ex of what i mean: i double clic to rotate child red comp, first software, then d2d. can post code in case made mistakes
https://youtu.be/DBk4D74fwXw
#pragma once
#include <JuceHeader.h>
class ChildComponent : public juce::Component
{
public:
ChildComponent(){};
~ChildComponent() {};
void paint(juce::Graphics& g){g.fillAll(juce::Colour{0xFFFF0000});}
};
class MainComponent : public juce::Component
{
public:
//==============================================================================
MainComponent()
{
addAndMakeVisible(child_comp);
setSize(600, 400);
};
~MainComponent() {};
//==============================================================================
void paint(juce::Graphics& g)
{
g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
}
void resized()
{
child_comp.setSize(600, 100);
};
bool is_rotated = false;
bool use_d2d = true;
void mouseDoubleClick(const juce::MouseEvent& e)
{
if (is_rotated)
{
child_comp.setSize(600, 100);
child_comp.setTopLeftPosition({ 0,0 });
child_comp.setTransform({});
}
else{ rotate_comp(child_comp, false, { 100,600 });}
is_rotated = !is_rotated;
}
void parentHierarchyChanged() override
{
if (use_d2d) return;
if (auto peer = getPeer())
{
int wanted_engine = 0; // software?
peer->setCurrentRenderingEngine(wanted_engine);
}
}
static void rotate_comp(juce::Component& component, bool clockWiseRotation, juce::Rectangle<int> verticalBounds)
{
auto angle = juce::MathConstants<float>::pi / 2.0f;
if (!clockWiseRotation) angle *= -1.0f;
component.setTransform({});
component.setSize(verticalBounds.getHeight(), verticalBounds.getWidth());
component.setCentrePosition(0, 0);
component.setTransform(juce::AffineTransform::rotation(angle).translated(verticalBounds.getCentreX(), verticalBounds.getCentreY()));
}
ChildComponent child_comp;
private:
//==============================================================================
// Your private member variables go here...
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};
