Files
ReWindow/main.cpp
Redacted 8d4db443bd
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m17s
Get rid of the need for SetFlag
2025-01-30 18:48:38 -05:00

94 lines
3.2 KiB
C++

#include <iostream>
#include <ReWindow/types/Window.h>
#if _WIN32
#include <windows.h>
#endif
#include <ReWindow/Logger.h>
using namespace ReWindow;
std::ostream& operator<<(std::ostream& os, const IPair& v) {
return os << "{" << v.x << ", " << v.y << "}";
}
class MyWindow : public OpenGLWindow {
public:
MyWindow(const std::string& title, int w, int h) : OpenGLWindow(title, w, h, 2, 1) {}
void OnMouseMove(const MouseMoveEvent& e) override {}
void OnKeyDown(const KeyDownEvent& e) override {}
void OnRefresh(float elapsed) override {
SwapBuffers();
if (IsMouseButtonDown(MouseButtons::Left))
std::cout << "Left Mouse Button" << std::endl;
if (IsMouseButtonDown(MouseButtons::Right))
std::cout << "Right Mouse Button" << std::endl;
if (IsMouseButtonDown(MouseButtons::Middle))
std::cout << "Middle Mouse Button" << std::endl;
if (IsMouseButtonDown(MouseButtons::Mouse4))
std::cout << "Mouse4 Mouse Button" << std::endl;
if (IsMouseButtonDown(MouseButtons::Mouse5))
std::cout << "Mouse5 Mouse Button" << std::endl;
if (IsKeyDown(Keys::N))
std::cout << "Gotteem" << std::endl;
RWindow::OnRefresh(elapsed);
}
bool OnResizeRequest(const WindowResizeRequestEvent& e) override {
//std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
return true;
}
void OnMouseButtonDown(const MouseButtonDownEvent &e) override
{
//std::cout << "Overload Down: " << e.Button.Mnemonic << std::endl;
RWindow::OnMouseButtonDown(e);
}
void OnMouseButtonUp(const MouseButtonUpEvent &e) override
{
//std::cout << "Overload Up: " << e.Button.Mnemonic << std::endl;
RWindow::OnMouseButtonUp(e);
}
};
int main() {
auto* window = new MyWindow("Test Window", 600, 480);
Logger::Debug(std::format("New window '{}' created. width={} height={}", window->GetTitle(), window->GetWidth(), window->GetHeight()));
if (window->Open())
Logger::Debug(std::format("Opened window '{}'", window->GetTitle()));
Logger::Debug("TODO: Cannot set flags until after window is open");
window->SetFullscreen(false);
window->SetVsyncEnabled(true);
window->SetResizable(true);
window->SetCursorVisible(false);
window->UniqueFunctionNameForMessageBoxBecauseMicrosoftUsesMacros("MessageBox", "Generic message from a ReWindow MessageBox.");
Logger::Debug(std::format("Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} QUIT={}",
window->GetTitle(), window->IsFocused(), window->IsFullscreen(),
window->IsResizable(), window->IsVsyncEnabled(), window->IsClosing()) );
window->OnKeyDownEvent += [&] (KeyDownEvent e) { jlog::Debug(e.key.Mnemonic); };
window->OnMouseButtonDownEvent += [&] (MouseButtonDownEvent e) { jlog::Debug(e.Button.Mnemonic + std::to_string(e.Button.ButtonIndex)); };
window->OnMouseWheelEvent += [&, window] (MouseWheelEvent e) { std::cout << window->GetMouseWheelPersistent() << std::endl; };
while (!window->IsClosing())
window->ManagedRefresh();
delete window;
}