1use std::ffi::c_void;
2
3pub mod events;
4pub mod functions;
5
6pub use functions::load_functions;
7
8use crate::{
9 players::Player,
10 types::colour::Colour,
11 types::vector::{Vector2, Vector3},
12};
13
14pub struct TextDraw {
15 handle: *const c_void,
16}
17
18#[deny(non_snake_case)]
19impl TextDraw {
20 pub fn get_handle(&self) -> *const c_void {
21 self.handle
22 }
23 pub fn new(handle: *const c_void) -> Self {
24 Self { handle }
25 }
26 pub fn create(position: Vector2, text: &str) -> Option<TextDraw> {
28 let mut _id = -1;
29
30 functions::TextDraw_Create(position.x, position.y, text, &mut _id)
31 }
32 pub fn destroy(&self) -> bool {
34 functions::TextDraw_Destroy(self)
35 }
36 pub fn is_shown_for_player(&self, player: &Player) -> bool {
37 functions::TextDraw_IsVisibleForPlayer(player, self)
38 }
39 pub fn set_letter_size(&self, size: Vector2) -> bool {
40 functions::TextDraw_SetLetterSize(self, size.x, size.y)
41 }
42 pub fn set_text_size(&self, size: Vector2) -> bool {
43 functions::TextDraw_SetTextSize(self, size.x, size.y)
44 }
45 pub fn set_alignment(&self, alignment: TextDrawAlignmentTypes) -> bool {
46 functions::TextDraw_SetAlignment(self, alignment as i32)
47 }
48 pub fn set_color(&self, colour: Colour) -> bool {
49 functions::TextDraw_SetColor(self, colour.rgba())
50 }
51 pub fn use_box(&self, use_box: bool) -> bool {
53 functions::TextDraw_SetUseBox(self, use_box)
54 }
55 pub fn set_box_color(&self, colour: Colour) -> bool {
56 functions::TextDraw_SetBoxColor(self, colour.rgba())
57 }
58 pub fn set_shadow(&self, size: i32) -> bool {
60 functions::TextDraw_SetShadow(self, size)
61 }
62 pub fn set_outline(&self, size: i32) -> bool {
64 functions::TextDraw_SetOutline(self, size)
65 }
66 pub fn set_background_color(&self, colour: Colour) -> bool {
67 functions::TextDraw_SetBackgroundColor(self, colour.rgba())
68 }
69 pub fn set_style(&self, font: TextDrawStyle) -> bool {
70 functions::TextDraw_SetFont(self, font as i32)
71 }
72 pub fn set_proportional(&self, set: bool) -> bool {
74 functions::TextDraw_SetSetProportional(self, set)
75 }
76 pub fn set_selectable(&self, set: bool) -> bool {
78 functions::TextDraw_SetSelectable(self, set)
79 }
80 pub fn show_for_player(&self, player: &Player) -> bool {
82 functions::TextDraw_ShowForPlayer(player, self)
83 }
84 pub fn hide_for_player(&self, player: &Player) -> bool {
86 functions::TextDraw_HideForPlayer(player, self)
87 }
88 pub fn show_for_all(&self) -> bool {
90 functions::TextDraw_ShowForAll(self)
91 }
92 pub fn hide_for_all(&self) -> bool {
94 functions::TextDraw_HideForAll(self)
95 }
96 pub fn set_string(&self, text: &str) -> bool {
98 functions::TextDraw_SetString(self, text)
99 }
100 pub fn set_preview_model(&self, model: i32) -> bool {
102 functions::TextDraw_SetPreviewModel(self, model)
103 }
104 pub fn set_preview_rotation(&self, rotation: Vector3, zoom: f32) -> bool {
105 functions::TextDraw_SetPreviewRot(self, rotation.x, rotation.y, rotation.z, zoom)
106 }
107 pub fn set_preview_veh_colour(&self, colour1: i32, colour2: i32) -> bool {
108 functions::TextDraw_SetPreviewVehCol(self, colour1, colour2)
109 }
110 pub fn set_pos(&self, pos: Vector2) -> bool {
112 functions::TextDraw_SetPos(self, pos.x, pos.y)
113 }
114 pub fn get_string(&self) -> String {
116 let mut text = String::new();
117 functions::TextDraw_GetString(self, &mut text, 16);
118 text
119 }
120 pub fn get_letter_size(&self) -> Vector2 {
122 let mut size = Vector2::default();
123 functions::TextDraw_GetLetterSize(self, &mut size.x, &mut size.y);
124 size
125 }
126 pub fn get_text_size(&self) -> Vector2 {
128 let mut size = Vector2::default();
129 functions::TextDraw_GetTextSize(self, &mut size.x, &mut size.y);
130 size
131 }
132 pub fn get_pos(&self) -> Vector2 {
134 let mut pos = Vector2::default();
135 functions::TextDraw_GetPos(self, &mut pos.x, &mut pos.y);
136 pos
137 }
138 pub fn get_color(&self) -> Colour {
140 Colour::from_rgba(functions::TextDraw_GetColor(self) as u32)
141 }
142 pub fn get_box_color(&self) -> Colour {
144 Colour::from_rgba(functions::TextDraw_GetBoxColor(self) as u32)
145 }
146 pub fn get_background_color(&self) -> Colour {
148 Colour::from_rgba(functions::TextDraw_GetBackgroundColor(self) as u32)
149 }
150 pub fn get_shadow(&self) -> i32 {
152 functions::TextDraw_GetShadow(self)
153 }
154 pub fn get_outline(&self) -> i32 {
156 functions::TextDraw_GetOutline(self)
157 }
158 pub fn get_style(&self) -> i32 {
159 functions::TextDraw_GetFont(self)
160 }
161 pub fn is_box(&self) -> bool {
163 functions::TextDraw_IsBox(self)
164 }
165 pub fn is_proportional(&self) -> bool {
167 functions::TextDraw_IsProportional(self)
168 }
169 pub fn is_selectable(&self) -> bool {
171 functions::TextDraw_IsSelectable(self)
172 }
173 pub fn get_alignment(&self) -> TextDrawAlignmentTypes {
175 unsafe { std::mem::transmute(functions::TextDraw_GetAlignment(self)) }
176 }
177 pub fn get_preview_model(&self) -> i32 {
179 functions::TextDraw_GetPreviewModel(self)
180 }
181 pub fn get_preview_rotation(&self) -> (Vector3, f32) {
182 let mut rotation = Vector3::default();
183 let mut zoom = 0.0;
184 functions::TextDraw_GetPreviewRot(
185 self,
186 &mut rotation.x,
187 &mut rotation.y,
188 &mut rotation.z,
189 &mut zoom,
190 );
191 (rotation, zoom)
192 }
193 pub fn get_preview_veh_colour(&self) -> (i32, i32) {
194 let mut colour1 = 0;
195 let mut colour2 = 0;
196 functions::TextDraw_GetPreviewVehColor(self, &mut colour1, &mut colour2);
197 (colour1, colour2)
198 }
199 pub fn set_string_for_player(&self, player: &Player, text: &str) -> bool {
201 functions::TextDraw_SetStringForPlayer(self, player, text)
202 }
203 pub fn get_id(&self) -> i32 {
204 functions::TextDraw_GetID(self)
205 }
206 pub fn from_id(id: i32) -> Option<TextDraw> {
207 functions::TextDraw_FromID(id)
208 }
209}
210
211pub struct PlayerTextDraw {
212 handle: *const c_void,
213 pub player: Player,
214}
215
216impl PlayerTextDraw {
217 pub fn get_handle(&self) -> *const c_void {
218 self.handle
219 }
220 pub fn new(handle: *const c_void, player: Player) -> Self {
221 Self { handle, player }
222 }
223 pub fn is_shown(&self) -> bool {
224 functions::PlayerTextDraw_IsVisible(&self.player, self)
225 }
226 pub fn set_letter_size(&self, size: Vector2) -> bool {
227 functions::PlayerTextDraw_SetLetterSize(&self.player, self, size.x, size.y)
228 }
229 pub fn set_text_size(&self, size: Vector2) -> bool {
230 functions::PlayerTextDraw_SetTextSize(&self.player, self, size.x, size.y)
231 }
232 pub fn alignment(&self, alignment: TextDrawAlignmentTypes) -> bool {
234 functions::PlayerTextDraw_SetAlignment(&self.player, self, alignment as i32)
235 }
236 pub fn color(&self, colour: Colour) -> bool {
238 functions::PlayerTextDraw_SetColor(&self.player, self, colour.rgba())
239 }
240 pub fn use_box(&self, box_use: bool) -> bool {
242 functions::PlayerTextDraw_UseBox(&self.player, self, box_use)
243 }
244 pub fn set_box_color(&self, colour: Colour) -> bool {
245 functions::PlayerTextDraw_SetBoxColor(&self.player, self, colour.rgba())
246 }
247 pub fn set_shadow(&self, size: i32) -> bool {
249 functions::PlayerTextDraw_SetShadow(&self.player, self, size)
250 }
251 pub fn set_outline(&self, size: i32) -> bool {
253 functions::PlayerTextDraw_SetOutline(&self.player, self, size)
254 }
255 pub fn background_color(&self, colour: Colour) -> bool {
257 functions::PlayerTextDraw_SetBackgroundColor(&self.player, self, colour.rgba())
258 }
259 pub fn set_style(&self, font: TextDrawStyle) -> bool {
260 functions::PlayerTextDraw_SetFont(&self.player, self, font as i32)
261 }
262 pub fn set_proportional(&self, set: bool) -> bool {
264 functions::PlayerTextDraw_SetProportional(&self.player, self, set)
265 }
266 pub fn set_selectable(&self, set: bool) -> bool {
268 functions::PlayerTextDraw_SetSelectable(&self.player, self, set)
269 }
270 pub fn show(&self) -> bool {
272 functions::PlayerTextDraw_Show(&self.player, self)
273 }
274 pub fn hide(&self) -> bool {
276 functions::PlayerTextDraw_Hide(&self.player, self)
277 }
278 pub fn set_string(&self, text: &str) -> bool {
280 functions::PlayerTextDraw_SetString(&self.player, self, text)
281 }
282 pub fn set_preview_model(&self, model: i32) -> bool {
284 functions::PlayerTextDraw_SetPreviewModel(&self.player, self, model)
285 }
286 pub fn set_preview_rotation(&self, rotation: Vector3, zoom: f32) -> bool {
287 functions::PlayerTextDraw_SetPreviewRot(
288 &self.player,
289 self,
290 rotation.x,
291 rotation.y,
292 rotation.z,
293 zoom,
294 )
295 }
296 pub fn set_preview_veh_colour(&self, colour1: i32, colour2: i32) -> bool {
297 functions::PlayerTextDraw_SetPreviewVehCol(&self.player, self, colour1, colour2)
298 }
299 pub fn set_pos(&self, pos: Vector2) -> bool {
301 functions::PlayerTextDraw_SetPos(&self.player, self, pos.x, pos.y)
302 }
303 pub fn get_string(&self) -> String {
305 let mut text = String::new();
306 functions::PlayerTextDraw_GetString(&self.player, self, &mut text, 16);
307 text
308 }
309 pub fn get_letter_size(&self) -> Vector2 {
311 let mut size = Vector2::default();
312 functions::PlayerTextDraw_GetLetterSize(&self.player, self, &mut size.x, &mut size.y);
313 size
314 }
315 pub fn get_text_size(&self) -> Vector2 {
317 let mut size = Vector2::default();
318 functions::PlayerTextDraw_GetTextSize(&self.player, self, &mut size.x, &mut size.y);
319 size
320 }
321 pub fn get_pos(&self) -> Vector2 {
323 let mut pos = Vector2::default();
324 functions::PlayerTextDraw_GetPos(&self.player, self, &mut pos.x, &mut pos.y);
325 pos
326 }
327 pub fn get_color(&self) -> Colour {
329 Colour::from_rgba(functions::PlayerTextDraw_GetColor(&self.player, self) as u32)
330 }
331 pub fn get_box_color(&self) -> Colour {
333 Colour::from_rgba(functions::PlayerTextDraw_GetBoxColor(&self.player, self) as u32)
334 }
335 pub fn get_background_colour(&self) -> Colour {
337 Colour::from_rgba(functions::PlayerTextDraw_GetBackgroundColor(&self.player, self) as u32)
338 }
339 pub fn get_shadow(&self) -> i32 {
341 functions::PlayerTextDraw_GetShadow(&self.player, self)
342 }
343 pub fn get_outline(&self) -> i32 {
345 functions::PlayerTextDraw_GetOutline(&self.player, self)
346 }
347 pub fn get_style(&self) -> i32 {
348 functions::PlayerTextDraw_GetFont(&self.player, self)
349 }
350 pub fn is_box(&self) -> bool {
352 functions::PlayerTextDraw_IsBox(&self.player, self)
353 }
354 pub fn is_proportional(&self) -> bool {
356 functions::PlayerTextDraw_IsProportional(&self.player, self)
357 }
358 pub fn is_selectable(&self) -> bool {
360 functions::PlayerTextDraw_IsSelectable(&self.player, self)
361 }
362 pub fn get_alignment(&self) -> TextDrawAlignmentTypes {
364 unsafe { std::mem::transmute(functions::PlayerTextDraw_GetAlignment(&self.player, self)) }
365 }
366 pub fn get_preview_model(&self) -> i32 {
368 functions::PlayerTextDraw_GetPreviewModel(&self.player, self)
369 }
370 pub fn get_preview_rotation(&self) -> (Vector3, f32) {
371 let mut rotation = Vector3::default();
372 let mut zoom = 0.0;
373 functions::PlayerTextDraw_GetPreviewRot(
374 &self.player,
375 self,
376 &mut rotation.x,
377 &mut rotation.y,
378 &mut rotation.z,
379 &mut zoom,
380 );
381 (rotation, zoom)
382 }
383 pub fn get_preview_veh_colour(&self) -> (i32, i32) {
384 let mut colour1 = 0;
385 let mut colour2 = 0;
386 functions::PlayerTextDraw_GetPreviewVehColor(
387 &self.player,
388 self,
389 &mut colour1,
390 &mut colour2,
391 );
392 (colour1, colour2)
393 }
394 pub fn get_id(&self) -> i32 {
395 functions::PlayerTextDraw_GetID(&self.player, self)
396 }
397 pub fn from_id(selfid: i32, player: &Player) -> Option<PlayerTextDraw> {
398 functions::PlayerTextDraw_FromID(player, selfid)
399 }
400}
401
402#[repr(C)]
403#[derive(PartialEq, Clone, Copy, Debug, Default)]
404pub enum TextDrawAlignmentTypes {
405 #[default]
406 Default,
407 Left,
408 Center,
409 Right,
410}
411
412#[repr(C)]
413#[derive(PartialEq, Clone, Copy, Debug)]
414pub enum TextDrawStyle {
415 FontBeckettRegular = 0,
416 FontAharoniBold,
417 FontBankGothic,
418 FontPricedown,
419 Sprite,
420 Preview,
421}