101 lines
2.3 KiB
C++
101 lines
2.3 KiB
C++
#include <iostream>
|
|
#include "include/rewindow/types/window.h"
|
|
|
|
#if __linux__
|
|
|
|
void KeyDown(KeyDownEvent e)
|
|
{
|
|
std::cout << e.key.CharCode << " pressed" << std::endl;
|
|
}
|
|
|
|
int main() {
|
|
auto* window = new RWindow();
|
|
window->init(RenderingAPI::OPENGL, "name",100,100, true);
|
|
window->setFlag(RWindowFlags::RESIZABLE, false);
|
|
|
|
window->onKeyboardPress += KeyDown;
|
|
window->onKeyboardRelease += [&](KeyUpEvent e)
|
|
{
|
|
if (e.key == Keys::F)
|
|
window->setFullscreen(!window->isFullscreen());
|
|
};
|
|
|
|
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 RWindow();
|
|
window->init(RenderingAPI::OPENGL, "mame", 100, 100);
|
|
window->setFlag
|
|
|
|
// Register the window class.
|
|
const wchar_t CLASS_NAME[] = L"Sample Window Class";
|
|
|
|
WNDCLASS wc = { };
|
|
wc.lpfnWndProc = WindowProc;
|
|
wc.hInstance = hInstance;
|
|
wc.lpszClassName = CLASS_NAME;
|
|
|
|
RegisterClass(&wc);
|
|
|
|
// Create the window.
|
|
HWND hwnd = CreateWindowEx(
|
|
0,
|
|
CLASS_NAME,
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
NULL, // Parent Window
|
|
NULL, // Menu
|
|
hInstance, // Instancehandle
|
|
NULL
|
|
);
|
|
if (hwnd == NULL)
|
|
return 0;
|
|
|
|
ShowWindow(hwnd, nCmdShow);
|
|
|
|
// Run the message loop
|
|
MSG msg = {};
|
|
while (GetMessage(&msg, NULL, 0, 0) > 0)
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
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 |