Facet class file
#include "stdafx.h"
#include "Facet.h"
#include "PeriodicFunction.h"
PeriodicFunction* pf_track;
Facet::Facet(HWND hWnd, int window_width, int window_height)
{
pf_track = new PeriodicFunction(hWnd, window_width, window_height);
}
bool Facet::decorateButton(WPARAM wParam, LPARAM lParam) {
if (wParam == 12321)
{
LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT)lParam;
SetDCBrushColor(lpDIS->hDC, RGB(255, 192, 203));
SelectObject(lpDIS->hDC, GetStockObject(DC_BRUSH));
RECT rect = { 0 };
rect.left = lpDIS->rcItem.left;
rect.right = lpDIS->rcItem.right;
rect.top = lpDIS->rcItem.top;
rect.bottom = lpDIS->rcItem.bottom;
RoundRect(lpDIS->hDC, rect.left, rect.top, rect.right, rect.bottom, 50, 50);
DrawText(lpDIS->hDC, TEXT("MOVE"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
return TRUE;
}
return FALSE;
}
void Facet::informPaint() {
pf_track->paint();
}
bool Facet::actionPerformed(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case 12321:
pf_track->moveSinusoidal();
return TRUE;
default:
return FALSE;
}
}
Facet::~Facet()
{
delete pf_track;
}
PeriodicFunction Header file
#pragma once
#define aWIDTH 10
#define aHEIGHT 10
#define PI 3.1415926535897932384626433832795
class PeriodicFunction
{
public:
PeriodicFunction(HWND, int, int);
virtual ~PeriodicFunction();
void paint();
void moveSinusoidal();
protected:
HWND hWindow;
HDC hdc;
int window_width;
int window_height;
COLORREF ball_colour;
int theta;
int a;
int y;
HPEN ball_pen;
HBRUSH ball_brush;
};
C++ code for PeriodicFunction Class file
#include "stdafx.h"
#include "PeriodicFunction.h"
#include <math.h>
PeriodicFunction::PeriodicFunction(HWND hWnd, int window_width, int window_height)
{
hWindow = hWnd;
this->window_width = window_width;
this->window_height = window_height;
ball_colour = RGB(255, 0, 0);
theta = 0;
a = 100;
y = (int)round(a * sin(theta * (long double)PI / 180)) + int(window_height / 2);
ball_pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
ball_brush = CreateSolidBrush(ball_colour);
hdc = GetDC(hWindow);
SelectObject(hdc, ball_pen);
SelectObject(hdc, ball_brush);
MoveToEx(hdc, 0, 80, NULL);
LineTo(hdc, window_width, 80);
MoveToEx(hdc, 0, int(window_height/2 + aHEIGHT/2), NULL);
LineTo(hdc, window_width, int(window_height/2 + aHEIGHT/2));
}
void PeriodicFunction::paint() {
Ellipse(hdc, theta, y, theta + aWIDTH, y + aHEIGHT);
}
void PeriodicFunction::moveSinusoidal() {
while (theta + aWIDTH < window_width) {
y = (int)round(a * sin(theta * (long double)PI / 180)) + int(window_height / 2);
paint();
theta += 15;
Sleep(50);
}
}
PeriodicFunction::~PeriodicFunction()
{
DeleteObject(ball_pen);
DeleteObject(ball_brush);
ReleaseDC(hWindow, hdc);
}