-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcore_window_flags.bas
More file actions
270 lines (223 loc) · 9.32 KB
/
core_window_flags.bas
File metadata and controls
270 lines (223 loc) · 9.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
'*******************************************************************************************
'*
'* raylib [core] example - window flags
'*
'* Example originally created with raylib 3.5, last time updated with raylib 3.5
'*
'* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
'* BSD-like license that allows static linking with closed source software
'*
'* Copyright (c) 2020-2022 Ramon Santamaria (@raysan5)
'*
'* Converted to SmallBASIC by Joerg Siebenmorgen, 2022
'* https://github.com/smallbasic/smallbasic.plugins/blob/master/raylib/samples
'*
'********************************************************************************************
import raylib as rl
import raylibc as c
' Initialization
'--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450
' Possible window flags
' FLAG_VSYNC_HINT
' FLAG_FULLSCREEN_MODE
' FLAG_WINDOW_RESIZABLE
' FLAG_WINDOW_UNDECORATED
' FLAG_WINDOW_TRANSPARENT
' FLAG_WINDOW_HIDDEN
' FLAG_WINDOW_MINIMIZED -> Not supported on window creation
' FLAG_WINDOW_MAXIMIZED -> Not supported on window creation
' FLAG_WINDOW_UNFOCUSED
' FLAG_WINDOW_TOPMOST
' FLAG_WINDOW_HIGHDPI
' FLAG_WINDOW_ALWAYS_RUN
' FLAG_MSAA_4X_HINT
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - window flags")
ballPosition = {}
ballPosition.x = rl.GetScreenWidth() / 2
ballPosition.y = rl.GetScreenHeight() / 2
ballSpeed = { x: 5.0, y: 4.0}
ballRadius = 20
framesCounter = 0
rl.SetTargetFPS(60) ' Set our game to run at 60 frames-per-second
'--------------------------------------------------------------------------------------
' Main game loop
while (!rl.WindowShouldClose()) ' Detect window close button or ESC key
' Update
'----------------------------------------------------------------------------------
if (rl.IsKeyPressed(c.KEY_F)) then
rl.ToggleFullscreen() ' modifies window size when scaling!
endif
if(rl.IsKeyPressed(c.KEY_R)) then
if(rl.IsWindowState(c.FLAG_WINDOW_RESIZABLE)) then
rl.ClearWindowState(c.FLAG_WINDOW_RESIZABLE)
else
rl.SetWindowState(c.FLAG_WINDOW_RESIZABLE)
endif
endif
if (rl.IsKeyPressed(c.KEY_D)) then
if(rl.IsWindowState(c.FLAG_WINDOW_UNDECORATED)) then
rl.ClearWindowState(c.FLAG_WINDOW_UNDECORATED)
else
rl.SetWindowState(c.FLAG_WINDOW_UNDECORATED)
endif
endif
if(rl.IsKeyPressed(c.KEY_H)) then
if(!rl.IsWindowState(c.FLAG_WINDOW_HIDDEN)) then
rl.SetWindowState(c.FLAG_WINDOW_HIDDEN)
endif
framesCounter = 0
endif
if(rl.IsWindowState(c.FLAG_WINDOW_HIDDEN)) then
framesCounter++
if(framesCounter >= 240) then
rl.ClearWindowState(c.FLAG_WINDOW_HIDDEN) ' Show window after 3 seconds
endif
endif
if(rl.IsKeyPressed(c.KEY_N)) then
if(!rl.IsWindowState(c.FLAG_WINDOW_MINIMIZED)) then
rl.MinimizeWindow()
endif
framesCounter = 0
endif
if(rl.IsWindowState(c.FLAG_WINDOW_MINIMIZED)) then
framesCounter++
if(framesCounter >= 240) then
rl.RestoreWindow() ' Restore window after 3 seconds
endif
endif
if(rl.IsKeyPressed(c.KEY_M)) then
' NOTE: Requires FLAG_WINDOW_RESIZABLE enabled!
if(rl.IsWindowState(c.FLAG_WINDOW_MAXIMIZED)) then
rl.RestoreWindow()
else
rl.MaximizeWindow()
endif
endif
if(rl.IsKeyPressed(c.KEY_U)) then
if(rl.IsWindowState(c.FLAG_WINDOW_UNFOCUSED)) then
rl.ClearWindowState(cFLAG_WINDOW_UNFOCUSED)
else
rl.SetWindowState(c.FLAG_WINDOW_UNFOCUSED)
endif
endif
if(rl.IsKeyPressed(c.KEY_T)) then
if(rl.IsWindowState(c.FLAG_WINDOW_TOPMOST)) then
rl.ClearWindowState(c.FLAG_WINDOW_TOPMOST)
else
rl.SetWindowState(c.FLAG_WINDOW_TOPMOST)
endif
endif
if(rl.IsKeyPressed(c.KEY_A)) then
if(rl.IsWindowState(c.FLAG_WINDOW_ALWAYS_RUN)) then
rl.ClearWindowState(c.FLAG_WINDOW_ALWAYS_RUN)
else
rl.SetWindowState(c.FLAG_WINDOW_ALWAYS_RUN)
endif
endif
if(rl.IsKeyPressed(c.KEY_V)) then
if(rl.IsWindowState(c.FLAG_VSYNC_HINT)) then
rl.ClearWindowState(c.FLAG_VSYNC_HINT)
else
rl.SetWindowState(c.FLAG_VSYNC_HINT)
endif
endif
' Bouncing ball logic
ballPosition.x += ballSpeed.x
ballPosition.y += ballSpeed.y
if((ballPosition.x >= (rl.GetScreenWidth() - ballRadius)) OR (ballPosition.x <= ballRadius)) then
ballSpeed.x *= -1.0
endif
if((ballPosition.y >= (rl.GetScreenHeight() - ballRadius)) OR (ballPosition.y <= ballRadius)) then
ballSpeed.y *= -1.0
endif
'----------------------------------------------------------------------------------
' Draw
'----------------------------------------------------------------------------------
rl.BeginDrawing()
if(rl.IsWindowState(c.FLAG_WINDOW_TRANSPARENT)) then
rl.ClearBackground(c.BLANK)
else
rl.ClearBackground(c.RAYWHITE)
endif
rl.DrawCircleV(ballPosition, ballRadius, c.MAROON)
rl.DrawRectangleLinesEx([0, 0, rl.GetScreenWidth(), rl.GetScreenHeight()], 4, c.RAYWHITE)
rl.DrawCircleV(rl.GetMousePosition(), 10, c.DARKBLUE)
rl.DrawFPS(10, 10)
rl.DrawText(rl.TextFormat("Screen Size: [%i, %i]", rl.GetScreenWidth(), rl.GetScreenHeight()), 10, 40, 10, c.GREEN)
' Draw window state info
rl.DrawText("Following flags can be set after window creation:", 10, 60, 10, c.GRAY)
if(rl.IsWindowState(c.FLAG_FULLSCREEN_MODE)) then
rl.DrawText("[F] FLAG_FULLSCREEN_MODE: on", 10, 80, 10, c.LIME)
else
rl.DrawText("[F] FLAG_FULLSCREEN_MODE: off", 10, 80, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_RESIZABLE)) then
rl.DrawText("[R] FLAG_WINDOW_RESIZABLE: on", 10, 100, 10, c.LIME)
else
rl.DrawText("[R] FLAG_WINDOW_RESIZABLE: off", 10, 100, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_UNDECORATED)) then
rl.DrawText("[D] FLAG_WINDOW_UNDECORATED: on", 10, 120, 10, c.LIME)
else
rl.DrawText("[D] FLAG_WINDOW_UNDECORATED: off", 10, 120, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_HIDDEN)) then
rl.DrawText("[H] FLAG_WINDOW_HIDDEN: on", 10, 140, 10, c.LIME)
else
rl.DrawText("[H] FLAG_WINDOW_HIDDEN: off", 10, 140, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_MINIMIZED)) then
rl.DrawText("[N] FLAG_WINDOW_MINIMIZED: on", 10, 160, 10, c.LIME)
else
rl.DrawText("[N] FLAG_WINDOW_MINIMIZED: off", 10, 160, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_MAXIMIZED)) then
rl.DrawText("[M] FLAG_WINDOW_MAXIMIZED: on", 10, 180, 10, c.LIME)
else
rl.DrawText("[M] FLAG_WINDOW_MAXIMIZED: off", 10, 180, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_UNFOCUSED)) then
rl.DrawText("[G] FLAG_WINDOW_UNFOCUSED: on", 10, 200, 10, c.LIME)
else
rl.DrawText("[U] FLAG_WINDOW_UNFOCUSED: off", 10, 200, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_TOPMOST)) then
rl.DrawText("[T] FLAG_WINDOW_TOPMOST: on", 10, 220, 10, c.LIME)
else
rl.DrawText("[T] FLAG_WINDOW_TOPMOST: off", 10, 220, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_ALWAYS_RUN)) then
rl.DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: on", 10, 240, 10, c.LIME)
else
rl.DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: off", 10, 240, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_VSYNC_HINT)) then
rl.DrawText("[V] FLAG_VSYNC_HINT: on", 10, 260, 10, c.LIME)
else
rl.DrawText("[V] FLAG_VSYNC_HINT: off", 10, 260, 10, c.MAROON)
endif
rl.DrawText("Following flags can only be set before window creation:", 10, 300, 10, c.GRAY)
if(rl.IsWindowState(c.FLAG_WINDOW_HIGHDPI)) then
rl.DrawText("FLAG_WINDOW_HIGHDPI: on", 10, 320, 10, c.LIME)
else
rl.DrawText("FLAG_WINDOW_HIGHDPI: off", 10, 320, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_WINDOW_TRANSPARENT)) then
rl.DrawText("FLAG_WINDOW_TRANSPARENT: on", 10, 340, 10, c.LIME)
else
rl.DrawText("FLAG_WINDOW_TRANSPARENT: off", 10, 340, 10, c.MAROON)
endif
if(rl.IsWindowState(c.FLAG_MSAA_4X_HINT)) then
rl.DrawText("FLAG_MSAA_4X_HINT: on", 10, 360, 10, c.LIME)
else
rl.DrawText("FLAG_MSAA_4X_HINT: off", 10, 360, 10, c.MAROON)
endif
rl.EndDrawing()
'----------------------------------------------------------------------------------
wend
' De-Initialization
'--------------------------------------------------------------------------------------
rl.CloseWindow() ' Close window and OpenGL context
'--------------------------------------------------------------------------------------