/* ----------------------------------------------------------------------------
 * Draws the textbox. It's basically a rectangle with a border.
 * The border is drawn line by line. Finally, it draws the
 * text within.
 */
void textbox::draw_self() {
    al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color());
    draw_line(this, DRAW_LINE_TOP,    0, 1, 0, get_darker_bg_color());  // Top line.
    draw_line(this, DRAW_LINE_LEFT,   0, 1, 0, get_darker_bg_color());  // Left line.
    draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, get_lighter_bg_color()); // Bottom line.
    draw_line(this, DRAW_LINE_RIGHT,  1, 0, 0, get_lighter_bg_color()); // Right line.
    
    if(style->text_font) {
        int text_start = x1 + 2 - scroll_x;
        
        if(parent->focused_widget == this) {
            al_draw_filled_rectangle(
                text_start + al_get_text_width(style->text_font, text.substr(0, min(sel_start, sel_end)).c_str()),
                y1 + 2,
                text_start + al_get_text_width(style->text_font, text.substr(0, max(sel_start, sel_end)).c_str()),
                y2 - 2,
                get_alt_color()
            );
        }
        
        al_draw_text(style->text_font, get_fg_color(), text_start, (y2 + y1) / 2  - al_get_font_line_height(style->text_font) / 2, 0, text.c_str());
        
        unsigned int cursor_x = al_get_text_width(style->text_font, text.substr(0, cursor).c_str());
        
        if(parent->focused_widget == this) {
            al_draw_line(
                x1 + cursor_x + 1.5 - scroll_x,
                y1 + 2,
                x1 + cursor_x + 1.5 - scroll_x,
                y2 - 2,
                get_alt_color(),
                1);
        }
    }
}
Example #2
0
/* ----------------------------------------------------------------------------
 * Draws the checkbox box. It's just a square with a fancy border.
 * The latter is drawn line by line. It also draws the checkmark,
 * if the box is ticked.
 */
void checkbox_box::draw_self() {
    al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color());
    //Top line.
    draw_line(this, DRAW_LINE_TOP,    0, 1, 0, get_darker_bg_color());
    //Left line.
    draw_line(this, DRAW_LINE_LEFT,   0, 1, 0, get_darker_bg_color());
    //Bottom line.
    draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, get_lighter_bg_color());
    //Right line.
    draw_line(this, DRAW_LINE_RIGHT,  1, 0, 0, get_lighter_bg_color());
    
    if(checked) {
        //Southeast-going line.
        al_draw_line(x1 + 2.5, y1 + 6.5, x1 + 5.5, y1 + 9.5, get_fg_color(), 3);
        //Northeast-going line.
        al_draw_line(x1 + 3.5, y1 + 9.5, x1 + 10,  y1 + 3,   get_fg_color(), 3);
    }
}
Example #3
0
/* ----------------------------------------------------------------------------
 * Draws the actual frame. Like the frame of a painting, this
 * is basically a rectangle and a border.
 */
void frame::draw_self() {
    al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color());
    //Top line, outermost.
    draw_line(this, DRAW_LINE_TOP,    0, 1, 0, get_lighter_bg_color());
    //Top line, innermost.
    draw_line(this, DRAW_LINE_TOP,    1, 2, 1, get_darker_bg_color());
    //Left line, outermost.
    draw_line(this, DRAW_LINE_LEFT,   0, 1, 0, get_lighter_bg_color());
    //Left line, innermost.
    draw_line(this, DRAW_LINE_LEFT,   1, 2, 1, get_darker_bg_color());
    //Bottom line, outermost.
    draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, get_darker_bg_color());
    //Bottom line, innermost.
    draw_line(this, DRAW_LINE_BOTTOM, 2, 1, 1, get_lighter_bg_color());
    //Right line, outermost.
    draw_line(this, DRAW_LINE_RIGHT,  1, 0, 0, get_darker_bg_color());
    //Right line, innermost.
    draw_line(this, DRAW_LINE_RIGHT,  2, 1, 1, get_lighter_bg_color());
}
/* ----------------------------------------------------------------------------
 * Draws the circle and the pointer.
 */
