4747 color_depth = 16 ,
4848 )
4949 display = framebufferio .FramebufferDisplay (fb )
50+ supervisor .runtime .display = display
5051
5152game_logic = GameLogic (display ) # pylint: disable=no-value-for-parameter
5253
7475ui_group = Group ()
7576main_group .append (ui_group )
7677
77- # Create the mouse graphics and add to the main group
78- mouse_bmp = OnDiskBitmap ("bitmaps/mouse_cursor.bmp" )
79- mouse_bmp .pixel_shader .make_transparent (0 )
80- mouse_tg = TileGrid (mouse_bmp , pixel_shader = mouse_bmp .pixel_shader )
81- mouse_tg .x = display .width // 2
82- mouse_tg .y = display .height // 2
83- main_group .append (mouse_tg )
84-
8578MENU_ITEM_HEIGHT = INFO_BAR_HEIGHT
8679
8780def create_game_board ():
@@ -114,11 +107,23 @@ def update_ui():
114107 mines_left_label .text = f"Mines: { game_logic .mines_left } "
115108 elapsed_time_label .text = f"Time: { game_logic .elapsed_time } "
116109
110+
111+ # Mouse resolution/sensitivity
112+ sensitivity = 4
113+
117114# variable for the mouse USB device instance
118- mouse = find_and_init_boot_mouse ()
115+ mouse = find_and_init_boot_mouse (cursor_image = "bitmaps/mouse_cursor.bmp" )
119116if mouse is None :
120117 raise RuntimeError ("No mouse found. Please connect a USB mouse." )
121118
119+ mouse .sensitivity = sensitivity
120+ mouse_tg = mouse .tilegrid
121+ mouse_tg .x = display .width // 2
122+ mouse_tg .y = display .height // 2
123+
124+ # add mouse graphic to main_group
125+ main_group .append (mouse_tg )
126+
122127buf = array .array ("b" , [0 ] * 4 )
123128waiting_for_release = False
124129left_button = right_button = False
@@ -235,26 +240,17 @@ def hide_group(group):
235240left_button_pressed = False
236241right_button_pressed = False
237242
238- # Mouse resolution/sensitivity
239- sensitivity = 4
240- mouse .x = mouse_coords [0 ] * sensitivity
241- mouse .y = mouse_coords [1 ] * sensitivity
242-
243- # Change the mouse resolution so it's not too sensitive
244- mouse .display_size = (display .width * sensitivity , display .height * sensitivity )
245-
246243# main loop
247244while True :
248245 update_ui ()
249- # attempt mouse read
246+ # update cursor position, and check for clicks
250247 buttons = mouse .update ()
251248
252249 # Extract button states
253250 if buttons is None :
254251 left_button = 0
255252 right_button = 0
256253 else :
257- print (buttons )
258254 left_button = 1 if 'left' in buttons else 0
259255 right_button = 1 if 'right' in buttons else 0
260256
@@ -273,11 +269,6 @@ def hide_group(group):
273269 last_left_button_state = left_button
274270 last_right_button_state = right_button
275271
276- # Update position
277- # Ensure position stays within bounds
278- mouse_tg .x = max (0 , min (display .width - 1 , mouse .x // sensitivity ))
279- mouse_tg .y = max (0 , min (display .height - 1 , mouse .y // sensitivity ))
280-
281272 mouse_coords = (mouse_tg .x , mouse_tg .y )
282273
283274 if waiting_for_release and not left_button and not right_button :
0 commit comments