nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
window.cc
Go to the documentation of this file.
1#include "client/window.h"
2
3#include <raylib.h>
4
5#include <memory>
6#include <string>
7
8#include "absl/memory/memory.h"
9#include "absl/status/status.h"
10
11namespace nanommo {
12
13absl::StatusOr<std::unique_ptr<Window>> Window::Create(const std::string& title,
14 int width, int height,
15 Visibility visibility) {
16 SetTraceLogLevel(LOG_WARNING);
17 // Any size the player drags it to, as the interface follows its height.
18 unsigned int flags = FLAG_WINDOW_RESIZABLE;
19#ifndef __EMSCRIPTEN__
20 // A high-DPI screen gets all its pixels. In a browser, raylib draws a
21 // high-DPI canvas into a quarter of it, so the page draws at its own size
22 // and the browser scales it up.
23 flags |= FLAG_WINDOW_HIGHDPI;
24#endif
25 if (visibility == Visibility::kHidden) {
26 flags |= FLAG_WINDOW_HIDDEN;
27 }
28 SetConfigFlags(flags);
29 InitWindow(width, height, title.c_str());
30 if (!IsWindowReady()) {
31 return absl::UnavailableError("couldn't open the window");
32 }
33 // raylib closes the window on Escape. In a game, Escape closes menus.
34 SetExitKey(KEY_NULL);
35 SetTargetFPS(60);
36 return absl::WrapUnique(new Window());
37}
38
39Window::~Window() { CloseWindow(); }
40
41bool Window::ShouldClose() const { return closing_ || WindowShouldClose(); }
42
43void Window::Close() { closing_ = true; }
44
45} // namespace nanommo
static absl::StatusOr< std::unique_ptr< Window > > Create(const std::string &title, int width, int height, Visibility visibility=Visibility::kShown)
Definition window.cc:13
void Close()
Definition window.cc:43
Window(const Window &)=delete
Visibility
raylib needs a window even to draw into a texture, so tests hide theirs.
Definition window.h:14
bool ShouldClose() const
Definition window.cc:41
Definition chat.cc:9