void ScrollView::ScrollBar::display() { int h = view->scroll_bar_bottom - view->scroll_bar_top; resize(get_w(), h * h/view->display_view->get_h()); static GUIImage top("GUIImages/scroll_bar_vert5.bmp"); static GUIImage mid("GUIImages/scroll_bar_vert7.bmp"); static GUIImage bottom("GUIImages/scroll_bar_vert6.bmp"); draw_onto_self(top, VGPoint()); for (int i = top.geth(); i < get_h()-bottom.geth(); i+=mid.geth()) { draw_onto_self(mid, VGPoint(0,i)); } draw_onto_self(bottom, VGPoint(0, get_h()-bottom.geth())); }
void ScrollView::ScrollBarBg::display() { static GUIImage top("GUIImages/scroll_bar_vert0.bmp"); static GUIImage mid("GUIImages/scroll_bar_vert4.bmp"); static GUIImage bottom("GUIImages/scroll_bar_vert1.bmp"); draw_onto_self(top, VGPoint()); view->scroll_bar_top = top.geth() - 13; // HACK!! view->scroll_bar_bottom = get_h() + 7 - (view->arrow_up.get_h()+view->arrow_down.get_h()); // HACK!! int bottom_of_drawing = view->scroll_bar_bottom-bottom.geth(); for (int i = top.geth(); i < bottom_of_drawing; i+=mid.geth()) { draw_onto_self(mid, VGPoint(0,i)); } draw_onto_self(bottom, VGPoint(0, bottom_of_drawing)); }
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)); }
void View::fill_with_color(SDL_Color color) { draw_onto_self(GUIImage::create_filled(w, h, color), DispPoint()); }