energy/cef/types-image.go

107 lines
2.4 KiB
Go
Raw Normal View History

2023-01-25 09:31:07 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// 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
//
//----------------------------------------
package cef
import (
"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"
"github.com/energye/golcl/lcl/api"
"unsafe"
)
2023-03-01 13:38:43 +08:00
// ImageRef -> ICefImage
var ImageRef image
// image
type image uintptr
2023-03-01 13:38:43 +08:00
func (m *image) New() *ICefImage {
var result uintptr
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
}
func (m *ICefImage) AddPng(scaleFactor float32, png []byte) bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFImage_AddPng).Call(m.Instance(), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&png[0])), uintptr(uint32(len(png))))
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)
}
func (m *ICefImage) AddJpeg(scaleFactor float32, jpeg []byte) bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFImage_AddJpeg).Call(m.Instance(), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&jpeg[0])), uintptr(uint32(len(jpeg))))
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
}
r1, _, _ := imports.Proc(def.CEFImage_GetWidth).Call(m.Instance())
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
}
r1, _, _ := imports.Proc(def.CEFImage_GetHeight).Call(m.Instance())
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
}
}