aboutsummaryrefslogtreecommitdiff
path: root/archive/blr2/src/libcghEx.cpp
blob: a8fa698f525f2770b1e2b1fd0cc42f15ed91be21 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Chrisoft Bullet Lab Remix HGE -*- C++ -*-
// Chrisoft Game Helper Extras implementations
// Copyright Chrisoft 2014
#include "libcgh.h"
#include <cmath>
#include <cstring>
//static const char* LIBCGH_SRC_FN="libcghEx.cpp";

void RandomEngine::SetSeed(unsigned int seed){cseed=seed;}
int RandomEngine::NextInt(int min,int max)
{
	if (min>max){int t=min;min=max;max=t;}
	cseed*=214013;cseed+=2531011;
	return min+(cseed^cseed>>15)%(max-min+1);
}
double RandomEngine::NextDouble(double min,double max)
{
	if (min>max){double t=min;min=max;max=t;}
	cseed*=214013;cseed+=2531011;
	return min+(cseed>>16)*(1.0f/65535.0f)*(max-min);
}
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);
		}
		delete tc;
	}
}
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+DT>=Limit)return (void)(val=b,Elapsed=Limit);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);
	TFont->SetScale(0.8);
	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)
	{
		delete TFont;TFont=0;
		return (void)(done=true);
	}
	Progalpha.Update(DT);
	if(!TFont)return;
	TFont->SetColor(SETA(TFont->GetColor(),Progalpha.GetValue()));
	TFont->printf(Position.x,Position.y,HGETEXT_CENTER,Text);
}