Nav apraksta

TestApp1.cpp 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. DKWindow::WindowCallback cb = {};
  15. cb.filesDropped = DKFunction([](DKWindow*, const DKPoint&, const DKWindow::WindowCallback::StringArray&) {
  16. DKLog("cb.filesDropped");
  17. });
  18. window = DKWindow::Create("DefaultWindow",
  19. DKWindow::StyleGenericWindow|DKWindow::StyleAcceptFileDrop,
  20. this->EventLoop(),
  21. cb);
  22. window->Activate();
  23. window->AddEventHandler(this,
  24. DKFunction([this](const DKWindow::WindowEvent& e)
  25. {
  26. DKLog("WindowEvent: %d, origin:(%.1f, %.1f), size:(%.1f x %.1f), content:(%.1f, %.1f), scale:%f",
  27. e.type,
  28. e.windowRect.origin.x, e.windowRect.origin.y,
  29. e.windowRect.size.width, e.windowRect.size.height,
  30. e.contentRect.size.width, e.contentRect.size.height,
  31. e.contentScaleFactor);
  32. if (e.type == DKWindow::WindowEvent::WindowClosed)
  33. DKApplication::Instance()->Terminate(0);
  34. }),
  35. DKFunction([this](const DKWindow::KeyboardEvent& e)
  36. {
  37. if (e.type == DKWindow::KeyboardEvent::KeyUp)
  38. {
  39. if (e.key == DKVK_ENTER || e.key == DKVK_RETURN)
  40. {
  41. window->SetTextInputEnabled(0, !window->IsTextInputEnabled(0));
  42. DKLog("TextInput: %d", window->IsTextInputEnabled(0));
  43. }
  44. else if (e.key == DKVK_ESCAPE)
  45. {
  46. window->HoldMouse(0, !window->IsMouseHeld(0));
  47. DKLog("HoldMouse: %d", window->IsMouseHeld(0));
  48. }
  49. }
  50. DKLog("KeyboardEvent: %d, %ls, %ls",
  51. e.type,
  52. (const wchar_t*)DKWindow::GetVKName(e.key),
  53. (const wchar_t*)e.text);
  54. }),
  55. DKFunction([this](const DKWindow::MouseEvent& e)
  56. {
  57. if (e.type != DKWindow::MouseEvent::Move || window->IsMouseHeld(0))
  58. {
  59. DKLog("MouseEvent: %d, btn:%d, location:%.1f, %.1f, delta:%.1f, %.1f",
  60. e.type, e.buttonId, e.location.x, e.location.y, e.delta.x, e.delta.y);
  61. }
  62. })
  63. );
  64. }
  65. void OnTerminate(void) override
  66. {
  67. DKLog("%s", DKGL_FUNCTION_NAME);
  68. }
  69. };
  70. #ifdef _WIN32
  71. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  72. _In_opt_ HINSTANCE hPrevInstance,
  73. _In_ LPWSTR lpCmdLine,
  74. _In_ int nCmdShow)
  75. #else
  76. int main(int argc, const char * argv[])
  77. #endif
  78. {
  79. DKPropertySet::SystemConfig().SetValue("DisableWindowKey", 1LL);
  80. TestApp1 app;
  81. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  82. return app.Run();
  83. }