FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
imgui-java/example/src/main/java/ExampleImNodes.java at main · SpaiR/imgui-java · GitHub
SpaiR
/
imgui-java
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
153
Star
817
Code
Issues
40
Pull requests
12
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
imgui-java
/
example
/
src
/
main
/
java
/
ExampleImNodes.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
120 lines (99 loc) · 4.55 KB
Breadcrumbs
imgui-java
/
example
/
src
/
main
/
java
/
ExampleImNodes.java
Copy path
File metadata and controls
120 lines (99 loc) · 4.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import
imgui
.
extension
.
imnodes
.
ImNodes
;
import
imgui
.
extension
.
imnodes
.
ImNodesContext
;
import
imgui
.
extension
.
imnodes
.
ImNodesEditorContext
;
import
imgui
.
extension
.
imnodes
.
flag
.
ImNodesPinShape
;
import
imgui
.
extension
.
imnodes
.
flag
.
ImNodesMiniMapLocation
;
import
imgui
.
flag
.
ImGuiCond
;
import
imgui
.
flag
.
ImGuiMouseButton
;
import
imgui
.
internal
.
ImGui
;
import
imgui
.
type
.
ImBoolean
;
import
imgui
.
type
.
ImInt
;
import
java
.
awt
.
Desktop
;
import
java
.
net
.
URI
;
public
class
ExampleImNodes
{
private
static
final
String
URL
=
"https://github.com/Nelarius/imnodes/tree/857cc86"
;
private
static
final
ImInt
LINK_A
=
new
ImInt
();
private
static
final
ImInt
LINK_B
=
new
ImInt
();
private
static
ImNodesEditorContext
editorContext
=
null
;
static
{
ImNodes
.
createContext
();
editorContext
=
ImNodes
.
editorContextCreate
();
}
public
static
void
show
(
final
ImBoolean
showImNodesWindow
,
final
Graph
graph
) {
ImGui
.
setNextWindowSize
(
500
,
400
,
ImGuiCond
.
Once
);
ImGui
.
setNextWindowPos
(
ImGui
.
getMainViewport
().
getPosX
() +
100
,
ImGui
.
getMainViewport
().
getPosY
() +
100
,
ImGuiCond
.
Once
);
if
(
ImGui
.
begin
(
"ImNodes Demo"
,
showImNodesWindow
)) {
ImGui
.
text
(
"This a demo graph editor for ImNodes"
);
ImGui
.
alignTextToFramePadding
();
ImGui
.
text
(
"Repo:"
);
ImGui
.
sameLine
();
if
(
ImGui
.
button
(
URL
)) {
try
{
Desktop
.
getDesktop
().
browse
(
new
URI
(
URL
));
}
catch
(
Exception
e
) {
e
.
printStackTrace
();
}
}
ImNodes
.
editorContextSet
(
editorContext
);
ImNodes
.
beginNodeEditor
();
for
(
Graph
.
GraphNode
node
:
graph
.
nodes
.
values
()) {
ImNodes
.
beginNode
(
node
.
nodeId
);
ImNodes
.
beginNodeTitleBar
();
ImGui
.
text
(
node
.
getName
());
ImNodes
.
endNodeTitleBar
();
ImNodes
.
beginInputAttribute
(
node
.
getInputPinId
(),
ImNodesPinShape
.
CircleFilled
);
ImGui
.
text
(
"In"
);
ImNodes
.
endInputAttribute
();
ImGui
.
sameLine
();
ImNodes
.
beginOutputAttribute
(
node
.
getOutputPinId
());
ImGui
.
text
(
"Out"
);
ImNodes
.
endOutputAttribute
();
ImNodes
.
endNode
();
}
int
uniqueLinkId
=
1
;
for
(
Graph
.
GraphNode
node
:
graph
.
nodes
.
values
()) {
if
(
graph
.
nodes
.
containsKey
(
node
.
outputNodeId
)) {
ImNodes
.
link
(
uniqueLinkId
++,
node
.
getOutputPinId
(),
graph
.
nodes
.
get
(
node
.
outputNodeId
).
getInputPinId
());
}
}
final
boolean
isEditorHovered
=
ImNodes
.
isEditorHovered
();
ImNodes
.
miniMap
(
0.2f
,
ImNodesMiniMapLocation
.
BottomRight
);
ImNodes
.
endNodeEditor
();
if
(
ImNodes
.
isLinkCreated
(
LINK_A
,
LINK_B
)) {
final
Graph
.
GraphNode
source
=
graph
.
findByOutput
(
LINK_A
.
get
());
final
Graph
.
GraphNode
target
=
graph
.
findByInput
(
LINK_B
.
get
());
if
(
source
!=
null
&&
target
!=
null
&&
source
.
outputNodeId
!=
target
.
nodeId
) {
source
.
outputNodeId
=
target
.
nodeId
;
}
}
if
(
ImGui
.
isMouseClicked
(
ImGuiMouseButton
.
Right
)) {
final
int
hoveredNode
=
ImNodes
.
getHoveredNode
();
if
(
hoveredNode
!= -
1
) {
ImGui
.
openPopup
(
"node_context"
);
ImGui
.
getStateStorage
().
setInt
(
ImGui
.
getID
(
"delete_node_id"
),
hoveredNode
);
}
else
if
(
isEditorHovered
) {
ImGui
.
openPopup
(
"node_editor_context"
);
}
}
if
(
ImGui
.
isPopupOpen
(
"node_context"
)) {
final
int
targetNode
=
ImGui
.
getStateStorage
().
getInt
(
ImGui
.
getID
(
"delete_node_id"
));
if
(
ImGui
.
beginPopup
(
"node_context"
)) {
if
(
ImGui
.
button
(
"Delete "
+
graph
.
nodes
.
get
(
targetNode
).
getName
())) {
graph
.
nodes
.
remove
(
targetNode
);
ImGui
.
closeCurrentPopup
();
}
ImGui
.
endPopup
();
}
}
if
(
ImGui
.
beginPopup
(
"node_editor_context"
)) {
if
(
ImGui
.
button
(
"Create New Node"
)) {
final
Graph
.
GraphNode
node
=
graph
.
createGraphNode
();
ImNodes
.
setNodeScreenSpacePos
(
node
.
nodeId
,
ImGui
.
getMousePosX
(),
ImGui
.
getMousePosY
());
ImGui
.
closeCurrentPopup
();
}
ImGui
.
endPopup
();
}
}
ImGui
.
end
();
}
}
Back
|
FazBrowse Home
|
New Git URL