mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-15 10:48:04 +00:00
Start of clay website example
This commit is contained in:
parent
eb1ee390bb
commit
11e3f91220
4
bindings/jai/.gitignore
vendored
4
bindings/jai/.gitignore
vendored
@ -1 +1,3 @@
|
||||
.build/
|
||||
.build/
|
||||
examples/clay_official_website.exe
|
||||
examples/clay_official_website.pdb
|
||||
|
16
bindings/jai/examples/clay_official_website.jai
Normal file
16
bindings/jai/examples/clay_official_website.jai
Normal file
@ -0,0 +1,16 @@
|
||||
using Basic :: #import "Basic";
|
||||
|
||||
Clay :: #import,file "../module.jai";
|
||||
Raylib :: #import "raylib-jai";
|
||||
|
||||
#load "clay_renderer_raylib.jai";
|
||||
|
||||
window_width := 1024;
|
||||
window_height := 768;
|
||||
|
||||
main :: () {
|
||||
min_memory_size := Clay.MinMemorySize();
|
||||
memory := alloc(min_memory_size);
|
||||
arena := Clay.CreateArenaWithCapacityAndMemory(min_memory_size, memory);
|
||||
Clay.SetMeasureTextFunction(measure_text);
|
||||
}
|
47
bindings/jai/examples/clay_renderer_raylib.jai
Normal file
47
bindings/jai/examples/clay_renderer_raylib.jai
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
RaylibFont :: struct {
|
||||
font_id: u16;
|
||||
font: Raylib.Font;
|
||||
}
|
||||
|
||||
clay_color_to_raylib_color :: (color: Clay.Color) -> Raylib.Color {
|
||||
return .{cast(u8) color.x, cast(u8) color.y, cast(u8) color.z, cast(u8) color.w};
|
||||
}
|
||||
|
||||
raylib_fonts: [10]RaylibFont;
|
||||
|
||||
c_max :: (a: $T, b: T) -> T #c_call {
|
||||
if b < a return a;
|
||||
return b;
|
||||
}
|
||||
|
||||
measure_text :: (text: *Clay.String, config: *Clay.TextElementConfig) -> Clay.Dimensions #c_call {
|
||||
text_size := Clay.Dimensions.{0, 0};
|
||||
|
||||
max_text_width: float = 0;
|
||||
line_text_width: float = 0;
|
||||
|
||||
text_height := cast(float)config.fontSize;
|
||||
font_to_use := raylib_fonts[config.fontId].font;
|
||||
|
||||
for 0..text.length - 1 {
|
||||
if text.chars[it] == #char "\n" {
|
||||
max_text_width = c_max(max_text_width, line_text_width);
|
||||
line_text_width = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
index := cast(s32) text.chars[it] - 32;
|
||||
if font_to_use.glyphs[index].advanceX != 0 {
|
||||
line_text_width += cast(float) font_to_use.glyphs[index].advanceX;
|
||||
} else {
|
||||
line_text_width += (font_to_use.recs[index].width + cast(float) font_to_use.glyphs[index].offsetX);
|
||||
}
|
||||
}
|
||||
|
||||
max_text_width = c_max(max_text_width, line_text_width);
|
||||
text_size.width = max_text_width / 2;
|
||||
text_size.height = text_height;
|
||||
|
||||
return text_size;
|
||||
}
|
2
bindings/jai/examples/modules/raylib-jai/.gitignore
vendored
Normal file
2
bindings/jai/examples/modules/raylib-jai/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.build
|
||||
raylib/
|
41
bindings/jai/examples/modules/raylib-jai/README.md
Normal file
41
bindings/jai/examples/modules/raylib-jai/README.md
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
Module by [Grouflon](https://github.com/Grouflon/raylib-jai).
|
||||
|
||||
# Raylib Module for Jai
|
||||
Module and generator script for [Raylib](https://www.raylib.com).
|
||||
Current version is **Raylib 5.1**.
|
||||
|
||||
## How to use
|
||||
- Checkout this repository and put it in the `modules` folder of your project.
|
||||
- Include the module with the `#import "raylib";` directive.
|
||||
|
||||
## Example
|
||||
```
|
||||
#import "raylib";
|
||||
|
||||
main :: ()
|
||||
{
|
||||
InitWindow(800, 600, "raylib example");
|
||||
SetTargetFPS(60);
|
||||
|
||||
while !WindowShouldClose()
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
}
|
||||
```
|
||||
|
||||
## Supported Platforms
|
||||
- Windows
|
||||
- Wasm (Not working yet because of some 32bits/64bits mismatch)
|
||||
|
||||
## Contributing
|
||||
Feel free to submit pull requests if you want to add new platforms or any improvement.
|
||||
|
100
bindings/jai/examples/modules/raylib-jai/generate.jai
Normal file
100
bindings/jai/examples/modules/raylib-jai/generate.jai
Normal file
@ -0,0 +1,100 @@
|
||||
AT_COMPILE_TIME :: true;
|
||||
|
||||
RAYLIB_PATH :: "raylib";
|
||||
|
||||
DECLARATIONS_TO_OMIT :: string.[
|
||||
"Vector2",
|
||||
"Vector3",
|
||||
"Vector4",
|
||||
"Quaternion",
|
||||
"PI",
|
||||
"TraceLogLevel",
|
||||
"PixelFormat",
|
||||
"TextureFilter",
|
||||
"BlendMode",
|
||||
"ShaderLocationIndex",
|
||||
"ShaderUniformDataType",
|
||||
"ShaderAttributeDataType",
|
||||
];
|
||||
|
||||
#if AT_COMPILE_TIME {
|
||||
#run,stallable {
|
||||
set_build_options_dc(.{do_output=false});
|
||||
root_options := get_build_options();
|
||||
args := root_options.compile_time_command_line;
|
||||
if !generate_bindings(args) {
|
||||
compiler_set_workspace_status(.FAILED);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#import "System";
|
||||
|
||||
main :: () {
|
||||
set_working_directory(path_strip_filename(get_path_of_running_executable()));
|
||||
args := get_command_line_arguments();
|
||||
if !generate_bindings(args) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generate_bindings :: (args: [] string) -> bool
|
||||
{
|
||||
output_filename: string;
|
||||
opts: Generate_Bindings_Options;
|
||||
{
|
||||
using opts;
|
||||
|
||||
target_wasm: = false;
|
||||
if array_find(args, "-wasm") target_wasm = true;
|
||||
|
||||
if target_wasm
|
||||
{
|
||||
array_add(*libpaths, "wasm");
|
||||
output_filename = "wasm.jai";
|
||||
opts.static_library_suffix = ".a";
|
||||
}
|
||||
else
|
||||
{
|
||||
#if OS == .WINDOWS {
|
||||
array_add(*libpaths, "windows");
|
||||
output_filename = "windows.jai";
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
array_add(*libnames, "raylib");
|
||||
array_add(*include_paths, RAYLIB_PATH);
|
||||
array_add(*source_files, tprint("%/src/raylib.h", RAYLIB_PATH));
|
||||
array_add(*source_files, tprint("%/src/raymath.h", RAYLIB_PATH));
|
||||
array_add(*source_files, tprint("%/src/rlgl.h", RAYLIB_PATH));
|
||||
array_add(*strip_prefixes, "rl");
|
||||
auto_detect_enum_prefixes = false;
|
||||
log_stripped_declarations = false;
|
||||
generate_compile_time_struct_checks = false;
|
||||
|
||||
visitor = raylib_visitor;
|
||||
}
|
||||
|
||||
return generate_bindings(opts, output_filename);
|
||||
}
|
||||
|
||||
raylib_visitor :: (decl: *Declaration, parent_decl: *Declaration) -> Declaration_Visit_Result
|
||||
{
|
||||
if !parent_decl
|
||||
{
|
||||
if array_find(DECLARATIONS_TO_OMIT, decl.name)
|
||||
{
|
||||
decl.decl_flags |= .OMIT_FROM_OUTPUT;
|
||||
return .STOP;
|
||||
}
|
||||
}
|
||||
|
||||
return .RECURSE;
|
||||
}
|
||||
|
||||
#import "Basic";
|
||||
#import "Bindings_Generator";
|
||||
#import "Compiler";
|
||||
#import "String";
|
51
bindings/jai/examples/modules/raylib-jai/module.jai
Normal file
51
bindings/jai/examples/modules/raylib-jai/module.jai
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
LIGHTGRAY :: Color.{ 200, 200, 200, 255 };
|
||||
GRAY :: Color.{ 130, 130, 130, 255 };
|
||||
DARKGRAY :: Color.{ 80, 80, 80, 255 };
|
||||
YELLOW :: Color.{ 253, 249, 0, 255 };
|
||||
GOLD :: Color.{ 255, 203, 0, 255 };
|
||||
ORANGE :: Color.{ 255, 161, 0, 255 };
|
||||
PINK :: Color.{ 255, 109, 194, 255 };
|
||||
RED :: Color.{ 230, 41, 55, 255 };
|
||||
MAROON :: Color.{ 190, 33, 55, 255 };
|
||||
GREEN :: Color.{ 0, 228, 48, 255 };
|
||||
LIME :: Color.{ 0, 158, 47, 255 };
|
||||
DARKGREEN :: Color.{ 0, 117, 44, 255 };
|
||||
SKYBLUE :: Color.{ 102, 191, 255, 255 };
|
||||
BLUE :: Color.{ 0, 121, 241, 255 };
|
||||
DARKBLUE :: Color.{ 0, 82, 172, 255 };
|
||||
PURPLE :: Color.{ 200, 122, 255, 255 };
|
||||
VIOLET :: Color.{ 135, 60, 190, 255 };
|
||||
DARKPURPLE :: Color.{ 112, 31, 126, 255 };
|
||||
BEIGE :: Color.{ 211, 176, 131, 255 };
|
||||
BROWN :: Color.{ 127, 106, 79, 255 };
|
||||
DARKBROWN :: Color.{ 76, 63, 47, 255 };
|
||||
WHITE :: Color.{ 255, 255, 255, 255 };
|
||||
BLACK :: Color.{ 0, 0, 0, 255 };
|
||||
BLANK :: Color.{ 0, 0, 0, 0 };
|
||||
MAGENTA :: Color.{ 255, 0, 255, 255 };
|
||||
RAYWHITE :: Color.{ 245, 245, 245, 255 };
|
||||
|
||||
IsMouseButtonPressed :: (button: MouseButton) -> bool { return IsMouseButtonPressed(cast(s32) button); }
|
||||
IsMouseButtonDown :: (button: MouseButton) -> bool { return IsMouseButtonDown(cast(s32) button); }
|
||||
IsMouseButtonReleased :: (button: MouseButton) -> bool { return IsMouseButtonReleased(cast(s32) button); }
|
||||
IsMouseButtonUp :: (button: MouseButton) -> bool { return IsMouseButtonUp(cast(s32) button); }
|
||||
|
||||
IsKeyPressed :: (key: KeyboardKey) -> bool { return IsKeyPressed(cast(s32) key); }
|
||||
IsKeyPressedRepeat :: (key: KeyboardKey) -> bool { return IsKeyPressedRepeat(cast(s32) key); }
|
||||
IsKeyDown :: (key: KeyboardKey) -> bool { return IsKeyDown(cast(s32) key); }
|
||||
IsKeyReleased :: (key: KeyboardKey) -> bool { return IsKeyReleased(cast(s32) key); }
|
||||
IsKeyUp :: (key: KeyboardKey) -> bool { return IsKeyUp(cast(s32) key); }
|
||||
SetExitKey :: (key: KeyboardKey) -> void { return SetExitKey(cast(s32) key); }
|
||||
|
||||
#scope_module
|
||||
|
||||
#if OS == .WINDOWS {
|
||||
#load "windows.jai";
|
||||
}
|
||||
#if OS == .WASM {
|
||||
#load "wasm.jai";
|
||||
}
|
||||
|
||||
#import "Basic";
|
||||
#import "Math";
|
2291
bindings/jai/examples/modules/raylib-jai/wasm.jai
Normal file
2291
bindings/jai/examples/modules/raylib-jai/wasm.jai
Normal file
File diff suppressed because it is too large
Load Diff
BIN
bindings/jai/examples/modules/raylib-jai/wasm/raylib.a
Normal file
BIN
bindings/jai/examples/modules/raylib-jai/wasm/raylib.a
Normal file
Binary file not shown.
2291
bindings/jai/examples/modules/raylib-jai/windows.jai
Normal file
2291
bindings/jai/examples/modules/raylib-jai/windows.jai
Normal file
File diff suppressed because it is too large
Load Diff
BIN
bindings/jai/examples/modules/raylib-jai/windows/raylib.dll
Normal file
BIN
bindings/jai/examples/modules/raylib-jai/windows/raylib.dll
Normal file
Binary file not shown.
BIN
bindings/jai/examples/modules/raylib-jai/windows/raylib.lib
Normal file
BIN
bindings/jai/examples/modules/raylib-jai/windows/raylib.lib
Normal file
Binary file not shown.
BIN
bindings/jai/examples/modules/raylib-jai/windows/raylib.pdb
Normal file
BIN
bindings/jai/examples/modules/raylib-jai/windows/raylib.pdb
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user