Skip to content

Commit

Permalink
add ability to load static cursors from text-based asset files (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgi388 authored Jan 16, 2025
1 parent 047602f commit 1c75988
Show file tree
Hide file tree
Showing 12 changed files with 695 additions and 4 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ license = "MIT OR Apache-2.0"
[features]
default = []
serde = ["dep:serde", "bitflags/serde", "ico/serde"]
serde_asset = ["serde"]
serde_json_asset = ["dep:serde_json", "serde_asset"]
serde_ron_asset = ["dep:ron", "serde_asset"]
serde_toml_asset = ["dep:toml", "serde_asset"]

# TODO: Change 0.16.0-dev to 0.16.0 once Bevy 0.16 is released.
[dependencies]
Expand All @@ -24,8 +28,11 @@ byteorder = "1.5"
ico = "0.4"
image = "0.25"
riff = "2"
ron = { version = "0.8", optional = true, default-features = false }
serde = { version = "1", optional = true, default-features = false }
serde_json = { version = "1", optional = true }
thiserror = "2"
toml = { version = "0.8", optional = true }

# TODO: Change 0.16.0-dev to 0.16.0 once Bevy 0.16 is released.
[dev-dependencies]
Expand All @@ -41,9 +48,18 @@ bevy = { version = "0.16.0-dev", default-features = false, features = [
] }
ron = "0.8"

[lints.clippy]
type_complexity = "allow"

[package.metadata.docs.rs]
all-features = true

[[example]]
name = "cur_ron_asset"
path = "examples/cur_ron_asset.rs"
doc-scrape-examples = true
required-features = ["serde_ron_asset"]

# TODO: Remove once Bevy 0.16 is released.
[patch.crates-io]
bevy = { git = "https://github.com/bevyengine/bevy.git", branch = "main" }
Expand Down
49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
# Bevy cursor kit
# `bevy_cursor_kit`

[![Crates.io](https://img.shields.io/crates/v/bevy_cursor_kit.svg)](https://crates.io/crates/bevy_cursor_kit)
[![Docs.rs](https://docs.rs/bevy_cursor_kit/badge.svg)](https://docs.rs/bevy_cursor_kit)
[![CI](https://github.com/mgi388/bevy-cursor-kit/workflows/CI/badge.svg)](https://github.com/mgi388/bevy-cursor-kit/actions)

## Summary

Allows you to load .CUR and .ANI cursor files in your Bevy app and use them in custom `CursorIcon`s.
`bevy_cursor_kit` is a crate for Bevy apps that lets you load cursor assets in various formats and use them as custom `CursorIcon`s.

- .CUR files can be used for static cursor icons like a grabbing hand.
- .ANI files can be used for animated cursor icons like an hourglass.
## Features

### `.CUR` and `.ANI` binary formats

Load the classic Microsoft Windows `.CUR` and `.ANI` cursor file formats.

- `.CUR` files can be used for static cursor icons like a grabbing hand.
- `.ANI` files can be used for animated cursor icons like an hourglass.

### `.cur.json` ,`.cur.ron`, `.cur.toml` text formats

Text-based versions of the classic `.CUR` static cursor file format.

Write your static cursors in JSON, RON, or TOML and `bevy_cursor_kit` can load them for you.

```ron
(
image: (
path: "path/to/sprite-sheet.png",
),
texture_atlas_layout: (
tile_size: (32, 32),
columns: 20,
rows: 10,
),
hotspots: (
default: (0, 0),
overrides: {
11: (32, 32),
95: (32, 8),
},
),
)
```

Check out the [cur_ron_asset.rs example](example/cur_ron_asset.rs) for more details.

## Quick start

Expand Down Expand Up @@ -43,6 +78,12 @@ commands
}));
```

If you want to use the text-based formats, enable the `serde_json_asset`, `serde_ron_asset`, or `serde_toml_asset` feature in your `Cargo.toml` and load away:

```rust
let handle = asset_server.load("example.cur.ron");
```

Check out the [examples](examples) for more details.

## License
Expand Down
20 changes: 20 additions & 0 deletions assets/kenney_crosshairPack.cur.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(
image: (
path: "kenney_crosshairPack/Tilesheet/crosshairs_tilesheet_white.png",
),
texture_atlas_layout: (
tile_size: (64, 64),
columns: 20,
rows: 10,
padding: Some((5, 5)),
),
hotspots: (
// The hotspot for the default cursor. Can be omitted if it's (0, 0).
default: (0, 0),
overrides: {
11: (32, 32),
95: (32, 8),
// You can add more overrides here.
},
),
)
19 changes: 19 additions & 0 deletions assets/kenney_crosshairPack/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


Crosshair Pack

by Kenney Vleugels (Kenney.nl)

------------------------------

License (Creative Commons Zero, CC0)
http://creativecommons.org/publicdomain/zero/1.0/

You may use these assets in personal and commercial projects.
Credit (Kenney or www.kenney.nl) would be nice but is not mandatory.

------------------------------

Donate: http://support.kenney.nl

Follow on Twitter for updates: @KenneyNL (www.twitter.com/kenneynl)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1c75988

Please sign in to comment.