src/conf.zig can now be used to configure color theme.

Related things were improved.
This commit is contained in:
KikooDX 2021-02-25 22:53:02 +01:00
parent a0528de619
commit 75351eb8b5
7 changed files with 58 additions and 31 deletions

View File

@ -9,7 +9,7 @@ Subject to change.
* Fully keyboard driven modal editing. Mouse support is secondary.
* GUI software made in [Zig](https://ziglang.org/) with
[raylib](https://www.raylib.com/).
* Configurable (format unknown).
* Configurable (editing `src/conf.zig`).
# Installation
Runtime requirements: [raylib](https://www.raylib.com).

View File

@ -3,11 +3,42 @@
// This file is part of [KBLE](https://sr.ht/~kikoodx/kble), which is
// MIT licensed. The MIT license requires this copyright notice to be
// included in all copies and substantial portions of the software.
//! Values and types used by different files and that don't fit in any.
//! Read /etc/kble.conf and execute content.
/// Number passed to commands.
const std = @import("std");
//! User defined settings.
const ray = @import("raylib.zig");
const cell_type = @import("level.zig").cell_type;
/// raylib.Color initialisation wrapper.
fn col(r: u8, g: u8, b: u8) ray.Color {
return ray.Color{
.r = r,
.g = g,
.b = b,
.a = 255,
};
}
// BEGIN USER CONFIG
pub const mouse_enabled: bool = true;
pub const mouse_left_btn: c_int = 0;
pub const mouse_right_btn: c_int = 1;
pub const theme = .{
.background = ray.BLACK,
.mode = .{
.normal = ray.GRAY,
.select = ray.BLUE,
.select_rect = ray.SKYBLUE,
.camera = ray.PURPLE,
},
};
/// Return user defined color for corresponding cell ID.
pub fn cell_color(cell: cell_type) ray.Color {
return switch (cell) {
0 => comptime col(026, 026, 026), // air
1 => comptime col(144, 144, 144), // solid
2 => comptime col(240, 010, 050), // red thing
else => ray.PURPLE, // undefined
};
}
// END USER CONFIG

View File

@ -3,10 +3,9 @@
// This file is part of [KBLE](https://sr.ht/~kikoodx/kble), which is
// MIT licensed. The MIT license requires this copyright notice to be
// included in all copies and substantial portions of the software.
const ray = @cImport({
@cInclude("raylib.h");
});
const ray = @import("raylib.zig");
const conf = @import("conf.zig");
const Vec2 = @import("vec2.zig");
const Rect = @import("rect.zig");
const scaling = @import("scaling.zig");
@ -17,10 +16,10 @@ pub fn cursor(scale: scaling.scale_type, offset: Vec2, pos: Vec2, mode: Mode) vo
const x = (pos.x - offset.y) * scale;
const y = (pos.y - offset.y) * scale;
const color: ray.Color = switch (mode) {
.normal => ray.GRAY,
.select => ray.BLUE,
.rectangle => ray.SKYBLUE,
.camera => ray.PURPLE,
.normal => conf.theme.mode.normal,
.select => conf.theme.mode.select,
.rectangle => conf.theme.mode.select_rect,
.camera => conf.theme.mode.camera,
};
ray.DrawRectangleLines(x, y, scale, scale, color);
}
@ -31,5 +30,5 @@ pub fn rectangle_selection(scale: scaling.scale_type, offset: Vec2, rect: Rect)
const w = (rect.right_x - rect.left_x + 1) * scale;
const y = (rect.top_y - offset.y) * scale;
const h = (rect.bottom_y - rect.top_y + 1) * scale;
ray.DrawRectangleLines(x, y, w, h, ray.SKYBLUE);
ray.DrawRectangleLines(x, y, w, h, conf.theme.mode.select_rect);
}

View File

@ -4,12 +4,11 @@
// MIT licensed. The MIT license requires this copyright notice to be
// included in all copies and substantial portions of the software.
//! Level structure, grid containing tile data.
const ray = @cImport({
@cInclude("raylib.h");
});
const ray = @import("raylib.zig");
const std = @import("std");
const expect = std.testing.expect;
const conf = @import("conf.zig");
const Vec2 = @import("vec2.zig");
const Rect = @import("rect.zig");
const SelectionUpdate = @import("movement.zig").SelectionUpdate;
@ -190,11 +189,7 @@ pub fn draw(self: Self, scale: u16, offset: Vec2) void {
var cy: Vec2.int_type = offset.y;
while (cy < self.height) {
const cell_content: cell_type = self.content[cy * self.width + cx];
const color = switch (cell_content) {
0 => ray.Color{ .r = 26, .g = 26, .b = 26, .a = 255 },
1 => ray.Color{ .r = 144, .g = 144, .b = 144, .a = 255 },
else => ray.PURPLE, //unknown
};
const color: ray.Color = conf.cell_color(cell_content);
ray.DrawRectangle(x + 1, y + 1, scale - 2, scale - 2, color);
y += scale;
cy += 1;

View File

@ -3,9 +3,7 @@
// This file is part of [KBLE](https://sr.ht/~kikoodx/kble), which is
// MIT licensed. The MIT license requires this copyright notice to be
// included in all copies and substantial portions of the software.
const ray = @cImport({
@cInclude("raylib.h");
});
const ray = @import("raylib.zig");
const std = @import("std");
const maxInt = std.math.maxInt;
const log = std.log.info;
@ -257,13 +255,13 @@ pub fn main() void {
ray.BeginDrawing();
defer ray.EndDrawing();
ray.ClearBackground(ray.BLACK);
ray.ClearBackground(conf.theme.background);
level.draw(scale, camera);
level.draw_selection(scale, camera);
draw.cursor(scale, camera, cursor, mode);
if (mode == Mode.rectangle)
draw.rectangle_selection(scale, camera, Rect.init_from_vec2(cursor, cursor_before));
mouse.draw(scale, camera);
//ray.DrawFPS(0, 0);
if (conf.mouse_enabled)
mouse.draw(scale, camera);
}
}

View File

@ -4,11 +4,10 @@
// MIT licensed. The MIT license requires this copyright notice to be
// included in all copies and substantial portions of the software.
//! Mouse (eurk) logic and operations.
const ray = @cImport({
@cInclude("raylib.h");
});
const ray = @import("raylib.zig");
const std = @import("std");
const conf = @import("conf.zig");
const Vec2 = @import("vec2.zig");
const Rect = @import("rect.zig");
const scaling = @import("scaling.zig");
@ -42,7 +41,7 @@ pub fn draw(self: *Self, scale: scaling.scale_type, offset: Vec2) void {
MouseMode.sel => {
const x = (self.pos.x - offset.y) * scale;
const y = (self.pos.y - offset.y) * scale;
ray.DrawRectangleLines(x, y, scale, scale, ray.SKYBLUE);
ray.DrawRectangleLines(x, y, scale, scale, conf.theme.mode.select);
},
MouseMode.rect_sel => {
const rect = Rect.init_from_vec2(self.pos, self.start_pos);
@ -51,3 +50,4 @@ pub fn draw(self: *Self, scale: scaling.scale_type, offset: Vec2) void {
else => {},
}
}

4
src/raylib.zig Normal file
View File

@ -0,0 +1,4 @@
/// Simplest imaginable raylib wrapper
pub usingnamespace @cImport({
@cInclude("raylib.h");
});