xplane11-sys

git clone git://archive.git.mtrnord.blog/MTRNord/xplane11-sys.git
Log | Files | Refs | README | LICENSE

commit beb906bd5910191f1b9f10aa1f0642f5fbac7801
parent ba4483c41b7a0e0d089fc6659343d19151d3d490
Author: MTRNord <mtrnord1@gmail.com>
Date:   Wed, 14 Oct 2020 19:09:11 +0200

feat: Add XPLMGetWindowGeometry and XPLMDrawString safe functions

Diffstat:
Msrc/display.rs | 14++++++++++++++
Asrc/graphics.rs | 29+++++++++++++++++++++++++++++
Msrc/lib.rs | 2++
3 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/display.rs b/src/display.rs @@ -186,3 +186,16 @@ impl XPLMWindowBuilder { XPLMWindow { inner: window } } } + +pub fn XPLMGetWindowGeometry(in_window_id: bindings::XPLMWindowID) -> (i32,i32,i32,i32) { + let mut l = 0; + let mut t = 0; + let mut r = 0; + let mut b = 0; + + unsafe { + XPLMGetWindowGeometry(in_window_id, &mut l, &mut t, &mut r, &mut b); + } + + (l,t,r,b) +} +\ No newline at end of file diff --git a/src/graphics.rs b/src/graphics.rs @@ -0,0 +1,29 @@ +use crate::bindings; + +pub fn XPLMDrawString( + mut color: [f32; 3], + xOffset: i32, + yOffset: i32, + string: &str, + wordWrapWidth: Option<i32>, + fontID: bindings::XPLMFontID, +) { + let bytes = String::from(format!("{}\0", string)).into_bytes(); + let mut cchars: Vec<::std::os::raw::c_char> = + bytes.iter().map(|&b| b as ::std::os::raw::c_char).collect(); + let text: *mut ::std::os::raw::c_char = cchars.as_mut_ptr(); + let wordWrapWidthl = match wordWrapWidth { + Some(mut v) => &mut v, + None => std::ptr::null_mut(), + }; + unsafe { + bindings::XPLMDrawString( + color.as_mut_ptr(), + xOffset, + yOffset, + text, + wordWrapWidthl, + fontID, + ) + }; +} diff --git a/src/lib.rs b/src/lib.rs @@ -3,6 +3,8 @@ #![allow(non_snake_case)] pub mod display; +pub mod graphics; + pub mod utils; pub mod bindings { include!(concat!(env!("OUT_DIR"), "/bindings.rs"));