github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/windows/winc/brush.go (about) 1 //go:build windows 2 3 /* 4 * Copyright (C) 2019 The Winc Authors. All Rights Reserved. 5 * Copyright (C) 2010-2013 Allen Dang. All Rights Reserved. 6 */ 7 8 package winc 9 10 import ( 11 "github.com/secoba/wails/v2/internal/frontend/desktop/windows/winc/w32" 12 ) 13 14 var DefaultBackgroundBrush = NewSystemColorBrush(w32.COLOR_BTNFACE) 15 16 type Brush struct { 17 hBrush w32.HBRUSH 18 logBrush w32.LOGBRUSH 19 } 20 21 func NewSolidColorBrush(color Color) *Brush { 22 lb := w32.LOGBRUSH{LbStyle: w32.BS_SOLID, LbColor: w32.COLORREF(color)} 23 hBrush := w32.CreateBrushIndirect(&lb) 24 if hBrush == 0 { 25 panic("Faild to create solid color brush") 26 } 27 28 return &Brush{hBrush, lb} 29 } 30 31 func NewSystemColorBrush(colorIndex int) *Brush { 32 //lb := w32.LOGBRUSH{LbStyle: w32.BS_SOLID, LbColor: w32.COLORREF(colorIndex)} 33 lb := w32.LOGBRUSH{LbStyle: w32.BS_NULL} 34 hBrush := w32.GetSysColorBrush(colorIndex) 35 if hBrush == 0 { 36 panic("GetSysColorBrush failed") 37 } 38 return &Brush{hBrush, lb} 39 } 40 41 func NewHatchedColorBrush(color Color) *Brush { 42 lb := w32.LOGBRUSH{LbStyle: w32.BS_HATCHED, LbColor: w32.COLORREF(color)} 43 hBrush := w32.CreateBrushIndirect(&lb) 44 if hBrush == 0 { 45 panic("Faild to create solid color brush") 46 } 47 48 return &Brush{hBrush, lb} 49 } 50 51 func NewNullBrush() *Brush { 52 lb := w32.LOGBRUSH{LbStyle: w32.BS_NULL} 53 hBrush := w32.CreateBrushIndirect(&lb) 54 if hBrush == 0 { 55 panic("Failed to create null brush") 56 } 57 58 return &Brush{hBrush, lb} 59 } 60 61 func (br *Brush) GetHBRUSH() w32.HBRUSH { 62 return br.hBrush 63 } 64 65 func (br *Brush) GetLOGBRUSH() *w32.LOGBRUSH { 66 return &br.logBrush 67 } 68 69 func (br *Brush) Dispose() { 70 if br.hBrush != 0 { 71 w32.DeleteObject(w32.HGDIOBJ(br.hBrush)) 72 br.hBrush = 0 73 } 74 }