1 module unecht.core.components.editor.ui.dragDropEditor;
2 
3 version(UEIncludeEditor):
4 
5 import unecht.core.object;
6 import unecht.core.component;
7 import unecht.core.components.internal.gui;
8 import unecht.core.entity;
9 
10 import derelict.imgui.imgui;
11 
12 ///
13 final class UEDragDropEditor : UEComponent 
14 {
15     mixin(UERegisterObject!());
16     
17     private static UEObject object;
18     private static bool validDrop;
19 
20     ///
21     public static bool mayStartDrag(UEObject _obj)
22     {
23         if(igIsItemActive() && igIsMouseDragging(0))
24         {
25             object = _obj;
26             return true;
27         }
28         return false;
29     }
30 
31     ///
32     public static void canDrop(TypeInfo _acceptType)
33     {
34         if (igIsItemHoveredRect() && object !is null)
35         {
36             validDrop = true;
37         }
38     }
39 
40     ///
41     public static UEObject isDropped()
42     {
43         if (validDrop && igIsMouseReleased(0))
44         {
45             return object;
46         }
47 
48         return null;
49     }
50     
51     ///
52     public void render()
53     {
54         if(igIsMouseReleased(0) && object !is null)
55             object = null;
56 
57         if(object is null)
58             return;
59 
60         ImVec2 v;
61         igGetMousePos(&v);
62         igSetNextWindowPos(v,ImGuiSetCond_Always);
63         igBegin("drag",null,
64             ImGuiWindowFlags_NoInputs|
65             ImGuiWindowFlags_ShowBorders|
66             ImGuiWindowFlags_AlwaysAutoResize|
67             ImGuiWindowFlags_NoTitleBar);
68 
69         if(validDrop)
70             igPushStyleColor(ImGuiCol_Text, ImVec4(0,1,0,1));
71 
72         UEGui.Text(object.typename);
73 
74         if(validDrop)
75             igPopStyleColor();
76         
77         igEnd();
78 
79         validDrop = false;
80     }
81 }