/* ----------------------------------------------------------------------------
 * Draws a button widget.
 */
void menu_button::draw(const float time_spent) {
    if(!font || !enabled) return;
    
    al_draw_rounded_rectangle(
        center.x - size.x * 0.5, center.y - size.y * 0.5,
        center.x + size.x * 0.5, center.y + size.y * 0.5,
        16, 16, al_map_rgba(255, 255, 255, 32), 2
    );
    
    if(selected) {
        draw_bitmap(
            bmp_icon, point(center.x - size.x * 0.5 + 16, center.y),
            point(16, 16),
            sin(time_spent * ICON_SWAY_TIME_SCALE) * ICON_SWAY_DELTA
        );
        draw_bitmap(
            bmp_icon, point(center.x + size.x * 0.5 - 16, center.y),
            point(16, 16),
            sin(time_spent * ICON_SWAY_TIME_SCALE) * ICON_SWAY_DELTA
        );
    }
    
    int text_x = center.x;
    if(text_align == ALLEGRO_ALIGN_LEFT) {
        text_x = center.x - size.x * 0.5 + 32;
    } else if(text_align == ALLEGRO_ALIGN_RIGHT) {
        text_x = center.x + size.x * 0.5 - 32;
    }
    
    draw_text_lines(
        font, text_color,
        point(text_x, center.y),
        text_align, 1, text
    );
}
Example #2
0
void winbox::draw()
{
	m_graphics->Clear(m_back_color);

	std::string err;
	lua_guard g(m_lvm);
	lua_call_object_function(err, m_lvm, this, "on_draw");
	log_err(err.c_str());
	draw_text_lines();
}
Example #3
0
/* ----------------------------------------------------------------------------
 * Draws the button. It' just a rectangle with a fancy border;
 * the latter is drawn one line at a time.
 */
void button::draw_self() {
    unsigned int w = x2 - x1;
    unsigned int h = y2 - y1;
    
    ALLEGRO_COLOR top_color, bottom_color;
    if(mouse_clicking && mouse_in) {
        top_color =    get_darker_bg_color();
        bottom_color = get_lighter_bg_color();
    } else {
        top_color =    get_lighter_bg_color();
        bottom_color = get_darker_bg_color();
    }
    
    al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color());
    //Top line, outermost.
    draw_line(this, DRAW_LINE_TOP,    0, 1, 0, top_color);
    //Top line, innermost.
    draw_line(this, DRAW_LINE_TOP,    0, 2, 1, top_color);
    //Left line, outermost.
    draw_line(this, DRAW_LINE_LEFT,   0, 1, 0, top_color);
    //Left line, innermost.
    draw_line(this, DRAW_LINE_LEFT,   0, 2, 1, top_color);
    //Bottom line, outermost.
    draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, bottom_color);
    //Bottom line, innermost.
    draw_line(this, DRAW_LINE_BOTTOM, 2, 0, 1, bottom_color);
    //Right line, outermost.
    draw_line(this, DRAW_LINE_RIGHT,  1, 0, 0, bottom_color);
    //Right line, innermost.
    draw_line(this, DRAW_LINE_RIGHT,  2, 0, 1, bottom_color);
    
    //This is the center of the text, not top left. Also, relative coordinates.
    signed short final_text_y = 0;
    //Top left of the icon.
    signed short final_icon_y = 0;
    
    if(icon && text.size()) {
        //If there's an icon and text.
        unsigned short total_height =
            al_get_bitmap_height(icon) +
            al_get_font_line_height(style->text_font) + 2;
        //The icon goes to the top of the 2.
        final_icon_y = h / 2 - total_height / 2;
        //The text uses the same base y as the icon, except lowered, obviously.
        final_text_y =
            final_icon_y + al_get_bitmap_height(icon) +
            al_get_font_line_height(style->text_font) / 2 + 2;
            
    } else if(icon) {    //Icon, but no text.
        final_icon_y = h / 2 - al_get_bitmap_height(icon) / 2;
        
    } else if(!icon && text.size()) {    //Text, but no icon.
        final_text_y = h / 2;
    }
    
    if(icon) {
        al_draw_bitmap(
            icon,
            x1 + (w / 2 - al_get_bitmap_width(icon) / 2),
            y1 + final_icon_y,
            0);
    }
    
    if(text.size()) {
        draw_text_lines(
            style->text_font,
            get_fg_color(),
            x1 + (w / 2),
            y1 + final_text_y,
            ALLEGRO_ALIGN_CENTRE,
            true,
            text);
    }
}