gg: rename some variables (for consistency) (#13280)
parent
0979723636
commit
867056dafb
190
vlib/gg/gg.c.v
190
vlib/gg/gg.c.v
|
@ -145,7 +145,7 @@ pub mut:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gg_init_sokol_window(user_data voidptr) {
|
fn gg_init_sokol_window(user_data voidptr) {
|
||||||
mut g := unsafe { &Context(user_data) }
|
mut ctx := unsafe { &Context(user_data) }
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
/*
|
/*
|
||||||
desc := gfx.Desc{
|
desc := gfx.Desc{
|
||||||
|
@ -161,47 +161,47 @@ fn gg_init_sokol_window(user_data voidptr) {
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := sgl.Desc{}
|
sgl_desc := sgl.Desc{}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
g.scale = dpi_scale()
|
ctx.scale = dpi_scale()
|
||||||
// is_high_dpi := sapp.high_dpi()
|
// is_high_dpi := sapp.high_dpi()
|
||||||
// fb_w := sapp.width()
|
// fb_w := sapp.width()
|
||||||
// fb_h := sapp.height()
|
// fb_h := sapp.height()
|
||||||
// println('g.scale=$g.scale is_high_dpi=$is_high_dpi fb_w=$fb_w fb_h=$fb_h')
|
// println('ctx.scale=$ctx.scale is_high_dpi=$is_high_dpi fb_w=$fb_w fb_h=$fb_h')
|
||||||
// if g.config.init_text {
|
// if ctx.config.init_text {
|
||||||
// `os.is_file()` won't work on Android if the font file is embedded into the APK
|
// `os.is_file()` won't work on Android if the font file is embedded into the APK
|
||||||
exists := $if !android { os.is_file(g.config.font_path) } $else { true }
|
exists := $if !android { os.is_file(ctx.config.font_path) } $else { true }
|
||||||
if g.config.font_path != '' && !exists {
|
if ctx.config.font_path != '' && !exists {
|
||||||
g.render_text = false
|
ctx.render_text = false
|
||||||
} else if g.config.font_path != '' && exists {
|
} else if ctx.config.font_path != '' && exists {
|
||||||
// t := time.ticks()
|
// t := time.ticks()
|
||||||
g.ft = new_ft(
|
ctx.ft = new_ft(
|
||||||
font_path: g.config.font_path
|
font_path: ctx.config.font_path
|
||||||
custom_bold_font_path: g.config.custom_bold_font_path
|
custom_bold_font_path: ctx.config.custom_bold_font_path
|
||||||
scale: dpi_scale()
|
scale: dpi_scale()
|
||||||
) or { panic(err) }
|
) or { panic(err) }
|
||||||
// println('FT took ${time.ticks()-t} ms')
|
// println('FT took ${time.ticks()-t} ms')
|
||||||
g.font_inited = true
|
ctx.font_inited = true
|
||||||
} else {
|
} else {
|
||||||
if g.config.font_bytes_normal.len > 0 {
|
if ctx.config.font_bytes_normal.len > 0 {
|
||||||
g.ft = new_ft(
|
ctx.ft = new_ft(
|
||||||
bytes_normal: g.config.font_bytes_normal
|
bytes_normal: ctx.config.font_bytes_normal
|
||||||
bytes_bold: g.config.font_bytes_bold
|
bytes_bold: ctx.config.font_bytes_bold
|
||||||
bytes_mono: g.config.font_bytes_mono
|
bytes_mono: ctx.config.font_bytes_mono
|
||||||
bytes_italic: g.config.font_bytes_italic
|
bytes_italic: ctx.config.font_bytes_italic
|
||||||
scale: sapp.dpi_scale()
|
scale: sapp.dpi_scale()
|
||||||
) or { panic(err) }
|
) or { panic(err) }
|
||||||
g.font_inited = true
|
ctx.font_inited = true
|
||||||
} else {
|
} else {
|
||||||
sfont := font.default()
|
sfont := font.default()
|
||||||
if g.config.font_path != '' {
|
if ctx.config.font_path != '' {
|
||||||
eprintln('font file "$g.config.font_path" does not exist, the system font ($sfont) was used instead.')
|
eprintln('font file "$ctx.config.font_path" does not exist, the system font ($sfont) was used instead.')
|
||||||
}
|
}
|
||||||
|
|
||||||
g.ft = new_ft(
|
ctx.ft = new_ft(
|
||||||
font_path: sfont
|
font_path: sfont
|
||||||
custom_bold_font_path: g.config.custom_bold_font_path
|
custom_bold_font_path: ctx.config.custom_bold_font_path
|
||||||
scale: sapp.dpi_scale()
|
scale: sapp.dpi_scale()
|
||||||
) or { panic(err) }
|
) or { panic(err) }
|
||||||
g.font_inited = true
|
ctx.font_inited = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -219,19 +219,19 @@ fn gg_init_sokol_window(user_data voidptr) {
|
||||||
}
|
}
|
||||||
pipdesc.colors[0] = color_state
|
pipdesc.colors[0] = color_state
|
||||||
|
|
||||||
g.timage_pip = sgl.make_pipeline(&pipdesc)
|
ctx.timage_pip = sgl.make_pipeline(&pipdesc)
|
||||||
//
|
//
|
||||||
if g.config.init_fn != voidptr(0) {
|
if ctx.config.init_fn != voidptr(0) {
|
||||||
g.config.init_fn(g.user_data)
|
ctx.config.init_fn(ctx.user_data)
|
||||||
}
|
}
|
||||||
// Create images now that we can do that after sg is inited
|
// Create images now that we can do that after sg is inited
|
||||||
if g.native_rendering {
|
if ctx.native_rendering {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0 .. g.image_cache.len {
|
for i in 0 .. ctx.image_cache.len {
|
||||||
if g.image_cache[i].simg.id == 0 {
|
if ctx.image_cache[i].simg.id == 0 {
|
||||||
g.image_cache[i].init_sokol_image()
|
ctx.image_cache[i].init_sokol_image()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,105 +262,105 @@ fn gg_frame_fn(user_data voidptr) {
|
||||||
fn gg_event_fn(ce voidptr, user_data voidptr) {
|
fn gg_event_fn(ce voidptr, user_data voidptr) {
|
||||||
// e := unsafe { &sapp.Event(ce) }
|
// e := unsafe { &sapp.Event(ce) }
|
||||||
mut e := unsafe { &Event(ce) }
|
mut e := unsafe { &Event(ce) }
|
||||||
mut g := unsafe { &Context(user_data) }
|
mut ctx := unsafe { &Context(user_data) }
|
||||||
if g.ui_mode {
|
if ctx.ui_mode {
|
||||||
g.refresh_ui()
|
ctx.refresh_ui()
|
||||||
}
|
}
|
||||||
if e.typ == .mouse_down {
|
if e.typ == .mouse_down {
|
||||||
bitplace := int(e.mouse_button)
|
bitplace := int(e.mouse_button)
|
||||||
g.mbtn_mask |= byte(1 << bitplace)
|
ctx.mbtn_mask |= byte(1 << bitplace)
|
||||||
g.mouse_buttons = MouseButtons(g.mbtn_mask)
|
ctx.mouse_buttons = MouseButtons(ctx.mbtn_mask)
|
||||||
}
|
}
|
||||||
if e.typ == .mouse_up {
|
if e.typ == .mouse_up {
|
||||||
bitplace := int(e.mouse_button)
|
bitplace := int(e.mouse_button)
|
||||||
g.mbtn_mask &= ~(byte(1 << bitplace))
|
ctx.mbtn_mask &= ~(byte(1 << bitplace))
|
||||||
g.mouse_buttons = MouseButtons(g.mbtn_mask)
|
ctx.mouse_buttons = MouseButtons(ctx.mbtn_mask)
|
||||||
}
|
}
|
||||||
if e.typ == .mouse_move && e.mouse_button == .invalid {
|
if e.typ == .mouse_move && e.mouse_button == .invalid {
|
||||||
if g.mbtn_mask & 0x01 > 0 {
|
if ctx.mbtn_mask & 0x01 > 0 {
|
||||||
e.mouse_button = .left
|
e.mouse_button = .left
|
||||||
}
|
}
|
||||||
if g.mbtn_mask & 0x02 > 0 {
|
if ctx.mbtn_mask & 0x02 > 0 {
|
||||||
e.mouse_button = .right
|
e.mouse_button = .right
|
||||||
}
|
}
|
||||||
if g.mbtn_mask & 0x04 > 0 {
|
if ctx.mbtn_mask & 0x04 > 0 {
|
||||||
e.mouse_button = .middle
|
e.mouse_button = .middle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.mouse_pos_x = int(e.mouse_x / g.scale)
|
ctx.mouse_pos_x = int(e.mouse_x / ctx.scale)
|
||||||
g.mouse_pos_y = int(e.mouse_y / g.scale)
|
ctx.mouse_pos_y = int(e.mouse_y / ctx.scale)
|
||||||
g.mouse_dx = int(e.mouse_dx / g.scale)
|
ctx.mouse_dx = int(e.mouse_dx / ctx.scale)
|
||||||
g.mouse_dy = int(e.mouse_dy / g.scale)
|
ctx.mouse_dy = int(e.mouse_dy / ctx.scale)
|
||||||
g.scroll_x = int(e.scroll_x / g.scale)
|
ctx.scroll_x = int(e.scroll_x / ctx.scale)
|
||||||
g.scroll_y = int(e.scroll_y / g.scale)
|
ctx.scroll_y = int(e.scroll_y / ctx.scale)
|
||||||
g.key_modifiers = Modifier(e.modifiers)
|
ctx.key_modifiers = Modifier(e.modifiers)
|
||||||
g.key_repeat = e.key_repeat
|
ctx.key_repeat = e.key_repeat
|
||||||
if e.typ in [.key_down, .key_up] {
|
if e.typ in [.key_down, .key_up] {
|
||||||
key_idx := int(e.key_code) % key_code_max
|
key_idx := int(e.key_code) % key_code_max
|
||||||
prev := g.pressed_keys[key_idx]
|
prev := ctx.pressed_keys[key_idx]
|
||||||
next := e.typ == .key_down
|
next := e.typ == .key_down
|
||||||
g.pressed_keys[key_idx] = next
|
ctx.pressed_keys[key_idx] = next
|
||||||
g.pressed_keys_edge[key_idx] = prev != next
|
ctx.pressed_keys_edge[key_idx] = prev != next
|
||||||
}
|
}
|
||||||
if g.config.event_fn != voidptr(0) {
|
if ctx.config.event_fn != voidptr(0) {
|
||||||
g.config.event_fn(e, g.config.user_data)
|
ctx.config.event_fn(e, ctx.config.user_data)
|
||||||
}
|
}
|
||||||
match e.typ {
|
match e.typ {
|
||||||
.mouse_move {
|
.mouse_move {
|
||||||
if g.config.move_fn != voidptr(0) {
|
if ctx.config.move_fn != voidptr(0) {
|
||||||
g.config.move_fn(e.mouse_x / g.scale, e.mouse_y / g.scale, g.config.user_data)
|
ctx.config.move_fn(e.mouse_x / ctx.scale, e.mouse_y / ctx.scale, ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mouse_down {
|
.mouse_down {
|
||||||
if g.config.click_fn != voidptr(0) {
|
if ctx.config.click_fn != voidptr(0) {
|
||||||
g.config.click_fn(e.mouse_x / g.scale, e.mouse_y / g.scale, e.mouse_button,
|
ctx.config.click_fn(e.mouse_x / ctx.scale, e.mouse_y / ctx.scale, e.mouse_button,
|
||||||
g.config.user_data)
|
ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mouse_up {
|
.mouse_up {
|
||||||
if g.config.unclick_fn != voidptr(0) {
|
if ctx.config.unclick_fn != voidptr(0) {
|
||||||
g.config.unclick_fn(e.mouse_x / g.scale, e.mouse_y / g.scale, e.mouse_button,
|
ctx.config.unclick_fn(e.mouse_x / ctx.scale, e.mouse_y / ctx.scale, e.mouse_button,
|
||||||
g.config.user_data)
|
ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mouse_leave {
|
.mouse_leave {
|
||||||
if g.config.leave_fn != voidptr(0) {
|
if ctx.config.leave_fn != voidptr(0) {
|
||||||
g.config.leave_fn(e, g.config.user_data)
|
ctx.config.leave_fn(e, ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mouse_enter {
|
.mouse_enter {
|
||||||
if g.config.enter_fn != voidptr(0) {
|
if ctx.config.enter_fn != voidptr(0) {
|
||||||
g.config.enter_fn(e, g.config.user_data)
|
ctx.config.enter_fn(e, ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mouse_scroll {
|
.mouse_scroll {
|
||||||
if g.config.scroll_fn != voidptr(0) {
|
if ctx.config.scroll_fn != voidptr(0) {
|
||||||
g.config.scroll_fn(e, g.config.user_data)
|
ctx.config.scroll_fn(e, ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.key_down {
|
.key_down {
|
||||||
if g.config.keydown_fn != voidptr(0) {
|
if ctx.config.keydown_fn != voidptr(0) {
|
||||||
g.config.keydown_fn(e.key_code, Modifier(e.modifiers), g.config.user_data)
|
ctx.config.keydown_fn(e.key_code, Modifier(e.modifiers), ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.key_up {
|
.key_up {
|
||||||
if g.config.keyup_fn != voidptr(0) {
|
if ctx.config.keyup_fn != voidptr(0) {
|
||||||
g.config.keyup_fn(e.key_code, Modifier(e.modifiers), g.config.user_data)
|
ctx.config.keyup_fn(e.key_code, Modifier(e.modifiers), ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.char {
|
.char {
|
||||||
if g.config.char_fn != voidptr(0) {
|
if ctx.config.char_fn != voidptr(0) {
|
||||||
g.config.char_fn(e.char_code, g.config.user_data)
|
ctx.config.char_fn(e.char_code, ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.resized {
|
.resized {
|
||||||
if g.config.resized_fn != voidptr(0) {
|
if ctx.config.resized_fn != voidptr(0) {
|
||||||
g.config.resized_fn(e, g.config.user_data)
|
ctx.config.resized_fn(e, ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.quit_requested {
|
.quit_requested {
|
||||||
if g.config.quit_fn != voidptr(0) {
|
if ctx.config.quit_fn != voidptr(0) {
|
||||||
g.config.quit_fn(e, g.config.user_data)
|
ctx.config.quit_fn(e, ctx.config.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -370,18 +370,18 @@ fn gg_event_fn(ce voidptr, user_data voidptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gg_cleanup_fn(user_data voidptr) {
|
fn gg_cleanup_fn(user_data voidptr) {
|
||||||
mut g := unsafe { &Context(user_data) }
|
mut ctx := unsafe { &Context(user_data) }
|
||||||
if g.config.cleanup_fn != voidptr(0) {
|
if ctx.config.cleanup_fn != voidptr(0) {
|
||||||
g.config.cleanup_fn(g.config.user_data)
|
ctx.config.cleanup_fn(ctx.config.user_data)
|
||||||
}
|
}
|
||||||
gfx.shutdown()
|
gfx.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gg_fail_fn(msg &char, user_data voidptr) {
|
fn gg_fail_fn(msg &char, user_data voidptr) {
|
||||||
mut g := unsafe { &Context(user_data) }
|
mut ctx := unsafe { &Context(user_data) }
|
||||||
vmsg := unsafe { tos3(msg) }
|
vmsg := unsafe { tos3(msg) }
|
||||||
if g.config.fail_fn != voidptr(0) {
|
if ctx.config.fail_fn != voidptr(0) {
|
||||||
g.config.fail_fn(vmsg, g.config.user_data)
|
ctx.config.fail_fn(vmsg, ctx.config.user_data)
|
||||||
} else {
|
} else {
|
||||||
eprintln('gg error: $vmsg')
|
eprintln('gg error: $vmsg')
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ fn gg_fail_fn(msg &char, user_data voidptr) {
|
||||||
|
|
||||||
//
|
//
|
||||||
pub fn new_context(cfg Config) &Context {
|
pub fn new_context(cfg Config) &Context {
|
||||||
mut g := &Context{
|
mut ctx := &Context{
|
||||||
user_data: cfg.user_data
|
user_data: cfg.user_data
|
||||||
width: cfg.width
|
width: cfg.width
|
||||||
height: cfg.height
|
height: cfg.height
|
||||||
|
@ -401,12 +401,12 @@ pub fn new_context(cfg Config) &Context {
|
||||||
native_rendering: cfg.native_rendering
|
native_rendering: cfg.native_rendering
|
||||||
}
|
}
|
||||||
if isnil(cfg.user_data) {
|
if isnil(cfg.user_data) {
|
||||||
g.user_data = g
|
ctx.user_data = ctx
|
||||||
}
|
}
|
||||||
g.set_bg_color(cfg.bg_color)
|
ctx.set_bg_color(cfg.bg_color)
|
||||||
// C.printf('new_context() %p\n', cfg.user_data)
|
// C.printf('new_context() %p\n', cfg.user_data)
|
||||||
window := sapp.Desc{
|
window := sapp.Desc{
|
||||||
user_data: g
|
user_data: ctx
|
||||||
init_userdata_cb: gg_init_sokol_window
|
init_userdata_cb: gg_init_sokol_window
|
||||||
frame_userdata_cb: gg_frame_fn
|
frame_userdata_cb: gg_frame_fn
|
||||||
event_userdata_cb: gg_event_fn
|
event_userdata_cb: gg_event_fn
|
||||||
|
@ -426,8 +426,8 @@ pub fn new_context(cfg Config) &Context {
|
||||||
max_dropped_file_path_length: cfg.max_dropped_file_path_length
|
max_dropped_file_path_length: cfg.max_dropped_file_path_length
|
||||||
swap_interval: cfg.swap_interval
|
swap_interval: cfg.swap_interval
|
||||||
}
|
}
|
||||||
g.window = window
|
ctx.window = window
|
||||||
return g
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (ctx &Context) run() {
|
pub fn (ctx &Context) run() {
|
||||||
|
@ -456,9 +456,9 @@ pub fn (mut ctx Context) refresh_ui() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepares the context for drawing
|
// Prepares the context for drawing
|
||||||
pub fn (gg &Context) begin() {
|
pub fn (ctx &Context) begin() {
|
||||||
if gg.render_text && gg.font_inited {
|
if ctx.render_text && ctx.font_inited {
|
||||||
gg.ft.flush()
|
ctx.ft.flush()
|
||||||
}
|
}
|
||||||
sgl.defaults()
|
sgl.defaults()
|
||||||
sgl.matrix_mode_projection()
|
sgl.matrix_mode_projection()
|
||||||
|
@ -466,8 +466,8 @@ pub fn (gg &Context) begin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finishes drawing for the context
|
// Finishes drawing for the context
|
||||||
pub fn (gg &Context) end() {
|
pub fn (ctx &Context) end() {
|
||||||
gfx.begin_default_pass(gg.clear_pass, sapp.width(), sapp.height())
|
gfx.begin_default_pass(ctx.clear_pass, sapp.width(), sapp.height())
|
||||||
sgl.draw()
|
sgl.draw()
|
||||||
gfx.end_pass()
|
gfx.end_pass()
|
||||||
gfx.commit()
|
gfx.commit()
|
||||||
|
|
Loading…
Reference in New Issue