Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
HUDSurfaceClass.h
1/* Renegade Scripts.dll
2 Copyright 2023 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12
13#pragma once
14
15#include "engine_string.h"
16#include "engine_vector.h"
17#include "vector2.h"
18#include "vector4.h"
19#include "rect.h"
20
21typedef enum {
22 HUD_ELEMENT_LINE,
23 HUD_ELEMENT_RECTANGLE,
24 HUD_ELEMENT_OUTLINE,
25 HUD_ELEMENT_TEXT,
26 HUD_ELEMENT_MAX // Do NOT use!
27} HUDElementType;
28
29typedef enum {
30 HUD_FONT_TITLE,
31 HUD_FONT_BIG_HEADER,
32 HUD_FONT_SMALL_HEADER,
33 HUD_FONT_BIG_BODY,
34 HUD_FONT_NORMAL_BODY,
35 HUD_FONT_SUBTITLE,
36 HUD_FONT_MAX // Do NOT use!
37} HUDFontType;
38
39class HUDElementClass;
40class HUDLineElementClass;
41class HUDRectangleElementClass;
42class HUDOutlineElementClass;
43class HUDTextElementClass;
44
45class HUDSurfaceClass
46{
47public:
48 HUDSurfaceClass(int client, int srf_id);
49 virtual ~HUDSurfaceClass();
50
51 int Get_Surface_ID() const { return id; }
52 int Get_Client_ID() const { return clientId; }
53 bool Is_Dirty() const { return isDirty; }
54 void Set_Dirty(bool dirty) { isDirty = dirty; }
55 const RectClass& Get_Boundary_Area() const { return boundary; }
56 float Get_Aspect_Ratio() const { return boundary.Height() > WWMATH_EPSILON ? boundary.Width() / boundary.Height() : 0; }
57 const StringClass& Get_Surface_Texture() const { return surfaceTexture; }
58 void Set_Surface_Texture(const char* texture) { surfaceTexture = texture; Set_Dirty(true); }
59
60 virtual void Add_Element(HUDElementClass* element);
61 virtual HUDElementClass* Create_Element(HUDElementType type);
62 virtual HUDElementClass* Find_Element(int id);
63 virtual int Get_Element_Count();
64 virtual HUDElementClass* Get_Element_Index(int index);
65 virtual void Remove_Element(int id);
66 virtual void Remove_Element(HUDElementClass* element);
67 virtual void Clear_Elements();
68
69protected:
70 int id;
71 int clientId;
72 RectClass boundary;
73 StringClass surfaceTexture;
74 DynamicVectorClass<HUDElementClass*> elements;
75 bool isDirty;
76};
77
78class HUDElementClass
79{
80public:
81 HUDElementClass(int elem_id);
82 virtual ~HUDElementClass();
83
84 virtual HUDElementType Get_Element_Type() const = 0;
85 virtual HUDLineElementClass* As_HUDLineElementClass() { return NULL; }
86 virtual HUDRectangleElementClass* As_HUDRectangleElementClass() { return NULL; }
87 virtual HUDOutlineElementClass* As_HUDOutlineElementClass() { return NULL; }
88 virtual HUDTextElementClass* As_HUDTextElementClass() { return NULL; }
89
90 int Get_Element_ID() const { return elementId; }
91 bool Is_Dirty() const { return isDirty; }
92 void Set_Dirty(bool dirty) { isDirty = dirty; }
93 bool Is_Rendered() const { return isRendered; }
94 void Set_Rendered(bool rendered) { isRendered = rendered; Set_Dirty(true); }
95 const RectClass& Get_UV_Range() const { return uvRange; }
96 void Set_UV_Range(const RectClass& newRange) { uvRange = newRange; Set_Dirty(true); }
97
98protected:
99 int elementId;
100 bool isDirty;
101 bool isRendered;
102 RectClass uvRange;
103};
104
105class HUDLineElementClass : public HUDElementClass {
106public:
107 HUDLineElementClass(int elem_id);
108
109 virtual HUDElementType Get_Element_Type() const { return HUD_ELEMENT_LINE; }
110 virtual HUDLineElementClass* As_HUDLineElementClass() { return this; }
111
112 const Vector2& Get_P0() const { return p0; }
113 void Set_P0(const Vector2& newP0) { p0 = newP0; Set_Dirty(true); }
114 const Vector2& Get_P1() const { return p1; }
115 void Set_P1(const Vector2& newP1) { p1 = newP1; Set_Dirty(true); }
116 float Get_Length() const { return Vector2::Distance(p1, p0); }
117 float Get_Thickness() const { return thickness; }
118 void Set_Thickness(float newThickness) { thickness = newThickness; Set_Dirty(true); }
119 const Vector4& Get_Color() const { return color; }
120 void Set_Color(const Vector4& newColor) { color = newColor; Set_Dirty(true); }
121 void Set_Color(int a, int r, int g, int b) { color = Vector4(a / 255.f, r / 255.f, g / 255.f, b / 255.f); Set_Dirty(true); }
122
123protected:
124 Vector2 p0;
125 Vector2 p1;
126 float thickness;
127 Vector4 color;
128};
129
130class HUDRectangleElementClass : public HUDElementClass {
131public:
132 HUDRectangleElementClass(int elem_id);
133
134 virtual HUDElementType Get_Element_Type() const { return HUD_ELEMENT_RECTANGLE; }
135 virtual HUDRectangleElementClass* As_HUDRectangleElementClass() { return this; }
136
137 const RectClass& Get_Rect() const { return rect; }
138 void Set_Rect(const RectClass& newRect) { rect = newRect; Set_Dirty(true); }
139 float Get_Area() const { const Vector2& a = rect.getSize(); return a.X * a.Y; }
140 float Get_Diagonal_Length() const { return rect.Extent().Length() * 2; }
141 const Vector4& Get_Color() const { return color; }
142 void Set_Color(const Vector4& newColor) { color = newColor; Set_Dirty(true); }
143 void Set_Color(int a, int r, int g, int b) { color = Vector4(a / 255.f, r / 255.f, g / 255.f, b / 255.f); Set_Dirty(true); }
144
145protected:
146 RectClass rect;
147 Vector4 color;
148};
149
150class HUDOutlineElementClass : public HUDElementClass {
151public:
152 HUDOutlineElementClass(int elem_id);
153
154 virtual HUDElementType Get_Element_Type() const { return HUD_ELEMENT_OUTLINE; }
155 virtual HUDOutlineElementClass* As_HUDOutlineElementClass() { return this; }
156
157 const RectClass& Get_Rect() const { return rect; }
158 void Set_Rect(const RectClass& newRect) { rect = newRect; Set_Dirty(true); }
159 float Get_Area() const { const Vector2& a = rect.getSize(); return a.X * a.Y; }
160 float Get_Diagonal_Length() const { return rect.Extent().Length() * 2; }
161 float Get_Thickness() const { return thickness; }
162 void Set_Thickness(float newThickness) { thickness = newThickness; Set_Dirty(true); }
163 const Vector4& Get_Color() const { return color; }
164 void Set_Color(const Vector4& newColor) { color = newColor; Set_Dirty(true); }
165 void Set_Color(int a, int r, int g, int b) { color = Vector4(a / 255.f, r / 255.f, g / 255.f, b / 255.f); Set_Dirty(true); }
166
167protected:
168 RectClass rect;
169 float thickness;
170 Vector4 color;
171};
172
173class HUDTextElementClass : public HUDElementClass {
174public:
175 HUDTextElementClass(int elem_id);
176
177 virtual HUDElementType Get_Element_Type() const { return HUD_ELEMENT_TEXT; }
178 virtual HUDTextElementClass* As_HUDTextElementClass() { return this; }
179
180 const WideStringClass& Get_Text() const { return text; }
181 void Set_Text(const wchar_t* newText) { text = newText; Set_Dirty(true); }
182 HUDFontType Get_Font() const { return font; }
183 void Set_Font(HUDFontType newFont) { font = newFont; Set_Dirty(true); }
184 const RectClass& Get_Clipping_Area() const { return clipArea; }
185 void Set_Clipping_Area(const RectClass& newArea) { clipArea = newArea; Set_Dirty(true); }
186 float Get_Clipping_Area_Size() const { const Vector2& a = clipArea.getSize(); return a.X * a.Y; }
187 float Get_Clipping_Area_Diagonal_Length() const { return clipArea.Extent().Length() * 2; }
188 const Vector4& Get_Color() const { return color; }
189 void Set_Color(const Vector4& newColor) { color = newColor; Set_Dirty(true); }
190 void Set_Color(int a, int r, int g, int b) { color = Vector4(a / 255.f, r / 255.f, g / 255.f, b / 255.f); Set_Dirty(true); }
191
192protected:
193 WideStringClass text;
194 HUDFontType font;
195 RectClass clipArea;
196 Vector4 color;
197};