main.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 
  2. // TODO:
  3. // * A catalogue of SDK examples with images and descriptions loaded automatically from their folder.
  4. // * Offer one-click build and execution of SDK examples on multiple platforms, while explaining how the building works.
  5. // * Let the user browse a file system and select a location for a new or existing project.
  6. #include "../../DFPSR/includeFramework.h"
  7. #include "sound.h"
  8. using namespace dsr;
  9. // Global
  10. bool running = true;
  11. Window window;
  12. Component mainPanel;
  13. Component toolPanel;
  14. String interfaceContent =
  15. UR"QUOTE(
  16. Begin : Panel
  17. Name = "mainPanel"
  18. Solid = 0
  19. Color = 180,180,180
  20. End
  21. )QUOTE";
  22. int boomSound;
  23. DSR_MAIN_CALLER(dsrMain)
  24. void dsrMain(List<String> args) {
  25. // Start sound
  26. sound_initialize();
  27. boomSound = loadSoundFromFile(file_combinePaths(file_getApplicationFolder(), U"Boom.wav"));
  28. // Create a window
  29. window = window_create(U"DFPSR wizard application", 800, 600);
  30. window_loadInterfaceFromString(window, interfaceContent);
  31. // Find components
  32. mainPanel = window_findComponentByName(window, U"mainPanel");
  33. // Bind methods to events
  34. window_setKeyboardEvent(window, [](const KeyboardEvent& event) {
  35. DsrKey key = event.dsrKey;
  36. if (event.keyboardEventType == KeyboardEventType::KeyDown) {
  37. if (key == DsrKey_Escape) {
  38. running = false;
  39. }
  40. }
  41. });
  42. window_setCloseEvent(window, []() {
  43. running = false;
  44. });
  45. // Execute
  46. playSound(boomSound, false, 1.0, 1.0, 0.25); // TODO: Get the initial sound to play.
  47. while(running) {
  48. // Wait for actions so that we don't render until an action has been recieved
  49. // This will save battery on laptops for applications that don't require animation
  50. while (!window_executeEvents(window)) {
  51. time_sleepSeconds(0.01);
  52. }
  53. // Fill the background
  54. AlignedImageRgbaU8 canvas = window_getCanvas(window);
  55. image_fill(canvas, ColorRgbaI32(64, 64, 64, 255));
  56. // Draw interface
  57. window_drawComponents(window);
  58. // Show the final image
  59. window_showCanvas(window);
  60. }
  61. // Close sound
  62. sound_terminate();
  63. }