- added
git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@16 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -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 <cstdio>
|
||||
#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<double>(min, pData[i]);
|
||||
max = std::max<double>(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<double>(std::max<double>(*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
|
||||
|
||||
<JUCER_COMPONENT documentType="Component" className="DrawComponent" componentName=""
|
||||
parentClasses="public Component" constructorParams="int width, int height, int scale"
|
||||
variableInitialisers="" snapPixels="8" snapActive="1" snapShown="1"
|
||||
overlayOpacity="0.330" fixedSize="0" initialWidth="80" initialHeight="80">
|
||||
<METHODS>
|
||||
<METHOD name="mouseUp (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseMove (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseEnter (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseExit (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseDown (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseDrag (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseDoubleClick (const MouseEvent& e)"/>
|
||||
<METHOD name="mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)"/>
|
||||
</METHODS>
|
||||
<BACKGROUND backgroundColour="ff808080"/>
|
||||
</JUCER_COMPONENT>
|
||||
|
||||
END_JUCER_METADATA
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
||||
//[EndFile] You can add extra defines here...
|
||||
//[/EndFile]
|
||||
@@ -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;
|
||||
ScopedPointer<Image>m_pImage;
|
||||
ScopedPointer<Graphics>m_pG;
|
||||
ScopedPointer<double>m_pData;
|
||||
//[/UserVariables]
|
||||
|
||||
//==============================================================================
|
||||
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DrawComponent)
|
||||
};
|
||||
|
||||
//[EndFile] You can add extra defines here...
|
||||
//[/EndFile]
|
||||
|
||||
#endif // __JUCE_HEADER_7594B61AA9F7A49E__
|
||||
Reference in New Issue
Block a user