Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3af5e3dccb | ||
|
|
76a1b4691d | ||
|
|
e877b599c1 | ||
|
|
cc38e31dbb | ||
|
|
2739c45181 | ||
|
|
18b05338bf | ||
|
|
73ebb1655a | ||
|
|
87ff0968d8 | ||
|
|
54b454f8b9 | ||
|
|
6d0975fe15 | ||
|
|
64960b8c3c | ||
|
|
cf518a2c40 | ||
|
|
bf588528ca | ||
|
|
db98ba627b | ||
|
|
479b7196cf | ||
|
|
a338ff02f1 |
No files matched your search
+32
-1
@@ -2,6 +2,34 @@
|
||||
|
||||
## [Unreleased] - ReleaseDate
|
||||
|
||||
## [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
|
||||
@@ -83,8 +111,11 @@
|
||||
- First release
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.4...HEAD
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.7...HEAD
|
||||
|
||||
[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
|
||||
|
||||
Generated
+1
-1
@@ -2530,7 +2530,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-path-of-building"
|
||||
version = "0.2.4"
|
||||
version = "0.2.7"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ authors = ["meehl"]
|
||||
description = "Cross-platform runtime for Path of Building"
|
||||
repository = "https://github.com/meehl/rusty-path-of-building"
|
||||
license = "MIT"
|
||||
version = "0.2.4"
|
||||
version = "0.2.7"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -40,3 +44,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.
+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(())
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
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
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx
|
||||
.clipboard()
|
||||
.set_text(text)
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
@@ -11,8 +11,8 @@ pub fn copy(l: &Lua, text: String) -> LuaResult<()> {
|
||||
}
|
||||
|
||||
pub fn paste(l: &Lua, _: ()) -> LuaResult<String> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let text = socket
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let text = ctx
|
||||
.clipboard()
|
||||
.get_text()
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
+5
-5
@@ -3,7 +3,7 @@ use std::{fs, path::PathBuf};
|
||||
|
||||
use crate::{
|
||||
args::Game,
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
util::{change_working_directory, get_executable_dir},
|
||||
};
|
||||
|
||||
@@ -25,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(())
|
||||
}
|
||||
|
||||
+37
-45
@@ -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};
|
||||
@@ -127,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 {
|
||||
@@ -137,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 => {
|
||||
@@ -145,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 => {
|
||||
@@ -154,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"),
|
||||
};
|
||||
@@ -165,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"),
|
||||
};
|
||||
@@ -191,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) } {
|
||||
@@ -213,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"),
|
||||
@@ -227,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) {
|
||||
@@ -269,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
|
||||
}
|
||||
@@ -277,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) {
|
||||
@@ -337,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
|
||||
}
|
||||
@@ -345,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) };
|
||||
|
||||
@@ -370,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 => {
|
||||
@@ -387,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,
|
||||
@@ -399,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);
|
||||
|
||||
@@ -413,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) };
|
||||
|
||||
@@ -429,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
|
||||
@@ -442,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
|
||||
@@ -468,6 +454,7 @@ 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 => FontFamily::Named(Cow::Borrowed("Bitstream Vera Sans Mono")),
|
||||
PoBFontType::Var => FontFamily::Named(Cow::Borrowed("Liberation Sans")),
|
||||
@@ -475,10 +462,12 @@ fn build_layout_job<'a>(
|
||||
font_weight = Some(700.0);
|
||||
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 => {
|
||||
// TODO: use regular Smallcaps for now, add "faux italics" later
|
||||
font_style = FontStyle::Italic;
|
||||
// use regular Smallcaps with "faux italics"
|
||||
FontFamily::Named(Cow::Borrowed("Fontin SmallCaps"))
|
||||
}
|
||||
};
|
||||
@@ -492,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() {
|
||||
@@ -631,6 +621,7 @@ enum PoBFontType {
|
||||
VarBold,
|
||||
FontinSmallcaps,
|
||||
FontinSmallcapsItalic,
|
||||
Fontin,
|
||||
FontinItalic,
|
||||
}
|
||||
|
||||
@@ -644,6 +635,7 @@ impl std::str::FromStr for PoBFontType {
|
||||
"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",
|
||||
|
||||
+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)
|
||||
}
|
||||
+33
-2
@@ -1,4 +1,5 @@
|
||||
use crate::{
|
||||
args::Game,
|
||||
dpi::{ConvertToLogical, PhysicalPoint, PhysicalSize},
|
||||
fonts::{FontData, FontDefinitions, Fonts},
|
||||
gfx::{GraphicsContext, RenderJob},
|
||||
@@ -17,6 +18,7 @@ use winit::{
|
||||
event::*,
|
||||
event_loop::ActiveEventLoop,
|
||||
keyboard::{ModifiersState, PhysicalKey},
|
||||
platform::wayland::WindowAttributesExtWayland,
|
||||
window::Window,
|
||||
};
|
||||
|
||||
@@ -123,7 +125,19 @@ impl App {
|
||||
|
||||
impl ApplicationHandler<GraphicsContext> for App {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let window = match event_loop.create_window(Window::default_attributes()) {
|
||||
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"),
|
||||
};
|
||||
|
||||
let window_attributes = Window::default_attributes()
|
||||
.with_title(title)
|
||||
.with_window_icon(load_icon()) // only works on windows and x11
|
||||
// on wayland we need an `app_id` that matches the name of a `.desktop` entry to load
|
||||
// the icon
|
||||
.with_name(app_id, app_id);
|
||||
|
||||
let window = match event_loop.create_window(window_attributes) {
|
||||
Ok(window) => Arc::new(window),
|
||||
Err(err) => {
|
||||
log::error!("{err}");
|
||||
@@ -299,6 +313,12 @@ fn pob_font_definitions() -> FontDefinitions {
|
||||
"../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!(
|
||||
@@ -327,8 +347,19 @@ fn pob_font_definitions() -> FontDefinitions {
|
||||
|
||||
definitions.generic_families.insert(
|
||||
parley::GenericFamily::Serif,
|
||||
vec!["fontin-italic".to_owned(), "fontin-smallcaps".to_owned()],
|
||||
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()
|
||||
}
|
||||
+7
-1
@@ -16,7 +16,7 @@ use parley::{
|
||||
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;
|
||||
@@ -124,18 +124,21 @@ impl Fonts {
|
||||
font_size,
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -145,12 +148,14 @@ impl Fonts {
|
||||
font_size: f32,
|
||||
font_family: FontFamily,
|
||||
font_weight: Option<FontWeight>,
|
||||
font_style: parley::FontStyle,
|
||||
) {
|
||||
profiling::scope!("preload_text");
|
||||
|
||||
let style = TextStyle {
|
||||
font_stack: FontStack::Single(font_family),
|
||||
font_weight: font_weight.unwrap_or(FontWeight::NORMAL),
|
||||
font_style,
|
||||
font_size,
|
||||
..Default::default()
|
||||
};
|
||||
@@ -202,6 +207,7 @@ impl Fonts {
|
||||
.font_weight
|
||||
.map(|w| parley::FontWeight::new(w.into()))
|
||||
.unwrap_or(default_style.font_weight),
|
||||
font_style: job.font_style.into(),
|
||||
..default_style
|
||||
};
|
||||
|
||||
|
||||
+22
-1
@@ -2,13 +2,30 @@ use crate::{color::Srgba, dpi::LogicalPoint, fonts::rasterizer::RasterizedGlyph}
|
||||
use ordered_float::OrderedFloat;
|
||||
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,
|
||||
@@ -23,6 +40,7 @@ pub struct LayoutJob<'s> {
|
||||
pub line_height: OrderedFloat<f32>,
|
||||
pub alignment: Option<Alignment>,
|
||||
pub font_weight: Option<OrderedFloat<f32>>,
|
||||
pub font_style: FontStyle,
|
||||
}
|
||||
|
||||
impl<'s> LayoutJob<'s> {
|
||||
@@ -32,6 +50,7 @@ impl<'s> LayoutJob<'s> {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +83,7 @@ impl std::hash::Hash for LayoutJob<'_> {
|
||||
self.line_height.hash(state);
|
||||
self.alignment.hash(state);
|
||||
self.font_weight.hash(state);
|
||||
self.font_style.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+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]);
|
||||
|
||||
|
||||
+2
-1
@@ -3,7 +3,7 @@ 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},
|
||||
};
|
||||
@@ -120,6 +120,7 @@ impl InstallMode {
|
||||
34.0,
|
||||
Some(Alignment::Center),
|
||||
Some(700.0),
|
||||
FontStyle::Normal,
|
||||
);
|
||||
|
||||
let progress_text = match &self.current_progress {
|
||||
|
||||
+27
-27
@@ -21,7 +21,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,9 +42,9 @@ 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 {
|
||||
/// Before executing any lua code, we need to "plug" the references into
|
||||
/// the Context and "unplug" them afterwards.
|
||||
pub struct Context {
|
||||
window: Cell<*const WindowState>,
|
||||
input: Cell<*const InputState>,
|
||||
fonts: Cell<*mut Fonts>,
|
||||
@@ -56,7 +56,7 @@ pub struct ContextSocket {
|
||||
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()),
|
||||
@@ -96,15 +96,15 @@ impl ContextSocket {
|
||||
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: &WindowState);
|
||||
ctx_accessor!(input: &InputState);
|
||||
ctx_accessor!(fonts: &mut Fonts);
|
||||
ctx_accessor!(texture_manager: &mut WrappedTextureManager);
|
||||
ctx_accessor!(clipboard: &mut Clipboard);
|
||||
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 +183,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 +194,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 +234,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 +259,8 @@ impl LuaInstance {
|
||||
}
|
||||
};
|
||||
|
||||
// "Unplug" references from "socket"
|
||||
socket.clear();
|
||||
// "Unplug" references from context
|
||||
ctx.clear();
|
||||
|
||||
handler_result
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ 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;
|
||||
self.window = Some(window);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user