Advertisement
Guest User

Loading Fixes

a guest
Dec 24th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.49 KB | None | 0 0
  1. module main;
  2.  
  3. import std.c.windows.windows;
  4.  
  5. import dsfml.audio;
  6. import dsfml.graphics;
  7. import dsfml.window;
  8. import dsfml.system;
  9.  
  10. import std.c.windows.windows;
  11. import std.stdio;
  12. import std.conv;
  13. import std.string;
  14.  
  15. pragma(lib, "comdlg32");
  16.  
  17. struct OPENFILENAME {
  18.     DWORD         lStructSize;
  19.     HWND          hwndOwner;
  20.     HINSTANCE     hInstance;
  21.     LPCTSTR       lpstrFilter;
  22.     LPTSTR        lpstrCustomFilter;
  23.     DWORD         nMaxCustFilter;
  24.     DWORD         nFilterIndex;
  25.     LPTSTR        lpstrFile;
  26.     DWORD         nMaxFile;
  27.     LPTSTR        lpstrFileTitle;
  28.     DWORD         nMaxFileTitle;
  29.     LPCTSTR       lpstrInitialDir;
  30.     LPCTSTR       lpstrTitle;
  31.     DWORD         Flags;
  32.     WORD          nFileOffset;
  33.     WORD          nFileExtension;
  34.     LPCTSTR       lpstrDefExt;
  35.     LPARAM        lCustData;
  36.     LPOFNHOOKPROC lpfnHook;
  37.     LPCTSTR       lpTemplateName;
  38. }
  39.  
  40. extern(Windows) BOOL GetOpenFileNameA(OPENFILENAME*);
  41.  
  42. void main()
  43. {
  44.     auto font = new dsfml.graphics.font.Font();
  45.     font.loadFromFile("arial.ttf");
  46.     auto window = new RenderWindow(VideoMode(1280, 720), "Virtual Soundboard", Window.Style.Titlebar | Window.Style.Close);
  47.    
  48.     auto bgColor = Color(29, 29, 29, 255);
  49.    
  50.     auto label = new Text("Uninitialized", font);
  51.     label.setCharacterSize(15);
  52.     label.position(Vector2f(50, 50));
  53.  
  54.     SoundBuffer buffer = new SoundBuffer();
  55.    
  56.     while (window.isOpen())
  57.     {
  58.         Event event;
  59.        
  60.         while(window.pollEvent(event))
  61.         {
  62.             if(event.type == Event.EventType.Closed)
  63.             {
  64.                 window.close();
  65.             }
  66.             if(event.type == Event.EventType.MouseButtonReleased)
  67.             {
  68.                 if(event.mouseButton.button == 0)
  69.                 {
  70.                     writeln("finding sound file");
  71.                     auto temp = openSoundFile();
  72.                     writeln("file found: " ~ temp);
  73. //                  if(!buffer.loadFromFile(temp))
  74. //                  {
  75. //                      writeln("Buffer load failed");
  76. //                      return;
  77. //                  }
  78.                     auto setLabel = temp[(temp.lastIndexOf('\\') + 1)..$].dup;
  79.                     writefln("Setting label text to %s", setLabel);
  80.                     label.setString(to!(dstring)(setLabel));
  81.                     writeln("Label set.");
  82.                 }
  83.             }
  84.         }
  85.        
  86.         window.clear(bgColor);
  87.         window.draw(label);
  88.        
  89.         window.display();
  90.     }
  91. }
  92.  
  93. auto openSoundFile()
  94. {
  95.     char[256] filenameBuffer;
  96.     filenameBuffer[0] = 0;
  97.     OPENFILENAME info;
  98.     info.lStructSize = OPENFILENAME.sizeof;
  99.     info.lpstrFilter = "Audio Files\0*.wav;*.ogg\0\0".ptr;
  100.     info.lpstrFile = filenameBuffer.ptr;
  101.     info.nMaxFile = filenameBuffer.length;
  102.     if(GetOpenFileNameA(&info))
  103.     {
  104.         return to!string(filenameBuffer.ptr);
  105.     }
  106.     else return to!string("!!failed");
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement