Second painter and bugfixes
This commit is contained in:
parent
fb4cf5bd80
commit
6cc15c1989
@ -59,7 +59,7 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInst, LPSTR lpszArgs,
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Настройка частей StatusBar'а
|
// Настройка частей StatusBar'а
|
||||||
int statwidths[] = {150, 300, -1};
|
int statwidths[] = {150, 300, 450, -1};
|
||||||
SendMessageA(hWndStatusBar, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM) statwidths);
|
SendMessageA(hWndStatusBar, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM) statwidths);
|
||||||
|
|
||||||
ShowWindow(hWnd, nWinMode); // Показать окно
|
ShowWindow(hWnd, nWinMode); // Показать окно
|
||||||
@ -174,6 +174,8 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
|
|||||||
case WM_MOUSEMOVE: {
|
case WM_MOUSEMOVE: {
|
||||||
char str[256];
|
char str[256];
|
||||||
|
|
||||||
|
SendMessageA(hWndStatusBar, SB_SETTEXTA, 3, (LPARAM) "F4: Сменить рисунок");
|
||||||
|
|
||||||
// Устанавливаем текст в разных частях StatusBar'а
|
// Устанавливаем текст в разных частях StatusBar'а
|
||||||
// Экранные координаты курсора мыши
|
// Экранные координаты курсора мыши
|
||||||
sprintf_s(str, "X = %d, Y = %d", LOWORD(lParam), HIWORD(lParam));
|
sprintf_s(str, "X = %d, Y = %d", LOWORD(lParam), HIWORD(lParam));
|
||||||
@ -210,7 +212,7 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
|
|||||||
if (wParam == VK_F4) {
|
if (wParam == VK_F4) {
|
||||||
auto newPtr = reinterpret_cast<Painter const *const *>(GetWindowLongPtr(hWnd, sizeof(PainterState *)));
|
auto newPtr = reinterpret_cast<Painter const *const *>(GetWindowLongPtr(hWnd, sizeof(PainterState *)));
|
||||||
newPtr++;
|
newPtr++;
|
||||||
if (newPtr == nullptr)
|
if (*newPtr == nullptr)
|
||||||
newPtr = &predefined_painters[0];
|
newPtr = &predefined_painters[0];
|
||||||
|
|
||||||
SetWindowLongPtr(hWnd, sizeof(PainterState *), (LONG_PTR) newPtr);
|
SetWindowLongPtr(hWnd, sizeof(PainterState *), (LONG_PTR) newPtr);
|
||||||
@ -229,6 +231,7 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
delete reinterpret_cast<PainterState *>(GetWindowLongPtr(hWnd, 0));
|
delete reinterpret_cast<PainterState *>(GetWindowLongPtr(hWnd, 0));
|
||||||
SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(nullptr));
|
SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(nullptr));
|
||||||
|
@ -35,11 +35,47 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Variant3S1Painter : public Painter {
|
||||||
|
public:
|
||||||
|
void draw(PainterState *state, Frame *frame) const override {
|
||||||
|
int W = frame->width, H = frame->height;
|
||||||
|
// Размер рисунка возьмём меньше (7 / 8), чтобы он не касался границ экрана
|
||||||
|
float a = 7.0f / 8 * ((W < H) ? W - 1 : H - 1);
|
||||||
|
if (a < 1) return; // Если окно очень маленькое, то ничего не рисуем
|
||||||
|
float angle = state->angle; // Угол поворота
|
||||||
|
a = a / 2;
|
||||||
|
|
||||||
|
Point center{W / 2, H / 2};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Рисуем описанную окружность
|
||||||
|
draw_circle(frame, center, a, COLOR(0, 0, 0));
|
||||||
|
draw_polyline(
|
||||||
|
frame, COLOR{0, 200, 0},
|
||||||
|
center.moved(0, a).rotated_around(center, 0 + angle),
|
||||||
|
center.moved(0, a).rotated_around(center, +2.0944 + angle),
|
||||||
|
center.moved(0, a).rotated_around(center, -2.0944 + angle)
|
||||||
|
);
|
||||||
|
draw_circle(frame, center, a / 2, COLOR(0, 200, 0));
|
||||||
|
draw_circle(frame, center.moved(0, a * 2 / 3).rotated_around(center, angle), a / 6, COLOR(0, 200, 0));
|
||||||
|
draw_circle(frame, center.moved(0, a * 2 / 3).rotated_around(center, +2.0944 + angle), a / 6, COLOR(0, 200, 0));
|
||||||
|
draw_circle(frame, center.moved(0, a * 2 / 3).rotated_around(center, -2.0944 + angle), a / 6, COLOR(0, 200, 0));
|
||||||
|
|
||||||
|
// Рисуем пиксель, на который кликнул пользователь
|
||||||
|
if (state->clicked_pixel.x >= 0 && state->clicked_pixel.x < W &&
|
||||||
|
state->clicked_pixel.y >= 0 && state->clicked_pixel.y < H)
|
||||||
|
frame->set_pixel(state->clicked_pixel.x, state->clicked_pixel.y, {34, 175, 60}); // Пиксель зелёного цвета
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static auto predefined_painters_ = std::make_tuple(
|
static auto predefined_painters_ = std::make_tuple(
|
||||||
DemoPainter()
|
DemoPainter(),
|
||||||
|
Variant3S1Painter()
|
||||||
);
|
);
|
||||||
|
|
||||||
Painter const *const predefined_painters[] = {
|
Painter const *const predefined_painters[] = {
|
||||||
&std::get<0>(predefined_painters_),
|
&std::get<0>(predefined_painters_),
|
||||||
|
&std::get<1>(predefined_painters_),
|
||||||
nullptr
|
nullptr
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user