You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

388 lines
8.0 KiB

//! `GHOST_Types.h`
use super::*;
use libc::{
c_int,
};
use std::{
marker::{
PhantomData,
},
};
/// Trait for opaque types that represent GHOST handles.
///
/// API maps to `GHOST_DECLARE_HANDLE`, and ABI maps exactly for `Handle<T>` where `T` is an implementor of this.
///
/// See [`handle`](../handle/index.html) for implementors.
pub trait GhostHandle: private::Sealed{}
/// Opaque handle type for GHOST C++ object pointers.
///
/// These have the same ABI as structs defined with `GHOST_DECLARE_HANDLE`, but it is irrelevant as its use is just for typing pointers. This field should not be instantiated itself, but instead passed as `&Handle<T>` or `&mut Handle<T>` to provide safe interfaces for these C APIs.
///
/// The following is safe:
/// ```
/// # use ghost::{error::GhostResult, c::*, handle::*};
/// extern "C" {fn some_internal_call(window: GHOST_WindowHandle) -> GHOST_TSuccess;}
///
/// fn do_something_to_window(window: &mut Handle<Window>) -> GhostResult
/// {
/// unsafe {
/// some_internal_call(window as GHOST_WindowHandle).into() // `GHOST_WindowHandle` is an alias for `*mut Handle<Window>`
/// }
/// }
/// ```
#[repr(C)]
#[derive(Debug)]
pub struct Handle<T>(c_int, PhantomData<T>)
where T: GhostHandle;
pub type GHOST_TInt8 = libc::c_char;
pub type GHOST_TUns8 = libc::c_uchar;
pub type GHOST_TUns16 = libc::c_ushort;
pub type GHOST_TInt32 = libc::c_int;
pub type GHOST_TUns32 = libc::c_uint;
// -- skip MSVC specific shit. I'm not testing on that
pub type GHOST_TInt64 = libc::c_longlong;
pub type GHOST_TUns64 = libc::c_ulonglong;
pub type GHOST_TUserDataPtr = PVoidMut;
#[repr(C)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct GHOST_GLSettings
{
pub flags: GHOST_GLFlags,
}
/// dumb hack for bitflags
macro_rules! enum_flags {
($name:ident {
$($const_name:ident = $value:expr,)*
}) => {
#[repr(transparent)] //this seems dodgy to me
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, Default, Copy)] //this has to be copy for the assignments to be ergonomic :/
pub struct $name(libc::c_int);
impl $name {
$(
#[allow(non_upper_case_globals)] pub const $const_name: $name = $name($value);
)*
pub const fn from_int(int: libc::c_int) -> Self
{
Self(int)
}
pub const fn as_int(self) -> libc::c_int
{
self.0
}
pub const fn has(self, other: Self) -> bool
{
(self.0 & other.0) == other.0
}
pub const fn add(self, other: Self) -> Self
{
Self(self.0 | other.0)
}
pub const fn remove(self, other: Self) -> Self
{
Self((self.0 | other.0) ^ other.0)
}
}
impl From<libc::c_int> for $name
{
#[inline] fn from(from: libc::c_int) -> Self
{
Self(from)
}
}
impl From<$name> for libc::c_int
{
#[inline] fn from(from: $name) -> Self
{
from.0
}
}
impl ::std::ops::BitAnd for $name
{
type Output = Self;
#[inline] fn bitand(self, rhs: Self) -> Self {
Self(rhs.0 & self.0)
}
}
impl ::std::ops::BitOr for $name
{
type Output = Self;
#[inline] fn bitor(self, rhs: Self) -> Self {
Self(rhs.0 | self.0)
}
}
impl ::std::ops::BitXor for $name
{
type Output = Self;
#[inline] fn bitxor(self, rhs: Self) -> Self {
Self(rhs.0 ^ self.0)
}
}
impl ::std::ops::Not for $name
{
type Output = Self;
#[inline] fn not(self,) -> Self {
Self(!self.0)
}
}
impl ::std::ops::BitAndAssign for $name {
#[inline] fn bitand_assign(&mut self, rhs: Self) { self.0 &= rhs.0; }
}
impl ::std::ops::BitOrAssign for $name {
#[inline] fn bitor_assign(&mut self, rhs: Self) { self.0 |= rhs.0; }
}
impl ::std::ops::BitXorAssign for $name{
#[inline] fn bitxor_assign(&mut self, rhs: Self) { self.0 ^= rhs.0; }
}
};
}
enum_flags!(GHOST_GLFlags {
StereoVisual = 1<<0,
DebugContext = 1<<1,
AlphaBackground = 1<<2,
});
enum_flags!(GHOST_DialogOptions
{
DialogWarning = 1<<0,
DialogError = 1<<1,
});
/// Value returned by some GHOST functions to indicate a success or failure.
///
/// For mapping this behaviour onto Rust, see ['GhostResult`](./error/type.GhostResult.html).
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TSuccess
{
Failure = 0,
Success,
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TTabletMode
{
None = 0,
Stylus,
Eraser,
}
impl Default for GHOST_TTabletMode
{
#[inline]
fn default() -> Self
{
Self::None
}
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TTabletAPI
{
None = 0,
Native,
Wintab,
}
impl Default for GHOST_TTabletAPI
{
#[inline]
fn default() -> Self
{
Self::None
}
}
#[repr(C)]
#[derive(Debug, Clone, PartialEq)]
pub struct GHOST_TabletData
{
pub active: GHOST_TTabletMode,
pub pressure: f32,
pub xtilt: f32,
pub ytilt: f32,
}
impl GHOST_TabletData
{
/// We use `const fn` initialiser here instead of `GHOST_TABLET_DATA_NONE` constant.
pub const fn none() -> Self{
Self{active: GHOST_TTabletMode::None, pressure: 1.0, xtilt: 0.0, ytilt: 0.0}
}
}
impl Default for GHOST_TabletData
{
#[inline] fn default() -> Self
{
Self::none()
}
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TVisibility
{
Not =0,
Partially,
Fully,
}
impl Default for GHOST_TVisibility
{
#[inline]
fn default() -> Self
{
Self::Not
}
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Copy)]
pub enum GHOST_TFireTimeConstant
{
Never = 0xFFFFFFFF,
}
impl Default for GHOST_TFireTimeConstant
{
#[inline]
fn default() -> Self
{
Self::Never
}
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TModifierKeyMask {
LeftShift = 0,
RightShift,
LeftAlt,
RightAlt,
LeftControl,
RightControl,
OS,
NumMasks
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TWindowState {
Normal = 0,
Maximized,
Minimized,
FullScreen,
Embedded,
// Modified,
// UnModified,
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TWindowOrder
{
Top =0,
Bottom,
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TDrawingContextType {
None = 0,
OpenGL,
//D3D, //lol nope
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TButtonMask{
Left = 0,
Middle,
Right,
Button4,
Button5,
/* Trackballs and programmable buttons */
Button6,
Button7,
NumMasks // Should we even keep this? I guess yeah for ABI compatability
}
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum GHOST_TEventType {
Unknown = 0,
CursorMove,
ButtonDown,
ButtonUp,
Wheel,
Trackpad,
//#ifdef WITH_INPUT_NDOF
// NDOFMotion, /// N degree of freedom device motion event
// NDOFButton, /// N degree of freedom device button event
//#endif
KeyDown,
KeyUp,
// KeyAuto,
QuitRequest,
WindowClose,
WindowActivate,
WindowDeactivate,
WindowUpdate,
WindowSize,
WindowMove,
WindowDPIHintChanged,
DraggingEntered,
DraggingUpdated,
DraggingExited,
DraggingDropDone,
OpenMainFile, // Needed for Cocoa to open double-clicked .blend file at startup
NativeResolutionChange, // Needed for Cocoa when window moves to other display
Timer,
ImeCompositionStart,
ImeComposition,
ImeCompositionEnd,
NumEventTypes
}
/**
* Definition of a callback routine that receives events.
* * The event received.
* * The callback's user data, supplied to GHOST_CreateSystem.
*/
pub type GHOST_EventCallbackProcPtr = Option<fn(handle::GHOST_EventHandle, GHOST_TUserDataPtr) -> libc::c_int>;