-
Notifications
You must be signed in to change notification settings - Fork 35
/
pseudo_cursor_with_alpha.go
61 lines (53 loc) · 1.27 KB
/
pseudo_cursor_with_alpha.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package encodings
import (
"bytes"
"github.com/vprix/vncproxy/rfb"
)
type CursorWithAlphaPseudoEncoding struct {
buff *bytes.Buffer
}
func (that *CursorWithAlphaPseudoEncoding) Supported(session rfb.ISession) bool {
return true
}
func (that *CursorWithAlphaPseudoEncoding) Clone(data ...bool) rfb.IEncoding {
obj := &CursorWithAlphaPseudoEncoding{}
if len(data) > 0 && data[0] {
if that.buff != nil {
obj.buff = &bytes.Buffer{}
_, _ = obj.buff.Write(that.buff.Bytes())
}
}
return obj
}
func (that *CursorWithAlphaPseudoEncoding) Type() rfb.EncodingType {
return rfb.EncCursorWithAlphaPseudo
}
func (that *CursorWithAlphaPseudoEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error {
if that.buff == nil {
that.buff = &bytes.Buffer{}
}
var bt []byte
var err error
bt, err = ReadBytes(4, session)
if err != nil {
return err
}
_, _ = that.buff.Write(bt)
if rect.Width*rect.Height > 0 {
bt2, err := ReadBytes(int(rect.Width*rect.Height)*4, session)
if err != nil {
return err
}
_, _ = that.buff.Write(bt2)
}
return nil
}
func (that *CursorWithAlphaPseudoEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error {
if that.buff == nil {
return nil
}
var err error
_, err = that.buff.WriteTo(session)
that.buff.Reset()
return err
}