Remove window dependency from PipGui
PiperOrigin-RevId: 901115560 Change-Id: I85183a91fd07682f17f43fcfad593dececdde28c
This commit is contained in:
committed by
Copybara-Service
parent
506aa79ad8
commit
f91ce9a627
@@ -20,16 +20,14 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
#include "experimental/platform/hal/renderer.h"
|
#include "experimental/platform/hal/renderer.h"
|
||||||
#include "experimental/platform/hal/window.h"
|
|
||||||
#include "experimental/platform/ux/imgui_widgets.h"
|
#include "experimental/platform/ux/imgui_widgets.h"
|
||||||
|
|
||||||
namespace mujoco::platform {
|
namespace mujoco::platform {
|
||||||
|
|
||||||
// Returns false if the user requests that this picture-in-picture widget be
|
// Returns false if the user requests that this picture-in-picture widget be
|
||||||
// removed from the GUI.
|
// removed from the GUI.
|
||||||
static bool PipGuiImpl(const mjModel* model, mjData* data,
|
static bool PipGuiImpl(const mjModel* model, mjData* data, float aspect_ratio,
|
||||||
platform::Window* window, platform::Renderer* renderer,
|
platform::Renderer* renderer, PipState* pip) {
|
||||||
PipState* pip) {
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
auto get_camera_name = [model](int i) -> const char* {
|
auto get_camera_name = [model](int i) -> const char* {
|
||||||
@@ -41,7 +39,7 @@ static bool PipGuiImpl(const mjModel* model, mjData* data,
|
|||||||
};
|
};
|
||||||
|
|
||||||
const int width = ImGui::GetContentRegionAvail().x;
|
const int width = ImGui::GetContentRegionAvail().x;
|
||||||
const int height = width / window->GetAspectRatio();
|
const int height = aspect_ratio != 0.f ? width / aspect_ratio : width;
|
||||||
std::vector<std::byte> output(width * height * 3);
|
std::vector<std::byte> output(width * height * 3);
|
||||||
|
|
||||||
const int combo_width = (width - 30) / 2;
|
const int combo_width = (width - 30) / 2;
|
||||||
@@ -97,7 +95,7 @@ static bool PipGuiImpl(const mjModel* model, mjData* data,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipGui(const mjModel* model, mjData* data, platform::Window* window,
|
void PipGui(const mjModel* model, mjData* data, float aspect_ratio,
|
||||||
platform::Renderer* renderer, std::vector<PipState>* pips) {
|
platform::Renderer* renderer, std::vector<PipState>* pips) {
|
||||||
if (pips->empty()) {
|
if (pips->empty()) {
|
||||||
pips->emplace_back();
|
pips->emplace_back();
|
||||||
@@ -106,7 +104,7 @@ void PipGui(const mjModel* model, mjData* data, platform::Window* window,
|
|||||||
std::vector<int> to_delete;
|
std::vector<int> to_delete;
|
||||||
for (int i = 0; i < pips->size(); ++i) {
|
for (int i = 0; i < pips->size(); ++i) {
|
||||||
PipState& pip = pips->at(i);
|
PipState& pip = pips->at(i);
|
||||||
if (PipGuiImpl(model, data, window, renderer, &pip) == false) {
|
if (PipGuiImpl(model, data, aspect_ratio, renderer, &pip) == false) {
|
||||||
to_delete.push_back(i);
|
to_delete.push_back(i);
|
||||||
};
|
};
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
#include "experimental/platform/hal/renderer.h"
|
#include "experimental/platform/hal/renderer.h"
|
||||||
#include "experimental/platform/hal/window.h"
|
|
||||||
|
|
||||||
namespace mujoco::platform {
|
namespace mujoco::platform {
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ struct PipState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Renders the GUI for a set of picture-in-picture widgets.
|
// Renders the GUI for a set of picture-in-picture widgets.
|
||||||
void PipGui(const mjModel* model, mjData* data, platform::Window* window,
|
void PipGui(const mjModel* model, mjData* data, float aspect_ratio,
|
||||||
platform::Renderer* renderer, std::vector<PipState>* pips);
|
platform::Renderer* renderer, std::vector<PipState>* pips);
|
||||||
|
|
||||||
} // namespace mujoco::platform
|
} // namespace mujoco::platform
|
||||||
|
|||||||
@@ -902,7 +902,8 @@ void App::BuildGui() {
|
|||||||
|
|
||||||
if (tmp_.picture_in_picture) {
|
if (tmp_.picture_in_picture) {
|
||||||
if (ImGui::Begin("Picture-in-Picture", &tmp_.picture_in_picture)) {
|
if (ImGui::Begin("Picture-in-Picture", &tmp_.picture_in_picture)) {
|
||||||
PipGui(model(), data(), window_.get(), renderer_.get(), &tmp_.pips);
|
platform::PipGui(model(), data(), window_->GetAspectRatio(),
|
||||||
|
renderer_.get(), &tmp_.pips);
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user