(x, y float32, worldSpace bool, property *Property)
| 420 | } |
| 421 | |
| 422 | func NewCheckbox(x, y float32, worldSpace bool, property *Property) *Checkbox { |
| 423 | checkbox := &Checkbox{ |
| 424 | IconButton: *NewIconButton(x, y, &sdl.FRect{48, 0, 32, 32}, globals.GUITexture, worldSpace, nil), |
| 425 | InactiveSrcPos: Vector{48, 0}, |
| 426 | ActiveSrcPos: Vector{48, 32}, |
| 427 | } |
| 428 | |
| 429 | r := *checkbox.IconButton.Rect |
| 430 | checkbox.Rect = &r |
| 431 | |
| 432 | checkbox.Property = property |
| 433 | |
| 434 | checkbox.OnPressed = func() { |
| 435 | |
| 436 | if !checkbox.CanPress { |
| 437 | return |
| 438 | } |
| 439 | |
| 440 | PlayUISound(UISoundTypeSelect) |
| 441 | |
| 442 | if checkbox.Property != nil { |
| 443 | checkbox.Property.Set(!checkbox.Property.AsBool()) |
| 444 | } else { |
| 445 | checkbox.Checked = !checkbox.Checked |
| 446 | } |
| 447 | |
| 448 | if checkbox.OnChange != nil { |
| 449 | checkbox.OnChange() |
| 450 | } |
| 451 | |
| 452 | } |
| 453 | |
| 454 | return checkbox |
| 455 | } |
| 456 | |
| 457 | func (checkbox *Checkbox) Update() { |
| 458 |
no test coverage detected