/******************************************************************************************************/
//
//
// VERSION : 1.0
// NAME : BSpline.cpp (Non Uniform Non Rational B-Splines)
// DESC : a class for B-Splines
// AUTOR : Stefan Beck | tolschock@gmx.de
// DATE : 28.04.2004
// UPDATE : 28.04.2004 | 29.04.2004
// BUGS : none
//
/******************************************************************************************************/
#include <windows.h>
#include "BSpline.h" // class for BSplines
/******************************************************************************************************/
HWND hWnd = 0; // handle on the main application
HDC hDC; // graphics context
HWND CreateMainWindow(HINSTANCE hInstance); // create window and set its properties
LRESULT CALLBACK MessageHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); // process messages
BSpline b1(3, 40); // a BSpline Object
// organisationally variables
//----------------------------------------------------------------------------------------
bool picked = 0; // is a controll point picked ?
int picked_cp = 0; // which kp is picked ?
int loc_x = 500; // local x coordinates
int loc_y = 400; // local y coordinates
#include "functions.h" // include necesary functions
/******************************************************************************************************/
/******************************************************************************************************/
LRESULT CALLBACK MessageHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
/****************************************************************************/
case WM_LBUTTONDOWN: // add cp
{
if(b1.GetControllPoint(lParam, hDC) >= 0) // mouse is over point
{
picked_cp = b1.GetControllPoint(lParam, hDC); // whichh kp is picked ?
picked = 1; // kp is picked
}
else // add a new controll point
{
if(b1.GetCPNr() < b1.GetMaxCP())
{
b1.SetCPValue(b1.GetCPNr(), LOWORD(lParam)-loc_x, HIWORD(lParam)-loc_y, 0);
b1.SetCPNr(b1.GetCPNr()+1);
b1.createNodeVector();
}
InvalidateRect(hWnd, 0, TRUE);
}
return 0;
}break;
/****************************************************************************/
case WM_LBUTTONUP:
{
if( picked==1 ){ picked_cp = 0; picked = 0; }
return 0;
}break;
/****************************************************************************/
case WM_RBUTTONDOWN: // remove cp
{
if(b1.GetControllPoint(lParam, hDC) == b1.GetCPNr()-1) // delete the last kp
{
if(b1.GetCPNr() > b1.GetDegree()+1)
{
b1.SetCPNr(b1.GetCPNr()-1);
b1.createNodeVector();
}
}
InvalidateRect(hWnd, 0, TRUE);
return 0;
}break;
/****************************************************************************/
case WM_MOUSEMOVE: // move cp
{
if( picked==1 ) // if picked
{
b1.SetCPValue(picked_cp, LOWORD(lParam)-loc_x, HIWORD(lParam)-loc_y, 20);
InvalidateRect(hWnd, 0, TRUE);
}
return 0;
}break;
/****************************************************************************/
case WM_PAINT:
{
PAINTSTRUCT ps; // paintstructure
hDC = BeginPaint(hWnd, &ps); // here the paintings starts
//-------------------------------------------------------------------------------------------------
b1.ShowTextInfo(hDC); // infos about the nV, and thhe control points
b1.ShowControlElements(lParam, hDC); // show control points and control lines
//b1.BSplinePoints(hDC);
b1.BSplineLines(hDC);
//-------------------------------------------------------------------------------------------------
EndPaint(hWnd, &ps); // and here ends the paintings
return 0;
}break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
/******************************************************************************************************/