Commit ebf5a917 authored by Johannes Braun's avatar Johannes Braun
Browse files

Fix initialization of inactive renderlayers

parent 5dca3e4f
......@@ -76,7 +76,7 @@ void Editor::updateFromRenderer()
ActiveLayerInfo& info = m_activeRenderLayers.emplace_back();
info.indexInRenderer = i;
info.layerIndex = id;
m_inactiveRenderLayers.erase(m_inactiveRenderLayers.begin() + (id - erased));
m_inactiveRenderLayers.erase(std::remove(m_inactiveRenderLayers.begin(), m_inactiveRenderLayers.end(), id), m_inactiveRenderLayers.end());
++erased;
}
}
......@@ -741,10 +741,12 @@ void Editor::drawRenderingTab()
bool doIncrement = true;
const bool canDelete = static_cast<dino::RenderLayer::Type>(info.layerIndex) !=
dino::RenderLayer::SILHOUETTE;
const bool canMoveBackward = info.indexInRenderer && it > m_activeRenderLayers.begin() && canDelete;
const bool canMoveBackward =
info.indexInRenderer && it > m_activeRenderLayers.begin() && canDelete;
const bool canMoveForward =
info.indexInRenderer && (m_activeRenderLayers.size() != 1 &&
it < std::prev(std::prev(m_activeRenderLayers.end())) && canDelete);
info.indexInRenderer &&
(m_activeRenderLayers.size() != 1 &&
it < std::prev(std::prev(m_activeRenderLayers.end())) && canDelete);
if(!canDelete)
{
......@@ -757,11 +759,12 @@ void Editor::drawRenderingTab()
{
if(info.indexInRenderer)
m_renderer->removeRenderLayer(*info.indexInRenderer);
const auto id = it->indexInRenderer ? *it->indexInRenderer : std::numeric_limits<uint32_t>::max();
it = m_activeRenderLayers.erase(it);
for (auto& rl : m_activeRenderLayers)
if (rl.indexInRenderer && *rl.indexInRenderer > id)
--*rl.indexInRenderer;
const auto id = it->indexInRenderer ? *it->indexInRenderer
: std::numeric_limits<uint32_t>::max();
it = m_activeRenderLayers.erase(it);
for(auto& rl : m_activeRenderLayers)
if(rl.indexInRenderer && *rl.indexInRenderer > id)
--*rl.indexInRenderer;
doIncrement = false;
}
if(!canDelete)
......@@ -809,83 +812,93 @@ void Editor::drawRenderingTab()
ImGui::PopItemFlag();
ImGui::PopStyleVar();
}
const float btnHeight = ImGui::GetItemsLineHeightWithSpacing();
const float btnHeight = ImGui::GetItemsLineHeightWithSpacing();
ImGui::SameLine();
ImGui::Selectable(layerNames[info.layerIndex]);
if((canMoveBackward || canMoveForward) && ImGui::IsItemHovered() && !m_layerDragState.dragging)
{
if (glfwGetMouseButton(*m_window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
{
m_layerDragState.dragging = true;
m_layerDragState.draggedLayer = std::distance(m_activeRenderLayers.begin(), it);
m_layerDragState.lastItemDelta = 0;
m_layerDragState.dragStart = ImGui::GetMousePos();
m_layerDragState.itemHeight = btnHeight;
m_layerDragState.ydelta = m_layerDragState.dragStart.y - ImGui::GetItemRectMin().y;
}
}
if((canMoveBackward || canMoveForward) && ImGui::IsItemHovered() &&
!m_layerDragState.dragging)
{
if(glfwGetMouseButton(*m_window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
{
m_layerDragState.dragging = true;
m_layerDragState.draggedLayer = std::distance(m_activeRenderLayers.begin(), it);
m_layerDragState.lastItemDelta = 0;
m_layerDragState.dragStart = ImGui::GetMousePos();
m_layerDragState.itemHeight = btnHeight;
m_layerDragState.ydelta = m_layerDragState.dragStart.y - ImGui::GetItemRectMin().y;
}
}
if(doIncrement)
++it;
}
if (m_layerDragState.dragging)
{
const float delta = ImGui::GetMousePos().y - m_layerDragState.dragStart.y;
const int deltaItem = std::clamp<int>(m_layerDragState.draggedLayer + static_cast<int>(delta / m_layerDragState.itemHeight), 0, m_renderer->getRenderLayers().size() - 2) - m_layerDragState.draggedLayer;
std::cout << deltaItem << '\n';
if (m_layerDragState.lastItemDelta != deltaItem)
{
auto startItRot = m_activeRenderLayers.begin() + (m_layerDragState.draggedLayer + m_layerDragState.lastItemDelta);
auto endItRot = m_activeRenderLayers.begin() + (m_layerDragState.draggedLayer + deltaItem);
while (startItRot != endItRot)
{
if (startItRot > endItRot)
{
std::iter_swap(startItRot, std::prev(startItRot));
startItRot = std::prev(startItRot);
}
else
{
std::iter_swap(startItRot, std::next(startItRot));
startItRot = std::next(startItRot);
}
}
m_layerDragState.lastItemDelta = deltaItem;
}
if (glfwGetMouseButton(*m_window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_RELEASE)
{
auto startIt = m_activeRenderLayers.begin() + m_layerDragState.draggedLayer;
auto endIt = m_activeRenderLayers.begin() + (m_layerDragState.draggedLayer + deltaItem);
// Fix position;
int offset = 0;
while (startIt != endIt)
{
if (startIt > endIt)
{
std::swap(endIt->indexInRenderer, std::next(endIt)->indexInRenderer);
m_renderer->swapLayers(m_layerDragState.draggedLayer - offset, m_layerDragState.draggedLayer - offset - 1);
endIt = std::next(endIt);
}
else
{
std::swap(endIt->indexInRenderer, std::prev(endIt)->indexInRenderer);
m_renderer->swapLayers(m_layerDragState.draggedLayer + offset, m_layerDragState.draggedLayer + offset + 1);
endIt = std::prev(endIt);
}
++offset;
}
m_layerDragState.dragging = false;
m_layerDragState.draggedLayer = 0;
m_layerDragState.dragStart = ImVec2(0, 0);
m_layerDragState.itemHeight = 0;
}
}
if(m_layerDragState.dragging)
{
const float delta = ImGui::GetMousePos().y - m_layerDragState.dragStart.y;
const int deltaItem =
std::clamp<int>(m_layerDragState.draggedLayer +
static_cast<int>(delta / m_layerDragState.itemHeight),
0,
m_renderer->getRenderLayers().size() - 2) -
m_layerDragState.draggedLayer;
std::cout << deltaItem << '\n';
if(m_layerDragState.lastItemDelta != deltaItem)
{
auto startItRot = m_activeRenderLayers.begin() +
(m_layerDragState.draggedLayer + m_layerDragState.lastItemDelta);
auto endItRot =
m_activeRenderLayers.begin() + (m_layerDragState.draggedLayer + deltaItem);
while(startItRot != endItRot)
{
if(startItRot > endItRot)
{
std::iter_swap(startItRot, std::prev(startItRot));
startItRot = std::prev(startItRot);
}
else
{
std::iter_swap(startItRot, std::next(startItRot));
startItRot = std::next(startItRot);
}
}
m_layerDragState.lastItemDelta = deltaItem;
}
if(glfwGetMouseButton(*m_window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_RELEASE)
{
auto startIt = m_activeRenderLayers.begin() + m_layerDragState.draggedLayer;
auto endIt = m_activeRenderLayers.begin() + (m_layerDragState.draggedLayer + deltaItem);
// Fix position;
int offset = 0;
while(startIt != endIt)
{
if(startIt > endIt)
{
std::swap(endIt->indexInRenderer, std::next(endIt)->indexInRenderer);
m_renderer->swapLayers(m_layerDragState.draggedLayer - offset,
m_layerDragState.draggedLayer - offset - 1);
endIt = std::next(endIt);
}
else
{
std::swap(endIt->indexInRenderer, std::prev(endIt)->indexInRenderer);
m_renderer->swapLayers(m_layerDragState.draggedLayer + offset,
m_layerDragState.draggedLayer + offset + 1);
endIt = std::prev(endIt);
}
++offset;
}
m_layerDragState.dragging = false;
m_layerDragState.draggedLayer = 0;
m_layerDragState.dragStart = ImVec2(0, 0);
m_layerDragState.itemHeight = 0;
}
}
ImGui::PopStyleColor();
}
......@@ -926,6 +939,9 @@ void Editor::drawSettings()
glfwGetFramebufferSize(*m_window, &w, &h);
glBlitNamedFramebuffer(
0, m_previewFramebuffer->id(), 0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
ImGui::SetNextWindowSize(ImVec2(250, h - m_menuBarHeight));
ImGui::SetNextWindowPos(ImVec2(0, m_menuBarHeight));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
......@@ -1300,7 +1316,7 @@ void Editor::drawMenuBar()
ImGui::EndMenu();
}
drawTimer();
m_menuBarHeight = ImGui::GetWindowSize().y;
ImGui::EndMainMenuBar();
}
}
......
......@@ -75,21 +75,21 @@ private:
bool editorShown() const;
struct ActiveLayerInfo
{
uint32_t layerIndex;
std::optional<uint32_t> indexInRenderer;
};
struct ActiveLayerInfo
{
uint32_t layerIndex;
std::optional<uint32_t> indexInRenderer;
};
struct DragState
{
bool dragging = false;
uint32_t draggedLayer = 0;
uint32_t lastItemDelta = 0;
float ydelta = 0;
ImVec2 dragStart = ImVec2(0, 0);
float itemHeight = 0;
};
struct DragState
{
bool dragging = false;
uint32_t draggedLayer = 0;
uint32_t lastItemDelta = 0;
float ydelta = 0;
ImVec2 dragStart = ImVec2(0, 0);
float itemHeight = 0;
};
void prepareTextures();
const dino::Texture* m_stipplingTexture;
......@@ -99,29 +99,30 @@ private:
dino::TextureResource m_textureResourceHatching;
dino::TextureResource m_textureResourceBrick;
bool m_mainFocussed = false;
float m_previewScale = 200.f;
float m_windowAspect = 9.f / 16.f;
float m_lastTime;
float m_lastFrameTime = 0;
float m_accTime;
int m_nFrames;
std::unique_ptr<dino::FrameBuffer> m_previewFramebuffer;
std::shared_ptr<dino::Texture> m_previewTexture;
std::shared_ptr<Window> m_window = nullptr;
std::shared_ptr<Renderer> m_renderer;
std::unique_ptr<Window> m_editorWindow;
std::set<uint32_t> m_selectedFieldIndices;
std::set<uint32_t> m_selectedLightIndices;
std::vector<uint32_t> m_selectedLightIds;
std::vector<std::optional<uint32_t>> m_allFieldIds;
std::vector<uint32_t> m_allLightIds;
std::optional<uint32_t> m_activeFieldIndex = std::nullopt;
std::optional<uint32_t> m_activeLightIndex = std::nullopt;
bool m_mainFocussed = false;
float m_previewScale = 200.f;
float m_windowAspect = 9.f / 16.f;
float m_lastTime;
float m_lastFrameTime = 0;
float m_accTime;
float m_menuBarHeight = 0;
int m_nFrames;
std::unique_ptr<dino::FrameBuffer> m_previewFramebuffer;
std::shared_ptr<dino::Texture> m_previewTexture;
std::shared_ptr<Window> m_window = nullptr;
std::shared_ptr<Renderer> m_renderer;
std::unique_ptr<Window> m_editorWindow;
std::set<uint32_t> m_selectedFieldIndices;
std::set<uint32_t> m_selectedLightIndices;
std::vector<uint32_t> m_selectedLightIds;
std::vector<std::optional<uint32_t>> m_allFieldIds;
std::vector<uint32_t> m_allLightIds;
std::optional<uint32_t> m_activeFieldIndex = std::nullopt;
std::optional<uint32_t> m_activeLightIndex = std::nullopt;
DragState m_layerDragState;
std::vector<ActiveLayerInfo> m_activeRenderLayers;
std::vector<uint32_t> m_inactiveRenderLayers;
DragState m_layerDragState;
std::vector<ActiveLayerInfo> m_activeRenderLayers;
std::vector<uint32_t> m_inactiveRenderLayers;
std::vector<std::unique_ptr<Blueprints>> m_blueprints;
KeyboardButton m_ctrlC = KeyboardButton(GLFW_KEY_C, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlV = KeyboardButton(GLFW_KEY_V, GLFW_KEY_LEFT_CONTROL);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment