convert cp437-grid to tuple

This commit is contained in:
Vinzenz Schroeter 2024-09-07 15:18:51 +02:00
parent 9ab87f6748
commit eb43ccfa6d
2 changed files with 11 additions and 19 deletions

View file

@ -345,7 +345,7 @@ pub unsafe extern "C" fn sp_command_cp437_data(
let grid = *Box::from_raw(grid); let grid = *Box::from_raw(grid);
Box::into_raw(Box::new(SPCommand(servicepoint::Command::Cp437Data( Box::into_raw(Box::new(SPCommand(servicepoint::Command::Cp437Data(
Origin::new(x, y), Origin::new(x, y),
grid.actual, grid.0,
)))) ))))
} }

View file

@ -17,15 +17,11 @@ use servicepoint::{DataRef, Grid};
/// sp_cp437_grid_set(grid, 0, 0, '!'); /// sp_cp437_grid_set(grid, 0, 0, '!');
/// sp_cp437_grid_free(grid); /// sp_cp437_grid_free(grid);
/// ``` /// ```
pub struct SPCp437Grid { pub struct SPCp437Grid(pub(crate) servicepoint::Cp437Grid);
pub(crate) actual: servicepoint::Cp437Grid,
}
impl Clone for SPCp437Grid { impl Clone for SPCp437Grid {
fn clone(&self) -> Self { fn clone(&self) -> Self {
SPCp437Grid { SPCp437Grid(self.0.clone())
actual: self.actual.clone(),
}
} }
} }
@ -44,9 +40,7 @@ pub unsafe extern "C" fn sp_cp437_grid_new(
width: usize, width: usize,
height: usize, height: usize,
) -> *mut SPCp437Grid { ) -> *mut SPCp437Grid {
Box::into_raw(Box::new(SPCp437Grid { Box::into_raw(Box::new(SPCp437Grid(servicepoint::Cp437Grid::new(width, height))))
actual: servicepoint::Cp437Grid::new(width, height),
}))
} }
/// Loads a `SPCp437Grid` with the specified dimensions from the provided data. /// Loads a `SPCp437Grid` with the specified dimensions from the provided data.
@ -73,9 +67,7 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
data_length: usize, data_length: usize,
) -> *mut SPCp437Grid { ) -> *mut SPCp437Grid {
let data = std::slice::from_raw_parts(data, data_length); let data = std::slice::from_raw_parts(data, data_length);
Box::into_raw(Box::new(SPCp437Grid { Box::into_raw(Box::new(SPCp437Grid(servicepoint::Cp437Grid::load(width, height, data))))
actual: servicepoint::Cp437Grid::load(width, height, data),
}))
} }
/// Clones a `SPCp437Grid`. /// Clones a `SPCp437Grid`.
@ -134,7 +126,7 @@ pub unsafe extern "C" fn sp_cp437_grid_get(
x: usize, x: usize,
y: usize, y: usize,
) -> u8 { ) -> u8 {
(*cp437_grid).actual.get(x, y) (*cp437_grid).0.get(x, y)
} }
/// Sets the value of the specified position in the `SPCp437Grid`. /// Sets the value of the specified position in the `SPCp437Grid`.
@ -164,7 +156,7 @@ pub unsafe extern "C" fn sp_cp437_grid_set(
y: usize, y: usize,
value: u8, value: u8,
) { ) {
(*cp437_grid).actual.set(x, y, value); (*cp437_grid).0.set(x, y, value);
} }
/// Sets the value of all cells in the `SPCp437Grid`. /// Sets the value of all cells in the `SPCp437Grid`.
@ -185,7 +177,7 @@ pub unsafe extern "C" fn sp_cp437_grid_fill(
cp437_grid: *mut SPCp437Grid, cp437_grid: *mut SPCp437Grid,
value: u8, value: u8,
) { ) {
(*cp437_grid).actual.fill(value); (*cp437_grid).0.fill(value);
} }
/// Gets the width of the `SPCp437Grid` instance. /// Gets the width of the `SPCp437Grid` instance.
@ -203,7 +195,7 @@ pub unsafe extern "C" fn sp_cp437_grid_fill(
pub unsafe extern "C" fn sp_cp437_grid_width( pub unsafe extern "C" fn sp_cp437_grid_width(
cp437_grid: *const SPCp437Grid, cp437_grid: *const SPCp437Grid,
) -> usize { ) -> usize {
(*cp437_grid).actual.width() (*cp437_grid).0.width()
} }
/// Gets the height of the `SPCp437Grid` instance. /// Gets the height of the `SPCp437Grid` instance.
@ -221,7 +213,7 @@ pub unsafe extern "C" fn sp_cp437_grid_width(
pub unsafe extern "C" fn sp_cp437_grid_height( pub unsafe extern "C" fn sp_cp437_grid_height(
cp437_grid: *const SPCp437Grid, cp437_grid: *const SPCp437Grid,
) -> usize { ) -> usize {
(*cp437_grid).actual.height() (*cp437_grid).0.height()
} }
/// Gets an unsafe reference to the data of the `SPCp437Grid` instance. /// Gets an unsafe reference to the data of the `SPCp437Grid` instance.
@ -239,7 +231,7 @@ pub unsafe extern "C" fn sp_cp437_grid_height(
pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref( pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref(
cp437_grid: *mut SPCp437Grid, cp437_grid: *mut SPCp437Grid,
) -> SPByteSlice { ) -> SPByteSlice {
let data = (*cp437_grid).actual.data_ref_mut(); let data = (*cp437_grid).0.data_ref_mut();
SPByteSlice { SPByteSlice {
start: data.as_mut_ptr_range().start, start: data.as_mut_ptr_range().start,
length: data.len(), length: data.len(),