playdate_graphics/
api.rs

1//! Global Playdate graphics API.
2
3use core::ffi::c_void;
4use core::ffi::c_char;
5use core::ffi::c_float;
6use core::ffi::c_int;
7use core::ptr::NonNull;
8
9use sys::ffi::LCDBitmap;
10use sys::ffi::LCDColor;
11use sys::ffi::LCDRect;
12use sys::ffi::LCDLineCapStyle;
13use sys::ffi::LCDPolygonFillRule;
14use sys::ffi::playdate_graphics;
15use sys::ffi::LCDBitmapDrawMode;
16use sys::ffi::LCDSolidColor;
17use sys::ffi::LCDBitmapFlip;
18use sys::ffi::LCDBitmapTable;
19use sys::ffi::LCDFontPage;
20use sys::ffi::LCDFontGlyph;
21use sys::ffi::LCDFont;
22use sys::ffi::PDStringEncoding;
23use sys::ffi::LCDFontData;
24use sys::ffi::playdate_video;
25
26
27/// Default graphics api end-point, ZST.
28///
29/// All calls approximately costs ~3 derefs.
30#[derive(Debug, Clone, Copy, core::default::Default)]
31pub struct Default;
32impl crate::bitmap::api::Api for Default {}
33impl crate::bitmap::table::api::Api for Default {}
34impl crate::text::api::Api for Default {}
35
36impl Api for Default {
37	#[inline(always)]
38	fn video<VApi: crate::video::api::Api + From<*const playdate_video>>(&self) -> VApi {
39		VApi::from(sys::api!(graphics.video))
40	}
41}
42
43
44/// Cached graphics api end-point.
45///
46/// Stores one reference, so size on stack is eq `usize`.
47///
48/// All calls approximately costs ~1 deref.
49#[derive(Clone, Copy)]
50#[cfg_attr(feature = "bindings-derive-debug", derive(Debug))]
51pub struct Cache(&'static playdate_graphics);
52
53impl core::default::Default for Cache {
54	fn default() -> Self { Self(sys::api!(graphics)) }
55}
56
57impl From<*const playdate_graphics> for Cache {
58	#[inline(always)]
59	fn from(ptr: *const playdate_graphics) -> Self { Self(unsafe { ptr.as_ref() }.expect("system")) }
60}
61
62impl From<&'static playdate_graphics> for Cache {
63	#[inline(always)]
64	fn from(r: &'static playdate_graphics) -> Self { Self(r) }
65}
66
67impl From<NonNull<playdate_graphics>> for Cache {
68	#[inline(always)]
69	fn from(ptr: NonNull<playdate_graphics>) -> Self { Self(unsafe { ptr.as_ref() }) }
70}
71
72impl From<&'_ NonNull<playdate_graphics>> for Cache {
73	#[inline(always)]
74	fn from(ptr: &NonNull<playdate_graphics>) -> Self { Self(unsafe { ptr.as_ref() }) }
75}
76
77
78impl crate::text::api::Api for Cache {
79	/// Equivalent to [`sys::ffi::playdate_graphics::drawText`]
80	#[doc(alias = "sys::ffi::playdate_graphics::drawText")]
81	#[inline(always)]
82	fn draw_text(
83		&self)
84		-> unsafe extern "C" fn(text: *const c_void,
85		                        len: usize,
86		                        encoding: PDStringEncoding,
87		                        x: c_int,
88		                        y: c_int) -> c_int {
89		self.0.drawText.expect("drawText")
90	}
91
92	/// Equivalent to [`sys::ffi::playdate_graphics::getTextWidth`]
93	#[doc(alias = "sys::ffi::playdate_graphics::getTextWidth")]
94	#[inline(always)]
95	fn get_text_width(
96		&self)
97		-> unsafe extern "C" fn(font: *mut LCDFont,
98		                        text: *const c_void,
99		                        len: usize,
100		                        encoding: PDStringEncoding,
101		                        tracking: c_int) -> c_int {
102		self.0.getTextWidth.expect("getTextWidth")
103	}
104
105	/// Equivalent to [`sys::ffi::playdate_graphics::getFontHeight`]
106	#[doc(alias = "sys::ffi::playdate_graphics::getFontHeight")]
107	#[inline(always)]
108	fn get_font_height(&self) -> unsafe extern "C" fn(font: *mut LCDFont) -> u8 {
109		self.0.getFontHeight.expect("getFontHeight")
110	}
111
112	/// Equivalent to [`sys::ffi::playdate_graphics::setFont`]
113	#[doc(alias = "sys::ffi::playdate_graphics::setFont")]
114	#[inline(always)]
115	fn set_font(&self) -> unsafe extern "C" fn(font: *mut LCDFont) { self.0.setFont.expect("setFont") }
116
117	/// Equivalent to [`sys::ffi::playdate_graphics::setTextTracking`]
118	#[doc(alias = "sys::ffi::playdate_graphics::setTextTracking")]
119	#[inline(always)]
120	fn set_text_tracking(&self) -> unsafe extern "C" fn(tracking: c_int) {
121		self.0.setTextTracking.expect("setTextTracking")
122	}
123
124	/// Equivalent to [`sys::ffi::playdate_graphics::getTextTracking`]
125	#[doc(alias = "sys::ffi::playdate_graphics::getTextTracking")]
126	#[inline(always)]
127	fn get_text_tracking(&self) -> unsafe extern "C" fn() -> c_int {
128		self.0.getTextTracking.expect("getTextTracking")
129	}
130
131	/// Equivalent to [`sys::ffi::playdate_graphics::getGlyphKerning`]
132	#[doc(alias = "sys::ffi::playdate_graphics::getGlyphKerning")]
133	#[inline(always)]
134	fn get_glyph_kerning(
135		&self)
136		-> unsafe extern "C" fn(glyph: *mut LCDFontGlyph, glyphcode: u32, nextcode: u32) -> c_int {
137		self.0.getGlyphKerning.expect("getGlyphKerning")
138	}
139
140	/// Equivalent to [`sys::ffi::playdate_graphics::loadFont`]
141	#[doc(alias = "sys::ffi::playdate_graphics::loadFont")]
142	#[inline(always)]
143	fn load_font(&self) -> unsafe extern "C" fn(path: *const c_char, outErr: *mut *const c_char) -> *mut LCDFont {
144		self.0.loadFont.expect("loadFont")
145	}
146
147	/// Equivalent to [`sys::ffi::playdate_graphics::getFontPage`]
148	#[doc(alias = "sys::ffi::playdate_graphics::getFontPage")]
149	#[inline(always)]
150	fn get_font_page(&self) -> unsafe extern "C" fn(font: *mut LCDFont, c: u32) -> *mut LCDFontPage {
151		self.0.getFontPage.expect("getFontPage")
152	}
153
154	/// Equivalent to [`sys::ffi::playdate_graphics::getPageGlyph`]
155	#[doc(alias = "sys::ffi::playdate_graphics::getPageGlyph")]
156	#[inline(always)]
157	fn get_page_glyph(
158		&self)
159		-> unsafe extern "C" fn(page: *mut LCDFontPage,
160		                        c: u32,
161		                        bitmap: *mut *mut LCDBitmap,
162		                        advance: *mut c_int) -> *mut LCDFontGlyph {
163		self.0.getPageGlyph.expect("getPageGlyph")
164	}
165
166	/// Equivalent to [`sys::ffi::playdate_graphics::makeFontFromData`]
167	#[doc(alias = "sys::ffi::playdate_graphics::makeFontFromData")]
168	#[inline(always)]
169	fn make_font_from_data(&self) -> unsafe extern "C" fn(data: *mut LCDFontData, wide: c_int) -> *mut LCDFont {
170		self.0.makeFontFromData.expect("makeFontFromData")
171	}
172
173	/// Equivalent to [`sys::ffi::playdate_graphics::setTextLeading`]
174	#[doc(alias = "sys::ffi::playdate_graphics::setTextLeading")]
175	#[inline(always)]
176	fn set_text_leading(&self) -> unsafe extern "C" fn(lineHeightAdjustment: c_int) {
177		self.0.setTextLeading.expect("setTextLeading")
178	}
179}
180
181
182impl crate::bitmap::table::api::Api for Cache {
183	#[inline(always)]
184	fn new_bitmap_table(
185		&self)
186		-> unsafe extern "C" fn(count: c_int, width: c_int, height: c_int) -> *mut LCDBitmapTable {
187		self.0.newBitmapTable.expect("newBitmapTable")
188	}
189
190	#[inline(always)]
191	fn free_bitmap_table(&self) -> unsafe extern "C" fn(table: *mut LCDBitmapTable) {
192		self.0.freeBitmapTable.expect("freeBitmapTable")
193	}
194
195	#[inline(always)]
196	fn load_bitmap_table(
197		&self)
198		-> unsafe extern "C" fn(path: *const c_char, out_err: *mut *const c_char) -> *mut LCDBitmapTable {
199		self.0.loadBitmapTable.expect("loadBitmapTable")
200	}
201
202	#[inline(always)]
203	fn load_into_bitmap_table(
204		&self)
205		-> unsafe extern "C" fn(path: *const c_char, table: *mut LCDBitmapTable, out_err: *mut *const c_char) {
206		self.0.loadIntoBitmapTable.expect("loadIntoBitmapTable")
207	}
208
209	#[inline(always)]
210	fn get_table_bitmap(&self) -> unsafe extern "C" fn(table: *mut LCDBitmapTable, idx: c_int) -> *mut LCDBitmap {
211		self.0.getTableBitmap.expect("getTableBitmap")
212	}
213}
214
215
216impl crate::bitmap::api::Api for Cache {
217	#[inline(always)]
218	fn new_bitmap(&self)
219	              -> unsafe extern "C" fn(width: c_int, height: c_int, bgcolor: LCDColor) -> *mut LCDBitmap {
220		self.0.newBitmap.expect("newBitmap")
221	}
222
223	#[inline(always)]
224	fn free_bitmap(&self) -> unsafe extern "C" fn(bitmap: *mut LCDBitmap) {
225		self.0.freeBitmap.expect("freeBitmap")
226	}
227
228	#[inline(always)]
229	fn load_bitmap(&self)
230	               -> unsafe extern "C" fn(path: *const c_char, outerr: *mut *const c_char) -> *mut LCDBitmap {
231		self.0.loadBitmap.expect("loadBitmap")
232	}
233
234	#[inline(always)]
235	fn copy_bitmap(&self) -> unsafe extern "C" fn(bitmap: *mut LCDBitmap) -> *mut LCDBitmap {
236		self.0.copyBitmap.expect("copyBitmap")
237	}
238
239	#[inline(always)]
240	fn load_into_bitmap(
241		&self)
242		-> unsafe extern "C" fn(path: *const c_char, bitmap: *mut LCDBitmap, out_err: *mut *const c_char) {
243		self.0.loadIntoBitmap.expect("loadIntoBitmap")
244	}
245
246	#[inline(always)]
247	fn get_bitmap_data(
248		&self)
249		-> unsafe extern "C" fn(bitmap: *mut LCDBitmap,
250		                        width: *mut c_int,
251		                        height: *mut c_int,
252		                        row_bytes: *mut c_int,
253		                        mask: *mut *mut u8,
254		                        data: *mut *mut u8) {
255		self.0.getBitmapData.expect("getBitmapData")
256	}
257
258	#[inline(always)]
259	fn clear_bitmap(&self) -> unsafe extern "C" fn(bitmap: *mut LCDBitmap, bgcolor: LCDColor) {
260		self.0.clearBitmap.expect("clearBitmap")
261	}
262
263	#[inline(always)]
264	fn rotated_bitmap(
265		&self)
266		-> unsafe extern "C" fn(bitmap: *mut LCDBitmap,
267		                        rotation: c_float,
268		                        x_scale: c_float,
269		                        y_scale: c_float,
270		                        allocedSize: *mut c_int) -> *mut LCDBitmap {
271		self.0.rotatedBitmap.expect("rotatedBitmap")
272	}
273
274	#[inline(always)]
275	fn set_bitmap_mask(&self) -> unsafe extern "C" fn(bitmap: *mut LCDBitmap, mask: *mut LCDBitmap) -> c_int {
276		self.0.setBitmapMask.expect("setBitmapMask")
277	}
278
279	#[inline(always)]
280	fn get_bitmap_mask(&self) -> unsafe extern "C" fn(bitmap: *mut LCDBitmap) -> *mut LCDBitmap {
281		self.0.getBitmapMask.expect("getBitmapMask")
282	}
283
284	#[inline(always)]
285	fn draw_bitmap(&self)
286	               -> unsafe extern "C" fn(bitmap: *mut LCDBitmap, x: c_int, y: c_int, flip: LCDBitmapFlip) {
287		self.0.drawBitmap.expect("drawBitmap")
288	}
289
290	#[inline(always)]
291	fn tile_bitmap(
292		&self)
293		-> unsafe extern "C" fn(bitmap: *mut LCDBitmap,
294		                        x: c_int,
295		                        y: c_int,
296		                        width: c_int,
297		                        height: c_int,
298		                        flip: LCDBitmapFlip) {
299		self.0.tileBitmap.expect("tileBitmap")
300	}
301
302	#[inline(always)]
303	fn draw_rotated_bitmap(
304		&self)
305		-> unsafe extern "C" fn(bitmap: *mut LCDBitmap,
306		                        x: c_int,
307		                        y: c_int,
308		                        rotation: c_float,
309		                        center_x: c_float,
310		                        center_y: c_float,
311		                        x_scale: c_float,
312		                        y_scale: c_float) {
313		self.0.drawRotatedBitmap.expect("drawRotatedBitmap")
314	}
315
316	#[inline(always)]
317	fn draw_scaled_bitmap(
318		&self)
319		-> unsafe extern "C" fn(bitmap: *mut LCDBitmap, x: c_int, y: c_int, x_scale: c_float, y_scale: c_float) {
320		self.0.drawScaledBitmap.expect("drawScaledBitmap")
321	}
322
323	#[inline(always)]
324	fn check_mask_collision(
325		&self)
326		-> unsafe extern "C" fn(bitmap1: *mut LCDBitmap,
327		                        x1: c_int,
328		                        y1: c_int,
329		                        flip1: LCDBitmapFlip,
330		                        bitmap2: *mut LCDBitmap,
331		                        x2: c_int,
332		                        y2: c_int,
333		                        flip2: LCDBitmapFlip,
334		                        rect: LCDRect) -> c_int {
335		self.0.checkMaskCollision.expect("checkMaskCollision")
336	}
337
338	#[inline(always)]
339	fn set_color_to_pattern(
340		&self)
341		-> unsafe extern "C" fn(color: *mut LCDColor,
342		                        bitmap: *mut LCDBitmap,
343		                        x: core::ffi::c_int,
344		                        y: core::ffi::c_int) {
345		self.0.setColorToPattern.expect("setColorToPattern")
346	}
347}
348
349
350impl Api for Cache {
351	/// Equivalent to [`sys::ffi::playdate_graphics::video`]
352	#[doc(alias = "sys::ffi::playdate_graphics::video")]
353	#[inline(always)]
354	fn video<VApi: crate::video::api::Api + From<*const playdate_video>>(&self) -> VApi {
355		VApi::from(self.0.video)
356	}
357
358	/// Equivalent to [`sys::ffi::playdate_graphics::clear`]
359	#[doc(alias = "sys::ffi::playdate_graphics::clear")]
360	#[inline(always)]
361	fn clear(&self) -> unsafe extern "C" fn(color: LCDColor) { self.0.clear.expect("clear") }
362
363	/// Equivalent to [`sys::ffi::playdate_graphics::setBackgroundColor`]
364	#[doc(alias = "sys::ffi::playdate_graphics::setBackgroundColor")]
365	#[inline(always)]
366	fn set_background_color(&self) -> unsafe extern "C" fn(color: LCDSolidColor) {
367		self.0.setBackgroundColor.expect("setBackgroundColor")
368	}
369
370	/// Equivalent to [`sys::ffi::playdate_graphics::setStencil`]
371	#[doc(alias = "sys::ffi::playdate_graphics::setStencil")]
372	#[inline(always)]
373	fn set_stencil(&self) -> unsafe extern "C" fn(stencil: *mut LCDBitmap) {
374		self.0.setStencil.expect("setStencil")
375	}
376
377	/// Equivalent to [`sys::ffi::playdate_graphics::setDrawMode`]
378	#[doc(alias = "sys::ffi::playdate_graphics::setDrawMode")]
379	#[inline(always)]
380	fn set_draw_mode(&self) -> unsafe extern "C" fn(mode: LCDBitmapDrawMode) -> LCDBitmapDrawMode {
381		self.0.setDrawMode.expect("setDrawMode")
382	}
383
384	/// Equivalent to [`sys::ffi::playdate_graphics::setDrawOffset`]
385	#[doc(alias = "sys::ffi::playdate_graphics::setDrawOffset")]
386	#[inline(always)]
387	fn set_draw_offset(&self) -> unsafe extern "C" fn(dx: c_int, dy: c_int) {
388		self.0.setDrawOffset.expect("setDrawOffset")
389	}
390
391	/// Equivalent to [`sys::ffi::playdate_graphics::setClipRect`]
392	#[doc(alias = "sys::ffi::playdate_graphics::setClipRect")]
393	#[inline(always)]
394	fn set_clip_rect(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int) {
395		self.0.setClipRect.expect("setClipRect")
396	}
397
398	/// Equivalent to [`sys::ffi::playdate_graphics::clearClipRect`]
399	#[doc(alias = "sys::ffi::playdate_graphics::clearClipRect")]
400	#[inline(always)]
401	fn clear_clip_rect(&self) -> unsafe extern "C" fn() { self.0.clearClipRect.expect("clearClipRect") }
402
403	/// Equivalent to [`sys::ffi::playdate_graphics::setLineCapStyle`]
404	#[doc(alias = "sys::ffi::playdate_graphics::setLineCapStyle")]
405	#[inline(always)]
406	fn set_line_cap_style(&self) -> unsafe extern "C" fn(endCapStyle: LCDLineCapStyle) {
407		self.0.setLineCapStyle.expect("setLineCapStyle")
408	}
409
410	/// Equivalent to [`sys::ffi::playdate_graphics::pushContext`]
411	#[doc(alias = "sys::ffi::playdate_graphics::pushContext")]
412	#[inline(always)]
413	fn push_context(&self) -> unsafe extern "C" fn(target: *mut LCDBitmap) {
414		self.0.pushContext.expect("pushContext")
415	}
416
417	/// Equivalent to [`sys::ffi::playdate_graphics::popContext`]
418	#[doc(alias = "sys::ffi::playdate_graphics::popContext")]
419	#[inline(always)]
420	fn pop_context(&self) -> unsafe extern "C" fn() { self.0.popContext.expect("popContext") }
421
422	/// Equivalent to [`sys::ffi::playdate_graphics::drawLine`]
423	#[doc(alias = "sys::ffi::playdate_graphics::drawLine")]
424	#[inline(always)]
425	fn draw_line(
426		&self)
427		-> unsafe extern "C" fn(x1: c_int, y1: c_int, x2: c_int, y2: c_int, width: c_int, color: LCDColor) {
428		self.0.drawLine.expect("drawLine")
429	}
430
431	/// Equivalent to [`sys::ffi::playdate_graphics::fillTriangle`]
432	#[doc(alias = "sys::ffi::playdate_graphics::fillTriangle")]
433	#[inline(always)]
434	fn fill_triangle(
435		&self)
436		-> unsafe extern "C" fn(x1: c_int, y1: c_int, x2: c_int, y2: c_int, x3: c_int, y3: c_int, color: LCDColor) {
437		self.0.fillTriangle.expect("fillTriangle")
438	}
439
440	/// Equivalent to [`sys::ffi::playdate_graphics::drawRect`]
441	#[doc(alias = "sys::ffi::playdate_graphics::drawRect")]
442	#[inline(always)]
443	fn draw_rect(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int, color: LCDColor) {
444		self.0.drawRect.expect("drawRect")
445	}
446
447	/// Equivalent to [`sys::ffi::playdate_graphics::fillRect`]
448	#[doc(alias = "sys::ffi::playdate_graphics::fillRect")]
449	#[inline(always)]
450	fn fill_rect(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int, color: LCDColor) {
451		self.0.fillRect.expect("fillRect")
452	}
453
454	/// Equivalent to [`sys::ffi::playdate_graphics::drawEllipse`]
455	#[doc(alias = "sys::ffi::playdate_graphics::drawEllipse")]
456	#[inline(always)]
457	fn draw_ellipse(
458		&self)
459		-> unsafe extern "C" fn(x: c_int,
460		                        y: c_int,
461		                        width: c_int,
462		                        height: c_int,
463		                        lineWidth: c_int,
464		                        startAngle: c_float,
465		                        endAngle: c_float,
466		                        color: LCDColor) {
467		self.0.drawEllipse.expect("drawEllipse")
468	}
469
470	/// Equivalent to [`sys::ffi::playdate_graphics::fillEllipse`]
471	#[doc(alias = "sys::ffi::playdate_graphics::fillEllipse")]
472	#[inline(always)]
473	fn fill_ellipse(
474		&self)
475		-> unsafe extern "C" fn(x: c_int,
476		                        y: c_int,
477		                        width: c_int,
478		                        height: c_int,
479		                        startAngle: c_float,
480		                        endAngle: c_float,
481		                        color: LCDColor) {
482		self.0.fillEllipse.expect("fillEllipse")
483	}
484
485	/// Equivalent to [`sys::ffi::playdate_graphics::setPixel`]
486	#[doc(alias = "sys::ffi::playdate_graphics::setPixel")]
487	#[inline(always)]
488	fn set_pixel(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, c: LCDColor) {
489		self.0.setPixel.expect("setPixel")
490	}
491
492	/// Equivalent to [`sys::ffi::playdate_graphics::getFrame`]
493	#[doc(alias = "sys::ffi::playdate_graphics::getFrame")]
494	#[inline(always)]
495	fn get_frame(&self) -> unsafe extern "C" fn() -> *mut u8 { self.0.getFrame.expect("getFrame") }
496
497	/// Equivalent to [`sys::ffi::playdate_graphics::getDisplayFrame`]
498	#[doc(alias = "sys::ffi::playdate_graphics::getDisplayFrame")]
499	#[inline(always)]
500	fn get_display_frame(&self) -> unsafe extern "C" fn() -> *mut u8 {
501		self.0.getDisplayFrame.expect("getDisplayFrame")
502	}
503
504	/// Equivalent to [`sys::ffi::playdate_graphics::getDebugBitmap`]
505	#[doc(alias = "sys::ffi::playdate_graphics::getDebugBitmap")]
506	#[inline(always)]
507	fn get_debug_bitmap(&self) -> Option<unsafe extern "C" fn() -> *mut LCDBitmap> {
508		sys::api!(graphics).getDebugBitmap
509	}
510
511	/// Equivalent to [`sys::ffi::playdate_graphics::copyFrameBufferBitmap`]
512	#[doc(alias = "sys::ffi::playdate_graphics::copyFrameBufferBitmap")]
513	#[inline(always)]
514	fn copy_frame_buffer_bitmap(&self) -> unsafe extern "C" fn() -> *mut LCDBitmap {
515		self.0.copyFrameBufferBitmap.expect("copyFrameBufferBitmap")
516	}
517
518	/// Equivalent to [`sys::ffi::playdate_graphics::markUpdatedRows`]
519	#[doc(alias = "sys::ffi::playdate_graphics::markUpdatedRows")]
520	#[inline(always)]
521	fn mark_updated_rows(&self) -> unsafe extern "C" fn(start: c_int, end: c_int) {
522		self.0.markUpdatedRows.expect("markUpdatedRows")
523	}
524
525	/// Equivalent to [`sys::ffi::playdate_graphics::display`]
526	#[doc(alias = "sys::ffi::playdate_graphics::display")]
527	#[inline(always)]
528	fn display(&self) -> unsafe extern "C" fn() { self.0.display.expect("display") }
529
530	/// Equivalent to [`sys::ffi::playdate_graphics::setScreenClipRect`]
531	#[doc(alias = "sys::ffi::playdate_graphics::setScreenClipRect")]
532	#[inline(always)]
533	fn set_screen_clip_rect(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int) {
534		self.0.setScreenClipRect.expect("setScreenClipRect")
535	}
536
537	/// Equivalent to [`sys::ffi::playdate_graphics::fillPolygon`]
538	#[doc(alias = "sys::ffi::playdate_graphics::fillPolygon")]
539	#[inline(always)]
540	fn fill_polygon(
541		&self)
542		-> unsafe extern "C" fn(nPoints: c_int, coords: *mut c_int, color: LCDColor, fillrule: LCDPolygonFillRule) {
543		self.0.fillPolygon.expect("fillPolygon")
544	}
545
546	/// Equivalent to [`sys::ffi::playdate_graphics::getDisplayBufferBitmap`]
547	#[doc(alias = "sys::ffi::playdate_graphics::getDisplayBufferBitmap")]
548	#[inline(always)]
549	fn get_display_buffer_bitmap(&self) -> unsafe extern "C" fn() -> *mut LCDBitmap {
550		self.0.getDisplayBufferBitmap.expect("getDisplayBufferBitmap")
551	}
552
553	/// Equivalent to [`sys::ffi::playdate_graphics::setStencilImage`]
554	#[doc(alias = "sys::ffi::playdate_graphics::setStencilImage")]
555	#[inline(always)]
556	fn set_stencil_image(&self) -> unsafe extern "C" fn(stencil: *mut LCDBitmap, tile: c_int) {
557		self.0.setStencilImage.expect("setStencilImage")
558	}
559}
560
561
562pub trait Api: crate::bitmap::api::Api + crate::bitmap::table::api::Api + crate::text::api::Api {
563	/// Equivalent to [`sys::ffi::playdate_graphics::video`]
564	#[doc(alias = "sys::ffi::playdate_graphics::video")]
565	fn video<VApi>(&self) -> VApi
566		where VApi: From<*const playdate_video> + crate::video::api::Api;
567
568	/// Equivalent to [`sys::ffi::playdate_graphics::clear`]
569	#[doc(alias = "sys::ffi::playdate_graphics::clear")]
570	#[inline(always)]
571	fn clear(&self) -> unsafe extern "C" fn(color: LCDColor) { *sys::api!(graphics.clear) }
572
573	/// Equivalent to [`sys::ffi::playdate_graphics::setBackgroundColor`]
574	#[doc(alias = "sys::ffi::playdate_graphics::setBackgroundColor")]
575	#[inline(always)]
576	fn set_background_color(&self) -> unsafe extern "C" fn(color: LCDSolidColor) {
577		*sys::api!(graphics.setBackgroundColor)
578	}
579
580	/// Equivalent to [`sys::ffi::playdate_graphics::setStencil`]
581	#[doc(alias = "sys::ffi::playdate_graphics::setStencil")]
582	#[inline(always)]
583	fn set_stencil(&self) -> unsafe extern "C" fn(stencil: *mut LCDBitmap) { *sys::api!(graphics.setStencil) }
584
585	/// Equivalent to [`sys::ffi::playdate_graphics::setDrawMode`]
586	#[doc(alias = "sys::ffi::playdate_graphics::setDrawMode")]
587	#[inline(always)]
588	fn set_draw_mode(&self) -> unsafe extern "C" fn(mode: LCDBitmapDrawMode) -> LCDBitmapDrawMode {
589		*sys::api!(graphics.setDrawMode)
590	}
591
592	/// Equivalent to [`sys::ffi::playdate_graphics::setDrawOffset`]
593	#[doc(alias = "sys::ffi::playdate_graphics::setDrawOffset")]
594	#[inline(always)]
595	fn set_draw_offset(&self) -> unsafe extern "C" fn(dx: c_int, dy: c_int) { *sys::api!(graphics.setDrawOffset) }
596
597	/// Equivalent to [`sys::ffi::playdate_graphics::setClipRect`]
598	#[doc(alias = "sys::ffi::playdate_graphics::setClipRect")]
599	#[inline(always)]
600	fn set_clip_rect(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int) {
601		*sys::api!(graphics.setClipRect)
602	}
603
604	/// Equivalent to [`sys::ffi::playdate_graphics::clearClipRect`]
605	#[doc(alias = "sys::ffi::playdate_graphics::clearClipRect")]
606	#[inline(always)]
607	fn clear_clip_rect(&self) -> unsafe extern "C" fn() { *sys::api!(graphics.clearClipRect) }
608
609	/// Equivalent to [`sys::ffi::playdate_graphics::setLineCapStyle`]
610	#[doc(alias = "sys::ffi::playdate_graphics::setLineCapStyle")]
611	#[inline(always)]
612	fn set_line_cap_style(&self) -> unsafe extern "C" fn(endCapStyle: LCDLineCapStyle) {
613		*sys::api!(graphics.setLineCapStyle)
614	}
615
616	/// Equivalent to [`sys::ffi::playdate_graphics::pushContext`]
617	#[doc(alias = "sys::ffi::playdate_graphics::pushContext")]
618	#[inline(always)]
619	fn push_context(&self) -> unsafe extern "C" fn(target: *mut LCDBitmap) { *sys::api!(graphics.pushContext) }
620
621	/// Equivalent to [`sys::ffi::playdate_graphics::popContext`]
622	#[doc(alias = "sys::ffi::playdate_graphics::popContext")]
623	#[inline(always)]
624	fn pop_context(&self) -> unsafe extern "C" fn() { *sys::api!(graphics.popContext) }
625
626	/// Equivalent to [`sys::ffi::playdate_graphics::drawLine`]
627	#[doc(alias = "sys::ffi::playdate_graphics::drawLine")]
628	#[inline(always)]
629	fn draw_line(
630		&self)
631		-> unsafe extern "C" fn(x1: c_int, y1: c_int, x2: c_int, y2: c_int, width: c_int, color: LCDColor) {
632		*sys::api!(graphics.drawLine)
633	}
634
635	/// Equivalent to [`sys::ffi::playdate_graphics::fillTriangle`]
636	#[doc(alias = "sys::ffi::playdate_graphics::fillTriangle")]
637	#[inline(always)]
638	fn fill_triangle(
639		&self)
640		-> unsafe extern "C" fn(x1: c_int, y1: c_int, x2: c_int, y2: c_int, x3: c_int, y3: c_int, color: LCDColor) {
641		*sys::api!(graphics.fillTriangle)
642	}
643
644	/// Equivalent to [`sys::ffi::playdate_graphics::drawRect`]
645	#[doc(alias = "sys::ffi::playdate_graphics::drawRect")]
646	#[inline(always)]
647	fn draw_rect(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int, color: LCDColor) {
648		*sys::api!(graphics.drawRect)
649	}
650
651	/// Equivalent to [`sys::ffi::playdate_graphics::fillRect`]
652	#[doc(alias = "sys::ffi::playdate_graphics::fillRect")]
653	#[inline(always)]
654	fn fill_rect(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int, color: LCDColor) {
655		*sys::api!(graphics.fillRect)
656	}
657
658	/// Equivalent to [`sys::ffi::playdate_graphics::drawEllipse`]
659	#[doc(alias = "sys::ffi::playdate_graphics::drawEllipse")]
660	#[inline(always)]
661	fn draw_ellipse(
662		&self)
663		-> unsafe extern "C" fn(x: c_int,
664		                        y: c_int,
665		                        width: c_int,
666		                        height: c_int,
667		                        lineWidth: c_int,
668		                        startAngle: c_float,
669		                        endAngle: c_float,
670		                        color: LCDColor) {
671		*sys::api!(graphics.drawEllipse)
672	}
673
674	/// Equivalent to [`sys::ffi::playdate_graphics::fillEllipse`]
675	#[doc(alias = "sys::ffi::playdate_graphics::fillEllipse")]
676	#[inline(always)]
677	fn fill_ellipse(
678		&self)
679		-> unsafe extern "C" fn(x: c_int,
680		                        y: c_int,
681		                        width: c_int,
682		                        height: c_int,
683		                        startAngle: c_float,
684		                        endAngle: c_float,
685		                        color: LCDColor) {
686		*sys::api!(graphics.fillEllipse)
687	}
688
689	/// Equivalent to [`sys::ffi::playdate_graphics::setPixel`]
690	#[doc(alias = "sys::ffi::playdate_graphics::setPixel")]
691	#[inline(always)]
692	fn set_pixel(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, c: LCDColor) { *sys::api!(graphics.setPixel) }
693
694	/// Equivalent to [`sys::ffi::playdate_graphics::getFrame`]
695	#[doc(alias = "sys::ffi::playdate_graphics::getFrame")]
696	#[inline(always)]
697	fn get_frame(&self) -> unsafe extern "C" fn() -> *mut u8 { *sys::api!(graphics.getFrame) }
698
699	/// Equivalent to [`sys::ffi::playdate_graphics::getDisplayFrame`]
700	#[doc(alias = "sys::ffi::playdate_graphics::getDisplayFrame")]
701	#[inline(always)]
702	fn get_display_frame(&self) -> unsafe extern "C" fn() -> *mut u8 { *sys::api!(graphics.getDisplayFrame) }
703
704	/// Equivalent to [`sys::ffi::playdate_graphics::getDebugBitmap`]
705	#[doc(alias = "sys::ffi::playdate_graphics::getDebugBitmap")]
706	#[inline(always)]
707	fn get_debug_bitmap(&self) -> Option<unsafe extern "C" fn() -> *mut LCDBitmap> {
708		sys::api!(graphics).getDebugBitmap
709	}
710
711	/// Equivalent to [`sys::ffi::playdate_graphics::copyFrameBufferBitmap`]
712	#[doc(alias = "sys::ffi::playdate_graphics::copyFrameBufferBitmap")]
713	#[inline(always)]
714	fn copy_frame_buffer_bitmap(&self) -> unsafe extern "C" fn() -> *mut LCDBitmap {
715		*sys::api!(graphics.copyFrameBufferBitmap)
716	}
717
718	/// Equivalent to [`sys::ffi::playdate_graphics::markUpdatedRows`]
719	#[doc(alias = "sys::ffi::playdate_graphics::markUpdatedRows")]
720	#[inline(always)]
721	fn mark_updated_rows(&self) -> unsafe extern "C" fn(start: c_int, end: c_int) {
722		*sys::api!(graphics.markUpdatedRows)
723	}
724
725	/// Equivalent to [`sys::ffi::playdate_graphics::display`]
726	#[doc(alias = "sys::ffi::playdate_graphics::display")]
727	#[inline(always)]
728	fn display(&self) -> unsafe extern "C" fn() { *sys::api!(graphics.display) }
729
730	/// Equivalent to [`sys::ffi::playdate_graphics::setScreenClipRect`]
731	#[doc(alias = "sys::ffi::playdate_graphics::setScreenClipRect")]
732	#[inline(always)]
733	fn set_screen_clip_rect(&self) -> unsafe extern "C" fn(x: c_int, y: c_int, width: c_int, height: c_int) {
734		*sys::api!(graphics.setScreenClipRect)
735	}
736
737	/// Equivalent to [`sys::ffi::playdate_graphics::fillPolygon`]
738	#[doc(alias = "sys::ffi::playdate_graphics::fillPolygon")]
739	#[inline(always)]
740	fn fill_polygon(
741		&self)
742		-> unsafe extern "C" fn(nPoints: c_int, coords: *mut c_int, color: LCDColor, fillrule: LCDPolygonFillRule) {
743		*sys::api!(graphics.fillPolygon)
744	}
745
746	/// Equivalent to [`sys::ffi::playdate_graphics::getDisplayBufferBitmap`]
747	#[doc(alias = "sys::ffi::playdate_graphics::getDisplayBufferBitmap")]
748	#[inline(always)]
749	fn get_display_buffer_bitmap(&self) -> unsafe extern "C" fn() -> *mut LCDBitmap {
750		*sys::api!(graphics.getDisplayBufferBitmap)
751	}
752
753	/// Equivalent to [`sys::ffi::playdate_graphics::setStencilImage`]
754	#[doc(alias = "sys::ffi::playdate_graphics::setStencilImage")]
755	#[inline(always)]
756	fn set_stencil_image(&self) -> unsafe extern "C" fn(stencil: *mut LCDBitmap, tile: c_int) {
757		*sys::api!(graphics.setStencilImage)
758	}
759}