|
|
@@ -19,20 +19,12 @@ bool SushiViewer::create(RequestedContainerInfo &requestedInfo, pika::StaticStri
|
|
|
{
|
|
|
renderer.create(requestedInfo.requestedFBO.fbo);
|
|
|
|
|
|
-
|
|
|
- sushi::SushiUiElement element;
|
|
|
- element.background.color = Colors_Magenta;
|
|
|
- element.transform.absoluteTransformPixelSize({100,100,200,100});
|
|
|
- element.id = 2;
|
|
|
-
|
|
|
- sushiContext.root.allUiElements.push_back(element);
|
|
|
-
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-void displaySushiBackgroundImgui(::sushi::Background &e)
|
|
|
+void SushiViewer::displaySushiBackgroundImgui(::sushi::Background &e, int id)
|
|
|
{
|
|
|
- if (ImGui::BeginChildFrame(11, {0, 100}, true))
|
|
|
+ if (ImGui::BeginChildFrame(id, {0, 100}, true))
|
|
|
{
|
|
|
ImGui::Text("Background element editor");
|
|
|
|
|
|
@@ -43,52 +35,98 @@ void displaySushiBackgroundImgui(::sushi::Background &e)
|
|
|
ImGui::EndChildFrame();
|
|
|
}
|
|
|
|
|
|
-void displaySushiTransformImgui(::sushi::Transform &e)
|
|
|
+void SushiViewer::displaySushiTransformImgui(::sushi::Transform & e, glm::vec4 parent, int id)
|
|
|
{
|
|
|
- if (ImGui::BeginChildFrame(12, {0, 100}, true))
|
|
|
+ if (ImGui::BeginChildFrame(id, {0, 200}, true))
|
|
|
{
|
|
|
+ auto copy = e;
|
|
|
+
|
|
|
ImGui::Text("Transform element editor");
|
|
|
|
|
|
+ ImGui::Combo("Pos type", ©.placementType, "Relative\0Absolute\0");
|
|
|
+ ImGui::Combo("Size type", ©.dimensionsType, "Percentage\0Absolute\0");
|
|
|
+
|
|
|
+ ImGui::DragFloat2("Pos", &e.pos[0]);
|
|
|
+ ImGui::DragFloat2("Size", &e.size[0]);
|
|
|
|
|
|
+ e.changeSettings(copy, parent);
|
|
|
|
|
|
}
|
|
|
ImGui::EndChildFrame();
|
|
|
}
|
|
|
|
|
|
-void displaySushiUiElementImgui(::sushi::SushiUiElement &e)
|
|
|
+void SushiViewer::displaySushiUiElementImgui(::sushi::SushiUiElement &e, glm::vec4 parent, int id)
|
|
|
{
|
|
|
- if (ImGui::BeginChildFrame(13, {0, 500}, true))
|
|
|
+ if (ImGui::BeginChildFrame(id, {0, 500}, true))
|
|
|
{
|
|
|
ImGui::Text("Ui element editor: %s, id: %u", e.name, e.id);
|
|
|
|
|
|
- displaySushiTransformImgui(e.transform);
|
|
|
+ displaySushiTransformImgui(e.transform, parent, id + 1000);
|
|
|
ImGui::Separator();
|
|
|
- displaySushiBackgroundImgui(e.background);
|
|
|
+ displaySushiBackgroundImgui(e.background, id + 500);
|
|
|
|
|
|
}
|
|
|
ImGui::EndChildFrame();
|
|
|
}
|
|
|
|
|
|
-void displaySushiParentElementImgui(::sushi::SushiParent &e)
|
|
|
+void SushiViewer::displaySushiParentElementImgui(::sushi::SushiParent &e, glm::vec4 parent)
|
|
|
{
|
|
|
- if (ImGui::BeginChildFrame(14, {0, 700}, true))
|
|
|
+ if (ImGui::BeginChildFrame(2, {0, 700}, true))
|
|
|
{
|
|
|
ImGui::Text("Parent editor: %s, id: %u", e.name, e.id);
|
|
|
|
|
|
- displaySushiTransformImgui(e.transform);
|
|
|
+ displaySushiTransformImgui(e.transform, parent, 3);
|
|
|
+ ImGui::Separator();
|
|
|
+ displaySushiBackgroundImgui(e.background, 4);
|
|
|
ImGui::Separator();
|
|
|
- displaySushiBackgroundImgui(e.background);
|
|
|
+
|
|
|
+ sushi::Transform transform;
|
|
|
+ transform.relativeTransformPixelSize({10, 10, 100, 100});
|
|
|
+
|
|
|
+ if (ImGui::Button("Add element"))
|
|
|
+ {
|
|
|
+ sushiContext.addElement(e, "New Element", transform, sushi::Background());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ImGui::Button("Add parent"))
|
|
|
+ {
|
|
|
+ sushiContext.addParent(e, "New Parent", transform, sushi::Background({0.5,0.2,0.2,1.f}));
|
|
|
+ }
|
|
|
|
|
|
ImGui::Separator();
|
|
|
+ int id = 30;
|
|
|
for (auto &i : e.allUiElements)
|
|
|
{
|
|
|
- displaySushiUiElementImgui(i);
|
|
|
+ ImGui::PushID(id++);
|
|
|
+ displaySushiUiElementImgui(i, e.outData.absTransform, id+500);
|
|
|
+ ImGui::PopID();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
ImGui::EndChildFrame();
|
|
|
}
|
|
|
|
|
|
+//takes the id of a parent and returns his parent
|
|
|
+sushi::SushiParent *findParentOfParent(sushi::SushiParent &parent, unsigned int id)
|
|
|
+{
|
|
|
+
|
|
|
+ for (auto &i : parent.subElements)
|
|
|
+ {
|
|
|
+ if (i.id == id)
|
|
|
+ {
|
|
|
+ return &parent;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (auto &i : parent.subElements)
|
|
|
+ {
|
|
|
+ auto rez = findParentOfParent(i, id);
|
|
|
+ if (rez) { return rez; }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
void visit(sushi::SushiParent &parent, unsigned int id, sushi::SushiUiElement* &selectedElement,
|
|
|
sushi::SushiParent* &selectedParent
|
|
|
)
|
|
|
@@ -112,6 +150,7 @@ sushi::SushiParent* &selectedParent
|
|
|
for (auto &i : parent.subElements)
|
|
|
{
|
|
|
visit(i, id, selectedElement, selectedParent);
|
|
|
+ if (selectedElement || selectedParent) { break; }
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
@@ -148,6 +187,7 @@ void visitSelect(sushi::SushiParent &parent, unsigned int &id, sushi::SushiUiEle
|
|
|
for (auto &i : parent.subElements)
|
|
|
{
|
|
|
visitSelect(i, id, selectedElement, selectedParent, mousePos);
|
|
|
+ if (selectedElement || selectedParent) { break; }
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
@@ -175,7 +215,6 @@ bool SushiViewer::update(pika::Input input, pika::WindowState windowState, Reque
|
|
|
}
|
|
|
#pragma endregion
|
|
|
|
|
|
-
|
|
|
|
|
|
sushi::SushiUiElement *selectedElement = 0;
|
|
|
sushi::SushiParent *selectedParent = 0;
|
|
|
@@ -208,21 +247,27 @@ bool SushiViewer::update(pika::Input input, pika::WindowState windowState, Reque
|
|
|
//img.elementSelected = glm::clamp(img.elementSelected, -1, (int)(elementsSize - 1));
|
|
|
//
|
|
|
|
|
|
- if (selectedElement)
|
|
|
+
|
|
|
+ if (selectedElement && selectedParent)
|
|
|
{
|
|
|
- if (selectedParent)
|
|
|
+ if (ImGui::Button("Select parent"))
|
|
|
{
|
|
|
- if (ImGui::Button("Select parent"))
|
|
|
- {
|
|
|
- img.elementId = selectedParent->id;
|
|
|
- }
|
|
|
+ img.elementId = selectedParent->id;
|
|
|
}
|
|
|
|
|
|
- displaySushiUiElementImgui(*selectedElement);
|
|
|
+ displaySushiUiElementImgui(*selectedElement, selectedParent->outData.absTransform, 100);
|
|
|
}else
|
|
|
if (selectedParent)
|
|
|
{
|
|
|
- displaySushiParentElementImgui(*selectedParent);
|
|
|
+ auto parentOfParentId = findParentOfParent(sushiContext.root, img.elementId);
|
|
|
+ glm::vec4 parentRect = {0, 0, renderer.windowW, renderer.windowH};
|
|
|
+
|
|
|
+ if (parentOfParentId)
|
|
|
+ {
|
|
|
+ parentRect = parentOfParentId->outData.absTransform;
|
|
|
+ }
|
|
|
+
|
|
|
+ displaySushiParentElementImgui(*selectedParent, parentRect);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -231,6 +276,11 @@ bool SushiViewer::update(pika::Input input, pika::WindowState windowState, Reque
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
+ if (selectedElement)
|
|
|
+ {
|
|
|
+ renderer.renderRectangleOutline(selectedElement->outData.absTransform,
|
|
|
+ {1,0,0,0.5}, 4.0f);
|
|
|
+ }else
|
|
|
if (selectedParent)
|
|
|
{
|
|
|
//todo add alias render box
|
|
|
@@ -238,12 +288,6 @@ bool SushiViewer::update(pika::Input input, pika::WindowState windowState, Reque
|
|
|
{1,0,0,0.5}, 4.0f);
|
|
|
}
|
|
|
|
|
|
- if (selectedElement)
|
|
|
- {
|
|
|
- renderer.renderRectangleOutline(selectedElement->outData.absTransform,
|
|
|
- {1,0,0,0.5}, 4.0f);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
renderer.flush();
|
|
|
|