github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/windows/winc/pen.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 type Pen struct { 15 hPen w32.HPEN 16 style uint 17 brush *Brush 18 } 19 20 func NewPen(style uint, width uint, brush *Brush) *Pen { 21 if brush == nil { 22 panic("Brush cannot be nil") 23 } 24 25 hPen := w32.ExtCreatePen(style, width, brush.GetLOGBRUSH(), 0, nil) 26 if hPen == 0 { 27 panic("Failed to create pen") 28 } 29 30 return &Pen{hPen, style, brush} 31 } 32 33 func NewNullPen() *Pen { 34 lb := w32.LOGBRUSH{LbStyle: w32.BS_NULL} 35 36 hPen := w32.ExtCreatePen(w32.PS_COSMETIC|w32.PS_NULL, 1, &lb, 0, nil) 37 if hPen == 0 { 38 panic("failed to create null brush") 39 } 40 41 return &Pen{hPen: hPen} 42 } 43 44 func (pen *Pen) Style() uint { 45 return pen.style 46 } 47 48 func (pen *Pen) Brush() *Brush { 49 return pen.brush 50 } 51 52 func (pen *Pen) GetHPEN() w32.HPEN { 53 return pen.hPen 54 } 55 56 func (pen *Pen) Dispose() { 57 if pen.hPen != 0 { 58 w32.DeleteObject(w32.HGDIOBJ(pen.hPen)) 59 pen.hPen = 0 60 } 61 }