66 lines
1.5 KiB
Zig
66 lines
1.5 KiB
Zig
const rl = @import("raylib");
|
|
|
|
x: f32,
|
|
y: f32,
|
|
width: f32,
|
|
height: f32,
|
|
|
|
pub fn init(x: f32, y: f32, width: f32, height: f32) @This() {
|
|
return @This(){
|
|
.x = x,
|
|
.y = y,
|
|
.width = width,
|
|
.height = height,
|
|
};
|
|
}
|
|
|
|
pub fn initScreen() @This() {
|
|
const width: f32 = @floatFromInt(rl.GetScreenWidth());
|
|
const height: f32 = @floatFromInt(rl.GetScreenHeight());
|
|
return @This().init(0, 0, width, height);
|
|
}
|
|
|
|
pub fn box(self: @This(), x: f32, y: f32, width: f32, height: f32) @This() {
|
|
return @This().init(self.x + x, self.y + y, width, height);
|
|
}
|
|
|
|
pub fn rect(self: @This()) rl.Rectangle {
|
|
return rl.Rectangle{
|
|
.x = self.x,
|
|
.y = self.y,
|
|
.width = self.width,
|
|
.height = self.height,
|
|
};
|
|
}
|
|
|
|
pub fn left(self: @This()) f32 {
|
|
return self.x;
|
|
}
|
|
pub fn center(self: @This()) f32 {
|
|
return self.x + self.width/2;
|
|
}
|
|
pub fn right(self: @This()) f32 {
|
|
return self.x + self.width;
|
|
}
|
|
|
|
pub fn top(self: @This()) f32 {
|
|
return self.y;
|
|
}
|
|
pub fn middle(self: @This()) f32 {
|
|
return self.y + self.height/2;
|
|
}
|
|
pub fn bottom(self: @This()) f32 {
|
|
return self.y + self.height;
|
|
}
|
|
|
|
pub fn center_top(self: @This()) rl.Vector2 {
|
|
return rl.Vector2{ .x = self.center(), .y = self.top() };
|
|
}
|
|
pub fn center_middle(self: @This()) rl.Vector {
|
|
return rl.Vector2{ .x = self.center(), .y = self.middle() };
|
|
}
|
|
|
|
pub fn margin(self: @This(), amount: f32) @This() {
|
|
return @This().init(self.x + amount, self.y + amount, self.width - 2*amount, self.height - 2*amount);
|
|
}
|