main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "../../DFPSR/includeFramework.h"
  2. using namespace dsr;
  3. // Global
  4. const String mediaPath = string_combine(U"media", file_separator());
  5. bool running = true;
  6. // The window handle
  7. Window window;
  8. int main(int argn, char **argv) {
  9. // Create a window
  10. window = window_create(U"GUI example", 1000, 700);
  11. // Load an interface to the window
  12. window_loadInterfaceFromFile(window, mediaPath + U"interface.lof");
  13. // Bind methods to events
  14. window_setCloseEvent(window, []() {
  15. running = false;
  16. });
  17. // Look up components by name
  18. Component buttonA = window_findComponentByName(window, U"buttonA");
  19. Component buttonB = window_findComponentByName(window, U"buttonB");
  20. // Connect components with actions
  21. component_setPressedEvent(buttonA, []() {
  22. printText("Pressed buttonA!\n");
  23. });
  24. component_setPressedEvent(buttonB, []() {
  25. printText("Pressed buttonB!\n");
  26. });
  27. // Execute
  28. while(running) {
  29. // Wait for actions
  30. while (!window_executeEvents(window)) {
  31. time_sleepSeconds(0.01);
  32. }
  33. // Busy loop instead of waiting
  34. //window_executeEvents(window);
  35. // Draw interface
  36. window_drawComponents(window);
  37. // Show the final image
  38. window_showCanvas(window);
  39. }
  40. }