-
Notifications
You must be signed in to change notification settings - Fork 30
/
imageview.go
57 lines (45 loc) · 1.09 KB
/
imageview.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
/*
* Copyright (C) 2019 The Winc Authors. All Rights Reserved.
*/
package winc
import "github.com/tadvi/winc/w32"
type ImageView struct {
ControlBase
bmp *Bitmap
}
func NewImageView(parent Controller) *ImageView {
iv := new(ImageView)
iv.InitWindow("winc_ImageView", parent, w32.WS_EX_CONTROLPARENT, w32.WS_CHILD|w32.WS_VISIBLE)
RegMsgHandler(iv)
iv.SetFont(DefaultFont)
iv.SetText("")
iv.SetSize(200, 65)
return iv
}
func (iv *ImageView) DrawImageFile(filepath string) error {
bmp, err := NewBitmapFromFile(filepath, RGB(255, 255, 0))
if err != nil {
return err
}
iv.bmp = bmp
return nil
}
func (iv *ImageView) DrawImage(bmp *Bitmap) {
iv.bmp = bmp
}
func (iv *ImageView) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_SIZE, w32.WM_SIZING:
iv.Invalidate(true)
case w32.WM_ERASEBKGND:
return 1 // important
case w32.WM_PAINT:
if iv.bmp != nil {
canvas := NewCanvasFromHwnd(iv.hwnd)
defer canvas.Dispose()
iv.SetSize(iv.bmp.Size())
canvas.DrawBitmap(iv.bmp, 0, 0)
}
}
return w32.DefWindowProc(iv.hwnd, msg, wparam, lparam)
}