No Description

TestApp1.cpp 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // TestApp1.cpp : Defines the entry point for the application.
  2. //
  3. #ifdef _WIN32
  4. #include "Win32/stdafx.h"
  5. #endif
  6. #include <DK.h>
  7. class TestApp1 : public DKApplication
  8. {
  9. DKObject<DKWindow> window;
  10. public:
  11. void OnInitialize(void) override
  12. {
  13. DKLog("%s", DKGL_FUNCTION_NAME);
  14. window = DKWindow::Create("DefaultWindow");
  15. window->Activate();
  16. window->AddEventHandler(this,
  17. DKFunction([this](const DKWindow::WindowEvent& e)
  18. {
  19. DKLog("WindowEvent: %d, origin:(%.1f, %.1f), size:(%.1f x %.1f), content:(%.1f, %.1f), scale:%f",
  20. e.type,
  21. e.windowRect.origin.x, e.windowRect.origin.y,
  22. e.windowRect.size.width, e.windowRect.size.height,
  23. e.contentRect.size.width, e.contentRect.size.height,
  24. e.contentScaleFactor);
  25. if (e.type == DKWindow::WindowEvent::WindowClosed)
  26. DKApplication::Instance()->Terminate(0);
  27. }),
  28. DKFunction([this](const DKWindow::KeyboardEvent& e)
  29. {
  30. if (e.type == DKWindow::KeyboardEvent::KeyUp)
  31. {
  32. if (e.key == DKVK_ENTER || e.key == DKVK_RETURN)
  33. {
  34. window->SetTextInputEnabled(0, !window->IsTextInputEnabled(0));
  35. DKLog("TextInput: %d", window->IsTextInputEnabled(0));
  36. }
  37. else if (e.key == DKVK_ESCAPE)
  38. {
  39. window->HoldMouse(0, !window->IsMouseHeld(0));
  40. DKLog("HoldMouse: %d", window->IsMouseHeld(0));
  41. }
  42. }
  43. DKLog("KeyboardEvent: %d, %ls, %ls",
  44. e.type,
  45. (const wchar_t*)DKWindow::GetVKName(e.key),
  46. (const wchar_t*)e.text);
  47. }),
  48. DKFunction([this](const DKWindow::MouseEvent& e)
  49. {
  50. if (e.type != DKWindow::MouseEvent::Move || window->IsMouseHeld(0))
  51. {
  52. DKLog("MouseEvent: %d, btn:%d, location:%.1f, %.1f, delta:%.1f, %.1f",
  53. e.type, e.buttonId, e.location.x, e.location.y, e.delta.x, e.delta.y);
  54. }
  55. })
  56. );
  57. }
  58. void OnTerminate(void) override
  59. {
  60. DKLog("%s", DKGL_FUNCTION_NAME);
  61. }
  62. };
  63. #ifdef _WIN32
  64. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  65. _In_opt_ HINSTANCE hPrevInstance,
  66. _In_ LPWSTR lpCmdLine,
  67. _In_ int nCmdShow)
  68. #else
  69. int main(int argc, const char * argv[])
  70. #endif
  71. {
  72. TestApp1 app;
  73. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  74. return app.Run();
  75. }