From 97e6c498a836cff87876c6835c1bca3ddbc33910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 3 Jan 2018 21:37:42 -0800 Subject: [PATCH] entry: Added drop file event WIP. --- examples/common/entry/entry.cpp | 6 +++ examples/common/entry/entry_p.h | 16 ++++++++ examples/common/entry/entry_windows.cpp | 14 ++++++- tools/texturev/texturev.cpp | 54 ++++++++++++++++--------- 4 files changed, 69 insertions(+), 21 deletions(-) diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index ac4d986e0..ec2d654a6 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -745,6 +745,9 @@ restart: case Event::Suspend: break; + case Event::DropFile: + break; + default: break; } @@ -900,6 +903,9 @@ restart: case Event::Suspend: break; + case Event::DropFile: + break; + default: break; } diff --git a/examples/common/entry/entry_p.h b/examples/common/entry/entry_p.h index db268bc9f..6776610b6 100644 --- a/examples/common/entry/entry_p.h +++ b/examples/common/entry/entry_p.h @@ -9,6 +9,7 @@ #define TINYSTL_ALLOCATOR entry::TinyStlAllocator #include +#include #include "entry.h" @@ -84,6 +85,7 @@ namespace entry Size, Window, Suspend, + DropFile, }; Event(Enum _type) @@ -170,6 +172,13 @@ namespace entry Suspend::Enum m_state; }; + struct DropFileEvent : public Event + { + ENTRY_IMPLEMENT_EVENT(DropFileEvent, Event::DropFile); + + bx::FilePath m_filePath; + }; + const Event* poll(); const Event* poll(WindowHandle _handle); void release(const Event* _event); @@ -276,6 +285,13 @@ namespace entry m_queue.push(ev); } + void postDropFileEvent(WindowHandle _handle, const bx::FilePath& _filePath) + { + DropFileEvent* ev = BX_NEW(getAllocator(), DropFileEvent)(_handle); + ev->m_filePath = _filePath; + m_queue.push(ev); + } + const Event* poll() { return m_queue.pop(); diff --git a/examples/common/entry/entry_windows.cpp b/examples/common/entry/entry_windows.cpp index b69745093..a5258fd63 100644 --- a/examples/common/entry/entry_windows.cpp +++ b/examples/common/entry/entry_windows.cpp @@ -469,7 +469,9 @@ namespace entry RegisterClassExA(&wnd); m_windowAlloc.alloc(); - m_hwnd[0] = CreateWindowA("bgfx" + m_hwnd[0] = CreateWindowExA( + WS_EX_ACCEPTFILES + , "bgfx" , "BGFX" , WS_OVERLAPPEDWINDOW|WS_VISIBLE , 0 @@ -858,6 +860,16 @@ namespace entry } break; + case WM_DROPFILES: + { + HDROP drop = (HDROP)_wparam; + char tmp[bx::kMaxFilePath]; + uint32_t result = DragQueryFileA(drop, 0, tmp, sizeof(tmp) ); + WindowHandle handle = findHandle(_hwnd); + m_eventQueue.postDropFileEvent(handle, tmp); + } + break; + default: break; } diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index f395d11a9..a49ae5bde 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -1472,28 +1472,35 @@ int _main_(int _argc, char** _argv) { if (ImGui::BeginChild("##info", ImVec2(0.0f, 0.0f) ) ) { - ImGui::Text("Dimensions: %d x %d" - , view.m_textureInfo.width - , view.m_textureInfo.height - ); + if (!bgfx::isValid(texture) ) + { + ImGui::Text("Texture is not loaded."); + } + else + { + ImGui::Text("Dimensions: %d x %d" + , view.m_textureInfo.width + , view.m_textureInfo.height + ); - ImGui::Text("Format: %s" - , bimg::getName(bimg::TextureFormat::Enum(view.m_textureInfo.format) ) - ); + ImGui::Text("Format: %s" + , bimg::getName(bimg::TextureFormat::Enum(view.m_textureInfo.format) ) + ); - ImGui::SliderInt("Layer", (int32_t*)&view.m_layer, 0, view.m_textureInfo.numLayers - 1); - ImGui::SliderInt("Mip", (int32_t*)&view.m_mip, 0, view.m_textureInfo.numMips - 1); + ImGui::SliderInt("Layer", (int32_t*)&view.m_layer, 0, view.m_textureInfo.numLayers - 1); + ImGui::SliderInt("Mip", (int32_t*)&view.m_mip, 0, view.m_textureInfo.numMips - 1); - ImGui::Separator(); + ImGui::Separator(); - ImGui::Checkbox("Input linear", &view.m_inLinear); - ImGui::RangeSliderFloat("EV range", &view.m_evMin, &view.m_evMax, kEvMin, kEvMax); - ImGui::SliderFloat("EV", &view.m_ev, view.m_evMin, view.m_evMax); + ImGui::Checkbox("Input linear", &view.m_inLinear); + ImGui::RangeSliderFloat("EV range", &view.m_evMin, &view.m_evMax, kEvMin, kEvMax); + ImGui::SliderFloat("EV", &view.m_ev, view.m_evMin, view.m_evMax); - ImGui::Separator(); + ImGui::Separator(); - ImGui::Checkbox("Fit to window", &view.m_fit); - ImGui::SliderFloat("Scale", &view.m_zoom, 0.01f, 10.0f); + ImGui::Checkbox("Fit to window", &view.m_fit); + ImGui::SliderFloat("Scale", &view.m_zoom, 0.01f, 10.0f); + } ImGui::EndChild(); } @@ -1636,8 +1643,8 @@ int _main_(int _argc, char** _argv) imguiEndFrame(); - if (!bgfx::isValid(texture) - || view.m_fileIndex != fileIndex) + if ( (!bgfx::isValid(texture) || view.m_fileIndex != fileIndex) + && 0 != view.m_fileList.size() ) { if (bgfx::isValid(texture) ) { @@ -1745,7 +1752,7 @@ int _main_(int _argc, char** _argv) , 0 , width , height - , view.m_alpha ? UINT32_MAX : 0 + , view.m_alpha || !bgfx::isValid(texture) ? UINT32_MAX : 0 , float(width )/float(checkerBoardSize) , float(height)/float(checkerBoardSize) ); @@ -1885,7 +1892,14 @@ int _main_(int _argc, char** _argv) } } - bgfx::submit(IMAGE_VIEW_ID, program); + if (bgfx::isValid(texture) ) + { + bgfx::submit(IMAGE_VIEW_ID, program); + } + else + { + bgfx::discard(); + } bgfx::frame(); }