]> icculus.org git repositories - divverent/nexuiz.git/blob - menu/cursor.qc
grappling hook
[divverent/nexuiz.git] / menu / cursor.qc
1 ///////////////////////////////////////////////
2 // Cursor Source File
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains all cursor specific functions
6 ///////////////////////////////////////////////
7
8 void(void) cursor_reset =
9 {
10         cursor_x = rint(GFX_WIDTH /2);
11         cursor_y = rint(GFX_HEIGHT /2);
12
13         cursor_rel = '0 0 0';
14
15         cursor_last_frame_time = time;
16         cursor_color = CURSOR_COLOR;
17         cursor_transparency = CURSOR_TRANSPARENCY;
18         cursor_type = CT_NORMAL;
19 };
20
21 void(void) cursor_toggle =
22 {
23         cursor_x = rint(GFX_WIDTH /2);
24         cursor_y = rint(GFX_HEIGHT /2);
25         cursor_type = CT_NORMAL;
26 };
27
28 void(void) cursor_init =
29 {
30         // load the images
31         if(CF_NORMAL != "")
32                 CF_NORMAL = gfx_loadpic(CF_NORMAL, CURSOR_ENFORCELOADING);
33
34         if(CF_NORMAL == "")
35                 CF_NORMAL = gfx_loadpic("ui/mousepointer.tga", true); // always
36
37         if(CF_PULSE_0 != "")
38                 CF_PULSE_0 = gfx_loadpic(CF_PULSE_0, CURSOR_ENFORCELOADING);
39         if(CF_PULSE_1 != "")
40                 CF_PULSE_1 = gfx_loadpic(CF_PULSE_1, CURSOR_ENFORCELOADING);
41         if(CF_PULSE_2 != "")
42                 CF_PULSE_2 = gfx_loadpic(CF_PULSE_2, CURSOR_ENFORCELOADING);
43         if(CF_PULSE_3 != "")
44                 CF_PULSE_3 = gfx_loadpic(CF_PULSE_3, CURSOR_ENFORCELOADING);
45         if(CF_PULSE_4 != "")
46                 CF_PULSE_4 = gfx_loadpic(CF_PULSE_4, CURSOR_ENFORCELOADING);
47         if(CF_PULSE_5 != "")
48                 CF_PULSE_5 = gfx_loadpic(CF_PULSE_5, CURSOR_ENFORCELOADING);
49         if(CF_PULSE_6 != "")
50                 CF_PULSE_6 = gfx_loadpic(CF_PULSE_6, CURSOR_ENFORCELOADING);
51
52         // init the values
53         cursor_reset();
54 };
55
56 void(void) cursor_shutdown =
57 {
58         if(CF_NORMAL != "")
59                 gfx_unloadpic(CF_NORMAL);
60         if(CF_PULSE_0 != "")
61                 gfx_unloadpic(CF_PULSE_0);
62         if(CF_PULSE_1 != "")
63                 gfx_unloadpic(CF_PULSE_1);
64         if(CF_PULSE_2 != "")
65                 gfx_unloadpic(CF_PULSE_2);
66         if(CF_PULSE_3 != "")
67                 gfx_unloadpic(CF_PULSE_3);
68         if(CF_PULSE_4 != "")
69                 gfx_unloadpic(CF_PULSE_4);
70         if(CF_PULSE_5 != "")
71                 gfx_unloadpic(CF_PULSE_5);
72         if(CF_PULSE_6 != "")
73                 gfx_unloadpic(CF_PULSE_6);
74 };
75
76 void(void) cursor_frame =
77 {
78         // update cursor animations
79
80         if(cursor_type > CT_LAST_PULSE || cursor_type  < CT_FIRST_PULSE)
81                 cursor_last_frame_time = time;
82         else if(cursor_last_frame_time + CA_PULSE_SPEED <= time)
83                 {
84                 cursor_type = CT_FIRST_PULSE +
85                 mod((time - cursor_last_frame_time) / CA_PULSE_SPEED, CT_LAST_PULSE - CT_FIRST_PULSE +1);
86
87                 cursor_last_frame_time += rint((time - cursor_last_frame_time) / CA_PULSE_SPEED) * CA_PULSE_SPEED;
88                 }
89
90         // update cursor position
91         cursor_rel = getmousepos();
92         cursor_rel = gfx_converttogfx(cursor_rel);
93         // cursor speed, etc
94         cursor_rel = cursor_rel * CURSOR_SPEED;
95         cursor = cursor + cursor_rel;
96
97         cursor_x = bound(0, cursor_x, GFX_WIDTH);
98         cursor_y = bound(0, cursor_y, GFX_HEIGHT);
99 };
100
101 void(void) cursor_draw =
102 {
103         string pic;
104
105         if(cursor_type == CT_FIRST_PULSE + 0 && CF_PULSE_0 != "")
106                 pic = CF_PULSE_0;
107         else if(cursor_type == CT_FIRST_PULSE + 1 && CF_PULSE_1 != "")
108                 pic = CF_PULSE_1;
109         else if(cursor_type == CT_FIRST_PULSE + 2 && CF_PULSE_2 != "")
110                 pic = CF_PULSE_2;
111         else if((cursor_type == CT_FIRST_PULSE + 3 || cursor_type == CT_GLOW) && CF_PULSE_3 != "")
112                 pic = CF_PULSE_3;
113         else if(cursor_type == CT_FIRST_PULSE + 4 && CF_PULSE_4 != "")
114                 pic = CF_PULSE_4;
115         else if(cursor_type == CT_FIRST_PULSE + 5 && CF_PULSE_5 != "")
116                 pic = CF_PULSE_5;
117         else if(cursor_type == CT_FIRST_PULSE + 6 && CF_PULSE_6 != "")
118                 pic = CF_PULSE_6;
119         else // if(cursor_tpye = CT_NORMAL)
120                 pic = CF_NORMAL;
121
122         gfx_drawpic(cursor,pic, gfx_getimagesize(pic) * CURSOR_SCALE, cursor_color, cursor_transparency, 0);
123 };