Mercurial > repos > blastem
comparison bindings.c @ 1672:12d0c7c4ad80
Disable most bindings when UI is active
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 03 Jan 2019 09:14:49 -0800 |
parents | 6909c5d0bbb5 |
children | deaf31803b11 |
comparison
equal
deleted
inserted
replaced
1671:05c34078e1ac | 1672:12d0c7c4ad80 |
---|---|
186 joysticks[joystick].axes[i].negative.bind_type = BIND_NONE; | 186 joysticks[joystick].axes[i].negative.bind_type = BIND_NONE; |
187 } | 187 } |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 static uint8_t content_binds_enabled = 1; | |
192 void set_content_binding_state(uint8_t enabled) | |
193 { | |
194 content_binds_enabled = enabled; | |
195 } | |
196 | |
191 void handle_binding_down(keybinding * binding) | 197 void handle_binding_down(keybinding * binding) |
192 { | 198 { |
193 if (!current_system) { | 199 if (!current_system) { |
194 return; | 200 return; |
195 } | 201 } |
254 void handle_binding_up(keybinding * binding) | 260 void handle_binding_up(keybinding * binding) |
255 { | 261 { |
256 switch(binding->bind_type) | 262 switch(binding->bind_type) |
257 { | 263 { |
258 case BIND_GAMEPAD: | 264 case BIND_GAMEPAD: |
259 if (current_system && current_system->gamepad_up) { | 265 if (content_binds_enabled && current_system->gamepad_up) { |
260 current_system->gamepad_up(current_system, binding->subtype_a, binding->subtype_b); | 266 current_system->gamepad_up(current_system, binding->subtype_a, binding->subtype_b); |
261 } | 267 } |
262 break; | 268 break; |
263 case BIND_MOUSE: | 269 case BIND_MOUSE: |
264 if (current_system && current_system->mouse_up) { | 270 if (content_binds_enabled && current_system->mouse_up) { |
265 current_system->mouse_up(current_system, binding->subtype_a, binding->subtype_b); | 271 current_system->mouse_up(current_system, binding->subtype_a, binding->subtype_b); |
266 } | 272 } |
267 break; | 273 break; |
268 case BIND_UI: | 274 case BIND_UI: |
269 switch (binding->subtype_a) | 275 switch (binding->subtype_a) |
270 { | 276 { |
271 case UI_DEBUG_MODE_INC: | 277 case UI_DEBUG_MODE_INC: |
272 current_system->inc_debug_mode(current_system); | 278 if (content_binds_enabled) { |
279 current_system->inc_debug_mode(current_system); | |
280 } | |
273 break; | 281 break; |
274 case UI_ENTER_DEBUGGER: | 282 case UI_ENTER_DEBUGGER: |
275 current_system->enter_debugger = 1; | 283 if (content_binds_enabled) { |
284 current_system->enter_debugger = 1; | |
285 } | |
276 break; | 286 break; |
277 case UI_SAVE_STATE: | 287 case UI_SAVE_STATE: |
278 current_system->save_state = QUICK_SAVE_SLOT+1; | 288 if (content_binds_enabled) { |
289 current_system->save_state = QUICK_SAVE_SLOT+1; | |
290 } | |
279 break; | 291 break; |
280 case UI_NEXT_SPEED: | 292 case UI_NEXT_SPEED: |
281 current_speed++; | 293 if (content_binds_enabled) { |
282 if (current_speed >= num_speeds) { | 294 current_speed++; |
283 current_speed = 0; | 295 if (current_speed >= num_speeds) { |
284 } | 296 current_speed = 0; |
285 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); | 297 } |
286 current_system->set_speed_percent(current_system, speeds[current_speed]); | |
287 break; | |
288 case UI_PREV_SPEED: | |
289 current_speed--; | |
290 if (current_speed < 0) { | |
291 current_speed = num_speeds - 1; | |
292 } | |
293 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); | |
294 current_system->set_speed_percent(current_system, speeds[current_speed]); | |
295 break; | |
296 case UI_SET_SPEED: | |
297 if (binding->subtype_b < num_speeds) { | |
298 current_speed = binding->subtype_b; | |
299 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); | 298 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
300 current_system->set_speed_percent(current_system, speeds[current_speed]); | 299 current_system->set_speed_percent(current_system, speeds[current_speed]); |
301 } else { | 300 } |
302 printf("Setting speed to %d\n", speeds[current_speed]); | 301 break; |
302 case UI_PREV_SPEED: | |
303 if (content_binds_enabled) { | |
304 current_speed--; | |
305 if (current_speed < 0) { | |
306 current_speed = num_speeds - 1; | |
307 } | |
308 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); | |
303 current_system->set_speed_percent(current_system, speeds[current_speed]); | 309 current_system->set_speed_percent(current_system, speeds[current_speed]); |
310 } | |
311 break; | |
312 case UI_SET_SPEED: | |
313 if (content_binds_enabled) { | |
314 if (binding->subtype_b < num_speeds) { | |
315 current_speed = binding->subtype_b; | |
316 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); | |
317 current_system->set_speed_percent(current_system, speeds[current_speed]); | |
318 } else { | |
319 printf("Setting speed to %d\n", speeds[current_speed]); | |
320 current_system->set_speed_percent(current_system, speeds[current_speed]); | |
321 } | |
304 } | 322 } |
305 break; | 323 break; |
306 case UI_RELEASE_MOUSE: | 324 case UI_RELEASE_MOUSE: |
307 if (mouse_captured) { | 325 if (mouse_captured) { |
308 mouse_captured = 0; | 326 mouse_captured = 0; |
309 render_relative_mouse(0); | 327 render_relative_mouse(0); |
310 } | 328 } |
311 break; | 329 break; |
312 case UI_TOGGLE_KEYBOARD_CAPTURE: | 330 case UI_TOGGLE_KEYBOARD_CAPTURE: |
313 if (current_system && current_system->has_keyboard) { | 331 if (content_binds_enabled && current_system->has_keyboard) { |
314 keyboard_captured = !keyboard_captured; | 332 keyboard_captured = !keyboard_captured; |
315 } | 333 } |
316 break; | 334 break; |
317 case UI_TOGGLE_FULLSCREEN: | 335 case UI_TOGGLE_FULLSCREEN: |
318 render_toggle_fullscreen(); | 336 render_toggle_fullscreen(); |
319 break; | 337 break; |
320 case UI_SOFT_RESET: | 338 case UI_SOFT_RESET: |
321 current_system->soft_reset(current_system); | 339 if (content_binds_enabled) { |
340 current_system->soft_reset(current_system); | |
341 } | |
322 break; | 342 break; |
323 case UI_RELOAD: | 343 case UI_RELOAD: |
324 reload_media(); | 344 if (content_binds_enabled) { |
345 reload_media(); | |
346 } | |
325 break; | 347 break; |
326 case UI_SMS_PAUSE: | 348 case UI_SMS_PAUSE: |
327 if (current_system && current_system->gamepad_down) { | 349 if (content_binds_enabled && current_system->gamepad_down) { |
328 current_system->gamepad_down(current_system, GAMEPAD_MAIN_UNIT, MAIN_UNIT_PAUSE); | 350 current_system->gamepad_down(current_system, GAMEPAD_MAIN_UNIT, MAIN_UNIT_PAUSE); |
329 } | 351 } |
330 break; | 352 break; |
331 case UI_SCREENSHOT: { | 353 case UI_SCREENSHOT: { |
332 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval; | 354 if (content_binds_enabled) { |
333 if (!screenshot_base) { | 355 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval; |
334 screenshot_base = "$HOME"; | 356 if (!screenshot_base) { |
335 } | 357 screenshot_base = "$HOME"; |
336 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); | 358 } |
337 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); | 359 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); |
338 screenshot_base = replace_vars(screenshot_base, vars, 1); | 360 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); |
339 tern_free(vars); | 361 screenshot_base = replace_vars(screenshot_base, vars, 1); |
340 time_t now = time(NULL); | 362 tern_free(vars); |
341 struct tm local_store; | 363 time_t now = time(NULL); |
342 char fname_part[256]; | 364 struct tm local_store; |
343 char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval; | 365 char fname_part[256]; |
344 if (!template) { | 366 char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval; |
345 template = "blastem_%c.ppm"; | 367 if (!template) { |
346 } | 368 template = "blastem_%c.ppm"; |
347 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store)); | 369 } |
348 char const *parts[] = {screenshot_base, PATH_SEP, fname_part}; | 370 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store)); |
349 char *path = alloc_concat_m(3, parts); | 371 char const *parts[] = {screenshot_base, PATH_SEP, fname_part}; |
350 free(screenshot_base); | 372 char *path = alloc_concat_m(3, parts); |
351 render_save_screenshot(path); | 373 free(screenshot_base); |
374 render_save_screenshot(path); | |
375 } | |
352 break; | 376 break; |
353 } | 377 } |
354 case UI_EXIT: | 378 case UI_EXIT: |
355 #ifndef DISABLE_NUKLEAR | 379 #ifndef DISABLE_NUKLEAR |
356 if (is_nuklear_active()) { | 380 if (is_nuklear_active()) { |
371 #endif | 395 #endif |
372 break; | 396 break; |
373 case UI_PLANE_DEBUG: | 397 case UI_PLANE_DEBUG: |
374 case UI_VRAM_DEBUG: | 398 case UI_VRAM_DEBUG: |
375 case UI_CRAM_DEBUG: | 399 case UI_CRAM_DEBUG: |
376 case UI_COMPOSITE_DEBUG: { | 400 case UI_COMPOSITE_DEBUG: |
377 vdp_context *vdp = NULL; | 401 if (content_binds_enabled) { |
378 if (current_system->type == SYSTEM_GENESIS) { | 402 vdp_context *vdp = NULL; |
379 genesis_context *gen = (genesis_context *)current_system; | 403 if (current_system->type == SYSTEM_GENESIS) { |
380 vdp = gen->vdp; | 404 genesis_context *gen = (genesis_context *)current_system; |
381 } else if (current_system->type == SYSTEM_SMS) { | 405 vdp = gen->vdp; |
382 sms_context *sms = (sms_context *)current_system; | 406 } else if (current_system->type == SYSTEM_SMS) { |
383 vdp = sms->vdp; | 407 sms_context *sms = (sms_context *)current_system; |
384 } | 408 vdp = sms->vdp; |
385 if (vdp) { | 409 } |
386 uint8_t debug_type; | 410 if (vdp) { |
387 switch(binding->subtype_a) | 411 uint8_t debug_type; |
388 { | 412 switch(binding->subtype_a) |
389 case UI_PLANE_DEBUG: debug_type = VDP_DEBUG_PLANE; break; | 413 { |
390 case UI_VRAM_DEBUG: debug_type = VDP_DEBUG_VRAM; break; | 414 case UI_PLANE_DEBUG: debug_type = VDP_DEBUG_PLANE; break; |
391 case UI_CRAM_DEBUG: debug_type = VDP_DEBUG_CRAM; break; | 415 case UI_VRAM_DEBUG: debug_type = VDP_DEBUG_VRAM; break; |
392 case UI_COMPOSITE_DEBUG: debug_type = VDP_DEBUG_COMPOSITE; break; | 416 case UI_CRAM_DEBUG: debug_type = VDP_DEBUG_CRAM; break; |
393 default: return; | 417 case UI_COMPOSITE_DEBUG: debug_type = VDP_DEBUG_COMPOSITE; break; |
394 } | 418 default: return; |
395 vdp_toggle_debug_view(vdp, debug_type); | 419 } |
396 } | 420 vdp_toggle_debug_view(vdp, debug_type); |
397 break; | 421 } |
398 } | 422 break; |
423 } | |
399 } | 424 } |
400 break; | 425 break; |
401 } | 426 } |
402 } | 427 } |
403 | 428 |