Ready to fix some problems on linux

This commit is contained in:
杨红岩 2022-12-29 22:40:36 +08:00
parent 84e490ff69
commit 7efeb6aa85
6 changed files with 69 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package cef
import (
. "github.com/energye/energy/common"
"github.com/energye/golcl/energy/emfs"
"github.com/energye/golcl/lcl/api"
"unsafe"
)
@ -10,12 +11,21 @@ type ICefImage struct {
instance unsafe.Pointer
}
//func NewImage() *ICefImage {
// r1, _, _ := Proc(internale_CEFImage_New).Call()
// return &ICefImage{
// instance: unsafe.Pointer(r1),
// }
//}
func NewImage() *ICefImage {
r1, _, _ := Proc(internale_CEFImage_New).Call()
return &ICefImage{
instance: unsafe.Pointer(r1),
}
}
func (m *ICefImage) AddPngFS(scaleFactor float32, filename string) bool {
bytes, err := emfs.GetResources(filename)
if err != nil {
return false
}
r1, _, _ := Proc(internale_CEFImage_AddPng).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(uint32(len(bytes))))
return api.GoBool(r1)
}
func (m *ICefImage) AddPng(scaleFactor float32, png []byte) bool {
r1, _, _ := Proc(internale_CEFImage_AddPng).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&png[0])), uintptr(int32(len(png))))

View File

@ -376,7 +376,11 @@ func init() {
dllimports.NewEnergyImport("CEFWindowComponent_SetTitle", 0),
dllimports.NewEnergyImport("CEFWindowComponent_Title", 0),
dllimports.NewEnergyImport("CEFWindowComponent_WindowIcon", 0),
dllimports.NewEnergyImport("CEFWindowComponent_SetWindowIcon", 0),
dllimports.NewEnergyImport("CEFWindowComponent_SetWindowIconImage", 0),
dllimports.NewEnergyImport("CEFWindowComponent_WindowAppIcon", 0),
dllimports.NewEnergyImport("CEFWindowComponent_SetWindowAppIcon", 0),
dllimports.NewEnergyImport("CEFWindowComponent_SetWindowAppIconImage", 0),
dllimports.NewEnergyImport("CEFWindowComponent_Display", 0),
dllimports.NewEnergyImport("CEFWindowComponent_ClientAreaBoundsInScreen", 0),
dllimports.NewEnergyImport("CEFWindowComponent_WindowHandle", 0),
@ -789,7 +793,11 @@ const (
internale_CEFWindowComponent_SetTitle
internale_CEFWindowComponent_Title
internale_CEFWindowComponent_WindowIcon
internale_CEFWindowComponent_SetWindowIcon
internale_CEFWindowComponent_SetWindowIconImage
internale_CEFWindowComponent_WindowAppIcon
internale_CEFWindowComponent_SetWindowAppIcon
internale_CEFWindowComponent_SetWindowAppIconImage
internale_CEFWindowComponent_Display
internale_CEFWindowComponent_ClientAreaBoundsInScreen
internale_CEFWindowComponent_WindowHandle

View File

@ -5,6 +5,7 @@ import (
. "github.com/energye/energy/common"
"github.com/energye/energy/consts"
"github.com/energye/energy/logger"
"github.com/energye/golcl/energy/emfs"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/api"
"unsafe"
@ -122,6 +123,20 @@ func (m *TCEFWindowComponent) WindowIcon() *ICefImage {
}
}
func (m *TCEFWindowComponent) SetWindowIconImage(icon *ICefImage) error {
Proc(internale_CEFWindowComponent_SetWindowIconImage).Call(uintptr(m.instance), uintptr(icon.instance))
return nil
}
func (m *TCEFWindowComponent) SetWindowIcon(scaleFactor float32, filename string) error {
bytes, err := emfs.GetResources(filename)
if err != nil {
return err
}
Proc(internale_CEFWindowComponent_SetWindowIcon).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
return nil
}
func (m *TCEFWindowComponent) WindowAppIcon() *ICefImage {
var ret uintptr
Proc(internale_CEFWindowComponent_WindowAppIcon).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&ret)))
@ -130,6 +145,20 @@ func (m *TCEFWindowComponent) WindowAppIcon() *ICefImage {
}
}
func (m *TCEFWindowComponent) SetWindowAppIcon(scaleFactor float32, filename string) error {
bytes, err := emfs.GetResources(filename)
if err != nil {
return err
}
Proc(internale_CEFWindowComponent_SetWindowAppIcon).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
return nil
}
func (m *TCEFWindowComponent) SetWindowAppIconImage(icon *ICefImage) error {
Proc(internale_CEFWindowComponent_SetWindowAppIconImage).Call(uintptr(m.instance), uintptr(icon.instance))
return nil
}
func (m *TCEFWindowComponent) Display() *ICefDisplay {
var ret uintptr
Proc(internale_CEFWindowComponent_Display).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&ret)))

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -1,6 +1,7 @@
package main
import (
"embed"
"fmt"
"github.com/energye/energy/cef"
"github.com/energye/energy/common"
@ -9,8 +10,11 @@ import (
"github.com/energye/golcl/lcl"
)
//go:embed resources
var resources embed.FS
func main() {
inits.Init(nil, nil)
inits.Init(nil, &resources)
fmt.Println("main", common.Args.ProcessType())
config := cef.NewApplicationConfig()
@ -38,8 +42,9 @@ func main() {
})
chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, client *cef.ICefClient, noJavascriptAccess *bool) bool {
fmt.Println("OnBeforePopup")
return true
return false
})
windowComponent.SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
fmt.Println("OnWindowCreated")
b := chromium.CreateBrowserByBrowserViewComponent("https://www.baidu.com", browserViewComponent)
@ -50,7 +55,16 @@ func main() {
fmt.Println("\t", display.Bounds(), display.WorkArea())
windowComponent.CenterWindow(cef.NewCefSize(1024, 768))
browserViewComponent.RequestFocus()
image := cef.NewImage()
fs := image.AddPngFS(1, "resources/icon.png")
fmt.Println("image", image, fs)
windowComponent.SetWindowIcon(1, "resources/icon.png")
windowComponent.SetWindowAppIcon(1, "resources/icon.png")
windowComponent.SetWindowAppIconImage(image)
windowComponent.Show()
icon := windowComponent.WindowIcon()
appIcon := windowComponent.WindowAppIcon()
fmt.Println("WindowIcon", icon, appIcon)
})
windowComponent.SetOnCanClose(func(sender lcl.IObject, window *cef.ICefWindow, aResult *bool) {
fmt.Println("OnCanClose")