Skip to content

Commit 6c9e423

Browse files
authored
Merge pull request #110 from Timfon/master
Added core_window_flags example
2 parents 4893cfb + 9df3448 commit 6c9e423

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

examples/core/core_window_flags.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
from pyray import *
2+
import pyray
3+
4+
# Initialization
5+
# ---------------------------------------------------------
6+
screen_width = 800
7+
screen_height = 450
8+
9+
init_window(screen_width, screen_height, b"raylib [core] example - window flags")
10+
11+
ball_position = Vector2(get_screen_width() / 2.0, get_screen_height() / 2.0)
12+
ball_speed = Vector2(5.0, 4.0)
13+
ball_radius = 20.0
14+
15+
frames_counter = 0
16+
17+
# Main game loop
18+
while not window_should_close(): # Detect window close button or ESC key
19+
# Update
20+
# -----------------------------------------------------
21+
if is_key_pressed(pyray.KEY_F):
22+
toggle_fullscreen()
23+
24+
if is_key_pressed(pyray.KEY_R):
25+
if is_window_state(pyray.FLAG_WINDOW_RESIZABLE):
26+
clear_window_state(pyray.FLAG_WINDOW_RESIZABLE)
27+
else:
28+
set_window_state(pyray.FLAG_WINDOW_RESIZABLE)
29+
30+
if is_key_pressed(pyray.KEY_D):
31+
if is_window_state(pyray.FLAG_WINDOW_UNDECORATED):
32+
clear_window_state(pyray.FLAG_WINDOW_UNDECORATED)
33+
else:
34+
set_window_state(pyray.FLAG_WINDOW_UNDECORATED)
35+
36+
if is_key_pressed(pyray.KEY_H):
37+
if not is_window_state(pyray.FLAG_WINDOW_HIDDEN):
38+
set_window_state(pyray.FLAG_WINDOW_HIDDEN)
39+
frames_counter = 0
40+
41+
if is_window_state(pyray.FLAG_WINDOW_HIDDEN):
42+
frames_counter += 1
43+
if frames_counter >= 240:
44+
clear_window_state(pyray.FLAG_WINDOW_HIDDEN) # Show window after 3 seconds
45+
46+
if is_key_pressed(pyray.KEY_N):
47+
if not is_window_state(pyray.FLAG_WINDOW_MINIMIZED):
48+
minimize_window()
49+
frames_counter = 0
50+
51+
if is_window_state(pyray.FLAG_WINDOW_MINIMIZED):
52+
frames_counter += 1
53+
if frames_counter >= 240:
54+
restore_window() # Restore window after 3 seconds
55+
56+
if is_key_pressed(pyray.KEY_M):
57+
if is_window_state(pyray.FLAG_WINDOW_RESIZABLE):
58+
if is_window_state(pyray.FLAG_WINDOW_MAXIMIZED):
59+
restore_window()
60+
else:
61+
maximize_window()
62+
63+
if is_key_pressed(pyray.KEY_U):
64+
if is_window_state(pyray.FLAG_WINDOW_UNFOCUSED):
65+
clear_window_state(pyray.FLAG_WINDOW_UNFOCUSED)
66+
else:
67+
set_window_state(pyray.FLAG_WINDOW_UNFOCUSED)
68+
69+
if is_key_pressed(pyray.KEY_T):
70+
if is_window_state(pyray.FLAG_WINDOW_TOPMOST):
71+
clear_window_state(pyray.FLAG_WINDOW_TOPMOST)
72+
else:
73+
set_window_state(pyray.FLAG_WINDOW_TOPMOST)
74+
75+
if is_key_pressed(pyray.KEY_A):
76+
if is_window_state(pyray.FLAG_WINDOW_ALWAYS_RUN):
77+
clear_window_state(pyray.FLAG_WINDOW_ALWAYS_RUN)
78+
else:
79+
set_window_state(pyray.FLAG_WINDOW_ALWAYS_RUN)
80+
81+
if is_key_pressed(pyray.KEY_V):
82+
if is_window_state(pyray.FLAG_VSYNC_HINT):
83+
clear_window_state(pyray.FLAG_VSYNC_HINT)
84+
else:
85+
set_window_state(pyray.FLAG_VSYNC_HINT)
86+
87+
# Bouncing ball logic
88+
ball_position.x += ball_speed.x
89+
ball_position.y += ball_speed.y
90+
if ball_position.x >= (get_screen_width() - ball_radius) or ball_position.x <= ball_radius:
91+
ball_speed.x *= -1.0
92+
if ball_position.y >= (get_screen_height() - ball_radius) or ball_position.y <= ball_radius:
93+
ball_speed.y *= -1.0
94+
95+
# Draw
96+
# -----------------------------------------------------
97+
begin_drawing()
98+
99+
if is_window_state(pyray.FLAG_WINDOW_TRANSPARENT):
100+
clear_background(BLANK)
101+
else:
102+
clear_background(RAYWHITE)
103+
104+
draw_circle_v(ball_position, ball_radius, MAROON)
105+
draw_rectangle_lines_ex(Rectangle(0, 0, get_screen_width(), get_screen_height()), 4, RAYWHITE)
106+
107+
draw_circle_v(get_mouse_position(), 10, DARKBLUE)
108+
109+
draw_fps(10, 10)
110+
111+
draw_text(f"Screen Size: [{get_screen_width()}, {get_screen_height()}]", 10, 40, 10, GREEN)
112+
113+
# Draw window state info
114+
draw_text("Following flags can be set after window creation:", 10, 60, 10, GRAY)
115+
flag_texts = [
116+
("FLAG_FULLSCREEN_MODE", pyray.FLAG_FULLSCREEN_MODE),
117+
("FLAG_WINDOW_RESIZABLE", pyray.FLAG_WINDOW_RESIZABLE),
118+
("FLAG_WINDOW_UNDECORATED", pyray.FLAG_WINDOW_UNDECORATED),
119+
("FLAG_WINDOW_HIDDEN", pyray.FLAG_WINDOW_HIDDEN),
120+
("FLAG_WINDOW_MINIMIZED", pyray.FLAG_WINDOW_MINIMIZED),
121+
("FLAG_WINDOW_MAXIMIZED", pyray.FLAG_WINDOW_MAXIMIZED),
122+
("FLAG_WINDOW_UNFOCUSED", pyray.FLAG_WINDOW_UNFOCUSED),
123+
("FLAG_WINDOW_TOPMOST", pyray.FLAG_WINDOW_TOPMOST),
124+
("FLAG_WINDOW_ALWAYS_RUN", pyray.FLAG_WINDOW_ALWAYS_RUN),
125+
("FLAG_VSYNC_HINT", pyray.FLAG_VSYNC_HINT),
126+
]
127+
y_offset = 80
128+
for text, flag in flag_texts:
129+
if is_window_state(flag):
130+
draw_text(f"[{text[5:]}] {text}: on", 10, y_offset, 10, LIME)
131+
else:
132+
draw_text(f"[{text[5:]}] {text}: off", 10, y_offset, 10, MAROON)
133+
y_offset += 20
134+
135+
draw_text("Following flags can only be set before window creation:", 10, 300, 10, GRAY)
136+
if is_window_state(pyray.FLAG_WINDOW_HIGHDPI):
137+
draw_text("FLAG_WINDOW_HIGHDPI: on", 10, 320, 10, LIME)
138+
else:
139+
draw_text("FLAG_WINDOW_HIGHDPI: off", 10, 320, 10, MAROON)
140+
if is_window_state(pyray.FLAG_WINDOW_TRANSPARENT):
141+
draw_text("FLAG_WINDOW_TRANSPARENT: on", 10, 340, 10, LIME)
142+
else:
143+
draw_text("FLAG_WINDOW_TRANSPARENT: off", 10, 340, 10, MAROON)
144+
if is_window_state(pyray.FLAG_MSAA_4X_HINT):
145+
draw_text("FLAG_MSAA_4X_HINT: on", 10, 360, 10, LIME)
146+
else:
147+
draw_text("FLAG_MSAA_4X_HINT: off", 10, 360, 10, MAROON)
148+
149+
end_drawing()
150+
# -----------------------------------------------------
151+
152+
# De-Initialization
153+
# ---------------------------------------------------------
154+
close_window() # Close window and OpenGL context
155+
# ---------------------------------------------------------
156+

0 commit comments

Comments
 (0)