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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
//! <p align="center"> //! <img alt="Cala" src="https://libcala.github.io/logo.svg"> //! </p> //! <p align="center"> //! <a href="https://docs.rs/cala"><img src="https://docs.rs/cala/badge.svg"></a> //! <a href="https://travis-ci.com/libcala/cala"><img src="https://api.travis-ci.com/libcala/cala.svg?branch=master" alt="Cala Build Status"></a> //! <a href="https://crates.io/crates/cala"><img src="https://img.shields.io/crates/v/cala.svg" alt = "cala on crates.io"></a> //! <a href="https://discord.gg/nXwF59K"><img src="https://img.shields.io/badge/discord-join%20server-green.svg" alt="Discord"></a> //! <br> //! <strong><a href="https://libcala.github.io">Website</a> | <a href="https://github.com/libcala/cala">GitHub</a> | <a href="https://libcala.github.io/changelog">Changelog</a> | <a href="https://libcala.github.io/tutorials">Tutorials</a> </strong> //! </p> //! //! <p> //! <h4>Note</h4> //! <p>Cala is a complete redesign of previous library <a href="https://crates.io/crates/adi">ADI</a>. It is still in it's early stages. //! </p> //! </p> //! <h1>About</h1> //! <p>Easily create cross-platform applications. Some common tasks are not easily portable across different platforms, and this crate hopes to fix that. That way you don't have to worry about how to port your GUI, audio, or bluetooth interface, etc. and can get straight to building your application's content! //! </p> //! <p>Cala is a platform-agnostic system interface for hardware IO. This means that eventually, Cala should support all of the different hardware that's connected to your computer. Cala is designed so that it talks to the operating system to interface with the hardware, so no special permissions are needed for your application. Here's a list of all of the targeted platforms (<b>bold</b> means a port has been made, <i>italic</i> means the feature doesn't work on the platform): //! <ul> //! <li><b>Linux</b></li> //! <li><b>MacOS</b> - missing <a href="https://github.com/libcala/cala/issues/5"><i>audio</i></a>, <a href="https://github.com/libcala/cala/issues/7"><i>controller</i></a>, <a href="https://github.com/libcala/cala/issues/9"><i>graphics</i></a></li> //! <li><b>Windows</b> - missing <a href="https://github.com/libcala/cala/issues/4"><i>audio</i></a>, <a href="https://github.com/libcala/cala/issues/6"><i>controller</i></a>, <a href="https://github.com/libcala/cala/issues/8"><i>graphics</i></a></li> //! <li><b>Web (WASM)</b> - missing audio, controller, graphics, files</li> //! <li>Redox</li> //! <li>Android</li> //! <li>iOS</li> //! <li>Nintendo Switch</li> //! <li>XBox</li> //! <li>PlayStation</li> //! <li>FreeBSD</li> //! <li>Maybe FreeDOS for fun 😉️</li> //! <li>Others not on this list that you will make a pull request for adding them</li> //! </ul> //! </p> //! //! <h1>Motivation & Naming</h1> //! <p> //! The aim is to create a newer, better GTK + SDL in Rust! Why GTK + SDL? Because a lot of programs need to depend on both anyway (like <a href="https://en.wikipedia.org/wiki/Totem_Video_Player">totem</a>), and they do a lot of the same things; Usually one library does each specific task better than the other. The goal of this library is to provide the common ground for video games and general GUI applications together. The name cala is derived from the fungus known as calafate rust. //! //! <h1>Getting Started</h1> //! <p>Each hardware interface can be enabled with a feature. For example, If you //! want to depend on the <code>audio</code> feature and the <code>clock</code> //! feature, you might put this in your <code>Cargo.toml</code>:</p> //! <p style="width:100%"><pre style="width:100%"><code style="width:100%"><span style="font-weight:bold;">[dependencies.cala]</span> //! <span style="color:#0A0;font-weight:bold;">version</span> = <span style="color:#0A0">"0.5"</span> //! <span style="color:#0A0;font-weight:bold;">features</span> = [<span style="color:#0A0">"audio"</span>, <span style="color:#0A0">"clock"</span>]</code></pre></p> //! //! <p> //! There is a module for each feature (feature and module names match). Module documentation may include simple tutorials. More in depth tutorials may be //! found <a href="https://libcala.github.io/tutorials">here</a>. //! </p> #![warn(missing_docs)] #![doc( html_logo_url = "https://libcala.github.io/logo.svg", html_favicon_url = "https://libcala.github.io/icon.svg" )] mod run; #[cfg(feature = "timer")] mod timer; #[cfg(feature = "user")] pub mod user { //! API for getting user information. Enable with the `user` feature. //! //! # Usage //! ```rust //! // Set the home loop to `run()`. //! cala::init!(run, ()); //! //! // Function that runs while your app runs. //! pub fn run(_: &mut ()) -> cala::Loop<()> { //! // Print out the user's information. //! println!("{}", cala::user()); //! // Exit. //! cala::Exit //! } //! ``` include!("internal/whoami.rs"); } #[cfg(feature = "controller")] pub mod controller { //! API for getting joystick / controller / gamepad input. Enable with the //! `controller` feature. //! //! # Usage //! ```rust //! // Set the home loop to `run()`. //! cala::init!(run, ()); //! //! // Function that runs while your app runs. //! pub fn run(_: &mut ()) -> cala::Loop<()> { //! let layout = cala::ControllerLayout::new().joy(false).lrt(false).abxy(false); //! //! // Iterate through all of the controllers. //! 'a: for (id, state) in cala::controllers(&layout) { //! println!("{}: {:?}", id, state.get()); //! } //! std::thread::sleep(std::time::Duration::from_millis(16)); //! // Exit. //! cala::Continue //! } //! ``` include!("internal/stick.rs"); } #[cfg(feature = "audio")] pub mod audio { //! API for recording / playing audio. Enable with the `audio` feature. //! //! # Usage //! The following example shows how to play audio as it's being recorded. Headphones //! recommended. //! //! ```rust //! use std::collections::VecDeque; //! //! // The program data context. //! struct Data { //! buffer: VecDeque<(i16, i16)>, //! } //! //! // Set the home loop to `run()`. //! cala::init!(run, Data { //! buffer: VecDeque::new(), //! }); //! //! fn run(data: &mut Data) -> cala::Loop<Data> { //! // Record some sound. //! cala::record(&mut |_whichmic, l, r| { //! data.buffer.push_back((l, r)); //! }); //! //! // Play that sound. //! cala::play(&mut || { //! if let Some((lsample, rsample)) = data.buffer.pop_front() { //! cala::AudioSample::stereo(lsample, rsample) //! } else { //! // Play silence if not enough has been recorded yet. //! cala::AudioSample::stereo(0, 0) //! } //! }); //! //! cala::Continue //! } //! ``` include!("internal/wavy.rs"); } #[cfg(feature = "files")] pub mod files { //! API for loading & saving files. Enable with the `files` feature. //! //! # Usage //! ```rust //! // TODO //! ``` include!("internal/stronghold.rs"); } #[cfg(feature = "graphics")] mod icons; #[cfg(feature = "graphics")] #[macro_use] pub mod graphics { //! API for rendering graphics. Enable with the `graphics` feature. //! //! # Getting Started //! This API is designed to be high-level without sacrificing optimization. //! Graphics are complicated though, so before you start, a few things need //! to be defined. //! //! ## Shader //! A Shader is a program that runs on the GPU for the purpose of drawing //! Shapes. When you make your program, start by creating a shader. //! Shaders are built at compile time, so you'll need to make a build.rs and //! depend on the [`res`](https://crates.io/crates/res) crate. Calling //! `generate()` in your build.rs will generate your shaders. //! //! ## Shape //! A shape is a collection of vertices that when connected make a 2D or 3D //! shape. Shapes can only be used with one Shader because they may have //! shader-specific additional information attached to them like color or //! graphic coordinates. //! //! ## Instance //! Shapes themselves can't be drawn, first you must make an Instance of the //! Shape. Instances can have position attached to them, and/or rotation //! and size. //! //! # Example //! ```rust //! // TODO //! ``` include!("internal/barg.rs"); pub use crate::timer::*; } #[cfg(feature = "clock")] pub mod clock; // Export all types to root. pub use run::Loop; #[cfg(feature = "user")] #[doc(hidden)] pub use user::*; #[cfg(feature = "controller")] #[doc(hidden)] pub use controller::*; #[cfg(feature = "audio")] #[doc(hidden)] pub use audio::*; #[cfg(feature = "graphics")] #[doc(hidden)] pub use graphics::*; #[cfg(feature = "clock")] #[doc(hidden)] pub use clock::*; #[doc(hidden)] pub use internal::start; #[doc(hidden)] pub use internal::info as __cala_internal_info__; #[doc(hidden)] pub use internal::warn as __cala_internal_warn__; #[doc(hidden)] pub use internal::note as __cala_internal_note__; #[doc(hidden)] pub use run::Loop::*; pub use internal::delta; //mod audio; // mod dive; mod internal; // mod iolock; // Others.... //pub use audio::AudioSample; /// Define the entry point for your program. /// /// Note that not only is the function an entry point, but also a loop. Usually you'll /// want to do your initialization in a block of code for the second parameter. You can /// also do additional intialization inside of the initial loop, and then at the end of /// the function switch to your main loop. /// /// See [`Loop`](enum.Loop.html) for more details. /// /// # Usage /// ```rust /// // Set the home loop to `run()`. /// cala::init!(run, ()); /// /// // Function that runs while your app runs. /// pub fn run(_: &mut ()) -> cala::Loop<()> { /// // Print out the user's information. /// println!("{}", cala::user()); /// // Exit. /// cala::Exit /// } /// ``` #[macro_export] macro_rules! init { ($home_loop: expr, $init_data: expr) => { fn main() { let mut window_title = String::new(); let mut cap = true; let fallback = env!("CARGO_PKG_NAME"); for c in fallback.chars() { match c { '.' | '-' | '_' => { window_title.push(' '); cap = true; } a => { if cap { cap = false; for i in a.to_uppercase() { window_title.push(i); } } else { window_title.push(a); } } } } cala::start(window_title.as_str(), $home_loop, &|| $init_data); } }; } /// Log an informative (stdout) message only in debug mode. /// /// This is designed to be used for debugging. #[macro_export] macro_rules! note { () => { $crate::__cala_internal_note__("") }; ($($arg:tt)*) => { $crate::__cala_internal_note__(&format!("{}", format_args!($($arg)*))) }; } /// Log an informative (stdout) message in both release and debug mode. /// /// Do not overuse this function. Release builds should have few logs. #[macro_export] macro_rules! info { () => { $crate::__cala_internal_info__("") }; ($($arg:tt)*) => { $crate::__cala_internal_info__(&format!("{}", format_args!($($arg)*))) }; } /// Log a warning (stderr) message in both release and debug mode. /// /// Do not overuse this function. Release builds should have few logs. #[macro_export] macro_rules! warn { () => { $crate::__cala_internal_warn__("") }; ($($arg:tt)*) => { $crate::__cala_internal_warn__(&format!("{}", format_args!($($arg)*))) }; }