ui.go (2035B)
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 Update() error 24 Draw() error 25 Layout(outsideWidth, outsideHeight float64) 26 AdjustPosition(x, y float64) (float64, float64) 27 } 28 29 // RegularTermination represents a regular termination. 30 // Run can return this error, and if this error is received, 31 // the game loop should be terminated as soon as possible. 32 var RegularTermination = errors.New("regular termination") 33 34 type UI interface { 35 Run(context UIContext) error 36 RunWithoutMainLoop(context UIContext) 37 38 DeviceScaleFactor() float64 39 IsFocused() bool 40 ScreenSizeInFullscreen() (int, int) 41 ResetForFrame() 42 43 CursorMode() CursorMode 44 SetCursorMode(mode CursorMode) 45 46 IsFullscreen() bool 47 SetFullscreen(fullscreen bool) 48 49 IsRunnableOnUnfocused() bool 50 SetRunnableOnUnfocused(runnableOnUnfocused bool) 51 52 IsVsyncEnabled() bool 53 SetVsyncEnabled(enabled bool) 54 55 IsScreenTransparent() bool 56 SetScreenTransparent(transparent bool) 57 SetInitFocused(focused bool) 58 59 Input() Input 60 Window() Window 61 Graphics() Graphics 62 } 63 64 type Window interface { 65 IsDecorated() bool 66 SetDecorated(decorated bool) 67 68 IsResizable() bool 69 SetResizable(resizable bool) 70 71 Position() (int, int) 72 SetPosition(x, y int) 73 74 Size() (int, int) 75 SetSize(width, height int) 76 77 IsFloating() bool 78 SetFloating(floating bool) 79 80 Maximize() 81 IsMaximized() bool 82 83 Minimize() 84 IsMinimized() bool 85 86 SetIcon(iconImages []image.Image) 87 SetTitle(title string) 88 Restore() 89 }