cursorSprite returns the sprite for the cursor, which is only rendered once with a vertical bar, and just activated and inactivated depending on render status.
(on bool)
| 125 | // only rendered once with a vertical bar, and just activated and inactivated |
| 126 | // depending on render status. |
| 127 | func (ed *Editor) cursorSprite(on bool) *core.Sprite { |
| 128 | sc := ed.Scene |
| 129 | if sc == nil { |
| 130 | return nil |
| 131 | } |
| 132 | ms := sc.Stage.Main |
| 133 | if ms == nil { |
| 134 | return nil // only MainStage has sprites |
| 135 | } |
| 136 | spnm := ed.cursorSpriteName() |
| 137 | sp, ok := ms.Sprites.SpriteByName(spnm) |
| 138 | if !ok { |
| 139 | bbsz := image.Point{int(math32.Ceil(ed.CursorWidth.Dots)), int(math32.Ceil(ed.fontHeight))} |
| 140 | if bbsz.X < 2 { // at least 2 |
| 141 | bbsz.X = 2 |
| 142 | } |
| 143 | sp = core.NewSprite(spnm, bbsz, image.Point{}) |
| 144 | ibox := sp.Pixels.Bounds() |
| 145 | draw.Draw(sp.Pixels, ibox, ed.CursorColor, image.Point{}, draw.Src) |
| 146 | ms.Sprites.Add(sp) |
| 147 | } |
| 148 | if on { |
| 149 | ms.Sprites.ActivateSprite(sp.Name) |
| 150 | } else { |
| 151 | ms.Sprites.InactivateSprite(sp.Name) |
| 152 | } |
| 153 | return sp |
| 154 | } |
no test coverage detected