373 {
374 if (entity.HasComponent<NameComponent>())
375 {
376 auto& name = entity.GetComponent<NameComponent>().Name;
377
378 char buffer[256];
379 memset(buffer, 0, sizeof(buffer));
380 strncpy_s(buffer, sizeof(buffer), name.c_str(), sizeof(buffer));
381 if (ImGui::InputText("##Name", buffer, sizeof(buffer)))
382 {
383 name = std::string(buffer);
384 }
385 }
386
387 ImGui::SameLine();
388 ImGui::PushItemWidth(-1);
389
390 if (ImGui::Button("Add Component"))
391 ImGui::OpenPopup("AddComponent");
392
393 if (ImGui::BeginPopup("AddComponent"))
394 {
396
399
400 ImGui::EndPopup();
401 }
402
403 ImGui::PopItemWidth();
404
406 {
408 glm::vec3 rotation = glm::degrees(component.Rotation);
410 component.Rotation = glm::radians(rotation);
412 });
413
415 {
416 auto& camera = component.Camera;
417
418 ImGui::Checkbox("Primary", &component.Primary);
419
420 const char* projectionTypeStrings[] = { "Perspective", "Orthographic" };
421 const char* currentProjectionTypeString = projectionTypeStrings[(int)camera.GetProjectionType()];
422 if (ImGui::BeginCombo("Projection", currentProjectionTypeString))
423 {
424 for (int i = 0; i < 2; i++)
425 {
426 bool isSelected = currentProjectionTypeString == projectionTypeStrings[i];
427 if (ImGui::Selectable(projectionTypeStrings[i], isSelected))
428 {
429 currentProjectionTypeString = projectionTypeStrings[i];
431 }
432
433 if (isSelected)
434 ImGui::SetItemDefaultFocus();
435 }
436
437 ImGui::EndCombo();
438 }
439
441 {
442 float perspectiveVerticalFov = glm::degrees(camera.GetPerspectiveVerticalFOV());
443 if (ImGui::DragFloat("Vertical FOV", &perspectiveVerticalFov))
444 camera.SetPerspectiveVerticalFOV(glm::radians(perspectiveVerticalFov));
445
446 float perspectiveNear = camera.GetPerspectiveNearClip();
447 if (ImGui::DragFloat("Near", &perspectiveNear))
448 camera.SetPerspectiveNearClip(perspectiveNear);
449
450 float perspectiveFar = camera.GetPerspectiveFarClip();
451 if (ImGui::DragFloat("Far", &perspectiveFar))
452 camera.SetPerspectiveFarClip(perspectiveFar);
453 }
454
456 {
457 float orthoSize = camera.GetOrthographicSize();
458 if (ImGui::DragFloat("Size", &orthoSize))
459 camera.SetOrthographicSize(orthoSize);
460
461 float orthoNear = camera.GetOrthographicNearClip();
462 if (ImGui::DragFloat("Near", &orthoNear))
463 camera.SetOrthographicNearClip(orthoNear);
464
465 float orthoFar = camera.GetOrthographicFarClip();
466 if (ImGui::DragFloat("Far", &orthoFar))
467 camera.SetOrthographicFarClip(orthoFar);
468
469 ImGui::Checkbox("Fixed Aspect Ratio", &component.FixedAspectRatio);
470 }
471 });
472
474 {
475 ImGui::ColorEdit4("Color", glm::value_ptr(component.Color));
476
477
478 ImGui::Checkbox("Texture Enabled", &component.TextureEnabled);
479 ImGui::SameLine();
480
481
482 if (component.Texture)
483 {
484 ImGui::TextUnformatted(component.Texture->GetName().c_str());
485 ImGui::SameLine();
486 if (ImGui::Button("Change Texture"))
487 {
488 std::string filePath =
FileDialogs::OpenFile(
"Image Files (*.png;*.jpg;*.jpeg;*.bmp;*.tga)\0*.png;*.jpg;*.jpeg;*.bmp;*.tga\0All Files (*.*)\0*.*\0");
489 if (!filePath.empty())
490 {
492 if (tex)
493 {
494 component.Texture = tex;
495 component.TextureEnabled = true;
496 }
497 else
498 {
499 VZ_WARN(
"Could not load texture {0}", filePath);
500 }
501 }
502 }
503 ImGui::SameLine();
504 if (ImGui::Button("Clear Texture"))
505 {
506 component.Texture = nullptr;
507 component.TextureEnabled = false;
508 }
509 }
510 else
511 {
512 ImGui::SameLine();
513 if (ImGui::Button("Set Texture"))
514 {
515 std::string filePath =
FileDialogs::OpenFile(
"Image Files (*.png;*.jpg;*.jpeg;*.bmp;*.tga)\0*.png;*.jpg;*.jpeg;*.bmp;*.tga\0All Files (*.*)\0*.*\0");
516 if (!filePath.empty())
517 {
519 if (tex)
520 {
521 component.Texture = tex;
522 component.TextureEnabled = true;
523 }
524 else
525 {
526 VZ_WARN(
"Could not load texture {0}", filePath);
527 }
528 }
529 }
530 }
531
532 ImGui::DragFloat("Tiling Factor", &component.TilingFactor, 0.1f, 0.0f, 100.0f);
533
534 });
535
537 {
538 SubTextureEdit(component.SubTexture->GetTexture()->GetName(), component);
539
540 });
541 }
#define VZ_WARN(...)
warn: indicates a potential issue or important event
Definition Log.h:50
static std::string OpenFile(const char *filter)
Opens a file dialog to select a file to open.
Definition WindowsPlatformUtils.cpp:12
ProjectionType
Definition SceneCamera.h:9
@ Orthographic
Definition SceneCamera.h:9
@ Perspective
Definition SceneCamera.h:9
void DisplayAddComponentEntry(const std::string &entryName)
Definition SceneHierarchyPanel.cpp:545
static Ref< Texture2D > Create(uint32_t width, uint32_t height)
Definition Texture.cpp:10
static void SubTextureEdit(const std::string &label, SubTextureComponent &subTexture)
Definition SceneHierarchyPanel.cpp:297
static void DrawVec3Control(const std::string &label, glm::vec3 &values, float resetValue=0.0f, float columnWidth=100.0f)
Definition SceneHierarchyPanel.cpp:155
static void DrawComponent(const std::string &name, Entity entity, UIFunction uiFunction)
Definition SceneHierarchyPanel.cpp:332