diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2019-10-10 23:53:18 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2019-10-10 23:53:18 +0200 |
commit | 339c4f9b53192e65588d8bf8c5c35967f9f75d61 (patch) | |
tree | cbe627c43af68f7fe7d5f6d8e68da03b88a347ba | |
parent | 8dd95f94afcec6e5ee94cbd80170b1231a3e7ddf (diff) |
initial commit
-rw-r--r-- | GdiRadar.sln | 6 | ||||
-rw-r--r-- | GdiRadar/GdiRadar.cpp | 163 | ||||
-rw-r--r-- | GdiRadar/GdiRadar.vcxproj | 4 |
3 files changed, 153 insertions, 20 deletions
diff --git a/GdiRadar.sln b/GdiRadar.sln index e823c41..398fc16 100644 --- a/GdiRadar.sln +++ b/GdiRadar.sln @@ -8,19 +8,13 @@ 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 {C9774084-968A-4F0A-96F7-B5F4E7B254A4}.Debug|x64.ActiveCfg = Debug|x64 {C9774084-968A-4F0A-96F7-B5F4E7B254A4}.Debug|x64.Build.0 = Debug|x64 - {C9774084-968A-4F0A-96F7-B5F4E7B254A4}.Debug|x86.ActiveCfg = Debug|Win32 - {C9774084-968A-4F0A-96F7-B5F4E7B254A4}.Debug|x86.Build.0 = Debug|Win32 {C9774084-968A-4F0A-96F7-B5F4E7B254A4}.Release|x64.ActiveCfg = Release|x64 {C9774084-968A-4F0A-96F7-B5F4E7B254A4}.Release|x64.Build.0 = Release|x64 - {C9774084-968A-4F0A-96F7-B5F4E7B254A4}.Release|x86.ActiveCfg = Release|Win32 - {C9774084-968A-4F0A-96F7-B5F4E7B254A4}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GdiRadar/GdiRadar.cpp b/GdiRadar/GdiRadar.cpp index a15c58d..f6639e3 100644 --- a/GdiRadar/GdiRadar.cpp +++ b/GdiRadar/GdiRadar.cpp @@ -1,21 +1,156 @@ -// GdiRadar.cpp : This file contains the 'main' function. Program execution begins and ends there. -// - #include "pch.h" #include <iostream> +#include <vector> -int main() +#include <Windows.h> +#include <time.h> + +#pragma comment(lib, "Gdi32.lib") + +#define SCALE_X(posx) ((int)((float)GameMapWidth * (1000.0f / posx))) +#define SCALE_Y(posy) ((int)((float)GameMapHeight * (1000.0f / posy))) + +static HWND myDrawWnd = NULL; +static HINSTANCE hInstance = NULL; +static WNDCLASS wc = { 0 }; +static float GameMapWidth = 0; +static float GameMapHeight = 0; + +enum entity_color { + EC_RED +}; + +struct entity { + float pos[2]; + float health; + enum entity_color color; + const char *name; +}; +std::vector<struct entity> entities; + + +static void draw_entity(HDC hdc, float posx, float posy, float health, enum entity_color color, const char *name) { - std::cout << "Hello World!\n"; +#if 0 + RECT healthRect = { posx - 10, posy - 10, posx + 10, posy - 5 }; + FillRect(hdc, &rect, color); + + RECT textRect = { posx, posy, posx + 10, posy - 5 }; + DrawText(hdc, TEXT("Michael Morrison"), -1, &rect, + DT_SINGLELINE | DT_CENTER | DT_VCENTER); +#endif + + switch (color) { + case EC_RED: + SetDCBrushColor(hdc, RGB(255, 0, 0)); + break; + } + std::cout << GameMapWidth << ", " << SCALE_X(posx) << std::endl; + Ellipse(hdc, SCALE_X(posx), SCALE_Y(posy), SCALE_X(posx + 5), SCALE_Y(posy + 5)); } -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu +LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) +{ + static HBRUSH EnemyBrush = NULL; + static HBRUSH BackgroundBrush = NULL; + static COLORREF TextCOLOR = NULL; + static HFONT HFONT_Hunt = NULL; + static RECT DC_Dimensions = {}; + static HDC hdc = NULL; + + switch (message) + { + case WM_CREATE: + std::cout << "WM_CREATE\n"; + hdc = GetDC(hwnd); + EnemyBrush = CreateSolidBrush(RGB(255, 0, 0)); + BackgroundBrush = CreateSolidBrush(RGB(0, 0, 0)); + TextCOLOR = RGB(0, 255, 0); + SetBkMode(hdc, TRANSPARENT); + return 0; + case WM_PAINT: + { + std::cout << "WM_PAINT\n"; + PAINTSTRUCT ps; -// 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 + BeginPaint(hwnd, &ps); + for (auto& entity : entities) { + draw_entity(hdc, entity.pos[0], entity.pos[1], entity.health, entity.color, entity.name); + } + EndPaint(hwnd, &ps); + return 0; + } + break; + case WM_LBUTTONDOWN: + std::cout << "WM_LBUTTONDOWN\n"; + return 0; + case WM_NCLBUTTONDOWN: + std::cout << "WM_NCLBUTTONDOWN\n"; + break; + case WM_CHAR: + std::cout << "WM_CHAR\n"; + return 0; + case WM_MOVE: + std::cout << "WM_MOVE\n"; + return 0; + case WM_SIZE: + std::cout << "WM_SIZE\n"; + GetClientRect(hwnd, &DC_Dimensions); + FillRect(hdc, &DC_Dimensions, BackgroundBrush); + return 0; + case WM_DESTROY: + std::cout << "WM_DESTROY\n"; + PostQuitMessage(0); + return 0; + } + return DefWindowProc(hwnd, message, wparam, lparam); +} + +int main() +{ + static double last_time_called = 0.0; + double current_time; + + std::cout << "Init\n"; + + GameMapWidth = 1000.0f; + GameMapHeight = 1000.0f; + + hInstance = (HINSTANCE)GetWindowLongW(GetActiveWindow(), -6); + wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + wc.hCursor = LoadCursor(hInstance, IDC_ARROW); + wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION); + wc.hInstance = hInstance; + wc.lpfnWndProc = WndProc; + wc.lpszClassName = L"peter"; + wc.style = CS_HREDRAW | CS_VREDRAW; + + UnregisterClassW(L"peter", hInstance); + if (!RegisterClass(&wc)) + { + return 1; + } + + myDrawWnd = CreateWindowW(L"peter", + L"the window", + WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_MAXIMIZEBOX | WS_SIZEBOX, + 50, 50, 640, 480, + NULL, NULL, hInstance, NULL); + ShowWindow(myDrawWnd, SW_SHOWNORMAL); + UpdateWindow(myDrawWnd); + + last_time_called = clock(); + + entities.push_back(entity{ 0.0f, 0.0f, 100.0f, EC_RED, "test" }); + entities.push_back(entity{ 1000.0f, 1000.0f, 50.0f, EC_RED, "m0wL" }); + entities.push_back(entity{ 500.0f, 500.0f, 80.0f, EC_RED, "whiteshirt" }); + + MSG msg; + while (GetMessageA(&msg, myDrawWnd, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return 0; +} diff --git a/GdiRadar/GdiRadar.vcxproj b/GdiRadar/GdiRadar.vcxproj index e4d6055..e389f18 100644 --- a/GdiRadar/GdiRadar.vcxproj +++ b/GdiRadar/GdiRadar.vcxproj @@ -44,6 +44,7 @@ <UseDebugLibraries>true</UseDebugLibraries> <PlatformToolset>v141</PlatformToolset> <CharacterSet>Unicode</CharacterSet> + <SpectreMitigation>false</SpectreMitigation> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> @@ -51,6 +52,7 @@ <PlatformToolset>v141</PlatformToolset> <WholeProgramOptimization>true</WholeProgramOptimization> <CharacterSet>Unicode</CharacterSet> + <SpectreMitigation>false</SpectreMitigation> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <ImportGroup Label="ExtensionSettings"> @@ -106,6 +108,7 @@ <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -148,6 +151,7 @@ <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalLibraryDirectories>$(VCToolsInstallDir)lib\x64;$(OutputPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemGroup> |