Skip to content

Commit

Permalink
Improve Path UIs (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
ueshita authored Feb 20, 2024
1 parent 186d7de commit af65c56
Show file tree
Hide file tree
Showing 15 changed files with 409 additions and 1,066 deletions.
12 changes: 12 additions & 0 deletions Dev/Cpp/Viewer/GUI/efk.GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,18 @@ bool GUIManager::ImageButtonOriginal(std::shared_ptr<Effekseer::Tool::Image> use
return ImGui::ImageButton(ToImTextureID(user_texture_id), ImVec2(x, y), ImVec2(0, 0), ImVec2(1, 1), 0, ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1));
}

bool GUIManager::IconButton(const char16_t* icon)
{
const auto& style = ImGui::GetStyle();
const float fontSize = ImGui::GetFontSize();
const float frameHeight = ImGui::GetFrameHeight();
const float padding = (frameHeight - fontSize) * 0.5f;
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(padding, style.FramePadding.y));
bool result = ImGui::Button(utf8str<16>(icon), ImVec2(frameHeight, frameHeight));
ImGui::PopStyleVar();
return result;
}

bool GUIManager::Checkbox(const char16_t* label, bool* v)
{
return ImGui::Checkbox(utf8str<256>(label), v);
Expand Down
2 changes: 2 additions & 0 deletions Dev/Cpp/Viewer/GUI/efk.GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ class GUIManager

bool ImageButtonOriginal(std::shared_ptr<Effekseer::Tool::Image> user_texture_id, float x, float y);

bool IconButton(const char16_t* icon);

bool Checkbox(const char16_t* label, bool* v);

bool RadioButton(const char16_t* label, bool active);
Expand Down
14 changes: 14 additions & 0 deletions Dev/Cpp/Viewer/dll_cs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7422,6 +7422,20 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Effekseerfswig_GUIManager_ImageButton
}


SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Effekseerfswig_GUIManager_IconButton___(void * jarg1, void * jarg2) {
unsigned int jresult ;
efk::GUIManager *arg1 = (efk::GUIManager *) 0 ;
char16_t *arg2 = (char16_t *) 0 ;
bool result;

arg1 = (efk::GUIManager *)jarg1;
arg2 = (char16_t *)jarg2;
result = (bool)(arg1)->IconButton((char16_t const *)arg2);
jresult = result;
return jresult;
}


SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Effekseerfswig_GUIManager_Checkbox___(void * jarg1, void * jarg2, bool* jarg3) {
unsigned int jresult ;
efk::GUIManager *arg1 = (efk::GUIManager *) 0 ;
Expand Down
283 changes: 283 additions & 0 deletions Dev/Editor/EffekseerCoreGUI/GUI/BindableComponent/PathBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Effekseer.GUI.BindableComponent
{
class PathBase : Control, IParameterControl
{
protected string id1 = "";
protected string id2 = "";
protected string id_c = "";
protected string id_reset = "";

protected Data.Value.Path binding = null;

protected string filter = "*";
protected FileType fileType = FileType.Other;
protected string filePath = string.Empty;
protected bool isHovered = false;

protected bool isPopupShown = false;

protected Thumbnail thumbnail = null;
public bool EnableUndo { get; set; } = true;

public Data.Value.Path Binding
{
get
{
return binding;
}
set
{
if (binding == value)
{
return;
}

if (value == null)
{
binding.OnChanged -= Binding_OnChanged;
binding = null;
return;
}

binding = value;
binding.OnChanged += Binding_OnChanged;
Read();
}
}

private void Binding_OnChanged(object sender, ChangedValueEventArgs e)
{
Read();
}

public PathBase()
{
id1 = "###" + Manager.GetUniqueID().ToString();
id2 = "###" + Manager.GetUniqueID().ToString();
id_c = "###" + Manager.GetUniqueID().ToString();
id_reset = "###" + Manager.GetUniqueID().ToString();
}

public void SetBinding(object o)
{
var o_ = o as Data.Value.Path;
Binding = o_;
}

public void FixValue()
{
}

public override void OnDisposed()
{
}

public override void OnDropped(string path, ref bool handle)
{
if (isHovered)
{
if (CheckExtension(path))
{
binding.SetAbsolutePath(path);
Read();
}

handle = true;
}
}

public void Dropped(string path)
{
if (CheckExtension(path))
{
binding.SetAbsolutePath(path);
Read();
}
}

public override void Update()
{
isHovered = false;
isPopupShown = false;

if (binding == null) return;

string dd = null;

var size = Manager.NativeManager.GetContentRegionAvail();
float itemSpacing = 4;
float lineHeight = Manager.NativeManager.GetFrameHeight();
float lineSpacing = Manager.NativeManager.GetFrameHeightWithSpacing() - lineHeight;
float imageSize = lineHeight * 2 + lineSpacing;
float buttonSizeX = lineHeight;

float cursorX = Manager.NativeManager.GetCursorPosX();
float cursorY = Manager.NativeManager.GetCursorPosY();

Manager.NativeManager.BeginGroup();

{
if (thumbnail != null && thumbnail.Image != null)
{
Manager.NativeManager.ImageData(thumbnail.Image, imageSize, imageSize);
}
else
{
float x = Manager.NativeManager.GetCursorScreenPosX();
float y = Manager.NativeManager.GetCursorScreenPosY();
Manager.NativeManager.AddRectFilled(x, y, x + imageSize, y + imageSize, 0xff383838, 0, 0);
}
}

{
Manager.NativeManager.SetCursorPosX(cursorX + imageSize + itemSpacing);
Manager.NativeManager.SetCursorPosY(cursorY);

Manager.NativeManager.SetNextItemWidth(size.X - imageSize - buttonSizeX - itemSpacing * 2 - 1);
Manager.NativeManager.InputText(id1, filePath, swig.InputTextFlags.ReadOnly);

if (Manager.NativeManager.IsItemHovered())
{
Manager.NativeManager.SetTooltip(filePath);
}

Manager.NativeManager.SameLine();

Manager.NativeManager.SetCursorPosX(cursorX + size.X - buttonSizeX - 1);
Manager.NativeManager.SetCursorPosY(cursorY);
if (Manager.NativeManager.IconButton(Icons.FileView))
{
btn_load_Click();
}
}

{
Manager.NativeManager.SetCursorPosX(cursorX + imageSize + itemSpacing);
Manager.NativeManager.SetCursorPosY(cursorY + lineHeight + lineSpacing);

UpdateSubParts(size.X - imageSize - buttonSizeX - itemSpacing * 2 - 1);

if (thumbnail != null)
{
Manager.NativeManager.SameLine();

Manager.NativeManager.SetCursorPosX(cursorX + size.X - buttonSizeX - 1);
Manager.NativeManager.SetCursorPosY(cursorY + lineHeight + lineSpacing);

if (Manager.NativeManager.IconButton(Icons.Remove))
{
btn_delete_Click();
}
}
}

Manager.NativeManager.SetCursorPosX(cursorX);
Manager.NativeManager.SetCursorPosY(cursorY + imageSize);

Manager.NativeManager.EndGroup();

Popup();

if (dd == null) dd = DragAndDrops.UpdateFileDst(fileType);
isHovered = isHovered || Manager.NativeManager.IsItemHovered();

if (dd != null)
{
Dropped(dd);
}
}

protected virtual void UpdateSubParts(float width)
{
}

private void btn_load_Click()
{
if (binding == null) return;

var result = swig.FileDialog.OpenDialog(filter, System.IO.Directory.GetCurrentDirectory());

if (!string.IsNullOrEmpty(result))
{
var filepath = result;
binding.SetAbsolutePath(filepath);

LoadFile(filepath, false);

System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(filepath));
}
else
{
return;
}

Read();
}

private void btn_delete_Click()
{
binding.SetAbsolutePath("");
Read();
}

protected void Read()
{
if (binding != null)
{
filePath = binding.GetRelativePath();
UpdateInfo();
}
else
{
filePath = string.Empty;
UpdateInfo();
}
}

protected virtual void LoadFile(string filepath, bool isReloading)
{
}

protected virtual void UpdateInfo()
{
string path = binding.GetAbsolutePath();

if (System.IO.File.Exists(path))
{
thumbnail = ThumbnailManager.Load(path);
if (thumbnail == null)
{
return;
}
}
else
{
thumbnail = null;
}
}

protected virtual bool CheckExtension(string path)
{
var filters = filter.Split(',');
return filters.Any(_ => "." + _ == System.IO.Path.GetExtension(path).ToLower());
}

void Popup()
{
if (isPopupShown) return;

if (Manager.NativeManager.BeginPopupContextItem(id_c))
{
Functions.ShowReset(binding, id_reset);

Manager.NativeManager.EndPopup();

isPopupShown = true;
}
}
}
}
Loading

0 comments on commit af65c56

Please sign in to comment.