Facet class file
#include "stdafx.h"
#include "Facet.h"
#include "CircularRegion.h"
CircularRegion* cyc_region;
Facet::Facet(HWND hWnd, int window_width, int window_height)
{
cyc_region = new CircularRegion(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() {
cyc_region->paint();
}
bool Facet::actionPerformed(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case 12321:
cyc_region->circledSquare();
return TRUE;
default:
return FALSE;
}
}
Facet::~Facet()
{
delete cyc_region;
}
CircularRegion Header file
#pragma once
#define sqLENGTH 100
class CircularRegion
{
public:
CircularRegion(HWND, int, int);
virtual ~CircularRegion();
void paint();
void circledSquare();
protected:
HWND hWindow;
HDC hdc;
int window_width;
int window_height;
COLORREF sq_colour;
int x_square;
int y_square;
int previous_x;
int previous_y;
int a;
int b;
const int r = 150;
double discriminant;
HBRUSH background_brush;
HPEN circle_pen;
HBRUSH sq_brush;
};
C++ code for CircularRegion Class file
#include "stdafx.h"
#include "CircularRegion.h"
#include <math.h>
CircularRegion::CircularRegion(HWND hWnd, int window_width, int window_height)
{
hWindow = hWnd;
this->window_width = window_width;
this->window_height = window_height;
sq_colour = RGB(255, 255, 0);
x_square = 10;
y_square = 250;
previous_x = x_square;
previous_y = y_square;
a = 500;
b = 275;
double discriminant;
background_brush = CreateSolidBrush(RGB(192, 192, 192));
circle_pen = CreatePen(PS_SOLID, 5, RGB(255, 0, 255));
sq_brush = CreateSolidBrush(sq_colour);
hdc = GetDC(hWindow);
}
void CircularRegion::paint() {
SelectObject(hdc, circle_pen);
SelectObject(hdc, background_brush);
Ellipse(hdc, a - r, b - r, a + r, b + r);
RECT prev_sq;
prev_sq.left = previous_x;
prev_sq.top = previous_y;
prev_sq.right = previous_x + sqLENGTH;
prev_sq.bottom = previous_y + sqLENGTH;
FillRect(hdc, &prev_sq, background_brush);
RECT sq;
sq.left = x_square;
sq.top = y_square;
sq.right = x_square + sqLENGTH;
sq.bottom = y_square + sqLENGTH;
FillRect(hdc, &sq, sq_brush);
previous_x = x_square;
previous_y = y_square;
}
void CircularRegion::circledSquare() {
while (x_square + sqLENGTH < window_width) {
int square_left = x_square;
int square_right = x_square + sqLENGTH;
int square_top = y_square;
int square_bottom = y_square + sqLENGTH;
int x_left_det = (int)round(sqrt(pow(r, 2) - pow((square_left - a), 2)));
int x_right_det = (int)round(sqrt(pow(r, 2) - pow((square_right - a), 2)));
int y_up_det = (int)round(sqrt(pow(r, 2) - pow((square_top - b), 2)));
int y_down_det = (int)round(sqrt(pow(r, 2) - pow((square_bottom - b), 2)));
if (square_top > b - x_left_det && square_bottom < b + x_left_det
&& square_top > b - x_right_det && square_bottom < b + x_right_det
&& square_left > a - y_up_det && square_right < a + y_up_det
&& square_left > a - y_down_det && square_right < a + y_down_det) {
sq_colour = RGB(0, 255, 0);
}
else {
sq_colour = RGB(255, 255, 0);
}
DeleteObject(sq_brush);
sq_brush = CreateSolidBrush(sq_colour);
paint();
x_square += 10;
Sleep(50);
}
}
CircularRegion::~CircularRegion()
{
DeleteObject(background_brush);
DeleteObject(circle_pen);
DeleteObject(sq_brush);
ReleaseDC(hWindow, hdc);
}