Skip to content

Commit 2c8f2cc

Browse files
committed
Normalized enum cases
1 parent 2a22d03 commit 2c8f2cc

File tree

11 files changed

+212
-133
lines changed

11 files changed

+212
-133
lines changed

src/examples/heat_haze.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ pub fn main() !void {
4949
while (window.pollEvent()) |event| {
5050
switch (event) {
5151
.closed => return,
52-
.keyPressed => |kp| {
52+
.key_pressed => |kp| {
5353
switch (kp.code) {
54-
.Escape => return,
55-
.Up => distortion_factor *= 2,
56-
.Down => distortion_factor /= 2,
57-
.Right => rise_factor *= 2,
58-
.Left => rise_factor /= 2,
54+
.escape => return,
55+
.up => distortion_factor *= 2,
56+
.down => distortion_factor /= 2,
57+
.right => rise_factor *= 2,
58+
.left => rise_factor /= 2,
5959
else => {},
6060
}
6161
},

src/graphics/Text.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const sf = struct {
1111
const Text = @This();
1212

1313
pub const TextStyle = enum(c_uint) {
14-
Regular = 0,
15-
Bold = 1 << 0,
16-
Italic = 1 << 1,
17-
Underlined = 1 << 2,
18-
StrikeThrough = 1 << 3,
14+
regular = 0,
15+
bold = 1 << 0,
16+
italic = 1 << 1,
17+
underlined = 1 << 2,
18+
strike_through = 1 << 3,
1919
};
2020

2121
// Constructor/destructor

src/graphics/VertexArray.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,18 @@ test "VertexArray: sane getters and setters" {
113113
.{ .position = .{ .x = 1, .y = 0 }, .color = sf.graphics.Color.Green },
114114
.{ .position = .{ .x = -1, .y = 1 }, .color = sf.graphics.Color.Blue },
115115
};
116-
var va = try createFromSlice(va_slice[0..], sf.graphics.PrimitiveType.Triangles);
116+
var va = try createFromSlice(va_slice[0..], sf.graphics.PrimitiveType.triangles);
117117
defer va.destroy();
118118

119119
va.append(.{ .position = .{ .x = 1, .y = 1 }, .color = sf.graphics.Color.Yellow });
120-
va.setPrimitiveType(sf.graphics.PrimitiveType.Quads);
120+
va.setPrimitiveType(sf.graphics.PrimitiveType.quads);
121121

122122
try tst.expectEqual(@as(usize, 4), va.getVertexCount());
123-
try tst.expectEqual(sf.graphics.PrimitiveType.Quads, va.getPrimitiveType());
123+
try tst.expectEqual(sf.graphics.PrimitiveType.quads, va.getPrimitiveType());
124124
try tst.expectEqual(sf.graphics.FloatRect{ .left = -1, .top = 0, .width = 2, .height = 1 }, va.getBounds());
125125

126126
va.resize(3);
127-
va.setPrimitiveType(sf.graphics.PrimitiveType.TriangleFan);
127+
va.setPrimitiveType(sf.graphics.PrimitiveType.triangle_fan);
128128
try tst.expectEqual(@as(usize, 3), va.getVertexCount());
129129

130130
const vert = va.getVertex(0).*;

src/graphics/VertexBuffer.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const sf = @import("../root.zig");
44

55
const VertexBuffer = @This();
66

7-
pub const Usage = enum(c_uint) { Static = 0, Dynamic = 1, Stream = 2 };
7+
pub const Usage = enum(c_uint) { static = 0, dynamic = 1, stream = 2 };
88

99
// Constructors/destructors
1010

@@ -63,10 +63,10 @@ test "VertexBuffer: sane getters and setters" {
6363
.{ .position = .{ .x = 1, .y = 0 }, .color = sf.graphics.Color.Green },
6464
.{ .position = .{ .x = -1, .y = 1 }, .color = sf.graphics.Color.Blue },
6565
};
66-
var va = try createFromSlice(va_slice[0..], sf.graphics.PrimitiveType.Triangles, Usage.Static);
66+
var va = try createFromSlice(va_slice[0..], sf.graphics.PrimitiveType.triangles, Usage.static);
6767
defer va.destroy();
6868

6969
try tst.expectEqual(@as(usize, 3), va.getVertexCount());
70-
try tst.expectEqual(sf.graphics.PrimitiveType.Triangles, va.getPrimitiveType());
71-
try tst.expectEqual(Usage.Static, va.getUsage());
70+
try tst.expectEqual(sf.graphics.PrimitiveType.triangles, va.getPrimitiveType());
71+
try tst.expectEqual(Usage.static, va.getUsage());
7272
}

src/graphics/blend_mode.zig

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ pub const BlendMode = extern struct {
55
pub const Factor = enum(c_int) {
66
zero,
77
one,
8-
srcColor,
9-
oneMinusSrcColor,
10-
dstColor,
11-
oneMinusDstColor,
12-
srcAlpha,
13-
oneMinusSrcAlpha,
14-
dstAlpha,
15-
oneMinusDstAlpha,
8+
src_color,
9+
one_minus_src_color,
10+
dst_color,
11+
one_minus_dst_color,
12+
src_alpha,
13+
one_minus_src_alpha,
14+
dst_alpha,
15+
one_minus_dst_alpha,
1616
};
1717

1818
pub const Equation = enum(c_int) {
@@ -25,16 +25,16 @@ pub const BlendMode = extern struct {
2525

2626
// Preset blend modes
2727
pub const BlendAlpha = BlendMode{
28-
.color_src_factor = .srcAlpha,
29-
.color_dst_factor = .oneMinusSrcAlpha,
28+
.color_src_factor = .src_alpha,
29+
.color_dst_factor = .one_minus_src_alpha,
3030
.color_equation = .add,
3131
.alpha_src_factor = .one,
32-
.alpha_dst_factor = .oneMinusSrcAlpha,
32+
.alpha_dst_factor = .one_minus_src_alpha,
3333
.alpha_equation = .add,
3434
};
3535

3636
pub const BlendAdd = BlendMode{
37-
.color_src_factor = .srcAlpha,
37+
.color_src_factor = .src_alpha,
3838
.color_dst_factor = .one,
3939
.color_equation = .add,
4040
.alpha_src_factor = .one,
@@ -43,10 +43,10 @@ pub const BlendMode = extern struct {
4343
};
4444

4545
pub const BlendMultiply = BlendMode{
46-
.color_src_factor = .dstColor,
46+
.color_src_factor = .dst_color,
4747
.color_dst_factor = .zero,
4848
.color_equation = .add,
49-
.alpha_src_factor = .dstColor,
49+
.alpha_src_factor = .dst_color,
5050
.alpha_dst_factor = .zero,
5151
.alpha_equation = .add,
5252
};

src/graphics/primitive_type.zig

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
const Vertex = @import("vertex.zig").Vertex;
44

55
pub const PrimitiveType = enum(c_uint) {
6-
Points,
7-
Lines,
8-
LineStrip,
9-
Triangles,
10-
TriangleStrip,
11-
TriangleFan,
12-
Quads,
6+
points,
7+
lines,
8+
line_strip,
9+
triangles,
10+
triangle_strip,
11+
triangle_fan,
12+
quads,
1313

1414
/// Gives the corresponding primitive type for primitive iteration
1515
/// See Vertex.verticesAsPrimitives()
1616
pub fn Type(comptime primitive_type: PrimitiveType) type {
1717
return switch (primitive_type) {
18-
.Points => PointPrimitive,
19-
.Lines => LinePrimitive,
20-
.Triangles => TrianglePrimitive,
21-
.Quads => QuadPrimitive,
18+
.points => PointPrimitive,
19+
.lines => LinePrimitive,
20+
.triangles => TrianglePrimitive,
21+
.quads => QuadPrimitive,
2222
else => @compileError("Primitive type not supported"),
2323
};
2424
}
2525
/// Says how many vertices each primitive is composed of
26-
pub fn packedBy(primitive_type: PrimitiveType) usize {
26+
pub fn vertexCount(primitive_type: PrimitiveType) usize {
2727
return switch (primitive_type) {
28-
.Points => 1,
29-
.Lines => 2,
30-
.Triangles => 3,
31-
.Quads => 4,
28+
.points => 1,
29+
.lines => 2,
30+
.triangles => 3,
31+
.quads => 4,
3232
else => @panic("Primitive type not supported"),
3333
};
3434
}

src/window/Cursor.zig

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,37 @@ pub const Type = enum(c_uint) {
2222
/// Pointing hand cursor
2323
hand,
2424
/// Horizontal double arrow cursor
25-
sizeHorizontal,
25+
size_horizontal,
2626
/// Vertical double arrow cursor
27-
sizeVertical,
27+
size_vertical,
2828
/// Double arrow cursor going from top-left to bottom-right
29-
sizeTopLeftBottomRight,
29+
size_top_left_bottom_right,
3030
/// Double arrow cursor going from bottom-left to top-right
31-
sizeBottomLeftTopRight,
31+
size_bottom_left_top_right,
3232
/// Left arrow cursor on Linux, same as sizeHorizontal on other platforms
33-
sizeLeft,
33+
size_left,
3434
/// Right arrow cursor on Linux, same as sizeHorizontal on other platforms
35-
sizeRight,
35+
size_right,
3636
/// Up arrow cursor on Linux, same as sizeVertical on other platforms
37-
sizeTop,
37+
size_top,
3838
/// Down arrow cursor on Linux, same as sizeVertical on other platforms
39-
sizeBottom,
39+
size_bottom,
4040
/// Top-left arrow cursor on Linux, same as sizeTopLeftBottomRight on other platforms
41-
sizeTopLeft,
41+
size_top_left,
4242
/// Bottom-right arrow cursor on Linux, same as sizeTopLeftBottomRight on other platforms
43-
sizeBottomRight,
43+
size_bottom_right,
4444
/// Bottom-left arrow cursor on Linux, same as sizeBottomLeftTopRight on other platforms
45-
sizeBottomLeft,
45+
size_bottom_left,
4646
/// Top-right arrow cursor on Linux, same as sizeBottomLeftTopRight on other platforms
47-
sizeTopRight,
47+
size_top_right,
4848
/// Combination of sizeHorizontal and sizeVertical
49-
sizeAll,
49+
size_all,
5050
/// Crosshair cursor
5151
cross,
5252
/// Help cursor
5353
help,
5454
/// Action not allowed cursor
55-
notAllowed,
55+
not_allowed,
5656
};
5757

5858
// Constructors and destructors

src/window/Joystick.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub const MaxButtonCount = 32;
1111
pub const MaxAxisCount = 8;
1212

1313
/// Joystick axis
14-
pub const Axis = enum(c_uint) { X, Y, Z, R, U, V, PovX, PovY };
14+
pub const Axis = enum(c_uint) { x, y, z, r, u, v, pov_x, pov_y };
1515

1616
/// Gets a joystick if it is connected, null if it is not
1717
/// Technically, you can use a joystick's getters if it's not connected or before it connects

src/window/event.zig

Lines changed: 41 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,35 @@ const sf = struct {
66
pub usingnamespace sfml.system;
77
};
88

9-
pub const Event = union(Event.Type) {
9+
pub const Event = union(enum) {
1010
const Self = @This();
1111

12-
pub const Type = enum(c_int) {
13-
closed,
14-
resized,
15-
lostFocus,
16-
gainedFocus,
17-
textEntered,
18-
keyPressed,
19-
keyReleased,
20-
mouseWheelScrolled,
21-
mouseButtonPressed,
22-
mouseButtonReleased,
23-
mouseMoved,
24-
mouseEntered,
25-
mouseLeft,
26-
joystickButtonPressed,
27-
joystickButtonReleased,
28-
joystickMoved,
29-
joystickConnected,
30-
joystickDisconnected,
31-
touchBegan,
32-
touchMoved,
33-
touchEnded,
34-
sensorChanged,
35-
};
36-
3712
// Big oof
3813
/// Creates this event from a csfml one
3914
pub fn _fromCSFML(event: sf.c.sfEvent) Self {
4015
return switch (event.type) {
4116
sf.c.sfEvtClosed => .closed,
4217
sf.c.sfEvtResized => .{ .resized = .{ .size = .{ .x = event.size.width, .y = event.size.height } } },
43-
sf.c.sfEvtLostFocus => .lostFocus,
44-
sf.c.sfEvtGainedFocus => .gainedFocus,
45-
sf.c.sfEvtTextEntered => .{ .textEntered = .{ .unicode = event.text.unicode } },
46-
sf.c.sfEvtKeyPressed => .{ .keyPressed = .{ .code = @as(sf.window.keyboard.KeyCode, @enumFromInt(event.key.code)), .alt = (event.key.alt != 0), .control = (event.key.control != 0), .shift = (event.key.shift != 0), .system = (event.key.system != 0) } },
47-
sf.c.sfEvtKeyReleased => .{ .keyReleased = .{ .code = @as(sf.window.keyboard.KeyCode, @enumFromInt(event.key.code)), .alt = (event.key.alt != 0), .control = (event.key.control != 0), .shift = (event.key.shift != 0), .system = (event.key.system != 0) } },
48-
sf.c.sfEvtMouseWheelScrolled => .{ .mouseWheelScrolled = .{ .wheel = @as(sf.window.mouse.Wheel, @enumFromInt(event.mouseWheelScroll.wheel)), .delta = event.mouseWheelScroll.delta, .pos = .{ .x = event.mouseWheelScroll.x, .y = event.mouseWheelScroll.y } } },
49-
sf.c.sfEvtMouseButtonPressed => .{ .mouseButtonPressed = .{ .button = @as(sf.window.mouse.Button, @enumFromInt(event.mouseButton.button)), .pos = .{ .x = event.mouseButton.x, .y = event.mouseButton.y } } },
50-
sf.c.sfEvtMouseButtonReleased => .{ .mouseButtonReleased = .{ .button = @as(sf.window.mouse.Button, @enumFromInt(event.mouseButton.button)), .pos = .{ .x = event.mouseButton.x, .y = event.mouseButton.y } } },
51-
sf.c.sfEvtMouseMoved => .{ .mouseMoved = .{ .pos = .{ .x = event.mouseMove.x, .y = event.mouseMove.y } } },
52-
sf.c.sfEvtMouseEntered => .mouseEntered,
53-
sf.c.sfEvtMouseLeft => .mouseLeft,
54-
sf.c.sfEvtJoystickButtonPressed => .{ .joystickButtonPressed = .{ .joystickId = event.joystickButton.joystickId, .button = event.joystickButton.button } },
55-
sf.c.sfEvtJoystickButtonReleased => .{ .joystickButtonReleased = .{ .joystickId = event.joystickButton.joystickId, .button = event.joystickButton.button } },
56-
sf.c.sfEvtJoystickMoved => .{ .joystickMoved = .{ .joystickId = event.joystickMove.joystickId, .axis = event.joystickMove.axis, .position = event.joystickMove.position } },
57-
sf.c.sfEvtJoystickConnected => .{ .joystickConnected = .{ .joystickId = event.joystickConnect.joystickId } },
58-
sf.c.sfEvtJoystickDisconnected => .{ .joystickDisconnected = .{ .joystickId = event.joystickConnect.joystickId } },
59-
sf.c.sfEvtTouchBegan => .{ .touchBegan = .{ .finger = event.touch.finger, .pos = .{ .x = event.touch.x, .y = event.touch.y } } },
60-
sf.c.sfEvtTouchMoved => .{ .touchMoved = .{ .finger = event.touch.finger, .pos = .{ .x = event.touch.x, .y = event.touch.y } } },
61-
sf.c.sfEvtTouchEnded => .{ .touchEnded = .{ .finger = event.touch.finger, .pos = .{ .x = event.touch.x, .y = event.touch.y } } },
62-
sf.c.sfEvtSensorChanged => .{ .sensorChanged = .{ .sensorType = event.sensor.sensorType, .vector = .{ .x = event.sensor.x, .y = event.sensor.y, .z = event.sensor.z } } },
18+
sf.c.sfEvtLostFocus => .lost_focus,
19+
sf.c.sfEvtGainedFocus => .gained_focus,
20+
sf.c.sfEvtTextEntered => .{ .text_entered = .{ .unicode = event.text.unicode } },
21+
sf.c.sfEvtKeyPressed => .{ .key_pressed = .{ .code = @as(sf.window.keyboard.KeyCode, @enumFromInt(event.key.code)), .alt = (event.key.alt != 0), .control = (event.key.control != 0), .shift = (event.key.shift != 0), .system = (event.key.system != 0) } },
22+
sf.c.sfEvtKeyReleased => .{ .key_released = .{ .code = @as(sf.window.keyboard.KeyCode, @enumFromInt(event.key.code)), .alt = (event.key.alt != 0), .control = (event.key.control != 0), .shift = (event.key.shift != 0), .system = (event.key.system != 0) } },
23+
sf.c.sfEvtMouseWheelScrolled => .{ .mouse_wheel_scrolled = .{ .wheel = @as(sf.window.mouse.Wheel, @enumFromInt(event.mouseWheelScroll.wheel)), .delta = event.mouseWheelScroll.delta, .pos = .{ .x = event.mouseWheelScroll.x, .y = event.mouseWheelScroll.y } } },
24+
sf.c.sfEvtMouseButtonPressed => .{ .mouse_button_pressed = .{ .button = @as(sf.window.mouse.Button, @enumFromInt(event.mouseButton.button)), .pos = .{ .x = event.mouseButton.x, .y = event.mouseButton.y } } },
25+
sf.c.sfEvtMouseButtonReleased => .{ .mouse_button_released = .{ .button = @as(sf.window.mouse.Button, @enumFromInt(event.mouseButton.button)), .pos = .{ .x = event.mouseButton.x, .y = event.mouseButton.y } } },
26+
sf.c.sfEvtMouseMoved => .{ .mouse_moved = .{ .pos = .{ .x = event.mouseMove.x, .y = event.mouseMove.y } } },
27+
sf.c.sfEvtMouseEntered => .mouse_entered,
28+
sf.c.sfEvtMouseLeft => .mouse_left,
29+
sf.c.sfEvtJoystickButtonPressed => .{ .joystick_button_pressed = .{ .joystickId = event.joystickButton.joystickId, .button = event.joystickButton.button } },
30+
sf.c.sfEvtJoystickButtonReleased => .{ .joystick_button_released = .{ .joystickId = event.joystickButton.joystickId, .button = event.joystickButton.button } },
31+
sf.c.sfEvtJoystickMoved => .{ .joystick_moved = .{ .joystickId = event.joystickMove.joystickId, .axis = event.joystickMove.axis, .position = event.joystickMove.position } },
32+
sf.c.sfEvtJoystickConnected => .{ .joystick_connected = .{ .joystickId = event.joystickConnect.joystickId } },
33+
sf.c.sfEvtJoystickDisconnected => .{ .joystick_disconnected = .{ .joystickId = event.joystickConnect.joystickId } },
34+
sf.c.sfEvtTouchBegan => .{ .touch_began = .{ .finger = event.touch.finger, .pos = .{ .x = event.touch.x, .y = event.touch.y } } },
35+
sf.c.sfEvtTouchMoved => .{ .touch_moved = .{ .finger = event.touch.finger, .pos = .{ .x = event.touch.x, .y = event.touch.y } } },
36+
sf.c.sfEvtTouchEnded => .{ .touch_ended = .{ .finger = event.touch.finger, .pos = .{ .x = event.touch.x, .y = event.touch.y } } },
37+
sf.c.sfEvtSensorChanged => .{ .sensor_changed = .{ .sensorType = event.sensor.sensorType, .vector = .{ .x = event.sensor.x, .y = event.sensor.y, .z = event.sensor.z } } },
6338
sf.c.sfEvtCount => @panic("sfEvtCount should't exist as an event!"),
6439
else => @panic("Unknown event!"),
6540
};
@@ -140,24 +115,24 @@ pub const Event = union(Event.Type) {
140115
// An event is one of those
141116
closed,
142117
resized: SizeEvent,
143-
lostFocus,
144-
gainedFocus,
145-
textEntered: TextEvent,
146-
keyPressed: KeyEvent,
147-
keyReleased: KeyEvent,
148-
mouseWheelScrolled: MouseWheelScrollEvent,
149-
mouseButtonPressed: MouseButtonEvent,
150-
mouseButtonReleased: MouseButtonEvent,
151-
mouseMoved: MouseMoveEvent,
152-
mouseEntered,
153-
mouseLeft,
154-
joystickButtonPressed: JoystickButtonEvent,
155-
joystickButtonReleased: JoystickButtonEvent,
156-
joystickMoved: JoystickMoveEvent,
157-
joystickConnected: JoystickConnectEvent,
158-
joystickDisconnected: JoystickConnectEvent,
159-
touchBegan: TouchEvent,
160-
touchMoved: TouchEvent,
161-
touchEnded: TouchEvent,
162-
sensorChanged: SensorEvent,
118+
lost_focus,
119+
gained_focus,
120+
text_entered: TextEvent,
121+
key_pressed: KeyEvent,
122+
key_released: KeyEvent,
123+
mouse_wheel_scrolled: MouseWheelScrollEvent,
124+
mouse_button_pressed: MouseButtonEvent,
125+
mouse_button_released: MouseButtonEvent,
126+
mouse_moved: MouseMoveEvent,
127+
mouse_entered,
128+
mouse_left,
129+
joystick_button_pressed: JoystickButtonEvent,
130+
joystick_button_released: JoystickButtonEvent,
131+
joystick_moved: JoystickMoveEvent,
132+
joystick_connected: JoystickConnectEvent,
133+
joystick_disconnected: JoystickConnectEvent,
134+
touch_began: TouchEvent,
135+
touch_moved: TouchEvent,
136+
touch_ended: TouchEvent,
137+
sensor_changed: SensorEvent,
163138
};

0 commit comments

Comments
 (0)