Skip to content

Commit

Permalink
Update Documentation 👍
Browse files Browse the repository at this point in the history
	new file:   rustfmt.toml
	modified:   src/capture.rs
	modified:   src/lib.rs
	modified:   src/monitor.rs
	modified:   src/window.rs
  • Loading branch information
NiiightmareXD committed Sep 22, 2023
1 parent 1cc7d3c commit 6c67a9b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 29 deletions.
12 changes: 12 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
wrap_comments = true
edition = "2021"
format_code_in_doc_comments = true
format_macro_matchers = true
format_strings = true
version = "Two"
use_try_shorthand = true
use_field_init_shorthand = true
unstable_features = true
normalize_doc_attributes = true
normalize_comments = true
imports_granularity = "Crate"
15 changes: 8 additions & 7 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ use std::sync::Arc;
use log::error;
use parking_lot::Mutex;
use thiserror::Error;
use windows::Win32::System::WinRT::{
CreateDispatcherQueueController, DispatcherQueueOptions, RoInitialize, RoUninitialize,
DQTAT_COM_NONE, DQTYPE_THREAD_CURRENT, RO_INIT_MULTITHREADED,
};
use windows::{
core::{ComInterface, IInspectable},
Foundation::{AsyncActionCompletedHandler, TypedEventHandler},
Expand All @@ -19,7 +15,11 @@ use windows::{
ID3D11Texture2D, D3D11_CPU_ACCESS_READ, D3D11_MAPPED_SUBRESOURCE, D3D11_MAP_READ,
D3D11_TEXTURE2D_DESC, D3D11_USAGE_STAGING,
},
System::WinRT::Direct3D11::IDirect3DDxgiInterfaceAccess,
System::WinRT::{
CreateDispatcherQueueController, Direct3D11::IDirect3DDxgiInterfaceAccess,
DispatcherQueueOptions, RoInitialize, RoUninitialize, DQTAT_COM_NONE,
DQTYPE_THREAD_CURRENT, RO_INIT_MULTITHREADED,
},
UI::WindowsAndMessaging::{
DispatchMessageW, GetMessageW, PostQuitMessage, TranslateMessage, MSG,
},
Expand Down Expand Up @@ -102,7 +102,7 @@ impl WindowsCapture {
let session = frame_pool.CreateCaptureSession(&_item)?;
let trigger = Arc::new(Mutex::new(trigger));
let trigger_item = trigger.clone();
let trigger_frame_pool = trigger.clone();
let trigger_frame_pool = trigger;

// Set CaptureItem Closed Event
_item.Closed(
Expand Down Expand Up @@ -288,7 +288,8 @@ pub trait WindowsCaptureHandler: Sized {
Ok(())
}

/// Function That Will Be Called To Create The Struct The Flags Can Be Passed From Settigns
/// Function That Will Be Called To Create The Struct The Flags Can Be
/// Passed From Settigns
fn new(flags: Self::Flags) -> Self;

/// Called Every Time A New Frame Is Available
Expand Down
86 changes: 68 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,93 @@
//! # Windows Capture Rust Library
//!
//! **Windows Capture** is a highly efficient Rust library that enables you to
//! effortlessly capture the screen using the Graphics Capture API. This library
//! allows you to easily capture the screen of your Windows-based computer and
//! use it for various purposes, such as creating instructional videos, taking
//! screenshots, or recording your gameplay. With its intuitive interface and
//! robust functionality, Windows-Capture is an excellent choice for anyone
//! looking for a reliable and easy-to-use screen capturing solution.
//!
//! ## Features
//!
//! - Only Updates The Frame When Required.
//! - High Performance.
//! - Easy To Use.
//! - Latest Screen Capturing API.
//!
//! ## Installation
//!
//! Add this library to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! windows-capture = "1.0.11"
//! ```
//! or run this command
//!
//! ```text
//! cargo add windows-capture
//! ```
//!
//! ## Usage
//!
//! ```no_run
//! use std::time::Instant;
//!
//! use windows_capture::{
//! capture::{WindowsCaptureHandler, WindowsCaptureSettings},
//! frame::Frame,
//! window::Window,
//! };
//!
//! struct Capture {
//! fps: usize,
//! last_output: Instant,
//! }
//!
//! impl WindowsCaptureHandler for Capture {
//! type Flags = ();
//!
//! fn new(_: Self::Flags) -> Self {
//! Self {
//! fps: 0,
//! last_output: Instant::now(),
//! }
//! }
//!
//! fn on_frame_arrived(&mut self, _frame: Frame) {
//! self.fps += 1;
//!
//! if self.last_output.elapsed().as_secs() >= 1 {
//! println!("{}", self.fps);
//! self.fps = 0;
//! self.last_output = Instant::now();
//! }
//! }
//!
//! fn on_closed(&mut self) {
//! println!("Closed");
//! }
//! }
//!
//! let settings = WindowsCaptureSettings {
//! item: Window::get_foreground().into(),
//! capture_cursor: false,
//! draw_border: true,
//! flags: (),
//! };
//!
//! Capture::start(settings).unwrap();
//! ```
//!
//! ## Documentation
//!
//! Detailed documentation for each API and type can be found [here](https://docs.rs/windows-capture).
//!
//! ## Contributing
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//! Contributions are welcome! If you find a bug or want to add new features to
//! the library, please open an issue or submit a pull request.

pub mod capture;
mod d3d11;
Expand Down
4 changes: 2 additions & 2 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Monitor {
}

/// Create From A HMONITOR
pub fn from_hmonitor(monitor: HMONITOR) -> Self {
pub const fn from_hmonitor(monitor: HMONITOR) -> Self {
Self { monitor }
}

Expand All @@ -46,7 +46,7 @@ impl Monitor {
}

/// Get The Raw HMONITOR
pub fn get_raw_hmonitor(&self) -> HMONITOR {
pub const fn get_raw_hmonitor(&self) -> HMONITOR {
self.monitor
}

Expand Down
4 changes: 2 additions & 2 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Window {
}

/// Crate From A HWND
pub fn from_hwnd(window: HWND) -> Self {
pub const fn from_hwnd(window: HWND) -> Self {
Self { window }
}

Expand Down Expand Up @@ -103,7 +103,7 @@ impl Window {
}

/// Get The Raw HWND
pub fn get_raw_hwnd(&self) -> HWND {
pub const fn get_raw_hwnd(&self) -> HWND {
self.window
}

Expand Down

0 comments on commit 6c67a9b

Please sign in to comment.