macro_rules! if_ok
{
($e: expr) =>
{
if ($e).is_err()
{
return Err(());
}
}
}
macro_rules! opaque
{
($f: ident) =>
{
#[allow(missing_copy_implementations)]
pub enum $f
{
}
}
}
macro_rules! flag_type
{
($f: ident { $($n: ident = $v: expr),*}) =>
{
#[derive(Copy)]
pub struct $f
{
bits: u32
}
impl $f
{
#[inline]
pub fn get(&self) -> u32
{
self.bits
}
}
impl Flag for $f
{
fn zero() -> $f
{
$f{bits: 0}
}
}
impl ::std::ops::BitOr for $f
{
type Output = $f;
fn bitor(self, e: $f) -> $f
{
$f{bits: self.bits | e.bits}
}
}
impl ::std::ops::BitAnd for $f
{
type Output = bool;
fn bitand(self, e: $f) -> bool
{
self.bits & e.bits != 0
}
}
$(
pub const $n: $f = $f{bits: $v};
)+
}
}
macro_rules! cast_to_c
{
($p:ident, f32) =>
{
$p as c_float
};
($p:ident, Color) =>
{
*$p
}
}
macro_rules! wrap_bitmap_drawing
{
($cf:ident -> $rf:ident ( $( $p:ident : $t:ident ),* )) =>
{
fn $rf<T: BitmapLike>(dummy:dummy, bitmap: &T, $( $p : $t ),* , flags: BitmapDrawingFlags)
{
target_bitmap_check(self.get_target_bitmap());
unsafe
{
$cf(bitmap.get_bitmap(),
$(
cast_to_c!($p, $t)
),*
, (flags.get() << 1) as c_int);
}
}
}
}