share/gui: don't use less of widget width for truncation than available
[neverball] / share / item.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #include "item.h"
16 #include "glext.h"
17 #include "vec3.h"
18 #include "solid_gl.h"
19 #include "image.h"
20 #include "config.h"
21
22 /*---------------------------------------------------------------------------*/
23
24 static struct s_file item_coin_file;
25 static struct s_file item_grow_file;
26 static struct s_file item_shrink_file;
27
28 void item_color(const struct s_item *hp, float *c)
29 {
30     switch (hp->t)
31     {
32
33     case ITEM_COIN:
34
35         if (hp->n >= 1)
36         {
37             c[0] = 1.0f;
38             c[1] = 1.0f;
39             c[2] = 0.2f;
40         }
41         if (hp->n >= 5)
42         {
43             c[0] = 1.0f;
44             c[1] = 0.2f;
45             c[2] = 0.2f;
46         }
47         if (hp->n >= 10)
48         {
49             c[0] = 0.2f;
50             c[1] = 0.2f;
51             c[2] = 1.0f;
52         }
53         break;
54
55     case ITEM_GROW:
56
57         c[0] = 0.00f;
58         c[1] = 0.51f;
59         c[2] = 0.80f;
60
61         break;
62
63     case ITEM_SHRINK:
64
65         c[0] = 1.00f;
66         c[1] = 0.76f;
67         c[2] = 0.00f;
68
69         break;
70
71     default:
72
73         c[0] = 1.0f;
74         c[1] = 1.0f;
75         c[2] = 1.0f;
76
77         break;
78     }
79 }
80
81 void item_init(void)
82 {
83     int T = config_get_d(CONFIG_TEXTURES);
84
85     sol_load_gl(&item_coin_file,   "item/coin/coin.sol",     T, 0);
86     sol_load_gl(&item_grow_file,   "item/grow/grow.sol",     T, 0);
87     sol_load_gl(&item_shrink_file, "item/shrink/shrink.sol", T, 0);
88 }
89
90 void item_free(void)
91 {
92     sol_free_gl(&item_coin_file);
93     sol_free_gl(&item_grow_file);
94     sol_free_gl(&item_shrink_file);
95 }
96
97 void item_push(int type)
98 {
99     glEnable(GL_COLOR_MATERIAL);
100 }
101
102 void item_draw(const struct s_item *hp, float r)
103 {
104     float c[3];
105     struct s_file *fp = NULL;
106
107     switch (hp->t)
108     {
109     case ITEM_COIN:   fp = &item_coin_file;   break;
110     case ITEM_GROW:   fp = &item_grow_file;   break;
111     case ITEM_SHRINK: fp = &item_shrink_file; break;
112     }
113
114     item_color(hp, c);
115
116     glColor3fv(c);
117     sol_draw(fp, 0, 1);
118 }
119
120 void item_pull(void)
121 {
122     glColor3f(1.0f, 1.0f, 1.0f);
123     glDisable(GL_COLOR_MATERIAL);
124 }
125
126 /*---------------------------------------------------------------------------*/
127