void Gate::calculate_output() { auto t = get_type(); vector<int> ou (8); for (int i = 0; i < 8; ++i) { switch (t) { case 'a': ou[i] = ((total_gates[get_first_input()].get_output()[i]) && (total_gates[get_second_input()].get_output()[i])); break; case 'o': ou[i] = (total_gates[get_first_input()].get_output()[i] || total_gates[get_second_input()].get_output()[i]); break; case 'n': ou[i] = !(total_gates[get_first_input()].get_output()[i]); break; } } set_output(ou); }
/** * Handle input and update display * */ void uimenu::query( bool loop, int timeout ) { bool new_interface = dynamic_cast<uilist *>( this ) != nullptr; keypress = 0; if ( entries.empty() ) { if( new_interface ) { ret = UIMENU_ERROR; } return; } ret = ( new_interface ? UIMENU_WAIT_INPUT : UIMENU_INVALID ); input_context ctxt( input_category ); ctxt.register_updown(); ctxt.register_action( "PAGE_UP" ); ctxt.register_action( "PAGE_DOWN" ); ctxt.register_action( "SCROLL_UP" ); ctxt.register_action( "SCROLL_DOWN" ); if( new_interface ? allow_cancel : return_invalid ) { ctxt.register_action( "QUIT" ); } ctxt.register_action( "CONFIRM" ); ctxt.register_action( "FILTER" ); ctxt.register_action( "ANY_INPUT" ); ctxt.register_action( "HELP_KEYBINDINGS" ); for ( const auto &additional_action : additional_actions ) { ctxt.register_action( additional_action.first, additional_action.second ); } hotkeys = ctxt.get_available_single_char_hotkeys( hotkeys ); show(); #ifdef __ANDROID__ for (const auto& entry : entries) { if (entry.hotkey > 0 && entry.enabled) ctxt.register_manual_key(entry.hotkey, entry.txt); } #endif do { const auto action = ctxt.handle_input( timeout ); const auto event = ctxt.get_raw_input(); keypress = event.get_first_input(); const auto iter = keymap.find( keypress ); if( scrollby( scroll_amount_from_action( action ) ) ) { /* nothing */ } else if ( action == "HELP_KEYBINDINGS" ) { /* nothing, handled by input_context */ } else if ( filtering && action == "FILTER" ) { inputfilter(); } else if( iter != keymap.end() ) { selected = iter->second; if( entries[ selected ].enabled ) { ret = entries[ selected ].retval; // valid } else if( !new_interface && return_invalid ) { ret = 0 - entries[ selected ].retval; // disabled } else if( new_interface && allow_disabled ) { ret = entries[selected].retval; // disabled } } else if ( !fentries.empty() && action == "CONFIRM" ) { if( entries[ selected ].enabled ) { ret = entries[ selected ].retval; // valid } else if ( !new_interface && return_invalid ) { ret = 0 - entries[ selected ].retval; // disabled } else if( new_interface && allow_disabled ) { ret = entries[selected].retval; // disabled } } else if( ( !new_interface || allow_cancel ) && action == "QUIT" ) { if( new_interface ) { ret = UIMENU_CANCEL; } else { break; } } else if( action == "TIMEOUT" ) { ret = UIMENU_TIMEOUT; } else { bool unhandled = callback == nullptr || !callback->key( ctxt, event, selected, this ); if( unhandled && ( new_interface ? allow_anykey : return_invalid ) ) { ret = new_interface ? UIMENU_UNBOUND : -1; } } show(); } while( loop && ret == ( new_interface ? UIMENU_WAIT_INPUT : UIMENU_INVALID ) ); }