Skip to content

Commit 20d8c7e

Browse files
committed
Use SHOUT_CASE for ProjectionEye, ProjectionPlane, ColorChannelOrder
1 parent cb33417 commit 20d8c7e

File tree

3 files changed

+83
-41
lines changed

3 files changed

+83
-41
lines changed

godot-core/src/builtin/color.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,31 +368,43 @@ impl ApproxEq for Color {
368368
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
369369
pub enum ColorChannelOrder {
370370
/// RGBA channel order. Godot's default.
371-
Rgba,
371+
RGBA,
372372

373373
/// ABGR channel order. Reverse of the default RGBA order.
374-
Abgr,
374+
ABGR,
375375

376376
/// ARGB channel order. More compatible with DirectX.
377-
Argb,
377+
ARGB,
378+
}
379+
380+
#[allow(non_upper_case_globals)]
381+
impl ColorChannelOrder {
382+
#[deprecated(note = "Renamed to `ColorChannelOrder::RGBA`.")]
383+
pub const Rgba: Self = Self::RGBA;
384+
385+
#[deprecated(note = "Renamed to `ColorChannelOrder::ABGR`.")]
386+
pub const Abgr: Self = Self::ABGR;
387+
388+
#[deprecated(note = "Renamed to `ColorChannelOrder::ARGB`.")]
389+
pub const Argb: Self = Self::ARGB;
378390
}
379391

380392
impl ColorChannelOrder {
381393
fn pack<T>(self, rgba: [T; 4]) -> [T; 4] {
382394
let [r, g, b, a] = rgba;
383395
match self {
384-
ColorChannelOrder::Rgba => [r, g, b, a],
385-
ColorChannelOrder::Abgr => [a, b, g, r],
386-
ColorChannelOrder::Argb => [a, r, g, b],
396+
ColorChannelOrder::RGBA => [r, g, b, a],
397+
ColorChannelOrder::ABGR => [a, b, g, r],
398+
ColorChannelOrder::ARGB => [a, r, g, b],
387399
}
388400
}
389401

390402
fn unpack<T>(self, xyzw: [T; 4]) -> [T; 4] {
391403
let [x, y, z, w] = xyzw;
392404
match self {
393-
ColorChannelOrder::Rgba => [x, y, z, w],
394-
ColorChannelOrder::Abgr => [w, z, y, x],
395-
ColorChannelOrder::Argb => [y, z, w, x],
405+
ColorChannelOrder::RGBA => [x, y, z, w],
406+
ColorChannelOrder::ABGR => [w, z, y, x],
407+
ColorChannelOrder::ARGB => [y, z, w, x],
396408
}
397409
}
398410
}

godot-core/src/builtin/projection.rs

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ impl Projection {
122122
f2 = (f2 + add) * near;
123123

124124
match eye {
125-
ProjectionEye::Left => Self::create_frustum(-f2, f1, -f3, f3, near, far),
126-
ProjectionEye::Right => Self::create_frustum(-f1, f2, -f3, f3, near, far),
125+
ProjectionEye::LEFT => Self::create_frustum(-f2, f1, -f3, f3, near, far),
126+
ProjectionEye::RIGHT => Self::create_frustum(-f1, f2, -f3, f3, near, far),
127127
}
128128
}
129129

@@ -302,12 +302,12 @@ impl Projection {
302302
let frustumshift = (intraocular_dist * near * 0.5) / convergence_dist;
303303

304304
let (left, right, model_translation) = match eye {
305-
ProjectionEye::Left => (
305+
ProjectionEye::LEFT => (
306306
frustumshift - xmax,
307307
xmax + frustumshift,
308308
intraocular_dist / 2.0,
309309
),
310-
ProjectionEye::Right => (
310+
ProjectionEye::RIGHT => (
311311
-frustumshift - xmax,
312312
xmax - frustumshift,
313313
intraocular_dist / -2.0,
@@ -544,24 +544,45 @@ impl_godot_as_self!(Projection);
544544
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
545545
#[repr(C)]
546546
pub enum ProjectionPlane {
547-
Near = 0,
548-
Far = 1,
549-
Left = 2,
550-
Top = 3,
551-
Right = 4,
552-
Bottom = 5,
547+
NEAR = 0,
548+
FAR = 1,
549+
LEFT = 2,
550+
TOP = 3,
551+
RIGHT = 4,
552+
BOTTOM = 5,
553+
}
554+
555+
#[allow(non_upper_case_globals)]
556+
impl ProjectionPlane {
557+
#[deprecated(note = "Renamed to `ProjectionPlane::NEAR`")]
558+
pub const Near: Self = Self::NEAR;
559+
560+
#[deprecated(note = "Renamed to `ProjectionPlane::FAR`")]
561+
pub const Far: Self = Self::FAR;
562+
563+
#[deprecated(note = "Renamed to `ProjectionPlane::LEFT`")]
564+
pub const Left: Self = Self::LEFT;
565+
566+
#[deprecated(note = "Renamed to `ProjectionPlane::TOP`")]
567+
pub const Top: Self = Self::TOP;
568+
569+
#[deprecated(note = "Renamed to `ProjectionPlane::RIGHT`")]
570+
pub const Right: Self = Self::RIGHT;
571+
572+
#[deprecated(note = "Renamed to `ProjectionPlane::BOTTOM`")]
573+
pub const Bottom: Self = Self::BOTTOM;
553574
}
554575

555576
impl ProjectionPlane {
556577
/// Convert from one of GDScript's `Projection.PLANE_*` integer constants.
557578
pub fn try_from_ord(ord: i64) -> Option<Self> {
558579
match ord {
559-
0 => Some(Self::Near),
560-
1 => Some(Self::Far),
561-
2 => Some(Self::Left),
562-
3 => Some(Self::Top),
563-
4 => Some(Self::Right),
564-
5 => Some(Self::Bottom),
580+
0 => Some(Self::NEAR),
581+
1 => Some(Self::FAR),
582+
2 => Some(Self::LEFT),
583+
3 => Some(Self::TOP),
584+
4 => Some(Self::RIGHT),
585+
5 => Some(Self::BOTTOM),
565586
_ => None,
566587
}
567588
}
@@ -571,16 +592,25 @@ impl ProjectionPlane {
571592
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
572593
#[repr(C)]
573594
pub enum ProjectionEye {
574-
Left = 1,
575-
Right = 2,
595+
LEFT = 1,
596+
RIGHT = 2,
597+
}
598+
599+
#[allow(non_upper_case_globals)]
600+
impl ProjectionEye {
601+
#[deprecated(note = "Renamed to `ProjectionEye::LEFT`")]
602+
pub const Left: Self = Self::LEFT;
603+
604+
#[deprecated(note = "Renamed to `ProjectionEye::RIGHT`")]
605+
pub const Right: Self = Self::RIGHT;
576606
}
577607

578608
impl ProjectionEye {
579609
/// Convert from numbers `1` and `2`.
580610
pub fn try_from_ord(ord: i64) -> Option<Self> {
581611
match ord {
582-
1 => Some(Self::Left),
583-
2 => Some(Self::Right),
612+
1 => Some(Self::LEFT),
613+
2 => Some(Self::RIGHT),
584614
_ => None,
585615
}
586616
}

itest/rust/src/builtin_tests/color_test.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ fn color_from_rgba8() {
2121
fn color_from_u32() {
2222
const D: f32 = 255.0;
2323
assert_eq!(
24-
Color::from_u32_rgba(0x01020304, ColorChannelOrder::Rgba),
24+
Color::from_u32_rgba(0x01020304, ColorChannelOrder::RGBA),
2525
Color::from_rgba(1.0 / D, 2.0 / D, 3.0 / D, 4.0 / D)
2626
);
2727
assert_eq!(
28-
Color::from_u32_rgba(0x01020304, ColorChannelOrder::Abgr),
28+
Color::from_u32_rgba(0x01020304, ColorChannelOrder::ABGR),
2929
Color::from_rgba(4.0 / D, 3.0 / D, 2.0 / D, 1.0 / D)
3030
);
3131
assert_eq!(
32-
Color::from_u32_rgba(0x01020304, ColorChannelOrder::Argb),
32+
Color::from_u32_rgba(0x01020304, ColorChannelOrder::ARGB),
3333
Color::from_rgba(2.0 / D, 3.0 / D, 4.0 / D, 1.0 / D)
3434
);
3535
}
@@ -38,15 +38,15 @@ fn color_from_u32() {
3838
fn color_from_u64() {
3939
const D: f32 = 65535.0;
4040
assert_eq!(
41-
Color::from_u64_rgba(0x0001000200030004, ColorChannelOrder::Rgba),
41+
Color::from_u64_rgba(0x0001000200030004, ColorChannelOrder::RGBA),
4242
Color::from_rgba(1.0 / D, 2.0 / D, 3.0 / D, 4.0 / D)
4343
);
4444
assert_eq!(
45-
Color::from_u64_rgba(0x0001000200030004, ColorChannelOrder::Abgr),
45+
Color::from_u64_rgba(0x0001000200030004, ColorChannelOrder::ABGR),
4646
Color::from_rgba(4.0 / D, 3.0 / D, 2.0 / D, 1.0 / D)
4747
);
4848
assert_eq!(
49-
Color::from_u64_rgba(0x0001000200030004, ColorChannelOrder::Argb),
49+
Color::from_u64_rgba(0x0001000200030004, ColorChannelOrder::ARGB),
5050
Color::from_rgba(2.0 / D, 3.0 / D, 4.0 / D, 1.0 / D)
5151
);
5252
}
@@ -100,17 +100,17 @@ fn color_blend() {
100100
#[itest]
101101
fn color_to_u32() {
102102
let c = Color::from_html("#01020304").unwrap();
103-
assert_eq!(c.to_u32(ColorChannelOrder::Rgba), 0x01020304);
104-
assert_eq!(c.to_u32(ColorChannelOrder::Abgr), 0x04030201);
105-
assert_eq!(c.to_u32(ColorChannelOrder::Argb), 0x04010203);
103+
assert_eq!(c.to_u32(ColorChannelOrder::RGBA), 0x01020304);
104+
assert_eq!(c.to_u32(ColorChannelOrder::ABGR), 0x04030201);
105+
assert_eq!(c.to_u32(ColorChannelOrder::ARGB), 0x04010203);
106106
}
107107

108108
#[itest]
109109
fn color_to_u64() {
110110
let c = Color::from_html("#01020304").unwrap();
111-
assert_eq!(c.to_u64(ColorChannelOrder::Rgba), 0x0101_0202_0303_0404);
112-
assert_eq!(c.to_u64(ColorChannelOrder::Abgr), 0x0404_0303_0202_0101);
113-
assert_eq!(c.to_u64(ColorChannelOrder::Argb), 0x0404_0101_0202_0303);
111+
assert_eq!(c.to_u64(ColorChannelOrder::RGBA), 0x0101_0202_0303_0404);
112+
assert_eq!(c.to_u64(ColorChannelOrder::ABGR), 0x0404_0303_0202_0101);
113+
assert_eq!(c.to_u64(ColorChannelOrder::ARGB), 0x0404_0101_0202_0303);
114114
}
115115

116116
// Multiple specific cases because HSV->RGB conversion algorithm used is very dependent on Hue value, taking into account different values

0 commit comments

Comments
 (0)