2023-01-25 09:31:07 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2023-01-25 09:31:07 +08:00
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
2023-06-11 00:10:55 +08:00
|
|
|
"github.com/energye/energy/v2/cef/internal/def"
|
2023-05-31 18:00:34 +08:00
|
|
|
"github.com/energye/energy/v2/common/imports"
|
2022-12-29 22:40:36 +08:00
|
|
|
"github.com/energye/golcl/energy/emfs"
|
2022-12-12 17:34:57 +08:00
|
|
|
"github.com/energye/golcl/lcl/api"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
// ImageRef -> ICefImage
|
|
|
|
var ImageRef image
|
|
|
|
|
|
|
|
// image
|
|
|
|
type image uintptr
|
2022-12-12 17:34:57 +08:00
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
func (m *image) New() *ICefImage {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFImage_New).Call(uintptr(unsafe.Pointer(&result)))
|
2023-03-01 13:38:43 +08:00
|
|
|
return &ICefImage{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
|
|
|
}
|
2022-12-30 14:14:33 +08:00
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
// Instance 实例
|
2022-12-30 14:14:33 +08:00
|
|
|
func (m *ICefImage) Instance() uintptr {
|
|
|
|
return uintptr(m.instance)
|
2022-12-29 22:40:36 +08:00
|
|
|
}
|
|
|
|
|
2023-05-31 17:41:14 +08:00
|
|
|
func (m *ICefImage) IsValid() bool {
|
|
|
|
if m == nil || m.instance == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return m.instance != nil
|
|
|
|
}
|
|
|
|
|
2022-12-29 22:40:36 +08:00
|
|
|
func (m *ICefImage) AddPngFS(scaleFactor float32, filename string) bool {
|
2023-05-31 17:41:14 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
2022-12-29 22:40:36 +08:00
|
|
|
bytes, err := emfs.GetResources(filename)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2023-03-01 13:38:43 +08:00
|
|
|
return m.AddPng(scaleFactor, bytes)
|
2022-12-29 22:40:36 +08:00
|
|
|
}
|
2022-12-12 17:34:57 +08:00
|
|
|
|
|
|
|
func (m *ICefImage) AddPng(scaleFactor float32, png []byte) bool {
|
2023-05-31 17:41:14 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CEFImage_AddPng).Call(m.Instance(), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&png[0])), uintptr(uint32(len(png))))
|
2022-12-12 17:34:57 +08:00
|
|
|
return api.GoBool(r1)
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
func (m *ICefImage) AddJpegFS(scaleFactor float32, filename string) bool {
|
2023-05-31 17:41:14 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
2023-03-01 13:38:43 +08:00
|
|
|
bytes, err := emfs.GetResources(filename)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return m.AddJpeg(scaleFactor, bytes)
|
|
|
|
}
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *ICefImage) AddJpeg(scaleFactor float32, jpeg []byte) bool {
|
2023-05-31 17:41:14 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CEFImage_AddJpeg).Call(m.Instance(), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&jpeg[0])), uintptr(uint32(len(jpeg))))
|
2022-12-12 17:34:57 +08:00
|
|
|
return api.GoBool(r1)
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
func (m *ICefImage) Width() int32 {
|
2023-05-31 17:41:14 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return 0
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CEFImage_GetWidth).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
return int32(r1)
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
func (m *ICefImage) Height() int32 {
|
2023-05-31 17:41:14 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return 0
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CEFImage_GetHeight).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
return int32(r1)
|
|
|
|
}
|
2023-03-14 22:20:08 +08:00
|
|
|
|
|
|
|
func (m *ICefImage) Free() {
|
|
|
|
if m.instance != nil {
|
|
|
|
m.base.Free(m.Instance())
|
|
|
|
m.instance = nil
|
|
|
|
}
|
|
|
|
}
|