1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//! Types.

pub mod setting;
pub mod window_type;

pub use setting::SettingValue;
pub use window_type::WindowTypeValue;

#[derive(
    Debug,
    Default,
    Clone,
    PartialOrd,
    Ord,
    PartialEq,
    Eq,
    serde::Serialize,
    serde::Deserialize,
)]
pub struct Uid(pub i32);

#[derive(
    Clone,
    Debug,
    Default,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "PascalCase")]
pub struct P3 {
    /// X value.
    pub x: f64,
    /// Y value.
    pub y: f64,
    /// Z value.
    pub z: f64,
}

/// Position.
#[derive(
    Clone,
    Debug,
    Default,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase", transparent)]
pub struct Pos(pub P3);

/// Rotation (EulerAngles).
#[derive(
    Clone,
    Debug,
    Default,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase", transparent)]
pub struct Rot(pub P3);

serde_with::with_prefix!(prefix_pos "pos");
serde_with::with_prefix!(prefix_rot "rot");
serde_with::with_prefix!(prefix_center "center");
serde_with::with_prefix!(prefix_extents "extents");

/// OVROverlayTransform.
// #[wasm_bindgen]
#[derive(
    Clone,
    Debug,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase")]
// TODO: try renaming into OvrOverlayTransform
pub struct OVROverlayTransform {
    /// Position of window.
    #[serde(flatten, with = "prefix_pos")]
    pub pos: Pos,
    /// rotation of window (EulerAngles).
    #[serde(flatten, with = "prefix_rot")]
    pub rot: Rot,
    /// Size of window (In meters).
    pub size: f64,
    /// Opacity of window.
    pub opacity: f64,
    /// Curvature of window.
    pub curvature: f64,
    /// Framerate of window.
    pub framerate: i32,
    /// Eco mode enabled or disabled.
    pub eco_mode: bool,
    /// Look hiding enabled or disabled.
    pub look_hiding: bool,
    /// Device window is attached to.
    pub attached_device: i32,
    /// If overlay should save and automatically re-open next program start.
    pub should_save: bool,
}

impl Default for OVROverlayTransform {
    fn default() -> Self {
        Self {
            pos: Default::default(),
            rot: Default::default(),
            size: 0.25,
            opacity: 1.,
            curvature: 0.,
            framerate: 60,
            eco_mode: true,
            look_hiding: false,
            attached_device: 0,
            should_save: false,
        }
    }
}

/// OVRWebContents.
#[derive(
    Clone,
    Debug,
    Default,
    Eq,
    PartialEq,
    Ord,
    PartialOrd,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase")]
// TODO: try renaming into OvrWebContents
pub struct OVRWebContents {
    /// URL of web page to display.
    url: String,
    /// Width of overlay.
    pub width: i32,
    /// Height of overlay.
    pub height: i32,
}

// https://github.com/rustwasm/wasm-bindgen/issues/1775
// `String` fields cannot be `pub`, and require getter/setters.
impl OVRWebContents {
    pub fn url(&self) -> &str {
        &self.url
    }
    pub fn url_mut(&mut self) -> &mut String {
        &mut self.url
    }
}

/// OVROverlayBounds.
///
/// Refer to Unity documentation for 'Bounds'.
#[derive(
    Clone,
    Debug,
    Default,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase")]
// TODO: try renaming into OvrOverlayBounds
pub struct OVROverlayBounds {
    /// Center - position.
    #[serde(flatten, with = "prefix_center")]
    pub center: Pos,
    /// Extents - position.
    #[serde(flatten, with = "prefix_extents")]
    pub extents: Pos,
}

/// OVRFingerCurls.
///
/// 0 to 1.
#[derive(
    Clone,
    Debug,
    Default,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase")]
// TODO: try renaming into OvrFingerCurls
pub struct OVRFingerCurls {
    /// Thumb curl.
    pub thumb: f64,
    /// Index curl.
    pub index: f64,
    /// Middle curl.
    pub middle: f64,
    /// ring curl.
    pub ring: f64,
    /// ring pinky.
    pub pinky: f64,
}

/// OVRDeviceUpdate.
#[derive(
    Clone,
    Debug,
    Default,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase")]
// TODO: try renaming into OvrDeviceUpdate
pub struct OVRDeviceUpdate {
    /// If this is the active controller. (Always true for HMD).
    pub active: bool,
    #[serde(flatten, with = "prefix_pos")]
    pub pos: Pos,
    #[serde(flatten, with = "prefix_rot")]
    pub rot: Rot,
    /// If trigger bind is pressed.
    pub trigger_down: bool,
    /// If window move bind is pressed.
    pub window_move_down: bool,
    /// If edit mode bind is pressed.
    pub edit_mode_down: bool,
    /// Trackpad X tocuh position. (Left/Right)
    pub trackpad_x: f64,
    /// Trackpad Y touch position. (Up/Down)
    pub trackpad_y: f64,
}

/// OVRTransformUpdate.
#[derive(
    Clone,
    Debug,
    Default,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase")]
// TODO: try renaming into OvrTransformUpdate
pub struct OVRTransformUpdate {
    #[serde(flatten, with = "prefix_pos")]
    pub pos: Pos,
    #[serde(flatten, with = "prefix_rot")]
    pub rot: Rot,
    /// Overlay size.
    pub size: f64,
    /// Overlay width in pixels.
    pub width: i32,
    /// Overlay height in pixels.
    pub height: i32,
}

#[derive(
    Clone,
    Debug,
    Default,
    Eq,
    PartialEq,
    Ord,
    PartialOrd,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
#[serde(rename_all = "camelCase")]
// TODO: check this rename from KeyValuePair
pub struct KeyValuePairI32String {
    pub name: Option<i32>,
    value: Option<String>,
}

// https://github.com/rustwasm/wasm-bindgen/issues/1775
// `String` fields cannot be `pub`, and require getter/setters.
impl KeyValuePairI32String {
    pub fn value(&self) -> Option<&str> {
        self.value.as_deref()
    }
    pub fn value_mut(&mut self) -> Option<&mut str> {
        self.value.as_deref_mut()
    }
}