Skip to content

Commit

Permalink
gg: fix empty circle in native; http: post_form_with_cookies; veb: pr…
Browse files Browse the repository at this point in the history
…int veb action in html errors
  • Loading branch information
medvednikov committed Mar 11, 2024
1 parent 565cdf2 commit b2df326
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 3 deletions.
7 changes: 7 additions & 0 deletions vlib/gg/draw.c.v
Expand Up @@ -540,6 +540,13 @@ fn radius_to_segments(r f32) int {
// `radius` defines the radius of the circle.
// `c` is the color of the outline.
pub fn (ctx &Context) draw_circle_empty(x f32, y f32, radius f32, c gx.Color) {
$if macos {
if ctx.native_rendering {
C.darwin_draw_circle_empty(x - radius + 1, ctx.height - (y + radius + 3),
radius, c)
return
}
}
if c.a != 255 {
sgl.load_pipeline(ctx.pipeline.alpha)
}
Expand Down
1 change: 1 addition & 0 deletions vlib/gg/gg_darwin.c.v
Expand Up @@ -19,5 +19,6 @@ fn C.darwin_create_image(path string) Image
fn C.darwin_draw_image(f32, f32, f32, f32, &Image)

fn C.darwin_draw_circle(f32, f32, f32, voidptr)
fn C.darwin_draw_circle_empty(f32, f32, f32, voidptr)

//, gx.Color c)
13 changes: 13 additions & 0 deletions vlib/gg/gg_darwin.m
Expand Up @@ -120,3 +120,16 @@ void darwin_draw_circle(float x, float y, float d, gx__Color color) {
[circlePath fill];
// NSRectFill(rect);
}

void darwin_draw_circle_empty(float x, float y, float d, gx__Color color) {
NSColor* outlineColor = nscolor(color);
CGFloat outlineWidth = 1.0; //2.0;

NSRect rect = NSMakeRect(x, y, d * 2, d * 2);
NSBezierPath* circlePath = [NSBezierPath bezierPath];
[circlePath appendBezierPathWithOvalInRect:rect];

[outlineColor setStroke];
[circlePath setLineWidth:outlineWidth];
[circlePath stroke];
}
2 changes: 2 additions & 0 deletions vlib/gg/image.c.v
Expand Up @@ -291,7 +291,9 @@ pub fn (ctx &Context) draw_image_with_config(config DrawImageConfig) {
if config.img_id > 0 {
img = &ctx.image_cache[config.img_id]
} else {
//$if !noggverbose ? {
eprintln('gg: failed to get image to draw natively')
//}
return
}
}
Expand Down
10 changes: 10 additions & 0 deletions vlib/net/http/http.v
Expand Up @@ -90,6 +90,16 @@ pub fn post_form(url string, data map[string]string) !Response {
)
}

pub fn post_form_with_cookies(url string, data map[string]string, cookies map[string]string) !Response {
return fetch(
method: .post
url: url
header: new_header(key: .content_type, value: 'application/x-www-form-urlencoded')
data: url_encode_form_data(data)
cookies: cookies
)
}

@[params]
pub struct PostMultipartFormConfig {
pub mut:
Expand Down
14 changes: 13 additions & 1 deletion vlib/v/checker/errors.v
Expand Up @@ -37,7 +37,19 @@ fn (mut c Checker) error(message string, pos token.Pos) {
// TODO move this
return
}
msg := message.replace('`Array_', '`[]')
mut msg := message.replace('`Array_', '`[]')
if c.pref.is_vweb {
// Show in which veb action the error occurred (for easier debugging)
veb_action := c.table.cur_fn.name.replace('vweb_tmpl_', '')
mut j := 0
for _, ch in veb_action {
if ch.is_digit() {
break
}
j++
}
msg += ' (veb action: ${veb_action[..j]})'
}
c.warn_or_error(msg, pos, false)
}

Expand Down
9 changes: 7 additions & 2 deletions vlib/x/vweb/context.v
Expand Up @@ -291,11 +291,16 @@ pub fn (ctx &Context) user_agent() string {

// Returns the ip address from the current user
pub fn (ctx &Context) ip() string {
mut ip := ctx.req.header.get(.x_forwarded_for) or { '' }
mut ip := ctx.req.header.get_custom('CF-Connecting-IP') or { '' }
if ip == '' {
ip = ctx.req.header.get(.x_forwarded_for) or { '' }
}
if ip == '' {
ip = ctx.req.header.get_custom('X-Forwarded-For') or { '' }
}
if ip == '' {
ip = ctx.req.header.get_custom('X-Real-Ip') or { '' }
}

if ip.contains(',') {
ip = ip.all_before(',')
}
Expand Down

0 comments on commit b2df326

Please sign in to comment.