MenuEntry(const string &text, int text_size, DropDownMenu &menu_, int index_) :TextButton(text), menu(menu_), index(index_) { button_text->set_text_size(text_size); set_image(GUIImage("GUIImages/dropdown_row.bmp")); set_hovered_image(GUIImage("GUIImages/dropdown_row_hl.bmp")); set_clicked_image(GUIImage("GUIImages/dropdown_row_hl.bmp")); }
void DropDownMenu::update_menu_view() { // always display at least one entry menu->draw_onto_self(GUIImage("GUIImages/dropdown_row.bmp"), DispPoint()); // display full menu int row_size = (text_size + vertical_padding*2); for (int i = 0; i < entries.size(); ++i) { menu->draw_onto_self(GUIImage("GUIImages/dropdown_row.bmp"), DispPoint(0, i * row_size)); } }
void DropDownMenu::init_menu_view(int text_size_) { // Init main view resize(get_w(), text_size_ + vertical_padding*2); text_size = text_size_; selected_entry_idx = 0; menu = 0; clicked = false; set_clear_color(green_color_c); fill_with_color(get_clear_color()); // Init menu view int row_size = (text_size + vertical_padding*2); menu = new View(get_w(), (int)(entries.size() ? entries.size() : 1) * row_size); // always display at least one entry menu->draw_onto_self(GUIImage("GUIImages/dropdown_row.bmp"), DispPoint()); // display full menu int i = 0; for (list<string>::iterator it = entries.begin(); it != entries.end(); ++it, ++i) { // menu->attach_subview(new MenuEntry(*it, text_size, *this, i), // DispPoint(0, i * row_size)); menu->draw_onto_self(GUIImage("GUIImages/dropdown_row.bmp"), DispPoint(0, i * row_size)); menu->attach_subview(createTextView(*it, text_size), DispPoint(0, i * row_size)); } attach_subview(menu, DispPoint()); }
ScrollView::ScrollView(int w_, int h_, View *display_view_) :View(w_,h_), scroll_bar(SCROLL_BAR_W, h_ * h_/display_view_->get_h(), this), scroll_bar_bg(SCROLL_BAR_W, h_, this), arrow_up(true, GUIImage("GUIImages/scroll_bar_vert2.bmp")), arrow_down(false, GUIImage("GUIImages/scroll_bar_vert3.bmp")), display_view(display_view_), w_init(w_), h_init(h_), scroll_y(0), scroll_y_vel(0), scrolling(false) { SDL_Color clear = {0xff, 0, 0xff}; GUIImage bg = GUIImage::create_filled(w_, h_, clear); draw_onto_self(bg, VGPoint()); set_clear_color(clear); attach_subview(display_view_, VGPoint()); if (display_view->get_h() <= get_h()) { scrollable = false; resize(min(display_view->get_w(), w_), min(display_view->get_h(), h_)); return; // todo Remove to so you can resize later. } scrollable = true; scroll_bar_bg.display(); scroll_bar.display(); scroll_bar_x = get_w()-scroll_bar_bg.get_w(); attach_subview(&scroll_bar_bg, VGPoint(scroll_bar_x, 0)); attach_subview(&arrow_up, VGPoint(scroll_bar_x, scroll_bar_bottom-7)); // HACK!! attach_subview(&arrow_down, VGPoint(scroll_bar_x, scroll_bar_bottom-7+arrow_up.get_h())); // HACK!! attach_subview(&scroll_bar, VGPoint(scroll_bar_x, scroll_bar_top)); }
bool DropDownMenu::handle_mouse_motion(DispPoint coord, DispPoint rel_motion) { if (!clicked) { return false; } int row_size = (text_size + vertical_padding*2); int row_to_hl = coord.y / row_size; update_menu_view(); menu->draw_onto_self(GUIImage("GUIImages/dropdown_row_hl.bmp"), DispPoint(0, row_to_hl * row_size)); return true; }