github.com/rajveermalviya/gamen@v0.1.2-0.20220930195403-9be15877c1aa/events/callbacks.go (about) 1 package events 2 3 import ( 4 "strconv" 5 6 "github.com/rajveermalviya/gamen/dpi" 7 ) 8 9 type MouseScrollDelta uint8 10 11 const ( 12 MouseScrollDeltaLine MouseScrollDelta = iota 13 MouseScrollDeltaPixel 14 ) 15 16 func (v MouseScrollDelta) String() string { 17 switch v { 18 case MouseScrollDeltaLine: 19 return "Line" 20 case MouseScrollDeltaPixel: 21 return "Pixel" 22 default: 23 return "" 24 } 25 } 26 27 type MouseScrollAxis uint8 28 29 const ( 30 MouseScrollAxisVertical MouseScrollAxis = iota 31 MouseScrollAxisHorizontal 32 ) 33 34 func (v MouseScrollAxis) String() string { 35 switch v { 36 case MouseScrollAxisVertical: 37 return "Vertical" 38 case MouseScrollAxisHorizontal: 39 return "Horizontal" 40 default: 41 return "" 42 } 43 } 44 45 type ModifiersState uint8 46 47 const ( 48 ModifiersStateShift ModifiersState = 1 << iota 49 ModifiersStateCtrl 50 ModifiersStateAlt 51 ModifiersStateLogo 52 ) 53 54 func (v ModifiersState) String() (s string) { 55 if v&ModifiersStateShift != 0 { 56 if s == "" { 57 s += "Shift" 58 } else { 59 s += " Shift" 60 } 61 } 62 if v&ModifiersStateCtrl != 0 { 63 if s == "" { 64 s += "Ctrl" 65 } else { 66 s += " Ctrl" 67 } 68 } 69 if v&ModifiersStateAlt != 0 { 70 if s == "" { 71 s += "Alt" 72 } else { 73 s += " Alt" 74 } 75 } 76 if v&ModifiersStateLogo != 0 { 77 if s == "" { 78 s += "Logo" 79 } else { 80 s += " Logo" 81 } 82 } 83 return 84 } 85 86 type ButtonState uint8 87 88 const ( 89 ButtonStatePressed ButtonState = iota 90 ButtonStateReleased 91 ) 92 93 func (v ButtonState) String() string { 94 switch v { 95 case ButtonStatePressed: 96 return "Pressed" 97 case ButtonStateReleased: 98 return "Released" 99 default: 100 return "" 101 } 102 } 103 104 type MouseButton uint32 105 106 const ( 107 MouseButtonLeft MouseButton = iota 108 MouseButtonRight 109 MouseButtonMiddle 110 ) 111 112 func (v MouseButton) String() string { 113 switch v { 114 case MouseButtonLeft: 115 return "Left" 116 case MouseButtonRight: 117 return "Right" 118 case MouseButtonMiddle: 119 return "Middle" 120 default: 121 return "0x" + strconv.FormatUint(uint64(v), 8) 122 } 123 } 124 125 type TouchPointerID uint8 126 type TouchPhase uint32 127 128 const ( 129 TouchPhaseStarted TouchPhase = iota 130 TouchPhaseMoved 131 TouchPhaseEnded 132 TouchPhaseCancelled 133 ) 134 135 func (v TouchPhase) String() string { 136 switch v { 137 case TouchPhaseStarted: 138 return "Started" 139 case TouchPhaseMoved: 140 return "Moved" 141 case TouchPhaseEnded: 142 return "Ended" 143 case TouchPhaseCancelled: 144 return "Cancelled" 145 default: 146 return "" 147 } 148 } 149 150 type ScanCode uint32 151 152 type ( 153 WindowSurfaceCreatedCallback func() 154 WindowSurfaceDestroyedCallback func() 155 WindowCloseRequestedCallback func() 156 WindowResizedCallback func(physicalWidth, physicalHeight uint32, scaleFactor float64) 157 WindowCursorEnteredCallback func() 158 WindowCursorLeftCallback func() 159 WindowCursorMovedCallback func(physicalX, physicalY float64) 160 WindowMouseScrollCallback func(delta MouseScrollDelta, axis MouseScrollAxis, value float64) 161 WindowMouseInputCallback func(state ButtonState, button MouseButton) 162 WindowFocusedCallback func() 163 WindowUnfocusedCallback func() 164 WindowModifiersChangedCallback func(state ModifiersState) 165 WindowKeyboardInputCallback func(state ButtonState, scanCode ScanCode, virtualKeyCode VirtualKey) 166 WindowReceivedCharacterCallback func(char rune) 167 WindowTouchInputCallback func(phase TouchPhase, location dpi.PhysicalPosition[float64], id TouchPointerID) 168 )