-
Notifications
You must be signed in to change notification settings - Fork 410
Add file image preview for Graph Editor #2710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4ef6701
9b56362
3fed0c2
fe4478d
40794fb
f0d839d
8aa31fa
6daeef6
eab92f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,8 @@ Graph::Graph(const std::string& materialFilename, | |
| const mx::FileSearchPath& searchPath, | ||
| const mx::FilePathVec& libraryFolders, | ||
| int viewWidth, | ||
| int viewHeight) : | ||
| int viewHeight, | ||
| float previewWidth) : | ||
| _materialFilename(materialFilename), | ||
| _searchPath(searchPath), | ||
| _libraryFolders(libraryFolders), | ||
|
|
@@ -143,6 +144,7 @@ Graph::Graph(const std::string& materialFilename, | |
| _autoLayout(false), | ||
| _frameCount(INT_MIN), | ||
| _fontScale(1.0f), | ||
| _previewSize(previewWidth), | ||
| _saveNodePositions(true) | ||
| { | ||
| loadStandardLibraries(); | ||
|
|
@@ -903,12 +905,60 @@ void Graph::showPropertyEditorValue(UiNodePtr node, mx::InputPtr input, const mx | |
| } | ||
| else if (input->getType() == "filename") | ||
| { | ||
| mx::ValuePtr val = input->getValue(); | ||
| mx::ValuePtr val = input->getResolvedValue(); | ||
|
|
||
| if (val && val->isA<std::string>()) | ||
| { | ||
| std::string prev, temp; | ||
| prev = temp = val->asA<std::string>(); | ||
| mx::FilePath filePath(temp); | ||
|
|
||
| bool drawPreview = _previewSize > 0; | ||
| if (drawPreview) | ||
| { | ||
| float previewSize = _previewSize; | ||
| // Clamp preview size to width of panel | ||
| float panelWidth = ImGui::GetContentRegionAvail().x; | ||
| if (previewSize > panelWidth) | ||
| { | ||
| previewSize = panelWidth; | ||
| } | ||
|
|
||
| ImGui::BeginChild("imagePreview", ImVec2(previewSize, previewSize), false, | ||
| ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); | ||
|
|
||
| // Show image preview if file exists and is an image | ||
| if (!temp.empty()) | ||
| { | ||
| mx::ImageHandlerPtr imageHandler = _renderer ? _renderer->getImageHandler() : nullptr; | ||
| if (imageHandler) | ||
| { | ||
| unsigned int textureId = 0; | ||
| int width = 0, height = 0; | ||
| mx::ImagePtr image = imageHandler->acquireImage(filePath); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will reusage images from the handler's cache if found. |
||
| if (image) | ||
| { | ||
| textureId = image->getResourceId(); | ||
| width = image->getWidth(); | ||
| height = image->getHeight(); | ||
| } | ||
| else | ||
| { | ||
| std::cout << "Image file not loaded: " << temp << std::endl; | ||
| } | ||
| if (textureId) | ||
| { | ||
| float aspect = (height > 0) ? (float)width / (float)height : 1.0f; | ||
| ImVec2 imagePreviewSize(previewSize, previewSize / aspect); | ||
|
|
||
| ImGui::Image((void*)(intptr_t)textureId, imagePreviewSize); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just preview scaling not actual image pixels resizing. |
||
| } | ||
| } | ||
| } | ||
| ImGui::EndChild(); | ||
| //ImGui::PopItemWidth(); | ||
| } | ||
|
|
||
| ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(.15f, .15f, .15f, 1.0f)); | ||
| ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(.2f, .4f, .6f, 1.0f)); | ||
|
|
||
|
|
@@ -923,7 +973,8 @@ void Graph::showPropertyEditorValue(UiNodePtr node, mx::InputPtr input, const mx | |
| } | ||
| ImGui::PopItemWidth(); | ||
| ImGui::SameLine(); | ||
| ImGui::Text("%s", mx::FilePath(temp).getBaseName().c_str()); | ||
| ImGui::Text("%s", filePath.getBaseName().c_str()); | ||
|
|
||
| ImGui::PopStyleColor(); | ||
| ImGui::PopStyleColor(); | ||
|
|
||
|
|
@@ -3382,23 +3433,32 @@ void Graph::propertyEditor() | |
| { | ||
| _currUiNode->setShowAllInputs(showAllInputs); | ||
| } | ||
| bool showOutputsInEditor = _currUiNode->getShowOutputsInEditor(); | ||
| if (ImGui::Checkbox("Show output connections", &showOutputsInEditor)) | ||
|
|
||
| int count = 0; | ||
| float totalImagePadding = 0.0f; | ||
| float imagePadding = 0.0f; | ||
| if (_previewSize > 0.0f) | ||
| { | ||
| _currUiNode->setShowOutputsInEditor(showOutputsInEditor); | ||
| imagePadding = (_previewSize > availableWidth) ? availableWidth : _previewSize; | ||
| } | ||
|
|
||
| int count = 0; | ||
| for (UiPinPtr input : _currUiNode->getInputPins()) | ||
| { | ||
| if (_currUiNode->getShowAllInputs() || (input->getConnected() || _currUiNode->getNode()->getInput(input->getName()))) | ||
| { | ||
| count++; | ||
|
|
||
| // Add space for image previews | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are using a fixed height, we need to take into consideration space for image previews. |
||
| if (imagePadding > 0.0f && input->getInput()->getType() == "filename") | ||
| { | ||
| totalImagePadding += imagePadding; | ||
| } | ||
| } | ||
| } | ||
| if (count) | ||
| { | ||
| ImVec2 tableSize(0.0f, TEXT_BASE_HEIGHT * std::min(SCROLL_LINE_COUNT, count)); | ||
| float baseHeight = TEXT_BASE_HEIGHT * std::min(SCROLL_LINE_COUNT, count); | ||
| ImVec2 tableSize(0.0f, baseHeight + totalImagePadding); | ||
| bool haveTable = ImGui::BeginTable("inputs_node_table", 2, tableFlags, tableSize); | ||
| if (haveTable) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A size of 0 will turn on previews.