Beispiel #1
0
void View::resize(int w_, int h_) {
    
    if (w == w_ && h == h_) {
        
        did_resize(w_,h_);
        return;
    }
    
    w = w_; h = h_;
    View temp(w,h);

    std::swap(image, temp.image);
    std::swap(display, temp.display);
    
    if (is_alpha) {
        set_clear_color(clear_color);
        fill_with_color(clear_color);
    }
    
    SDL_Rect dest_rect = {0, 0, w, h};
	SDL_BlitSurface(temp.image, 0, image, &dest_rect);

    mark_changed();
    did_resize(w_,h_);
}
MsgNew::MsgNew(int w_, int h_, const std::string& msg_, Button_ctrs_t buttons_)
:View(w_,h_), msg_text(new TextView(w_-10, h_-10)), buttons(buttons_)
{    
    attach_subview(msg_text, VGPoint(get_w()/2 - msg_text->get_w()/2, 5));
   
    fill_with_color(color);
    set_msg(msg_);
    msg_text->set_text_size(20);
    
    for (size_t i = 0; i < buttons_.size(); i++) {
        add_button(buttons_[i]);
    }
    
}
// 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;
}
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());
    
}
Beispiel #5
0
/**
 * \brief Fills the entire surface with the specified color.
 *
 * If the color has a non-opaque alpha component, then the color is
 * alpha-blended onto the surface.
 *
 * \param color A color.
 */
void Surface::fill_with_color(const Color& color) {

  fill_with_color(color, Rectangle(0, 0, width, height));
}