@@ -36,25 +36,6 @@ const (
36
36
)
37
37
38
38
// parseAndApply converts MasterWindowFlags to appropriate glfwbackend.GLFWWindowFlags.
39
- func (m MasterWindowFlags ) parseAndApply (b backend.Backend [glfwbackend.GLFWWindowFlags ]) {
40
- data := map [MasterWindowFlags ]struct {
41
- f glfwbackend.GLFWWindowFlags
42
- value int // value isn't always true (sometimes false). Also WindowHint takes int not bool
43
- }{
44
- MasterWindowFlagsNotResizable : {glfwbackend .GLFWWindowFlagsResizable , 0 },
45
- MasterWindowFlagsMaximized : {glfwbackend .GLFWWindowFlagsMaximized , 1 },
46
- MasterWindowFlagsFloating : {glfwbackend .GLFWWindowFlagsFloating , 1 },
47
- MasterWindowFlagsFrameless : {glfwbackend .GLFWWindowFlagsDecorated , 0 },
48
- MasterWindowFlagsTransparent : {glfwbackend .GLFWWindowFlagsTransparent , 1 },
49
- MasterWindowFlagsHidden : {glfwbackend .GLFWWindowFlagsVisible , 0 },
50
- }
51
-
52
- for flag , d := range data {
53
- if m & flag != 0 {
54
- b .SetWindowFlags (d .f , d .value )
55
- }
56
- }
57
- }
58
39
59
40
// TODO(gucio321) implement this in cimgui-go
60
41
// DontCare could be used as an argument to (*MasterWindow).SetSizeLimits.
@@ -63,7 +44,9 @@ func (m MasterWindowFlags) parseAndApply(b backend.Backend[glfwbackend.GLFWWindo
63
44
// MasterWindow represents a glfw master window
64
45
// It is a base for a windows (see Window.go).
65
46
type MasterWindow struct {
66
- backend backend.Backend [glfwbackend.GLFWWindowFlags ]
47
+ // generally Context should be used instead but as I don't like global
48
+ // variables, I prefer to keep a pointer here and refer it as possible.
49
+ ctx * GIUContext
67
50
68
51
width int
69
52
height int
@@ -96,7 +79,7 @@ func NewMasterWindow(title string, width, height int, flags MasterWindowFlags) *
96
79
// Disable imgui.ini
97
80
io .SetIniFilename ("" )
98
81
99
- currentBackend , err := backend .CreateBackend (glfwbackend . NewGLFWBackend ())
82
+ currentBackend , err := backend .CreateBackend (NewGLFWBackend ())
100
83
if err != nil && ! errors .Is (err , backend .CExposerError ) {
101
84
panic (err )
102
85
}
@@ -111,18 +94,24 @@ func NewMasterWindow(title string, width, height int, flags MasterWindowFlags) *
111
94
title : title ,
112
95
io : io ,
113
96
context : imGuiContext ,
114
- backend : currentBackend ,
97
+ ctx : Context ,
115
98
}
116
99
117
100
currentBackend .SetBeforeRenderHook (mw .beforeRender )
118
101
currentBackend .SetAfterRenderHook (mw .afterRender )
119
102
currentBackend .SetBeforeDestroyContextHook (mw .beforeDestroy )
120
- flags .parseAndApply (currentBackend )
103
+
104
+ for f := MasterWindowFlagsNotResizable ; f <= MasterWindowFlagsHidden ; f <<= 1 {
105
+ if f & flags != 0 {
106
+ currentBackend .SetWindowFlags (f , 0 ) // 0 because it is not used anyway (flag values are determined by giu
107
+ }
108
+ }
109
+
121
110
currentBackend .CreateWindow (title , width , height )
122
111
123
112
mw .SetInputHandler (newInputHandler ())
124
113
125
- mw .backend .SetSizeChangeCallback (mw .sizeChange )
114
+ mw .ctx . backend .SetSizeChangeCallback (mw .sizeChange )
126
115
127
116
mw .SetBgColor (colornames .Black )
128
117
@@ -279,8 +268,8 @@ func (w *MasterWindow) Run(loopFunc func()) {
279
268
280
269
// GetSize return size of master window.
281
270
func (w * MasterWindow ) GetSize () (width , height int ) {
282
- if w .backend != nil {
283
- w , h := w .backend .DisplaySize ()
271
+ if w .ctx . backend != nil {
272
+ w , h := w .ctx . backend .DisplaySize ()
284
273
return int (w ), int (h )
285
274
}
286
275
@@ -299,36 +288,36 @@ func (w *MasterWindow) SetBgColor(bgColor color.Color) {
299
288
W : float32 (a ) / mask ,
300
289
}
301
290
302
- w .backend .SetBgColor (w .clearColor )
291
+ w .ctx . backend .SetBgColor (w .clearColor )
303
292
}
304
293
305
294
// SetTargetFPS sets target FPS of master window.
306
295
// Default for GLFW is 30.
307
296
func (w * MasterWindow ) SetTargetFPS (fps uint ) {
308
- w .backend .SetTargetFPS (fps )
297
+ w .ctx . backend .SetTargetFPS (fps )
309
298
}
310
299
311
300
// GetPos return position of master window.
312
301
func (w * MasterWindow ) GetPos () (x , y int ) {
313
302
var xResult , yResult int32
314
- if w .backend != nil {
315
- xResult , yResult = w .backend .GetWindowPos ()
303
+ if w .ctx . backend != nil {
304
+ xResult , yResult = w .ctx . backend .GetWindowPos ()
316
305
}
317
306
318
307
return int (xResult ), int (yResult )
319
308
}
320
309
321
310
// SetPos sets position of master window.
322
311
func (w * MasterWindow ) SetPos (x , y int ) {
323
- if w .backend != nil {
324
- w .backend .SetWindowPos (x , y )
312
+ if w .ctx . backend != nil {
313
+ w .ctx . backend .SetWindowPos (x , y )
325
314
}
326
315
}
327
316
328
317
// SetSize sets size of master window.
329
318
func (w * MasterWindow ) SetSize (x , y int ) {
330
- if w .backend != nil {
331
- w .backend .SetWindowSize (x , y )
319
+ if w .ctx . backend != nil {
320
+ w .ctx . backend .SetWindowSize (x , y )
332
321
}
333
322
}
334
323
@@ -342,14 +331,14 @@ func (w *MasterWindow) SetSize(x, y int) {
342
331
// Mac OS X: Selecting Quit from the application menu will trigger the close
343
332
// callback for all windows.
344
333
func (w * MasterWindow ) SetCloseCallback (cb func () bool ) {
345
- w .backend .SetCloseCallback (func () {
346
- w .backend .SetShouldClose (cb ())
334
+ w .ctx . backend .SetCloseCallback (func () {
335
+ w .ctx . backend .SetShouldClose (cb ())
347
336
})
348
337
}
349
338
350
339
// SetDropCallback sets callback when file was dropped into the window.
351
340
func (w * MasterWindow ) SetDropCallback (cb func ([]string )) {
352
- w .backend .SetDropCallback (cb )
341
+ w .ctx . backend .SetDropCallback (cb )
353
342
}
354
343
355
344
// RegisterKeyboardShortcuts registers a global - master window - keyboard shortcuts.
@@ -379,7 +368,7 @@ func (w *MasterWindow) RegisterKeyboardShortcuts(s ...WindowShortcut) *MasterWin
379
368
// The desired image sizes varies depending on platform and system settings. The selected
380
369
// images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48.
381
370
func (w * MasterWindow ) SetIcon (icons ... image.Image ) {
382
- w .backend .SetIcons (icons ... )
371
+ w .ctx . backend .SetIcons (icons ... )
383
372
}
384
373
385
374
// SetSizeLimits sets the size limits of the client area of the specified window.
@@ -389,30 +378,30 @@ func (w *MasterWindow) SetIcon(icons ...image.Image) {
389
378
// To specify only a minimum size or only a maximum one, set the other pair to giu.DontCare.
390
379
// To disable size limits for a window, set them all to giu.DontCare.
391
380
func (w * MasterWindow ) SetSizeLimits (minw , minh , maxw , maxh int ) {
392
- w .backend .SetWindowSizeLimits (minw , minh , maxw , maxh )
381
+ w .ctx . backend .SetWindowSizeLimits (minw , minh , maxw , maxh )
393
382
}
394
383
395
384
// SetTitle updates master window's title.
396
385
func (w * MasterWindow ) SetTitle (title string ) {
397
- w .backend .SetWindowTitle (title )
386
+ w .ctx . backend .SetWindowTitle (title )
398
387
}
399
388
400
389
// Close will safely close the master window.
401
390
func (w * MasterWindow ) Close () {
402
- w .SetShouldClose (true )
391
+ w .ctx . backend . SetShouldClose (true )
403
392
}
404
393
405
394
// SetShouldClose sets whether master window should be closed.
406
395
func (w * MasterWindow ) SetShouldClose (v bool ) {
407
- w .backend .SetShouldClose (v )
396
+ w .ctx . backend .SetShouldClose (v )
408
397
}
409
398
410
399
// SetInputHandler allows to change default input handler.
411
400
// see InputHandler.go.
412
401
func (w * MasterWindow ) SetInputHandler (handler InputHandler ) {
413
402
Context .InputHandler = handler
414
403
415
- w .backend .SetKeyCallback (func (key , _ , action , modifier int ) {
404
+ w .ctx . backend .SetKeyCallback (func (key , _ , action , modifier int ) {
416
405
k , m , a := keyFromGLFWKey (glfwbackend .GLFWKey (key )), Modifier (modifier ), Action (action )
417
406
handler .Handle (k , m , a )
418
407
0 commit comments