1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

gg: renaming drawing functions (#12913)

This commit is contained in:
Benjamin Stigsen
2021-12-23 12:31:25 +01:00
committed by GitHub
parent ad1ef6a9e2
commit 546c388b02
15 changed files with 145 additions and 55 deletions

View File

@@ -593,7 +593,7 @@ fn (app &App) draw() {
app.draw_tiles()
// TODO: Make transparency work in `gg`
if app.state == .over {
app.gg.draw_rect(0, 0, ww, wh, gx.rgba(10, 0, 0, 180))
app.gg.draw_rect_filled(0, 0, ww, wh, gx.rgba(10, 0, 0, 180))
app.gg.draw_text(ww / 2, (m * 4 / 10) + ypad, 'Game Over', app.label_format(.game_over))
f := app.label_format(.tile)
msg := $if android { 'Tap to restart' } $else { 'Press `r` to restart' }
@@ -604,7 +604,7 @@ fn (app &App) draw() {
})
}
if app.state == .victory {
app.gg.draw_rect(0, 0, ww, wh, gx.rgba(0, 10, 0, 180))
app.gg.draw_rect_filled(0, 0, ww, wh, gx.rgba(0, 10, 0, 180))
app.gg.draw_text(ww / 2, (m * 4 / 10) + ypad, 'Victory!', app.label_format(.victory))
// f := app.label_format(.tile)
msg1 := $if android { 'Tap to continue' } $else { 'Press `space` to continue' }
@@ -623,7 +623,7 @@ fn (app &App) draw_tiles() {
toffset := app.ui.tile_size + app.ui.padding_size
tiles_size := mu.min(app.ui.window_width, app.ui.window_height) - app.ui.border_size * 2
// Draw the padding around the tiles
app.gg.draw_rounded_rect(xstart, ystart, tiles_size, tiles_size, tiles_size / 24,
app.gg.draw_rounded_rect_filled(xstart, ystart, tiles_size, tiles_size, tiles_size / 24,
app.theme.padding_color)
// Draw the actual tiles
for y in 0 .. 4 {
@@ -640,7 +640,7 @@ fn (app &App) draw_tiles() {
th := tw // square tiles, w == h
xoffset := xstart + app.ui.padding_size + x * toffset + (app.ui.tile_size - tw) / 2
yoffset := ystart + app.ui.padding_size + y * toffset + (app.ui.tile_size - th) / 2
app.gg.draw_rounded_rect(xoffset, yoffset, tw, th, tw / 8, tile_color)
app.gg.draw_rounded_rect_filled(xoffset, yoffset, tw, th, tw / 8, tile_color)
if tidx != 0 { // 0 == blank spot
xpos := xoffset + tw / 2
ypos := yoffset + th / 2

View File

@@ -13,7 +13,7 @@ pub mut:
}
pub fn (particle Particle) draw(mut ctx gg.Context) {
ctx.draw_circle(particle.pos.x, get_params().height - particle.pos.y, get_params().particle_radius,
ctx.draw_circle_filled(particle.pos.x, get_params().height - particle.pos.y, get_params().particle_radius,
particle.color)
}

View File

@@ -16,7 +16,7 @@ pub mut:
}
pub fn (rocket Rocket) draw(mut ctx gg.Context) {
ctx.draw_circle(rocket.pos.x, get_params().height - rocket.pos.y, get_params().rocket_radius,
ctx.draw_circle_filled(rocket.pos.x, get_params().height - rocket.pos.y, get_params().rocket_radius,
rocket.color)
}

View File

@@ -17,7 +17,7 @@ fn print_automaton(app &App) {
for x := 1; x < app.a.field.maxx; x++ {
cell := app.a.field.get(x, y)
if cell == 1 {
app.gg.draw_rect(f32(square_size * x), f32(square_size * y), f32(square_size),
app.gg.draw_rect_filled(f32(square_size * x), f32(square_size * y), f32(square_size),
f32(square_size), filled_color)
}
}

View File

@@ -41,12 +41,14 @@ fn main() {
fn frame(mut app App) {
app.gg.begin()
// Set a blue pixel near each corner. (Find your magnifying glass)
app.gg.set_pixel(2, 2, gx.blue)
app.gg.set_pixel(app.gg.width - 2, 2, gx.blue)
app.gg.set_pixel(app.gg.width - 2, app.gg.height - 2, gx.blue)
app.gg.set_pixel(2, app.gg.height - 2, gx.blue)
// Set pixels in a grid-like pattern.
app.gg.set_pixels(app.pixels, gx.red)
// Draw a blue pixel near each corner. (Find your magnifying glass)
app.gg.draw_pixel(2, 2, gx.blue)
app.gg.draw_pixel(app.gg.width - 2, 2, gx.blue)
app.gg.draw_pixel(app.gg.width - 2, app.gg.height - 2, gx.blue)
app.gg.draw_pixel(2, app.gg.height - 2, gx.blue)
// Draw pixels in a grid-like pattern.
app.gg.draw_pixels(app.pixels, gx.red)
app.gg.end()
}

View File

@@ -18,7 +18,7 @@ fn frame(mut ctx gg.Context) {
ctx.begin()
ctx.draw_convex_poly([f32(100.0), 100.0, 200.0, 100.0, 300.0, 200.0, 200.0, 300.0, 100.0, 300.0],
gx.blue)
ctx.draw_empty_poly([f32(50.0), 50.0, 70.0, 60.0, 90.0, 80.0, 70.0, 110.0], gx.black)
ctx.draw_triangle(450, 142, 530, 280, 370, 280, gx.red)
ctx.draw_poly_empty([f32(50.0), 50.0, 70.0, 60.0, 90.0, 80.0, 70.0, 110.0], gx.black)
ctx.draw_triangle_filled(450, 142, 530, 280, 370, 280, gx.red)
ctx.end()
}

View File

@@ -47,7 +47,7 @@ fn frame(app &App) {
fn (app &App) draw() {
// app.gg.draw_text_def(200,20, 'hello world!')
// app.gg.draw_text_def(300,300, 'привет')
app.gg.draw_rect(10, 10, 100, 30, gx.blue)
app.gg.draw_empty_rect(110, 150, 80, 40, gx.black)
app.gg.draw_rect_filled(10, 10, 100, 30, gx.blue)
app.gg.draw_rect_empty(110, 150, 80, 40, gx.black)
app.gg.draw_image(230, 30, app.image.width, app.image.height, app.image)
}

View File

@@ -56,10 +56,11 @@ fn main() {
fn frame(mut game Game) {
game.gg.begin()
game.gg.draw_text_def(10, 5, 'Modify examples/hot_reload/bounce.v to get instant updates')
game.gg.draw_rect(game.x, game.y, width, width, gx.blue)
game.gg.draw_rect(window_width - width - game.x + 10, 200 - game.y + width, width,
width, gx.rgb(228, 10, 55))
game.gg.draw_rect(game.x - 25, 250 - game.y, width, width, gx.rgb(28, 240, 55))
game.gg.draw_rect_filled(game.x, game.y, width, width, gx.blue)
game.gg.draw_rect_filled(window_width - width - game.x + 10, 200 - game.y + width,
width, width, gx.rgb(228, 10, 55))
game.gg.draw_rect_filled(game.x - 25, 250 - game.y, width, width, gx.rgb(28, 240,
55))
game.gg.end()
}

View File

@@ -77,10 +77,10 @@ fn (ctx &Context) draw() {
// y = (x + 3) * (x + 3) / stime + stime*2.5
// y = math.sqrt(30.0 - x * x) * stime
// y -= (stime-0.5) + stime
// ctx.gg.draw_rect(f32((w/2) + x * scale), f32((h/2) - y * scale), 2, 2, blue)
ctx.gg.draw_rect(f32((w / 2) + x * scale), f32((h / 2) - y * scale), 2, (f32(y) * scale),
blue)
ctx.gg.draw_rect(f32((w / 2) + x * scale), f32((h / 2) + y * scale), 2, (f32(y) * scale) +
32, red)
// ctx.gg.draw_rect_filled(f32((w/2) + x * scale), f32((h/2) - y * scale), 2, 2, blue)
ctx.gg.draw_rect_filled(f32((w / 2) + x * scale), f32((h / 2) - y * scale), 2,
(f32(y) * scale), blue)
ctx.gg.draw_rect_filled(f32((w / 2) + x * scale), f32((h / 2) + y * scale), 2,
(f32(y) * scale) + 32, red)
}
}

View File

@@ -157,16 +157,16 @@ fn on_frame(mut app App) {
}
// drawing snake
for pos in app.snake {
app.gg.draw_rect(tile_size * pos.x, tile_size * pos.y + top_height, tile_size,
app.gg.draw_rect_filled(tile_size * pos.x, tile_size * pos.y + top_height, tile_size,
tile_size, gx.blue)
}
// drawing food
app.gg.draw_rect(tile_size * app.food.x, tile_size * app.food.y + top_height, tile_size,
tile_size, gx.red)
app.gg.draw_rect_filled(tile_size * app.food.x, tile_size * app.food.y + top_height,
tile_size, tile_size, gx.red)
// drawing top
app.gg.draw_rect(0, 0, canvas_size, top_height, gx.black)
app.gg.draw_rect_filled(0, 0, canvas_size, top_height, gx.black)
app.gg.draw_text(150, top_height / 2, 'Score: $app.score', gx.TextCfg{
color: gx.white
align: .center

View File

@@ -354,7 +354,7 @@ fn (g &Game) draw_next_tetro() {
}
fn (g &Game) draw_block_color(i int, j int, color gx.Color) {
g.gg.draw_rect(f32((j - 1) * g.block_size) + g.margin, f32((i - 1) * g.block_size),
g.gg.draw_rect_filled(f32((j - 1) * g.block_size) + g.margin, f32((i - 1) * g.block_size),
f32(g.block_size - 1), f32(g.block_size - 1), color)
}
@@ -380,11 +380,11 @@ fn (mut g Game) draw_ui() {
lines := g.lines.str()
g.gg.draw_text(ws.width - lines.len * textsize, 3, lines, text_cfg)
if g.state == .gameover {
g.gg.draw_rect(0, ws.height / 2 - textsize, ws.width, 5 * textsize, ui_color)
g.gg.draw_rect_filled(0, ws.height / 2 - textsize, ws.width, 5 * textsize, ui_color)
g.gg.draw_text(1, ws.height / 2 + 0 * textsize, 'Game Over', over_cfg)
g.gg.draw_text(1, ws.height / 2 + 2 * textsize, 'Space to restart', over_cfg)
} else if g.state == .paused {
g.gg.draw_rect(0, ws.height / 2 - textsize, ws.width, 5 * textsize, ui_color)
g.gg.draw_rect_filled(0, ws.height / 2 - textsize, ws.width, 5 * textsize, ui_color)
g.gg.draw_text(1, ws.height / 2 + 0 * textsize, 'Game Paused', text_cfg)
g.gg.draw_text(1, ws.height / 2 + 2 * textsize, 'SPACE to resume', text_cfg)
}