gui buttons
This commit is contained in:
parent
e75be484cd
commit
d8f5dee46d
54
build.zig
54
build.zig
@ -74,22 +74,6 @@ pub fn build(b: *std.Build) void {
|
||||
},
|
||||
});
|
||||
|
||||
const mod3 = b.addModule("GuiOps", .{
|
||||
// The root source file is the "entry point" of this module. Users of
|
||||
// this module will only be able to access public declarations contained
|
||||
// in this file, which means that if you have declarations that you
|
||||
// intend to expose to consumers that were defined in other files part
|
||||
// of this module, you will have to make sure to re-export them from
|
||||
// the root file.
|
||||
.root_source_file = b.path("src/graphics/gui.zig"),
|
||||
// Later on we'll use this module as the root module of a test executable
|
||||
// which requires us to specify a target.
|
||||
.target = target,
|
||||
.imports = &.{
|
||||
.{.name = "raylib", .module = raylib},
|
||||
.{.name = "raygui", .module = raygui},
|
||||
},
|
||||
});
|
||||
|
||||
const mod4 = b.addModule("InputOps", .{
|
||||
// The root source file is the "entry point" of this module. Users of
|
||||
@ -108,6 +92,43 @@ pub fn build(b: *std.Build) void {
|
||||
},
|
||||
});
|
||||
|
||||
const mod3 = b.addModule("GuiOps", .{
|
||||
// The root source file is the "entry point" of this module. Users of
|
||||
// this module will only be able to access public declarations contained
|
||||
// in this file, which means that if you have declarations that you
|
||||
// intend to expose to consumers that were defined in other files part
|
||||
// of this module, you will have to make sure to re-export them from
|
||||
// the root file.
|
||||
.root_source_file = b.path("src/graphics/gui.zig"),
|
||||
// Later on we'll use this module as the root module of a test executable
|
||||
// which requires us to specify a target.
|
||||
.target = target,
|
||||
.imports = &.{
|
||||
.{.name = "raylib", .module = raylib},
|
||||
.{.name = "raygui", .module = raygui},
|
||||
.{ .name= "InputOps", .module = mod4 },
|
||||
},
|
||||
});
|
||||
|
||||
const mod5 = b.addModule("BaseDraw", .{
|
||||
// The root source file is the "entry point" of this module. Users of
|
||||
// this module will only be able to access public declarations contained
|
||||
// in this file, which means that if you have declarations that you
|
||||
// intend to expose to consumers that were defined in other files part
|
||||
// of this module, you will have to make sure to re-export them from
|
||||
// the root file.
|
||||
.root_source_file = b.path("src/graphics/base_drawers.zig"),
|
||||
// Later on we'll use this module as the root module of a test executable
|
||||
// which requires us to specify a target.
|
||||
.target = target,
|
||||
.imports = &.{
|
||||
.{.name = "raylib", .module = raylib},
|
||||
.{.name = "raygui", .module = raygui},
|
||||
.{ .name= "InputOps", .module = mod4 },
|
||||
.{ .name= "Cam", .module = mod2 },
|
||||
},
|
||||
});
|
||||
|
||||
// Here we define an executable. An executable needs to have a root module
|
||||
// which needs to expose a `main` function. While we could add a main function
|
||||
// to the module defined above, it's sometimes preferable to split business
|
||||
@ -149,6 +170,7 @@ pub fn build(b: *std.Build) void {
|
||||
.{ .name = "Cam", .module = mod2 },
|
||||
.{ .name= "Gui", .module = mod3 },
|
||||
.{ .name= "InputOps", .module = mod4 },
|
||||
.{ .name= "BaseDraw", .module = mod5 },
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
@ -1,5 +1,34 @@
|
||||
const std = @import("std");
|
||||
const rl = @import("raylib");
|
||||
const cm = @import("Cam");
|
||||
const b_inp = @import("InputOps");
|
||||
|
||||
|
||||
pub fn add(a : f32, b : f32) f32 {
|
||||
return a + b;
|
||||
// Raylib döngüsünde kullanmak için çizim fonksiyonu
|
||||
pub fn drawShapes(shapes : *std.ArrayList(b_inp.Shape)) void {
|
||||
for (shapes.items, 0..) |shape, index| {
|
||||
// Seçili nesneyi işaretle
|
||||
if (b_inp.selected_shape_index) |sel_index| {
|
||||
if (index == sel_index) {
|
||||
// Seçili nesnenin sınırlarını çiz
|
||||
switch (shape.data) {
|
||||
.cube => |d| {
|
||||
//const box = getBoundingBoxForCube(shape.position, d.width, d.height, d.length);
|
||||
//rl.drawCubeWiresV(box.min, box.max, .yellow);
|
||||
rl.drawCubeWires(shape.position, d.width + 0.5, d.height + 0.5, d.length + 0.5, .green);
|
||||
},
|
||||
.sphere => |d| rl.drawSphereWires(shape.position, d.radius + 0.5, 16, 16, .green),
|
||||
.cylinder => |d| rl.drawCylinderWires(shape.position, d.radius + 0.5, d.radius + 0.5, d.height, 10, .green),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Asıl nesneyi çiz
|
||||
switch (shape.data) {
|
||||
.cube => |d| rl.drawCubeV(shape.position, rl.Vector3.init(d.width, d.height, d.length), shape.color),
|
||||
.sphere => |d| rl.drawSphere(shape.position, d.radius, shape.color),
|
||||
.cylinder => |d| rl.drawCylinder(shape.position, d.radius, d.radius, d.height, 10, shape.color),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
const gui = @import("raygui");
|
||||
const rl = @import("raylib");
|
||||
const std = @import("std");
|
||||
const io = @import("InputOps");
|
||||
|
||||
pub var is_cursor_hidden: bool = undefined;
|
||||
|
||||
@ -26,10 +27,36 @@ pub const GUI = struct {
|
||||
self.guiPos.width = self.width / 4.0;
|
||||
self.guiPos.x = self.width / 4.0 * 3.0;
|
||||
self.guiPos.y = 0.0;
|
||||
|
||||
//gui pos sağ menunun güncel halidir
|
||||
}
|
||||
|
||||
pub fn draw(self: *GUI) void {
|
||||
pub fn draw(self: *GUI, shapes : std.ArrayList(io.Shape)) void {
|
||||
//panel
|
||||
rl.drawRectangleRec(self.guiPos, .red);
|
||||
try self.objects(shapes);
|
||||
}
|
||||
|
||||
|
||||
pub fn objects(self: *GUI, shapes: std.ArrayList(io.Shape)) !void {
|
||||
const button_height: f32 = 25; // Her düğmenin yüksekliği
|
||||
const button_spacing: f32 = 5; // Düğmeler arası boşluk
|
||||
|
||||
for (shapes.items, 0..) |shape, i| {
|
||||
// Her düğme için pozisyon hesapla
|
||||
const button_positions = rl.Rectangle.init(
|
||||
self.guiPos.x + 15,
|
||||
self.guiPos.y + 15 + (@as(f32, @floatFromInt(i)) * (button_height + button_spacing)),
|
||||
self.guiPos.width - 30, // Genişlik
|
||||
button_height,
|
||||
);
|
||||
|
||||
// GuiButton kullanarak şekil adını yazdır
|
||||
// GuiButton, tıklanırsa true, tıklanmazsa false döner
|
||||
if (gui.button(button_positions, shape.name)) {
|
||||
std.debug.print("Seçilen şekil: {s}, ID: {}\n", .{shape.name, shape.id});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -5,9 +5,10 @@ const cm = @import("Cam");
|
||||
|
||||
pub var is_object_dragging : bool = undefined; // drag işlemi için gerekli
|
||||
pub var freeMode = false;
|
||||
// ışın ve ışına bağlı çarpışma ray ve raycollison değişkenleri ile yapılır.
|
||||
pub var count_id : usize = 0; // bu değişken anlık id'yi tutar
|
||||
|
||||
var selected_shape_index:?usize = 0;
|
||||
// ışın ve ışına bağlı çarpışma ray ve raycollison değişkenleri ile yapılır.
|
||||
pub var selected_shape_index:?usize = 0;
|
||||
|
||||
pub const ShapeType = enum {
|
||||
cube,
|
||||
@ -17,6 +18,8 @@ pub const ShapeType = enum {
|
||||
}; //tipler
|
||||
|
||||
pub const Shape = struct {
|
||||
id : usize = 0,
|
||||
name : [:0]const u8,
|
||||
position: rl.Vector3,
|
||||
color: rl.Color,
|
||||
|
||||
@ -37,7 +40,10 @@ pub const Shape = struct {
|
||||
},
|
||||
|
||||
pub fn initCube(position: rl.Vector3, color: rl.Color, width: f32, height: f32, length: f32) Shape {
|
||||
count_id += 1;
|
||||
return Shape{
|
||||
.id = count_id,
|
||||
.name = "count_id",
|
||||
.position = position,
|
||||
.color = color,
|
||||
.data = .{ .cube = .{ .width = width, .height = height, .length = length } },
|
||||
@ -46,7 +52,10 @@ pub const Shape = struct {
|
||||
|
||||
// Küre için özel init metodu
|
||||
pub fn initSphere(position: rl.Vector3, color: rl.Color, radius: f32) Shape {
|
||||
count_id += 1;
|
||||
return Shape{
|
||||
.id = count_id,
|
||||
.name= "count_id",
|
||||
.position = position,
|
||||
.color = color,
|
||||
.data = .{ .sphere = .{ .radius = radius } },
|
||||
@ -55,7 +64,10 @@ pub const Shape = struct {
|
||||
|
||||
// Silindir için özel init metodu
|
||||
pub fn initCylinder(position: rl.Vector3, color: rl.Color, radius: f32, height: f32) Shape {
|
||||
count_id += 1;
|
||||
return Shape{
|
||||
.id = count_id,
|
||||
.name = "count_id",
|
||||
.position = position,
|
||||
.color = color,
|
||||
.data = .{ .cylinder = .{ .radius = radius, .height = height } },
|
||||
@ -64,34 +76,6 @@ pub const Shape = struct {
|
||||
};
|
||||
|
||||
|
||||
// Raylib döngüsünde kullanmak için çizim fonksiyonu
|
||||
pub fn drawShapes(shapes : *std.ArrayList(Shape)) void {
|
||||
for (shapes.items, 0..) |shape, index| {
|
||||
// Seçili nesneyi işaretle
|
||||
if (selected_shape_index) |sel_index| {
|
||||
if (index == sel_index) {
|
||||
// Seçili nesnenin sınırlarını çiz
|
||||
switch (shape.data) {
|
||||
.cube => |d| {
|
||||
//const box = getBoundingBoxForCube(shape.position, d.width, d.height, d.length);
|
||||
//rl.drawCubeWiresV(box.min, box.max, .yellow);
|
||||
rl.drawCubeWires(shape.position, d.width + 0.5, d.height + 0.5, d.length + 0.5, .green);
|
||||
},
|
||||
.sphere => |d| rl.drawSphereWires(shape.position, d.radius + 0.5, 16, 16, .green),
|
||||
.cylinder => |d| rl.drawCylinderWires(shape.position, d.radius + 0.5, d.radius + 0.5, d.height, 10, .green),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Asıl nesneyi çiz
|
||||
switch (shape.data) {
|
||||
.cube => |d| rl.drawCubeV(shape.position, rl.Vector3.init(d.width, d.height, d.length), shape.color),
|
||||
.sphere => |d| rl.drawSphere(shape.position, d.radius, shape.color),
|
||||
.cylinder => |d| rl.drawCylinder(shape.position, d.radius, d.radius, d.height, 10, shape.color),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn findClosestHitObject(
|
||||
mouse_position: rl.Vector2,
|
||||
camera: rl.Camera3D,
|
||||
@ -138,6 +122,19 @@ pub fn findClosestHitObject(
|
||||
}
|
||||
|
||||
|
||||
pub fn inputControls() void {
|
||||
|
||||
if (rl.isMouseButtonPressed(.right)) {
|
||||
freeMode = !freeMode;
|
||||
if (freeMode) {
|
||||
rl.disableCursor();
|
||||
} else {
|
||||
rl.enableCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn getBoundingBoxForCube(position: rl.Vector3, width: f32, height: f32, length: f32) rl.BoundingBox {
|
||||
// Nesnenin boyutlarının yarısını hesapla
|
||||
const half_width = width / 2.0;
|
||||
@ -181,15 +178,3 @@ pub fn getBoundingBoxForCylinder(position: rl.Vector3, radius: f32, height: f32)
|
||||
.max = rl.Vector3.init(max_x, max_y, max_z),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn inputControls() void {
|
||||
|
||||
if (rl.isMouseButtonPressed(.right)) {
|
||||
freeMode = !freeMode;
|
||||
if (freeMode) {
|
||||
rl.disableCursor();
|
||||
} else {
|
||||
rl.enableCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const rl = @import("raylib");
|
||||
const gi = @import("raygui");
|
||||
const gr = @import("Drawers");
|
||||
const drw = @import("BaseDraw");
|
||||
const cm = @import("Cam");
|
||||
const panel = @import("Gui");
|
||||
const io = @import("InputOps");
|
||||
@ -59,15 +59,14 @@ pub fn main() anyerror!void {
|
||||
defer rl.endDrawing();
|
||||
|
||||
rl.clearBackground(.ray_white);
|
||||
|
||||
rl.beginMode3D(cam);
|
||||
io.drawShapes(&shapes);
|
||||
drw.drawShapes(&shapes);
|
||||
rl.drawGrid(10, 1.0);
|
||||
rl.endMode3D();
|
||||
rl.drawText(rl.textFormat("x:%.2f y:%.2f z:%.2f", .{cam.position.x, cam.position.y, cam.position.z}),
|
||||
180, 200, 20, .light_gray);
|
||||
rl.drawText(rl.textFormat("x : %d y : %d", .{rl.getScreenWidth(), rl.getScreenHeight()}), 50, 50, 20, .red);
|
||||
my_gui.draw();
|
||||
my_gui.draw(shapes);
|
||||
rl.drawFPS(200, 200);
|
||||
if (io.is_object_dragging) {
|
||||
rl.drawText("Nesne drag...", 10, 10, 20, .dark_gray);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user