use crate::structs::coord::Coord;
use winapi::um::wincon::{CONSOLE_SELECTION_INFO};
use crate::structs::small_rect::SmallRect;
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub struct ConsoleSelectionInfo {
pub selection_indicator: SelectionState,
pub selection_anchor: Coord,
pub selection_rect: SmallRect,
}
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd,Copy, Clone)]
pub struct SelectionState(u32);
impl SelectionState {
pub const CONSOLE_NO_SELECTION: u32 = 0x0000;
pub const CONSOLE_SELECTION_IN_PROGRESS: u32 = 0x0001;
pub const CONSOLE_SELECTION_NOT_EMPTY: u32 = 0x0002;
pub const CONSOLE_MOUSE_SELECTION: u32 = 0x0004;
pub const CONSOLE_MOUSE_DOWN: u32 = 0x0008;
#[inline]
pub fn get_state(&self) -> u32 {
self.0
}
#[inline]
pub fn has_state(&self, state: u32) -> bool {
(self.0 & state) != 0
}
#[inline]
pub fn no_selection(&self) -> bool {
self.0 == SelectionState::CONSOLE_NO_SELECTION
}
#[inline]
pub fn selection_in_progress(&self) -> bool {
self.has_state(SelectionState::CONSOLE_SELECTION_IN_PROGRESS)
}
#[inline]
pub fn selection_not_empty(&self) -> bool {
self.has_state(SelectionState::CONSOLE_SELECTION_NOT_EMPTY)
}
#[inline]
pub fn mouse_selection(&self) -> bool {
self.has_state(SelectionState::CONSOLE_MOUSE_SELECTION)
}
#[inline]
pub fn is_mouse_down(&self) -> bool {
self.has_state(SelectionState::CONSOLE_MOUSE_DOWN)
}
}
impl Into<CONSOLE_SELECTION_INFO> for ConsoleSelectionInfo {
#[inline]
fn into(self) -> CONSOLE_SELECTION_INFO {
CONSOLE_SELECTION_INFO {
dwFlags: self.selection_indicator.0,
dwSelectionAnchor: self.selection_anchor.into(),
srSelection: self.selection_rect.into(),
}
}
}
impl From<CONSOLE_SELECTION_INFO> for ConsoleSelectionInfo {
#[inline]
fn from(info: CONSOLE_SELECTION_INFO) -> Self {
ConsoleSelectionInfo {
selection_indicator: SelectionState(info.dwFlags),
selection_anchor: Coord::from(info.dwSelectionAnchor),
selection_rect: SmallRect::from(info.srSelection),
}
}
}