From dd6ac22c1691e819abc5a2f64f6a0c407c0826cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D7=90=D7=99=D7=AA=D7=9F=20=D7=A7=D7=98=D7=99=D7=99=D7=91?= Date: Wed, 20 Mar 2024 17:07:02 +0200 Subject: [PATCH] Add project files. --- 8BitBounce.sln | 31 +++++ 8BitBounce/8BitBounce.cpp | 40 ++++++ 8BitBounce/8BitBounce.vcxproj | 139 +++++++++++++++++++++ 8BitBounce/8BitBounce.vcxproj.filters | 30 +++++ 8BitBounce/Ball.cpp | 173 ++++++++++++++++++++++++++ 8BitBounce/Ball.h | 18 +++ 6 files changed, 431 insertions(+) create mode 100644 8BitBounce.sln create mode 100644 8BitBounce/8BitBounce.cpp create mode 100644 8BitBounce/8BitBounce.vcxproj create mode 100644 8BitBounce/8BitBounce.vcxproj.filters create mode 100644 8BitBounce/Ball.cpp create mode 100644 8BitBounce/Ball.h diff --git a/8BitBounce.sln b/8BitBounce.sln new file mode 100644 index 0000000..78edc9f --- /dev/null +++ b/8BitBounce.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33502.453 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "8BitBounce", "8BitBounce\8BitBounce.vcxproj", "{C1D10CC7-827E-491B-93C1-306F2A5E2EAE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C1D10CC7-827E-491B-93C1-306F2A5E2EAE}.Debug|x64.ActiveCfg = Debug|x64 + {C1D10CC7-827E-491B-93C1-306F2A5E2EAE}.Debug|x64.Build.0 = Debug|x64 + {C1D10CC7-827E-491B-93C1-306F2A5E2EAE}.Debug|x86.ActiveCfg = Debug|Win32 + {C1D10CC7-827E-491B-93C1-306F2A5E2EAE}.Debug|x86.Build.0 = Debug|Win32 + {C1D10CC7-827E-491B-93C1-306F2A5E2EAE}.Release|x64.ActiveCfg = Release|x64 + {C1D10CC7-827E-491B-93C1-306F2A5E2EAE}.Release|x64.Build.0 = Release|x64 + {C1D10CC7-827E-491B-93C1-306F2A5E2EAE}.Release|x86.ActiveCfg = Release|Win32 + {C1D10CC7-827E-491B-93C1-306F2A5E2EAE}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0F2F1CA2-F0D2-42FF-97C3-F2584CBC8D9C} + EndGlobalSection +EndGlobal diff --git a/8BitBounce/8BitBounce.cpp b/8BitBounce/8BitBounce.cpp new file mode 100644 index 0000000..c4e9d2a --- /dev/null +++ b/8BitBounce/8BitBounce.cpp @@ -0,0 +1,40 @@ +// 8BitBounce.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include "Ball.h" +using namespace std; + +int main() +{ + Window* pWindow = new Window(); + + bool running = true; + while (running) + { + + if (!pWindow->ProcessMessages()) + { + + cout << "Closing window\n"; + running = false; + } + + Sleep(10); + } + + delete pWindow; + + return 0; +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/8BitBounce/8BitBounce.vcxproj b/8BitBounce/8BitBounce.vcxproj new file mode 100644 index 0000000..ae4818c --- /dev/null +++ b/8BitBounce/8BitBounce.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {c1d10cc7-827e-491b-93c1-306f2a5e2eae} + My8BitBounce + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/8BitBounce/8BitBounce.vcxproj.filters b/8BitBounce/8BitBounce.vcxproj.filters new file mode 100644 index 0000000..597d125 --- /dev/null +++ b/8BitBounce/8BitBounce.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/8BitBounce/Ball.cpp b/8BitBounce/Ball.cpp new file mode 100644 index 0000000..59638a4 --- /dev/null +++ b/8BitBounce/Ball.cpp @@ -0,0 +1,173 @@ +#include "Ball.h" + + +int width = 100; +int height = 100; +int centerW = width / 2; +int centerH = height / 2; + +LRESULT CALLBACK BallWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + { + static HBRUSH hBrush = NULL; + static RECT rect; + PAINTSTRUCT ps; + HDC hdc; + static bool isPressed; + + switch (uMsg) + { + case WM_CREATE: + { + // Creates a solid brush for the button background color + hBrush = CreateSolidBrush(RGB(100, 0, 0)); // Change the RGB values to set your desired background color + break; + } + case WM_SIZE: + { + // Stores the button's client area dimensions + GetClientRect(hWnd, &rect); + + // Create a circular region based on the updated client rect + HRGN hRgn = CreateEllipticRgn(0, 0, rect.right, rect.bottom); + SetWindowRgn(hWnd, hRgn, TRUE); // Set the window region. TRUE to redraw the window immediately + + // NOTE: The region is now owned by the system, no need to call DeleteObject on hRgn + break; + } + case WM_PAINT: + { + hdc = BeginPaint(hWnd, &ps); + + // Create the outer and inner rectangles + RECT outerRect = { 0, 0, rect.right, rect.bottom }; + RECT innerRect = { 5, 5, rect.right - 5, rect.bottom - 5 }; + + // Create the outer and inner regions + HRGN outerRgn = CreateEllipticRgnIndirect(&outerRect); + HRGN innerRgn = CreateEllipticRgnIndirect(&innerRect); + + // Combine the regions to create a ring shape + CombineRgn(outerRgn, outerRgn, innerRgn, RGN_DIFF); + if (isPressed) + { + // Set the brush color for the outer ring + HBRUSH outerBrush = CreateSolidBrush(RGB(100, 0, 0)); + SelectObject(hdc, outerBrush); + + // Fill the outer ring + FillRgn(hdc, outerRgn, outerBrush); + + // Set the brush color for the inner circle + HBRUSH innerBrush = CreateSolidBrush(RGB(255, 0, 0)); + SelectObject(hdc, innerBrush); + + // Fill the inner circle + Ellipse(hdc, innerRect.left, innerRect.top, innerRect.right, innerRect.bottom); + FillRgn(hdc, innerRgn, innerBrush); + // Clean up the brushes and regions + DeleteObject(outerBrush); + DeleteObject(innerBrush); + } + else + { + // Set the brush color for the outer ring + HBRUSH outerBrush = CreateSolidBrush(RGB(100,0,0)); + SelectObject(hdc, outerBrush); + + // Fill the outer ring + FillRgn(hdc, outerRgn, outerBrush); + + // Set the brush color for the inner circle + HBRUSH innerBrush = CreateSolidBrush(RGB(255, 0, 0)); + SelectObject(hdc, innerBrush); + + // Fill the inner circle + Ellipse(hdc, innerRect.left, innerRect.top, innerRect.right, innerRect.bottom); + FillRgn(hdc, innerRgn, innerBrush); + // Clean up the brushes and regions + DeleteObject(outerBrush); + DeleteObject(innerBrush); + } + DeleteObject(outerRgn); + DeleteObject(innerRgn); + + EndPaint(hWnd, &ps); + break; + + + } + case WM_DESTROY: + { + // Clean up resources + DeleteObject(hBrush); + break; + } + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + + return 0; + } +} + +Window::Window() : m_hinstance(GetModuleHandle(nullptr)) +{ + + const wchar_t* CLASS_NAME = L"Snawy's Window Class"; + + WNDCLASS wndClass = {}; + wndClass.lpszClassName = CLASS_NAME; + wndClass.hInstance = m_hinstance; + wndClass.hIcon = LoadIcon(NULL, IDI_WINLOGO); + wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndClass.lpfnWndProc = BallWindowProc; + wndClass.hbrBackground = CreateSolidBrush(RGB(0,0,0)); + RegisterClass(&wndClass); + + DWORD style = WS_POPUP | WS_CLIPCHILDREN; + + + m_hWnd = CreateWindowEx( + 0, + CLASS_NAME, + L"Ball", + style, + CW_USEDEFAULT, + CW_USEDEFAULT, + width, + height, + NULL, + NULL, + m_hinstance, + NULL + ); + + ShowWindow(m_hWnd, SW_SHOW); + +} + +Window::~Window() +{ + const wchar_t* CLASS_NAME = L"Snawy's Window Class"; + + UnregisterClass(CLASS_NAME, m_hinstance); +} + +bool Window::ProcessMessages() +{ + MSG msg = {}; + + while (PeekMessage(&msg, nullptr, 0u, 0u, PM_REMOVE)) + { + if (msg.message == WM_QUIT) + { + return false; + } + + TranslateMessage(&msg); + DispatchMessage(&msg); + + } + return true; +} \ No newline at end of file diff --git a/8BitBounce/Ball.h b/8BitBounce/Ball.h new file mode 100644 index 0000000..a7052f2 --- /dev/null +++ b/8BitBounce/Ball.h @@ -0,0 +1,18 @@ +#pragma once +#include + + +class Window +{ +public: + Window(); + Window(const Window&) = delete; + Window& operator=(const Window&) = delete; + ~Window(); + + bool ProcessMessages(); + +private: + HINSTANCE m_hinstance; + HWND m_hWnd; +}; \ No newline at end of file