use crate::{dx::*, ext::tdx::*};
pub struct Font {
pub d: bool,
pub h: i32
}
impl Tr for Font {
fn as_font(&self) -> Font { Font{d: false, h: self.h} }
fn handle(&self) -> i32 { self.h }
fn dispose(&mut self) {
if self.d && self.h != 0 {
unsafe { DeleteFontToHandle(self.h); }
self.h = 0;
}
}
}
impl Drop for Font {
fn drop(&mut self) { self.dispose(); }
}
impl Font {
pub fn create(n: &str, sz: i32, thick: i32,
fonttype: i32, charset: i32, edgesz: i32, italic: i32) -> Self {
Font{d: true, h: unsafe { CreateFontToHandle(n.as_ptr(), sz, thick,
fonttype, charset, edgesz, italic, -1) } }
}
pub fn load_data(n: &String) -> Self {
Font{d: true, h: unsafe { LoadFontDataToHandle(n.as_ptr(), 0) } }
}
pub fn draw_string(&self, x: i32, y: i32, s: &String, c: u32, e: u32, v: i32) {
unsafe { DrawStringToHandle(x, y, s.as_ptr(), c, self.h, e, v); }
}
pub fn draw_bytes(&self, x: i32, y: i32, b: &[u8], c: u32, e: u32, v: i32) {
unsafe { DrawStringToHandle(x, y, b.as_ptr(), c, self.h, e, v); }
}
}