Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67cc995f78 | ||
|
|
534788f027 | ||
|
|
a57e0afda0 | ||
|
|
91ddf5696a | ||
|
|
08260cabd2 | ||
|
|
4316366f87 | ||
|
|
01697e32bd | ||
|
|
3e065a8838 | ||
|
|
1aa0aa128f |
No files matched your search
+8
-49
@@ -8,57 +8,16 @@
|
|||||||
|
|
||||||
## Contributing code
|
## Contributing code
|
||||||
|
|
||||||
- Get familiar with the code base before you start. I'll try to add more documentation providing a high-level overview of the architecture in the future. Until then, feel free to reach out through [Discussions](https://github.com/meehl/rusty-path-of-building/discussions) if you have any questions.
|
- Get familiar with the code base before you start. Feel free to reach out through [Discussions](https://github.com/meehl/rusty-path-of-building/discussions) if you have any questions.
|
||||||
- If you intend to work on the API functions, also check out the [SimpleGraphic](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) code base. A great place to ask questions about it is the PoB dev discord server. [Here](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) is more info on how to join.
|
- Make sure the [API](https://github.com/meehl/rusty-path-of-building/blob/main/src/pob/api.rs) functions stay compatible with [SimpleGraphic](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) (SG). A great place to ask questions about SG is the PoB dev discord server. [Here](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) is more info on how to join.
|
||||||
- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
|
- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
|
||||||
|
|
||||||
## macOS Development Setup
|
## Code Ownership and AI-Assisted Contributions
|
||||||
|
|
||||||
### 1. Install Lua runtime dependencies
|
Contributors are responsible for every line of code they submit, regardless of how it was written. Make sure to:
|
||||||
|
|
||||||
The application requires several Lua C libraries at runtime. Install them using LuaRocks with the LuaJIT backend:
|
- **Understand your code** - You must be able to explain how your contribution works and why it is implemented the way it is.
|
||||||
|
- **Review before submitting** - Carefully review all AI-generated code for correctness, security, maintainability, and consistency with the project's conventions.
|
||||||
|
- **Maintain quality** - AI assistance is not an excuse for untested code, unnecessary complexity, duplicated logic, or careless implementations.
|
||||||
|
|
||||||
```bash
|
If you cannot confidently explain and verify a piece of code, don't submit it.
|
||||||
brew install luajit luarocks
|
|
||||||
|
|
||||||
luarocks --lua-version 5.1 install luasocket
|
|
||||||
luarocks --lua-version 5.1 install luautf8
|
|
||||||
luarocks --lua-version 5.1 install lua-curl
|
|
||||||
```
|
|
||||||
|
|
||||||
Build and install `lzip` from the bundled source (requires zlib, which is pre-installed on macOS):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd lua/libs/lzip && make LUA_IMPL=luajit install
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Configure LUA_CPATH
|
|
||||||
|
|
||||||
Add the following to your shell profile (`~/.zshrc` or `~/.bash_profile`) so the runtime can locate the installed libraries:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
eval $(luarocks --lua-version 5.1 path)
|
|
||||||
```
|
|
||||||
|
|
||||||
Then reload your shell or run `source ~/.bash_profile`.
|
|
||||||
|
|
||||||
### 3. Startup
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cargo run <poe1|poe2>
|
|
||||||
```
|
|
||||||
|
|
||||||
Path of Building files are automatically downloaded to the following directories on first startup:
|
|
||||||
|
|
||||||
- poe1: `~/Library/Application Support/RustyPathOfBuilding1`
|
|
||||||
- poe2: `~/Library/Application Support/RustyPathOfBuilding2`
|
|
||||||
|
|
||||||
### Troubleshooting
|
|
||||||
|
|
||||||
**Build fails with `library 'luajit-5.1' not found`**
|
|
||||||
|
|
||||||
This usually means the build cache points to an old LuaJIT version after a Homebrew upgrade. Run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cargo clean && cargo run <poe1|poe2>
|
|
||||||
```
|
|
||||||
+16
-1
@@ -2,6 +2,19 @@
|
|||||||
|
|
||||||
## [Unreleased] - ReleaseDate
|
## [Unreleased] - ReleaseDate
|
||||||
|
|
||||||
|
## [0.3.5] - 2026-11-20
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix a crash when filtering nodes in the Timeless Jewel Finder
|
||||||
|
|
||||||
|
## [0.3.4] - 2026-11-13
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix blurry text inside viewports with fractional scale factors
|
||||||
|
- Fix crash on macOS
|
||||||
|
|
||||||
## [0.3.3] - 2026-10-23
|
## [0.3.3] - 2026-10-23
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
@@ -252,8 +265,10 @@
|
|||||||
- First release
|
- First release
|
||||||
|
|
||||||
<!-- next-url -->
|
<!-- next-url -->
|
||||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.3...HEAD
|
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.5...HEAD
|
||||||
|
|
||||||
|
[0.3.5]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.4...v0.3.5
|
||||||
|
[0.3.4]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.3...v0.3.4
|
||||||
[0.3.3]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.2...v0.3.3
|
[0.3.3]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.2...v0.3.3
|
||||||
[0.3.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.1...v0.3.2
|
[0.3.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.1...v0.3.2
|
||||||
[0.3.1]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.0...v0.3.1
|
[0.3.1]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.0...v0.3.1
|
||||||
|
|||||||
Generated
+1
-1
@@ -3502,7 +3502,7 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rusty-path-of-building"
|
name = "rusty-path-of-building"
|
||||||
version = "0.3.3"
|
version = "0.3.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ authors = ["meehl"]
|
|||||||
description = "Cross-platform runtime for Path of Building"
|
description = "Cross-platform runtime for Path of Building"
|
||||||
repository = "https://github.com/meehl/rusty-path-of-building"
|
repository = "https://github.com/meehl/rusty-path-of-building"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
version = "0.3.3"
|
version = "0.3.5"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|||||||
+27
-10
@@ -4,7 +4,8 @@ use ahash::AHasher;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
color::Srgba,
|
color::Srgba,
|
||||||
dpi::{LogicalQuad, LogicalRect, LogicalSize},
|
dpi::{LogicalPoint, LogicalQuad, LogicalRect, LogicalSize, ScaleFactor},
|
||||||
|
fonts::{Layout, LayoutToLogical},
|
||||||
math::Size,
|
math::Size,
|
||||||
renderer::textures::TextureId,
|
renderer::textures::TextureId,
|
||||||
uv::{UvConstructors, UvQuad, UvRect},
|
uv::{UvConstructors, UvQuad, UvRect},
|
||||||
@@ -143,20 +144,36 @@ impl DrawCommandRecorder {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_glyph(
|
/// Records a laid-out string whose top-left corner is at `layout_origin`.
|
||||||
|
pub fn draw_glyphs(
|
||||||
&mut self,
|
&mut self,
|
||||||
rect: LogicalRect<f32>,
|
layout: &Layout,
|
||||||
|
layout_origin: LogicalPoint<f32>,
|
||||||
|
is_absolute_position: bool,
|
||||||
|
scale_factor: ScaleFactor<f32>,
|
||||||
|
) {
|
||||||
|
// resolve the layout origin to screen space
|
||||||
|
let origin = if is_absolute_position {
|
||||||
|
layout_origin
|
||||||
|
} else {
|
||||||
|
layout_origin + self.current_viewport.min.to_vector()
|
||||||
|
};
|
||||||
|
// align the layout origin with the physical pixel grid to reduce blurriness
|
||||||
|
let origin = (origin * scale_factor).round() / scale_factor;
|
||||||
|
|
||||||
|
for glyph in &layout.glyphs {
|
||||||
|
let rect = LayoutToLogical::new(origin.x, origin.y).transform_box(&glyph.rect);
|
||||||
|
self.draw_glyph(rect, glyph.uv, glyph.color, glyph.layer_idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_glyph(
|
||||||
|
&mut self,
|
||||||
|
positions: LogicalRect<f32>,
|
||||||
uv: UvRect,
|
uv: UvRect,
|
||||||
color: Srgba,
|
color: Srgba,
|
||||||
layer_idx: u32,
|
layer_idx: u32,
|
||||||
is_absolute_position: bool,
|
|
||||||
) {
|
) {
|
||||||
let positions = if is_absolute_position {
|
|
||||||
rect
|
|
||||||
} else {
|
|
||||||
rect.translate(self.current_viewport.min.to_vector())
|
|
||||||
};
|
|
||||||
|
|
||||||
// cull if outside of viewport
|
// cull if outside of viewport
|
||||||
if !positions.intersects(&self.current_viewport) {
|
if !positions.intersects(&self.current_viewport) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+15
-4
@@ -174,7 +174,16 @@ impl GraphicsContext {
|
|||||||
pub fn render(&mut self, render_job: Option<RenderJob>) -> anyhow::Result<()> {
|
pub fn render(&mut self, render_job: Option<RenderJob>) -> anyhow::Result<()> {
|
||||||
profiling::scope!("render");
|
profiling::scope!("render");
|
||||||
|
|
||||||
|
// apply textures delta
|
||||||
|
if let Some(render_job) = &render_job {
|
||||||
|
self.renderer
|
||||||
|
.update_textures(&self.device, &self.queue, &render_job.textures_delta);
|
||||||
|
}
|
||||||
|
|
||||||
if !self.is_surface_configured {
|
if !self.is_surface_configured {
|
||||||
|
if let Some(render_job) = &render_job {
|
||||||
|
self.renderer.free_textures(&render_job.textures_delta);
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,10 +194,16 @@ impl GraphicsContext {
|
|||||||
| wgpu::CurrentSurfaceTexture::Occluded
|
| wgpu::CurrentSurfaceTexture::Occluded
|
||||||
| wgpu::CurrentSurfaceTexture::Validation => {
|
| wgpu::CurrentSurfaceTexture::Validation => {
|
||||||
// Skip frame
|
// Skip frame
|
||||||
|
if let Some(render_job) = &render_job {
|
||||||
|
self.renderer.free_textures(&render_job.textures_delta);
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => {
|
wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => {
|
||||||
self.surface.configure(&self.device, &self.config);
|
self.surface.configure(&self.device, &self.config);
|
||||||
|
if let Some(render_job) = &render_job {
|
||||||
|
self.renderer.free_textures(&render_job.textures_delta);
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -208,10 +223,6 @@ impl GraphicsContext {
|
|||||||
if let Some(render_job) = render_job {
|
if let Some(render_job) = render_job {
|
||||||
let screen_size = PhysicalSize::new(self.config.width, self.config.height);
|
let screen_size = PhysicalSize::new(self.config.width, self.config.height);
|
||||||
|
|
||||||
// upload new textures
|
|
||||||
self.renderer
|
|
||||||
.update_textures(&self.device, &self.queue, &render_job.textures_delta);
|
|
||||||
|
|
||||||
// upload vertex, index, and uniform buffers
|
// upload vertex, index, and uniform buffers
|
||||||
self.renderer.update_buffers(
|
self.renderer.update_buffers(
|
||||||
&self.device,
|
&self.device,
|
||||||
|
|||||||
+46
-46
@@ -41,24 +41,24 @@ pub unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_
|
|||||||
match nargs {
|
match nargs {
|
||||||
// escape_code
|
// escape_code
|
||||||
1 => {
|
1 => {
|
||||||
let esc_str = str_from_stack!(state, -nargs);
|
let esc_str = str_from_stack!(state, 1);
|
||||||
let color = Srgba::from_escape_code(esc_str);
|
let color = Srgba::from_escape_code(esc_str);
|
||||||
ctx.recorder.set_draw_color(color);
|
ctx.recorder.set_draw_color(color);
|
||||||
}
|
}
|
||||||
// rgb
|
// rgb
|
||||||
3 => {
|
3 => {
|
||||||
let r = f32_from_stack!(state, -nargs);
|
let r = f32_from_stack!(state, 1);
|
||||||
let g = f32_from_stack!(state, -nargs + 1);
|
let g = f32_from_stack!(state, 2);
|
||||||
let b = f32_from_stack!(state, -nargs + 2);
|
let b = f32_from_stack!(state, 3);
|
||||||
let color = Srgba::new_f32(r, g, b, 1.0);
|
let color = Srgba::new_f32(r, g, b, 1.0);
|
||||||
ctx.recorder.set_draw_color(color);
|
ctx.recorder.set_draw_color(color);
|
||||||
}
|
}
|
||||||
// rgba
|
// rgba
|
||||||
4 => {
|
4 => {
|
||||||
let r = f32_from_stack!(state, -nargs);
|
let r = f32_from_stack!(state, 1);
|
||||||
let g = f32_from_stack!(state, -nargs + 1);
|
let g = f32_from_stack!(state, 2);
|
||||||
let b = f32_from_stack!(state, -nargs + 2);
|
let b = f32_from_stack!(state, 3);
|
||||||
let a = f32_from_stack!(state, -nargs + 3);
|
let a = f32_from_stack!(state, 4);
|
||||||
let color = Srgba::new_f32(r, g, b, a);
|
let color = Srgba::new_f32(r, g, b, a);
|
||||||
ctx.recorder.set_draw_color(color);
|
ctx.recorder.set_draw_color(color);
|
||||||
}
|
}
|
||||||
@@ -91,10 +91,10 @@ pub unsafe extern "C-unwind" fn set_viewport(state: *mut ffi::lua_State) -> c_in
|
|||||||
match nargs {
|
match nargs {
|
||||||
0 => ctx.set_recorder_viewport_to_window_size(),
|
0 => ctx.set_recorder_viewport_to_window_size(),
|
||||||
4 => {
|
4 => {
|
||||||
let x = f32_from_stack!(state, -nargs);
|
let x = f32_from_stack!(state, 1);
|
||||||
let y = f32_from_stack!(state, -nargs + 1);
|
let y = f32_from_stack!(state, 2);
|
||||||
let w = f32_from_stack!(state, -nargs + 2);
|
let w = f32_from_stack!(state, 3);
|
||||||
let h = f32_from_stack!(state, -nargs + 3);
|
let h = f32_from_stack!(state, 4);
|
||||||
let rect = Rect::from_origin_and_size(Point::new(x, y), Size::new(w, h));
|
let rect = Rect::from_origin_and_size(Point::new(x, y), Size::new(w, h));
|
||||||
ctx.recorder.set_viewport(rect);
|
ctx.recorder.set_viewport(rect);
|
||||||
}
|
}
|
||||||
@@ -113,19 +113,19 @@ pub unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_
|
|||||||
|
|
||||||
match nargs {
|
match nargs {
|
||||||
1 => {
|
1 => {
|
||||||
let layer = i32_from_stack!(state, -nargs);
|
let layer = i32_from_stack!(state, 1);
|
||||||
ctx.recorder.set_draw_layer(layer, 0);
|
ctx.recorder.set_draw_layer(layer, 0);
|
||||||
}
|
}
|
||||||
2 => {
|
2 => {
|
||||||
let layer = match unsafe { ffi::lua_type(state, -nargs) } {
|
let layer = match unsafe { ffi::lua_type(state, 1) } {
|
||||||
ffi::LUA_TNIL => None,
|
ffi::LUA_TNIL => None,
|
||||||
ffi::LUA_TNUMBER => {
|
ffi::LUA_TNUMBER => {
|
||||||
let layer = i32_from_stack!(state, -nargs);
|
let layer = i32_from_stack!(state, 1);
|
||||||
Some(layer)
|
Some(layer)
|
||||||
}
|
}
|
||||||
t => panic!("Expected Nil or Number, got {t:?}"),
|
t => panic!("Expected Nil or Number, got {t:?}"),
|
||||||
};
|
};
|
||||||
let sublayer = i32_from_stack!(state, -nargs + 1);
|
let sublayer = i32_from_stack!(state, 2);
|
||||||
if let Some(layer) = layer {
|
if let Some(layer) = layer {
|
||||||
ctx.recorder.set_draw_layer(layer, sublayer);
|
ctx.recorder.set_draw_layer(layer, sublayer);
|
||||||
} else {
|
} else {
|
||||||
@@ -153,22 +153,22 @@ pub unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int
|
|||||||
let parse_uv = matches!(nargs, 9 | 10);
|
let parse_uv = matches!(nargs, 9 | 10);
|
||||||
let parse_layer_idx = matches!(nargs, 6 | 10);
|
let parse_layer_idx = matches!(nargs, 6 | 10);
|
||||||
|
|
||||||
let texture_id = unsafe { image_handle_texture_id(state, -nargs) };
|
let texture_id = unsafe { image_handle_texture_id(state, 1) };
|
||||||
|
|
||||||
// left, top, width, height
|
// left, top, width, height
|
||||||
let x = f32_from_stack!(state, -nargs + 1);
|
let x = f32_from_stack!(state, 2);
|
||||||
let y = f32_from_stack!(state, -nargs + 2);
|
let y = f32_from_stack!(state, 3);
|
||||||
let w = f32_from_stack!(state, -nargs + 3);
|
let w = f32_from_stack!(state, 4);
|
||||||
let h = f32_from_stack!(state, -nargs + 4);
|
let h = f32_from_stack!(state, 5);
|
||||||
let rect = Rect::from_origin_and_size(Point::new(x, y), Size::new(w, h));
|
let rect = Rect::from_origin_and_size(Point::new(x, y), Size::new(w, h));
|
||||||
|
|
||||||
// u1, v1, u2, v2
|
// u1, v1, u2, v2
|
||||||
let mut i = 5;
|
let mut i = 6;
|
||||||
let uv = if parse_uv {
|
let uv = if parse_uv {
|
||||||
let u1 = f32_from_stack!(state, -nargs + i);
|
let u1 = f32_from_stack!(state, i);
|
||||||
let v1 = f32_from_stack!(state, -nargs + i + 1);
|
let v1 = f32_from_stack!(state, i + 1);
|
||||||
let u2 = f32_from_stack!(state, -nargs + i + 2);
|
let u2 = f32_from_stack!(state, i + 2);
|
||||||
let v2 = f32_from_stack!(state, -nargs + i + 3);
|
let v2 = f32_from_stack!(state, i + 3);
|
||||||
i += 4;
|
i += 4;
|
||||||
Some(Rect::new(Point::new(u1, v1), Point::new(u2, v2)))
|
Some(Rect::new(Point::new(u1, v1), Point::new(u2, v2)))
|
||||||
} else {
|
} else {
|
||||||
@@ -176,7 +176,7 @@ pub unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int
|
|||||||
};
|
};
|
||||||
|
|
||||||
let layer_idx = if parse_layer_idx {
|
let layer_idx = if parse_layer_idx {
|
||||||
let layer_idx = i32_from_stack!(state, -nargs + i);
|
let layer_idx = i32_from_stack!(state, i);
|
||||||
(layer_idx - 1) as u32
|
(layer_idx - 1) as u32
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
@@ -202,17 +202,17 @@ pub unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c
|
|||||||
let parse_uv = matches!(nargs, 17 | 18);
|
let parse_uv = matches!(nargs, 17 | 18);
|
||||||
let parse_layer_idx = matches!(nargs, 10 | 18);
|
let parse_layer_idx = matches!(nargs, 10 | 18);
|
||||||
|
|
||||||
let texture_id = unsafe { image_handle_texture_id(state, -nargs) };
|
let texture_id = unsafe { image_handle_texture_id(state, 1) };
|
||||||
|
|
||||||
// x1, y1, x2, y2, ...
|
// x1, y1, x2, y2, ...
|
||||||
let x1 = f32_from_stack!(state, -nargs + 1);
|
let x1 = f32_from_stack!(state, 2);
|
||||||
let y1 = f32_from_stack!(state, -nargs + 2);
|
let y1 = f32_from_stack!(state, 3);
|
||||||
let x2 = f32_from_stack!(state, -nargs + 3);
|
let x2 = f32_from_stack!(state, 4);
|
||||||
let y2 = f32_from_stack!(state, -nargs + 4);
|
let y2 = f32_from_stack!(state, 5);
|
||||||
let x3 = f32_from_stack!(state, -nargs + 5);
|
let x3 = f32_from_stack!(state, 6);
|
||||||
let y3 = f32_from_stack!(state, -nargs + 6);
|
let y3 = f32_from_stack!(state, 7);
|
||||||
let x4 = f32_from_stack!(state, -nargs + 7);
|
let x4 = f32_from_stack!(state, 8);
|
||||||
let y4 = f32_from_stack!(state, -nargs + 8);
|
let y4 = f32_from_stack!(state, 9);
|
||||||
let quad = Quad::new(
|
let quad = Quad::new(
|
||||||
Point::new(x1, y1),
|
Point::new(x1, y1),
|
||||||
Point::new(x2, y2),
|
Point::new(x2, y2),
|
||||||
@@ -221,16 +221,16 @@ pub unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c
|
|||||||
);
|
);
|
||||||
|
|
||||||
// u1, v1, u2, v2, ...
|
// u1, v1, u2, v2, ...
|
||||||
let mut i = 9;
|
let mut i = 10;
|
||||||
let uv = if parse_uv {
|
let uv = if parse_uv {
|
||||||
let u1 = f32_from_stack!(state, -nargs + i);
|
let u1 = f32_from_stack!(state, i);
|
||||||
let v1 = f32_from_stack!(state, -nargs + i + 1);
|
let v1 = f32_from_stack!(state, i + 1);
|
||||||
let u2 = f32_from_stack!(state, -nargs + i + 2);
|
let u2 = f32_from_stack!(state, i + 2);
|
||||||
let v2 = f32_from_stack!(state, -nargs + i + 3);
|
let v2 = f32_from_stack!(state, i + 3);
|
||||||
let u3 = f32_from_stack!(state, -nargs + i + 4);
|
let u3 = f32_from_stack!(state, i + 4);
|
||||||
let v3 = f32_from_stack!(state, -nargs + i + 5);
|
let v3 = f32_from_stack!(state, i + 5);
|
||||||
let u4 = f32_from_stack!(state, -nargs + i + 6);
|
let u4 = f32_from_stack!(state, i + 6);
|
||||||
let v4 = f32_from_stack!(state, -nargs + i + 7);
|
let v4 = f32_from_stack!(state, i + 7);
|
||||||
i += 8;
|
i += 8;
|
||||||
Some(Quad::new(
|
Some(Quad::new(
|
||||||
Point::new(u1, v1),
|
Point::new(u1, v1),
|
||||||
@@ -243,7 +243,7 @@ pub unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c
|
|||||||
};
|
};
|
||||||
|
|
||||||
let layer_idx = if parse_layer_idx {
|
let layer_idx = if parse_layer_idx {
|
||||||
let layer_idx = i32_from_stack!(state, -nargs + i);
|
let layer_idx = i32_from_stack!(state, i);
|
||||||
(layer_idx - 1) as u32
|
(layer_idx - 1) as u32
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
|||||||
+17
-26
@@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
color::Srgba,
|
color::Srgba,
|
||||||
dpi::LogicalPoint,
|
dpi::LogicalPoint,
|
||||||
fonts::{Alignment, FontStyle, LayoutJob, LayoutToLogical},
|
fonts::{Alignment, FontStyle, LayoutJob},
|
||||||
math::Point,
|
math::Point,
|
||||||
pob::Context,
|
pob::Context,
|
||||||
};
|
};
|
||||||
@@ -46,14 +46,16 @@ pub unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int
|
|||||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||||
let mut ctx = lua_instance.app_data_mut::<Context>().unwrap();
|
let mut ctx = lua_instance.app_data_mut::<Context>().unwrap();
|
||||||
|
|
||||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
let x = f32_from_stack!(state, 1);
|
||||||
|
let y = f32_from_stack!(state, 2);
|
||||||
let x = f32_from_stack!(state, -nargs);
|
let alignment = if unsafe { ffi::lua_isnil(state, 3) } != 0 {
|
||||||
let y = f32_from_stack!(state, -nargs + 1);
|
"LEFT"
|
||||||
let alignment = str_from_stack!(state, -nargs + 2);
|
} else {
|
||||||
let line_height = i32_from_stack!(state, -nargs + 3);
|
str_from_stack!(state, 3)
|
||||||
let font_type = str_from_stack!(state, -nargs + 4);
|
};
|
||||||
let text = str_from_stack!(state, -nargs + 5);
|
let line_height = i32_from_stack!(state, 4);
|
||||||
|
let font_type = str_from_stack!(state, 5);
|
||||||
|
let text = str_from_stack!(state, 6);
|
||||||
|
|
||||||
let Ok(alignment) = alignment.parse::<PoBTextAlignment>() else {
|
let Ok(alignment) = alignment.parse::<PoBTextAlignment>() else {
|
||||||
panic!("Invalid alignment");
|
panic!("Invalid alignment");
|
||||||
@@ -101,19 +103,10 @@ pub unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int
|
|||||||
let layout = ctx.fonts.borrow_mut().layout(job, scale_factor);
|
let layout = ctx.fonts.borrow_mut().layout(job, scale_factor);
|
||||||
|
|
||||||
// apply offset to account for anchor position
|
// apply offset to account for anchor position
|
||||||
let position = position + layout.anchor_offset(halign);
|
let layout_origin = position + layout.anchor_offset(halign);
|
||||||
// align layout anchor with the physical pixel grid to reduce blurriness
|
|
||||||
let position = (position * scale_factor).round() / scale_factor;
|
|
||||||
|
|
||||||
for glyph in &layout.glyphs {
|
ctx.recorder
|
||||||
ctx.recorder.draw_glyph(
|
.draw_glyphs(&layout, layout_origin, is_absolute_position, scale_factor);
|
||||||
LayoutToLogical::new(position.x, position.y).transform_box(&glyph.rect),
|
|
||||||
glyph.uv,
|
|
||||||
glyph.color,
|
|
||||||
glyph.layer_idx,
|
|
||||||
is_absolute_position,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
@@ -123,11 +116,9 @@ pub unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) ->
|
|||||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||||
let ctx = lua_instance.app_data_ref::<Context>().unwrap();
|
let ctx = lua_instance.app_data_ref::<Context>().unwrap();
|
||||||
|
|
||||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
let line_height = i32_from_stack!(state, 1);
|
||||||
|
let font_type = str_from_stack!(state, 2);
|
||||||
let line_height = i32_from_stack!(state, -nargs);
|
let text = str_from_stack!(state, 3);
|
||||||
let font_type = str_from_stack!(state, -nargs + 1);
|
|
||||||
let text = str_from_stack!(state, -nargs + 2);
|
|
||||||
|
|
||||||
let Ok(font_type) = font_type.parse::<PoBFontType>() else {
|
let Ok(font_type) = font_type.parse::<PoBFontType>() else {
|
||||||
panic!("Invalid font type");
|
panic!("Invalid font type");
|
||||||
|
|||||||
Reference in new issue
Block a user