sokol: type alias all `sapp` structs (#12962)
parent
04be2465dc
commit
2210f89ea3
|
@ -16,7 +16,7 @@ fn main() {
|
|||
pass_action: gfx.create_clear_pass(0.1, 0.1, 0.1, 1.0)
|
||||
}
|
||||
title := 'Sokol Drawing Template'
|
||||
desc := C.sapp_desc{
|
||||
desc := sapp.Desc{
|
||||
user_data: state
|
||||
init_userdata_cb: init
|
||||
frame_userdata_cb: frame
|
||||
|
|
|
@ -31,7 +31,7 @@ fn main() {
|
|||
fons: voidptr(0) // &fontstash.Context(0)
|
||||
}
|
||||
title := 'V Metal/GL Text Rendering'
|
||||
desc := C.sapp_desc{
|
||||
desc := sapp.Desc{
|
||||
user_data: state
|
||||
init_userdata_cb: init
|
||||
frame_userdata_cb: frame
|
||||
|
|
|
@ -79,7 +79,7 @@ fn main() {
|
|||
fons: voidptr(0) // &fontstash.Context(0)
|
||||
}
|
||||
title := 'V Metal/GL Text Rendering'
|
||||
desc := C.sapp_desc{
|
||||
desc := sapp.Desc{
|
||||
user_data: state
|
||||
init_userdata_cb: init
|
||||
frame_userdata_cb: frame
|
||||
|
|
|
@ -52,7 +52,7 @@ fn (mut a App) cleanup() {
|
|||
|
||||
fn (mut a App) run() {
|
||||
title := 'V Particle Example'
|
||||
desc := C.sapp_desc{
|
||||
desc := sapp.Desc{
|
||||
width: a.width
|
||||
height: a.height
|
||||
user_data: a
|
||||
|
@ -117,7 +117,7 @@ fn frame(user_data voidptr) {
|
|||
app.last = t
|
||||
}
|
||||
|
||||
fn event(ev &C.sapp_event, mut app App) {
|
||||
fn event(ev &sapp.Event, mut app App) {
|
||||
if ev.@type == .mouse_move {
|
||||
app.ps.explode(ev.mouse_x, ev.mouse_y)
|
||||
}
|
||||
|
|
|
@ -500,7 +500,7 @@ fn (mut game Game) key_down(key gg.KeyCode) {
|
|||
}
|
||||
}
|
||||
|
||||
fn (mut game Game) touch_event(touch_point C.sapp_touchpoint) {
|
||||
fn (mut game Game) touch_event(touch_point gg.TouchPoint) {
|
||||
ws := gg.window_size()
|
||||
tx := touch_point.pos_x
|
||||
ty := touch_point.pos_y
|
||||
|
|
|
@ -11,6 +11,8 @@ import sokol.sgl
|
|||
import sokol.gfx
|
||||
import math
|
||||
|
||||
pub type TouchPoint = C.sapp_touchpoint
|
||||
|
||||
pub struct Event {
|
||||
pub mut:
|
||||
frame_count u64
|
||||
|
@ -27,7 +29,7 @@ pub mut:
|
|||
scroll_x f32
|
||||
scroll_y f32
|
||||
num_touches int
|
||||
touches [8]C.sapp_touchpoint
|
||||
touches [8]TouchPoint
|
||||
window_width int
|
||||
window_height int
|
||||
framebuffer_width int
|
||||
|
@ -108,7 +110,7 @@ pub mut:
|
|||
width int
|
||||
height int
|
||||
clear_pass C.sg_pass_action
|
||||
window C.sapp_desc
|
||||
window sapp.Desc
|
||||
timage_pip C.sgl_pipeline
|
||||
config Config
|
||||
user_data voidptr
|
||||
|
@ -241,7 +243,7 @@ pub fn new_context(cfg Config) &Context {
|
|||
}
|
||||
g.set_bg_color(cfg.bg_color)
|
||||
// C.printf('new_context() %p\n', cfg.user_data)
|
||||
window := C.sapp_desc{
|
||||
window := sapp.Desc{
|
||||
user_data: g
|
||||
init_userdata_cb: gg_init_sokol_window
|
||||
frame_userdata_cb: gg_frame_fn
|
||||
|
|
|
@ -49,7 +49,7 @@ pub mut:
|
|||
scroll_y f32
|
||||
// todo(playX): add touches API support in js.dom
|
||||
// num_touches int
|
||||
// touches [8]C.sapp_touchpoint
|
||||
// touches [8]TouchPoint
|
||||
window_width int
|
||||
window_height int
|
||||
framebuffer_width int
|
||||
|
|
|
@ -102,7 +102,7 @@ pub fn userdata() voidptr {
|
|||
|
||||
// return a copy of the sapp_desc structure
|
||||
[inline]
|
||||
pub fn query_desc() C.sapp_desc {
|
||||
pub fn query_desc() Desc {
|
||||
return C.sapp_query_desc()
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ pub fn get_clipboard_string() &char {
|
|||
|
||||
// special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub)
|
||||
[inline]
|
||||
pub fn run(desc &C.sapp_desc) {
|
||||
pub fn run(desc &Desc) {
|
||||
g_desc = *desc
|
||||
C.sapp_run(desc)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ fn C.sapp_mouse_locked() bool
|
|||
fn C.sapp_userdata() voidptr
|
||||
|
||||
// return a copy of the sapp_desc structure
|
||||
fn C.sapp_query_desc() C.sapp_desc
|
||||
fn C.sapp_query_desc() Desc
|
||||
|
||||
// initiate a "soft quit" (sends SAPP_EVENTTYPE_QUIT_REQUESTED)
|
||||
fn C.sapp_request_quit()
|
||||
|
@ -63,7 +63,7 @@ fn C.sapp_set_clipboard_string(str &byte)
|
|||
fn C.sapp_get_clipboard_string() &byte
|
||||
|
||||
// special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub)
|
||||
fn C.sapp_run(desc &C.sapp_desc) int
|
||||
fn C.sapp_run(desc &Desc) int
|
||||
|
||||
// GL: return true when GLES2 fallback is active (to detect fallback from GLES3)
|
||||
fn C.sapp_gles2() bool
|
||||
|
|
|
@ -13,31 +13,37 @@ pub:
|
|||
size usize
|
||||
}
|
||||
|
||||
pub type Range = C.sapp_range
|
||||
|
||||
pub struct C.sapp_image_desc {
|
||||
pub:
|
||||
width int
|
||||
height int
|
||||
pixels C.spp_range
|
||||
pixels Range
|
||||
}
|
||||
|
||||
pub type ImageDesc = C.sapp_image_desc
|
||||
|
||||
pub struct C.sapp_icon_desc {
|
||||
sokol_default bool
|
||||
images [sapp_max_iconimages]C.sapp_image_desc
|
||||
images [sapp_max_iconimages]ImageDesc
|
||||
}
|
||||
|
||||
pub type IconDesc = C.sapp_icon_desc
|
||||
|
||||
pub struct C.sapp_desc {
|
||||
pub:
|
||||
init_cb fn () // these are the user-provided callbacks without user data
|
||||
frame_cb fn ()
|
||||
cleanup_cb fn ()
|
||||
event_cb fn (&C.sapp_event) //&sapp_event)
|
||||
event_cb fn (&Event) //&sapp_event)
|
||||
fail_cb fn (&byte)
|
||||
|
||||
user_data voidptr // these are the user-provided callbacks with user data
|
||||
init_userdata_cb fn (voidptr)
|
||||
frame_userdata_cb fn (voidptr)
|
||||
cleanup_userdata_cb fn (voidptr)
|
||||
event_userdata_cb fn (&C.sapp_event, voidptr)
|
||||
event_userdata_cb fn (&Event, voidptr)
|
||||
fail_userdata_cb fn (&char, voidptr)
|
||||
|
||||
width int // the preferred width of the window / canvas
|
||||
|
@ -54,7 +60,7 @@ pub:
|
|||
enable_dragndrop bool // enable file dropping (drag'n'drop), default is false
|
||||
max_dropped_files int // max number of dropped files to process (default: 1)
|
||||
max_dropped_file_path_length int // max length in bytes of a dropped UTF-8 file path (default: 2048)
|
||||
icon C.sapp_icon_desc
|
||||
icon IconDesc
|
||||
// backend-specific options
|
||||
gl_force_gles2 bool // if true, setup GLES2/WebGL even if GLES3/WebGL2 is available
|
||||
win32_console_utf8 bool // if true, set the output console codepage to UTF-8
|
||||
|
@ -70,28 +76,7 @@ pub:
|
|||
__v_native_render bool // V patch to allow for native rendering
|
||||
}
|
||||
|
||||
pub struct Event {
|
||||
pub:
|
||||
frame_count u64
|
||||
typ EventType
|
||||
key_code KeyCode
|
||||
char_code u32
|
||||
key_repeat bool
|
||||
modifiers u32
|
||||
mouse_button MouseButton
|
||||
mouse_x f32
|
||||
mouse_y f32
|
||||
mouse_dx f32
|
||||
mouse_dy f32
|
||||
scroll_x f32
|
||||
scroll_y f32
|
||||
num_touches int
|
||||
touches [sapp_max_touchpoints]C.sapp_touchpoint
|
||||
window_width int
|
||||
window_height int
|
||||
framebuffer_width int
|
||||
framebuffer_height int
|
||||
}
|
||||
pub type Desc = C.sapp_desc
|
||||
|
||||
pub struct C.sapp_event {
|
||||
pub:
|
||||
|
@ -109,13 +94,15 @@ pub:
|
|||
scroll_x f32
|
||||
scroll_y f32
|
||||
num_touches int
|
||||
touches [sapp_max_touchpoints]C.sapp_touchpoint
|
||||
touches [sapp_max_touchpoints]TouchPoint
|
||||
window_width int
|
||||
window_height int
|
||||
framebuffer_width int
|
||||
framebuffer_height int
|
||||
}
|
||||
|
||||
pub type Event = C.sapp_event
|
||||
|
||||
pub fn (e &C.sapp_event) str() string {
|
||||
t := e.@type
|
||||
return 'evt: frame_count=$e.frame_count, type=$t'
|
||||
|
@ -128,3 +115,5 @@ pub:
|
|||
pos_y f32
|
||||
changed bool
|
||||
}
|
||||
|
||||
pub type TouchPoint = C.sapp_touchpoint
|
||||
|
|
Loading…
Reference in New Issue