mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
gg: make draw_rect_empty/5 draw more exact borders, independent of the device, and fitting the draw_rect_filled/5 shapes (#24024)
This commit is contained in:
parent
a199a6ea2e
commit
0ad74ded92
2 changed files with 47 additions and 7 deletions
|
@ -190,13 +190,29 @@ pub fn (ctx &Context) draw_rect_empty(x f32, y f32, w f32, h f32, c gx.Color) {
|
||||||
sgl.load_pipeline(ctx.pipeline.alpha)
|
sgl.load_pipeline(ctx.pipeline.alpha)
|
||||||
}
|
}
|
||||||
sgl.c4b(c.r, c.g, c.b, c.a)
|
sgl.c4b(c.r, c.g, c.b, c.a)
|
||||||
|
// The small offsets here, are to make sure, that the start and end points will be
|
||||||
sgl.begin_line_strip()
|
// inside pixels, and not on their borders. That in turn, makes it much more likely
|
||||||
sgl.v2f(x * ctx.scale, y * ctx.scale)
|
// that different OpenGL implementations will render them identically, for example
|
||||||
sgl.v2f((x + w) * ctx.scale, y * ctx.scale)
|
// Mesa, with `LIBGL_ALWAYS_SOFTWARE=1` renders the same as HD4000.
|
||||||
sgl.v2f((x + w) * ctx.scale, (y + h) * ctx.scale)
|
mut toffset := f32(0.1)
|
||||||
sgl.v2f(x * ctx.scale, (y + h) * ctx.scale)
|
mut boffset := f32(-0.1)
|
||||||
sgl.v2f(x * ctx.scale, (y - 1) * ctx.scale)
|
tleft_x := toffset + x * ctx.scale
|
||||||
|
tleft_y := toffset + y * ctx.scale
|
||||||
|
bright_x := boffset + (x + w) * ctx.scale
|
||||||
|
bright_y := boffset + (y + h) * ctx.scale
|
||||||
|
sgl.begin_lines() // more predictable, compared to sgl.begin_line_strip, at the price of more vertexes send
|
||||||
|
// top:
|
||||||
|
sgl.v2f(tleft_x, tleft_y)
|
||||||
|
sgl.v2f(bright_x, tleft_y)
|
||||||
|
// left:
|
||||||
|
sgl.v2f(tleft_x, tleft_y)
|
||||||
|
sgl.v2f(tleft_x, bright_y)
|
||||||
|
// right:
|
||||||
|
sgl.v2f(bright_x, tleft_y)
|
||||||
|
sgl.v2f(bright_x, bright_y)
|
||||||
|
// bottom:
|
||||||
|
sgl.v2f(tleft_x, bright_y)
|
||||||
|
sgl.v2f(bright_x, bright_y)
|
||||||
sgl.end()
|
sgl.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
vlib/gg/testdata/draw_rectangles.vv
vendored
Normal file
24
vlib/gg/testdata/draw_rectangles.vv
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
import gg
|
||||||
|
import gx
|
||||||
|
|
||||||
|
gg.start(
|
||||||
|
bg_color: gx.white
|
||||||
|
window_title: 'Rectangles'
|
||||||
|
width: 250
|
||||||
|
height: 100
|
||||||
|
frame_fn: fn (ctx &gg.Context) {
|
||||||
|
ctx.begin()
|
||||||
|
ctx.draw_rect_filled(10, 10, 10, 10, gx.blue)
|
||||||
|
ctx.draw_rect_empty(30, 10, 10, 10, gx.red)
|
||||||
|
ctx.draw_rect_filled(50, 10, 30, 10, gx.green)
|
||||||
|
ctx.draw_rect_empty(100, 10, 30, 10, gx.black)
|
||||||
|
|
||||||
|
ctx.draw_rect_empty(10, 50, 10, 10, gx.blue)
|
||||||
|
ctx.draw_rect_filled(30, 50, 10, 10, gx.red)
|
||||||
|
ctx.draw_rect_empty(50, 50, 30, 10, gx.green)
|
||||||
|
ctx.draw_rect_filled(100, 50, 30, 10, gx.black)
|
||||||
|
ctx.end()
|
||||||
|
}
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue