changed naming convention to zig's
This commit is contained in:
parent
38cc535235
commit
5339757abe
5 changed files with 197 additions and 239 deletions
|
@ -14,59 +14,59 @@ pub fn clayColorToRaylibColor(color: cl.Color) rl.Color {
|
|||
|
||||
pub var raylib_fonts: [10]?rl.Font = .{null} ** 10;
|
||||
|
||||
pub fn clayRaylibRender(renderCommands: *cl.ClayArray(cl.RenderCommand), allocator: std.mem.Allocator) void {
|
||||
pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), allocator: std.mem.Allocator) void {
|
||||
var i: usize = 0;
|
||||
while (i < renderCommands.length) : (i += 1) {
|
||||
const renderCommand = cl.renderCommandArrayGet(renderCommands, @intCast(i));
|
||||
const boundingBox = renderCommand.boundingBox;
|
||||
switch (renderCommand.commandType) {
|
||||
while (i < render_commands.length) : (i += 1) {
|
||||
const render_command = cl.renderCommandArrayGet(render_commands, @intCast(i));
|
||||
const bounding_box = render_command.bounding_box;
|
||||
switch (render_command.command_type) {
|
||||
.None => {},
|
||||
.Text => {
|
||||
const text = renderCommand.text.chars[0..@intCast(renderCommand.text.length)];
|
||||
const text = render_command.text.chars[0..@intCast(render_command.text.length)];
|
||||
const cloned = allocator.dupeZ(c_char, text) catch unreachable;
|
||||
defer allocator.free(cloned);
|
||||
const fontToUse: rl.Font = raylib_fonts[renderCommand.config.textElementConfig.fontId].?;
|
||||
rl.setTextLineSpacing(renderCommand.config.textElementConfig.lineSpacing);
|
||||
const fontToUse: rl.Font = raylib_fonts[render_command.config.text_element_config.font_id].?;
|
||||
rl.setTextLineSpacing(render_command.config.text_element_config.lineSpacing);
|
||||
rl.drawTextEx(
|
||||
fontToUse,
|
||||
@ptrCast(@alignCast(cloned.ptr)),
|
||||
rl.Vector2{ .x = boundingBox.x, .y = boundingBox.y },
|
||||
@floatFromInt(renderCommand.config.textElementConfig.fontSize),
|
||||
@floatFromInt(renderCommand.config.textElementConfig.letterSpacing),
|
||||
clayColorToRaylibColor(renderCommand.config.textElementConfig.textColor),
|
||||
rl.Vector2{ .x = bounding_box.x, .y = bounding_box.y },
|
||||
@floatFromInt(render_command.config.text_element_config.font_size),
|
||||
@floatFromInt(render_command.config.text_element_config.letter_spacing),
|
||||
clayColorToRaylibColor(render_command.config.text_element_config.text_color),
|
||||
);
|
||||
},
|
||||
.Image => {
|
||||
const imageTexture: *rl.Texture2D = @ptrCast(
|
||||
@alignCast(renderCommand.config.imageElementConfig.imageData),
|
||||
const image_texture: *rl.Texture2D = @ptrCast(
|
||||
@alignCast(render_command.config.image_element_config.image_data),
|
||||
);
|
||||
rl.drawTextureEx(
|
||||
imageTexture.*,
|
||||
rl.Vector2{ .x = boundingBox.x, .y = boundingBox.y },
|
||||
image_texture.*,
|
||||
rl.Vector2{ .x = bounding_box.x, .y = bounding_box.y },
|
||||
0,
|
||||
boundingBox.width / @as(f32, @floatFromInt(imageTexture.width)),
|
||||
bounding_box.width / @as(f32, @floatFromInt(image_texture.width)),
|
||||
rl.Color.white,
|
||||
);
|
||||
},
|
||||
.ScissorStart => {
|
||||
rl.beginScissorMode(
|
||||
@intFromFloat(math.round(boundingBox.x)),
|
||||
@intFromFloat(math.round(boundingBox.y)),
|
||||
@intFromFloat(math.round(boundingBox.width)),
|
||||
@intFromFloat(math.round(boundingBox.height)),
|
||||
@intFromFloat(math.round(bounding_box.x)),
|
||||
@intFromFloat(math.round(bounding_box.y)),
|
||||
@intFromFloat(math.round(bounding_box.width)),
|
||||
@intFromFloat(math.round(bounding_box.height)),
|
||||
);
|
||||
},
|
||||
.ScissorEnd => rl.endScissorMode(),
|
||||
.Rectangle => {
|
||||
const config = renderCommand.config.rectangleElementConfig;
|
||||
if (config.cornerRadius.topLeft > 0) {
|
||||
const radius: f32 = (config.cornerRadius.topLeft * 2) / @min(boundingBox.width, boundingBox.height);
|
||||
const config = render_command.config.rectangle_element_config;
|
||||
if (config.corner_radius.top_left > 0) {
|
||||
const radius: f32 = (config.corner_radius.top_left * 2) / @min(bounding_box.width, bounding_box.height);
|
||||
rl.drawRectangleRounded(
|
||||
rl.Rectangle{
|
||||
.x = boundingBox.x,
|
||||
.y = boundingBox.y,
|
||||
.width = boundingBox.width,
|
||||
.height = boundingBox.height,
|
||||
.x = bounding_box.x,
|
||||
.y = bounding_box.y,
|
||||
.width = bounding_box.width,
|
||||
.height = bounding_box.height,
|
||||
},
|
||||
radius,
|
||||
8,
|
||||
|
@ -74,103 +74,103 @@ pub fn clayRaylibRender(renderCommands: *cl.ClayArray(cl.RenderCommand), allocat
|
|||
);
|
||||
} else {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(boundingBox.x),
|
||||
@intFromFloat(boundingBox.y),
|
||||
@intFromFloat(boundingBox.width),
|
||||
@intFromFloat(boundingBox.height),
|
||||
@intFromFloat(bounding_box.x),
|
||||
@intFromFloat(bounding_box.y),
|
||||
@intFromFloat(bounding_box.width),
|
||||
@intFromFloat(bounding_box.height),
|
||||
clayColorToRaylibColor(config.color),
|
||||
);
|
||||
}
|
||||
},
|
||||
.Border => {
|
||||
const config = renderCommand.config.borderElementConfig;
|
||||
const config = render_command.config.border_element_config;
|
||||
if (config.left.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(boundingBox.x)),
|
||||
@intFromFloat(math.round(boundingBox.y + config.cornerRadius.topLeft)),
|
||||
@intFromFloat(math.round(bounding_box.x)),
|
||||
@intFromFloat(math.round(bounding_box.y + config.corner_radius.top_left)),
|
||||
@intCast(config.left.width),
|
||||
@intFromFloat(math.round(boundingBox.height - config.cornerRadius.topLeft - config.cornerRadius.bottomLeft)),
|
||||
@intFromFloat(math.round(bounding_box.height - config.corner_radius.top_left - config.corner_radius.bottom_left)),
|
||||
clayColorToRaylibColor(config.left.color),
|
||||
);
|
||||
}
|
||||
if (config.right.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(boundingBox.x + boundingBox.width - @as(f32, @floatFromInt(config.right.width)))),
|
||||
@intFromFloat(math.round(boundingBox.y + config.cornerRadius.topRight)),
|
||||
@intFromFloat(math.round(bounding_box.x + bounding_box.width - @as(f32, @floatFromInt(config.right.width)))),
|
||||
@intFromFloat(math.round(bounding_box.y + config.corner_radius.top_right)),
|
||||
@intCast(config.right.width),
|
||||
@intFromFloat(math.round(boundingBox.height - config.cornerRadius.topRight - config.cornerRadius.bottomRight)),
|
||||
@intFromFloat(math.round(bounding_box.height - config.corner_radius.top_right - config.corner_radius.bottom_right)),
|
||||
clayColorToRaylibColor(config.right.color),
|
||||
);
|
||||
}
|
||||
if (config.top.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(boundingBox.x + config.cornerRadius.topLeft)),
|
||||
@intFromFloat(math.round(boundingBox.y)),
|
||||
@intFromFloat(math.round(boundingBox.width - config.cornerRadius.topLeft - config.cornerRadius.topRight)),
|
||||
@intFromFloat(math.round(bounding_box.x + config.corner_radius.top_left)),
|
||||
@intFromFloat(math.round(bounding_box.y)),
|
||||
@intFromFloat(math.round(bounding_box.width - config.corner_radius.top_left - config.corner_radius.top_right)),
|
||||
@intCast(config.top.width),
|
||||
clayColorToRaylibColor(config.top.color),
|
||||
);
|
||||
}
|
||||
if (config.bottom.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(boundingBox.x + config.cornerRadius.bottomLeft)),
|
||||
@intFromFloat(math.round(boundingBox.y + boundingBox.height - @as(f32, @floatFromInt(config.bottom.width)))),
|
||||
@intFromFloat(math.round(boundingBox.width - config.cornerRadius.bottomLeft - config.cornerRadius.bottomRight)),
|
||||
@intFromFloat(math.round(bounding_box.x + config.corner_radius.bottom_left)),
|
||||
@intFromFloat(math.round(bounding_box.y + bounding_box.height - @as(f32, @floatFromInt(config.bottom.width)))),
|
||||
@intFromFloat(math.round(bounding_box.width - config.corner_radius.bottom_left - config.corner_radius.bottom_right)),
|
||||
@intCast(config.bottom.width),
|
||||
clayColorToRaylibColor(config.bottom.color),
|
||||
);
|
||||
}
|
||||
|
||||
if (config.cornerRadius.topLeft > 0) {
|
||||
if (config.corner_radius.top_left > 0) {
|
||||
rl.drawRing(
|
||||
rl.Vector2{
|
||||
.x = math.round(boundingBox.x + config.cornerRadius.topLeft),
|
||||
.y = math.round(boundingBox.y + config.cornerRadius.topLeft),
|
||||
.x = math.round(bounding_box.x + config.corner_radius.top_left),
|
||||
.y = math.round(bounding_box.y + config.corner_radius.top_left),
|
||||
},
|
||||
math.round(config.cornerRadius.topLeft - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.cornerRadius.topLeft,
|
||||
math.round(config.corner_radius.top_left - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.corner_radius.top_left,
|
||||
180,
|
||||
270,
|
||||
10,
|
||||
clayColorToRaylibColor(config.top.color),
|
||||
);
|
||||
}
|
||||
if (config.cornerRadius.topRight > 0) {
|
||||
if (config.corner_radius.top_right > 0) {
|
||||
rl.drawRing(
|
||||
rl.Vector2{
|
||||
.x = math.round(boundingBox.x + boundingBox.width - config.cornerRadius.topRight),
|
||||
.y = math.round(boundingBox.y + config.cornerRadius.topRight),
|
||||
.x = math.round(bounding_box.x + bounding_box.width - config.corner_radius.top_right),
|
||||
.y = math.round(bounding_box.y + config.corner_radius.top_right),
|
||||
},
|
||||
math.round(config.cornerRadius.topRight - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.cornerRadius.topRight,
|
||||
math.round(config.corner_radius.top_right - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.corner_radius.top_right,
|
||||
270,
|
||||
360,
|
||||
10,
|
||||
clayColorToRaylibColor(config.top.color),
|
||||
);
|
||||
}
|
||||
if (config.cornerRadius.bottomLeft > 0) {
|
||||
if (config.corner_radius.bottom_left > 0) {
|
||||
rl.drawRing(
|
||||
rl.Vector2{
|
||||
.x = math.round(boundingBox.x + config.cornerRadius.bottomLeft),
|
||||
.y = math.round(boundingBox.y + boundingBox.height - config.cornerRadius.bottomLeft),
|
||||
.x = math.round(bounding_box.x + config.corner_radius.bottom_left),
|
||||
.y = math.round(bounding_box.y + bounding_box.height - config.corner_radius.bottom_left),
|
||||
},
|
||||
math.round(config.cornerRadius.bottomLeft - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.cornerRadius.bottomLeft,
|
||||
math.round(config.corner_radius.bottom_left - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.corner_radius.bottom_left,
|
||||
90,
|
||||
180,
|
||||
10,
|
||||
clayColorToRaylibColor(config.bottom.color),
|
||||
);
|
||||
}
|
||||
if (config.cornerRadius.bottomRight > 0) {
|
||||
if (config.corner_radius.bottom_right > 0) {
|
||||
rl.drawRing(
|
||||
rl.Vector2{
|
||||
.x = math.round(boundingBox.x + boundingBox.width - config.cornerRadius.bottomRight),
|
||||
.y = math.round(boundingBox.y + boundingBox.height - config.cornerRadius.bottomRight),
|
||||
.x = math.round(bounding_box.x + bounding_box.width - config.corner_radius.bottom_right),
|
||||
.y = math.round(bounding_box.y + bounding_box.height - config.corner_radius.bottom_right),
|
||||
},
|
||||
math.round(config.cornerRadius.bottomRight - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.cornerRadius.bottomRight,
|
||||
math.round(config.corner_radius.bottom_right - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.corner_radius.bottom_right,
|
||||
0.1,
|
||||
90,
|
||||
10,
|
||||
|
@ -186,10 +186,10 @@ pub fn clayRaylibRender(renderCommands: *cl.ClayArray(cl.RenderCommand), allocat
|
|||
}
|
||||
|
||||
pub fn measureText(clay_text: []const u8, config: *cl.TextElementConfig) cl.Dimensions {
|
||||
const font = raylib_fonts[config.fontId].?;
|
||||
const font = raylib_fonts[config.font_id].?;
|
||||
const text: []const u8 = clay_text;
|
||||
const font_size: f32 = @floatFromInt(config.fontSize);
|
||||
const letter_spacing: f32 = @floatFromInt(config.letterSpacing);
|
||||
const font_size: f32 = @floatFromInt(config.font_size);
|
||||
const letter_spacing: f32 = @floatFromInt(config.letter_spacing);
|
||||
const line_spacing = config.lineSpacing;
|
||||
|
||||
var temp_byte_counter: usize = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue