Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Tima32

Pages: [1] 2
1
Window / Re: WinEvent
« on: July 11, 2021, 07:41:27 pm »
Yes. But I need some events that cannot be received via sf :: Event. For example, raw input and stylus events. Usually these events are received by the function
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

(System Windows)

2
Window / WinEvent
« on: July 11, 2021, 01:50:44 am »
Is there a way to get windows events other than using the SetWinEventHook function?

3
Window / My app is not receiving touch events.
« on: June 04, 2021, 10:18:08 pm »
My application is not receiving touch events.
The touchscreen works well, tested in Chrome.
cout << "E: " << event_e.type << endl;
if (event_e.type == Event::TouchBegan)
{
        cout << event_e.touch.finger << endl;
}
 
What could I have missed?
SFML 2.5.1
Windows 10
Visual Studio 19

4
General / Re: GPU info
« on: May 26, 2020, 05:49:44 pm »
OS: Windows
GPU: Nvidia

5
General / GPU info
« on: May 26, 2020, 04:46:07 pm »
How to get information from video memory and GPU load?

6
Graphics / Re: Memory leak when loading textures in multi-thread
« on: October 15, 2018, 12:25:57 am »
If you repeat the above with RenderWindov there will be a memory leak.

7
Graphics / Memory leak when loading textures in multi-thread
« on: October 15, 2018, 12:07:59 am »
There is a memory leak:
void _1()
{
        Texture t_up;
        t_up.loadFromFile(String(L"GUI\\Textures\\Up.png"));
}

while (1)
        {
                Thread t(&_1);
                t.launch();
                t.wait();
        }
 

No memory leaks:
void _1()
{
        Texture t_up;
        t_up.loadFromFile(String(L"GUI\\Textures\\Up.png"));
}

while (1)
        {
                _1();
        }

How to load textures in a multi-thread and not get memory leaks?
SFML 2.5.0 Visual Studio 15

8
Graphics / Re: problems with view
« on: July 24, 2018, 06:03:34 pm »
There was an error in converting data types in the string:
view.setCenter(parent_window->getSize().x / 2 - x, parent_window->getSize().y / 2 - y);
the data turned into a unsigned int.

9
Graphics / problems with view
« on: July 23, 2018, 12:26:21 pm »
I make a window that can be moved with the mouse, but when it is at the right or bottom side of the window it disappears. What am I doing wrong?
View save_view = parent_window->getView();

        RectangleShape background;
        background.setPosition(0, 0);
        background.setSize(Vector2f(width, height));
        background.setFillColor(fon_color);
        background.setOutlineThickness(outlain_size);
        background.setOutlineColor(border_color);

        RectangleShape handl;
        handl.setPosition(-outlain_size, -header_height);
        handl.setSize(Vector2f(width + outlain_size*2, header_height));
        handl.setFillColor(border_color);
       
        View view = parent_window->getView();
        view.setCenter(parent_window->getSize().x / 2 - x, parent_window->getSize().y / 2 - y);
        parent_window->setView(view);
        parent_window->draw(background);
        parent_window->draw(handl);
        parent_window->setView(save_view);

10
Graphics / How to make pixel shadows?
« on: June 04, 2018, 06:19:34 pm »
I want to make similar shadows in my game, but I do not know how.

I'll take the library, the article, whatever.

11
Graphics / Re: button error
« on: February 11, 2018, 06:18:57 pm »
Solved the problem with the help of a std::mutex.
Why does FloatRect lack thread safety? :-\

12
Graphics / Re: button error
« on: February 11, 2018, 02:25:39 pm »
Removed (new \ delete). Looked in the debugger, but did not understand why the error occurs.

It is only known that an error occurs only when a class is used in multiple threads.

13
Graphics / button error
« on: February 10, 2018, 08:26:50 pm »
I can not understand the reason for the error.

Unhandled exception at 0x000007FED080264D (sfml-graphics-2.dll) in Test.exe: 0xC0000005: violation of access rights when reading at 0x0000000000000000.

Video:

Project:
https://drive.google.com/file/d/15NDtyPFyfFMrHVf64q3HNxGbd4psblGR/view?usp=sharing


For those who do not want to download the project.
main.cpp:
#include "SFML/Graphics.hpp"
#include <iostream>
#include <windows.h>
#include <list>
#include <thread>

#include "Button.h"

using namespace std;
using namespace sf;

Font font;

