this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

added menu mouse handling #1748

nesbox fd538f91 8ce3260d

+71 -16
+64 -10
src/studio/screens/menu.c
··· 228 228 option->pos = option->get(); 229 229 } 230 230 231 + static void onMenuItem(Menu* menu, const MenuItem* item) 232 + { 233 + playSystemSfx(2); 234 + resetMovie(menu, item->back ? &menu->anim.back : &menu->anim.close); 235 + } 236 + 231 237 static void drawMenu(Menu* menu, s32 x, s32 y) 232 238 { 233 239 if (getStudioMode() != TIC_MENU_MODE) ··· 251 257 resetMovie(menu, &menu->anim.down); 252 258 } 253 259 254 - MenuOption* option = menu->items[menu->pos].option; 260 + MenuItem* item = &menu->items[menu->pos]; 261 + MenuOption* option = item->option; 255 262 if(option) 256 263 { 257 264 if(tic_api_btnp(menu->tic, Left, Hold, Period) ··· 278 285 updateOption(option, +1); 279 286 } 280 287 else if(menu->items[menu->pos].handler) 281 - { 282 - playSystemSfx(2); 283 - resetMovie(menu, &menu->anim.close); 284 - } 288 + onMenuItem(menu, item); 285 289 } 286 290 287 291 if((tic_api_btnp(menu->tic, B, -1, -1) ··· 297 301 char buf[TICNAME_MAX]; 298 302 for(const MenuItem *it = menu->items, *end = it + menu->count; it != end; ++it, ++i) 299 303 { 300 - s32 len = it->option 304 + s32 width = (it->option 301 305 ? sprintf(buf, "%s%s", it->label, it->option->values[it->option->pos]) 302 - : sprintf(buf, "%s", it->label); 306 + : sprintf(buf, "%s", it->label)) * TIC_FONT_WIDTH; 307 + 308 + tic_rect rect = {x + (TIC80_WIDTH - width) / 2 + menu->anim.offset, 309 + y + TextMargin + ItemHeight * (i - menu->pos) - menu->anim.pos, width, TIC_FONT_HEIGHT}; 310 + 311 + bool down = false; 312 + if(animIdle(menu) && checkMousePos(&rect)) 313 + { 314 + setCursor(tic_cursor_hand); 303 315 304 - printShadow(tic, buf, x + (TIC80_WIDTH - len * TIC_FONT_WIDTH) / 2 + menu->anim.offset, 305 - y + TextMargin + ItemHeight * (i - menu->pos) - menu->anim.pos, tic_color_white); 316 + if(checkMouseDown(&rect, tic_mouse_left) || checkMouseDown(&rect, tic_mouse_right)) 317 + down = true; 318 + 319 + bool left = checkMouseClick(&rect, tic_mouse_left); 320 + if(left || checkMouseClick(&rect, tic_mouse_right)) 321 + { 322 + if(it->option) 323 + { 324 + playSystemSfx(2); 325 + updateOption(it->option, left ? +1 : -1); 326 + } 327 + else if(it->handler) 328 + { 329 + menu->pos = i; 330 + onMenuItem(menu, it); 331 + } 332 + } 333 + } 334 + 335 + if(down) 336 + tic_api_print(tic, buf, rect.x, rect.y + 1, tic_color_white, true, 1, false); 337 + else 338 + printShadow(tic, buf, rect.x, rect.y, tic_color_white); 306 339 } 307 340 } 308 341 ··· 409 442 410 443 processAnim(menu); 411 444 445 + // process scroll 446 + if(animIdle(menu)) 447 + { 448 + tic80_input* input = &tic->ram.input; 449 + 450 + if(input->mouse.scrolly) 451 + { 452 + if(tic_api_key(tic, tic_key_ctrl) || tic_api_key(tic, tic_key_shift)) 453 + { 454 + MenuOption* option = menu->items[menu->pos].option; 455 + if(option) 456 + updateOption(option, input->mouse.scrolly < 0 ? -1 : +1); 457 + } 458 + else 459 + { 460 + s32 pos = menu->pos + (input->mouse.scrolly < 0 ? +1 : -1); 461 + menu->pos = CLAMP(pos, 0, menu->count - 1); 462 + } 463 + } 464 + } 465 + 412 466 if(getStudioMode() != TIC_MENU_MODE) 413 467 return; 414 468 ··· 457 511 if(menu->back) 458 512 { 459 513 playSystemSfx(2); 460 - resetMovie(menu, &menu->anim.back); 514 + resetMovie(menu, &menu->anim.back); 461 515 } 462 516 463 517 return menu->back != NULL;
+1
src/studio/screens/menu.h
··· 46 46 47 47 MenuOption* option; 48 48 const char* help; 49 + bool back; 49 50 } MenuItem; 50 51 51 52 void studio_menu_init(Menu* menu, const MenuItem* items, s32 rows, s32 pos, s32 backPos, void(*back)(void*), void* data);
+6 -6
src/studio/studio.c
··· 1229 1229 {"FULLSCREEN ", NULL, &FullscreenOption}, 1230 1230 {"VOLUME ", NULL, &VolumeOption}, 1231 1231 {"SETUP GAMEPAD", showGamepadMenu}, 1232 - {"", NULL}, 1233 - {"BACK", showGameMenu}, 1232 + {""}, 1233 + {"BACK", showGameMenu, .back = true}, 1234 1234 }; 1235 1235 1236 1236 static void showOptionsMenu(); ··· 1243 1243 {"RESET GAME", resetGame}, 1244 1244 {"RESUME GAME", hideGameMenu}, 1245 1245 {"OPTIONS", showOptionsMenu}, 1246 - {"", NULL}, 1246 + {""}, 1247 1247 {"QUIT TIC-80", exitStudio}, 1248 1248 }; 1249 1249 ··· 1264 1264 { 1265 1265 enum{Count = COUNT_OF(OptionMenu)}; 1266 1266 studio_menu_init(impl.menu, OptionMenu, 1267 - Count, Count - 5, COUNT_OF(GameMenu) - 3, showGameMenu, NULL); 1267 + Count, Count - 4, COUNT_OF(GameMenu) - 3, showGameMenu, NULL); 1268 1268 } 1269 1269 1270 1270 static const char* KeysList[] = ··· 1336 1336 {"X ", NULL, &XKeyOption}, 1337 1337 {"Y ", NULL, &YKeyOption}, 1338 1338 1339 - {"", NULL}, 1339 + {""}, 1340 1340 {"SAVE MAPPING", saveGamepadMenu}, 1341 1341 {"RESET TO DEFAULTS", resetGamepadMenu}, 1342 - {"BACK", showOptionsMenu}, 1342 + {"BACK", showOptionsMenu, .back = true}, 1343 1343 }; 1344 1344 1345 1345 GamepadMapping = getConfig()->options.mapping;