Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module main;
- import std.c.windows.windows;
- import dsfml.audio;
- import dsfml.graphics;
- import dsfml.window;
- import dsfml.system;
- import std.c.windows.windows;
- import std.stdio;
- import std.conv;
- import std.string;
- pragma(lib, "comdlg32");
- struct OPENFILENAME {
- DWORD lStructSize;
- HWND hwndOwner;
- HINSTANCE hInstance;
- LPCTSTR lpstrFilter;
- LPTSTR lpstrCustomFilter;
- DWORD nMaxCustFilter;
- DWORD nFilterIndex;
- LPTSTR lpstrFile;
- DWORD nMaxFile;
- LPTSTR lpstrFileTitle;
- DWORD nMaxFileTitle;
- LPCTSTR lpstrInitialDir;
- LPCTSTR lpstrTitle;
- DWORD Flags;
- WORD nFileOffset;
- WORD nFileExtension;
- LPCTSTR lpstrDefExt;
- LPARAM lCustData;
- LPOFNHOOKPROC lpfnHook;
- LPCTSTR lpTemplateName;
- }
- extern(Windows) BOOL GetOpenFileNameA(OPENFILENAME*);
- void main()
- {
- auto font = new dsfml.graphics.font.Font();
- font.loadFromFile("arial.ttf");
- auto window = new RenderWindow(VideoMode(1280, 720), "Virtual Soundboard", Window.Style.Titlebar | Window.Style.Close);
- auto bgColor = Color(29, 29, 29, 255);
- auto label = new Text("Uninitialized", font);
- label.setCharacterSize(15);
- label.position(Vector2f(50, 50));
- SoundBuffer buffer = new SoundBuffer();
- while (window.isOpen())
- {
- Event event;
- while(window.pollEvent(event))
- {
- if(event.type == Event.EventType.Closed)
- {
- window.close();
- }
- if(event.type == Event.EventType.MouseButtonReleased)
- {
- if(event.mouseButton.button == 0)
- {
- writeln("finding sound file");
- auto temp = openSoundFile();
- writeln("file found: " ~ temp);
- // if(!buffer.loadFromFile(temp))
- // {
- // writeln("Buffer load failed");
- // return;
- // }
- auto setLabel = temp[(temp.lastIndexOf('\\') + 1)..$].dup;
- writefln("Setting label text to %s", setLabel);
- label.setString(to!(dstring)(setLabel));
- writeln("Label set.");
- }
- }
- }
- window.clear(bgColor);
- window.draw(label);
- window.display();
- }
- }
- auto openSoundFile()
- {
- char[256] filenameBuffer;
- filenameBuffer[0] = 0;
- OPENFILENAME info;
- info.lStructSize = OPENFILENAME.sizeof;
- info.lpstrFilter = "Audio Files\0*.wav;*.ogg\0\0".ptr;
- info.lpstrFile = filenameBuffer.ptr;
- info.nMaxFile = filenameBuffer.length;
- if(GetOpenFileNameA(&info))
- {
- return to!string(filenameBuffer.ptr);
- }
- else return to!string("!!failed");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement