PageRenderTime 28ms CodeModel.GetById 18ms app.highlight 9ms RepoModel.GetById 0ms app.codeStats 0ms

/planet/Objects.c4d/HUD.c4d/Elements.c4d/Bars.c4d/Script.c

https://bitbucket.org/randrian/openclonk2
C | 72 lines | 44 code | 15 blank | 13 comment | 3 complexity | f0b9a9611e80d0c4ef7d3e4ae0e2579d MD5 | raw file
Possible License(s): WTFPL, 0BSD, LGPL-2.1, CC-BY-3.0
 1#strict 2
 2
 3/*
 4	Progress-Bar element
 5	
 6	This object can show an unlimited amount of progress bars in different
 7	locations, sizes and colors. Using this basic funcionality, one could create
 8	floating health bars attached to clonks or include the bars as layers into
 9	(HUD) objects.
10*/
11
12local offsx, offsy, layer, width, height;
13
14protected func Construction()
15{
16	offsx = CreateArray();
17	offsy = CreateArray();
18	width = CreateArray();
19	height = CreateArray();
20	layer = CreateArray();
21}
22
23public func SetBarOffset(int x, int y, int num)
24{
25	offsx[num] = x;
26	offsy[num] = y;
27}
28
29public func RemoveBarLayers(int la)
30{
31	// remove layers
32	SetGraphics(nil,nil,nil,la);
33	SetGraphics(nil,nil,nil,la+1);
34}
35
36public func SetBarLayers(int la, int num)
37{
38	RemoveBarLayers(la);
39
40	// new layers
41	layer[num] = la;
42	SetGraphics("Empty",BAR0,layer[num],GFXOV_MODE_Base);
43	SetGraphics("Bar",BAR0,layer[num]+1,GFXOV_MODE_Base);
44}
45
46public func SetBarDimensions(int wdt, int hgt, int num)
47{
48	width[num] = 1000 * wdt / BAR0->GetDefWidth();
49	height[num] = 1000 * hgt / BAR0->GetDefHeight();
50}
51
52public func SetBarProgress(int promille, int num)
53{
54	// not existing
55	if(GetLength(layer) <= num) return false;
56
57	// width/height not set == 1000
58	if(!width[num]) width[num] = 1000;
59	if(!height[num]) height[num] = 1000;
60
61	var w = BAR0->GetDefWidth()/2;
62	
63	// the bar does not start on the left side of the graphics... correct this
64	var graphicscorrect = 100;
65	
66	var baroffset = offsx[num]*1000 - width[num]*w * (1000-promille)/(1000+graphicscorrect);
67
68	SetObjDrawTransform(width[num],0,offsx[num]*1000, 0, height[num], offsy[num]*1000, layer[num]);
69	SetObjDrawTransform((promille * width[num])/1000,0, baroffset, 0, height[num], offsy[num]*1000, layer[num]+1);
70
71	return true;
72}