English 中文(简体)
gjs cairo背景,没有出现在cl窗上
原标题:gjs cairo context drawing not displaying in clutter window

I m试图利用捆绑的 j脚带进入一个cl窗。 我的问题是,除了略为不同的名称的一半职能外,不管我所尝试的是什么,热罗图也没有显示。 我利用了奏效的猪的榜样,并把它放到 j。 I m还利用外推测获得Clutter模块检查。 I m还使用0.7.14的js版本。 任何人都能够告诉我什么是错的。

下面是使用Im的范例。


const cairo = imports.cairo;
const clutter =  imports.gi.Clutter;

function on_button_press_event (stage, event) {
    clutter.main_quit();
}

function draw(cairo_tex) {
    var context = cairo_tex.create();


    context.scale(200, 200);
    context.setLineWidth(0.1);
    var colour2 = new clutter.Color();
    colour2.from_string( #dd000088 );
    clutter.cairo_set_source_color(context, colour2);
    context.translate(0.5, 0.5);
    context.arc(0, 0, 0.4, 0, Math.PI * 2);
    context.stroke();
}

function main () {
    clutter.init(0, null);
    var stage = new clutter.Stage();
    var colour = new clutter.Color();
    colour.from_string("#ffccccff");
    stage.set_color(colour);
    stage.set_size(400, 300);
    stage.connect( button-press-event ,  on_button_press_event);
    stage.connect( destroy , clutter.main_quit);

    var cairo_tex = new clutter.CairoTexture.new(200, 200);
    cairo_tex.set_position((stage.get_width() - 200) / 2,
                       (stage.get_height() - 200) / 2);

    draw(cairo_tex);


    var center_x = cairo_tex.get_width() / 2;
    var center_z = cairo_tex.get_height() / 2;
    cairo_tex.set_rotation(clutter.AlignAxis.Y_AXIS, 45.0, center_x, 0, center_z);
    stage.add_actor(cairo_tex);
    cairo_tex.show();

    stage.show();

    clutter.main();
}

main();

I think the reason this is not working has to do with the deletion of the cairo context in javascript. context.destroy does not exist and using delete doesn t either. Infact if I use delete then I get the warning

WARNING:  applying the  delete  operator to an unqualified name is deprecated 

这根本无助于。 根据参与j的有些开发商所公布的情况,分配到无效的,由于其垃圾收集,应当产生同样的效果。 我怀疑在幕后是否有东西可以收集。

如果说情况确实如此,那么我会接受这一说法。

最新资料:

我将问题领域缩小到进口。 我尝试了另一个例子,但这次使用Gtk而不是Clutter,以下守则实际上行之有效。

cairo = imports.cairo;
Gtk = imports.gi.Gtk;
Gdk = imports.gi.Gdk;

function draw_arc(drawing_area){
    var cr = Gdk.cairo_create(drawing_area.get_window());

    cr.scale(2, 2);

    cr.operator = cairo.Operator.CLEAR;
    cr.paint();
    cr.operator = cairo.Operator.OVER;

    cr.setSourceRGB(0,255,0);
    cr.arc(128, 128, 76.8, 0, 2*Math.PI);
    cr.fill();

    return false;
}

Gtk.init(0, null);

var w = new Gtk.Window();
w.connect( delete-event , Gtk.main_quit);

var d = new Gtk.DrawingArea();
w.add(d);

w.resize(500,600);
w.decorated = false;

d.connect( draw , draw_arc);

w.show_all();
Gtk.main();

这使我相信,问题不在于执行盖罗,而在于执行Clutter开罗会议的投机方法。 我现在想到这一点。 CairoTexture.new or clutter. 《开罗协议》没有适当执行。 我怀疑这是utter。 CairoTexture.create, which is caused the problem.

最佳回答

利用Clutter与开罗之间的新融合,特别是Clutter.Canvas,这将吸引一个圈子:

const Clutter = imports.gi.Clutter;
const Cairo = imports.cairo;

const draw_stuff = function (canvas, cr, width, height) {
    cr.save ();
    cr.setOperator (Cairo.Operator.CLEAR);
    cr.paint ();
    cr.restore ();
    cr.setOperator (Cairo.Operator.OVER);
    cr.scale (width, height);
    cr.setLineCap (Cairo.LineCap.ROUND);
    cr.setLineWidth (0.1);

    cr.translate (0.5, 0.5);
    cr.arc (0, 0, 0.4, 0, Math.PI * 2);
    cr.stroke ();

    return true;
};

const test = function () {
    Clutter.init(null);

    let stage = new Clutter.Stage();
    stage.set_title ("Circle!");

    let color = new Clutter.Color({
        red : 255,
        green : 0,
        blue : 0,
        alpha : 128 // Just for the heck of it.
});
stage.set_background_color(color);
stage.set_size(300, 300);

let canvas = new Clutter.Canvas ();
canvas.set_size (155, 155);

let dummy = new Clutter.Actor ();
dummy.set_content (canvas);
dummy.set_size(155, 155);
stage.add_child (dummy);

stage.connect ("destroy", Clutter.main_quit);
canvas.connect ("draw", draw_stuff);
canvas.invalidate ();
stage.show_all();

Clutter.main ();
};

test ();
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签