void m2()
{
        RenderWindow MainWindow;
        MainWindow.create(VideoMode(640,480), L"Test");
        //window.setVerticalSyncEnabled(true);
        MainWindow.setFramerateLimit(60);//&#1082;&#1086;&#1083;&#1083;&#1080;&#1095;&#1077;&#1089;&#1090;&#1074;&#1086; &#1082;&#1072;&#1076;&#1088;&#1086;&#1074; &#1074; &#1089;&#1077;&#1082;&#1091;&#1085;&#1076;&#1091;

        //Button button(L"&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;", font, 50, 50, 11);
        Button *button = new Button(L"&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;", font, 5, 5, 11);
        Button *button2 = new Button(L"LOL", font, 60, 5, 20);

        while(MainWindow.isOpen())
        {
                Vector2i pixelPos = Mouse::getPosition(MainWindow);//&#1079;&#1072;&#1073;&#1080;&#1088;&#1072;&#1077;&#1084; &#1082;&#1086;&#1086;&#1088;&#1076; &#1082;&#1091;&#1088;&#1089;&#1086;&#1088;&#1072;
                Vector2f pos = MainWindow.mapPixelToCoords(pixelPos);//&#1087;&#1077;&#1088;&#1077;&#1074;&#1086;&#1076;&#1080;&#1084; &#1080;&#1093; &#1074; &#1080;&#1075;&#1088;&#1086;&#1074;&#1099;&#1077; (&#1091;&#1093;&#1086;&#1076;&#1080;&#1084; &#1086;&#1090; &#1082;&#1086;&#1086;&#1088;&#1076; &#1086;&#1082;&#1085;&#1072;)
               
                Event event;
                while(MainWindow.pollEvent(event))
                {
                        //&#1077;&#1089;&#1083;&#1080; &#1084;&#1099; &#1085;&#1072;&#1078;&#1084;&#1077;&#1084; &#1085;&#1072; &#1082;&#1085;&#1086;&#1087;&#1082;&#1091; &#1079;&#1072;&#1082;&#1088;&#1099;&#1090;&#1100;
                        if(event.type == Event::Closed)
                                MainWindow.close();

                        //&#1053;&#1072;&#1078;&#1072;&#1090;&#1080;&#1077;
                        if (event.type == Event::MouseButtonPressed && event.mouseButton.button == Mouse::Left)//&#1077;&#1089;&#1083;&#1080; &#1085;&#1072;&#1078;&#1072;&#1090;&#1072; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1072; &#1084;&#1099;&#1096;&#1080;
                        while(true)
                        {
                                if(button->pressed(event.mouseButton.x, event.mouseButton.y))
                                {break;}
                                if(button2->pressed(event.mouseButton.x, event.mouseButton.y))
                                {break;}
                                break;
                        }

                        //&#1054;&#1090;&#1078;&#1072;&#1090;&#1080;&#1077;
                        if (event.type == Event::MouseButtonReleased && event.mouseButton.button == Mouse::Left)//&#1077;&#1089;&#1083;&#1080; &#1085;&#1072;&#1078;&#1072;&#1090;&#1072; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1072; &#1084;&#1099;&#1096;&#1080;
                        {
                                button->released();
                                button2->released();
                        }

                        //&#1050;&#1083;&#1080;&#1082; &#1084;&#1099;&#1096;&#1080;
                        if (event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left)
                        do{
                                if(button->click(event.mouseButton.x, event.mouseButton.y))
                                {cout << "&#1050;&#1085;&#1086;&#1087;&#1082;&#1072; 1" << endl; button2->setText(L"EEE!!");break;}
                                if(button2->click(event.mouseButton.x, event.mouseButton.y))
                                {cout << "&#1050;&#1085;&#1086;&#1087;&#1082;&#1072; 2" << endl; button2->setText(L"Long long text on button2");break;}
                        }while(0);

                        //&#1055;&#1088;&#1072;&#1074;&#1099;&#1081; &#1082;&#1083;&#1080;&#1082;
                        if (event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Right)
                        {
                        }
                }

                MainWindow.clear(Color(45, 45, 48));
                bool tr = 1;
                button->draw(MainWindow, pos.x, pos.y, &tr);
                button2->draw(MainWindow, pos.x, pos.y, &tr);
                MainWindow.display();
        }

        delete button;
        delete button2;

        return;
}

