~ubuntu-branches/ubuntu/dapper/newt/dapper

« back to all changes in this revision

Viewing changes to scale.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-03-22 12:44:37 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050322124437-nuhl0pqjcijjno9z
Tags: 0.51.6-20ubuntu3
Add Xhosa translation (thanks, Adi Attar).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <slang.h>
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
 
5
 
#include "newt.h"
6
 
#include "newt_pr.h"
7
 
 
8
 
struct scale {
9
 
    long long fullValue;
10
 
    int charsSet;
11
 
};
12
 
 
13
 
static void scaleDraw(newtComponent co);
14
 
 
15
 
static struct componentOps scaleOps = {
16
 
    scaleDraw,
17
 
    newtDefaultEventHandler,
18
 
    NULL,
19
 
    newtDefaultPlaceHandler,
20
 
    newtDefaultMappedHandler,
21
 
} ;
22
 
 
23
 
newtComponent newtScale(int left, int top, int width, long long fullValue) {
24
 
    newtComponent co;
25
 
    struct scale * sc;
26
 
 
27
 
    co = malloc(sizeof(*co));
28
 
    sc = malloc(sizeof(struct scale));
29
 
    co->data = sc;
30
 
 
31
 
    co->ops = &scaleOps;
32
 
 
33
 
    co->height = 1;
34
 
    co->width = width;
35
 
    co->top = top;
36
 
    co->left = left;
37
 
    co->takesFocus = 0;
38
 
 
39
 
    sc->fullValue = fullValue;
40
 
    sc->charsSet = 0;
41
 
 
42
 
    return co;
43
 
}
44
 
 
45
 
void newtScaleSet(newtComponent co, unsigned long long amount) {
46
 
    struct scale * sc = co->data;
47
 
    int newCharsSet;
48
 
 
49
 
    newCharsSet = (amount * co->width) / sc->fullValue;
50
 
    
51
 
    if (newCharsSet != sc->charsSet) {
52
 
        sc->charsSet = newCharsSet;
53
 
        scaleDraw(co);
54
 
    }
55
 
}
56
 
 
57
 
static void scaleDraw(newtComponent co) {
58
 
    struct scale * sc = co->data;
59
 
    int c;
60
 
    int i;
61
 
 
62
 
    if (co->top == -1) return;
63
 
 
64
 
    newtGotorc(co->top, co->left);
65
 
 
66
 
    c = SLtt_Use_Ansi_Colors ? ' ' : '-';
67
 
    newtColor(NEWT_COLORSET_FULLSCALE);
68
 
    for (i = 0; i < sc->charsSet; i++)
69
 
        SLsmg_write_char(c);
70
 
 
71
 
    newtColor(NEWT_COLORSET_EMPTYSCALE);
72
 
    for (i = 0; i < (co->width - sc->charsSet); i++)
73
 
        SLsmg_write_char(c);
74
 
}