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 - AntonBesp

Pages: [1]
1
I want to load resources(images, fonts, sounds ant etc.) that has wide(Unicode) characters in their path. SFML's "loadFromFile" functions takes only standard std::string but not std::wstring.

I tried using custom file input stream but it didn't work.

#include <string>
#include <SFML/System/InputStream.hpp>
#include <SFML/Config.hpp>
#include <fstream>

namespace FileIO
{

class WFileInputStream : public sf::InputStream
{
public:
    std::ifstream stream;

public:
    WFileInputStream()
    : sf::InputStream(), stream() {}

    WFileInputStream(std::wstring path)
    : sf::InputStream(), stream()
    {
        stream.open(path);
    }


    bool open(std::wstring path)
    {
        stream.open(path);
        return stream.is_open();
    }

    sf::Int64 getSize() override
    {
        long l1 = stream.tellg();
        long l2 = l1;
        stream.seekg(0, std::ios::end);
        l1 = static_cast<long>(stream.tellg()) - l1;
        stream.seekg(l2);
        return l1; // Tried adding 1. It didn't work
    }

    sf::Int64 tell() override
    {
        return stream.tellg();
    }

    sf::Int64 seek(sf::Int64 position) override
    {
        stream.seekg(position, std::ios::beg);
        return stream.tellg();
    }

    sf::Int64 read(void* data, sf::Int64 size) override
    {
        long long l1 = stream.tellg();
        stream.read(static_cast<char*>(data), size);
        //stream.seekg(size, std::ios::right);
        return stream.tellg().operator-(l1);
    }
};

}
 

Trying to load an image(I checked its path multiple times) using this stream fails with error "Failed to load image from stream. Reason: Image not of any known type, or corrupt", "Trying to access the pixels of an empty image". But I tried using this stream with plain text files(.txt) and all methods of the stream worked properly.

Maybe you can suggest some other way to load image from directory with wide(Unicode) characters in it. Or fix my stream code.

2
General discussions / Overlapping views to create GUI and world view.
« on: December 18, 2019, 08:04:35 pm »
I want to make user be able to zoom in/out the world. Like in games such as Terraria where you need to press + to zoom in and - to zoom out. I know that this feature is implemented in one method of View class. But also I have GUI that mustn't be resized on zooming. Can I create two views(one for GUI, another for world) and overlap them to achieve it? Will GUI view be transparent in places where it is wanted to be transparent?

Pages: [1]