diff --git a/Source/DrawComponent.cpp b/Source/DrawComponent.cpp new file mode 100644 index 0000000..0b06103 --- /dev/null +++ b/Source/DrawComponent.cpp @@ -0,0 +1,243 @@ +/* + ============================================================================== + + This is an automatically generated GUI class created by the Introjucer! + + Be careful when adding custom code to these files, as only the code within + the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded + and re-saved. + + Created with Introjucer version: 3.1.0 + + ------------------------------------------------------------------------------ + + The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions" + Copyright 2004-13 by Raw Material Software Ltd. + + ============================================================================== +*/ + +//[Headers] You can add your own extra header files here... +#include +#include "noise.h" +//[/Headers] + +#include "DrawComponent.h" + + +//[MiscUserDefs] You can add your own user definitions and misc code here... +//[/MiscUserDefs] + +//============================================================================== +DrawComponent::DrawComponent (int width, int height, int scale) +{ + + //[UserPreSize] + noise_gen_t noise; + m_width = width; + m_height = height; + m_scale = scale; + + //[/UserPreSize] + + setSize (80, 80); + + + //[Constructor] You can add your own custom stuff here.. + m_pImage = new Image(Image::RGB , scale*width, scale*height, true); + m_pG = new Graphics(*m_pImage); + setSize (scale*width, scale*height); + m_pData = new double[width*height]; + + Noise_Init(&noise, 0x3231); + + double *pData = m_pData; + for (int i=0; i < width; i++) + { + for (int j=0; j < height; j++) + { + *(pData++) = Noise_Gaussian(&noise, 0.5, 0.3); + } + } + m_pG->setImageResamplingQuality(Graphics::lowResamplingQuality); + //[/Constructor] +} + +DrawComponent::~DrawComponent() +{ + //[Destructor_pre]. You can add your own custom destruction code here.. + //[/Destructor_pre] + + + + //[Destructor]. You can add your own custom destruction code here.. + m_pImage = nullptr; + m_pG = nullptr; + m_pData = nullptr; + //[/Destructor] +} + +//============================================================================== +void DrawComponent::paint (Graphics& g) +{ + //[UserPrePaint] Add your own custom painting code here.. + AffineTransform t; + + g.drawImage(*m_pImage, 0, 0, getWidth(), getHeight(), 0, 0, getWidth(), getHeight(), false); +// g.drawImageTransformed(*m_pImage, t.rotated(8), false); + return; + //[/UserPrePaint] + + g.fillAll (Colours::grey); + + //[UserPaint] Add your own custom painting code here.. + //[/UserPaint] +} + +void DrawComponent::resized() +{ + //[UserResized] Add your own custom resize handling here.. + printf("%s (%d,%d)\n", __func__, getWidth(), getHeight()); + repaint(); + //[/UserResized] +} + +void DrawComponent::mouseMove (const MouseEvent& e) +{ + //[UserCode_mouseMove] -- Add your code here... + printf("%s\n", __func__); + //[/UserCode_mouseMove] +} + +void DrawComponent::mouseEnter (const MouseEvent& e) +{ + //[UserCode_mouseEnter] -- Add your code here... + printf("%s\n", __func__); + //[/UserCode_mouseEnter] +} + +void DrawComponent::mouseExit (const MouseEvent& e) +{ + //[UserCode_mouseExit] -- Add your code here... + printf("%s\n", __func__); + //[/UserCode_mouseExit] +} + +void DrawComponent::mouseDown (const MouseEvent& e) +{ + //[UserCode_mouseDown] -- Add your code here... + printf("%s\n", __func__); + m_pG->setColour (Colours::black); + m_pG->fillAll(); + repaint(); + //[/UserCode_mouseDown] +} + +void DrawComponent::mouseDrag (const MouseEvent& e) +{ + //[UserCode_mouseDrag] -- Add your code here... + int x, y; + x = e.x; + y = e.y; + + printf("%s x:%d, y:%d\n", __func__, x, y); + m_pG->setColour (Colours::white); + m_pG->fillRect(x, y, 5, 5); + repaint(); + //[/UserCode_mouseDrag] +} + +void DrawComponent::mouseUp (const MouseEvent& e) +{ + //[UserCode_mouseUp] -- Add your code here... + printf("%s\n", __func__); + //[/UserCode_mouseUp] +} + +void DrawComponent::mouseDoubleClick (const MouseEvent& e) +{ + //[UserCode_mouseDoubleClick] -- Add your code here... + printf("%s\n", __func__); + //[/UserCode_mouseDoubleClick] +} + +void DrawComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel) +{ + //[UserCode_mouseWheelMove] -- Add your code here... + printf("%s\n", __func__); + //[/UserCode_mouseWheelMove] +} + + + +//[MiscUserCode] You can add your own definitions of your custom methods or any other code here... +void DrawComponent::drawGray (const double *pData) +{ + double a; + double min = +1E12; + double max = -1E12; + + for (int i=0; i < m_width*m_height; i++) + { + m_pData[i] = pData[i]; + min = std::min(min, pData[i]); + max = std::max(max, pData[i]); + } + for (int i=0; i < m_width*m_height; i++) + { + m_pData[i] -= min; + } + for (int i=0; i < m_width*m_height; i++) + { + m_pData[i] /= (max-min); + } + + pData = m_pData; + for (int i=0; i < m_width; i++) + { + for (int j=0; j < m_height; j++) + { + a = std::min(std::max(*pData, 0), 1); + m_pG->setColour(Colour(Colours::white).greyLevel(a)); + m_pG->fillRect(m_scale*i, m_scale*j, m_scale, m_scale); + pData++; + } + } + repaint(); +} +//[/MiscUserCode] + + +//============================================================================== +#if 0 +/* -- Introjucer information section -- + + This is where the Introjucer stores the metadata that describe this GUI layout, so + make changes in here at your peril! + +BEGIN_JUCER_METADATA + + + + + + + + + + + + + + + +END_JUCER_METADATA +*/ +#endif + + +//[EndFile] You can add extra defines here... +//[/EndFile] diff --git a/Source/DrawComponent.h b/Source/DrawComponent.h new file mode 100644 index 0000000..7357108 --- /dev/null +++ b/Source/DrawComponent.h @@ -0,0 +1,82 @@ +/* + ============================================================================== + + This is an automatically generated GUI class created by the Introjucer! + + Be careful when adding custom code to these files, as only the code within + the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded + and re-saved. + + Created with Introjucer version: 3.1.0 + + ------------------------------------------------------------------------------ + + The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions" + Copyright 2004-13 by Raw Material Software Ltd. + + ============================================================================== +*/ + +#ifndef __JUCE_HEADER_7594B61AA9F7A49E__ +#define __JUCE_HEADER_7594B61AA9F7A49E__ + +//[Headers] -- You can add your own extra header files here -- +#include "JuceHeader.h" +//[/Headers] + + + +//============================================================================== +/** + //[Comments] + An auto-generated component, created by the Introjucer. + + Describe your class and how it works here! + //[/Comments] +*/ +class DrawComponent : public Component +{ +public: + //============================================================================== + DrawComponent (int width, int height, int scale); + ~DrawComponent(); + + //============================================================================== + //[UserMethods] -- You can add your own custom methods in this section. + void drawGray(const double *pData); + //[/UserMethods] + + void paint (Graphics& g); + void resized(); + void mouseMove (const MouseEvent& e); + void mouseEnter (const MouseEvent& e); + void mouseExit (const MouseEvent& e); + void mouseDown (const MouseEvent& e); + void mouseDrag (const MouseEvent& e); + void mouseUp (const MouseEvent& e); + void mouseDoubleClick (const MouseEvent& e); + void mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel); + + + +private: + //[UserVariables] -- You can add your own custom variables in this section. + int m_width; + int m_height; + int m_scale; + ScopedPointerm_pImage; + ScopedPointerm_pG; + ScopedPointerm_pData; + //[/UserVariables] + + //============================================================================== + + + //============================================================================== + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DrawComponent) +}; + +//[EndFile] You can add extra defines here... +//[/EndFile] + +#endif // __JUCE_HEADER_7594B61AA9F7A49E__