void Fl_Cairo_Window_Wrapper::draw_cb(Fl_Cairo_Window *self, cairo_t *ctx) {
  Dart_PersistentHandle *ref = (Dart_PersistentHandle*)self -> user_data();

  // Create instance of CairoContext.
  Dart_Handle dartCairoContextType = HandleError(Dart_GetType(
                                       Dart_LookupLibrary(
                                         Dart_NewStringFromCString("package:fltk/fltk.dart")),
                                       Dart_NewStringFromCString("CairoContext"), 0, {}));
  Dart_Handle dartCairoContext = Dart_New(
                                   dartCairoContextType, Dart_EmptyString(), 0, {});

  // Link cairo context to CairoContext.
  Dart_SetNativeInstanceField(dartCairoContext, 0, (intptr_t)ctx);

  Dart_Handle args[1] = { dartCairoContext };
  HandleError(Dart_Invoke(*ref, Dart_NewStringFromCString("runDrawCb"), 1, args));
}
示例#2
0
void VM::loadCinderDartLib()
{
	string script = getCinderDartScript();
	Dart_Handle source = toDart( script );
	CIDART_CHECK( source );

	Dart_Handle cinderDartLib = Dart_LoadLibrary( toDart( "cinder.dart" ), source, 0, 0 );
	if( Dart_IsError( cinderDartLib ) ) {
		throw DartException( string( "failed to load cinder.dart, error message: " ) + Dart_GetError( cinderDartLib ) );
	}

	CIDART_CHECK( Dart_SetNativeResolver( cinderDartLib, Script::resolveNameHandler, NULL ) );

	// finalize any scripts loaded, needs to be done before the libs can be looked up and modified below
	CIDART_CHECK( Dart_FinalizeLoading( false ) );

	// swap in custom _printClosure to enable print() in dart
	Dart_Handle internalLib = Dart_LookupLibrary( toDart( "dart:_internal" ) );
	CIDART_CHECK( internalLib );
	Dart_Handle print = Dart_GetField( cinderDartLib, toDart( "_printClosure" ) );
	CIDART_CHECK( print );
	CIDART_CHECK( Dart_SetField( internalLib, toDart( "_printClosure" ), print ) );
}