1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // TestApp1.cpp : Defines the entry point for the application.
- //
-
- #ifdef _WIN32
- #include "Win32/stdafx.h"
- #endif
-
- #include <DK.h>
-
-
- class TestApp1 : public DKApplication
- {
- DKObject<DKWindow> window;
- public:
- void OnInitialize(void) override
- {
- DKLog("%s", DKGL_FUNCTION_NAME);
- window = DKWindow::Create("DefaultWindow", DKWindow::StyleGenericWindow, this->EventLoop());
- window->Activate();
-
- window->AddEventHandler(this,
- DKFunction([this](const DKWindow::WindowEvent& e)
- {
- DKLog("WindowEvent: %d, origin:(%.1f, %.1f), size:(%.1f x %.1f), content:(%.1f, %.1f), scale:%f",
- e.type,
- e.windowRect.origin.x, e.windowRect.origin.y,
- e.windowRect.size.width, e.windowRect.size.height,
- e.contentRect.size.width, e.contentRect.size.height,
- e.contentScaleFactor);
- if (e.type == DKWindow::WindowEvent::WindowClosed)
- DKApplication::Instance()->Terminate(0);
- }),
- DKFunction([this](const DKWindow::KeyboardEvent& e)
- {
- if (e.type == DKWindow::KeyboardEvent::KeyUp)
- {
- if (e.key == DKVK_ENTER || e.key == DKVK_RETURN)
- {
- window->SetTextInputEnabled(0, !window->IsTextInputEnabled(0));
- DKLog("TextInput: %d", window->IsTextInputEnabled(0));
- }
- else if (e.key == DKVK_ESCAPE)
- {
- window->HoldMouse(0, !window->IsMouseHeld(0));
- DKLog("HoldMouse: %d", window->IsMouseHeld(0));
- }
- }
- DKLog("KeyboardEvent: %d, %ls, %ls",
- e.type,
- (const wchar_t*)DKWindow::GetVKName(e.key),
- (const wchar_t*)e.text);
- }),
- DKFunction([this](const DKWindow::MouseEvent& e)
- {
- if (e.type != DKWindow::MouseEvent::Move || window->IsMouseHeld(0))
- {
- DKLog("MouseEvent: %d, btn:%d, location:%.1f, %.1f, delta:%.1f, %.1f",
- e.type, e.buttonId, e.location.x, e.location.y, e.delta.x, e.delta.y);
- }
- })
- );
- }
- void OnTerminate(void) override
- {
- DKLog("%s", DKGL_FUNCTION_NAME);
- }
- };
-
-
- #ifdef _WIN32
- int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
- _In_opt_ HINSTANCE hPrevInstance,
- _In_ LPWSTR lpCmdLine,
- _In_ int nCmdShow)
- #else
- int main(int argc, const char * argv[])
- #endif
- {
- DKPropertySet::SystemConfig().SetValue("DisableWindowKey", 1LL);
- TestApp1 app;
- DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
- return app.Run();
- }
|