236 lines
7.9 KiB
C++
236 lines
7.9 KiB
C++
#include <cashflow/graphwnd.hpp>
|
|
#include <cashflow/graph3d.hpp>
|
|
#include <cashflow/purecflo.hpp>
|
|
#include <cashflow/clrrect.hpp>
|
|
#include <engine/spacial.hpp>
|
|
#include <engine/rect3d.hpp>
|
|
#include <common/string.hpp>
|
|
#include <common/rect.hpp>
|
|
|
|
char GraphWindow::smszClassName[]={"GraphWindow"};
|
|
char GraphWindow::smszMenuName[]={""};
|
|
|
|
#pragma warning(disable:4355)
|
|
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();
|
|
createWindow(parentWindow,winRect);
|
|
mGraph3D=new Graph3D(*this);
|
|
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::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::showFlows(Block<PureCashFlow> &pureCashFlows,int baseMonths)
|
|
{
|
|
PureVector<int> vectorInt;
|
|
|
|
mGraphRects.remove();
|
|
setPerspective();
|
|
vectorInt.size(pureCashFlows.size());
|
|
for(int itemIndex=0;itemIndex<pureCashFlows.size();itemIndex++)vectorInt[itemIndex]=int(pureCashFlows[itemIndex].totPrin());
|
|
showFlows(pureCashFlows,baseMonths,vectorInt,32);
|
|
for(itemIndex=0;itemIndex<pureCashFlows.size();itemIndex++)vectorInt[itemIndex]=int(pureCashFlows[itemIndex].netIntPay());
|
|
showFlows(pureCashFlows,baseMonths,vectorInt,30,10);
|
|
invalidate();
|
|
}
|
|
|
|
void GraphWindow::showFlows(Block<PureCashFlow> &pureCashFlows,int baseMonths,PureVector<int> &vectorInt,BYTE paletteIndex,int zDepth)
|
|
{
|
|
PureVector<int> scrnInt;
|
|
int widthAdjust(5);
|
|
|
|
clamp(vectorInt);
|
|
WORD sizeFactor(((((float)width()-20)/(float)widthAdjust)/(float)baseMonths)*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));
|
|
}
|
|
}
|
|
|
|
void GraphWindow::clamp(PureVector<int> &vectorInt)
|
|
{
|
|
float factor=0.00;
|
|
int vectorMax;
|
|
|
|
if(!vectorInt.size())return;
|
|
for(int itemIndex=0;itemIndex<vectorInt.size();itemIndex++)
|
|
{
|
|
if(!itemIndex)vectorMax=vectorInt[itemIndex];
|
|
else if(vectorInt[itemIndex]>vectorMax)vectorMax=vectorInt[itemIndex];
|
|
}
|
|
factor=(1.00/(float)vectorMax);
|
|
for(itemIndex=0;itemIndex<vectorInt.size();itemIndex++)vectorInt[itemIndex]=(float)vectorInt[itemIndex]*factor*100.00;
|
|
}
|
|
|
|
WORD GraphWindow::handleUpArrow(void)
|
|
{
|
|
Point3D cameraPoint(mGraph3D->cameraPoint());
|
|
cameraPoint.y(cameraPoint.y()+TurnDelta);
|
|
mGraph3D->cameraPoint(cameraPoint);
|
|
return TRUE;
|
|
}
|
|
|
|
WORD GraphWindow::handleDownArrow(void)
|
|
{
|
|
Point3D cameraPoint(mGraph3D->cameraPoint());
|
|
cameraPoint.y(cameraPoint.y()-TurnDelta);
|
|
mGraph3D->cameraPoint(cameraPoint);
|
|
return TRUE;
|
|
}
|
|
|
|
WORD 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;
|
|
}
|
|
|
|
WORD 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));
|
|
}
|
|
|