116 lines
2.6 KiB
C++
116 lines
2.6 KiB
C++
#include <iostream>
|
|
#include <rewindow/types/window.h>
|
|
|
|
#if __linux__
|
|
|
|
Vector2 mouse_pos;
|
|
|
|
// TODO: Move to J3ML::LinearAlgebra::Vector2
|
|
std::ostream& operator<<(std::ostream& os, const Vector2& v)
|
|
{
|
|
return os << "{" << v.x << ", " << v.y << "}";
|
|
}
|
|
|
|
class MyWindow : public ReWindow::RWindow
|
|
{
|
|
public:
|
|
MyWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h)
|
|
{}
|
|
|
|
|
|
void OnMouseMove(const ReWindow::MouseMoveEvent& e) override
|
|
{
|
|
|
|
}
|
|
void OnKeyDown(const ReWindow::KeyDownEvent& e) override
|
|
{
|
|
|
|
}
|
|
void OnRefresh(float elapsed) override
|
|
{
|
|
glSwapBuffers();
|
|
auto pos = getCursorPos();
|
|
//std::cout << pos.x << ", " << pos.y << std::endl;
|
|
|
|
if (isKeyDown(Keys::L))
|
|
this->setCursorStyle(ReWindow::Cursors::Pencil);
|
|
else
|
|
this->setCursorStyle(ReWindow::Cursors::Default);
|
|
}
|
|
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override
|
|
{
|
|
std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
|
|
return true;
|
|
}
|
|
};
|
|
|
|
int main() {
|
|
auto* window = new MyWindow("Test Window", 600, 480);
|
|
|
|
window->setRenderer(RenderingAPI::OPENGL);
|
|
window->Open();
|
|
|
|
// TODO: Cannot set flags until after window is open
|
|
// Make this work somehow
|
|
window->setFullscreen(false);
|
|
window->setVsyncEnabled(false);
|
|
window->setResizable(false);
|
|
|
|
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e)
|
|
{
|
|
if (e.key == Keys::LeftArrow)
|
|
{
|
|
std::cout << "Left Arrow Hit" << std::endl;
|
|
}
|
|
};
|
|
|
|
while (window->isAlive()) {
|
|
window->pollEvents();
|
|
window->refresh();
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef WIN32
|
|
|
|
#ifndef UNICODE
|
|
#define UNICODE
|
|
#endif
|
|
|
|
#include <windows.h>
|
|
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|
|
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
|
|
auto* window = new ReWindow::RWindow(hInstance);
|
|
window->setTitle ("Sample Window");
|
|
window->raise ();
|
|
|
|
while (window->pollEvents ()) {
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
switch(uMsg) {
|
|
case WM_DESTROY:
|
|
PostQuitMessage(0);
|
|
return 0;
|
|
case WM_PAINT:
|
|
{
|
|
PAINTSTRUCT ps;
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
// All painting occurs here, between BeginPaint and EndPaint
|
|
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
|
|
EndPaint(hwnd, &ps);
|
|
}
|
|
return 0;
|
|
}
|
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
|
}
|
|
|
|
#endif |