gg: new draw_empty_rounded_rect() (#6891)
							parent
							
								
									f2d59fbc0f
								
							
						
					
					
						commit
						54df7d1daf
					
				
							
								
								
									
										56
									
								
								vlib/gg/gg.v
								
								
								
								
							
							
						
						
									
										56
									
								
								vlib/gg/gg.v
								
								
								
								
							| 
						 | 
				
			
			@ -457,7 +457,61 @@ pub fn (ctx &Context) draw_line(x f32, y f32, x2 f32, y2 f32, c gx.Color) {
 | 
			
		|||
pub fn (ctx &Context) draw_rounded_rect(x f32, y f32, width f32, height f32, radius f32, color gx.Color) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn (ctx &Context) draw_empty_rounded_rect(x f32, y f32, width f32, height f32, radius f32, border_color gx.Color) {
 | 
			
		||||
pub fn (ctx &Context) draw_empty_rounded_rect(x f32, y f32, w f32, h f32, radius f32, border_color gx.Color) {
 | 
			
		||||
	mut theta := f32(0)
 | 
			
		||||
	mut xx := f32(0)
 | 
			
		||||
	mut yy := f32(0)
 | 
			
		||||
	r := radius * f32(ctx.scale)
 | 
			
		||||
	nx := x * f32(ctx.scale)
 | 
			
		||||
	ny := y * f32(ctx.scale)
 | 
			
		||||
	width := w * f32(ctx.scale)
 | 
			
		||||
	height := h * f32(ctx.scale)
 | 
			
		||||
	segments := 2 * math.pi * r
 | 
			
		||||
	segdiv := segments / 4
 | 
			
		||||
	rb := 0
 | 
			
		||||
	lb := int(rb + segdiv)
 | 
			
		||||
	lt := int(lb + segdiv)
 | 
			
		||||
	rt := int(lt + segdiv)
 | 
			
		||||
	sgl.c4b(border_color.r, border_color.g, border_color.b, border_color.a)
 | 
			
		||||
	sgl.begin_line_strip()
 | 
			
		||||
	// left top
 | 
			
		||||
	lx := nx + r
 | 
			
		||||
	ly := ny + r
 | 
			
		||||
	for i in lt .. rt {
 | 
			
		||||
		theta = 2 * f32(math.pi) * f32(i) / segments
 | 
			
		||||
		xx = r * math.cosf(theta)
 | 
			
		||||
		yy = r * math.sinf(theta)
 | 
			
		||||
		sgl.v2f(xx + lx, yy + ly)
 | 
			
		||||
	}
 | 
			
		||||
	// right top
 | 
			
		||||
	mut rx := nx + 2 * width - r
 | 
			
		||||
	mut ry := ny + r
 | 
			
		||||
	for i in rt .. int(segments) {
 | 
			
		||||
		theta = 2 * f32(math.pi) * f32(i) / segments
 | 
			
		||||
		xx = r * math.cosf(theta)
 | 
			
		||||
		yy = r * math.sinf(theta)
 | 
			
		||||
		sgl.v2f(xx + rx, yy + ry)
 | 
			
		||||
	}
 | 
			
		||||
	// right bottom
 | 
			
		||||
	mut rbx := rx
 | 
			
		||||
	mut rby := ny + 2 * height - r
 | 
			
		||||
	for i in rb .. lb {
 | 
			
		||||
		theta = 2 * f32(math.pi) * f32(i) / segments
 | 
			
		||||
		xx = r * math.cosf(theta)
 | 
			
		||||
		yy = r * math.sinf(theta)
 | 
			
		||||
		sgl.v2f(xx + rbx, yy + rby)
 | 
			
		||||
	}
 | 
			
		||||
	// left bottom
 | 
			
		||||
	mut lbx := lx
 | 
			
		||||
	mut lby := ny + 2 * height - r
 | 
			
		||||
	for i in lb .. lt {
 | 
			
		||||
		theta = 2 * f32(math.pi) * f32(i) / segments
 | 
			
		||||
		xx = r * math.cosf(theta)
 | 
			
		||||
		yy = r * math.sinf(theta)
 | 
			
		||||
		sgl.v2f(xx + lbx, yy + lby)
 | 
			
		||||
	}
 | 
			
		||||
	sgl.v2f(lx + xx, ly)
 | 
			
		||||
	sgl.end()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn C.WaitMessage()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue