use crate::ffi::system::sfString;
pub use crate::ffi::*;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
decl_opaque! {
sfContext;
sfWindow;
JoystickIdentification;
sfVideoModeVector;
}
type sfJoystickIdentification = JoystickIdentification;
pub type sfCursor = crate::window::Cursor;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[allow(missing_docs)]
pub enum sfCursorType {
Arrow,
ArrowWait,
Wait,
Text,
Hand,
SizeHorizontal,
SizeVertical,
SizeTopLeftBottomRight,
SizeBottomLeftTopRight,
SizeAll,
Cross,
Help,
NotAllowed,
}
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct sfVideoMode {
pub width: c_uint,
pub height: c_uint,
pub bits_per_pixel: c_uint,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct sfContextSettings {
pub depth_bits: c_uint,
pub stencil_bits: c_uint,
pub antialiasing_level: c_uint,
pub major_version: c_uint,
pub minor_version: c_uint,
pub attribute_flags: u32,
pub srgb_capable: bool,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct SizeEvent {
pub(crate) width: c_uint,
pub(crate) height: c_uint,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct KeyEvent {
pub(crate) code: Key,
pub(crate) alt: bool,
pub(crate) control: bool,
pub(crate) shift: bool,
pub(crate) system: bool,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct TextEvent {
pub(crate) unicode: u32,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct MouseMoveEvent {
pub(crate) x: c_int,
pub(crate) y: c_int,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct MouseButtonEvent {
pub(crate) button: MouseButton,
pub(crate) x: c_int,
pub(crate) y: c_int,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct MouseWheelEvent {
pub(crate) delta: c_int,
pub(crate) x: c_int,
pub(crate) y: c_int,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct MouseWheelScrollEvent {
pub(crate) wheel: MouseWheel,
pub(crate) delta: f32,
pub(crate) x: c_int,
pub(crate) y: c_int,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct JoystickConnectEvent {
pub(crate) joystick_id: c_uint,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct JoystickMoveEvent {
pub(crate) joystick_id: c_uint,
pub(crate) axis: JoystickAxis,
pub(crate) position: f32,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct JoystickButtonEvent {
pub(crate) joystick_id: c_uint,
pub(crate) button: c_uint,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct TouchEvent {
pub(crate) finger: c_uint,
pub(crate) x: c_int,
pub(crate) y: c_int,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct SensorEvent {
pub(crate) type_: crate::ffi::window::sfSensorType,
pub(crate) x: f32,
pub(crate) y: f32,
pub(crate) z: f32,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(dead_code)] pub(crate) enum EventType {
Closed,
Resized,
LostFocus,
GainedFocus,
TextEntered,
KeyPressed,
KeyReleased,
MouseWheelMoved,
MouseWheelScrolled,
MouseButtonPressed,
MouseButtonReleased,
MouseMoved,
MouseEntered,
MouseLeft,
JoystickButtonPressed,
JoystickButtonReleased,
JoystickMoved,
JoystickConnected,
JoystickDisconnected,
TouchBegan,
TouchMoved,
TouchEnded,
SensorChanged,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Event {
pub(crate) type_: EventType,
pub(crate) union: EventUnion,
}
type sfEvent = Event;
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) union EventUnion {
pub(crate) size: SizeEvent,
pub(crate) key: KeyEvent,
pub(crate) text: TextEvent,
pub(crate) mouse_move: MouseMoveEvent,
pub(crate) mouse_button: MouseButtonEvent,
pub(crate) mouse_wheel: MouseWheelEvent,
pub(crate) mouse_wheel_scroll: MouseWheelScrollEvent,
pub(crate) joystick_move: JoystickMoveEvent,
pub(crate) joystick_button: JoystickButtonEvent,
pub(crate) joystick_connect: JoystickConnectEvent,
pub(crate) touch: TouchEvent,
pub(crate) sensor: SensorEvent,
}
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub enum JoystickAxis {
X,
Y,
Z,
R,
U,
V,
PovX,
PovY,
}
type sfJoystickAxis = JoystickAxis;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum MouseWheel {
VerticalWheel,
HorizontalWheel,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum MouseButton {
Left,
Right,
Middle,
XButton1,
XButton2,
}
type sfMouseButton = MouseButton;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Key {
Unknown = -1,
A = 0,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
Num0,
Num1,
Num2,
Num3,
Num4,
Num5,
Num6,
Num7,
Num8,
Num9,
Escape,
LControl,
LShift,
LAlt,
LSystem,
RControl,
RShift,
RAlt,
RSystem,
Menu,
LBracket,
RBracket,
Semicolon,
Comma,
Period,
Quote,
Slash,
Backslash,
Tilde,
Equal,
Hyphen,
Space,
Enter,
Backspace,
Tab,
PageUp,
PageDown,
End,
Home,
Insert,
Delete,
Add,
Subtract,
Multiply,
Divide,
Left,
Right,
Up,
Down,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
Pause,
}
type sfKeyboardKey = Key;
impl Dispose for JoystickIdentification {
unsafe fn dispose(&mut self) {
sfJoystickIdentification_destroy(self);
}
}
impl<'a> IntoIterator for &'a sfVideoModeVector {
type IntoIter = sfVideoModeVectorIter<'a>;
type Item = &'a sfVideoMode;
fn into_iter(self) -> Self::IntoIter {
sfVideoModeVectorIter {
vec: self,
len: unsafe { sfVideoModeVector_getLength(self) },
cursor: 0,
}
}
}
#[derive(Debug)]
pub struct sfVideoModeVectorIter<'a> {
vec: &'a sfVideoModeVector,
len: usize,
cursor: usize,
}
impl<'a> Iterator for sfVideoModeVectorIter<'a> {
type Item = &'a sfVideoMode;
fn next(&mut self) -> Option<&'a sfVideoMode> {
if self.cursor >= self.len {
return None;
}
unsafe {
let item = sfVideoModeVector_index(self.vec, self.cursor);
self.cursor += 1;
Some(&*item)
}
}
}
#[cfg(target_os = "windows")]
pub type sfWindowHandle = *mut c_void;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub type sfWindowHandle = std::os::raw::c_ulong;
#[cfg(target_os = "macos")]
pub type sfWindowHandle = *mut c_void;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum sfSensorType {
Accelerometer,
Gyroscope,
Magnetometer,
Gravity,
UserAcceleration,
Orientation,
Count,
}
include!("window_bindgen.rs");