игра жизнь начало
This commit is contained in:
parent
a7e778640f
commit
92e2fbf7e9
28
Game of Life/Game of Life.sln
Normal file
28
Game of Life/Game of Life.sln
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.12.35527.113 d17.12
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Game of Life", "Game of Life\Game of Life.vcxproj", "{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}"
|
||||
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
|
||||
{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}.Debug|x64.Build.0 = Debug|x64
|
||||
{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}.Release|x64.ActiveCfg = Release|x64
|
||||
{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}.Release|x64.Build.0 = Release|x64
|
||||
{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{743E4B45-9B39-4BC5-939A-C9CF6C0B295B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
144
Game of Life/Game of Life/Game of Life.vcxproj
Normal file
144
Game of Life/Game of Life/Game of Life.vcxproj
Normal file
@ -0,0 +1,144 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{743e4b45-9b39-4bc5-939a-c9cf6c0b295b}</ProjectGuid>
|
||||
<RootNamespace>GameofLife</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)\lib</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>raylib.lib;winmm.lib;opengl32.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)\lib</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>raylib.lib;winmm.lib;opengl32.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\raylib.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\main.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
27
Game of Life/Game of Life/Game of Life.vcxproj.filters
Normal file
27
Game of Life/Game of Life/Game of Life.vcxproj.filters
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Исходные файлы">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы заголовков">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы ресурсов">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\raylib.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\main.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
1708
Game of Life/include/raylib.h
Normal file
1708
Game of Life/include/raylib.h
Normal file
File diff suppressed because it is too large
Load Diff
2941
Game of Life/include/raymath.h
Normal file
2941
Game of Life/include/raymath.h
Normal file
File diff suppressed because it is too large
Load Diff
5262
Game of Life/include/rlgl.h
Normal file
5262
Game of Life/include/rlgl.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Game of Life/lib/raylib.lib
Normal file
BIN
Game of Life/lib/raylib.lib
Normal file
Binary file not shown.
BIN
Game of Life/resources/Inconsolata-LGC-Bold.ttf
Normal file
BIN
Game of Life/resources/Inconsolata-LGC-Bold.ttf
Normal file
Binary file not shown.
BIN
Game of Life/resources/Inconsolata-LGC.ttf
Normal file
BIN
Game of Life/resources/Inconsolata-LGC.ttf
Normal file
Binary file not shown.
35
Game of Life/src/main.c
Normal file
35
Game of Life/src/main.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include "raylib.h"
|
||||
#include <stdbool.h>
|
||||
#include <iso646.h>
|
||||
|
||||
|
||||
#define MAP_X 20
|
||||
#define MAP_Y 20
|
||||
|
||||
static bool map[MAP_X][MAP_Y] = { 0 };
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
@ -55,7 +55,7 @@ int map[M][N] = {
|
||||
int player_x = 1;
|
||||
int player_y = 1;
|
||||
|
||||
typedef enum { empty = 0, wall = 2, gold = 3 } obj_enum;
|
||||
typedef enum obj_enum { empty = 0, wall = 2, gold = 3 } obj_enum;
|
||||
// TODO: do something with "empty" object
|
||||
#define INVENTORY_SIZE 4
|
||||
int inventory[INVENTORY_SIZE] = { 0, 0, 15, 0 };
|
||||
@ -65,16 +65,52 @@ typedef enum { left, right, up, down } enum_ways;
|
||||
void movePlayer(enum_ways move) {
|
||||
switch (move) {
|
||||
case left:
|
||||
if ((player_x > 0) and map[player_y][player_x - 1] != wall) player_x -= 1;
|
||||
if (player_x > 0) {
|
||||
if (map[player_y][player_x - 1] != wall) {
|
||||
player_x -= 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (map[player_y][N - 1] != wall) {
|
||||
player_x = N - 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case right:
|
||||
if ((player_x < N - 1) and map[player_y][player_x + 1] != wall) player_x += 1;
|
||||
if (player_x < N - 1) {
|
||||
if (map[player_y][player_x + 1] != wall) {
|
||||
player_x += 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (map[player_y][0] != wall) {
|
||||
player_x = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case up:
|
||||
if ((player_y > 0) and map[player_y - 1][player_x] != wall) player_y -= 1;
|
||||
if (player_y > 0) {
|
||||
if (map[player_y - 1][player_x] != wall) {
|
||||
player_y -= 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (map[M - 1][player_x] != wall) {
|
||||
player_y = M - 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case down:
|
||||
if ((player_y < M - 1) and map[player_y + 1][player_x] != wall) player_y += 1;
|
||||
if (player_y < M - 1) {
|
||||
if (map[player_y + 1][player_x] != wall) {
|
||||
player_y += 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (map[0][player_x] != wall) {
|
||||
player_y = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (map[player_y][player_x] == gold) {
|
||||
@ -465,7 +501,7 @@ void callNKErrorBoxes(struct nk_context* ctx) {
|
||||
int main()
|
||||
{
|
||||
//SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
||||
//SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
InitWindow(N * WIDTH, M * HEIGHT + VOFFSET, "lab16 with raylib");
|
||||
|
||||
@ -481,8 +517,8 @@ int main()
|
||||
//Font InconsolataSemiBold = LoadFontEx("Inconsolata-SemiBold.ttf", 48, codepoints, 512);
|
||||
Font InconsolataBold = LoadFontEx("Inconsolata-LGC-Bold.ttf", 36, codepoints, CPSIZE);
|
||||
SetTextureFilter(InconsolataBold.texture, TEXTURE_FILTER_BILINEAR);
|
||||
Font Consolas = LoadFontEx("consola.ttf", 24, codepoints, CPSIZE);
|
||||
SetTextureFilter(Consolas.texture, TEXTURE_FILTER_BILINEAR);
|
||||
//Font Consolas = LoadFontEx("consola.ttf", 24, codepoints, CPSIZE);
|
||||
//SetTextureFilter(Consolas.texture, TEXTURE_FILTER_BILINEAR);
|
||||
//Font Arial = LoadFontEx("arial.ttf", 36, codepoints, CPSIZE);
|
||||
//SetTextureFilter(Arial.texture, TEXTURE_FILTER_BILINEAR);
|
||||
|
||||
@ -505,6 +541,9 @@ int main()
|
||||
//------------------------------------------------------------------
|
||||
// Update game logic
|
||||
//------------------------------------------------------------------
|
||||
|
||||
printf("lol");
|
||||
|
||||
if (errorCode == OK)
|
||||
{
|
||||
handleKeys();
|
||||
@ -543,7 +582,7 @@ int main()
|
||||
|
||||
drawMap();
|
||||
drawPlayer();
|
||||
drawBottomBar(Consolas, 24);
|
||||
drawBottomBar(InconsolataBold, 24);
|
||||
|
||||
if (editMap) {
|
||||
Rectangle rec = {
|
||||
@ -571,10 +610,14 @@ int main()
|
||||
// Render the Nuklear GUI
|
||||
//DrawNuklear(ctx);
|
||||
|
||||
//drawRayguiErrorBoxes();
|
||||
drawRayguiErrorBoxes();
|
||||
}
|
||||
|
||||
DrawTextEx(Consolas, u8"Файл не найден\nПопробуйте сначала сохранить игру", (Vector2) { 100, 100 }, 24, 0, BLACK);
|
||||
Rectangle roundRect = { 100, 250, 185, 36 };
|
||||
DrawRectangleRounded(roundRect, 0.5f, 6, BLACK);
|
||||
DrawRectangleRoundedLines(roundRect, 0.5f, 6, ORANGE);
|
||||
|
||||
//DrawTextEx(Consolas, u8"Файл не найден\nПопробуйте сначала сохранить игру", (Vector2) { 100, 100 }, 24, 0, BLACK);
|
||||
|
||||
// show mouse position
|
||||
//DrawText(TextFormat("%.1f %.1f", mousePos.x, mousePos.y), 5, M * HEIGHT - 30, 30, ORANGE);
|
||||
@ -589,6 +632,7 @@ int main()
|
||||
|
||||
//UnloadFont(InconsolataRegular);
|
||||
UnloadFont(InconsolataBold);
|
||||
//UnloadFont(Consolas);
|
||||
//UnloadFont(Arial);
|
||||
//UnloadFont(InconsolataBold);
|
||||
|
||||
|
@ -1,388 +1,388 @@
|
||||
// lab18.cpp : Определяет точку входа для приложения.
|
||||
//
|
||||
|
||||
#include "framework.h"
|
||||
#include "lab18.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
|
||||
// Глобальные переменные:
|
||||
HINSTANCE hInst; // текущий экземпляр
|
||||
WCHAR szTitle[MAX_LOADSTRING]; // Текст строки заголовка
|
||||
WCHAR szWindowClass[MAX_LOADSTRING]; // имя класса главного окна
|
||||
|
||||
// Отправить объявления функций, включенных в этот модуль кода:
|
||||
ATOM MyRegisterClass(HINSTANCE hInstance);
|
||||
BOOL InitInstance(HINSTANCE, int);
|
||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
_In_opt_ HINSTANCE hPrevInstance,
|
||||
_In_ LPWSTR lpCmdLine,
|
||||
_In_ int nCmdShow)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
// TODO: Разместите код здесь.
|
||||
|
||||
// Инициализация глобальных строк
|
||||
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
||||
LoadStringW(hInstance, IDC_LAB18, szWindowClass, MAX_LOADSTRING);
|
||||
MyRegisterClass(hInstance);
|
||||
|
||||
// Выполнить инициализацию приложения:
|
||||
if (!InitInstance (hInstance, nCmdShow))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LAB18));
|
||||
|
||||
MSG msg;
|
||||
|
||||
// Цикл основного сообщения:
|
||||
while (GetMessage(&msg, nullptr, 0, 0))
|
||||
{
|
||||
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
return (int) msg.wParam;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// ФУНКЦИЯ: MyRegisterClass()
|
||||
//
|
||||
// ЦЕЛЬ: Регистрирует класс окна.
|
||||
//
|
||||
ATOM MyRegisterClass(HINSTANCE hInstance)
|
||||
{
|
||||
WNDCLASSEXW wcex;
|
||||
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LAB18));
|
||||
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_LAB18);
|
||||
wcex.lpszClassName = szWindowClass;
|
||||
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
|
||||
|
||||
return RegisterClassExW(&wcex);
|
||||
}
|
||||
|
||||
//
|
||||
// ФУНКЦИЯ: InitInstance(HINSTANCE, int)
|
||||
//
|
||||
// ЦЕЛЬ: Сохраняет маркер экземпляра и создает главное окно
|
||||
//
|
||||
// КОММЕНТАРИИ:
|
||||
//
|
||||
// В этой функции маркер экземпляра сохраняется в глобальной переменной, а также
|
||||
// создается и выводится главное окно программы.
|
||||
//
|
||||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
{
|
||||
hInst = hInstance; // Сохранить маркер экземпляра в глобальной переменной
|
||||
|
||||
HWND hWnd = CreateWindowExW(WS_EX_COMPOSITED, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
|
||||
|
||||
if (!hWnd)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool netToggle = true;
|
||||
|
||||
void drawNet(HDC hdc, int width, int height, int hstep, int vstep) {
|
||||
for (int i = 0; i <= width; i = i + hstep) {
|
||||
MoveToEx(hdc, i, 0, NULL);
|
||||
LineTo(hdc, i, height);
|
||||
}
|
||||
|
||||
for (int i = 0; i <= height; i = i + vstep) {
|
||||
MoveToEx(hdc, 0, i, NULL);
|
||||
LineTo(hdc, width, i);
|
||||
}
|
||||
}
|
||||
|
||||
void drawTriangle(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(78, 201, 176));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
POINT p[4] = {
|
||||
cx, cy - size,
|
||||
cx + size, cy + size,
|
||||
cx - size, cy + size,
|
||||
cx, cy - size
|
||||
};
|
||||
Polyline(hdc, p, 4);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawHourglass(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(78, 180, 200));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
POINT p[5] = {
|
||||
cx - size / 2, cy - size,
|
||||
cx + size / 2, cy - size,
|
||||
cx - size, cy + size,
|
||||
cx + size, cy + size,
|
||||
cx - size / 2, cy - size
|
||||
};
|
||||
Polyline(hdc, p, 5);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawRomb(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(78, 201, 176));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
POINT p[5] = {
|
||||
cx, cy - size,
|
||||
cx + size, cy,
|
||||
cx, cy + size,
|
||||
cx - size, cy,
|
||||
cx, cy - size,
|
||||
};
|
||||
Polyline(hdc, p, 5);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawStar(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(78, 180, 255));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
POINT p[9] = {
|
||||
cx, cy - size,
|
||||
cx + size / 4, cy - size / 4,
|
||||
cx + size, cy,
|
||||
cx + size / 4, cy + size / 4,
|
||||
cx, cy + size,
|
||||
cx - size / 4, cy + size / 4,
|
||||
cx - size, cy,
|
||||
cx - size / 4, cy - size / 4,
|
||||
cx, cy - size
|
||||
};
|
||||
Polyline(hdc, p, 9);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawCirle(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 255));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
Ellipse(hdc, cx - size, cy - size, cx + size, cy + size);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawRecursiveTriangle(HDC hdc, int cx, int cy, int size, int mode) {
|
||||
drawTriangle(hdc, cx, cy, size);
|
||||
|
||||
if (size < 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode > 0 && mode != 3) drawRecursiveTriangle(hdc, cx, cy - size, size / 2, mode);
|
||||
if (mode > 1 && mode != 4) drawRecursiveTriangle(hdc, cx + size, cy + size, size / 2, mode);
|
||||
if (mode > 2) drawRecursiveTriangle(hdc, cx - size, cy + size, size / 2, mode);
|
||||
}
|
||||
|
||||
void drawRecursiveHourglass(HDC hdc, int cx, int cy, int size, int mode) {
|
||||
drawHourglass(hdc, cx, cy, size);
|
||||
if (size < 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode >= 1 && mode < 4) drawRecursiveHourglass(hdc, cx - size / 2, cy - size, size / 2, mode);
|
||||
if (mode >= 2 && mode < 4) drawRecursiveHourglass(hdc, cx + size / 2, cy - size, size / 2, mode);
|
||||
if (mode >= 3 && mode < 5) {
|
||||
drawRecursiveHourglass(hdc, cx - size, cy + size, size / 2, mode);
|
||||
drawRecursiveHourglass(hdc, cx + size, cy + size, size / 2, mode);
|
||||
}
|
||||
if (mode == 5 || mode == 7) drawRecursiveHourglass(hdc, cx - size, cy, size / 2, mode);
|
||||
if (mode == 6 || mode == 7) drawRecursiveHourglass(hdc, cx + size, cy, size / 2, mode);
|
||||
|
||||
}
|
||||
|
||||
void drawRecursiveRomb(HDC hdc, int cx, int cy, int size, int mode) {
|
||||
drawRomb(hdc, cx, cy, size);
|
||||
if (size < 20) {
|
||||
return;
|
||||
}
|
||||
drawRecursiveRomb(hdc, cx - size, cy, size / 2, mode);
|
||||
drawRecursiveRomb(hdc, cx + size, cy, size / 2, mode);
|
||||
if (mode == 1 || mode == 3) drawRecursiveRomb(hdc, cx, cy + size, size / 2, mode);
|
||||
if (mode == 2 || mode == 3) drawRecursiveRomb(hdc, cx, cy - size, size / 2, mode);
|
||||
}
|
||||
|
||||
void drawRecursiveStar(HDC hdc, int cx, int cy, int size, int mode) {
|
||||
drawStar(hdc, cx, cy, size);
|
||||
if (size < 20) {
|
||||
return;
|
||||
}
|
||||
if (mode == 0 || mode == 2) drawRecursiveStar(hdc, cx - size, cy, size / 2, mode);
|
||||
if (mode == 0) drawRecursiveStar(hdc, cx + size, cy, size / 2, mode);
|
||||
if (mode == 1 || mode == 2) drawRecursiveStar(hdc, cx, cy + size, size / 2, mode);
|
||||
if (mode == 1 || mode == 2) drawRecursiveStar(hdc, cx, cy - size, size / 2, mode);
|
||||
}
|
||||
|
||||
int circlecount = 0;
|
||||
void drawRecursiveCircle(HDC hdc, int cx, int cy, int size, int i) {
|
||||
drawCirle(hdc, cx, cy, size);
|
||||
i--;
|
||||
circlecount++;
|
||||
|
||||
static HFONT hFont = CreateFontW(18, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
|
||||
OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, TEXT("Consolas"));
|
||||
|
||||
SelectObject(hdc, hFont);
|
||||
SetTextColor(hdc, RGB(0, 0, 0));
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
|
||||
static char circle_string[10];
|
||||
sprintf_s(circle_string, "%d", circlecount);
|
||||
RECT circlerect = { cx - size, cy - size, cx + size, cy + size };
|
||||
|
||||
DrawTextA(hdc, circle_string, -1, &circlerect, (DT_SINGLELINE | DT_VCENTER | DT_CENTER));
|
||||
|
||||
if (i == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawRecursiveCircle(hdc, cx, cy - size, size / 2, i);
|
||||
drawRecursiveCircle(hdc, cx + size, cy, size / 2, i);
|
||||
}
|
||||
|
||||
int trmode = 0;
|
||||
int hgmode = 0;
|
||||
int rbmode = 0;
|
||||
int imageVar = 0;
|
||||
|
||||
//
|
||||
// ФУНКЦИЯ: WndProc(HWND, UINT, WPARAM, LPARAM)
|
||||
//
|
||||
// ЦЕЛЬ: Обрабатывает сообщения в главном окне.
|
||||
//
|
||||
// WM_COMMAND - обработать меню приложения
|
||||
// WM_PAINT - Отрисовка главного окна
|
||||
// WM_DESTROY - отправить сообщение о выходе и вернуться
|
||||
//
|
||||
//
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int wmId = LOWORD(wParam);
|
||||
// Разобрать выбор в меню:
|
||||
switch (wmId)
|
||||
{
|
||||
case IDM_ABOUT:
|
||||
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
|
||||
break;
|
||||
case IDM_EXIT:
|
||||
DestroyWindow(hWnd);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hWnd, &ps);
|
||||
// TODO: Добавьте сюда любой код прорисовки, использующий HDC...
|
||||
|
||||
RECT rect;
|
||||
GetClientRect(hWnd, &rect);
|
||||
|
||||
if (netToggle) drawNet(hdc, rect.right, rect.bottom, 50, 50);
|
||||
|
||||
drawRecursiveTriangle(hdc, 300, 300, 100, trmode);
|
||||
drawRecursiveHourglass(hdc, 700, 300, 100, hgmode);
|
||||
|
||||
drawRecursiveRomb(hdc, 300, 700, 100, rbmode);
|
||||
drawRecursiveStar(hdc, 1100, 300, 100, rbmode);
|
||||
|
||||
drawRecursiveCircle(hdc, 1300, 700, 200, 5);
|
||||
circlecount = 0;
|
||||
|
||||
EndPaint(hWnd, &ps);
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
{
|
||||
switch (wParam)
|
||||
{
|
||||
case VK_SPACE:
|
||||
netToggle = !netToggle;
|
||||
break;
|
||||
default:
|
||||
trmode++;
|
||||
hgmode++;
|
||||
rbmode++;
|
||||
if (trmode > 5) trmode = 0;
|
||||
if (hgmode > 7) hgmode = 0;
|
||||
if (rbmode > 3) rbmode = 0;
|
||||
break;
|
||||
}
|
||||
InvalidateRect(hWnd, NULL, TRUE);
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Обработчик сообщений для окна "О программе".
|
||||
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(lParam);
|
||||
switch (message)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
return (INT_PTR)TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
||||
{
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (INT_PTR)FALSE;
|
||||
}
|
||||
// lab18.cpp : Определяет точку входа для приложения.
|
||||
//
|
||||
|
||||
#include "framework.h"
|
||||
#include "lab18.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
|
||||
// Глобальные переменные:
|
||||
HINSTANCE hInst; // текущий экземпляр
|
||||
WCHAR szTitle[MAX_LOADSTRING]; // Текст строки заголовка
|
||||
WCHAR szWindowClass[MAX_LOADSTRING]; // имя класса главного окна
|
||||
|
||||
// Отправить объявления функций, включенных в этот модуль кода:
|
||||
ATOM MyRegisterClass(HINSTANCE hInstance);
|
||||
BOOL InitInstance(HINSTANCE, int);
|
||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
_In_opt_ HINSTANCE hPrevInstance,
|
||||
_In_ LPWSTR lpCmdLine,
|
||||
_In_ int nCmdShow)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
// TODO: Разместите код здесь.
|
||||
|
||||
// Инициализация глобальных строк
|
||||
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
||||
LoadStringW(hInstance, IDC_LAB18, szWindowClass, MAX_LOADSTRING);
|
||||
MyRegisterClass(hInstance);
|
||||
|
||||
// Выполнить инициализацию приложения:
|
||||
if (!InitInstance (hInstance, nCmdShow))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LAB18));
|
||||
|
||||
MSG msg;
|
||||
|
||||
// Цикл основного сообщения:
|
||||
while (GetMessage(&msg, nullptr, 0, 0))
|
||||
{
|
||||
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
return (int) msg.wParam;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// ФУНКЦИЯ: MyRegisterClass()
|
||||
//
|
||||
// ЦЕЛЬ: Регистрирует класс окна.
|
||||
//
|
||||
ATOM MyRegisterClass(HINSTANCE hInstance)
|
||||
{
|
||||
WNDCLASSEXW wcex;
|
||||
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LAB18));
|
||||
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_LAB18);
|
||||
wcex.lpszClassName = szWindowClass;
|
||||
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
|
||||
|
||||
return RegisterClassExW(&wcex);
|
||||
}
|
||||
|
||||
//
|
||||
// ФУНКЦИЯ: InitInstance(HINSTANCE, int)
|
||||
//
|
||||
// ЦЕЛЬ: Сохраняет маркер экземпляра и создает главное окно
|
||||
//
|
||||
// КОММЕНТАРИИ:
|
||||
//
|
||||
// В этой функции маркер экземпляра сохраняется в глобальной переменной, а также
|
||||
// создается и выводится главное окно программы.
|
||||
//
|
||||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
{
|
||||
hInst = hInstance; // Сохранить маркер экземпляра в глобальной переменной
|
||||
|
||||
HWND hWnd = CreateWindowExW(WS_EX_COMPOSITED, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
|
||||
|
||||
if (!hWnd)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool netToggle = true;
|
||||
|
||||
void drawNet(HDC hdc, int width, int height, int hstep, int vstep) {
|
||||
for (int i = 0; i <= width; i = i + hstep) {
|
||||
MoveToEx(hdc, i, 0, NULL);
|
||||
LineTo(hdc, i, height);
|
||||
}
|
||||
|
||||
for (int i = 0; i <= height; i = i + vstep) {
|
||||
MoveToEx(hdc, 0, i, NULL);
|
||||
LineTo(hdc, width, i);
|
||||
}
|
||||
}
|
||||
|
||||
void drawTriangle(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(78, 201, 176));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
POINT p[4] = {
|
||||
cx, cy - size,
|
||||
cx + size, cy + size,
|
||||
cx - size, cy + size,
|
||||
cx, cy - size
|
||||
};
|
||||
Polyline(hdc, p, 4);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawHourglass(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(78, 180, 200));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
POINT p[5] = {
|
||||
cx - size / 2, cy - size,
|
||||
cx + size / 2, cy - size,
|
||||
cx - size, cy + size,
|
||||
cx + size, cy + size,
|
||||
cx - size / 2, cy - size
|
||||
};
|
||||
Polyline(hdc, p, 5);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawRomb(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(78, 201, 176));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
POINT p[5] = {
|
||||
cx, cy - size,
|
||||
cx + size, cy,
|
||||
cx, cy + size,
|
||||
cx - size, cy,
|
||||
cx, cy - size,
|
||||
};
|
||||
Polyline(hdc, p, 5);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawStar(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(78, 180, 255));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
POINT p[9] = {
|
||||
cx, cy - size,
|
||||
cx + size / 4, cy - size / 4,
|
||||
cx + size, cy,
|
||||
cx + size / 4, cy + size / 4,
|
||||
cx, cy + size,
|
||||
cx - size / 4, cy + size / 4,
|
||||
cx - size, cy,
|
||||
cx - size / 4, cy - size / 4,
|
||||
cx, cy - size
|
||||
};
|
||||
Polyline(hdc, p, 9);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawCirle(HDC hdc, int cx, int cy, int size) {
|
||||
HPEN hPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 255));
|
||||
SelectObject(hdc, hPen);
|
||||
|
||||
Ellipse(hdc, cx - size, cy - size, cx + size, cy + size);
|
||||
|
||||
DeleteObject(hPen);
|
||||
}
|
||||
|
||||
void drawRecursiveTriangle(HDC hdc, int cx, int cy, int size, int mode) {
|
||||
drawTriangle(hdc, cx, cy, size);
|
||||
|
||||
if (size < 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode > 0 && mode != 3) drawRecursiveTriangle(hdc, cx, cy - size, size / 2, mode);
|
||||
if (mode > 1 && mode != 4) drawRecursiveTriangle(hdc, cx + size, cy + size, size / 2, mode);
|
||||
if (mode > 2) drawRecursiveTriangle(hdc, cx - size, cy + size, size / 2, mode);
|
||||
}
|
||||
|
||||
void drawRecursiveHourglass(HDC hdc, int cx, int cy, int size, int mode) {
|
||||
drawHourglass(hdc, cx, cy, size);
|
||||
if (size < 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode >= 1 && mode < 4) drawRecursiveHourglass(hdc, cx - size / 2, cy - size, size / 2, mode);
|
||||
if (mode >= 2 && mode < 4) drawRecursiveHourglass(hdc, cx + size / 2, cy - size, size / 2, mode);
|
||||
if (mode >= 3 && mode < 5) {
|
||||
drawRecursiveHourglass(hdc, cx - size, cy + size, size / 2, mode);
|
||||
drawRecursiveHourglass(hdc, cx + size, cy + size, size / 2, mode);
|
||||
}
|
||||
if (mode == 5 || mode == 7) drawRecursiveHourglass(hdc, cx - size, cy, size / 2, mode);
|
||||
if (mode == 6 || mode == 7) drawRecursiveHourglass(hdc, cx + size, cy, size / 2, mode);
|
||||
|
||||
}
|
||||
|
||||
void drawRecursiveRomb(HDC hdc, int cx, int cy, int size, int mode) {
|
||||
drawRomb(hdc, cx, cy, size);
|
||||
if (size < 20) {
|
||||
return;
|
||||
}
|
||||
drawRecursiveRomb(hdc, cx - size, cy, size / 2, mode);
|
||||
drawRecursiveRomb(hdc, cx + size, cy, size / 2, mode);
|
||||
if (mode == 1 || mode == 3) drawRecursiveRomb(hdc, cx, cy + size, size / 2, mode);
|
||||
if (mode == 2 || mode == 3) drawRecursiveRomb(hdc, cx, cy - size, size / 2, mode);
|
||||
}
|
||||
|
||||
void drawRecursiveStar(HDC hdc, int cx, int cy, int size, int mode) {
|
||||
drawStar(hdc, cx, cy, size);
|
||||
if (size < 20) {
|
||||
return;
|
||||
}
|
||||
if (mode == 0 || mode == 2) drawRecursiveStar(hdc, cx - size, cy, size / 2, mode);
|
||||
if (mode == 0) drawRecursiveStar(hdc, cx + size, cy, size / 2, mode);
|
||||
if (mode == 1 || mode == 2) drawRecursiveStar(hdc, cx, cy + size, size / 2, mode);
|
||||
if (mode == 1 || mode == 2) drawRecursiveStar(hdc, cx, cy - size, size / 2, mode);
|
||||
}
|
||||
|
||||
int circlecount = 0;
|
||||
void drawRecursiveCircle(HDC hdc, int cx, int cy, int size, int i) {
|
||||
drawCirle(hdc, cx, cy, size);
|
||||
i--;
|
||||
circlecount++;
|
||||
|
||||
static HFONT hFont = CreateFontW(18, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
|
||||
OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, TEXT("Consolas"));
|
||||
|
||||
SelectObject(hdc, hFont);
|
||||
SetTextColor(hdc, RGB(0, 0, 0));
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
|
||||
static char circle_string[10];
|
||||
sprintf_s(circle_string, "%d", circlecount);
|
||||
RECT circlerect = { cx - size, cy - size, cx + size, cy + size };
|
||||
|
||||
DrawTextA(hdc, circle_string, -1, &circlerect, (DT_SINGLELINE | DT_VCENTER | DT_CENTER));
|
||||
|
||||
if (i == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawRecursiveCircle(hdc, cx, cy - size, size / 2, i);
|
||||
drawRecursiveCircle(hdc, cx + size, cy, size / 2, i);
|
||||
}
|
||||
|
||||
int trmode = 0;
|
||||
int hgmode = 0;
|
||||
int rbmode = 0;
|
||||
int imageVar = 0;
|
||||
|
||||
//
|
||||
// ФУНКЦИЯ: WndProc(HWND, UINT, WPARAM, LPARAM)
|
||||
//
|
||||
// ЦЕЛЬ: Обрабатывает сообщения в главном окне.
|
||||
//
|
||||
// WM_COMMAND - обработать меню приложения
|
||||
// WM_PAINT - Отрисовка главного окна
|
||||
// WM_DESTROY - отправить сообщение о выходе и вернуться
|
||||
//
|
||||
//
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int wmId = LOWORD(wParam);
|
||||
// Разобрать выбор в меню:
|
||||
switch (wmId)
|
||||
{
|
||||
case IDM_ABOUT:
|
||||
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
|
||||
break;
|
||||
case IDM_EXIT:
|
||||
DestroyWindow(hWnd);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hWnd, &ps);
|
||||
// TODO: Добавьте сюда любой код прорисовки, использующий HDC...
|
||||
|
||||
RECT rect;
|
||||
GetClientRect(hWnd, &rect);
|
||||
|
||||
if (netToggle) drawNet(hdc, rect.right, rect.bottom, 50, 50);
|
||||
|
||||
drawRecursiveTriangle(hdc, 300, 300, 100, trmode);
|
||||
drawRecursiveHourglass(hdc, 700, 300, 100, hgmode);
|
||||
|
||||
drawRecursiveRomb(hdc, 300, 700, 100, rbmode);
|
||||
drawRecursiveStar(hdc, 1100, 300, 100, rbmode);
|
||||
|
||||
drawRecursiveCircle(hdc, 1300, 700, 200, 5);
|
||||
circlecount = 0;
|
||||
|
||||
EndPaint(hWnd, &ps);
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
{
|
||||
switch (wParam)
|
||||
{
|
||||
case VK_SPACE:
|
||||
netToggle = !netToggle;
|
||||
break;
|
||||
default:
|
||||
trmode++;
|
||||
hgmode++;
|
||||
rbmode++;
|
||||
if (trmode > 5) trmode = 0;
|
||||
if (hgmode > 7) hgmode = 0;
|
||||
if (rbmode > 3) rbmode = 0;
|
||||
break;
|
||||
}
|
||||
InvalidateRect(hWnd, NULL, TRUE);
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Обработчик сообщений для окна "О программе".
|
||||
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(lParam);
|
||||
switch (message)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
return (INT_PTR)TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
||||
{
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (INT_PTR)FALSE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user