예제 #1
0
bool DropDownMenu::handle_mouse_up(DispPoint coord) {

    if (!clicked) {
        return false;
    }
    
    clicked = false;

    // Find clicked row
    int row_size = text_size + vertical_padding*2;
    selected_entry_idx = coord.y / row_size;    
    
    // order matters incase entries is empty to avoid -1
    if (selected_entry_idx >= entries.size())
        { selected_entry_idx = entries.size()-1; }
    if (selected_entry_idx <= 0)
        { selected_entry_idx = 0; }
    
    update_menu_view();
    resize(get_w(), row_size);
    
    int vert_adj = -selected_entry_idx * row_size; // (move subview up)
    move_subview(menu, DispPoint(0, vert_adj)); // move correct entry to visible
    get_parent()->move_subview(this, pre_click_pos);

    lose_focus();
    
    return true;
}
예제 #2
0
void ScrollView::move_scroll_bar_to(VGPoint pos) {
    
    
    const double display_scroll_range = display_view->get_h() - get_h();
    const double scroll_bar_range = scroll_bar_bottom + 7 - scroll_bar_top - scroll_bar.get_h();
    
    if (pos.y < scroll_bar_top) {
        pos.y = scroll_bar_top;
    }
    if (pos.y > scroll_bar_range) {
        pos.y = scroll_bar_range;
    }
    move_subview(&scroll_bar, pos);
    
    const double ratio = display_scroll_range / scroll_bar_range;
    
    scroll_y = pos.y * ratio;
    
    move_subview(display_view, VGPoint(0, -scroll_y));
    
}
예제 #3
0
void ScrollView::move_display_to(VGPoint pos) {
    
    const double display_scroll_range = display_view->get_h() - get_h();
    const double scroll_bar_range = scroll_bar_bottom - scroll_bar_top - scroll_bar.get_h();
    
    scroll_y = pos.y;
    
    if (scroll_y < 0) {
        scroll_y = 0;
        scroll_y_vel = 0;
    }
    if (scroll_y > display_scroll_range) {
        scroll_y = display_scroll_range;
        scroll_y_vel = 0;
    }
    move_subview(display_view, VGPoint(pos.x, -scroll_y));
    
    int scroll_bar_pos = scroll_bar_top + (scroll_y / display_scroll_range * scroll_bar_range);
    
    move_subview(&scroll_bar, VGPoint(scroll_bar_x, scroll_bar_pos));
    
}
예제 #4
0
// Mouse Events. Following three functions all work the same:
//  Returns true if the mouse-event is finished being handled.
//  If returns false, handling will continue up the chain.
//  May optionally call capture_focus() to become the target for keypresses.
bool DropDownMenu::handle_mouse_down(DispPoint coord) {
    
    capture_focus();
    
    if (clicked) {
        return false;
    }
    
    clicked = true;
    pre_click_pos = get_rel_pos();

    resize(get_w(), menu->get_h());
    fill_with_color(get_clear_color());

    int vert_adj = -selected_entry_idx * (text_size + vertical_padding*2); // (up)
    move_subview(menu, DispPoint()); // reset menu subview
    get_parent()->move_subview(this, get_rel_pos() + DispPoint(0,vert_adj));
    
    return true;
}