entry: Added drop file event WIP.

This commit is contained in:
Branimir Karadžić 2018-01-03 21:37:42 -08:00
parent 0f339f7494
commit 97e6c498a8
4 changed files with 69 additions and 21 deletions

View File

@ -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;
}

View File

@ -9,6 +9,7 @@
#define TINYSTL_ALLOCATOR entry::TinyStlAllocator
#include <bx/spscqueue.h>
#include <bx/filepath.h>
#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();

View File

@ -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;
}

View File

@ -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();
}