-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagelist.go
71 lines (57 loc) · 1.42 KB
/
imagelist.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
62
63
64
65
66
67
68
69
70
71
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package walk
import . "github.com/lxn/go-winapi"
type ImageList struct {
hIml HIMAGELIST
maskColor Color
}
func NewImageList(imageSize Size, maskColor Color) (*ImageList, error) {
hIml := ImageList_Create(
int32(imageSize.Width),
int32(imageSize.Height),
ILC_MASK|ILC_COLOR24,
8,
8)
if hIml == 0 {
return nil, newError("ImageList_Create failed")
}
return &ImageList{hIml: hIml, maskColor: maskColor}, nil
}
func (il *ImageList) Add(bitmap, maskBitmap *Bitmap) (int, error) {
if bitmap == nil {
return 0, newError("bitmap cannot be nil")
}
var maskHandle HBITMAP
if maskBitmap != nil {
maskHandle = maskBitmap.handle()
}
index := int(ImageList_Add(il.hIml, bitmap.handle(), maskHandle))
if index == -1 {
return 0, newError("ImageList_Add failed")
}
return index, nil
}
func (il *ImageList) AddMasked(bitmap *Bitmap) (int32, error) {
if bitmap == nil {
return 0, newError("bitmap cannot be nil")
}
index := ImageList_AddMasked(
il.hIml,
bitmap.handle(),
COLORREF(il.maskColor))
if index == -1 {
return 0, newError("ImageList_AddMasked failed")
}
return index, nil
}
func (il *ImageList) Dispose() {
if il.hIml != 0 {
ImageList_Destroy(il.hIml)
il.hIml = 0
}
}
func (il *ImageList) MaskColor() Color {
return il.maskColor
}