Project

General

Profile

Revision 286

many changes. added transparency to rectangles

View differences:

rectangle.c
9 9
    int16_t  x, y;
10 10
    uint16_t w, h;
11 11
    uint32_t fill_color;
12
    uint8_t  fill_alpha;
12 13
    uint32_t outline_color;
13 14
    int16_t  outline_width;
14 15
};
......
21 22
    ret->w = w;
22 23
    ret->h = h;
23 24
    ret->fill_color    = 0xFFFFFF;
25
    ret->fill_alpha    = 0xFF;
24 26
    ret->outline_color = 0x000000;
25 27
    ret->outline_width = 0;
26 28
    return ret;
......
33 35
void (rectangle_set_pos)          (rectangle_t *p,  int16_t x,  int16_t y){ p->x = x; p->y = y; }
34 36
void (rectangle_set_size)         (rectangle_t *p, uint16_t w, uint16_t h){ p->w = w; p->h = h; }
35 37
void (rectangle_set_fill_color)   (rectangle_t *p, uint32_t color        ){ p->fill_color = color; }
38
void (rectangle_set_fill_trans)   (rectangle_t *p, uint8_t  alpha        ){ p->fill_alpha = alpha; }
36 39
void (rectangle_set_outline_color)(rectangle_t *p, uint32_t color        ){ p->outline_color = color; }
37 40
void (rectangle_set_outline_width)(rectangle_t *p,  int16_t width        ){ p->outline_width = width; }
38 41

  
......
52 55
        graph_set_pixel(x_, y, color);
53 56
    }
54 57
}
55

  
56 58
static void (rectangle_draw_vline)(int16_t x, int16_t y, int16_t l, uint32_t color){
57 59
    if(l < 0){ rectangle_draw_vline(x, y+l, -l, color); return; }
58 60
    for(int16_t y_ = max(0,y); y_ < min(y+l,graph_get_YRes()); ++y_){
......
61 63
}
62 64

  
63 65
void (rectangle_draw)(const rectangle_t *p){
64
    for(int16_t y = max(p->y,0); y < min(p->y+p->h, graph_get_YRes()); ++y)
65
        rectangle_draw_hline(p->x, y, p->w, p->fill_color);
66

  
66
    /// fill
67
    if(p->fill_alpha > ALPHA_THRESHOLD)
68
        for(int16_t y = max(p->y,0); y < min(p->y+p->h, graph_get_YRes()); ++y)
69
            rectangle_draw_hline(p->x, y, p->w, p->fill_color);
70
    /// border
67 71
    int16_t step = (p->outline_width > 0 ? 1 : -1);
68 72
    int16_t l = p->x, r = p->x+p->w, t = p->y, b = p->y+p->h;
69 73
    if(step > 0){

Also available in: Unified diff