ui.go (2513B)
1 // Copyright 2019 The Ebiten Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package driver 16 17 import ( 18 "errors" 19 "image" 20 ) 21 22 type UIContext interface { 23 UpdateFrame() error 24 ForceUpdateFrame() error 25 Layout(outsideWidth, outsideHeight float64) 26 27 // AdjustPosition can be called from a different goroutine from Update's or Layout's. 28 AdjustPosition(x, y float64, deviceScaleFactor float64) (float64, float64) 29 } 30 31 // RegularTermination represents a regular termination. 32 // Run can return this error, and if this error is received, 33 // the game loop should be terminated as soon as possible. 34 var RegularTermination = errors.New("regular termination") 35 36 type UI interface { 37 Run(context UIContext) error 38 RunWithoutMainLoop(context UIContext) 39 40 DeviceScaleFactor() float64 41 IsFocused() bool 42 ScreenSizeInFullscreen() (int, int) 43 ResetForFrame() 44 45 CursorMode() CursorMode 46 SetCursorMode(mode CursorMode) 47 48 CursorShape() CursorShape 49 SetCursorShape(shape CursorShape) 50 51 IsFullscreen() bool 52 SetFullscreen(fullscreen bool) 53 54 IsRunnableOnUnfocused() bool 55 SetRunnableOnUnfocused(runnableOnUnfocused bool) 56 57 FPSMode() FPSMode 58 SetFPSMode(mode FPSMode) 59 ScheduleFrame() 60 61 IsScreenTransparent() bool 62 SetScreenTransparent(transparent bool) 63 SetInitFocused(focused bool) 64 65 Input() Input 66 Window() Window 67 Graphics() Graphics 68 } 69 70 type Window interface { 71 IsDecorated() bool 72 SetDecorated(decorated bool) 73 74 IsResizable() bool 75 SetResizable(resizable bool) 76 77 Position() (int, int) 78 SetPosition(x, y int) 79 80 Size() (int, int) 81 SetSize(width, height int) 82 SizeLimits() (minw, minh, maxw, maxh int) 83 SetSizeLimits(minw, minh, maxw, maxh int) 84 85 IsFloating() bool 86 SetFloating(floating bool) 87 88 Maximize() 89 IsMaximized() bool 90 91 Minimize() 92 IsMinimized() bool 93 94 SetIcon(iconImages []image.Image) 95 SetTitle(title string) 96 Restore() 97 98 IsBeingClosed() bool 99 SetClosingHandled(handled bool) 100 IsClosingHandled() bool 101 } 102 103 type FPSMode int 104 105 const ( 106 FPSModeVsyncOn FPSMode = iota 107 FPSModeVsyncOffMaximum 108 FPSModeVsyncOffMinimum 109 )