Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
122 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
122 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
122 theseven 9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
122 theseven 14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
122 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "progressbar.h"
26
#include "lcd.h"
27
 
28
 
124 theseven 29
static void progressbar_drawborderbg(struct progressbar_state* state, int bgstart)
122 theseven 30
{
31
    state->currentx = state->startx;
124 theseven 32
    displaylcd(bgstart + 1, state->endx - 1, state->starty + 1, state->endy - 1,
122 theseven 33
               (void*)-1, state->bgcolor);
34
    displaylcd(state->startx, state->endx, state->starty, state->starty,
35
               (void*)-1, state->bordercolor);
36
    displaylcd(state->startx, state->endx, state->endy, state->endy,
37
               (void*)-1, state->bordercolor);
38
    displaylcd(state->startx, state->startx, state->starty + 1, state->endy - 1,
39
               (void*)-1, state->bordercolor);
40
    displaylcd(state->endx, state->endx, state->starty + 1, state->endy - 1,
41
               (void*)-1, state->bordercolor);
42
}
43
 
44
void progressbar_init(struct progressbar_state* state, int startx, int endx, int starty, int endy,
45
                      int bordercolor, int bgcolor, int fgcolor, int min, int max)
46
{
47
    state->startx = startx;
48
    state->endx = endx;
49
    state->starty = starty;
50
    state->endy = endy;
51
    state->bordercolor = bordercolor;
52
    state->bgcolor = bgcolor;
53
    state->fgcolor = fgcolor;
54
    state->min = min;
55
    state->max = max;
124 theseven 56
    progressbar_drawborderbg(state, state->startx);
122 theseven 57
}
58
 
59
void progressbar_setpos(struct progressbar_state* state, int value, bool redraw)
60
{
61
    if (value > state->max) value = state->max;
62
    if (value < state->min) value = state->min;
63
    int newx = (value - state->min) * (state->endx - state->startx - 1)
64
             / (state->max - state->min) + state->startx;
124 theseven 65
    if (redraw || newx < state->currentx) progressbar_drawborderbg(state, newx);
122 theseven 66
    if (newx > state->currentx)
67
        displaylcd(state->currentx + 1, newx, state->starty + 1, state->endy - 1,
68
                   (void*)-1, state->fgcolor);
69
    state->currentx = newx;
70
}