// 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; }
bool ScrollView::ScrollBar::handle_mouse_motion(VGPoint coord, VGPoint rel_motion) { if (!clicked) return false; // const double scroll_bar_range = view->scroll_bar_bottom - view->scroll_bar_top; // // double offset = coord.y / scroll_bar_range; // double display_range = view->display_view->get_h() - (double)view->get_h(); // // int new_y = offset * display_range; // view->scroll_y = new_y; // view->scroll_y_vel = 0; // const double display_scroll_range = view->display_view->get_h() - view->get_h(); // const double scroll_bar_range = view->scroll_bar_bottom - view->scroll_bar_top; // // const double ratio = display_scroll_range / scroll_bar_range; // // int old_pos = get_rel_pos().y; // // int new_pos = old_pos + rel_motion.y; // // // view->scroll_y += rel_motion.y ; // view->scroll_y_vel = 0; int old_pos = get_rel_pos().y; int new_pos = old_pos + rel_motion.y; cout << "MOTION: " << rel_motion.y << " " << new_pos << endl; VGPoint new_coord = adjust_to_parent(coord - click); view->move_scroll_bar_to(VGPoint(view->scroll_bar_x, new_coord.y)); return true; }