Загрузить файлы в «src»
This commit is contained in:
parent
0da9c732b2
commit
eed6defe91
9
src/data-files.hpp
Normal file
9
src/data-files.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
sf::Font betterVCR;
|
||||
|
||||
void get_files(){
|
||||
betterVCR.loadFromFile("../src/BetterVCR/BetterVCR_6.1.ttf");
|
||||
// betterVCR.loadFromFile("Arial.ttf");
|
||||
}
|
257
src/data.hpp
Normal file
257
src/data.hpp
Normal file
@ -0,0 +1,257 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "data-files.hpp"
|
||||
#include <math.h>
|
||||
|
||||
sf::Vector2u old_size_window;
|
||||
|
||||
void old_size(sf::RenderWindow& window){
|
||||
old_size_window = window.getSize();
|
||||
}
|
||||
|
||||
class object;
|
||||
|
||||
void RoundedRectangle(object& obj,sf::RenderWindow& window);
|
||||
void rectangle_draw(sf::RenderWindow& window, object& obj);
|
||||
void text_draw(sf::RenderWindow& window, object& obj);
|
||||
|
||||
class object{
|
||||
public:
|
||||
std::string name;
|
||||
sf::Color color, outline_col;
|
||||
|
||||
sf::Vector2f position;
|
||||
sf::Vector2f size;
|
||||
sf::Vector2f real_size=sf::Vector2f(0, 0), real_pos=sf::Vector2f(0, 0);
|
||||
std::string type = "sprite";
|
||||
sf::String text;
|
||||
bool isActive, isInput, statusInput, isWisible;
|
||||
sf::Vector2i stick_pos = sf::Vector2i(0,0);
|
||||
sf::Vector2i origin_pos = sf::Vector2i(-1,-1);
|
||||
sf::Vector2i scale_pos = sf::Vector2i(0,0);
|
||||
float rotate_angle = 0;
|
||||
int layer;
|
||||
float radius, outline;
|
||||
object* stick_object;
|
||||
|
||||
void draw(sf::RenderWindow& window){
|
||||
if(type == "sprite")
|
||||
rectangle_draw(window, *this);
|
||||
if(type == "round")
|
||||
RoundedRectangle(*this, window);
|
||||
if(type == "text")
|
||||
text_draw(window, *this);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
object* null;
|
||||
|
||||
void rectangle_draw(sf::RenderWindow& window, object& obj){
|
||||
sf::RectangleShape shape;
|
||||
|
||||
float psX=obj.position.x;
|
||||
float psY=obj.position.y;
|
||||
float spX=obj.size.x;
|
||||
float spY=obj.size.y;
|
||||
|
||||
if(obj.scale_pos.x == 1 || obj.scale_pos.x == -1){
|
||||
spX = obj.size.x+(float)window.getSize().x/2-(float)old_size_window.x/2;
|
||||
}
|
||||
if(obj.scale_pos.y == 1 || obj.scale_pos.y == -1){
|
||||
spY = obj.size.y+(float)window.getSize().y/2-(float)old_size_window.y/2;
|
||||
}
|
||||
if(obj.scale_pos.x == 0){
|
||||
spX = obj.size.x+(float)window.getSize().x-(float)old_size_window.x;
|
||||
}
|
||||
if(obj.scale_pos.y == 0){
|
||||
spY = obj.size.y+(float)window.getSize().y-(float)old_size_window.y;
|
||||
}
|
||||
|
||||
obj.real_size.x = spX;
|
||||
obj.real_size.y = spY;
|
||||
|
||||
if(obj.stick_object != null){
|
||||
if(obj.stick_pos.x == 0){
|
||||
psX = ((float)obj.stick_object->real_size.x)/2-obj.real_size.x/2+obj.position.x+(float)obj.stick_object->real_pos.x;
|
||||
}
|
||||
if(obj.stick_pos.x == 1){
|
||||
psX = ((float)obj.stick_object->real_size.x)-obj.real_size.x-obj.position.x+(float)obj.stick_object->real_pos.x;
|
||||
}
|
||||
if(obj.stick_pos.x == -1){
|
||||
psX = (float)obj.position.x+obj.stick_object->real_pos.x;
|
||||
}
|
||||
|
||||
if(obj.stick_pos.y == 0){
|
||||
psY = ((float)obj.stick_object->real_size.y)/2-obj.real_size.y/2+obj.position.y+(float)obj.stick_object->real_pos.y;
|
||||
}
|
||||
if(obj.stick_pos.y == 1){
|
||||
psY = ((float)obj.stick_object->real_size.y)-obj.real_size.y-obj.position.y+(float)obj.stick_object->real_pos.y;
|
||||
}
|
||||
if(obj.stick_pos.y == -1){
|
||||
psY = (float)obj.position.y+obj.stick_object->real_pos.y;
|
||||
}
|
||||
}
|
||||
obj.real_pos.x = psX;
|
||||
obj.real_pos.y = psY;
|
||||
|
||||
shape.setOutlineThickness(obj.outline);
|
||||
shape.setOutlineColor(obj.outline_col);
|
||||
shape.setSize(sf::Vector2f(spX, spY));
|
||||
shape.setPosition(sf::Vector2f(psX,psY));
|
||||
shape.setFillColor(obj.color);
|
||||
window.draw(shape);
|
||||
}
|
||||
|
||||
|
||||
void RoundedRectangle(object& obj,sf::RenderWindow& window)
|
||||
{
|
||||
int POINTS = obj.radius;
|
||||
|
||||
float psX=obj.position.x;
|
||||
float psY=obj.position.y;
|
||||
float spX=obj.size.x;
|
||||
float spY=obj.size.y;
|
||||
|
||||
if(obj.scale_pos.x == 1 || obj.scale_pos.x == -1){
|
||||
spX = obj.size.x+(float)window.getSize().x/2-(float)old_size_window.x/2;
|
||||
}
|
||||
if(obj.scale_pos.y == 1 || obj.scale_pos.y == -1){
|
||||
spY = obj.size.y+(float)window.getSize().y/2-(float)old_size_window.y/2;
|
||||
}
|
||||
if(obj.scale_pos.x == 0){
|
||||
spX = obj.size.x+(float)window.getSize().x-(float)old_size_window.x;
|
||||
}
|
||||
if(obj.scale_pos.y == 0){
|
||||
spY = obj.size.y+(float)window.getSize().y-(float)old_size_window.y;
|
||||
}
|
||||
|
||||
obj.real_size.x = spX;
|
||||
obj.real_size.y = spY;
|
||||
|
||||
if(obj.stick_object != null){
|
||||
if(obj.stick_pos.x == 0){
|
||||
psX = ((float)obj.stick_object->real_size.x)/2-obj.real_size.x/2+obj.position.x+(float)obj.stick_object->real_pos.x;
|
||||
}
|
||||
if(obj.stick_pos.x == 1){
|
||||
psX = ((float)obj.stick_object->real_size.x)-obj.real_size.x-obj.position.x+(float)obj.stick_object->real_pos.x;
|
||||
}
|
||||
if(obj.stick_pos.x == -1){
|
||||
psX = (float)obj.position.x+obj.stick_object->real_pos.x;
|
||||
}
|
||||
|
||||
if(obj.stick_pos.y == 0){
|
||||
psY = ((float)obj.stick_object->real_size.y)/2-obj.real_size.y/2+obj.position.y+(float)obj.stick_object->real_pos.y;
|
||||
}
|
||||
if(obj.stick_pos.y == 1){
|
||||
psY = ((float)obj.stick_object->real_size.y)-obj.real_size.y-obj.position.y+(float)obj.stick_object->real_pos.y;
|
||||
}
|
||||
if(obj.stick_pos.y == -1){
|
||||
psY = (float)obj.position.y+obj.stick_object->real_pos.y;
|
||||
}
|
||||
}
|
||||
obj.real_pos.x = psX;
|
||||
obj.real_pos.y = psY;
|
||||
|
||||
/* https://en.sfml-dev.org/forums/index.php?topic=973.0 */
|
||||
sf::ConvexShape rrect;
|
||||
rrect.setPointCount(POINTS*4);
|
||||
rrect.setOutlineThickness(obj.outline);
|
||||
rrect.setOutlineColor(obj.outline_col);
|
||||
rrect.setFillColor(obj.color);
|
||||
float X=0,Y=0;
|
||||
int a = 0;
|
||||
for(int i=0; i<POINTS; i++)
|
||||
{
|
||||
X+=obj.radius/POINTS;
|
||||
Y=sqrt(obj.radius*obj.radius-X*X);
|
||||
rrect.setPoint(a, sf::Vector2f(X+psX+spX-obj.radius,psY-Y+obj.radius));
|
||||
a++;
|
||||
}
|
||||
Y=0;
|
||||
for(int i=0; i<POINTS; i++)
|
||||
{
|
||||
Y+=obj.radius/POINTS;
|
||||
X=sqrt(obj.radius*obj.radius-Y*Y);
|
||||
rrect.setPoint(a, sf::Vector2f(psX+spX+X-obj.radius,psY+spY-obj.radius+Y));
|
||||
a++;
|
||||
}
|
||||
X=0;
|
||||
for(int i=0; i<POINTS; i++)
|
||||
{
|
||||
X+=obj.radius/POINTS;
|
||||
Y=sqrt(obj.radius*obj.radius-X*X);
|
||||
rrect.setPoint(a, sf::Vector2f(psX+obj.radius-X,psY+spY-obj.radius+Y));
|
||||
a++;
|
||||
}
|
||||
Y=0;
|
||||
for(int i=0; i<POINTS; i++)
|
||||
{
|
||||
Y+=obj.radius/POINTS;
|
||||
X=sqrt(obj.radius*obj.radius-Y*Y);
|
||||
rrect.setPoint(a, sf::Vector2f(psX-X+obj.radius,psY+obj.radius-Y));
|
||||
a++;
|
||||
}
|
||||
window.draw(rrect);
|
||||
}
|
||||
|
||||
void text_draw(sf::RenderWindow& window, object& obj){
|
||||
sf::Text shape(obj.text, betterVCR);
|
||||
float psX=obj.position.x;
|
||||
float psY=obj.position.y;
|
||||
|
||||
shape.setCharacterSize(obj.size.x);
|
||||
shape.setFillColor(obj.color);
|
||||
//shape.setOutlineColor(obj.outline_col);
|
||||
//shape.setOutlineThickness(obj.outline);
|
||||
|
||||
sf::FloatRect textRect = shape.getLocalBounds(); // получение границ текста
|
||||
sf::Vector2f textSize(textRect.width, textRect.height); // размеры текста
|
||||
|
||||
obj.real_size = textSize;
|
||||
|
||||
if(obj.stick_object != null){
|
||||
if(obj.stick_pos.x == 0){
|
||||
psX = ((float)obj.stick_object->real_size.x)/2-obj.real_size.x/2+obj.position.x+(float)obj.stick_object->real_pos.x;
|
||||
}
|
||||
if(obj.stick_pos.x == 1){
|
||||
psX = ((float)obj.stick_object->real_size.x)-obj.real_size.x-obj.position.x+(float)obj.stick_object->real_pos.x;
|
||||
}
|
||||
if(obj.stick_pos.x == -1){
|
||||
psX = (float)obj.position.x+obj.stick_object->real_pos.x;
|
||||
}
|
||||
|
||||
if(obj.stick_pos.y == 0){
|
||||
psY = ((float)obj.stick_object->real_size.y)/2-obj.real_size.y/2+obj.position.y+(float)obj.stick_object->real_pos.y;
|
||||
}
|
||||
if(obj.stick_pos.y == 1){
|
||||
psY = ((float)obj.stick_object->real_size.y)-obj.real_size.y-obj.position.y+(float)obj.stick_object->real_pos.y;
|
||||
}
|
||||
if(obj.stick_pos.y == -1){
|
||||
psY = (float)obj.position.y+obj.stick_object->real_pos.y;
|
||||
}
|
||||
}
|
||||
obj.real_pos.x = psX;
|
||||
obj.real_pos.y = psY;
|
||||
shape.setPosition(psX, psY);
|
||||
window.draw(shape);
|
||||
}
|
||||
|
||||
object* new_object(std::vector<std::unique_ptr<object>>& massive,std::string name, float pos_x, float pos_y, float size_x, float size_y, object* obj_stick = null,int st_x=2,int st_y=0, sf::Color color=sf::Color::White){
|
||||
auto obj = std::make_unique<object>();
|
||||
obj->name = name;
|
||||
obj->position.x = pos_x;
|
||||
obj->position.y = pos_y;
|
||||
obj->size.x = size_x;
|
||||
obj->size.y = size_y;
|
||||
obj->color = color;
|
||||
obj->stick_pos.x = st_x;
|
||||
obj->stick_pos.y = st_y;
|
||||
obj->stick_object = obj_stick;
|
||||
massive.push_back(std::move(obj));
|
||||
return massive.back().get();
|
||||
}
|
||||
|
||||
|
13
src/draw.hpp
Normal file
13
src/draw.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "data.hpp"
|
||||
|
||||
|
||||
void update_window(sf::RenderWindow& window,std::vector<std::unique_ptr<object>>& objects){
|
||||
window.clear();
|
||||
for(const auto & i : objects){
|
||||
object* obj = i.get();
|
||||
obj->draw(window);
|
||||
}
|
||||
window.display();
|
||||
}
|
41
src/main.cpp
Normal file
41
src/main.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "data-files.hpp"
|
||||
#include "draw.hpp"
|
||||
#include "data.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
std::vector<std::unique_ptr<object>> objects;
|
||||
|
||||
int main(){
|
||||
sf::ContextSettings settings;
|
||||
settings.antialiasingLevel = 5;
|
||||
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!", sf::Style::Default, settings); old_size(window); get_files();
|
||||
|
||||
object* canvas = new_object(objects,"canvas" , 0, 0, 0, 0, null, 10, 10,sf::Color::Black);
|
||||
canvas->size = sf::Vector2f(200,200);
|
||||
|
||||
object* obj = new_object(objects,"center",0,0,120,50,canvas,-1,-1,sf::Color(120,100,200,100));
|
||||
obj->type = "round";
|
||||
obj->radius = 20;
|
||||
|
||||
object* text = new_object(objects,"texte",0,0,30,0,obj,0,0,sf::Color::White);
|
||||
text->type = "text";
|
||||
text->text = "UwU";
|
||||
|
||||
while (window.isOpen()){
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event)){
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
if (event.type == sf::Event::Resized){
|
||||
sf::FloatRect visible(0.f, 0.f, event.size.width, event.size.height);
|
||||
window.setView(sf::View(visible));
|
||||
}
|
||||
}
|
||||
update_window(window,objects);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user