int main()
{
        SetConsoleCP(1251);// &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1082;&#1072; &#1082;&#1086;&#1076;&#1086;&#1074;&#1086;&#1081; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1099; win-cp 1251 &#1074; &#1087;&#1086;&#1090;&#1086;&#1082; &#1074;&#1074;&#1086;&#1076;&#1072;
    SetConsoleOutputCP(1251); // &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1082;&#1072; &#1082;&#1086;&#1076;&#1086;&#1074;&#1086;&#1081; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1099; win-cp 1251 &#1074; &#1087;&#1086;&#1090;&#1086;&#1082; &#1074;&#1099;&#1074;&#1086;&#1076;&#1072;

        font.loadFromFile("tahoma.ttf");

        thread func_thread(m2);
        //Sleep(5000);

        RenderWindow MainWindow;
        MainWindow.create(VideoMode(640,480), L"Test");
        //window.setVerticalSyncEnabled(true);
        MainWindow.setFramerateLimit(60);//&#1082;&#1086;&#1083;&#1083;&#1080;&#1095;&#1077;&#1089;&#1090;&#1074;&#1086; &#1082;&#1072;&#1076;&#1088;&#1086;&#1074; &#1074; &#1089;&#1077;&#1082;&#1091;&#1085;&#1076;&#1091;

        //Button button(L"&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;", font, 50, 50, 11);
        Button *button = new Button(L"&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;", font, 5, 5, 11);
        Button *button2 = new Button(L"EEE!!", font, 60, 5, 20);

        while(MainWindow.isOpen())
        {
                Vector2i pixelPos = Mouse::getPosition(MainWindow);//&#1079;&#1072;&#1073;&#1080;&#1088;&#1072;&#1077;&#1084; &#1082;&#1086;&#1086;&#1088;&#1076; &#1082;&#1091;&#1088;&#1089;&#1086;&#1088;&#1072;
                Vector2f pos = MainWindow.mapPixelToCoords(pixelPos);//&#1087;&#1077;&#1088;&#1077;&#1074;&#1086;&#1076;&#1080;&#1084; &#1080;&#1093; &#1074; &#1080;&#1075;&#1088;&#1086;&#1074;&#1099;&#1077; (&#1091;&#1093;&#1086;&#1076;&#1080;&#1084; &#1086;&#1090; &#1082;&#1086;&#1086;&#1088;&#1076; &#1086;&#1082;&#1085;&#1072;)
               
                Event event;
                while(MainWindow.pollEvent(event))
                {
                        //&#1077;&#1089;&#1083;&#1080; &#1084;&#1099; &#1085;&#1072;&#1078;&#1084;&#1077;&#1084; &#1085;&#1072; &#1082;&#1085;&#1086;&#1087;&#1082;&#1091; &#1079;&#1072;&#1082;&#1088;&#1099;&#1090;&#1100;
                        if(event.type == Event::Closed)
                                MainWindow.close();

                        //&#1053;&#1072;&#1078;&#1072;&#1090;&#1080;&#1077;
                        if (event.type == Event::MouseButtonPressed && event.mouseButton.button == Mouse::Left)//&#1077;&#1089;&#1083;&#1080; &#1085;&#1072;&#1078;&#1072;&#1090;&#1072; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1072; &#1084;&#1099;&#1096;&#1080;
                        while(true)
                        {
                                if(button->pressed(event.mouseButton.x, event.mouseButton.y))
                                {break;}
                                if(button2->pressed(event.mouseButton.x, event.mouseButton.y))
                                {break;}
                                break;
                        }

                        //&#1054;&#1090;&#1078;&#1072;&#1090;&#1080;&#1077;
                        if (event.type == Event::MouseButtonReleased && event.mouseButton.button == Mouse::Left)//&#1077;&#1089;&#1083;&#1080; &#1085;&#1072;&#1078;&#1072;&#1090;&#1072; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1072; &#1084;&#1099;&#1096;&#1080;
                        {
                                button->released();
                                button2->released();
                        }

                        //&#1050;&#1083;&#1080;&#1082; &#1084;&#1099;&#1096;&#1080;
                        if (event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left)
                        do{
                                if(button->click(event.mouseButton.x, event.mouseButton.y))
                                {cout << "&#1050;&#1085;&#1086;&#1087;&#1082;&#1072; 1" << endl; button2->setText(L"EEE!!");break;}
                                if(button2->click(event.mouseButton.x, event.mouseButton.y))
                                {cout << "&#1050;&#1085;&#1086;&#1087;&#1082;&#1072; 2" << endl; button2->setText(L"Long long text on button2");break;}
                        }while(0);

                        //&#1055;&#1088;&#1072;&#1074;&#1099;&#1081; &#1082;&#1083;&#1080;&#1082;
                        if (event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Right)
                        {
                        }
                }

                MainWindow.clear(Color(45, 45, 48));
                bool tr = 1;
                button->draw(MainWindow, pos.x, pos.y, &tr);
                button2->draw(MainWindow, pos.x, pos.y, &tr);
                MainWindow.display();
        }

        delete button;
        delete button2;

        return 0;
}

