mod accels;
pub mod application;
pub mod clipboard;
pub mod dcomp;
pub mod dialog;
pub mod error;
mod keyboard;
pub mod menu;
pub mod paint;
pub mod screen;
mod timers;
pub mod util;
pub mod window;
use piet_common::d2d::DeviceContext;
use std::fmt::{Debug, Display, Formatter};
use winapi::shared::winerror::HRESULT;
use winapi::um::d2d1::ID2D1RenderTarget;
use wio::com::ComPtr;
#[derive(Clone)]
pub struct DxgiSurfaceRenderTarget {
ptr: ComPtr<ID2D1RenderTarget>,
}
impl DxgiSurfaceRenderTarget {
pub unsafe fn from_raw(raw: *mut ID2D1RenderTarget) -> Self {
DxgiSurfaceRenderTarget {
ptr: ComPtr::from_raw(raw),
}
}
pub unsafe fn as_device_context(&self) -> Option<DeviceContext> {
self.ptr
.cast()
.ok()
.map(|com_ptr| DeviceContext::new(com_ptr))
}
}
pub enum Error {
WinapiError(HRESULT),
}
impl From<HRESULT> for Error {
fn from(hr: HRESULT) -> Error {
Error::WinapiError(hr)
}
}
impl Debug for Error {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self {
Error::WinapiError(hr) => write!(f, "hresult {hr:x}"),
}
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self {
Error::WinapiError(hr) => write!(f, "hresult {hr:x}"),
}
}
}
impl std::error::Error for Error {
fn description(&self) -> &str {
"winapi error"
}
}