void angle_picker::draw_self() {
    float circle_r = (y2 - y1) / 2;
    float circle_cx = x1 + circle_r;
    float circle_cy = y1 + circle_r;
    al_draw_filled_circle(circle_cx, circle_cy, circle_r, get_bg_color());
    al_draw_arc(circle_cx, circle_cy, circle_r, M_PI_2 + M_PI_4, M_PI, get_darker_bg_color(), 1);
    al_draw_arc(circle_cx, circle_cy, circle_r, M_PI_2 + M_PI_4 + M_PI, M_PI, get_lighter_bg_color(), 1);
    al_draw_line(
        circle_cx, circle_cy,
        circle_cx + cos(angle) * circle_r,
        circle_cy + sin(angle) * circle_r,
        get_fg_color(), 2
    );
}
/* ----------------------------------------------------------------------------
 * Draws the scrollbar. The button can draw itself, but this widget
 * draws the harness.
 */
void scrollbar::draw_self() {
    int w = x2 - x1;
    int h = y2 - y1;
    
    if(vertical) {
        al_draw_filled_rectangle(
            x1 + w / 2 - 2,
            y1 + 0.5,
            x1 + w / 2 + 2,
            y2 - 0.5,
            get_bg_color()
        );
        al_draw_line(
            x1 + w / 2 - 0.5,
            y1 + 0.5,
            x1 + w / 2 - 0.5,
            y2 - 0.5,
            get_lighter_bg_color(),
            1
        );
        al_draw_line(
            x1 + w / 2 + 0.5,
            y1 + 0.5,
            x1 + w / 2 + 0.5,
            y2 - 0.5,
            get_darker_bg_color(),
            1
        );
        al_draw_line(x1 + w / 2 - 4, y1 + 0.5, x1 + w / 2 + 4, y1 + 0.5, get_lighter_bg_color(), 1);
        al_draw_line(x1 + w / 2 - 4, y1 + 1.5, x1 + w / 2 + 4, y1 + 1.5, get_darker_bg_color(),  1);
        al_draw_line(x1 + w / 2 - 4, y2 - 0.5, x1 + w / 2 + 4, y2 - 0.5, get_darker_bg_color(),  1);
        al_draw_line(x1 + w / 2 - 4, y2 - 1.5, x1 + w / 2 + 4, y2 - 1.5, get_lighter_bg_color(), 1);
        
    } else { //Horizontal bar.
    
        al_draw_filled_rectangle(
            x1 + 0.5,
            y1 + h / 2 - 2,
            x2 - 0.5,
            y1 + h / 2 + 2,
            get_bg_color()
        );
        al_draw_line(
            x1 + 0.5,
            y1 + h / 2 - 0.5,
            x2 - 0.5,
            y1 + h / 2 - 0.5,
            get_lighter_bg_color(),
            1
        );
        al_draw_line(
            x1 + 0.5,
            y1 + h / 2 + 0.5,
            x2 - 0.5,
            y1 + h / 2 + 0.5,
            get_darker_bg_color(),
            1
        );
        al_draw_line(x1 + 0.5, y1 + h / 2 - 4, x1 + 0.5, y1 + h / 2 + 4, get_lighter_bg_color(), 1);
        al_draw_line(x1 + 1.5, y1 + h / 2 - 4, x1 + 1.5, y1 + h / 2 + 4, get_darker_bg_color(),  1);
        al_draw_line(x2 - 0.5, y1 + h / 2 - 4, x2 - 0.5, y1 + h / 2 + 4, get_darker_bg_color(),  1);
        al_draw_line(x2 - 1.5, y1 + h / 2 - 4, x2 - 1.5, y1 + h / 2 + 4, get_lighter_bg_color(), 1);
        
    }
}
Example #6
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);
    }
}