static void vscrollby(uiArea *a, int delta) { struct scrollParams p; vscrollParams(a, &p); scrollby(a, SB_VERT, &p, delta); }
static void hscrollby(uiArea *a, int delta) { struct scrollParams p; hscrollParams(a, &p); scrollby(a, SB_HORZ, &p, delta); }
/** * Call string_input_win / ui_element_input::input_filter and filter the entries list interactively */ std::string uimenu::inputfilter() { std::string identifier = ""; // @todo: uimenu.filter_identifier ? mvwprintz(window, w_height - 1, 2, border_color, "< "); mvwprintz(window, w_height - 1, w_width - 3, border_color, " >"); /* //debatable merit std::string origfilter = filter; int origselected = selected; int origfselected = fselected; int origvshift = vshift; */ string_input_popup popup; popup.text( filter ) .max_length( 256 ) .window( window, 4, w_height - 1, w_width - 4 ) .identifier( identifier ); input_event event; #ifdef __ANDROID__ if( get_option<bool>( "ANDROID_AUTO_KEYBOARD" ) ) { SDL_StartTextInput(); } #endif do { // filter=filter_input->query(filter, false); filter = popup.query_string( false ); event = popup.context().get_raw_input(); // key = filter_input->keypress; if ( event.get_first_input() != KEY_ESCAPE ) { if( !scrollby( scroll_amount_from_key( event.get_first_input() ) ) ) { filterlist(); } show(); } } while(event.get_first_input() != '\n' && event.get_first_input() != KEY_ESCAPE); if ( event.get_first_input() == KEY_ESCAPE ) { /* //perhaps as an option filter = origfilter; selected = origselected; fselected = origfselected; vshift = origvshift; */ filterlist(); } wattron(window, border_color); for( int i = 1; i < w_width - 1; i++ ) { mvwaddch(window, w_height - 1, i, LINE_OXOX); } wattroff(window, border_color); return filter; }
/* * Call string_input_win / ui_element_input::input_filter and filter the entries list interactively */ std::string uimenu::inputfilter() { std::string identifier = ""; // todo: uimenu.filter_identifier ? long key = 0; int spos = -1; mvwprintz(window, w_height - 1, 2, border_color, "< "); mvwprintz(window, w_height - 1, w_width - 3, border_color, " >"); /* //debatable merit std::string origfilter = filter; int origselected = selected; int origfselected = fselected; int origvshift = vshift; */ do { // filter=filter_input->query(filter, false); filter = string_input_win( window, filter, 256, 4, w_height - 1, w_width - 4, false, key, spos, identifier, 4, w_height - 1 ); // key = filter_input->keypress; if ( key != KEY_ESCAPE ) { if ( scrollby(0, key) == false ) { filterlist(); } show(); } } while(key != '\n' && key != KEY_ESCAPE); if ( key == KEY_ESCAPE ) { /* //perhaps as an option filter = origfilter; selected = origselected; fselected = origfselected; vshift = origvshift; */ filterlist(); } wattron(window, border_color); for( int i = 1; i < w_width - 1; i++ ) { mvwaddch(window, w_height-1, i, LINE_OXOX); } wattroff(window, border_color); return filter; }
/* * Handle input and update display */ void uimenu::query(bool loop) { keypress = 0; if ( entries.empty() ) { return; } int startret = UIMENU_INVALID; ret = UIMENU_INVALID; bool keycallback = (callback != NULL ); show(); do { bool skiprefresh = false; bool skipkey = false; keypress = getch(); if ( scrollby(0, keypress) == true ) { /* nothing */ } else if ( filtering && ( keypress == '/' || keypress == '.' ) ) { inputfilter(); } else if ( !fentries.empty() && ( keypress == '\n' || keypress == KEY_ENTER || keymap.find(keypress) != keymap.end() ) ) { if ( keymap.find(keypress) != keymap.end() ) { selected = keymap[ keypress ];//fixme ? } if( entries[ selected ].enabled ) { ret = entries[ selected ].retval; // valid } else if ( return_invalid ) { ret = 0 - entries[ selected ].retval; // disabled } } else if ( keypress == KEY_ESCAPE && return_invalid) { //break loop with ESCAPE key break; } else { if ( keycallback ) { skipkey = callback->key( keypress, selected, this ); } if ( ! skipkey && return_invalid ) { ret = -1; } } if ( skiprefresh == false ) { show(); } } while ( loop && (ret == startret ) ); }
static void wheelscroll(uiArea *a, int which, struct scrollParams *p, WPARAM wParam, LPARAM lParam) { int delta; int lines; UINT scrollAmount; delta = GET_WHEEL_DELTA_WPARAM(wParam); if (SystemParametersInfoW(p->wheelSPIAction, 0, &scrollAmount, 0) == 0) // TODO use scrollAmount == 3 (for both v and h) instead? logLastError(L"error getting area wheel scroll amount"); if (scrollAmount == WHEEL_PAGESCROLL) scrollAmount = p->pagesize; if (scrollAmount == 0) // no mouse wheel scrolling (or t->pagesize == 0) return; // the rest of this is basically http://blogs.msdn.com/b/oldnewthing/archive/2003/08/07/54615.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/08/11/54624.aspx // see those pages for information on subtleties delta += *(p->wheelCarry); lines = delta * ((int) scrollAmount) / WHEEL_DELTA; *(p->wheelCarry) = delta - lines * WHEEL_DELTA / ((int) scrollAmount); scrollby(a, which, p, -lines); }
/** * 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 ) ); }