further development
git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@17 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+76
-56
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
|
||||
//[Headers] You can add your own extra header files here...
|
||||
#include <cstdio>
|
||||
#include "noise.h"
|
||||
void mylog(const char* format, ...);
|
||||
//[/Headers]
|
||||
|
||||
#include "DrawComponent.h"
|
||||
@@ -29,14 +29,16 @@
|
||||
//[/MiscUserDefs]
|
||||
|
||||
//==============================================================================
|
||||
DrawComponent::DrawComponent (int width, int height, int scale)
|
||||
DrawComponent::DrawComponent (int width, int height)
|
||||
{
|
||||
|
||||
//[UserPreSize]
|
||||
noise_gen_t noise;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_scale = scale;
|
||||
m_scaleX = 1.0;
|
||||
m_scaleY = 1.0;
|
||||
m_pG = nullptr;
|
||||
|
||||
//[/UserPreSize]
|
||||
|
||||
@@ -44,21 +46,11 @@ DrawComponent::DrawComponent (int width, int height, int scale)
|
||||
|
||||
|
||||
//[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_pG = new Graphics(m_image);
|
||||
m_pData = new double[width*height];
|
||||
|
||||
memset(m_pData, 0, m_width*m_height*sizeof(double));
|
||||
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]
|
||||
}
|
||||
@@ -71,7 +63,6 @@ DrawComponent::~DrawComponent()
|
||||
|
||||
|
||||
//[Destructor]. You can add your own custom destruction code here..
|
||||
m_pImage = nullptr;
|
||||
m_pG = nullptr;
|
||||
m_pData = nullptr;
|
||||
//[/Destructor]
|
||||
@@ -83,7 +74,7 @@ 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.drawImage(m_image, 0, 0, getWidth(), getHeight(), 0, 0, getWidth(), getHeight(), false);
|
||||
// g.drawImageTransformed(*m_pImage, t.rotated(8), false);
|
||||
return;
|
||||
//[/UserPrePaint]
|
||||
@@ -97,7 +88,13 @@ void DrawComponent::paint (Graphics& g)
|
||||
void DrawComponent::resized()
|
||||
{
|
||||
//[UserResized] Add your own custom resize handling here..
|
||||
printf("%s (%d,%d)\n", __func__, getWidth(), getHeight());
|
||||
// mylog("%s (%d,%d)\n", __func__, getWidth(), getHeight());
|
||||
m_scaleX = (float)getWidth()/m_width;
|
||||
m_scaleY = (float)getHeight()/m_height;
|
||||
m_image = Image(Image::RGB , getWidth(), getHeight(), true);
|
||||
m_pG = nullptr;
|
||||
m_pG = new Graphics(m_image);
|
||||
|
||||
repaint();
|
||||
//[/UserResized]
|
||||
}
|
||||
@@ -105,101 +102,124 @@ void DrawComponent::resized()
|
||||
void DrawComponent::mouseMove (const MouseEvent& e)
|
||||
{
|
||||
//[UserCode_mouseMove] -- Add your code here...
|
||||
printf("%s\n", __func__);
|
||||
// mylogMessage(String("MouseMove"));
|
||||
//[/UserCode_mouseMove]
|
||||
}
|
||||
|
||||
void DrawComponent::mouseEnter (const MouseEvent& e)
|
||||
{
|
||||
//[UserCode_mouseEnter] -- Add your code here...
|
||||
printf("%s\n", __func__);
|
||||
// mylog("%s\n", __func__);
|
||||
//[/UserCode_mouseEnter]
|
||||
}
|
||||
|
||||
void DrawComponent::mouseExit (const MouseEvent& e)
|
||||
{
|
||||
//[UserCode_mouseExit] -- Add your code here...
|
||||
printf("%s\n", __func__);
|
||||
// mylog("%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();
|
||||
// mylog("%s x:%d, y:%d\n", __func__, e.x, e.y);
|
||||
if (e.mods.isRightButtonDown())
|
||||
{
|
||||
clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
drawAt(e.x, e.y);
|
||||
}
|
||||
//[/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();
|
||||
// mylog("%s x:%d, y:%d\n", __func__, e.x, e.y);
|
||||
if (e.mods.isLeftButtonDown())
|
||||
{
|
||||
drawAt(e.x, e.y);
|
||||
}
|
||||
//[/UserCode_mouseDrag]
|
||||
}
|
||||
|
||||
void DrawComponent::mouseUp (const MouseEvent& e)
|
||||
{
|
||||
//[UserCode_mouseUp] -- Add your code here...
|
||||
printf("%s\n", __func__);
|
||||
// mylog("%s\n", __func__);
|
||||
//[/UserCode_mouseUp]
|
||||
}
|
||||
|
||||
void DrawComponent::mouseDoubleClick (const MouseEvent& e)
|
||||
{
|
||||
//[UserCode_mouseDoubleClick] -- Add your code here...
|
||||
printf("%s\n", __func__);
|
||||
// mylog("%s\n", __func__);
|
||||
//[/UserCode_mouseDoubleClick]
|
||||
}
|
||||
|
||||
void DrawComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
|
||||
{
|
||||
//[UserCode_mouseWheelMove] -- Add your code here...
|
||||
printf("%s\n", __func__);
|
||||
// mylog("%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)
|
||||
void DrawComponent::drawAt(int x, int y)
|
||||
{
|
||||
int index;
|
||||
double fx = (double)x / m_scaleX;
|
||||
double fy = (double)y / m_scaleY;
|
||||
|
||||
index = (int)(x/m_scaleX) + m_width*(int)(y/m_scaleY);
|
||||
// mylog("Write(%d)\n", index);
|
||||
|
||||
if (index >= 0)
|
||||
if (index < m_width*m_height)
|
||||
m_pData[index] = 1.0;
|
||||
|
||||
x = (int)fx * m_scaleX;
|
||||
y = (int)fy * m_scaleY;
|
||||
m_pG->setColour (Colours::white);
|
||||
m_pG->fillRect((float)x, (float)y, m_scaleX, m_scaleY);
|
||||
repaint();
|
||||
}
|
||||
|
||||
void DrawComponent::clear()
|
||||
{
|
||||
double *pData = m_pData;
|
||||
for (int i=0; i < m_width*m_height; i++)
|
||||
{
|
||||
*(pData++) = 0;
|
||||
}
|
||||
setData(m_pData);
|
||||
}
|
||||
|
||||
const double* DrawComponent::getData ()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
void DrawComponent::setData (const double *pData)
|
||||
{
|
||||
double a;
|
||||
double min = +1E12;
|
||||
double max = -1E12;
|
||||
|
||||
for (int i=0; i < m_width*m_height; i++)
|
||||
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++)
|
||||
for (int i=0; i < 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++)
|
||||
for (int j=0; j < m_width; 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);
|
||||
m_pG->fillRect(m_scaleX*j, m_scaleY*i, m_scaleX, m_scaleY);
|
||||
pData++;
|
||||
}
|
||||
}
|
||||
@@ -218,7 +238,7 @@ void DrawComponent::drawGray (const double *pData)
|
||||
BEGIN_JUCER_METADATA
|
||||
|
||||
<JUCER_COMPONENT documentType="Component" className="DrawComponent" componentName=""
|
||||
parentClasses="public Component" constructorParams="int width, int height, int scale"
|
||||
parentClasses="public Component" constructorParams="int width, int height"
|
||||
variableInitialisers="" snapPixels="8" snapActive="1" snapShown="1"
|
||||
overlayOpacity="0.330" fixedSize="0" initialWidth="80" initialHeight="80">
|
||||
<METHODS>
|
||||
|
||||
Reference in New Issue
Block a user