engine: complete C ABI facade (liboakengine oakengine_* surface)

The full pure-C facade used by the app: node/project/timeline/viewer/
undo/task/events/serializer/playback/preview/renderer/gizmo/color/
audio/footage/proxy/encoding/exporter/config/disk/ipc/plugin/worker
families, plus undo-group semantics, display renderer handles,
NodeFactory accessors, and per-family pure-C engine tests.
This commit is contained in:
2026-07-26 22:43:00 +08:00
parent c486c853ff
commit e9f173916f
80 changed files with 28715 additions and 126 deletions
+268
View File
@@ -0,0 +1,268 @@
/***
Oak - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "oakengine/gizmo.h"
#include <QString>
#include "node/gizmo/draggable.h"
#include "node/gizmo/text.h"
#include "node/generator/text/textv3.h"
#include "node/node.h"
extern "C" {
int oakengine_text_gizmo_get(OakEngineNode *node,
int64_t time_num, int64_t time_den, oakengine_text_gizmo *out)
{
if (!node || !out) {
return OAKENGINE_E_INVALID;
}
auto *textv3 = dynamic_cast<olive::TextGeneratorV3 *>(
reinterpret_cast<olive::Node *>(node));
if (!textv3) {
return OAKENGINE_E_INVALID;
}
olive::TextGizmo *gizmo = textv3->text_gizmo();
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
QRectF r = gizmo->get_rect();
out->rect_x = r.x();
out->rect_y = r.y();
out->rect_w = r.width();
out->rect_h = r.height();
// Map Qt::Alignment to our simple enum
Qt::Alignment va = gizmo->get_vertical_alignment();
if (va & Qt::AlignBottom) {
out->vertical_alignment = 1;
} else if (va & Qt::AlignVCenter) {
out->vertical_alignment = 2;
} else {
out->vertical_alignment = 0; // AlignTop
}
return OAKENGINE_OK;
}
int oakengine_text_gizmo_get_html(OakEngineNode *node,
int64_t time_num, int64_t time_den, char *buf, int buf_size)
{
if (!node) {
return OAKENGINE_E_INVALID;
}
auto *textv3 = dynamic_cast<olive::TextGeneratorV3 *>(
reinterpret_cast<olive::Node *>(node));
if (!textv3) {
return OAKENGINE_E_INVALID;
}
olive::TextGizmo *gizmo = textv3->text_gizmo();
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
QByteArray html = gizmo->get_html().toUtf8();
int needed = html.size() + 1; // include NUL
if (buf && buf_size > 0) {
int copy = qMin(needed, buf_size);
memcpy(buf, html.constData(), copy - 1);
buf[copy - 1] = '\0';
}
return needed;
}
int oakengine_text_gizmo_update_html(OakEngineNode *node,
const char *html, int64_t time_num, int64_t time_den)
{
if (!node || !html) {
return OAKENGINE_E_INVALID;
}
auto *textv3 = dynamic_cast<olive::TextGeneratorV3 *>(
reinterpret_cast<olive::Node *>(node));
if (!textv3) {
return OAKENGINE_E_INVALID;
}
olive::TextGizmo *gizmo = textv3->text_gizmo();
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
gizmo->update_input_html(QString::fromUtf8(html),
olive::core::Rational(time_num, time_den));
return OAKENGINE_OK;
}
int oakengine_text_gizmo_set_vertical_alignment(
OakEngineNode *node, int alignment)
{
if (!node) {
return OAKENGINE_E_INVALID;
}
auto *textv3 = dynamic_cast<olive::TextGeneratorV3 *>(
reinterpret_cast<olive::Node *>(node));
if (!textv3) {
return OAKENGINE_E_INVALID;
}
olive::TextGizmo *gizmo = textv3->text_gizmo();
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
Qt::Alignment va;
switch (alignment) {
case 1:
va = Qt::AlignBottom;
break;
case 2:
va = Qt::AlignVCenter;
break;
default:
va = Qt::AlignTop;
break;
}
gizmo->set_vertical_alignment(va);
return OAKENGINE_OK;
}
int oakengine_text_gizmo_activated(OakEngineNode *node)
{
if (!node) {
return OAKENGINE_E_INVALID;
}
auto *textv3 = dynamic_cast<olive::TextGeneratorV3 *>(
reinterpret_cast<olive::Node *>(node));
if (!textv3) {
return OAKENGINE_E_INVALID;
}
olive::TextGizmo *gizmo = textv3->text_gizmo();
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
emit gizmo->activated();
return OAKENGINE_OK;
}
int oakengine_text_gizmo_deactivated(OakEngineNode *node)
{
if (!node) {
return OAKENGINE_E_INVALID;
}
auto *textv3 = dynamic_cast<olive::TextGeneratorV3 *>(
reinterpret_cast<olive::Node *>(node));
if (!textv3) {
return OAKENGINE_E_INVALID;
}
olive::TextGizmo *gizmo = textv3->text_gizmo();
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
emit gizmo->deactivated();
return OAKENGINE_OK;
}
int oakengine_gizmo_get_drag_value_behavior(void *gizmo)
{
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
auto *dg = dynamic_cast<olive::DraggableGizmo *>(
static_cast<olive::NodeGizmo *>(gizmo));
if (!dg) {
return OAKENGINE_E_INVALID;
}
return static_cast<int>(dg->get_drag_value_behavior());
}
int oakengine_gizmo_drag_start(void *gizmo,
void *row, double abs_x, double abs_y, int64_t time_num,
int64_t time_den)
{
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
auto *dg = dynamic_cast<olive::DraggableGizmo *>(
static_cast<olive::NodeGizmo *>(gizmo));
if (!dg) {
return OAKENGINE_E_INVALID;
}
olive::NodeValueRow empty_row;
olive::NodeValueRow &row_ref = row
? *static_cast<olive::NodeValueRow *>(row)
: empty_row;
dg->drag_start(row_ref, abs_x, abs_y,
olive::core::Rational(time_num, time_den));
return OAKENGINE_OK;
}
int oakengine_gizmo_drag_move(void *gizmo,
double x, double y, int qt_keyboard_modifiers)
{
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
auto *dg = dynamic_cast<olive::DraggableGizmo *>(
static_cast<olive::NodeGizmo *>(gizmo));
if (!dg) {
return OAKENGINE_E_INVALID;
}
dg->drag_move(x, y, Qt::KeyboardModifiers(qt_keyboard_modifiers));
return OAKENGINE_OK;
}
int oakengine_gizmo_drag_end(void *gizmo, void *command)
{
if (!gizmo) {
return OAKENGINE_E_INVALID;
}
auto *dg = dynamic_cast<olive::DraggableGizmo *>(
static_cast<olive::NodeGizmo *>(gizmo));
if (!dg) {
return OAKENGINE_E_INVALID;
}
dg->drag_end(static_cast<olive::MultiUndoCommand *>(command));
return OAKENGINE_OK;
}
} // extern "C"