-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
230 lines (187 loc) · 8.66 KB
/
main.cpp
File metadata and controls
230 lines (187 loc) · 8.66 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "imgui.h"
#include "imgui-SFML.h"
#include "SFML/Graphics.hpp"
#include <iostream>
#include <fstream>
class AShape { // The class
public: // Access specifier
sf::CircleShape circle; // Attribute (int variable)
sf::RectangleShape rectangle; // Attribute (string variable)
float speed[2];
sf::Text name;
AShape() {
}
};
int main()
{
sf::RenderWindow window;
sf::Font font;
std::ifstream fin("config.txt");
std::string temp;
int characterSize, textR, textG, textB;
std::vector<AShape> circles;
std::vector<const char*> shapeNames;
while (fin >> temp) {
if (temp.compare("Window") == 0) {
int windowWidth, windowHeight;
fin >> windowWidth >> windowHeight;
window.create(sf::VideoMode(windowWidth, windowHeight), "Window Title");
}
else if (temp.compare("Font") == 0) {
std::string font1;
fin >> font1>> characterSize>>textR>>textG>>textB;
if (!font.loadFromFile(font1))
{
std::cout << "Download Arial!\n";
}
}
else if (temp.compare("Circle") == 0) {
AShape circle1;
fin >> temp;
circle1.name.setFont(font); // font is a sf::Font
circle1.name.setString(temp);
circle1.name.setCharacterSize(characterSize); // in pixels, not points!
circle1.name.setFillColor(sf::Color(textR, textG, textB));
circle1.name.setStyle(sf::Text::Bold | sf::Text::Underlined);
circle1.name.setOrigin(circle1.name.getLocalBounds().width / 2.f + circle1.name.getLocalBounds().left, circle1.name.getLocalBounds().height / 2.f + circle1.name.getLocalBounds().top);
char* char_array = new char[sizeof temp];
strcpy_s(char_array, sizeof temp, temp.c_str());
shapeNames.push_back(char_array);
int temp1, temp2;
fin >> temp1 >> temp2;
circle1.circle.setPosition(temp1, temp2); // Center circle
std::cout << temp1 << temp2;
fin >> temp1 >> temp2;
circle1.speed[0] = temp1;
circle1.speed[1] = temp2;
int temp3;
fin >> temp1 >> temp2>>temp3;
circle1.circle.setFillColor(sf::Color
(
(int)(temp1),
(int)(temp2),
(int)(temp3)
));
fin >> temp3;
circle1.circle.setRadius(temp3);
//circle1.circle.setOrigin(temp3, temp3);
// select the font
circles.push_back(circle1);
}
else if (temp.compare("Rectangle") == 0) {
AShape circle1;
fin >> temp;
circle1.name.setFont(font); // font is a sf::Font
circle1.name.setString(temp);
circle1.name.setCharacterSize(characterSize); // in pixels, not points!
circle1.name.setFillColor(sf::Color(textR, textG, textB));
circle1.name.setStyle(sf::Text::Bold | sf::Text::Underlined);
circle1.name.setOrigin(circle1.name.getLocalBounds().width / 2.f + circle1.name.getLocalBounds().left, circle1.name.getLocalBounds().height / 2.f + circle1.name.getLocalBounds().top);
char* char_array = new char[sizeof temp];
strcpy_s(char_array, sizeof temp, temp.c_str());
shapeNames.push_back(char_array);
int temp1, temp2;
fin >> temp1 >> temp2;
circle1.rectangle.setPosition(temp1, temp2); // Center circle
std::cout << temp1 << temp2;
fin >> temp1 >> temp2;
circle1.speed[0] = temp1;
circle1.speed[1] = temp2;
int temp3;
fin >> temp1 >> temp2 >> temp3;
circle1.rectangle.setFillColor(sf::Color
(
(int)(temp1),
(int)(temp2),
(int)(temp3)
));
fin >> temp1>>temp2;
circle1.rectangle.setSize(sf::Vector2f(temp1, temp2));
//circle1.rectangle.setOrigin(temp1/2, temp2/2);
// select the font
circles.push_back(circle1);
}
}
//const char* items[circles.size()];
window.setFramerateLimit(60);
ImGui::SFML::Init(window);
bool circleExists = true;
float circleScale = 1.0f;
int circleSegments = 100;
float circleColor[3] = { (float)0 / 255, (float)255 / 255, (float)0 / 255 };
//text.setPosition(shape.getPosition());
char displayString[255] = "CGreen";
sf::Clock deltaClock;
ImGui::GetStyle().ScaleAllSizes(1.0f);
static int item_current = 0;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
ImGui::SFML::ProcessEvent(event);
if (event.type == sf::Event::Closed)
window.close();
}
ImGui::SFML::Update(window, deltaClock.restart());
ImGui::ShowDemoWindow();
//edw.is
ImGui::Begin("Window title");
ImGui::Text("Window text!");
ImGui::Combo("combo3", &item_current, shapeNames.data(), shapeNames.size());
ImGui::Checkbox("Circle", &circleExists);
ImGui::SliderFloat("Scale", &circleScale, 0.0f, 4.0f);
ImGui::SliderInt("Sides", &circleSegments, 3, 150);
ImGui::SliderFloat2("velocity", circles[item_current].speed, -8, 8);
ImGui::ColorEdit3("Color Circle", circleColor);
ImGui::InputText("Text", displayString, 255);
if (ImGui::Button("Set Text")) {
//text.setString(displayString);
}
ImGui::End();
for (auto& c : circles) {
//c.circle.setRadius(circleRadius);
//c.circle.setOrigin(circleRadius, circleRadius);
std::string name_string = c.name.getString();
if (name_string[0] == 'C') {
c.circle.setPosition(c.circle.getPosition().x + c.speed[0], c.circle.getPosition().y + c.speed[1]);
//std::cout << c.circle.getPosition().x << c.circle.getPosition().y << "\n";
//c.name.setPosition(c.circle.getPosition()+sf::Vector2f(c.circle.getRadius(), c.circle.getRadius())*c.circle.getScale().x);
c.name.setPosition(sf::Vector2f(c.circle.getGlobalBounds().left + c.circle.getGlobalBounds().width / 2, c.circle.getGlobalBounds().top + c.circle.getGlobalBounds().height / 2));
if (c.circle.getPosition().x + c.circle.getRadius()*2*c.circle.getScale().x >= window.getSize().x || c.circle.getPosition().x <= 0) {
c.speed[0] *= -1;
}
if (c.circle.getPosition().y + c.circle.getRadius()*2* c.circle.getScale().y >= window.getSize().y || c.circle.getPosition().y <= 0) {
c.speed[1] *= -1;
}
}
else if (name_string[0] == 'R') {
c.rectangle.setPosition(c.rectangle.getPosition().x + c.speed[0], c.rectangle.getPosition().y + c.speed[1]);
//c.name.setPosition(c.rectangle.getPosition() + c.rectangle.getSize()/2.0f * c.rectangle.getScale().x);
c.name.setPosition(sf::Vector2f(c.rectangle.getGlobalBounds().left + c.rectangle.getGlobalBounds().width / 2, c.rectangle.getGlobalBounds().top + c.rectangle.getGlobalBounds().height / 2));
if (c.rectangle.getPosition().x + c.rectangle.getSize().x * c.rectangle.getScale().x >= window.getSize().x || c.rectangle.getPosition().x <= 0) {
c.speed[0] *= -1;
}
if (c.rectangle.getPosition().y + c.rectangle.getSize().y * c.rectangle.getScale().y >= window.getSize().y || c.rectangle.getPosition().y <= 0) {
c.speed[1] *= -1;
}
}
}
circles[item_current].circle.setScale(circleScale, circleScale);
circles[item_current].rectangle.setScale(circleScale, circleScale);
//text.setPosition(shape.getPosition().x, shape.getPosition().y);
window.clear(sf::Color(18, 33, 43)); // Color background
if (circleExists) {
//window.draw(text);
}
for (auto a : circles) {
window.draw(a.circle);
window.draw(a.rectangle);
window.draw(a.name);
}
ImGui::SFML::Render(window);
window.display();
}
ImGui::SFML::Shutdown();
return 0;
}