-
Notifications
You must be signed in to change notification settings - Fork 4
/
julia_canvas.cpp
43 lines (32 loc) · 1.05 KB
/
julia_canvas.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <QDebug>
#include <QPainter>
#include <QQuickWindow>
#include "foreign_thread_manager.hpp"
#include "julia_canvas.hpp"
namespace qmlwrap
{
JuliaCanvas::JuliaCanvas(QQuickItem *parent) : QQuickPaintedItem(parent)
{
}
void JuliaCanvas::paint(QPainter *painter)
{
ForeignThreadManager::instance().add_thread(QThread::currentThread());
// allocate buffer for julia callback to draw on
int iwidth = width();
int iheight = height();
unsigned int *draw_buffer = new unsigned int[iwidth * iheight];
// call julia painter
m_callback(jlcxx::make_julia_array(draw_buffer, iwidth*iheight), iwidth, iheight);
// make QImage
QImage *image = new QImage((uchar*)draw_buffer, width(), height(), QImage::Format_ARGB32);
// paint the image onto the QuickPaintedItem
painter->drawImage(0, 0, *image);
// free the QImage and the draw buffer
delete image;
delete[] draw_buffer;
}
void JuliaCanvas::setPaintFunction(jlcxx::SafeCFunction f)
{
m_callback = jlcxx::make_function_pointer<void(jlcxx::ArrayRef<uint>, int, int)>(f);
}
} // namespace qmlwrap