Memo : Flutter x Dart [2015-2016]
  • Introduction
  • hello
    • helloworld
    • build flutter
    • build as standalone android app(old)
      • draw text
      • draw image
      • set icon
    • build as standalone apk(now)
    • build as ios app
    • build as linux app
    • build as mac app
    • build mojo
    • build as chromeapp
  • rendering
    • draw_rect
    • anime_rect
    • anime_rect(use animation.dart)
    • draw_image
    • rotate_image
    • draw_image_from_assets
    • sound_test(rendering & service)
    • touch_test
    • multitouch_test
    • [@]demo::mini game(spacewar!)
    • draw_text
    • draw_path
    • draw_vertexs
    • draw_vertexs_with_image
    • [@]demo:3d anime
    • input text from ime(RenderObject)
  • widget
    • text
    • network image
    • assets image
    • raw image
    • container
    • row
    • col
    • flexible
    • navigator
    • stateful component
    • scaffold
    • scaffold x drawer
    • scrollable viewport
    • scrollable list
    • input text from ime(EditableText)
  • dart:io
    • HttpClient Post & Get
    • NetworkInterface
    • TCP Socket
    • UDP Socket
    • File Path(dart:io & service)
    • File Create & Permission
  • dart:ui
    • draw rect
    • pointer event
  • mojo for flutter
    • get and post request
    • sensor test
    • [@]demo:gravity sensor
  • 2d physics for scratch
    • collision without rotation
    • [@]democollision without friction
    • [b]
  • 2d physics for newton
  • mojo for native
    • build mojo
  • 48 hour trial
    • create iron heart
    • tiny tetris
Powered by GitBook
On this page

Was this helpful?

  1. rendering

draw_vertexs_with_image

Previousdraw_vertexsNext[@]demo:3d anime

Last updated 5 years ago

Was this helpful?

// following code is checked in 2016/01/13
// failed to draw vertex now!!
import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
import 'dart:ui' as sky;
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/src/services/fetch.dart';
import 'package:flutter/services.dart';

sky.Image img = null;
main() async {
  // "assets/icon.jpeg" is error 2015/12/13 's flutter, when draw image
  img = await ImageLoader.load("assets/a.png");
  runApp(new DrawVertexsWidget());
}

class DrawVertexsWidget extends OneChildRenderObjectWidget {
  RenderObject createRenderObject() {
    return new DrawVertexsObject();
  }
}

class DrawVertexsObject extends RenderBox {
  void paint(PaintingContext context, Offset offset) {
    context.canvas.translate(50.0, 50.0);
    context.canvas.scale(8.0, 8.0);
    paintWithImage(context, offset);
  }

  void paintWithImage(PaintingContext context, Offset offset) {
    Paint paint = new Paint();
    sky.VertexMode vertexMode = sky.VertexMode.triangleFan;
    List<Point> vertices = [
      new Point(0.0, 0.0),
      new Point(10.0, 50.0),
      new Point(50.0, 60.0),
      new Point(40.0, 10.0)
    ];
    List<Point> textureCoordinates = [
      new Point(0.0, 0.0),
      new Point(0.0, 1.0 * img.height),
      new Point(1.0 * img.width, 1.0 * img.height),
      new Point(1.0 * img.width, 0.0)
    ];
    List<Color> colors = [
      const Color.fromARGB(0xaa, 0x00, 0x00, 0xff),
      const Color.fromARGB(0xaa, 0x00, 0x00, 0xff),
      const Color.fromARGB(0xaa, 0x00, 0x00, 0xff),
      const Color.fromARGB(0xaa, 0x00, 0x00, 0xff)
    ];
    sky.TransferMode transferMode = sky.TransferMode.color;
    sky.TileMode tmx = sky.TileMode.clamp;
    sky.TileMode tmy = sky.TileMode.clamp;
    Float64List matrix4 = new Matrix4.identity().storage;
    sky.ImageShader imgShader = new sky.ImageShader(img, tmx, tmy, matrix4);
    paint.shader = imgShader;
    List<int> indicies = [0, 1, 2, 3];
    context.canvas.drawVertices(vertexMode, vertices, textureCoordinates,
        colors, transferMode, indicies, paint);
  }
}

AssetBundle getAssetBundle() {
  if (rootBundle != null) {
    return rootBundle;
  } else {
    return new NetworkAssetBundle(new Uri.directory(Uri.base.origin));
  }
}

class ImageLoader {
  static Future<sky.Image> load(String url) async {
    AssetBundle bundle = getAssetBundle();
    ImageResource resource = bundle.loadImage(url);
    return resource.first;
  }
}
# flutter.yaml
assets:
  - assets/icon.jpeg
  - assets/a.png
https://github.com/kyorohiro/hello_skyengine/tree/master/draw_vertices_1