Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37bc3c5dbb | ||
|
|
56155d066a | ||
|
|
f27e83b467 | ||
|
|
50d4b4b09c | ||
|
|
51e6881cb0 | ||
|
|
8a69d15b49 | ||
|
|
3af5e3dccb | ||
|
|
76a1b4691d | ||
|
|
e877b599c1 | ||
|
|
cc38e31dbb | ||
|
|
2739c45181 | ||
|
|
18b05338bf | ||
|
|
73ebb1655a | ||
|
|
87ff0968d8 | ||
|
|
54b454f8b9 | ||
|
|
6d0975fe15 | ||
|
|
64960b8c3c | ||
|
|
cf518a2c40 | ||
|
|
bf588528ca | ||
|
|
db98ba627b | ||
|
|
479b7196cf | ||
|
|
a338ff02f1 | ||
|
|
f9b29d4645 | ||
|
|
33f1984862 | ||
|
|
c2318f9929 | ||
|
|
1648aa5736 | ||
|
|
43b20ecd0d | ||
|
|
fff5aa8596 | ||
|
|
032a450d7e | ||
|
|
0881080b3f | ||
|
|
07784a848c | ||
|
|
bdf128addc |
No files matched your search
+63
-1
@@ -2,6 +2,62 @@
|
||||
|
||||
## [Unreleased] - ReleaseDate
|
||||
|
||||
## [0.2.8] - 2025-11-07
|
||||
|
||||
### Changed
|
||||
|
||||
- Replace non-ASCII characters in text input with '?'
|
||||
- Use `smithay-clipboard` crate for clipboard support on Wayland
|
||||
|
||||
## [0.2.7] - 2025-11-02
|
||||
|
||||
### Added
|
||||
|
||||
- Add missing window icon. Note for package maintainers: On Wayland, the name of the `.desktop` file entries needs to match RustyPoB's `app_id`. `app_id` is set to either `rusty-path-of-building-1` or `rusty-path-of-building-2`, depending on the game argument.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix missing window title during installation step
|
||||
- Fix UI scaling factor not being applied at startup on X11
|
||||
|
||||
## [0.2.6] - 2025-10-31
|
||||
|
||||
### Added
|
||||
|
||||
- Add regular variant of Fontin font
|
||||
- Add stubs for DPI scale overrides
|
||||
|
||||
## [0.2.5] - 2025-10-30
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for "faux italics"
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix crash that occurs due to surface format selection not filtering out formats that require unrequested GPU features
|
||||
|
||||
## [0.2.4] - 2025-10-30
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for loading webp images
|
||||
- Add support for new 'fontin' fonts
|
||||
|
||||
### Changed
|
||||
|
||||
- Use `~/.local/share/RustyPathOfBuilding{1,2}/userdata` as default location for settings and build files. Builds files created prior to this change need to be manually copied from the old location in `~/Documents/`. Sorry about the inconvenience.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix scrolling of gem selection dropdown
|
||||
|
||||
## [0.2.3] - 2025-10-29
|
||||
|
||||
### Added
|
||||
|
||||
- Add exponential backoff for github requests
|
||||
|
||||
## [0.2.2] - 2025-10-29
|
||||
|
||||
### Fixed
|
||||
@@ -62,8 +118,14 @@
|
||||
- First release
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.2...HEAD
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.8...HEAD
|
||||
|
||||
[0.2.8]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.7...v0.2.8
|
||||
[0.2.7]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.6...v0.2.7
|
||||
[0.2.6]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.5...v0.2.6
|
||||
[0.2.5]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.4...v0.2.5
|
||||
[0.2.4]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.3...v0.2.4
|
||||
[0.2.3]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.2...v0.2.3
|
||||
[0.2.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.1...v0.2.2
|
||||
[0.2.1]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.0...v0.2.1
|
||||
[0.2.0]: https://github.com/meehl/rusty-path-of-building/compare/v0.1.2...v0.2.0
|
||||
|
||||
Generated
+111
-101
@@ -173,7 +173,6 @@ dependencies = [
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"windows-sys 0.60.2",
|
||||
"wl-clipboard-rs",
|
||||
"x11rb",
|
||||
]
|
||||
|
||||
@@ -242,7 +241,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"arrayvec",
|
||||
"log",
|
||||
"nom 8.0.0",
|
||||
"nom",
|
||||
"num-rational",
|
||||
"v_frame",
|
||||
]
|
||||
@@ -387,18 +386,43 @@ dependencies = [
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop"
|
||||
version = "0.14.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb9f6e1368bd4621d2c86baa7e37de77a938adf5221e5dd3d6133340101b309e"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"polling",
|
||||
"rustix 1.1.2",
|
||||
"slab",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop-wayland-source"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20"
|
||||
dependencies = [
|
||||
"calloop",
|
||||
"calloop 0.13.0",
|
||||
"rustix 0.38.44",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop-wayland-source"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa"
|
||||
dependencies = [
|
||||
"calloop 0.14.3",
|
||||
"rustix 1.1.2",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.43"
|
||||
@@ -803,12 +827,6 @@ dependencies = [
|
||||
"thiserror 2.0.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "fdeflate"
|
||||
version = "0.3.7"
|
||||
@@ -836,12 +854,6 @@ version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.5"
|
||||
@@ -1120,6 +1132,7 @@ checksum = "529feb3e6769d234375c4cf1ee2ce713682b8e76538cb13f9fc23e1400a591e7"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder-lite",
|
||||
"image-webp",
|
||||
"moxcms",
|
||||
"num-traits",
|
||||
"png",
|
||||
@@ -1129,6 +1142,16 @@ dependencies = [
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image-webp"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
|
||||
dependencies = [
|
||||
"byteorder-lite",
|
||||
"quick-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "imgref"
|
||||
version = "1.12.0"
|
||||
@@ -1386,12 +1409,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.9"
|
||||
@@ -1507,16 +1524,6 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "8.0.0"
|
||||
@@ -1932,16 +1939,6 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_pipe"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "owned_ttf_parser"
|
||||
version = "0.25.1"
|
||||
@@ -2006,16 +2003,6 @@ version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db"
|
||||
dependencies = [
|
||||
"fixedbitset",
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.1.10"
|
||||
@@ -2519,7 +2506,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-path-of-building"
|
||||
version = "0.2.2"
|
||||
version = "0.2.8"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
@@ -2544,7 +2531,9 @@ dependencies = [
|
||||
"pollster",
|
||||
"profiling",
|
||||
"puffin_http",
|
||||
"raw-window-handle",
|
||||
"regex",
|
||||
"smithay-clipboard",
|
||||
"swash",
|
||||
"tar",
|
||||
"ureq",
|
||||
@@ -2583,7 +2572,7 @@ dependencies = [
|
||||
"ab_glyph",
|
||||
"log",
|
||||
"memmap2",
|
||||
"smithay-client-toolkit",
|
||||
"smithay-client-toolkit 0.19.2",
|
||||
"tiny-skia",
|
||||
]
|
||||
|
||||
@@ -2676,8 +2665,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"calloop",
|
||||
"calloop-wayland-source",
|
||||
"calloop 0.13.0",
|
||||
"calloop-wayland-source 0.3.0",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
@@ -2694,6 +2683,44 @@ dependencies = [
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smithay-client-toolkit"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0512da38f5e2b31201a93524adb8d3136276fa4fe4aafab4e1f727a82b534cc0"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"calloop 0.14.3",
|
||||
"calloop-wayland-source 0.4.1",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
"memmap2",
|
||||
"rustix 1.1.2",
|
||||
"thiserror 2.0.17",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-csd-frame",
|
||||
"wayland-cursor",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-experimental",
|
||||
"wayland-protocols-misc",
|
||||
"wayland-protocols-wlr",
|
||||
"wayland-scanner",
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smithay-clipboard"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71704c03f739f7745053bde45fa203a46c58d25bc5c4efba1d9a60e9dba81226"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"smithay-client-toolkit 0.20.0",
|
||||
"wayland-backend",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smol_str"
|
||||
version = "0.2.2"
|
||||
@@ -2788,19 +2815,6 @@ version = "0.12.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.3.4",
|
||||
"once_cell",
|
||||
"rustix 1.1.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.4.1"
|
||||
@@ -2956,6 +2970,7 @@ version = "0.1.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-core",
|
||||
]
|
||||
@@ -2966,18 +2981,6 @@ version = "0.1.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
|
||||
|
||||
[[package]]
|
||||
name = "tree_magic_mini"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f943391d896cdfe8eec03a04d7110332d445be7df856db382dd96a730667562c"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"nom 7.1.3",
|
||||
"once_cell",
|
||||
"petgraph",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ttf-parser"
|
||||
version = "0.25.1"
|
||||
@@ -3216,6 +3219,32 @@ dependencies = [
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-experimental"
|
||||
version = "20250721.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40a1f863128dcaaec790d7b4b396cc9b9a7a079e878e18c47e6c2d2c5a8dcbb1"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-misc"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dfe33d551eb8bffd03ff067a8b44bb963919157841a99957151299a6307d19c"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-plasma"
|
||||
version = "0.3.9"
|
||||
@@ -3726,7 +3755,7 @@ dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"block2",
|
||||
"bytemuck",
|
||||
"calloop",
|
||||
"calloop 0.13.0",
|
||||
"cfg_aliases",
|
||||
"concurrent-queue",
|
||||
"core-foundation",
|
||||
@@ -3748,7 +3777,7 @@ dependencies = [
|
||||
"redox_syscall 0.4.1",
|
||||
"rustix 0.38.44",
|
||||
"sctk-adwaita",
|
||||
"smithay-client-toolkit",
|
||||
"smithay-client-toolkit 0.19.2",
|
||||
"smol_str",
|
||||
"tracing",
|
||||
"unicode-segmentation",
|
||||
@@ -3781,25 +3810,6 @@ version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
|
||||
[[package]]
|
||||
name = "wl-clipboard-rs"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e5ff8d0e60065f549fafd9d6cb626203ea64a798186c80d8e7df4f8af56baeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"os_pipe",
|
||||
"rustix 0.38.44",
|
||||
"tempfile",
|
||||
"thiserror 2.0.17",
|
||||
"tree_magic_mini",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-wlr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "writeable"
|
||||
version = "0.6.2"
|
||||
|
||||
+7
-3
@@ -4,14 +4,14 @@ authors = ["meehl"]
|
||||
description = "Cross-platform runtime for Path of Building"
|
||||
repository = "https://github.com/meehl/rusty-path-of-building"
|
||||
license = "MIT"
|
||||
version = "0.2.2"
|
||||
version = "0.2.8"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
ahash = "0.8.12"
|
||||
anyhow = "1.0"
|
||||
arboard = { version = "3.6.1", default-features = false, features = ["wayland-data-control"] }
|
||||
arboard = { version = "3.6.1", default-features = false }
|
||||
bytemuck = "1.23.2"
|
||||
clap = { version = "4.5.46", features = ["derive"] }
|
||||
dds = "0.1.0"
|
||||
@@ -21,7 +21,7 @@ euclid = { version = "0.22.11", features = ["bytemuck"] }
|
||||
fast_image_resize = { version = "5.3.0", features = ["image"] }
|
||||
flate2 = "1.1.2"
|
||||
glob = "0.3.3"
|
||||
image = { version = "0.25.8", default-features = false, features = ["rayon", "jpeg", "png"] }
|
||||
image = { version = "0.25.8", default-features = false, features = ["rayon", "jpeg", "png", "webp"] }
|
||||
log = "0.4"
|
||||
mlua = { version = "0.11.2", features = ["luajit", "anyhow"] }
|
||||
nohash-hasher = "0.2.0"
|
||||
@@ -32,6 +32,7 @@ parley = "0.6.0"
|
||||
pollster = "0.3"
|
||||
profiling = "1.0"
|
||||
puffin_http = { version = "0.16", optional = true }
|
||||
raw-window-handle = "0.6.2"
|
||||
regex = "1.11.2"
|
||||
swash = "0.2.5"
|
||||
tar = "0.4.44"
|
||||
@@ -40,5 +41,8 @@ wgpu = { version = "27.0.1", default-features = false, features = ["std", "parki
|
||||
winit = "0.30"
|
||||
zstd = "0.13.3"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
smithay-clipboard = "0.7.3"
|
||||
|
||||
[features]
|
||||
profile-with-puffin = ["profiling/profile-with-puffin", "dep:puffin_http"]
|
||||
@@ -1,8 +1,8 @@
|
||||
# Rusty Path of Building
|
||||
|
||||
Rusty Path of Building is a cross-platform runtime for [Path of Building](https://github.com/PathOfBuildingCommunity/PathOfBuilding) and [Path of Building 2](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2). Like the [official runtime](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic), it serves as a host environment for PoB by implementing the API used by the application's Lua logic, as well as rendering, window management, and input handling.
|
||||
Rusty Path of Building is a cross-platform runtime environment for [Path of Building](https://github.com/PathOfBuildingCommunity/PathOfBuilding) and [Path of Building 2](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2). Like [SimpleGraphic](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic), PoB's official runtime environment, it implements the API functions required by PoB's Lua code, handles window management and input, and renders the UI.
|
||||
|
||||
This project was primarily created to allow Path of Building to run natively on Linux. It is written in Rust (in case you couldn't already tell from the unimaginative name) and should run on all platforms, though only Linux has been tested so far.
|
||||
The primary goal of this project is to provide native Linux support for Path of Building. It is written in Rust with cross-platform compatibility in mind and also runs on Windows, though testing there has been minimal.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -14,10 +14,14 @@ rusty-path-of-building [poe1|poe2]
|
||||
|
||||
### Arch (AUR)
|
||||
|
||||
[](https://aur.archlinux.org/packages/rusty-path-of-building)
|
||||
[](https://aur.archlinux.org/packages/rusty-path-of-building)
|
||||
|
||||
Please check [the Arch Wiki](https://wiki.archlinux.org/title/Arch_User_Repository) on how to install packages from the AUR.
|
||||
|
||||
### Flathub
|
||||
|
||||
[](https://flathub.org/en/apps/community.pathofbuilding.PathOfBuilding)
|
||||
|
||||
### Building from source
|
||||
|
||||
`LuaJIT` needs to be installed on your system for the `mlua` crate to compile.
|
||||
@@ -39,4 +43,5 @@ Please refer to the [Lua documentation](https://www.lua.org/manual/5.1/manual.ht
|
||||
|
||||
## Known Issues
|
||||
|
||||
- The clipboard doesn't work with Wayland compositors that don't support the data-control extension(s). It is recommended to fall back to `Xwayland` in these cases. This can be done by unsetting `WAYLAND_DISPLAY`. More info here: https://github.com/1Password/arboard?tab=readme-ov-file#backend-support
|
||||
- Overriding UI scaling through the options is currently not implemented.
|
||||
- If automatic updates fail, navigate to `~/.local/share/RustyPathOfBuilding{1,2}/` and delete both the `rpob.version` file and the `Update` directory. This will force a complete re-download of PoB's latest assets and Lua code on the next startup. (Note: Third-party backends, like this project, face challenges supporting PoB's update mechanism. To make it work, fragile workarounds had to be implemented that can break unexpectedly)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
+17
-6
@@ -13,9 +13,12 @@ use crate::{
|
||||
},
|
||||
rendering::PoBString,
|
||||
search_handle::new_search_handle,
|
||||
window::{get_screen_scale, get_screen_size, set_foreground, set_window_title},
|
||||
window::{
|
||||
get_dpi_scale_override, get_screen_scale, get_screen_size, set_dpi_scale_override,
|
||||
set_foreground, set_window_title,
|
||||
},
|
||||
},
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
};
|
||||
use mlua::{IntoLuaMulti, Lua, MultiValue, Result as LuaResult, Variadic};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
@@ -88,6 +91,14 @@ pub fn register_globals(lua: &Lua) -> LuaResult<()> {
|
||||
globals.set("GetScreenScale", lua.create_function(get_screen_scale)?)?;
|
||||
globals.set("SetWindowTitle", lua.create_function(set_window_title)?)?;
|
||||
globals.set("SetForeground", lua.create_function(set_foreground)?)?;
|
||||
globals.set(
|
||||
"SetDPIScaleOverridePercent",
|
||||
lua.create_function(set_dpi_scale_override)?,
|
||||
)?;
|
||||
globals.set(
|
||||
"GetDPIScaleOverridePercent",
|
||||
lua.create_function(get_dpi_scale_override)?,
|
||||
)?;
|
||||
|
||||
// lua
|
||||
globals.set("PCall", lua.create_function(protected_call)?)?;
|
||||
@@ -118,8 +129,8 @@ fn strip_escapes(_: &Lua, text: String) -> LuaResult<String> {
|
||||
}
|
||||
|
||||
fn restart(l: &Lua, _: ()) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
*socket.needs_restart() = true;
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
*ctx.needs_restart() = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -131,10 +142,10 @@ fn open_url(l: &Lua, url: String) -> LuaResult<MultiValue> {
|
||||
}
|
||||
|
||||
fn render_init(l: &Lua, features: Variadic<String>) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
for feature in features {
|
||||
if feature == "DPI_AWARE" {
|
||||
*socket.is_dpi_aware() = true;
|
||||
*ctx.is_dpi_aware() = true;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
+6
-13
@@ -1,20 +1,13 @@
|
||||
use crate::lua::ContextSocket;
|
||||
use crate::lua::Context;
|
||||
use mlua::{Lua, Result as LuaResult};
|
||||
|
||||
pub fn copy(l: &Lua, text: String) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket
|
||||
.clipboard()
|
||||
.set_text(text)
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.window().set_clipboard_text(text);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn paste(l: &Lua, _: ()) -> LuaResult<String> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let text = socket
|
||||
.clipboard()
|
||||
.get_text()
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
Ok(text)
|
||||
pub fn paste(l: &Lua, _: ()) -> LuaResult<Option<String>> {
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
Ok(ctx.window().get_clipboard_text())
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
renderer::textures::{TextureHandle, TextureOptions},
|
||||
};
|
||||
use mlua::{Lua, MultiValue, Result as LuaResult, UserData};
|
||||
@@ -56,7 +56,7 @@ fn load(
|
||||
handle: &mut ImageHandle,
|
||||
(image_path, flags): (String, MultiValue),
|
||||
) -> LuaResult<()> {
|
||||
let socket = lua.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = lua.app_data_ref::<&'static Context>().unwrap();
|
||||
let mut is_async = false;
|
||||
let mut options = TextureOptions::LINEAR_REPEAT;
|
||||
|
||||
@@ -76,7 +76,7 @@ fn load(
|
||||
// replace image data if already allocated
|
||||
ImageHandle::Loaded(texture_handle) => {
|
||||
// in case of error, stay loaded with current texture
|
||||
let _ = socket.texture_manager().update_texture(
|
||||
let _ = ctx.texture_manager().update_texture(
|
||||
texture_handle.id(),
|
||||
image_path,
|
||||
options,
|
||||
@@ -85,7 +85,7 @@ fn load(
|
||||
}
|
||||
// create new texture handle
|
||||
ImageHandle::Unloaded => {
|
||||
if let Ok(tex_handle) = socket
|
||||
if let Ok(tex_handle) = ctx
|
||||
.texture_manager()
|
||||
.load_texture(image_path, options, is_async)
|
||||
{
|
||||
|
||||
+6
-6
@@ -1,22 +1,22 @@
|
||||
use crate::{
|
||||
input::{str_as_keycode, str_as_mousebutton},
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
};
|
||||
use mlua::{Lua, Result as LuaResult};
|
||||
|
||||
pub fn get_cursor_pos(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let pos = socket.input().mouse_pos();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let pos = ctx.input().mouse_pos();
|
||||
Ok((pos.x as u32, pos.y as u32))
|
||||
}
|
||||
|
||||
pub fn is_key_down(l: &Lua, key_name: String) -> LuaResult<bool> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
if let Some(code) = str_as_keycode(&key_name) {
|
||||
Ok(socket.input().key_pressed(code))
|
||||
Ok(ctx.input().key_pressed(code))
|
||||
} else if let Some(button) = str_as_mousebutton(&key_name) {
|
||||
Ok(socket.input().mouse_pressed(button))
|
||||
Ok(ctx.input().mouse_pressed(button))
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
+7
-19
@@ -1,26 +1,14 @@
|
||||
use anyhow::anyhow;
|
||||
use directories::UserDirs;
|
||||
use mlua::{IntoLuaMulti, Lua, MultiValue, Result as LuaResult, Value};
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use crate::{
|
||||
args::Game,
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
util::{change_working_directory, get_executable_dir},
|
||||
};
|
||||
|
||||
pub fn get_user_path(_: &Lua, _: ()) -> LuaResult<anyhow::Result<PathBuf>> {
|
||||
let user_dirs = match UserDirs::new() {
|
||||
Some(user_dirs) => user_dirs,
|
||||
None => return Ok(Err(anyhow!("Failed to retrieve user's home directory"))),
|
||||
};
|
||||
|
||||
match user_dirs.document_dir() {
|
||||
Some(docs_dir) => Ok(Ok(docs_dir.canonicalize().unwrap())),
|
||||
None => Ok(Err(anyhow!(
|
||||
"Failed to retrieve user's documents directory"
|
||||
))),
|
||||
}
|
||||
pub fn get_user_path(_: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
Ok(Game::user_data_dir())
|
||||
}
|
||||
|
||||
// parent directory of Launch.lua script
|
||||
@@ -37,15 +25,15 @@ pub fn get_runtime_path(_: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
}
|
||||
|
||||
pub fn get_work_dir(l: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
Ok(socket.current_working_dir().to_path_buf())
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
Ok(ctx.current_working_dir().to_path_buf())
|
||||
}
|
||||
|
||||
// NOTE: unused
|
||||
pub fn set_work_dir(l: &Lua, path: String) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
if change_working_directory(&path).is_ok() {
|
||||
*socket.current_working_dir() = path.into();
|
||||
*ctx.current_working_dir() = path.into();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+53
-48
@@ -2,8 +2,8 @@ use crate::{
|
||||
api::image_handle::ImageHandle,
|
||||
color::Srgba,
|
||||
dpi::Uv,
|
||||
fonts::{Alignment, LayoutJob},
|
||||
lua::ContextSocket,
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
lua::Context,
|
||||
math::{Point, Quad, Rect, Size},
|
||||
};
|
||||
use core::ffi::{c_int, c_void};
|
||||
@@ -11,8 +11,9 @@ use mlua::{
|
||||
LightUserData, Lua, Result as LuaResult, UserDataRefMut, Value,
|
||||
ffi::{self},
|
||||
};
|
||||
use parley::FontFamily;
|
||||
use regex::Regex;
|
||||
use std::sync::LazyLock;
|
||||
use std::{borrow::Cow, sync::LazyLock};
|
||||
|
||||
pub fn register_globals(lua: &Lua) -> LuaResult<()> {
|
||||
let globals = lua.globals();
|
||||
@@ -126,9 +127,7 @@ unsafe extern "C" fn lua_toimghandle(state: *mut ffi::lua_State, idx: c_int) ->
|
||||
unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("set_draw_color");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
match nargs {
|
||||
@@ -136,7 +135,7 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int
|
||||
1 => {
|
||||
let esc_str = str_from_stack!(state, -nargs);
|
||||
let color = Srgba::from_escape_code(esc_str);
|
||||
socket.layers().set_draw_color(color);
|
||||
ctx.layers().set_draw_color(color);
|
||||
}
|
||||
// rgb
|
||||
3 => {
|
||||
@@ -144,7 +143,7 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int
|
||||
let g = f32_from_stack!(state, -nargs + 1);
|
||||
let b = f32_from_stack!(state, -nargs + 2);
|
||||
let color = Srgba::new_f32(r, g, b, 1.0);
|
||||
socket.layers().set_draw_color(color);
|
||||
ctx.layers().set_draw_color(color);
|
||||
}
|
||||
// rgba
|
||||
4 => {
|
||||
@@ -153,7 +152,7 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int
|
||||
let b = f32_from_stack!(state, -nargs + 2);
|
||||
let a = f32_from_stack!(state, -nargs + 3);
|
||||
let color = Srgba::new_f32(r, g, b, a);
|
||||
socket.layers().set_draw_color(color);
|
||||
ctx.layers().set_draw_color(color);
|
||||
}
|
||||
_ => panic!("Unexpected number of arguments"),
|
||||
};
|
||||
@@ -164,22 +163,20 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int
|
||||
unsafe extern "C-unwind" fn set_viewport(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("set_viewport");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
match nargs {
|
||||
0 => socket
|
||||
0 => ctx
|
||||
.layers()
|
||||
.set_viewport_from_size(socket.window().logical_size()),
|
||||
.set_viewport_from_size(ctx.window().logical_size()),
|
||||
4 => {
|
||||
let x = f32_from_stack!(state, -nargs);
|
||||
let y = f32_from_stack!(state, -nargs + 1);
|
||||
let w = f32_from_stack!(state, -nargs + 2);
|
||||
let h = f32_from_stack!(state, -nargs + 3);
|
||||
let rect = Rect::from_origin_and_size(Point::new(x, y), Size::new(w, h));
|
||||
socket.layers().set_viewport(rect);
|
||||
ctx.layers().set_viewport(rect);
|
||||
}
|
||||
_ => panic!("Unexpected number of arguments"),
|
||||
};
|
||||
@@ -190,16 +187,14 @@ unsafe extern "C-unwind" fn set_viewport(state: *mut ffi::lua_State) -> c_int {
|
||||
unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("set_draw_layer");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
|
||||
match nargs {
|
||||
1 => {
|
||||
let layer = i32_from_stack!(state, -nargs);
|
||||
socket.layers().set_draw_layer(layer, 0);
|
||||
ctx.layers().set_draw_layer(layer, 0);
|
||||
}
|
||||
2 => {
|
||||
let layer = match unsafe { ffi::lua_type(state, -nargs) } {
|
||||
@@ -212,9 +207,9 @@ unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int
|
||||
};
|
||||
let sublayer = i32_from_stack!(state, -nargs + 1);
|
||||
if let Some(layer) = layer {
|
||||
socket.layers().set_draw_layer(layer, sublayer);
|
||||
ctx.layers().set_draw_layer(layer, sublayer);
|
||||
} else {
|
||||
socket.layers().set_draw_sublayer(sublayer);
|
||||
ctx.layers().set_draw_sublayer(sublayer);
|
||||
}
|
||||
}
|
||||
_ => panic!("Unexpected number of arguments"),
|
||||
@@ -226,9 +221,7 @@ unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int
|
||||
unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("draw_image");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
if !matches!(nargs, 5 | 6 | 7 | 9 | 10 | 11) {
|
||||
@@ -268,7 +261,7 @@ unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int {
|
||||
0
|
||||
};
|
||||
|
||||
socket.layers().draw_rect(texture_id, rect, uv, layer_idx);
|
||||
ctx.layers().draw_rect(texture_id, rect, uv, layer_idx);
|
||||
|
||||
0
|
||||
}
|
||||
@@ -276,9 +269,7 @@ unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int {
|
||||
unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("draw_image_quad", format!("args: {:?}", args));
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
if !matches!(nargs, 9 | 10 | 11 | 17 | 18 | 19) {
|
||||
@@ -336,7 +327,7 @@ unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c_int
|
||||
0
|
||||
};
|
||||
|
||||
socket.layers().draw_quad(texture_id, quad, uv, layer_idx);
|
||||
ctx.layers().draw_quad(texture_id, quad, uv, layer_idx);
|
||||
|
||||
0
|
||||
}
|
||||
@@ -344,9 +335,7 @@ unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c_int
|
||||
unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("draw_string");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
|
||||
@@ -369,7 +358,7 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
let mut position = Point::new(x, y);
|
||||
let mut is_absolute_position = false;
|
||||
// the position needs to be adjusted for some alignments to match PoBs behavior
|
||||
let screen_size = socket.window().logical_size();
|
||||
let screen_size = ctx.window().logical_size();
|
||||
let halign = match alignment {
|
||||
PoBTextAlignment::Left => Alignment::Min,
|
||||
PoBTextAlignment::Center => {
|
||||
@@ -386,7 +375,7 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
PoBTextAlignment::RightX => Alignment::Max,
|
||||
};
|
||||
|
||||
let current_draw_color = socket.layers().get_draw_color();
|
||||
let current_draw_color = ctx.layers().get_draw_color();
|
||||
let job = build_layout_job(
|
||||
text,
|
||||
current_draw_color,
|
||||
@@ -398,11 +387,11 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
// NOTE: color escape codes modify the current draw color.
|
||||
// set current draw color to color of last segment to match PoB's behavior
|
||||
if let Some(last_segment) = job.segments.last() {
|
||||
socket.layers().set_draw_color(last_segment.color);
|
||||
ctx.layers().set_draw_color(last_segment.color);
|
||||
}
|
||||
|
||||
let layout = socket.fonts().layout(job, socket.window().scale_factor);
|
||||
socket
|
||||
let layout = ctx.fonts().layout(job, ctx.window().scale_factor);
|
||||
ctx
|
||||
.layers()
|
||||
.draw_text(position, layout, is_absolute_position);
|
||||
|
||||
@@ -412,9 +401,7 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("get_string_width");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
|
||||
@@ -428,9 +415,9 @@ unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) -> c_in
|
||||
};
|
||||
|
||||
let job = build_layout_job(text, Srgba::WHITE, font_type, line_height, None);
|
||||
let width = socket
|
||||
let width = ctx
|
||||
.fonts()
|
||||
.get_text_width(job, socket.window().scale_factor);
|
||||
.get_text_width(job, ctx.window().scale_factor);
|
||||
|
||||
unsafe { ffi::lua_pushnumber(state, width as f64) };
|
||||
1
|
||||
@@ -441,15 +428,15 @@ fn get_index_at_cur(
|
||||
(line_height, font_type, text, cur_x, cur_y): (i32, String, String, f32, f32),
|
||||
) -> LuaResult<usize> {
|
||||
//profiling::scope!("get_char_index_at_cur");
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let font_type = font_type.parse::<PoBFontType>()?;
|
||||
|
||||
let job = build_layout_job(&text, Srgba::WHITE, font_type, line_height, None);
|
||||
let index = socket.fonts().get_text_index_at_cursor(
|
||||
let index = ctx.fonts().get_text_index_at_cursor(
|
||||
job,
|
||||
Point::new(cur_x, cur_y),
|
||||
socket.window().scale_factor,
|
||||
ctx.window().scale_factor,
|
||||
);
|
||||
|
||||
// convert to lua's 1-based indexing
|
||||
@@ -467,12 +454,21 @@ fn build_layout_job<'a>(
|
||||
alignment: Option<Alignment>,
|
||||
) -> LayoutJob<'a> {
|
||||
let mut font_weight = None;
|
||||
let mut font_style = FontStyle::default();
|
||||
let font_family = match font_type {
|
||||
PoBFontType::Fixed => parley::GenericFamily::Monospace,
|
||||
PoBFontType::Var => parley::GenericFamily::SansSerif,
|
||||
PoBFontType::Fixed => FontFamily::Named(Cow::Borrowed("Bitstream Vera Sans Mono")),
|
||||
PoBFontType::Var => FontFamily::Named(Cow::Borrowed("Liberation Sans")),
|
||||
PoBFontType::VarBold => {
|
||||
font_weight = Some(700.0);
|
||||
parley::GenericFamily::SansSerif
|
||||
FontFamily::Named(Cow::Borrowed("Liberation Sans"))
|
||||
}
|
||||
PoBFontType::Fontin => FontFamily::Named(Cow::Borrowed("Fontin")),
|
||||
PoBFontType::FontinItalic => FontFamily::Named(Cow::Borrowed("Fontin")),
|
||||
PoBFontType::FontinSmallcaps => FontFamily::Named(Cow::Borrowed("Fontin SmallCaps")),
|
||||
PoBFontType::FontinSmallcapsItalic => {
|
||||
font_style = FontStyle::Italic;
|
||||
// use regular Smallcaps with "faux italics"
|
||||
FontFamily::Named(Cow::Borrowed("Fontin SmallCaps"))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -485,6 +481,7 @@ fn build_layout_job<'a>(
|
||||
line_height as f32,
|
||||
alignment,
|
||||
font_weight,
|
||||
font_style,
|
||||
);
|
||||
|
||||
for (color, segment) in PoBString(text).into_iter() {
|
||||
@@ -622,6 +619,10 @@ enum PoBFontType {
|
||||
Fixed,
|
||||
Var,
|
||||
VarBold,
|
||||
FontinSmallcaps,
|
||||
FontinSmallcapsItalic,
|
||||
Fontin,
|
||||
FontinItalic,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for PoBFontType {
|
||||
@@ -632,6 +633,10 @@ impl std::str::FromStr for PoBFontType {
|
||||
"FIXED" => Ok(Self::Fixed),
|
||||
"VAR" => Ok(Self::Var),
|
||||
"VAR BOLD" => Ok(Self::VarBold),
|
||||
"FONTIN SC" => Ok(Self::FontinSmallcaps),
|
||||
"FONTIN SC ITALIC" => Ok(Self::FontinSmallcapsItalic),
|
||||
"FONTIN" => Ok(Self::Fontin),
|
||||
"FONTIN ITALIC" => Ok(Self::FontinItalic),
|
||||
_ => Err(anyhow::anyhow!(
|
||||
"'{}' is not a valid TextFontType variant",
|
||||
s
|
||||
|
||||
+22
-11
@@ -1,34 +1,45 @@
|
||||
use crate::{
|
||||
dpi::{LogicalSize, PhysicalSize},
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
};
|
||||
use mlua::{Lua, Result as LuaResult};
|
||||
|
||||
pub fn get_screen_size(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let size = if *socket.is_dpi_aware() {
|
||||
let PhysicalSize { width, height, .. } = socket.window().size;
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let size = if *ctx.is_dpi_aware() {
|
||||
let PhysicalSize { width, height, .. } = ctx.window().size;
|
||||
(width, height)
|
||||
} else {
|
||||
let LogicalSize { width, height, .. } = socket.window().logical_size();
|
||||
let LogicalSize { width, height, .. } = ctx.window().logical_size();
|
||||
(width, height)
|
||||
};
|
||||
Ok(size)
|
||||
}
|
||||
|
||||
pub fn get_screen_scale(l: &Lua, _: ()) -> LuaResult<f32> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
Ok(socket.window().scale_factor)
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let scale_factor = ctx.window().scale_factor;
|
||||
Ok(scale_factor)
|
||||
}
|
||||
|
||||
pub fn set_window_title(l: &Lua, title: String) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket.window().set_window_title(&title);
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.window().set_window_title(&title);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_foreground(l: &Lua, _: ()) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket.window().focus();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.window().focus();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_dpi_scale_override(_: &Lua, _percent: i32) -> LuaResult<()> {
|
||||
// TODO:
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_dpi_scale_override(_: &Lua, _: ()) -> LuaResult<i32> {
|
||||
// TODO:
|
||||
Ok(0)
|
||||
}
|
||||
+123
-49
@@ -1,6 +1,7 @@
|
||||
use crate::{
|
||||
args::Game,
|
||||
dpi::{ConvertToLogical, PhysicalPoint, PhysicalSize},
|
||||
fonts::Fonts,
|
||||
fonts::{FontData, FontDefinitions, Fonts},
|
||||
gfx::{GraphicsContext, RenderJob},
|
||||
input::InputState,
|
||||
installer::InstallMode,
|
||||
@@ -10,14 +11,10 @@ use crate::{
|
||||
window::WindowState,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use arboard::Clipboard;
|
||||
use std::sync::Arc;
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::*,
|
||||
event_loop::ActiveEventLoop,
|
||||
keyboard::{ModifiersState, PhysicalKey},
|
||||
window::Window,
|
||||
application::ApplicationHandler, event::*, event_loop::ActiveEventLoop, keyboard::PhysicalKey,
|
||||
platform::modifier_supplement::KeyEventExtModifierSupplement, window::Window,
|
||||
};
|
||||
|
||||
struct FrameOutput {
|
||||
@@ -29,7 +26,6 @@ pub struct AppState {
|
||||
pub input: InputState,
|
||||
pub fonts: Fonts,
|
||||
pub texture_manager: WrappedTextureManager,
|
||||
pub clipboard: Clipboard,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
@@ -54,9 +50,8 @@ impl App {
|
||||
state: AppState {
|
||||
window: WindowState::default(),
|
||||
input: InputState::default(),
|
||||
fonts: Fonts::new(),
|
||||
fonts: Fonts::new(pob_font_definitions()),
|
||||
texture_manager: WrappedTextureManager::new(),
|
||||
clipboard: arboard::Clipboard::new()?,
|
||||
},
|
||||
tessellator: Tessellator::default(),
|
||||
force_render: false,
|
||||
@@ -119,28 +114,47 @@ impl App {
|
||||
log::error!("{err}");
|
||||
}
|
||||
}
|
||||
|
||||
fn create_window(&mut self, event_loop: &ActiveEventLoop) -> anyhow::Result<()> {
|
||||
let (title, _app_id) = match Game::current() {
|
||||
Game::Poe1 => ("Path of Building 1", "rusty-path-of-building-1"),
|
||||
Game::Poe2 => ("Path of Building 2", "rusty-path-of-building-2"),
|
||||
};
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut window_attributes = Window::default_attributes()
|
||||
.with_title(title)
|
||||
.with_window_icon(load_icon());
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
use winit::platform::wayland::ActiveEventLoopExtWayland;
|
||||
use winit::platform::x11::ActiveEventLoopExtX11;
|
||||
|
||||
if event_loop.is_x11() {
|
||||
use winit::platform::x11::WindowAttributesExtX11;
|
||||
window_attributes = window_attributes.with_name(_app_id, _app_id);
|
||||
} else if event_loop.is_wayland() {
|
||||
use winit::platform::wayland::WindowAttributesExtWayland;
|
||||
window_attributes = window_attributes.with_name(_app_id, _app_id);
|
||||
}
|
||||
}
|
||||
|
||||
let window = event_loop.create_window(window_attributes)?;
|
||||
let window = Arc::new(window);
|
||||
self.state.window.set_window(Arc::clone(&window));
|
||||
self.gfx_context = Some(pollster::block_on(GraphicsContext::new(window))?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler<GraphicsContext> for App {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let window = match event_loop.create_window(Window::default_attributes()) {
|
||||
Ok(window) => Arc::new(window),
|
||||
Err(err) => {
|
||||
log::error!("{err}");
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.state.window.set_window(Arc::clone(&window));
|
||||
|
||||
self.gfx_context = match pollster::block_on(GraphicsContext::new(window)) {
|
||||
Ok(gfx) => Some(gfx),
|
||||
Err(err) => {
|
||||
log::error!("{err}");
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
if let Err(err) = self.create_window(event_loop) {
|
||||
log::error!("{err}");
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,16 +216,17 @@ impl ApplicationHandler<GraphicsContext> for App {
|
||||
}
|
||||
WindowEvent::KeyboardInput {
|
||||
event:
|
||||
KeyEvent {
|
||||
key_event @ KeyEvent {
|
||||
physical_key: PhysicalKey::Code(code),
|
||||
logical_key,
|
||||
state,
|
||||
..
|
||||
},
|
||||
..
|
||||
} => {
|
||||
// update input state
|
||||
self.state.input.set_key_pressed(code, state.is_pressed());
|
||||
|
||||
// forward KeyUp/KeyDown events
|
||||
let event = match state {
|
||||
ElementState::Pressed => AppEvent::KeyDown { code },
|
||||
ElementState::Released => AppEvent::KeyUp { code },
|
||||
@@ -219,25 +234,12 @@ impl ApplicationHandler<GraphicsContext> for App {
|
||||
self.handle_event(event);
|
||||
|
||||
// handle text input
|
||||
if state.is_pressed() {
|
||||
match logical_key {
|
||||
winit::keyboard::Key::Character(text) => {
|
||||
// only emit event if no modifier except Shift is pressed.
|
||||
let modifiers = self.state.input.key_modifiers;
|
||||
if modifiers.difference(ModifiersState::SHIFT).is_empty() {
|
||||
for ch in text.chars() {
|
||||
let event = AppEvent::CharacterInput { ch };
|
||||
self.handle_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
winit::keyboard::Key::Named(named) => {
|
||||
if named == winit::keyboard::NamedKey::Space {
|
||||
let event = AppEvent::CharacterInput { ch: ' ' };
|
||||
self.handle_event(event);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
if let Some(text) = key_event.text_with_all_modifiers()
|
||||
&& state.is_pressed()
|
||||
{
|
||||
for ch in text.chars() {
|
||||
let event = AppEvent::CharacterInput { ch };
|
||||
self.handle_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,3 +279,75 @@ impl ApplicationHandler<GraphicsContext> for App {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn pob_font_definitions() -> FontDefinitions {
|
||||
let mut definitions = FontDefinitions::default();
|
||||
|
||||
definitions.font_data.insert(
|
||||
"bitstream-vera-sans-mono".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/VeraMono.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"liberation-sans".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/LiberationSans-Regular.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"liberation-sans-bold".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/LiberationSans-Bold.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"fontin-regular".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/fontin-regular.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"fontin-italic".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/fontin-italic.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"fontin-smallcaps".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/fontin-smallcaps.ttf"
|
||||
))),
|
||||
);
|
||||
|
||||
definitions.generic_families.insert(
|
||||
parley::GenericFamily::Monospace,
|
||||
vec!["bitstream-vera-sans-mono".to_owned()],
|
||||
);
|
||||
|
||||
definitions.generic_families.insert(
|
||||
parley::GenericFamily::SansSerif,
|
||||
vec![
|
||||
"liberation-sans".to_owned(),
|
||||
"liberation-sans-bold".to_owned(),
|
||||
],
|
||||
);
|
||||
|
||||
definitions.generic_families.insert(
|
||||
parley::GenericFamily::Serif,
|
||||
vec![
|
||||
"fontin-regular".to_owned(),
|
||||
"fontin-italic".to_owned(),
|
||||
"fontin-smallcaps".to_owned(),
|
||||
],
|
||||
);
|
||||
|
||||
definitions
|
||||
}
|
||||
|
||||
fn load_icon() -> Option<winit::window::Icon> {
|
||||
let image_data = include_bytes!("../assets/icon.png");
|
||||
let image = image::load_from_memory(image_data).ok()?.into_rgba8();
|
||||
let (width, height) = image.dimensions();
|
||||
winit::window::Icon::from_rgba(image.into_raw(), width, height).ok()
|
||||
}
|
||||
+9
-1
@@ -31,11 +31,19 @@ impl Game {
|
||||
GAME_CONFIG.get().expect("Game should be initialized")
|
||||
}
|
||||
|
||||
pub fn script_dir() -> PathBuf {
|
||||
pub fn data_dir() -> PathBuf {
|
||||
let directory_name = match Self::current() {
|
||||
Game::Poe1 => "RustyPathOfBuilding1",
|
||||
Game::Poe2 => "RustyPathOfBuilding2",
|
||||
};
|
||||
BaseDirs::new().unwrap().data_dir().join(directory_name)
|
||||
}
|
||||
|
||||
pub fn script_dir() -> PathBuf {
|
||||
Game::data_dir()
|
||||
}
|
||||
|
||||
pub fn user_data_dir() -> PathBuf {
|
||||
Game::data_dir().join("userdata")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
use raw_window_handle::RawDisplayHandle;
|
||||
|
||||
/// Abstraction over clipboard crates
|
||||
///
|
||||
/// `smithay_clipboard`: Used on wayland
|
||||
/// `arboard`: All other platforms (check arboard docs for platform support)
|
||||
pub struct Clipboard {
|
||||
#[cfg(target_family = "unix")]
|
||||
smithay: Option<smithay_clipboard::Clipboard>,
|
||||
arboard: Option<arboard::Clipboard>,
|
||||
// fallback if everything else fails. only supports intra-application copy/paste
|
||||
fallback: Option<String>,
|
||||
}
|
||||
|
||||
impl Clipboard {
|
||||
pub fn new(_raw_display_handle: Option<RawDisplayHandle>) -> Self {
|
||||
Self {
|
||||
#[cfg(target_family = "unix")]
|
||||
smithay: create_smithay_clipboard(_raw_display_handle),
|
||||
arboard: create_arboard_clipboard(),
|
||||
fallback: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the text content of clipboard
|
||||
pub fn set_text(&mut self, text: String) {
|
||||
#[cfg(target_family = "unix")]
|
||||
if let Some(clipboard) = &mut self.smithay {
|
||||
clipboard.store(text);
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(clipboard) = &mut self.arboard {
|
||||
let _ = clipboard.set_text(text);
|
||||
return;
|
||||
}
|
||||
|
||||
self.fallback = Some(text);
|
||||
}
|
||||
|
||||
/// Gets the text content of clipboard
|
||||
pub fn get_text(&mut self) -> Option<String> {
|
||||
#[cfg(target_family = "unix")]
|
||||
if let Some(clipboard) = &mut self.smithay {
|
||||
return clipboard.load().ok();
|
||||
}
|
||||
|
||||
if let Some(clipboard) = &mut self.arboard {
|
||||
return clipboard.get_text().ok();
|
||||
}
|
||||
|
||||
if let Some(text) = &self.fallback {
|
||||
return Some(text.clone());
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
fn create_smithay_clipboard(
|
||||
raw_display_handle: Option<RawDisplayHandle>,
|
||||
) -> Option<smithay_clipboard::Clipboard> {
|
||||
if let Some(RawDisplayHandle::Wayland(handle)) = raw_display_handle {
|
||||
log::debug!("Creating smithay clipboard...");
|
||||
Some(unsafe { smithay_clipboard::Clipboard::new(handle.display.as_ptr()) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn create_arboard_clipboard() -> Option<arboard::Clipboard> {
|
||||
log::debug!("Creating arboard clipboard...");
|
||||
match arboard::Clipboard::new() {
|
||||
Ok(clipboard) => Some(clipboard),
|
||||
Err(err) => {
|
||||
log::warn!("Failed to create arboard clipboard: {err}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
-42
@@ -7,24 +7,24 @@ use crate::{
|
||||
renderer::image::ImageDelta,
|
||||
util::calculate_hash,
|
||||
};
|
||||
use ahash::HashMap;
|
||||
use ordered_float::OrderedFloat;
|
||||
use parley::{
|
||||
FontContext, FontWeight, GenericFamily, LayoutContext, StyleProperty, TextStyle, fontique::Blob,
|
||||
FontContext, FontFamily, FontStack, FontWeight, GenericFamily, LayoutContext, StyleProperty,
|
||||
TextStyle, fontique::Blob,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use atlas::FontAtlasSize;
|
||||
pub use layout::{Alignment, Layout, LayoutJob};
|
||||
pub use layout::{Alignment, FontStyle, Layout, LayoutJob};
|
||||
|
||||
mod atlas;
|
||||
mod glyph_key;
|
||||
mod layout;
|
||||
mod rasterizer;
|
||||
|
||||
pub const BITSTREAM_VERA_SANS_MONO: &[u8] = include_bytes!("../fonts/VeraMono.ttf");
|
||||
pub const LIBERATION_SANS: &[u8] = include_bytes!("../fonts/LiberationSans-Regular.ttf");
|
||||
pub const LIBERATION_SANS_BOLD: &[u8] = include_bytes!("../fonts/LiberationSans-Bold.ttf");
|
||||
|
||||
/// Data of a .ttf or .otf file
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FontData {
|
||||
data: std::borrow::Cow<'static, [u8]>,
|
||||
}
|
||||
@@ -43,13 +43,14 @@ impl AsRef<[u8]> for FontData {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FontDefinition {
|
||||
pub generic_families: Vec<GenericFamily>,
|
||||
pub data: Arc<FontData>,
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct FontDefinitions {
|
||||
pub font_data: HashMap<String, Arc<FontData>>,
|
||||
pub generic_families: HashMap<GenericFamily, Vec<String>>,
|
||||
}
|
||||
|
||||
pub struct Fonts {
|
||||
font_definitions: Vec<FontDefinition>,
|
||||
definitions: FontDefinitions,
|
||||
font_context: FontContext,
|
||||
layout_context: LayoutContext<Srgba>,
|
||||
atlas: FontAtlas,
|
||||
@@ -58,25 +59,9 @@ pub struct Fonts {
|
||||
}
|
||||
|
||||
impl Fonts {
|
||||
pub fn new() -> Self {
|
||||
// add fonts used by PoB
|
||||
let font_definitions = vec![
|
||||
FontDefinition {
|
||||
generic_families: vec![GenericFamily::Monospace],
|
||||
data: Arc::new(FontData::from_static(BITSTREAM_VERA_SANS_MONO)),
|
||||
},
|
||||
FontDefinition {
|
||||
generic_families: vec![GenericFamily::SansSerif],
|
||||
data: Arc::new(FontData::from_static(LIBERATION_SANS)),
|
||||
},
|
||||
FontDefinition {
|
||||
generic_families: vec![GenericFamily::SansSerif],
|
||||
data: Arc::new(FontData::from_static(LIBERATION_SANS_BOLD)),
|
||||
},
|
||||
];
|
||||
|
||||
pub fn new(definitions: FontDefinitions) -> Self {
|
||||
let mut fonts = Self {
|
||||
font_definitions,
|
||||
definitions,
|
||||
font_context: FontContext::new(),
|
||||
layout_context: LayoutContext::new(),
|
||||
atlas: FontAtlas::new(1024),
|
||||
@@ -92,14 +77,20 @@ impl Fonts {
|
||||
}
|
||||
|
||||
fn register_fonts(&mut self) {
|
||||
for definition in &self.font_definitions {
|
||||
let blob = Blob::new(Arc::new(definition.data.data.clone()));
|
||||
let registered_fonts = self.font_context.collection.register_fonts(blob, None);
|
||||
for generic_family in &definition.generic_families {
|
||||
self.font_context
|
||||
.collection
|
||||
.append_generic_families(*generic_family, registered_fonts.iter().map(|f| f.0));
|
||||
}
|
||||
for data in self.definitions.font_data.values() {
|
||||
let blob = Blob::new(Arc::new(data.data.clone()));
|
||||
self.font_context.collection.register_fonts(blob, None);
|
||||
}
|
||||
|
||||
for (generic_family, family_fonts) in &self.definitions.generic_families {
|
||||
let family_ids: Vec<_> = family_fonts
|
||||
.iter()
|
||||
.filter_map(|family_name| self.font_context.collection.family_id(family_name))
|
||||
.collect();
|
||||
|
||||
self.font_context
|
||||
.collection
|
||||
.set_generic_families(*generic_family, family_ids.into_iter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,13 +119,26 @@ impl Fonts {
|
||||
common_chars.push(c as char);
|
||||
}
|
||||
|
||||
self.preload_text(&common_chars, font_size, GenericFamily::Monospace, None);
|
||||
self.preload_text(&common_chars, font_size, GenericFamily::SansSerif, None);
|
||||
self.preload_text(
|
||||
&common_chars,
|
||||
font_size,
|
||||
GenericFamily::SansSerif,
|
||||
FontFamily::Generic(GenericFamily::Monospace),
|
||||
None,
|
||||
parley::FontStyle::Normal,
|
||||
);
|
||||
self.preload_text(
|
||||
&common_chars,
|
||||
font_size,
|
||||
FontFamily::Generic(GenericFamily::SansSerif),
|
||||
None,
|
||||
parley::FontStyle::Normal,
|
||||
);
|
||||
self.preload_text(
|
||||
&common_chars,
|
||||
font_size,
|
||||
FontFamily::Generic(GenericFamily::SansSerif),
|
||||
Some(FontWeight::BOLD),
|
||||
parley::FontStyle::Normal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -142,14 +146,16 @@ impl Fonts {
|
||||
&mut self,
|
||||
text: &str,
|
||||
font_size: f32,
|
||||
generic_family: GenericFamily,
|
||||
font_family: FontFamily,
|
||||
font_weight: Option<FontWeight>,
|
||||
font_style: parley::FontStyle,
|
||||
) {
|
||||
profiling::scope!("preload_text");
|
||||
|
||||
let style = TextStyle {
|
||||
font_stack: parley::FontStack::Single(parley::FontFamily::Generic(generic_family)),
|
||||
font_stack: FontStack::Single(font_family),
|
||||
font_weight: font_weight.unwrap_or(FontWeight::NORMAL),
|
||||
font_style,
|
||||
font_size,
|
||||
..Default::default()
|
||||
};
|
||||
@@ -194,13 +200,14 @@ impl Fonts {
|
||||
|
||||
let default_style = TextStyle::default();
|
||||
let style = TextStyle {
|
||||
font_stack: parley::FontStack::Single(parley::FontFamily::Generic(job.font_family)),
|
||||
font_stack: parley::FontStack::Single(job.font_family),
|
||||
font_size: job.font_size.into(),
|
||||
line_height: parley::LineHeight::Absolute(job.line_height.into()),
|
||||
font_weight: job
|
||||
.font_weight
|
||||
.map(|w| parley::FontWeight::new(w.into()))
|
||||
.unwrap_or(default_style.font_weight),
|
||||
font_style: job.font_style.into(),
|
||||
..default_style
|
||||
};
|
||||
|
||||
|
||||
+44
-5
@@ -1,37 +1,56 @@
|
||||
use crate::{color::Srgba, dpi::LogicalPoint, fonts::rasterizer::RasterizedGlyph};
|
||||
use ordered_float::OrderedFloat;
|
||||
use parley::GenericFamily;
|
||||
use parley::FontFamily;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash)]
|
||||
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)]
|
||||
pub enum Alignment {
|
||||
#[default]
|
||||
Min,
|
||||
Center,
|
||||
Max,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)]
|
||||
pub enum FontStyle {
|
||||
#[default]
|
||||
Normal,
|
||||
Italic,
|
||||
}
|
||||
|
||||
impl From<FontStyle> for parley::FontStyle {
|
||||
fn from(value: FontStyle) -> Self {
|
||||
match value {
|
||||
FontStyle::Normal => parley::FontStyle::Normal,
|
||||
FontStyle::Italic => parley::FontStyle::Italic,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
pub struct LayoutSegment<'s> {
|
||||
pub text: &'s str,
|
||||
pub color: Srgba,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LayoutJob<'s> {
|
||||
pub segments: Vec<LayoutSegment<'s>>,
|
||||
pub font_family: GenericFamily,
|
||||
pub font_family: FontFamily<'static>,
|
||||
pub font_size: OrderedFloat<f32>,
|
||||
pub line_height: OrderedFloat<f32>,
|
||||
pub alignment: Option<Alignment>,
|
||||
pub font_weight: Option<OrderedFloat<f32>>,
|
||||
pub font_style: FontStyle,
|
||||
}
|
||||
|
||||
impl<'s> LayoutJob<'s> {
|
||||
pub fn new(
|
||||
font_family: GenericFamily,
|
||||
font_family: FontFamily<'static>,
|
||||
font_size: f32,
|
||||
line_height: f32,
|
||||
alignment: Option<Alignment>,
|
||||
font_weight: Option<f32>,
|
||||
font_style: FontStyle,
|
||||
) -> Self {
|
||||
Self {
|
||||
segments: Vec::new(),
|
||||
@@ -40,6 +59,7 @@ impl<'s> LayoutJob<'s> {
|
||||
line_height: line_height.into(),
|
||||
alignment,
|
||||
font_weight: font_weight.map(OrderedFloat),
|
||||
font_style,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +68,25 @@ impl<'s> LayoutJob<'s> {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::hash::Hash for LayoutJob<'_> {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.segments.hash(state);
|
||||
match &self.font_family {
|
||||
FontFamily::Named(cow) => {
|
||||
cow.hash(state);
|
||||
}
|
||||
FontFamily::Generic(generic_family) => {
|
||||
generic_family.hash(state);
|
||||
}
|
||||
}
|
||||
self.font_size.hash(state);
|
||||
self.line_height.hash(state);
|
||||
self.alignment.hash(state);
|
||||
self.font_weight.hash(state);
|
||||
self.font_style.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LayoutRow {
|
||||
pub glyphs: Vec<RasterizedGlyph>,
|
||||
|
||||
+23
-4
@@ -14,6 +14,7 @@ use image::GenericImage;
|
||||
use ordered_float::OrderedFloat;
|
||||
use parley::{FontData, GlyphRun};
|
||||
use std::borrow::Cow;
|
||||
use swash::zeno;
|
||||
|
||||
type FontBlobId = u64;
|
||||
type FontIndex = u32;
|
||||
@@ -25,14 +26,21 @@ struct StyleKey<'a> {
|
||||
font_blob_id: FontBlobId,
|
||||
font_size: OrderedFloat<f32>,
|
||||
normalized_coords: Cow<'a, [i16]>,
|
||||
skew: i8,
|
||||
}
|
||||
|
||||
impl<'a> StyleKey<'a> {
|
||||
fn new(font_blob_id: FontBlobId, font_size: f32, normalized_coords: &'a [i16]) -> Self {
|
||||
fn new(
|
||||
font_blob_id: FontBlobId,
|
||||
font_size: f32,
|
||||
normalized_coords: &'a [i16],
|
||||
skew: i8,
|
||||
) -> Self {
|
||||
Self {
|
||||
font_blob_id,
|
||||
font_size: font_size.into(),
|
||||
normalized_coords: Cow::Borrowed(normalized_coords),
|
||||
skew,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,8 +143,9 @@ impl GlyphRasterizer {
|
||||
font_data: &FontData,
|
||||
font_size: f32,
|
||||
norm_coords: &[i16],
|
||||
skew: i8,
|
||||
) -> StyleId {
|
||||
let style_key = StyleKey::new(font_data.data.id(), font_size, norm_coords);
|
||||
let style_key = StyleKey::new(font_data.data.id(), font_size, norm_coords, skew);
|
||||
match self.style_ids.get(&style_key) {
|
||||
Some(key) => *key,
|
||||
None => *self
|
||||
@@ -164,9 +173,16 @@ impl GlyphRasterizer {
|
||||
let color = glyph_run.style().brush;
|
||||
let font_size = run.font_size() * pixels_per_point;
|
||||
let normalized_coords = run.normalized_coords();
|
||||
let skew = run.synthesis().skew(); // skew angle for faux italic
|
||||
|
||||
let font_ref = self.get_font_ref(run.font());
|
||||
let style_id = self.get_style_id(run.font(), font_size, normalized_coords);
|
||||
let style_id = self.get_style_id(
|
||||
run.font(),
|
||||
font_size,
|
||||
normalized_coords,
|
||||
// parley stores skew as i8 internally so this conversion is ok
|
||||
skew.unwrap_or_default() as i8,
|
||||
);
|
||||
|
||||
let mut scaler = self
|
||||
.scale_context
|
||||
@@ -198,7 +214,10 @@ impl GlyphRasterizer {
|
||||
swash::scale::Source::ColorBitmap(swash::scale::StrikeWith::BestFit),
|
||||
swash::scale::Source::Outline,
|
||||
])
|
||||
.format(swash::zeno::Format::Alpha)
|
||||
.format(zeno::Format::Alpha)
|
||||
.transform(skew.map(|skew| {
|
||||
zeno::Transform::skew(zeno::Angle::from_degrees(skew), zeno::Angle::ZERO)
|
||||
}))
|
||||
.offset(fract_offset)
|
||||
.render_into(&mut scaler, glyph.id as u16, image);
|
||||
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ impl GraphicsContext {
|
||||
let surface_format = surface_caps
|
||||
.formats
|
||||
.iter()
|
||||
.find(|f| !f.is_srgb())
|
||||
.find(|f| !f.is_srgb() && f.required_features().is_empty())
|
||||
.copied()
|
||||
.unwrap_or(surface_caps.formats[0]);
|
||||
|
||||
|
||||
+110
-4
@@ -3,13 +3,15 @@ use crate::{
|
||||
args::Game,
|
||||
color::Srgba,
|
||||
dpi::{LogicalPoint, LogicalRect},
|
||||
fonts::{Alignment, LayoutJob},
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
mode::{AppEvent, ModeFrameOutput, ModeTransition},
|
||||
renderer::primitives::{ClippedPrimitive, DrawPrimitive, TextPrimitive},
|
||||
};
|
||||
use anyhow::bail;
|
||||
use flate2::read::GzDecoder;
|
||||
use parley::{FontFamily, GenericFamily};
|
||||
use regex::Regex;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use std::{
|
||||
fs::{self},
|
||||
io::copy,
|
||||
@@ -17,6 +19,7 @@ use std::{
|
||||
sync::mpsc::{self, Receiver, TryRecvError},
|
||||
thread,
|
||||
};
|
||||
use ureq::http::Response;
|
||||
|
||||
const REPO_NAME: &str = "meehl/rusty-pob-manifest";
|
||||
|
||||
@@ -112,11 +115,12 @@ impl InstallMode {
|
||||
app_state: &mut AppState,
|
||||
) -> Box<dyn Iterator<Item = ClippedPrimitive>> {
|
||||
let mut job = LayoutJob::new(
|
||||
parley::GenericFamily::SansSerif,
|
||||
FontFamily::Generic(GenericFamily::SansSerif),
|
||||
32.0,
|
||||
34.0,
|
||||
Some(Alignment::Center),
|
||||
Some(700.0),
|
||||
FontStyle::Normal,
|
||||
);
|
||||
|
||||
let progress_text = match &self.current_progress {
|
||||
@@ -195,7 +199,7 @@ fn download_path_of_building<P: AsRef<Path>>(
|
||||
repo
|
||||
);
|
||||
|
||||
let mut response = ureq::get(url).call()?;
|
||||
let mut response = http_get_with_backoff(&url)?;
|
||||
let total_size = response
|
||||
.headers()
|
||||
.get("Content-Length")
|
||||
@@ -299,7 +303,7 @@ fn set_branch_and_platform<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()>
|
||||
}
|
||||
|
||||
fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()> {
|
||||
let mut response = ureq::get(url).call()?;
|
||||
let mut response = http_get_with_backoff(url)?;
|
||||
|
||||
if response.status().is_success() {
|
||||
let body = response.body_mut();
|
||||
@@ -326,3 +330,105 @@ fn format_bytes(size_in_bytes: u64) -> String {
|
||||
format!("{} bytes", size_in_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates wait time based on rate limit headers or falls back to default backoff.
|
||||
fn calculate_wait_time(resp: &Response<ureq::Body>, default_backoff: u64) -> u64 {
|
||||
let headers = resp.headers();
|
||||
|
||||
// Wait for time specified in retry-after response header if present
|
||||
if let Some(retry_after) = headers
|
||||
.get("retry-after")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.and_then(|s| s.parse::<u64>().ok())
|
||||
{
|
||||
return retry_after;
|
||||
}
|
||||
|
||||
// The number of requests remaining in the current rate limit window
|
||||
let remaining = headers
|
||||
.get("x-ratelimit-remaining")
|
||||
.and_then(|v| v.to_str().ok());
|
||||
|
||||
if remaining == Some("0") {
|
||||
// Calculate time until rate limit reset
|
||||
if let Some(reset_epoch) = headers
|
||||
.get("x-ratelimit-reset")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.and_then(|s| s.parse::<u64>().ok())
|
||||
{
|
||||
let now_epoch = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
|
||||
if reset_epoch > now_epoch {
|
||||
return reset_epoch - now_epoch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default_backoff
|
||||
}
|
||||
|
||||
/// Performs a GET request with exponential backoff aware of GitHub rate limit headers.
|
||||
fn http_get_with_backoff(url: &str) -> anyhow::Result<Response<ureq::Body>> {
|
||||
const MAX_ATTEMPTS: usize = 6;
|
||||
const MAX_BACKOFF_SECS: u64 = 60;
|
||||
let mut attempt = 0;
|
||||
let mut backoff_secs: u64 = 2;
|
||||
|
||||
loop {
|
||||
attempt += 1;
|
||||
let resp_result = ureq::get(url)
|
||||
.header("User-Agent", "rusty-path-of-building")
|
||||
.call();
|
||||
|
||||
let resp = match resp_result {
|
||||
Ok(r) => r,
|
||||
Err(err) => {
|
||||
log::warn!(
|
||||
"Transport error: {} (attempt {}/{})",
|
||||
err,
|
||||
attempt,
|
||||
MAX_ATTEMPTS
|
||||
);
|
||||
if attempt >= MAX_ATTEMPTS {
|
||||
return Err(anyhow::Error::new(err));
|
||||
}
|
||||
thread::sleep(Duration::from_secs(backoff_secs));
|
||||
backoff_secs = (backoff_secs * 2).min(MAX_BACKOFF_SECS);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let status = resp.status();
|
||||
if status == 403 || status == 429 {
|
||||
let wait = calculate_wait_time(&resp, backoff_secs);
|
||||
|
||||
log::warn!(
|
||||
"Rate limited (status {}). Waiting {}s before retry (attempt {}/{})",
|
||||
status,
|
||||
wait,
|
||||
attempt,
|
||||
MAX_ATTEMPTS
|
||||
);
|
||||
if attempt >= MAX_ATTEMPTS {
|
||||
return Err(anyhow::anyhow!(
|
||||
"HTTP {} after {} attempts for {}",
|
||||
status,
|
||||
attempt,
|
||||
url
|
||||
));
|
||||
}
|
||||
thread::sleep(Duration::from_secs(wait));
|
||||
backoff_secs = (backoff_secs * 2).min(MAX_BACKOFF_SECS);
|
||||
continue;
|
||||
}
|
||||
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
return Err(anyhow::anyhow!("http status: {} for {}", status, url));
|
||||
}
|
||||
|
||||
return Ok(resp);
|
||||
}
|
||||
}
|
||||
+30
-36
@@ -12,7 +12,6 @@ use crate::{
|
||||
util::change_working_directory,
|
||||
window::WindowState,
|
||||
};
|
||||
use arboard::Clipboard;
|
||||
use clap::Parser;
|
||||
use mlua::{Lua, Result as LuaResult, Table};
|
||||
use std::{
|
||||
@@ -21,7 +20,7 @@ use std::{
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
macro_rules! socket_accessor {
|
||||
macro_rules! ctx_accessor {
|
||||
($field:ident: & $ty:ty) => {
|
||||
pub fn $field(&self) -> &$ty {
|
||||
let ptr = self.$field.get();
|
||||
@@ -42,28 +41,26 @@ macro_rules! socket_accessor {
|
||||
|
||||
/// A collection of pointers needed by the API funtions.
|
||||
///
|
||||
/// Before executing any lua code, we need to "plug" the [`PoBContext`] into
|
||||
/// the ContextSocket and "unplug" them afterwards.
|
||||
pub struct ContextSocket {
|
||||
window: Cell<*const WindowState>,
|
||||
/// Before executing any lua code, we need to "plug" the references into
|
||||
/// the Context and "unplug" them afterwards.
|
||||
pub struct Context {
|
||||
window: Cell<*mut WindowState>,
|
||||
input: Cell<*const InputState>,
|
||||
fonts: Cell<*mut Fonts>,
|
||||
texture_manager: Cell<*mut WrappedTextureManager>,
|
||||
clipboard: Cell<*mut Clipboard>,
|
||||
current_working_dir: Cell<*mut PathBuf>,
|
||||
layers: Cell<*mut Layers>,
|
||||
needs_restart: Cell<*mut bool>,
|
||||
is_dpi_aware: Cell<*mut bool>,
|
||||
}
|
||||
|
||||
impl ContextSocket {
|
||||
impl Context {
|
||||
pub fn new() -> &'static Self {
|
||||
Box::leak(Box::new(Self {
|
||||
window: Cell::new(std::ptr::null()),
|
||||
window: Cell::new(std::ptr::null_mut()),
|
||||
input: Cell::new(std::ptr::null()),
|
||||
fonts: Cell::new(std::ptr::null_mut()),
|
||||
texture_manager: Cell::new(std::ptr::null_mut()),
|
||||
clipboard: Cell::new(std::ptr::null_mut()),
|
||||
current_working_dir: Cell::new(std::ptr::null_mut()),
|
||||
layers: Cell::new(std::ptr::null_mut()),
|
||||
needs_restart: Cell::new(std::ptr::null_mut()),
|
||||
@@ -72,11 +69,10 @@ impl ContextSocket {
|
||||
}
|
||||
|
||||
pub fn set(&self, ctx: &mut PoBContext) {
|
||||
self.window.set(&ctx.app.window);
|
||||
self.window.set(&mut ctx.app.window);
|
||||
self.input.set(&ctx.app.input);
|
||||
self.fonts.set(&mut ctx.app.fonts);
|
||||
self.texture_manager.set(&mut ctx.app.texture_manager);
|
||||
self.clipboard.set(&mut ctx.app.clipboard);
|
||||
self.current_working_dir
|
||||
.set(&mut ctx.pob.current_working_dir);
|
||||
self.layers.set(&mut ctx.pob.layers);
|
||||
@@ -85,26 +81,24 @@ impl ContextSocket {
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
self.window.set(std::ptr::null());
|
||||
self.window.set(std::ptr::null_mut());
|
||||
self.input.set(std::ptr::null());
|
||||
self.fonts.set(std::ptr::null_mut());
|
||||
self.texture_manager.set(std::ptr::null_mut());
|
||||
self.clipboard.set(std::ptr::null_mut());
|
||||
self.current_working_dir.set(std::ptr::null_mut());
|
||||
self.layers.set(std::ptr::null_mut());
|
||||
self.needs_restart.set(std::ptr::null_mut());
|
||||
self.is_dpi_aware.set(std::ptr::null_mut());
|
||||
}
|
||||
|
||||
socket_accessor!(window: &WindowState);
|
||||
socket_accessor!(input: &InputState);
|
||||
socket_accessor!(fonts: &mut Fonts);
|
||||
socket_accessor!(texture_manager: &mut WrappedTextureManager);
|
||||
socket_accessor!(clipboard: &mut Clipboard);
|
||||
socket_accessor!(current_working_dir: &mut PathBuf);
|
||||
socket_accessor!(layers: &mut Layers);
|
||||
socket_accessor!(needs_restart: &mut bool);
|
||||
socket_accessor!(is_dpi_aware: &mut bool);
|
||||
ctx_accessor!(window: &mut WindowState);
|
||||
ctx_accessor!(input: &InputState);
|
||||
ctx_accessor!(fonts: &mut Fonts);
|
||||
ctx_accessor!(texture_manager: &mut WrappedTextureManager);
|
||||
ctx_accessor!(current_working_dir: &mut PathBuf);
|
||||
ctx_accessor!(layers: &mut Layers);
|
||||
ctx_accessor!(needs_restart: &mut bool);
|
||||
ctx_accessor!(is_dpi_aware: &mut bool);
|
||||
}
|
||||
|
||||
pub enum PoBEvent {
|
||||
@@ -183,9 +177,9 @@ impl LuaInstance {
|
||||
|
||||
Self::register_package_paths(&lua)?;
|
||||
|
||||
// register "socket"
|
||||
let socket = ContextSocket::new();
|
||||
lua.set_app_data(socket);
|
||||
// register context
|
||||
let ctx = Context::new();
|
||||
lua.set_app_data(ctx);
|
||||
|
||||
// register callbacks
|
||||
api::register_globals(&lua)?;
|
||||
@@ -194,15 +188,15 @@ impl LuaInstance {
|
||||
}
|
||||
|
||||
/// Loads and executes PoB's Launch.lua script
|
||||
pub fn launch(&self, ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
let socket = self.lua.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket.set(ctx);
|
||||
pub fn launch(&self, pob_ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
let ctx = self.lua.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.set(pob_ctx);
|
||||
|
||||
let script_dir = Game::script_dir();
|
||||
change_working_directory(script_dir.as_path())?;
|
||||
self.load(script_dir.join("Launch.lua")).exec()?;
|
||||
|
||||
socket.clear();
|
||||
ctx.clear();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -234,12 +228,12 @@ impl LuaInstance {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_event(&self, event: PoBEvent, ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
pub fn handle_event(&self, event: PoBEvent, pob_ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
profiling::scope!("handle_event", format!("{}", event));
|
||||
|
||||
// "Plug" references into "socket"
|
||||
let socket = self.lua.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket.set(ctx);
|
||||
// "Plug" references into context
|
||||
let ctx = self.lua.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.set(pob_ctx);
|
||||
|
||||
// Call event handler in PoB application code
|
||||
let handler_result = match event {
|
||||
@@ -259,8 +253,8 @@ impl LuaInstance {
|
||||
}
|
||||
};
|
||||
|
||||
// "Unplug" references from "socket"
|
||||
socket.clear();
|
||||
// "Unplug" references from context
|
||||
ctx.clear();
|
||||
|
||||
handler_result
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use winit::event_loop::EventLoop;
|
||||
mod api;
|
||||
mod app;
|
||||
mod args;
|
||||
mod clipboard;
|
||||
mod color;
|
||||
mod dpi;
|
||||
mod fonts;
|
||||
|
||||
@@ -121,14 +121,19 @@ impl PoBMode {
|
||||
}
|
||||
AppEvent::MouseWheel { delta } => {
|
||||
if delta > 0.0 {
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::KeyDown("WHEELUP", false), &mut ctx)?;
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::KeyUp("WHEELUP"), &mut ctx)?;
|
||||
} else if delta < 0.0 {
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::KeyDown("WHEELDOWN", false), &mut ctx)?;
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::KeyUp("WHEELDOWN"), &mut ctx)?;
|
||||
}
|
||||
}
|
||||
AppEvent::CharacterInput { ch } => {
|
||||
let ch = if ch.is_ascii() { ch } else { '?' };
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::Char(ch), &mut ctx)?;
|
||||
}
|
||||
|
||||
+28
-3
@@ -1,10 +1,14 @@
|
||||
use crate::{
|
||||
clipboard::Clipboard,
|
||||
dpi::{ConvertToLogical, LogicalSize, PhysicalSize},
|
||||
};
|
||||
use raw_window_handle::HasDisplayHandle;
|
||||
use std::sync::Arc;
|
||||
|
||||
use winit::window::Window;
|
||||
|
||||
use crate::dpi::{ConvertToLogical, LogicalSize, PhysicalSize};
|
||||
|
||||
pub struct WindowState {
|
||||
// NOTE: clipboard needs to be destroyed before window
|
||||
clipboard: Option<Clipboard>,
|
||||
pub window: Option<Arc<Window>>,
|
||||
pub size: PhysicalSize<u32>,
|
||||
pub scale_factor: f32,
|
||||
@@ -18,6 +22,7 @@ impl Default for WindowState {
|
||||
size: Default::default(),
|
||||
scale_factor: 1.0,
|
||||
pending_window_title: std::cell::Cell::new(None),
|
||||
clipboard: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +33,12 @@ impl WindowState {
|
||||
window.set_title(&title);
|
||||
}
|
||||
|
||||
let winit::dpi::PhysicalSize { width, height } = window.inner_size();
|
||||
self.size = PhysicalSize::new(width, height);
|
||||
self.scale_factor = window.scale_factor() as f32;
|
||||
|
||||
let raw_display_handle = window.display_handle().ok().map(|h| h.as_raw());
|
||||
self.clipboard = Some(Clipboard::new(raw_display_handle));
|
||||
self.window = Some(window);
|
||||
}
|
||||
|
||||
@@ -48,4 +59,18 @@ impl WindowState {
|
||||
window.focus_window();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_clipboard_text(&mut self, text: String) {
|
||||
if let Some(clipboard) = &mut self.clipboard {
|
||||
clipboard.set_text(text);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_clipboard_text(&mut self) -> Option<String> {
|
||||
if let Some(clipboard) = &mut self.clipboard {
|
||||
clipboard.get_text()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user