On 07-06-2019 04:38, Alex X wrote:

I'm either misunderstanding your code or didn't explain what I want well enough or you misunderstood me ;)

I have two widgets where I am drawing stuff to

w1.addOnDraw(&a)
w2.addOnDraw(&b)

Both a and b need to be synchronized though.

addOnDraw may call a and b at drastically different times. I queue them up together but the internal scheduling does not call them together(stuff happens in between).

I could up the frame rate and this might fix things at the cost of unnecessary processing.

What I'd like to do is

just have one draw routine:

w1.addOnDraw(&a)

bool a(Scoped!Context cr, Widget widget)
{
      widget.getWidgetClass().draw(widget.getWidgetStruct(),
cr.getContextStruct());

// Get the context for the the 2nd widget
      cr2 = getContext(w2);

      cr.moveTo(0,0);
      cr.lineTo(100,100);
      cr.stroke();

      cr2.moveTo(0,0);
      cr2.lineTo(100,100);
      cr2.stroke();

      cr2.destroy(); // or whatever it is

      return true;
}

I realize it might not be valid to get the context for another widget outside the draw(it might not exist or whatever) but the idea is to show that above they should be synced together. since the draw routines happen together.

What is happening is that I have two widgets that are suppose to draw something in sync. I queue the routines but they are not called together and one lags the other and it is clearly obvious they are not in sync by the design.

If I upped the frame rate it would make it less obvious I imagine but I'd rather not have it an issue at all.

I'm thinking I might have to rethink my design and it might solve some problems though. I'm drawing in a child drawing area and I might just need to draw in the parent widget and take try to position things properly and it might work. That way everything will definitely be synced. It might work for my application since it is relatively basic.

I misunderstood you.

To draw on a other widget you can use this:

auto gdkWin = otherWidget.getWindow();
auto gdkCx  = gdkWin.beginDrawFrame(gdkWin.getVisibleRegion());
auto cairoCx = gdkCx.getCairoContext();

// Draw to cairoCx.

gdkWin.endDrawFrame();