Initial
This commit is contained in:
256
Histogram/GraphWnd.cpp
Normal file
256
Histogram/GraphWnd.cpp
Normal file
@@ -0,0 +1,256 @@
|
||||
#include <histogram/graphwnd.hpp>
|
||||
#include <histogram/graph3d.hpp>
|
||||
#include <histogram/clrrect.hpp>
|
||||
#include <music/scales.hpp>
|
||||
#include <engine/spacial.hpp>
|
||||
#include <engine/rect3d.hpp>
|
||||
#include <common/string.hpp>
|
||||
#include <common/rect.hpp>
|
||||
#include <common/catmull.hpp>
|
||||
|
||||
char GraphWindow::smszClassName[]={"GraphWindow"};
|
||||
char GraphWindow::smszMenuName[]={""};
|
||||
|
||||
GraphWindow::GraphWindow(GUIWindow &parentWindow,const Rect &winRect)
|
||||
{
|
||||
mPaintHandler.setCallback(this,&GraphWindow::paintHandler);
|
||||
mCreateHandler.setCallback(this,&GraphWindow::createHandler);
|
||||
mDestroyHandler.setCallback(this,&GraphWindow::destroyHandler);
|
||||
mKeyDownHandler.setCallback(this,&GraphWindow::keyDownHandler);
|
||||
mLeftButtonDownHandler.setCallback(this,&GraphWindow::leftButtonDownHandler);
|
||||
mDialogCodeHandler.setCallback(this,&GraphWindow::dialogCodeHandler);
|
||||
insertHandler(VectorHandler::PaintHandler,&mPaintHandler);
|
||||
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
||||
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
||||
insertHandler(VectorHandler::KeyDownHandler,&mKeyDownHandler);
|
||||
insertHandler(VectorHandler::LeftButtonDownHandler,&mLeftButtonDownHandler);
|
||||
insertHandler(VectorHandler::DialogCodeHandler,&mDialogCodeHandler);
|
||||
registerClass();
|
||||
initializePalette();
|
||||
createWindow(parentWindow,winRect);
|
||||
mGraph3D=::new Graph3D(*this,mGraphPalette);
|
||||
mGraph3D.disposition(PointerDisposition::Delete);
|
||||
setPerspective();
|
||||
show(SW_SHOW);
|
||||
update();
|
||||
}
|
||||
|
||||
GraphWindow::GraphWindow(const GraphWindow &/*someGraphWindow*/)
|
||||
{ // private implementation
|
||||
}
|
||||
|
||||
GraphWindow::~GraphWindow()
|
||||
{
|
||||
removeHandler(VectorHandler::PaintHandler,&mPaintHandler);
|
||||
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
||||
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
||||
removeHandler(VectorHandler::KeyDownHandler,&mKeyDownHandler);
|
||||
removeHandler(VectorHandler::LeftButtonDownHandler,&mLeftButtonDownHandler);
|
||||
removeHandler(VectorHandler::DialogCodeHandler,&mDialogCodeHandler);
|
||||
}
|
||||
|
||||
void GraphWindow::initializePalette(void)
|
||||
{
|
||||
Array<RGBColor> rgbColors;;
|
||||
|
||||
rgbColors.size(4);
|
||||
rgbColors[0]=RGBColor(0,0,0);
|
||||
rgbColors[1]=RGBColor(255,255,255);
|
||||
rgbColors[2]=RGBColor(255,0,0);
|
||||
rgbColors[3]=RGBColor(0,255,0);
|
||||
mGraphPalette.setPaletteColors(rgbColors);
|
||||
}
|
||||
|
||||
void GraphWindow::registerClass(void)const
|
||||
{
|
||||
HINSTANCE hInstance(processInstance());
|
||||
WNDCLASS wndClass;
|
||||
|
||||
if(::GetClassInfo(hInstance,smszClassName,(WNDCLASS FAR*)&wndClass))return;
|
||||
wndClass.style =CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS|CS_OWNDC;
|
||||
wndClass.lpfnWndProc =(WNDPROC)Window::WndProc;
|
||||
wndClass.cbClsExtra =0;
|
||||
wndClass.cbWndExtra =sizeof(GraphWindow*);
|
||||
wndClass.hInstance =hInstance;
|
||||
wndClass.hIcon =::LoadIcon(NULL,IDI_APPLICATION);
|
||||
wndClass.hCursor =::LoadCursor(NULL,IDC_ARROW);
|
||||
wndClass.hbrBackground =(HBRUSH)::GetStockObject(HOLLOW_BRUSH);
|
||||
wndClass.lpszMenuName =smszMenuName;
|
||||
wndClass.lpszClassName =smszClassName;
|
||||
::RegisterClass(&wndClass);
|
||||
assert(0!=::GetClassInfo(hInstance,smszClassName,(WNDCLASS FAR*)&wndClass));
|
||||
}
|
||||
|
||||
void GraphWindow::createWindow(GUIWindow &parentWindow,const Rect &winRect)
|
||||
{
|
||||
Window::createWindow(WS_EX_CLIENTEDGE,String(smszClassName),String(smszMenuName),
|
||||
WS_CHILD|WS_OVERLAPPED|WS_CLIPCHILDREN|WS_BORDER,winRect,
|
||||
parentWindow,(HMENU)103,processInstance(),(LPSTR)this);
|
||||
show(SW_SHOW);
|
||||
update();
|
||||
}
|
||||
|
||||
CallbackData::ReturnType GraphWindow::paintHandler(CallbackData &someCallbackData)
|
||||
{
|
||||
if(!mGraph3D.isOkay())return (CallbackData::ReturnType)FALSE;
|
||||
PaintInformation *pPaintInfo=(PaintInformation*)someCallbackData.lParam();
|
||||
mGraph3D->clearBits();
|
||||
for(int rectIndex=0;rectIndex<mGraphRects.size();rectIndex++)
|
||||
{
|
||||
ColorRect &colorRect=mGraphRects[rectIndex];
|
||||
mGraph3D->rectangle(colorRect,colorRect.paletteIndex());
|
||||
}
|
||||
mGraph3D->bitBlt((PureDevice&)*pPaintInfo);
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType GraphWindow::createHandler(CallbackData &/*someCallbackData*/)
|
||||
{
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType GraphWindow::leftButtonDownHandler(CallbackData &/*someCallbackData*/)
|
||||
{
|
||||
setFocus();
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType GraphWindow::dialogCodeHandler(CallbackData &/*someCallbackData*/)
|
||||
{
|
||||
return (CallbackData::ReturnType)DLGC_WANTARROWS|DLGC_WANTCHARS;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType GraphWindow::keyDownHandler(CallbackData &someCallbackData)
|
||||
{
|
||||
switch(someCallbackData.wParam())
|
||||
{
|
||||
case inKey :
|
||||
if(shiftKeyPressed())mGraph3D->cameraTwistDegrees(mGraph3D->cameraTwistDegrees()-ThetaDelta);
|
||||
mGraph3D->viewPlaneDistance(mGraph3D->viewPlaneDistance()+ViewDelta);
|
||||
invalidate(FALSE);
|
||||
break;
|
||||
case outKey :
|
||||
if(shiftKeyPressed())mGraph3D->cameraTwistDegrees(mGraph3D->cameraTwistDegrees()+ThetaDelta);
|
||||
mGraph3D->viewPlaneDistance(mGraph3D->viewPlaneDistance()-ViewDelta);
|
||||
invalidate(FALSE);
|
||||
break;
|
||||
case UpArrow :
|
||||
if(handleUpArrow())invalidate(FALSE);
|
||||
break;
|
||||
case DownArrow :
|
||||
if(handleDownArrow())invalidate(FALSE);
|
||||
break;
|
||||
case LeftArrow :
|
||||
if(handleLeftArrow())invalidate(FALSE);
|
||||
break;
|
||||
case RightArrow :
|
||||
if(handleRightArrow())invalidate(FALSE);
|
||||
break;
|
||||
}
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType GraphWindow::destroyHandler(CallbackData &/*someCallbackData*/)
|
||||
{
|
||||
return (CallbackData::ReturnType)FALSE;
|
||||
}
|
||||
|
||||
void GraphWindow::showHistogram(TabEntries &entries)
|
||||
{
|
||||
Block<int> vectorInt;
|
||||
IonianScale ionianScale;
|
||||
|
||||
mGraphRects.remove();
|
||||
setPerspective();
|
||||
for(int itemIndex=0;itemIndex<entries.size();itemIndex++)
|
||||
{
|
||||
TabEntry &entry=entries[itemIndex];
|
||||
for(int index=0;index<entry.size();index++)
|
||||
{
|
||||
Note note=entry[index].getNote();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Array<int> vectorInt;
|
||||
int itemIndex;
|
||||
int vectorIndex;
|
||||
|
||||
vectorInt.size((Note::B-Note::C)+1);
|
||||
for(int index=0;index<vectorInt.size();index++)vectorInt[index]=0;
|
||||
mGraphRects.remove();
|
||||
setPerspective();
|
||||
for(itemIndex=0,vectorIndex=0;itemIndex<entries.size();itemIndex++,vectorIndex++)
|
||||
{
|
||||
TabEntry &entry=entries[itemIndex];
|
||||
for(int index=0;index<entry.size();index++)
|
||||
{
|
||||
int value=entry[index].getNote().getNote();
|
||||
vectorInt[value]=vectorInt[value]+1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
// showHistogram(vectorInt,mGraph3D->getPalette().paletteIndex(RGBColor(255,255,255)));
|
||||
// invalidate();
|
||||
}
|
||||
|
||||
void GraphWindow::showHistogram(Array<int> &vectorInt,BYTE paletteIndex,int zDepth)
|
||||
{
|
||||
Array<int> scrnInt;
|
||||
int widthAdjust(5);
|
||||
|
||||
WORD sizeFactor(((((float)width()-20)/(float)widthAdjust)/(float)(Note::B-Note::C)+1)*100.00);
|
||||
SpacialTransform resample;
|
||||
resample.transform(vectorInt,scrnInt,sizeFactor);
|
||||
for(int itemIndex=0,xPoint=widthAdjust;itemIndex<scrnInt.size();itemIndex++,xPoint+=widthAdjust)
|
||||
{
|
||||
Vector3D outerPlane(Point3D(xPoint,scrnInt[itemIndex]+1,zDepth),
|
||||
Point3D(xPoint+widthAdjust,scrnInt[itemIndex]+1,zDepth),Point3D(xPoint+widthAdjust,0,zDepth),Point3D(xPoint,0,zDepth));
|
||||
Rect3D rect3D(outerPlane,10);
|
||||
mGraphRects.insert(&ColorRect(rect3D,paletteIndex));
|
||||
}
|
||||
}
|
||||
|
||||
bool GraphWindow::handleUpArrow(void)
|
||||
{
|
||||
Point3D cameraPoint(mGraph3D->cameraPoint());
|
||||
cameraPoint.y(cameraPoint.y()+TurnDelta);
|
||||
mGraph3D->cameraPoint(cameraPoint);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool GraphWindow::handleDownArrow(void)
|
||||
{
|
||||
Point3D cameraPoint(mGraph3D->cameraPoint());
|
||||
cameraPoint.y(cameraPoint.y()-TurnDelta);
|
||||
mGraph3D->cameraPoint(cameraPoint);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool GraphWindow::handleLeftArrow(void)
|
||||
{
|
||||
Point3D cameraPoint(mGraph3D->cameraPoint());
|
||||
if(shiftKeyPressed())mGraph3D->cameraTwistDegrees(mGraph3D->cameraTwistDegrees()-ThetaDelta);
|
||||
else cameraPoint.x(cameraPoint.x()+TurnDelta);
|
||||
mGraph3D->cameraPoint(cameraPoint);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool GraphWindow::handleRightArrow(void)
|
||||
{
|
||||
Point3D cameraPoint(mGraph3D->cameraPoint());
|
||||
if(shiftKeyPressed())mGraph3D->cameraTwistDegrees(mGraph3D->cameraTwistDegrees()+ThetaDelta);
|
||||
else cameraPoint.x(cameraPoint.x()-TurnDelta);
|
||||
mGraph3D->cameraPoint(cameraPoint);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void GraphWindow::setPerspective(void)
|
||||
{
|
||||
mGraph3D->cameraTwistDegrees(134.64);
|
||||
mGraph3D->viewPlaneDistance(40);
|
||||
mGraph3D->cameraPoint(Point3D(-385,75,75));
|
||||
mGraph3D->focusPoint(Point3D(0,0,1));
|
||||
}
|
||||
Reference in New Issue
Block a user