summaryrefslogtreecommitdiff
path: root/libcghEx.cpp
blob: 7ae9aa5790dbc3f1d6c47cc92870ea05213a9643 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//Chrisoft Bullet Lab Remix HGE
//Chrisoft Game Helper Extras implementations
//"Copyleft" Chrisoft 2013
#include "libcgh.h"
#include <cmath>
#include <cstring>
//static const char* LIBCGH_SRC_FN="libcghEx.cpp";

void CircleIndicator::Init(double _r,double _thk,BYTE _a,bool _gr,HTEXTURE _Texture,TextureRect _TR,DWORD _cc)
{
	circle=new hgeDistortionMesh(1025,3);
	circle->SetTexture(_Texture);
	circle->SetTextureRect(_TR.x,_TR.y,_TR.w,_TR.h);
	radius=_r;thk=_thk;gradient=_gr;alpha=_a;
	if (_gr)ccolour=SETA(0x00FF0000,alpha);else ccolour=_cc;
	for (int i=0;i<=1024;++i)
	{
		double tang,tx,ty;
		tang=(double)i/1024.0f*pi*2-pi/2;
		tx=-cos(tang)*radius;ty=sin(tang)*radius;
		circle->SetDisplacement(i,2,tx,ty,HGEDISP_TOPLEFT);
		tx*=thk;ty*=thk;
		circle->SetDisplacement(i,1,tx,ty,HGEDISP_TOPLEFT);
		tx*=thk;ty*=thk;
		circle->SetDisplacement(i,0,tx,ty,HGEDISP_TOPLEFT);
	}
}
void CircleIndicator::SetAlpha(BYTE _alpha){alpha=_alpha;}
void CircleIndicator::SetValue(double _value)
{
		value=_value;
		for (int i=0;i<=1024;++i)
		{
			int tr=(int)((1.0f-value)*255);
			int tg=(int)(value*255);
			DWORD tcolour=ARGB(alpha,tr,tg,0);
			hgeColorHSV *tc=new hgeColorHSV(tcolour);
			if (tc->v<0.85)tc->v=0.85;
			if (gradient)tcolour=SETA(tc->GetHWColor(),alpha);else tcolour=SETA(ccolour,alpha);
			if ((double)i/1024.0f<=value)
			{
				circle->SetColor(i,0,tcolour);
				circle->SetColor(i,1,SETA(0x00FFFFFF,alpha));
				circle->SetColor(i,2,tcolour);
			}
			else
			{
				circle->SetColor(i,0,0x00000000);
				circle->SetColor(i,1,0x00000000);
				circle->SetColor(i,2,0x00000000);
			}
		}
	}
void CircleIndicator::Render(double x,double y){circle->Render(x,y);}

void LinearProgresser::Init(double _a,double _b,double _Lim){a=_a,b=_b,Limit=_Lim;}
void LinearProgresser::Launch(){Elapsed=0;val=a;}
void LinearProgresser::Update(double DT){if (Elapsed>=Limit)return;Elapsed+=DT;val=(b-a)*(Elapsed/Limit)+a;}
double LinearProgresser::GetValue(){return val;}
double LinearProgresser::GetA(){return a;}
double LinearProgresser::GetB(){return b;}
double LinearProgresser::GetPercentage(){return (Elapsed/Limit);}
double LinearProgresser::GetDelta(){return val-a;}
double LinearProgresser::GetElapsed(){return Elapsed;}

bool HangUpText::Active(){return TFont&&!done;}
void HangUpText::Init(const char *Font,const char *_Text,double _tlim,double _alim,double _dlim,DWORD _color)
{
	TFont=new hgeFont(Font);
	strcpy(Text,_Text);
	Limit=_tlim;alim=_alim;dlim=_dlim;TFont->SetColor(_color);
	Progresser.Init(0,dlim,Limit);Progalpha.Init(0,255,Limit/2);
}
void HangUpText::Launch(vector2d pos)
{
	Position=pos;Elapsed=0;delta=0;Progresser.Launch();Progalpha.Launch();done=false;
}
void HangUpText::Process(double DT)
{
	Progresser.Update(DT);
	Position.y-=delta;
	delta=Progresser.GetDelta();
	Position.y+=delta;
	if (Progresser.GetElapsed()>Limit/2&&Progalpha.GetA()<Progalpha.GetB())
	{
		Progalpha.Init(255,0,Limit/2);
		Progalpha.Launch();
	}
	if (Progalpha.GetA()>Progalpha.GetB()&&Progresser.GetElapsed()>=Limit)return (void)(done=true);
	Progalpha.Update(DT);
	TFont->SetColor(SETA(TFont->GetColor(),Progalpha.GetValue()));
	TFont->printf(Position.x,Position.y,HGETEXT_CENTER,Text);
}