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
use libc::c_int;
use ui::UI;
use ui_sys::{self, uiDrawPath};

pub use ui_sys::uiDrawFillMode as FillMode;

pub struct Path {
    ui_draw_path: *mut uiDrawPath,
}

impl Drop for Path {
    fn drop(&mut self) {
        unsafe { ui_sys::uiDrawFreePath(self.ui_draw_path) }
    }
}

impl Path {
    pub fn new(_ctx: &UI, fill_mode: FillMode) -> Path {
        unsafe {
            Path {
                ui_draw_path: ui_sys::uiDrawNewPath(fill_mode),
            }
        }
    }

    pub fn new_figure(&self, _ctx: &UI, x: f64, y: f64) {
        unsafe { ui_sys::uiDrawPathNewFigure(self.ui_draw_path, x, y) }
    }

    pub fn new_figure_with_arc(
        &self,
        _ctx: &UI,
        x_center: f64,
        y_center: f64,
        radius: f64,
        start_angle: f64,
        sweep: f64,
        negative: bool,
    ) {
        unsafe {
            ui_sys::uiDrawPathNewFigureWithArc(
                self.ui_draw_path,
                x_center,
                y_center,
                radius,
                start_angle,
                sweep,
                negative as c_int,
            )
        }
    }

    pub fn line_to(&self, _ctx: &UI, x: f64, y: f64) {
        unsafe { ui_sys::uiDrawPathLineTo(self.ui_draw_path, x, y) }
    }

    pub fn arc_to(
        &self,
        _ctx: &UI,
        x_center: f64,
        y_center: f64,
        radius: f64,
        start_angle: f64,
        sweep: f64,
        negative: bool,
    ) {
        unsafe {
            ui_sys::uiDrawPathArcTo(
                self.ui_draw_path,
                x_center,
                y_center,
                radius,
                start_angle,
                sweep,
                negative as c_int,
            )
        }
    }

    pub fn bezier_to(
        &self,
        _ctx: &UI,
        c1x: f64,
        c1y: f64,
        c2x: f64,
        c2y: f64,
        end_x: f64,
        end_y: f64,
    ) {
        unsafe { ui_sys::uiDrawPathBezierTo(self.ui_draw_path, c1x, c1y, c2x, c2y, end_x, end_y) }
    }

    pub fn close_figure(&self, _ctx: &UI) {
        unsafe { ui_sys::uiDrawPathCloseFigure(self.ui_draw_path) }
    }

    pub fn add_rectangle(&self, _ctx: &UI, x: f64, y: f64, width: f64, height: f64) {
        unsafe { ui_sys::uiDrawPathAddRectangle(self.ui_draw_path, x, y, width, height) }
    }

    pub fn end(&self, _ctx: &UI) {
        unsafe { ui_sys::uiDrawPathEnd(self.ui_draw_path) }
    }

    /// Return the underlying pointer for this Path.
    pub fn ptr(&self) -> *mut uiDrawPath {
        self.ui_draw_path
    }
}