use std::ops::*;

/// A hint to tell a window controller whether the previous render state is
/// intact and can be updated, or was destroyed and needs to be fully redrawn.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RenderHint {
    /// The buffer contents are intact, only updates need to be drawn.
    Update,
    /// The buffer contents were destroyed, a full redraw is required.
    Redraw,
}

impl RenderHint {
    pub fn is_update(&self) -> bool { *self == RenderHint::Update }
    pub fn is_redraw(&self) -> bool { *self == RenderHint::Redraw }
}

impl BitAnd for RenderHint {
    type Output = RenderHint;
    fn bitand(self, other: RenderHint) -> Self::Output {
        if self == RenderHint::Redraw || other == RenderHint::Redraw {
            RenderHint::Redraw
        } else {
            RenderHint::Update
        }
    }
}

impl BitAndAssign for RenderHint {
    fn bitand_assign(&mut self, other: RenderHint) {
        *self = *self & other;
    }
}