mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gg: GG => Context
This commit is contained in:
parent
926ffc8aa9
commit
13a7ce9e69
@ -10,7 +10,7 @@ const (
|
||||
filled_color = gx.blue
|
||||
)
|
||||
|
||||
fn new_graphics() &gg.GG {
|
||||
fn new_graphics() &gg.Context {
|
||||
glfw.init_glfw()
|
||||
return gg.new_context(gg.Cfg{
|
||||
width: screen_width
|
||||
|
@ -11,7 +11,7 @@ const (
|
||||
|
||||
struct App {
|
||||
mut:
|
||||
gg &gg.GG
|
||||
gg &gg.Context
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -61,7 +61,7 @@ lines = text.split('\n')
|
||||
|
||||
struct App {
|
||||
mut:
|
||||
gg &gg.GG
|
||||
gg &gg.Context
|
||||
ft &ft.FT
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import time
|
||||
|
||||
struct Game {
|
||||
mut:
|
||||
gg &gg.GG
|
||||
gg &gg.Context
|
||||
x int
|
||||
y int
|
||||
dy int
|
||||
|
@ -13,7 +13,7 @@ const (
|
||||
)
|
||||
|
||||
struct Context {
|
||||
gg &gg.GG
|
||||
gg &gg.Context
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -126,7 +126,7 @@ struct Game {
|
||||
// Index of the rotation (0-3)
|
||||
rotation_idx int
|
||||
// gg context for drawing
|
||||
gg &gg.GG = voidptr(0)
|
||||
gg &gg.Context = voidptr(0)
|
||||
// ft context for font drawing
|
||||
ft &ft.FT = voidptr(0)
|
||||
font_loaded bool
|
||||
|
@ -124,7 +124,7 @@ fn f64_min(a, b f64) f64 {
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn (a f32) eq_epsilon(b f32) bool {
|
||||
pub fn (a f32) eq_epsilon(b f32) bool {
|
||||
hi := f32_max(f32_abs(a), f32_abs(b))
|
||||
delta := f32_abs(a - b)
|
||||
if hi > f32(1.0) {
|
||||
@ -135,7 +135,7 @@ fn (a f32) eq_epsilon(b f32) bool {
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn (a f64) eq_epsilon(b f64) bool {
|
||||
pub fn (a f64) eq_epsilon(b f64) bool {
|
||||
hi := f64_max(f64_abs(a), f64_abs(b))
|
||||
delta := f64_abs(a - b)
|
||||
if hi > 1.0 {
|
||||
|
@ -13,4 +13,4 @@ pub fn println(s any) {
|
||||
|
||||
pub fn print(s any) {
|
||||
JS.process.stdout.write(s)
|
||||
}
|
||||
}
|
||||
|
30
vlib/gg/gg.v
30
vlib/gg/gg.v
@ -9,7 +9,7 @@ import sokol
|
||||
import sokol.sapp
|
||||
import sokol.sgl
|
||||
import sokol.gfx
|
||||
import gg.ft
|
||||
//import gg.ft
|
||||
|
||||
type FNvoidptr1 fn(voidptr)
|
||||
type FNvoidptr2 fn(voidptr,voidptr)
|
||||
@ -40,7 +40,7 @@ pub:
|
||||
font_path string
|
||||
}
|
||||
|
||||
pub struct GG {
|
||||
pub struct Context {
|
||||
scale f32 = 1.0// retina = 2 , normal = 1
|
||||
pub mut:
|
||||
width int
|
||||
@ -53,7 +53,7 @@ pub mut:
|
||||
pub struct Size { pub: width int height int }
|
||||
|
||||
fn gg_init_sokol_window(user_data voidptr) {
|
||||
mut g := &GG(user_data)
|
||||
mut g := &Context(user_data)
|
||||
desc := C.sg_desc{
|
||||
mtl_device: sapp.metal_get_device()
|
||||
mtl_renderpass_descriptor_cb: sapp.metal_get_renderpass_descriptor
|
||||
@ -72,28 +72,28 @@ fn gg_init_sokol_window(user_data voidptr) {
|
||||
}
|
||||
|
||||
fn gg_frame_fn(user_data voidptr) {
|
||||
mut g := &GG(user_data)
|
||||
mut g := &Context(user_data)
|
||||
if g.config.frame_fn != voidptr(0) {
|
||||
g.config.frame_fn( g.config.user_data )
|
||||
}
|
||||
}
|
||||
|
||||
fn gg_event_fn(e &C.sapp_event, user_data voidptr){
|
||||
mut g := &GG(user_data)
|
||||
mut g := &Context(user_data)
|
||||
if g.config.event_fn != voidptr(0) {
|
||||
g.config.event_fn(e, g.config.user_data)
|
||||
}
|
||||
}
|
||||
|
||||
fn gg_cleanup_fn(user_data voidptr){
|
||||
mut g := &GG(user_data)
|
||||
mut g := &Context(user_data)
|
||||
if g.config.cleanup_fn != voidptr(0) {
|
||||
g.config.cleanup_fn(g.config.user_data)
|
||||
}
|
||||
}
|
||||
|
||||
fn gg_fail_fn(msg charptr, user_data voidptr){
|
||||
mut g := &GG(user_data)
|
||||
mut g := &Context(user_data)
|
||||
vmsg := tos3(msg)
|
||||
if g.config.fail_fn != voidptr(0) {
|
||||
g.config.fail_fn(vmsg, g.config.user_data)
|
||||
@ -104,8 +104,8 @@ fn gg_fail_fn(msg charptr, user_data voidptr){
|
||||
|
||||
//
|
||||
|
||||
pub fn new_context(cfg Config) &GG {
|
||||
mut g := &GG{
|
||||
pub fn new_context(cfg Config) &Context{
|
||||
mut g := &Context{
|
||||
width: cfg.width
|
||||
height: cfg.height
|
||||
clear_pass: gfx.create_clear_pass( f32(cfg.bg_color.r) / 255.0, f32(cfg.bg_color.g) / 255.0,
|
||||
@ -136,11 +136,11 @@ f32(cfg.bg_color.b) / 255.0, 1.0)
|
||||
return g
|
||||
}
|
||||
|
||||
pub fn (gg &GG) run() {
|
||||
pub fn (gg &Context) run() {
|
||||
sapp.run(&gg.window)
|
||||
}
|
||||
|
||||
pub fn (ctx &GG) draw_rect(x, y, w, h f32, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
|
||||
sgl.c4b(c.r, c.g, c.b, 128)
|
||||
sgl.begin_quads()
|
||||
sgl.v2f(x * ctx.scale, y * ctx.scale)
|
||||
@ -150,7 +150,7 @@ pub fn (ctx &GG) draw_rect(x, y, w, h f32, c gx.Color) {
|
||||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (gg &GG) draw_empty_rect(x, y, w, h f32, c gx.Color) {
|
||||
pub fn (gg &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) {
|
||||
sgl.c4b(c.r, c.g, c.b, 128)
|
||||
sgl.begin_line_strip()
|
||||
sgl.v2f(x, y)
|
||||
@ -179,13 +179,13 @@ pub fn create_image_from_memory(buf byteptr) u32 {
|
||||
return 0 // texture
|
||||
}
|
||||
|
||||
pub fn (gg &GG) begin() {
|
||||
pub fn (gg &Context) begin() {
|
||||
sgl.defaults()
|
||||
sgl.matrix_mode_projection()
|
||||
sgl.ortho(0.0, f32(sapp.width()), f32(sapp.height()), 0.0, -1.0, 1.0)
|
||||
}
|
||||
|
||||
pub fn (gg &GG) end() {
|
||||
pub fn (gg &Context) end() {
|
||||
gfx.begin_default_pass(gg.clear_pass, sapp.width(), sapp.height())
|
||||
sgl.draw()
|
||||
gfx.end_pass()
|
||||
@ -196,7 +196,7 @@ pub fn (gg &GG) end() {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (ctx &GG) draw_line(x, y, x2, y2 f32, color gx.Color) {}
|
||||
pub fn (ctx &Context) draw_line(x, y, x2, y2 f32, color gx.Color) {}
|
||||
|
||||
fn C.WaitMessage()
|
||||
|
||||
|
@ -177,4 +177,4 @@ fn test_phi_11_digits() {
|
||||
fn test_phi_12_digits() {
|
||||
assert fractions.approximate_with_eps(math.phi, 5.0e-13).equals(fractions.fraction(2178309,
|
||||
1346269))
|
||||
}
|
||||
}
|
||||
|
@ -266,4 +266,4 @@ fn test_49_by_75_not_greater_than_2_by_3() {
|
||||
f2 := fractions.fraction(2, 3)
|
||||
assert !f1.gt(f2)
|
||||
assert !f1.ge(f2)
|
||||
}
|
||||
}
|
||||
|
@ -53,4 +53,4 @@ pub fn (l &Logger) s(message string) {
|
||||
|
||||
fn (l &Logger) print(mod, message string) {
|
||||
println('${colors[mod]};7m[${mod}]\e[0m \e[1m${l.mod}\e[0m: ${message}')
|
||||
}
|
||||
}
|
||||
|
@ -136,4 +136,4 @@ const (
|
||||
status_stack_buffer_overrun = 0xC0000409
|
||||
status_invalid_cruntime_parameter = 0xC0000417
|
||||
status_assertion_failure = 0xC0000420
|
||||
)
|
||||
)
|
||||
|
@ -12,4 +12,4 @@ type SysRNG WyRandRNG
|
||||
[inline]
|
||||
pub fn (r SysRNG) default_rand() int {
|
||||
return r.int()
|
||||
}
|
||||
}
|
||||
|
@ -56,4 +56,4 @@ fn (mut b Builder) run_js() {
|
||||
return
|
||||
}
|
||||
println(res.output)
|
||||
}
|
||||
}
|
||||
|
@ -2,4 +2,4 @@ module hello
|
||||
|
||||
pub fn raw_js_log() {
|
||||
#console.log('hello')
|
||||
}
|
||||
}
|
||||
|
@ -28,4 +28,4 @@ pub fn debugger() string {
|
||||
|
||||
pub fn excited() string {
|
||||
return debugger() + "!"
|
||||
}
|
||||
}
|
||||
|
@ -24,4 +24,4 @@ fn test_multi_level_pointer_dereferencing() {
|
||||
}
|
||||
assert n == 300 // updated by the unsafe pointer manipulation
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user