Skip to content

Commit

Permalink
misc command queue cleanup
Browse files Browse the repository at this point in the history
also do not enqueue multiple scissor commands in sequence.
  • Loading branch information
aarzilli committed Sep 18, 2018
1 parent 5679057 commit f3fdcc7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 48 deletions.
71 changes: 26 additions & 45 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,31 @@ import (

// CommandBuffer is a list of drawing directives.
type Buffer struct {
UseClipping bool
Clip rect.Rect
Commands []Command
Clip rect.Rect
Commands []Command
}

var nk_null_rect = rect.Rect{-8192.0, -8192.0, 16384.0, 16384.0}

func (buffer *Buffer) Reset() {
buffer.UseClipping = true
buffer.Clip = nk_null_rect
buffer.Commands = buffer.Commands[:0]
}

// Represents one drawing directive.
type Command struct {
rect.Rect
Kind CommandKind
Scissor Scissor
Line Line
RectFilled RectFilled
Kind CommandKind
Line Line
RectFilled RectFilled
TriangleFilled TriangleFilled
CircleFilled CircleFilled
Image Image
Text Text
CircleFilled CircleFilled
Image Image
Text Text
}

type CommandKind uint8

const (
ScissorCmd CommandKind = iota
LineCmd
Expand All @@ -48,10 +46,6 @@ const (
TextCmd
)

type Scissor struct {
rect.Rect
}

type Line struct {
LineThickness uint16
Begin image.Point
Expand All @@ -60,7 +54,6 @@ type Line struct {
}

type RectFilled struct {
//rect.Rect
Rounding uint16
Color color.RGBA
}
Expand All @@ -73,25 +66,27 @@ type TriangleFilled struct {
}

type CircleFilled struct {
//rect.Rect
Color color.RGBA
}

type Image struct {
//rect.Rect
Img *image.RGBA
}

type Text struct {
//rect.Rect
Face font.Face
Foreground color.RGBA
String string
}

func (b *Buffer) PushScissor(r rect.Rect) {
b.Clip = r


if len(b.Commands) > 0 && b.Commands[len(b.Commands)-1].Kind == ScissorCmd {
b.Commands[len(b.Commands)-1].Rect = r
return
}

var cmd Command
cmd.Kind = ScissorCmd
cmd.Rect = r
Expand All @@ -113,10 +108,8 @@ func (b *Buffer) FillRect(rect rect.Rect, rounding uint16, c color.RGBA) {
if c.A == 0 {
return
}
if b.UseClipping {
if !rect.Intersect(&b.Clip) {
return
}
if !rect.Intersect(&b.Clip) {
return
}

var cmd Command
Expand All @@ -131,12 +124,10 @@ func (b *Buffer) FillCircle(r rect.Rect, c color.RGBA) {
if c.A == 0 {
return
}
if b.UseClipping {
if !r.Intersect(&b.Clip) {
return
}
if !r.Intersect(&b.Clip) {
return
}

var cmd Command
cmd.Kind = CircleFilledCmd
cmd.Rect = r
Expand All @@ -148,10 +139,8 @@ func (b *Buffer) FillTriangle(p0, p1, p2 image.Point, c color.RGBA) {
if c.A == 0 {
return
}
if b.UseClipping {
if !b.Clip.Contains(p0) || !b.Clip.Contains(p1) || !b.Clip.Contains(p2) {
return
}
if !b.Clip.Contains(p0) || !b.Clip.Contains(p1) || !b.Clip.Contains(p2) {
return
}

var cmd Command
Expand All @@ -164,10 +153,8 @@ func (b *Buffer) FillTriangle(p0, p1, p2 image.Point, c color.RGBA) {
}

func (b *Buffer) DrawImage(r rect.Rect, img *image.RGBA) {
if b.UseClipping {
if !r.Intersect(&b.Clip) {
return
}
if !r.Intersect(&b.Clip) {
return
}

var cmd Command
Expand All @@ -181,16 +168,10 @@ func (b *Buffer) DrawText(r rect.Rect, str string, face font.Face, fg color.RGBA
if len(str) == 0 || (fg.A == 0) {
return
}
if b.UseClipping {
if !r.Intersect(&b.Clip) {
return
}
}

if len(str) == 0 {
if !r.Intersect(&b.Clip) {
return
}

var cmd Command
cmd.Kind = TextCmd
cmd.Rect = r
Expand Down
1 change: 0 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (ctx *context) setupMasterWindow(layout *panel, updatefn UpdateFn) {
ctx.Windows[0].idx = 0
ctx.Windows[0].layout = layout
ctx.Windows[0].flags = layout.Flags | WindowNonmodal
ctx.Windows[0].cmds.UseClipping = true
ctx.Windows[0].updateFn = updatefn
}

Expand Down
2 changes: 0 additions & 2 deletions nucular.go
Original file line number Diff line number Diff line change
Expand Up @@ -2628,7 +2628,6 @@ func (ctx *context) nonblockOpen(flags WindowFlags, body rect.Rect, header rect.
popup := createWindow(ctx, "")
popup.idx = len(ctx.Windows)
popup.updateFn = updateFn
popup.cmds.UseClipping = true
ctx.Windows = append(ctx.Windows, popup)

popup.Bounds = body
Expand Down Expand Up @@ -2667,7 +2666,6 @@ func (ctx *context) popupOpen(title string, flags WindowFlags, rect rect.Rect, s
}
ctx.Windows = append(ctx.Windows, popup)
ctx.dockedWindowFocus = 0
popup.cmds.UseClipping = true

if scale {
rect.X = ctx.scale(rect.X)
Expand Down

0 comments on commit f3fdcc7

Please sign in to comment.