add window icon
This commit is contained in:
parent
c0ba5be458
commit
b021339a8a
BIN
res/textures/misc/icon.png
Normal file
BIN
res/textures/misc/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
@ -64,6 +64,18 @@ inline void create_channel(Engine* engine, std::string name, NumberSetting& sett
|
||||
}, true));
|
||||
}
|
||||
|
||||
static std::unique_ptr<ImageData> load_icon(const fs::path& resdir) {
|
||||
try {
|
||||
auto file = resdir / fs::u8path("textures/misc/icon.png");
|
||||
if (fs::exists(file)) {
|
||||
return imageio::read(file.u8string());
|
||||
}
|
||||
} catch (const std::exception& err) {
|
||||
logger.error() << "could not load window icon: " << err.what();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Engine::Engine(EngineSettings& settings, SettingsHandler& settingsHandler, EnginePaths* paths)
|
||||
: settings(settings), settingsHandler(settingsHandler), paths(paths),
|
||||
interpreter(std::make_unique<cmd::CommandsInterpreter>())
|
||||
@ -71,10 +83,16 @@ Engine::Engine(EngineSettings& settings, SettingsHandler& settingsHandler, Engin
|
||||
paths->prepare();
|
||||
loadSettings();
|
||||
|
||||
auto resdir = paths->getResources();
|
||||
|
||||
controller = std::make_unique<EngineController>(this);
|
||||
if (Window::initialize(&this->settings.display)){
|
||||
throw initialize_error("could not initialize window");
|
||||
}
|
||||
if (auto icon = load_icon(resdir)) {
|
||||
icon->flipY();
|
||||
Window::setIcon(icon.get());
|
||||
}
|
||||
loadControls();
|
||||
audio::initialize(settings.audio.enabled.get());
|
||||
create_channel(this, "master", settings.audio.volumeMaster);
|
||||
@ -99,8 +117,6 @@ Engine::Engine(EngineSettings& settings, SettingsHandler& settingsHandler, Engin
|
||||
addWorldGenerators();
|
||||
|
||||
scripting::initialize(this);
|
||||
|
||||
auto resdir = paths->getResources();
|
||||
basePacks = files::read_list(resdir/fs::path("config/builtins.list"));
|
||||
}
|
||||
|
||||
@ -171,7 +187,7 @@ void Engine::mainloop() {
|
||||
if (!Window::isIconified()) {
|
||||
renderFrame(batch);
|
||||
}
|
||||
Window::setFramerate(Window::isIconified() ? 20 :
|
||||
Window::setFramerate(!Window::isIconified() ? 20 :
|
||||
settings.display.framerate.get());
|
||||
|
||||
processPostRunnables();
|
||||
|
||||
@ -323,13 +323,13 @@ bool Window::isFullscreen() {
|
||||
}
|
||||
|
||||
void Window::swapBuffers() {
|
||||
glfwSwapBuffers(window);
|
||||
Window::resetScissor();
|
||||
double currentTime = time();
|
||||
if (framerate > 0 && currentTime - prevSwap < (1.0 / framerate)) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(
|
||||
static_cast<int>((1.0/framerate - (currentTime-prevSwap))*1000)));
|
||||
}
|
||||
glfwSwapBuffers(window);
|
||||
Window::resetScissor();
|
||||
prevSwap = time();
|
||||
}
|
||||
|
||||
@ -375,3 +375,12 @@ bool Window::tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor) {
|
||||
workArea.y + (workArea.w - Window::height) / 2 + windowFrame.y / 2);
|
||||
return false;
|
||||
}
|
||||
|
||||
void Window::setIcon(const ImageData* image) {
|
||||
GLFWimage icon {
|
||||
static_cast<int>(image->getWidth()),
|
||||
static_cast<int>(image->getHeight()),
|
||||
image->getData()
|
||||
};
|
||||
glfwSetWindowIcon(window, 1, &icon);
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ public:
|
||||
static const char* getClipboardText();
|
||||
static void setClipboardText(const char* text);
|
||||
static DisplaySettings* getSettings();
|
||||
static void setIcon(const ImageData* image);
|
||||
|
||||
static glm::vec2 size() {
|
||||
return glm::vec2(width, height);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user