1 module creator.core.input; 2 import creator.core; 3 import inochi2d.core; 4 import inochi2d.math; 5 import bindbc.imgui; 6 7 private { 8 vec2 mpos; 9 ImGuiIO* io; 10 } 11 12 /** 13 Begins a UI input pass 14 */ 15 void incInputBegin() { 16 io = igGetIO(); 17 } 18 19 /** 20 Sets the mouse within the viewport 21 */ 22 void incInputSetViewportMouse(float x, float y) { 23 vec2 camPos = inGetCamera().position; 24 vec2 camScale = inGetCamera().scale; 25 vec2 camCenter = inGetCamera().getCenterOffset(); 26 27 mpos = ( 28 mat4.translation( 29 camPos.x+camCenter.x, 30 camPos.y+camCenter.y, 31 0 32 ) * 33 mat4.scaling( 34 camScale.x, 35 camScale.y, 36 1 37 ).inverse() * 38 mat4.translation( 39 x, 40 y, 41 0 42 ) * 43 vec4(0, 0, 0, 1) 44 ).xy; 45 } 46 47 /** 48 Gets the position of the mouse in the viewport 49 */ 50 vec2 incInputGetMousePosition() { 51 return mpos; 52 } 53 54 /** 55 Gets whether a key is held down 56 */ 57 bool incInputIsKeyDown(ImGuiKey key) { 58 return igIsKeyDown(igGetKeyIndex(key)); 59 } 60 61 /** 62 Gets whether a key is held down 63 */ 64 bool incInputIsKeyUp(ImGuiKey key) { 65 return !incInputIsKeyDown(key); 66 } 67 68 /** 69 Gets whether a key is held down 70 */ 71 bool incInputIsKeyPressed(ImGuiKey key) { 72 return igIsKeyPressed(igGetKeyIndex(key)); 73 }