This repository was archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyPaint.h
152 lines (134 loc) · 5.1 KB
/
MyPaint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once
#ifdef _MSC_VER
# // Используемые библиотеки:
# // - SFML 2.3.2
# // - SFGUI 0.3.0
# pragma comment(lib, "opengl32.lib")
# pragma comment(lib, "winmm.lib")
# pragma comment(lib, "freetype.lib")
# pragma comment(lib, "jpeg.lib")
# ifdef _DEBUG
# pragma comment(lib, "sfml-main-d.lib")
# pragma comment(lib, "sfml-window-s-d.lib")
# pragma comment(lib, "sfml-graphics-s-d.lib")
# pragma comment(lib, "sfml-system-s-d.lib")
# pragma comment(lib, "sfgui-s-d.lib")
# else
# pragma comment(lib, "sfml-main.lib")
# pragma comment(lib, "sfml-window-s.lib")
# pragma comment(lib, "sfml-graphics-s.lib")
# pragma comment(lib, "sfml-system-s.lib")
# pragma comment(lib, "sfgui-s.lib")
# endif // _DEBUG
#
# // Оконное (не консоль + окно) приложение
# pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
# //pragma comment(linker, "/SUBSYSTEM:console")
#endif // _MSC_VER
#include <string>
#include <memory>
#include <unordered_map>
#define SFML_STATIC
#define SFGUI_STATIC
#include <SFGUI/SFGUI.hpp>
#include <SFGUI/Widgets.hpp>
#include <SFML/Graphics.hpp>
#include "Canvas.h"
#include "Line.h"
#include "Rectangle.h"
#include "Ellipse.h"
#include "Brush.h"
namespace Tools
{
namespace Names
{
const std::string Line("Line");
const std::string Rectangle("Rectangle");
const std::string Ellipse("Ellipse");
const std::string Brush("Brush");
};
};
// Включает функции загрузки и сохранения
#define LOAD_SAVE_DIALOG
class MyPaint
{
const sf::Color colorCanvasBG { 200, 212, 226 };
const sf::Vector2i windowSize { 816, 616 };
const sf::Vector2i imageMaxSize { 800, 600 };
const int fpsLimit = 60;
const sf::Vector2i penWidthMinMax { 1, 400 };
const sf::Vector2i pickerSize { 104, 104 };
public:
MyPaint();
~MyPaint();
void show();
private:
// Регистрация инструментов
void setupTools();
// Настройка интерфейса
// Должно быть вызвано не раньше setupTools!
void setupUI();
// Инициализация цветов палитры (заливка)
// Должно быть вызвано не раньше setupUI!
void fillPalette();
// Добавление (регистрация) инструмента
template <typename T>
void registerTool(const std::string &name);
// Обработка выбранного инструмента
void updateTool();
void onClickButtonLine();
void onClickButtonRectangle();
void onClickButtonEllipse();
void onClickButtonBrush();
void onAdjustmentChange();
void onWidthValueChanged();
void onRValueChanged();
void onGValueChanged();
void onBValueChanged();
void onAValueChanged();
void onPickerClicked();
#ifdef LOAD_SAVE_DIALOG
void onLoadClicked();
void onSaveAsClicked();
#endif
sf::Vector2i canvasSize = imageMaxSize;
sf::Vector2i canvasPos { 8, 8 };
std::unique_ptr<sf::RenderWindow> m_window;
std::unique_ptr<sfg::SFGUI> m_sfgui;
std::unordered_map<std::string,
std::unique_ptr<Tool>> m_tools;
Tool *m_currentTool = nullptr;
std::unordered_map<std::string,
std::shared_ptr<sfg::Window>> m_guiWindows;
std::shared_ptr<sfg::Box> m_guiToolsBox;
std::unordered_map<std::string,
std::shared_ptr<sfg::Button>> m_guiToolsButtons;
std::shared_ptr<sfg::Label> m_guiToolsLabel;
std::shared_ptr<sfg::Button> m_guiToolsLoad;
std::shared_ptr<sfg::Button> m_guiToolsSaveAs;
std::shared_ptr<sfg::Box> m_guiParamBox1;
std::shared_ptr<sfg::Box> m_guiParamBox21;
std::shared_ptr<sfg::Label> m_guiParamLabelWidth;
std::shared_ptr<sfg::SpinButton> m_guiParamEntryWidth;
std::shared_ptr<sfg::Adjustment> m_guiParamAdjustmentWidth;
std::shared_ptr<sfg::Scale> m_guiParamScaleWidth;
std::shared_ptr<sfg::Box> m_guiParamBox22;
std::shared_ptr<sfg::Canvas> m_guiParamCanvasClrResult;
std::shared_ptr<sfg::Canvas> m_guiParamCanvasClrPicker;
std::shared_ptr<sfg::Box> m_guiParamBox3;
std::shared_ptr<sfg::Box> m_guiParamBox41;
std::shared_ptr<sfg::Label> m_guiParamLabelR;
std::shared_ptr<sfg::SpinButton> m_guiParamEntryR;
std::shared_ptr<sfg::Box> m_guiParamBox42;
std::shared_ptr<sfg::Label> m_guiParamLabelG;
std::shared_ptr<sfg::SpinButton> m_guiParamEntryG;
std::shared_ptr<sfg::Box> m_guiParamBox43;
std::shared_ptr<sfg::Label> m_guiParamLabelB;
std::shared_ptr<sfg::SpinButton> m_guiParamEntryB;
std::shared_ptr<sfg::Box> m_guiParamBox44;
std::shared_ptr<sfg::Label> m_guiParamLabelA;
std::shared_ptr<sfg::SpinButton> m_guiParamEntryA;
std::unique_ptr<Canvas> m_canvasMain;
std::unique_ptr<Canvas> m_canvasTemp;
PaintParameters m_paintParam;
};