Button.h:
#pragma once
#include "SFML/Graphics.hpp"
#include <iostream>
using namespace sf;
using namespace std;

class Button
{
public:
        Button(wchar_t *PText, Font &font, float x, float y, int CharacterSize);
        ~Button();
        void draw(RenderWindow &window, int x, int y, bool *tr);
        void setPosition(float x, float y);
        void setText(wchar_t *PText);
        void setTextColor(Color &color);
        void setColor(Color &color);
        void setGuidanceColor(Color &color);
        void setPressColor(Color &color);
        void setCharacterSize(int CharacterSize);
        bool pressed(int x, int y);
        void released();
        bool released(int x, int y);
        bool click(int x, int y);

private:
        Text *text;
        RectangleShape *Rectangle;
        Color *CStandart;
        Color *GuidanceColor;
        Color *PressedColor;
        int *positionX;
        int *positionY;
        float *width;
        float *height;
        bool *Pressed;

        bool activityZoneCheck(int x, int y);
};

Button.cpp:
#include "Button.h"


Button::Button(wchar_t *PText, Font &font, float x = 0, float y = 0, int CharacterSize = 11)
{
        Rectangle = new RectangleShape;
        text = new Text;
        CStandart = new Color(Color(45, 45, 48));
        GuidanceColor = new Color(Color(62, 62, 64));
        PressedColor = new Color(27, 27, 28);
        positionX = new int(x);
        positionY = new int(y);
        width = new float(0);
        height = new float(16);
        Pressed = new bool(0);

        //Rectangle->setPosition(x,y);
        Rectangle->setFillColor(*CStandart);

        text->setString(PText);
        text->setFont(font);
        text->setCharacterSize(CharacterSize);
        text->setColor(Color(255, 255, 255));

        setPosition(x, y);
}
Button::~Button()
{
        delete text;
        delete Rectangle;
        delete CStandart;
        delete GuidanceColor;
        delete PressedColor;
        delete positionX;
        delete positionY;
        delete width;
        delete height;
        delete Pressed;
}
void Button::draw(RenderWindow &window, int x, int y, bool *tr)
{
        if(*tr && activityZoneCheck(x, y) && !*Pressed)
        {
                Rectangle->setFillColor(*GuidanceColor);
                *tr = 0;
        }
        else if(!*Pressed)
                Rectangle->setFillColor(*CStandart);


        window.draw(*Rectangle);
        window.draw(*text);
}
void Button::setPosition(float x, float y)
{
        *positionX = x;
        *positionY = y;
        Rectangle->setPosition(x,y);
        FloatRect Bounding_Rectangle(text->getLocalBounds());
        text->setPosition(x+4,y);

        *width = (Bounding_Rectangle.width + 8) * 1.02;
        *height = (Bounding_Rectangle.height + 4)*1.35;

        Rectangle->setSize(Vector2f(*width, *height));
}
void Button::setText(wchar_t *PText)
{
        text->setString(PText);
        setPosition(*positionX, *positionY);
}
void Button::setTextColor(Color &color)
{
        text->setColor(color);
}
void Button::setColor(Color &color)
{
        *CStandart = color;
}
void Button::setGuidanceColor(Color &color)
{
        *GuidanceColor = color;
}
void Button::setPressColor(Color &color)
{
        *PressedColor = color;
}
void Button::setCharacterSize(int CharacterSize)
{
        text->setCharacterSize(CharacterSize);
        setPosition(*positionX, *positionY);
}
bool Button::pressed(int x, int y)
{
        if(activityZoneCheck(x, y))
        {
                Rectangle->setFillColor(*PressedColor);
                *Pressed = 1;
                return 1;
        }
        return 0;
}
void Button::released()
{
        Rectangle->setFillColor(*CStandart);
        *Pressed = 0;
}
bool Button::released(int x, int y)
{
        if(activityZoneCheck(x, y))
        {
                Rectangle->setFillColor(*CStandart);
                *Pressed = 0;
                return 1;
        }
        return 0;
}
bool Button::click(int x, int y)
{
        return activityZoneCheck(x, y);
}
//pivate:
bool Button::activityZoneCheck(int x, int y)
{
        if(x >= *positionX && x <= *positionX+*width && y >= *positionY && y <= *positionY+*height)
                return true;
        else
                return false;
}

14
Graphics / Re: Text Box
« on: February 07, 2018, 03:45:44 pm »
What am I doing wrong?

15
Graphics / Re: Text Box
« on: February 07, 2018, 02:59:20 pm »
p.s Windows will be processed in different threads.

Pages: [1] 2