mirror of
https://github.com/gosticks/gml.git
synced 2025-10-16 12:05:33 +00:00
starting to add imgprov
This commit is contained in:
parent
69da1a8f9a
commit
137b2624e1
2
TODO.md
2
TODO.md
@ -2,10 +2,8 @@
|
|||||||
- finish verbose mode
|
- finish verbose mode
|
||||||
- set core.QCoreApplication_SetApplicationName("App") core.QCoreApplication_SetOrganizationName("Desertbit")
|
- set core.QCoreApplication_SetApplicationName("App") core.QCoreApplication_SetOrganizationName("Desertbit")
|
||||||
- ImageProvider
|
- ImageProvider
|
||||||
- RunInEventLoop
|
|
||||||
- signals & slots
|
- signals & slots
|
||||||
- docker container
|
- docker container
|
||||||
- resources
|
|
||||||
- call qml slots directly from go
|
- call qml slots directly from go
|
||||||
- dp for pixels
|
- dp for pixels
|
||||||
- document, that slot names must not overlap with QObject names!
|
- document, that slot names must not overlap with QObject names!
|
||||||
90
imageprovider.go
Normal file
90
imageprovider.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* GML - Go QML
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Roland Singer <roland.singer[at]desertbit.com>
|
||||||
|
* Copyright (c) 2019 Sebastian Borchers <sebastian[at]desertbit.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package gml
|
||||||
|
|
||||||
|
// #include <gml.h>
|
||||||
|
//
|
||||||
|
// extern void gml_imageprovider_request_go_slot(void* goPtr, char* id);
|
||||||
|
// static void gml_imageprovider_init() {
|
||||||
|
// gml_imageprovider_request_cb_register(gml_imageprovider_request_go_slot);
|
||||||
|
// }
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/desertbit/gml/pointer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
C.gml_imageprovider_init()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImageProvider struct {
|
||||||
|
freed bool
|
||||||
|
ptr C.gml_imageprovider
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewImageProvider() *ImageProvider {
|
||||||
|
ip := &ImageProvider{}
|
||||||
|
ip.ptr = C.gml_imageprovider_new()
|
||||||
|
|
||||||
|
// Always free the C++ value.
|
||||||
|
runtime.SetFinalizer(ip, freeImageProvider)
|
||||||
|
|
||||||
|
// Check if something failed.
|
||||||
|
// This should never happen is signalizes a fatal error.
|
||||||
|
if ip.ptr == nil {
|
||||||
|
panic(fmt.Errorf("failed to create gml imageprovider: C pointer is nil"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|
||||||
|
func freeImageProvider(ip *ImageProvider) {
|
||||||
|
if ip.freed {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ip.freed = true
|
||||||
|
C.gml_imageprovider_free(ip.ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ip *ImageProvider) Free() {
|
||||||
|
freeImageProvider(ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
//#####################//
|
||||||
|
//### Exported to C ###//
|
||||||
|
//#####################//
|
||||||
|
|
||||||
|
//export gml_imageprovider_request_go_slot
|
||||||
|
func gml_imageprovider_request_go_slot(goPtr unsafe.Pointer, id *C.char) {
|
||||||
|
f := (pointer.Restore(goPtr)).(func())
|
||||||
|
f()
|
||||||
|
}
|
||||||
@ -34,5 +34,6 @@
|
|||||||
#include "gml_app.h"
|
#include "gml_app.h"
|
||||||
#include "gml_object.h"
|
#include "gml_object.h"
|
||||||
#include "gml_variant.h"
|
#include "gml_variant.h"
|
||||||
|
#include "gml_imageprovider.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
47
internal/binding/headers/gml_imageprovider.h
Normal file
47
internal/binding/headers/gml_imageprovider.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* GML - Go QML
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Roland Singer <roland.singer[at]desertbit.com>
|
||||||
|
* Copyright (c) 2019 Sebastian Borchers <sebastian[at]desertbit.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GML_HEADER_IMAGEPROVIDER_H
|
||||||
|
#define GML_HEADER_IMAGEPROVIDER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef void* gml_imageprovider;
|
||||||
|
|
||||||
|
typedef void (*gml_imageprovider_request_cb_t)(void* _go_ptr, char* id);
|
||||||
|
void gml_imageprovider_request_cb_register(gml_imageprovider_request_cb_t cb);
|
||||||
|
|
||||||
|
gml_imageprovider gml_imageprovider_new();
|
||||||
|
void gml_imageprovider_free(gml_imageprovider ip);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
93
internal/binding/sources/gml_imageprovider.cpp
Normal file
93
internal/binding/sources/gml_imageprovider.cpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* GML - Go QML
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Roland Singer <roland.singer[at]desertbit.com>
|
||||||
|
* Copyright (c) 2019 Sebastian Borchers <sebastian[at]desertbit.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gml_imageprovider.h"
|
||||||
|
|
||||||
|
//########################//
|
||||||
|
//### Static Variables ###//
|
||||||
|
//########################//
|
||||||
|
|
||||||
|
gml_imageprovider_request_cb_t gml_imageprovider_request_cb = NULL;
|
||||||
|
|
||||||
|
//#############//
|
||||||
|
//### C API ###//
|
||||||
|
//#############//
|
||||||
|
|
||||||
|
void gml_imageprovider_request_cb_register(gml_imageprovider_request_cb_t cb) {
|
||||||
|
gml_imageprovider_request_cb = cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
gml_imageprovider gml_imageprovider_new() {
|
||||||
|
try {
|
||||||
|
GmlImageProvider* gip = new GmlImageProvider();
|
||||||
|
return (void*)gip;
|
||||||
|
}
|
||||||
|
catch (std::exception& e) {
|
||||||
|
//api_error_set_msg(err, e.what()); TODO:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
//api_error_set_unknown_msg(err); TODO:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gml_imageprovider_free(gml_imageprovider ip) {
|
||||||
|
if (ip == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GmlImageProvider* gip = (GmlImageProvider*)ip;
|
||||||
|
delete gip;
|
||||||
|
ip = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//###################################//
|
||||||
|
//### GmlAsyncImageResponse Class ###//
|
||||||
|
//###################################//
|
||||||
|
|
||||||
|
GmlAsyncImageResponse::GmlAsyncImageResponse(
|
||||||
|
const QString &id,
|
||||||
|
const QSize &requestedSize
|
||||||
|
) {
|
||||||
|
// Call to go.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QQuickTextureFactory* GmlAsyncImageResponse::textureFactory() const {
|
||||||
|
return QQuickTextureFactory::textureFactoryForImage(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
//###########################//
|
||||||
|
//### ImageProvider Class ###//
|
||||||
|
//###########################//
|
||||||
|
|
||||||
|
QQuickImageResponse* GmlImageProvider::requestImageResponse(
|
||||||
|
const QString &id,
|
||||||
|
const QSize &requestedSize
|
||||||
|
) {
|
||||||
|
return new GmlAsyncImageResponse(id, requestedSize);
|
||||||
|
};
|
||||||
56
internal/binding/sources/gml_imageprovider.h
Normal file
56
internal/binding/sources/gml_imageprovider.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* GML - Go QML
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Roland Singer <roland.singer[at]desertbit.com>
|
||||||
|
* Copyright (c) 2019 Sebastian Borchers <sebastian[at]desertbit.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GML_IMAGEPROVIDER_H
|
||||||
|
#define GML_IMAGEPROVIDER_H
|
||||||
|
|
||||||
|
#include "gml_includes.h"
|
||||||
|
|
||||||
|
class GmlAsyncImageResponse : public QQuickImageResponse
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GmlAsyncImageResponse(
|
||||||
|
const QString &id,
|
||||||
|
const QSize &requestedSize
|
||||||
|
);
|
||||||
|
|
||||||
|
QQuickTextureFactory *textureFactory() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QImage img;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GmlImageProvider : public QQuickAsyncImageProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QQuickImageResponse* requestImageResponse(
|
||||||
|
const QString &id,
|
||||||
|
const QSize &requestedSize
|
||||||
|
) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -40,6 +40,10 @@
|
|||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QQuickTextureFactory>
|
||||||
|
#include <QQuickAsyncImageProvider>
|
||||||
|
#include <QQuickImageResponse>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
|||||||
@ -54,15 +54,6 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = app.AddImportPath("qrc://qml/")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
err = app.AddImportPath("qrc://resources/")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
b := &Bridge{}
|
b := &Bridge{}
|
||||||
b.GMLInit()
|
b.GMLInit()
|
||||||
err = app.SetContextProperty("bridge", b)
|
err = app.SetContextProperty("bridge", b)
|
||||||
@ -70,7 +61,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = app.Load("qrc:/main.qml")
|
err = app.Load("qrc:/qml/main.qml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user