Merge branch 'flutter'
14
examples/BUILD.gn
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
group("examples") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"//examples/fitness",
|
||||
"//examples/game",
|
||||
"//examples/mine_digger",
|
||||
"//examples/stocks",
|
||||
]
|
||||
}
|
||||
23
examples/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
Flutter Examples
|
||||
================
|
||||
|
||||
This directory contains several examples of using Flutter. Each of these is an
|
||||
individual Dart application package.
|
||||
|
||||
To run a sample with the `flutter` tool, run `pub get` inside its directory,
|
||||
then run `flutter start`. (See the
|
||||
[getting started guide](https://flutter.github.io/getting-started/) to install
|
||||
the `flutter` tool.)
|
||||
|
||||
Available examples include:
|
||||
|
||||
- *Hello, world.* The [hello world app](hello_world) is a basic app that shows
|
||||
the text "hello, world."
|
||||
|
||||
- *Stocks.* The [stocks app](stocks) is an example of a typical mobile app
|
||||
built using Flutter. The app shows a list of all the stocks in the NASDAQ.
|
||||
|
||||
- *Widgets.* The [widget apps](widgets) demonstrate a number of Flutter widgets
|
||||
so you can experiment with them in a simple container. There is no main.dart
|
||||
in this directory because each file is a standalone sample. To run a
|
||||
particular file, use `flutter start -t filename.dart`.
|
||||
12
examples/address_book/flutter.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
name: address_book
|
||||
version: 0.0.2
|
||||
material-design-icons:
|
||||
- name: av/volume_up
|
||||
- name: communication/email
|
||||
- name: communication/phone
|
||||
- name: content/add
|
||||
- name: image/photo_camera
|
||||
- name: maps/place
|
||||
- name: navigation/check
|
||||
- name: navigation/arrow_back
|
||||
- name: social/person
|
||||
98
examples/address_book/lib/main.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Field extends StatelessComponent {
|
||||
Field({
|
||||
Key key,
|
||||
this.inputKey,
|
||||
this.icon,
|
||||
this.placeholder
|
||||
}) : super(key: key);
|
||||
|
||||
final GlobalKey inputKey;
|
||||
final String icon;
|
||||
final String placeholder;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Row(<Widget>[
|
||||
new Padding(
|
||||
padding: const EdgeDims.symmetric(horizontal: 16.0),
|
||||
child: new Icon(icon: icon)
|
||||
),
|
||||
new Flexible(
|
||||
child: new Input(
|
||||
key: inputKey,
|
||||
placeholder: placeholder
|
||||
)
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AddressBookHome extends StatelessComponent {
|
||||
Widget buildToolBar(BuildContext context) {
|
||||
return new ToolBar(
|
||||
left: new IconButton(icon: "navigation/arrow_back"),
|
||||
right: <Widget>[new IconButton(icon: "navigation/check")]
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildFloatingActionButton(BuildContext context) {
|
||||
return new FloatingActionButton(
|
||||
child: new Icon(icon: 'image/photo_camera'),
|
||||
backgroundColor: Theme.of(context).accentColor
|
||||
);
|
||||
}
|
||||
|
||||
static final GlobalKey nameKey = new GlobalKey(label: 'name field');
|
||||
static final GlobalKey phoneKey = new GlobalKey(label: 'phone field');
|
||||
static final GlobalKey emailKey = new GlobalKey(label: 'email field');
|
||||
static final GlobalKey addressKey = new GlobalKey(label: 'address field');
|
||||
static final GlobalKey ringtoneKey = new GlobalKey(label: 'ringtone field');
|
||||
static final GlobalKey noteKey = new GlobalKey(label: 'note field');
|
||||
|
||||
Widget buildBody(BuildContext context) {
|
||||
return new Block(<Widget>[
|
||||
new AspectRatio(
|
||||
aspectRatio: 16.0 / 9.0,
|
||||
child: new Container(
|
||||
decoration: new BoxDecoration(backgroundColor: Colors.purple[300])
|
||||
)
|
||||
),
|
||||
new Field(inputKey: nameKey, icon: "social/person", placeholder: "Name"),
|
||||
new Field(inputKey: phoneKey, icon: "communication/phone", placeholder: "Phone"),
|
||||
new Field(inputKey: emailKey, icon: "communication/email", placeholder: "Email"),
|
||||
new Field(inputKey: addressKey, icon: "maps/place", placeholder: "Address"),
|
||||
new Field(inputKey: ringtoneKey, icon: "av/volume_up", placeholder: "Ringtone"),
|
||||
new Field(inputKey: noteKey, icon: "content/add", placeholder: "Add note"),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
toolBar: buildToolBar(context),
|
||||
body: buildBody(context),
|
||||
floatingActionButton: buildFloatingActionButton(context)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final ThemeData theme = new ThemeData(
|
||||
brightness: ThemeBrightness.light,
|
||||
primarySwatch: Colors.teal,
|
||||
accentColor: Colors.pinkAccent[100]
|
||||
);
|
||||
|
||||
void main() {
|
||||
runApp(new MaterialApp(
|
||||
title: 'Address Book',
|
||||
theme: theme,
|
||||
routes: <String, RouteBuilder>{
|
||||
'/': (RouteArguments args) => new AddressBookHome()
|
||||
}
|
||||
));
|
||||
}
|
||||
10
examples/address_book/pubspec.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
name: address_book
|
||||
dependencies:
|
||||
flutter:
|
||||
'0.0.16'
|
||||
sky_tools: any
|
||||
dependency_overrides:
|
||||
material_design_icons:
|
||||
path: ../../sky/packages/material_design_icons
|
||||
flutter:
|
||||
path: ../../sky/packages/sky
|
||||
21
examples/fitness/BUILD.gn
Normal file
@@ -0,0 +1,21 @@
|
||||
# Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//sky/build/sky_app.gni")
|
||||
|
||||
sky_app("fitness") {
|
||||
main_dart = "lib/main.dart"
|
||||
manifest = "flutter.yaml"
|
||||
|
||||
if (is_android) {
|
||||
apk_name = "Fitness"
|
||||
|
||||
deps = [
|
||||
"//examples/fitness/apk:resources",
|
||||
]
|
||||
} else if (is_mac) {
|
||||
info_plist = "mac/Info.plist"
|
||||
xibs = [ "mac/sky_mac.xib" ]
|
||||
}
|
||||
}
|
||||
23
examples/fitness/apk/AndroidManifest.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
Use of this source code is governed by a BSD-style license that can be
|
||||
found in the LICENSE file.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.domokit.fitness" android:versionCode="4" android:versionName="0.0.4">
|
||||
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application android:icon="@mipmap/ic_launcher" android:label="Fitness" android:name="org.domokit.sky.shell.SkyApplication">
|
||||
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize" android:hardwareAccelerated="true" android:launchMode="singleTask" android:name="org.domokit.sky.shell.SkyActivity" android:theme="@android:style/Theme.Black.NoTitleBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service
|
||||
android:name="org.domokit.sky.shell.UpdateService"
|
||||
android:exported="false"
|
||||
android:process=":remote"/>
|
||||
</application>
|
||||
</manifest>
|
||||
14
examples/fitness/apk/BUILD.gn
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
assert(is_android)
|
||||
|
||||
import("//build/config/android/config.gni")
|
||||
import("//build/config/android/rules.gni")
|
||||
|
||||
|
||||
android_resources("resources") {
|
||||
resource_dirs = [ "res" ]
|
||||
android_manifest = "AndroidManifest.xml"
|
||||
}
|
||||
10
examples/fitness/apk/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
Icon image comes from:
|
||||
https://openclipart.org/detail/22309/apple-icon
|
||||
and is public domain.
|
||||
|
||||
Icon resources were generated using:
|
||||
http://romannurik.github.io/AndroidAssetStudio/icons-launcher.html
|
||||
with settings:
|
||||
http://romannurik.github.io/AndroidAssetStudio/icons-launcher.html#foreground.type=image&foreground.space.trim=1&foreground.space.pad=0&foreColor=607d8b%2C0&crop=0&backgroundShape=none&backColor=ffffff%2C100&effects=none
|
||||
which produces art under CC 3.0:
|
||||
http://creativecommons.org/licenses/by/3.0/
|
||||
3
examples/fitness/apk/release_notes/0.0.2.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
Still barely works
|
||||
Fixed crash when entering an invalid number
|
||||
Made date list look less-awful.
|
||||
1
examples/fitness/apk/release_notes/0.0.3.txt
Normal file
@@ -0,0 +1 @@
|
||||
Adds very basic charting support
|
||||
1
examples/fitness/apk/release_notes/0.0.4.txt
Normal file
@@ -0,0 +1 @@
|
||||
Now supports setting goal weight.
|
||||
BIN
examples/fitness/apk/res/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
examples/fitness/apk/res/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
examples/fitness/apk/res/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
examples/fitness/apk/res/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
examples/fitness/apk/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
15
examples/fitness/flutter.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
name: fitness
|
||||
version: 0.0.1
|
||||
update-url: http://localhost:9888/
|
||||
material-design-icons:
|
||||
- name: action/assessment
|
||||
- name: action/help
|
||||
- name: action/settings
|
||||
- name: action/view_list
|
||||
- name: av/stop
|
||||
- name: content/add
|
||||
- name: maps/directions_run
|
||||
- name: navigation/arrow_back
|
||||
- name: navigation/close
|
||||
- name: navigation/menu
|
||||
- name: navigation/more_vert
|
||||
58
examples/fitness/ios/Info.plist
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
|
||||
<!--
|
||||
This executable name must match the name of the app provided to the
|
||||
ios_app GN template
|
||||
-->
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>fitness_app</string>
|
||||
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Fitness</string>
|
||||
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.google.SkyFitness</string>
|
||||
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>game_app</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>DTPlatformName</key>
|
||||
<string>iphonesimulator</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>iphonesimulator8.3</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>7.0</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>iPhoneSimulator</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
examples/fitness/ios/LaunchScreen.storyboardc/01J-lp-oVM-view-Ze5-6b-2t3.nib
generated
Normal file
BIN
examples/fitness/ios/LaunchScreen.storyboardc/Info.plist
Normal file
BIN
examples/fitness/ios/LaunchScreen.storyboardc/UIViewController-01J-lp-oVM.nib
generated
Normal file
87
examples/fitness/lib/date_utils.dart
Normal file
@@ -0,0 +1,87 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Forked from https://github.com/dart-lang/sdk/blob/master/samples-dev/swarm/swarm_ui_lib/util/DateUtils.dart
|
||||
class DateUtils {
|
||||
|
||||
static const WEEKDAYS = const ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
|
||||
'Friday', 'Saturday', 'Sunday'];
|
||||
|
||||
static const YESTERDAY = 'Yesterday';
|
||||
|
||||
static const MS_IN_WEEK = DateTime.DAYS_PER_WEEK * Duration.MILLISECONDS_PER_DAY;
|
||||
|
||||
// TODO(jmesserly): locale specific date format
|
||||
static String _twoDigits(int n) {
|
||||
if (n >= 10)
|
||||
return '$n';
|
||||
return '0$n';
|
||||
}
|
||||
|
||||
/// Formats a time in H:MM A format
|
||||
static String toHourMinutesString(Duration duration) {
|
||||
assert(duration.inDays == 0);
|
||||
int hours = duration.inHours;
|
||||
String a;
|
||||
if (hours >= 12) {
|
||||
a = 'pm';
|
||||
if (hours != 12)
|
||||
hours -= 12;
|
||||
} else {
|
||||
a = 'am';
|
||||
if (hours == 0)
|
||||
hours += 12;
|
||||
}
|
||||
String twoDigits(int n) {
|
||||
if (n >= 10)
|
||||
return '$n';
|
||||
return '0$n';
|
||||
}
|
||||
String mm = twoDigits(duration.inMinutes.remainder(Duration.MINUTES_PER_HOUR));
|
||||
return '$hours:$mm $a';
|
||||
}
|
||||
|
||||
/// A date/time formatter that takes into account the current date/time:
|
||||
/// - if it's from today, just show the time
|
||||
/// - if it's from yesterday, just show 'Yesterday'
|
||||
/// - if it's from the same week, just show the weekday
|
||||
/// - otherwise, show just the date
|
||||
static String toRecentTimeString(DateTime then) {
|
||||
bool datesAreEqual(DateTime d1, DateTime d2) {
|
||||
return (d1.year == d2.year) &&
|
||||
(d1.month == d2.month) &&
|
||||
(d1.day == d2.day);
|
||||
}
|
||||
|
||||
final now = new DateTime.now();
|
||||
if (datesAreEqual(then, now)) {
|
||||
return toHourMinutesString(new Duration(
|
||||
days: 0,
|
||||
hours: then.hour,
|
||||
minutes: then.minute,
|
||||
seconds: then.second,
|
||||
milliseconds: then.millisecond)
|
||||
);
|
||||
}
|
||||
|
||||
final today = new DateTime(now.year, now.month, now.day, 0, 0, 0, 0);
|
||||
Duration delta = today.difference(then);
|
||||
if (delta.inMilliseconds < Duration.MILLISECONDS_PER_DAY) {
|
||||
return YESTERDAY;
|
||||
} else if (delta.inMilliseconds < MS_IN_WEEK) {
|
||||
return WEEKDAYS[then.weekday];
|
||||
} else {
|
||||
String twoDigitMonth = _twoDigits(then.month);
|
||||
String twoDigitDay = _twoDigits(then.day);
|
||||
return '${then.year}-$twoDigitMonth-$twoDigitDay';
|
||||
}
|
||||
}
|
||||
|
||||
static String toDateString(DateTime then) {
|
||||
// TODO(jmesserly): locale specific date format
|
||||
String twoDigitMonth = _twoDigits(then.month);
|
||||
String twoDigitDay = _twoDigits(then.day);
|
||||
return '${then.year}-$twoDigitMonth-$twoDigitDay';
|
||||
}
|
||||
}
|
||||
267
examples/fitness/lib/feed.dart
Normal file
@@ -0,0 +1,267 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of fitness;
|
||||
|
||||
class FitnessItemList extends StatelessComponent {
|
||||
FitnessItemList({ Key key, this.items, this.onDismissed }) : super(key: key) {
|
||||
assert(items != null);
|
||||
assert(onDismissed != null);
|
||||
}
|
||||
|
||||
final List<FitnessItem> items;
|
||||
final FitnessItemHandler onDismissed;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new ScrollableList<FitnessItem>(
|
||||
padding: const EdgeDims.all(4.0),
|
||||
items: items,
|
||||
itemExtent: kFitnessItemHeight,
|
||||
itemBuilder: (BuildContext context, FitnessItem item) => item.toRow(onDismissed: onDismissed)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DialogMenuItem extends StatelessComponent {
|
||||
DialogMenuItem(this.children, { Key key, this.onPressed }) : super(key: key);
|
||||
|
||||
List<Widget> children;
|
||||
Function onPressed;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Container(
|
||||
height: 48.0,
|
||||
child: new InkWell(
|
||||
onTap: onPressed,
|
||||
child: new Padding(
|
||||
padding: const EdgeDims.symmetric(horizontal: 16.0),
|
||||
child: new Row(children)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FeedFragment extends StatefulComponent {
|
||||
FeedFragment({ this.userData, this.onItemCreated, this.onItemDeleted });
|
||||
|
||||
final UserData userData;
|
||||
final FitnessItemHandler onItemCreated;
|
||||
final FitnessItemHandler onItemDeleted;
|
||||
|
||||
FeedFragmentState createState() => new FeedFragmentState();
|
||||
}
|
||||
|
||||
class FeedFragmentState extends State<FeedFragment> {
|
||||
final GlobalKey<PlaceholderState> _snackBarPlaceholderKey = new GlobalKey<PlaceholderState>();
|
||||
FitnessMode _fitnessMode = FitnessMode.feed;
|
||||
|
||||
void _handleFitnessModeChange(FitnessMode value) {
|
||||
setState(() {
|
||||
_fitnessMode = value;
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
void _showDrawer() {
|
||||
showDrawer(
|
||||
context: context,
|
||||
child: new Block(<Widget>[
|
||||
new DrawerHeader(child: new Text('Fitness')),
|
||||
new DrawerItem(
|
||||
icon: 'action/view_list',
|
||||
onPressed: () => _handleFitnessModeChange(FitnessMode.feed),
|
||||
selected: _fitnessMode == FitnessMode.feed,
|
||||
child: new Text('Feed')),
|
||||
new DrawerItem(
|
||||
icon: 'action/assessment',
|
||||
onPressed: () => _handleFitnessModeChange(FitnessMode.chart),
|
||||
selected: _fitnessMode == FitnessMode.chart,
|
||||
child: new Text('Chart')),
|
||||
new DrawerDivider(),
|
||||
new DrawerItem(
|
||||
icon: 'action/settings',
|
||||
onPressed: _handleShowSettings,
|
||||
child: new Text('Settings')),
|
||||
new DrawerItem(
|
||||
icon: 'action/help',
|
||||
child: new Text('Help & Feedback'))
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
void _handleShowSettings() {
|
||||
Navigator.of(context)..pop()
|
||||
..pushNamed('/settings');
|
||||
}
|
||||
|
||||
// TODO(jackson): We should be localizing
|
||||
String get fitnessModeTitle {
|
||||
switch(_fitnessMode) {
|
||||
case FitnessMode.feed: return "Feed";
|
||||
case FitnessMode.chart: return "Chart";
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildToolBar() {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
icon: "navigation/menu",
|
||||
onPressed: _showDrawer),
|
||||
center: new Text(fitnessModeTitle)
|
||||
);
|
||||
}
|
||||
|
||||
void _handleItemDismissed(FitnessItem item) {
|
||||
config.onItemDeleted(item);
|
||||
showSnackBar(
|
||||
context: context,
|
||||
placeholderKey: _snackBarPlaceholderKey,
|
||||
content: new Text("Item deleted."),
|
||||
actions: <SnackBarAction>[new SnackBarAction(label: "UNDO", onPressed: () {
|
||||
config.onItemCreated(item);
|
||||
Navigator.of(context).pop();
|
||||
})]
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildChart() {
|
||||
double startX;
|
||||
double endX;
|
||||
double startY;
|
||||
double endY;
|
||||
List<Point> dataSet = new List<Point>();
|
||||
for (FitnessItem item in config.userData.items) {
|
||||
if (item is Measurement) {
|
||||
double x = item.when.millisecondsSinceEpoch.toDouble();
|
||||
double y = item.weight;
|
||||
if (startX == null || startX > x)
|
||||
startX = x;
|
||||
if (endX == null || endX < x)
|
||||
endX = x;
|
||||
if (startY == null || startY > y)
|
||||
startY = y;
|
||||
if (endY == null || endY < y)
|
||||
endY = y;
|
||||
dataSet.add(new Point(x, y));
|
||||
}
|
||||
}
|
||||
if (config.userData.goalWeight != null && config.userData.goalWeight > 0.0) {
|
||||
startY = math.min(startY, config.userData.goalWeight);
|
||||
endY = math.max(endY, config.userData.goalWeight);
|
||||
}
|
||||
playfair.ChartData data = new playfair.ChartData(
|
||||
startX: startX,
|
||||
startY: startY,
|
||||
endX: endX,
|
||||
endY: endY,
|
||||
dataSet: dataSet,
|
||||
numHorizontalGridlines: 5,
|
||||
roundToPlaces: 1,
|
||||
indicatorLine: config.userData.goalWeight,
|
||||
indicatorText: "GOAL WEIGHT"
|
||||
);
|
||||
return new playfair.Chart(data: data);
|
||||
}
|
||||
|
||||
Widget buildBody() {
|
||||
TextStyle style = Theme.of(context).text.title;
|
||||
if (config.userData == null)
|
||||
return new Container();
|
||||
if (config.userData.items.length == 0) {
|
||||
return new Row(
|
||||
<Widget>[new Text("No data yet.\nAdd some!", style: style)],
|
||||
justifyContent: FlexJustifyContent.center
|
||||
);
|
||||
}
|
||||
switch (_fitnessMode) {
|
||||
case FitnessMode.feed:
|
||||
return new FitnessItemList(
|
||||
items: config.userData.items.reversed.toList(),
|
||||
onDismissed: _handleItemDismissed
|
||||
);
|
||||
case FitnessMode.chart:
|
||||
return new Container(
|
||||
padding: const EdgeDims.all(20.0),
|
||||
child: buildChart()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleActionButtonPressed() {
|
||||
showDialog(context: context, child: new AddItemDialog()).then((routeName) {
|
||||
if (routeName != null)
|
||||
Navigator.of(context).pushNamed(routeName);
|
||||
});
|
||||
}
|
||||
|
||||
Widget buildFloatingActionButton() {
|
||||
switch (_fitnessMode) {
|
||||
case FitnessMode.feed:
|
||||
return new FloatingActionButton(
|
||||
child: new Icon(icon: 'content/add'),
|
||||
onPressed: _handleActionButtonPressed
|
||||
);
|
||||
case FitnessMode.chart:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
toolBar: buildToolBar(),
|
||||
body: buildBody(),
|
||||
snackBar: new Placeholder(key: _snackBarPlaceholderKey),
|
||||
floatingActionButton: buildFloatingActionButton()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AddItemDialog extends StatefulComponent {
|
||||
AddItemDialogState createState() => new AddItemDialogState();
|
||||
}
|
||||
|
||||
class AddItemDialogState extends State<AddItemDialog> {
|
||||
// TODO(jackson): Internationalize
|
||||
static final Map<String, String> _labels = <String, String>{
|
||||
'/measurements/new': 'Measure',
|
||||
'/meals/new': 'Eat',
|
||||
};
|
||||
|
||||
String _addItemRoute = _labels.keys.first;
|
||||
|
||||
void _handleAddItemRouteChanged(String routeName) {
|
||||
setState(() {
|
||||
_addItemRoute = routeName;
|
||||
});
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
List<Widget> menuItems = <Widget>[];
|
||||
for (String routeName in _labels.keys) {
|
||||
menuItems.add(new DialogMenuItem(<Widget>[
|
||||
new Flexible(child: new Text(_labels[routeName])),
|
||||
new Radio<String>(value: routeName, groupValue: _addItemRoute, onChanged: _handleAddItemRouteChanged),
|
||||
], onPressed: () => _handleAddItemRouteChanged(routeName)));
|
||||
}
|
||||
return new Dialog(
|
||||
title: new Text("What are you doing?"),
|
||||
content: new Block(menuItems),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text('CANCEL'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('ADD'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(_addItemRoute);
|
||||
}
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
61
examples/fitness/lib/fitness_item.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of fitness;
|
||||
|
||||
typedef void FitnessItemHandler(FitnessItem item);
|
||||
|
||||
// TODO(eseidel): This should be a constant on a SingleLineTile class
|
||||
// https://www.google.com/design/spec/components/lists.html#lists-specs
|
||||
const double kFitnessItemHeight = 48.0;
|
||||
|
||||
abstract class FitnessItem {
|
||||
FitnessItem.fromJson(Map json) : when = DateTime.parse(json['when']);
|
||||
|
||||
FitnessItem({ this.when }) {
|
||||
assert(when != null);
|
||||
}
|
||||
final DateTime when;
|
||||
|
||||
Map toJson() => { 'when' : when.toIso8601String() };
|
||||
|
||||
// TODO(jackson): Internationalize
|
||||
String get displayDate => DateUtils.toDateString(when);
|
||||
|
||||
FitnessItemRow toRow({ FitnessItemHandler onDismissed });
|
||||
}
|
||||
|
||||
abstract class FitnessItemRow extends StatelessComponent {
|
||||
|
||||
FitnessItemRow({ FitnessItem item, this.onDismissed })
|
||||
: this.item = item,
|
||||
super(key: new ValueKey<DateTime>(item.when)) {
|
||||
assert(onDismissed != null);
|
||||
}
|
||||
|
||||
final FitnessItem item;
|
||||
final FitnessItemHandler onDismissed;
|
||||
|
||||
Widget buildContent(BuildContext context);
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Dismissable(
|
||||
onDismissed: () => onDismissed(item),
|
||||
child: new Container(
|
||||
height: kFitnessItemHeight,
|
||||
// TODO(eseidel): Padding top should be 16px for a single-line tile:
|
||||
// https://www.google.com/design/spec/components/lists.html#lists-specs
|
||||
padding: const EdgeDims.all(10.0),
|
||||
// TODO(eseidel): This line should be drawn by the list as it should
|
||||
// stay put even when the tile is dismissed!
|
||||
decoration: new BoxDecoration(
|
||||
border: new Border(
|
||||
bottom: new BorderSide(color: Theme.of(context).dividerColor)
|
||||
)
|
||||
),
|
||||
child: buildContent(context)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
8
examples/fitness/lib/fitness_types.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of fitness;
|
||||
|
||||
enum FitnessMode { feed, chart }
|
||||
enum BackupMode { enabled, disabled }
|
||||
166
examples/fitness/lib/main.dart
Normal file
@@ -0,0 +1,166 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
library fitness;
|
||||
|
||||
import 'package:playfair/playfair.dart' as playfair;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
|
||||
import 'user_data.dart';
|
||||
import 'date_utils.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
part 'feed.dart';
|
||||
part 'fitness_item.dart';
|
||||
part 'fitness_types.dart';
|
||||
part 'meal.dart';
|
||||
part 'measurement.dart';
|
||||
part 'settings.dart';
|
||||
|
||||
abstract class UserData {
|
||||
BackupMode get backupMode;
|
||||
double get goalWeight;
|
||||
List<FitnessItem> get items;
|
||||
}
|
||||
|
||||
class UserDataImpl extends UserData {
|
||||
UserDataImpl();
|
||||
|
||||
List<FitnessItem> _items = <FitnessItem>[];
|
||||
|
||||
BackupMode _backupMode;
|
||||
BackupMode get backupMode => _backupMode;
|
||||
void set backupMode(BackupMode value) {
|
||||
_backupMode = value;
|
||||
}
|
||||
|
||||
double _goalWeight;
|
||||
double get goalWeight => _goalWeight;
|
||||
void set goalWeight(double value) {
|
||||
_goalWeight = value;
|
||||
}
|
||||
|
||||
List<FitnessItem> get items => _items;
|
||||
|
||||
void sort() {
|
||||
_items.sort((FitnessItem a, FitnessItem b) => a.when.compareTo(b.when));
|
||||
}
|
||||
|
||||
void add(FitnessItem item) {
|
||||
_items.add(item);
|
||||
sort();
|
||||
}
|
||||
|
||||
void remove(FitnessItem item) {
|
||||
_items.remove(item);
|
||||
}
|
||||
|
||||
Future save() => saveFitnessData(this);
|
||||
|
||||
UserDataImpl.fromJson(Map json) {
|
||||
json['items'].forEach((item) {
|
||||
_items.add(new Measurement.fromJson(item));
|
||||
});
|
||||
try {
|
||||
_backupMode = BackupMode.values.firstWhere((BackupMode mode) {
|
||||
return mode.toString() == json['backupMode'];
|
||||
});
|
||||
} catch(e) {
|
||||
print("Failed to load backup mode: $e");
|
||||
}
|
||||
_goalWeight = json['goalWeight'];
|
||||
}
|
||||
|
||||
Map toJson() {
|
||||
Map json = new Map();
|
||||
json['items'] = _items.map((FitnessItem item) => item.toJson()).toList();
|
||||
json['backupMode'] = _backupMode.toString();
|
||||
json['goalWeight'] = _goalWeight;
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
class FitnessApp extends StatefulComponent {
|
||||
FitnessAppState createState() => new FitnessAppState();
|
||||
}
|
||||
|
||||
class FitnessAppState extends State<FitnessApp> {
|
||||
UserDataImpl _userData;
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
loadFitnessData().then((UserData data) {
|
||||
setState(() => _userData = data);
|
||||
}).catchError((e) {
|
||||
print("Failed to load data: $e");
|
||||
setState(() => _userData = new UserDataImpl());
|
||||
});
|
||||
}
|
||||
|
||||
void _handleItemCreated(FitnessItem item) {
|
||||
setState(() {
|
||||
_userData.add(item);
|
||||
_userData.save();
|
||||
});
|
||||
}
|
||||
|
||||
void _handleItemDeleted(FitnessItem item) {
|
||||
setState(() {
|
||||
_userData.remove(item);
|
||||
_userData.save();
|
||||
});
|
||||
}
|
||||
|
||||
void settingsUpdater({ BackupMode backup, double goalWeight }) {
|
||||
setState(() {
|
||||
if (backup != null)
|
||||
_userData.backupMode = backup;
|
||||
if (goalWeight != null)
|
||||
_userData.goalWeight = goalWeight;
|
||||
_userData.save();
|
||||
});
|
||||
}
|
||||
|
||||
Widget build(BuildContext) {
|
||||
return new MaterialApp(
|
||||
theme: new ThemeData(
|
||||
brightness: ThemeBrightness.light,
|
||||
primarySwatch: Colors.indigo,
|
||||
accentColor: Colors.pinkAccent[200]
|
||||
),
|
||||
title: 'Fitness',
|
||||
routes: <String, RouteBuilder>{
|
||||
'/': (RouteArguments args) {
|
||||
return new FeedFragment(
|
||||
userData: _userData,
|
||||
onItemCreated: _handleItemCreated,
|
||||
onItemDeleted: _handleItemDeleted
|
||||
);
|
||||
},
|
||||
'/meals/new': (RouteArguments args) {
|
||||
return new MealFragment(
|
||||
onCreated: _handleItemCreated
|
||||
);
|
||||
},
|
||||
'/measurements/new': (RouteArguments args) {
|
||||
return new MeasurementFragment(
|
||||
onCreated: _handleItemCreated
|
||||
);
|
||||
},
|
||||
'/settings': (RouteArguments args) {
|
||||
return new SettingsFragment(
|
||||
userData: _userData,
|
||||
updater: settingsUpdater
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(new FitnessApp());
|
||||
}
|
||||
105
examples/fitness/lib/meal.dart
Normal file
@@ -0,0 +1,105 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of fitness;
|
||||
|
||||
class Meal extends FitnessItem {
|
||||
Meal({ DateTime when, this.description }) : super(when: when);
|
||||
|
||||
final String description;
|
||||
|
||||
FitnessItemRow toRow({ FitnessItemHandler onDismissed }) {
|
||||
return new MealRow(meal: this, onDismissed: onDismissed);
|
||||
}
|
||||
}
|
||||
|
||||
class MealRow extends FitnessItemRow {
|
||||
MealRow({ Meal meal, FitnessItemHandler onDismissed })
|
||||
: super(item: meal, onDismissed: onDismissed);
|
||||
|
||||
Widget buildContent(BuildContext context) {
|
||||
Meal meal = item;
|
||||
List<Widget> children = <Widget>[
|
||||
new Flexible(
|
||||
child: new Text(
|
||||
meal.description,
|
||||
style: const TextStyle(textAlign: TextAlign.right)
|
||||
)
|
||||
),
|
||||
new Flexible(
|
||||
child: new Text(
|
||||
meal.displayDate,
|
||||
style: Theme.of(context).text.caption.copyWith(textAlign: TextAlign.right)
|
||||
)
|
||||
)
|
||||
];
|
||||
return new Row(
|
||||
children,
|
||||
alignItems: FlexAlignItems.baseline,
|
||||
textBaseline: DefaultTextStyle.of(context).textBaseline
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MealFragment extends StatefulComponent {
|
||||
MealFragment({ this.onCreated });
|
||||
|
||||
FitnessItemHandler onCreated;
|
||||
|
||||
MealFragmentState createState() => new MealFragmentState();
|
||||
}
|
||||
|
||||
class MealFragmentState extends State<MealFragment> {
|
||||
String _description = "";
|
||||
|
||||
void _handleSave() {
|
||||
config.onCreated(new Meal(when: new DateTime.now(), description: _description));
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
Widget buildToolBar() {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
icon: "navigation/close",
|
||||
onPressed: Navigator.of(context).pop),
|
||||
center: new Text('New Meal'),
|
||||
right: <Widget>[
|
||||
// TODO(abarth): Should this be a FlatButton?
|
||||
new InkWell(
|
||||
onTap: _handleSave,
|
||||
child: new Text('SAVE')
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
void _handleDescriptionChanged(String description) {
|
||||
setState(() {
|
||||
_description = description;
|
||||
});
|
||||
}
|
||||
|
||||
static final GlobalKey descriptionKey = new GlobalKey();
|
||||
|
||||
Widget buildBody() {
|
||||
Meal meal = new Meal(when: new DateTime.now());
|
||||
return new Block(<Widget>[
|
||||
new Text(meal.displayDate),
|
||||
new Input(
|
||||
key: descriptionKey,
|
||||
placeholder: 'Describe meal',
|
||||
onChanged: _handleDescriptionChanged
|
||||
),
|
||||
],
|
||||
padding: const EdgeDims.all(20.0)
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
toolBar: buildToolBar(),
|
||||
body: buildBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
205
examples/fitness/lib/measurement.dart
Normal file
@@ -0,0 +1,205 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of fitness;
|
||||
|
||||
class Measurement extends FitnessItem {
|
||||
Measurement({ DateTime when, this.weight }) : super(when: when);
|
||||
Measurement.fromJson(Map json) : weight = json['weight'], super.fromJson(json);
|
||||
|
||||
final double weight;
|
||||
|
||||
// TODO(jackson): Internationalize
|
||||
String get displayWeight => "${weight.toStringAsFixed(1)} lbs";
|
||||
|
||||
@override
|
||||
Map toJson() {
|
||||
Map json = super.toJson();
|
||||
json['weight'] = weight;
|
||||
json['type'] = runtimeType.toString();
|
||||
return json;
|
||||
}
|
||||
|
||||
FitnessItemRow toRow({ FitnessItemHandler onDismissed }) {
|
||||
return new MeasurementRow(measurement: this, onDismissed: onDismissed);
|
||||
}
|
||||
}
|
||||
|
||||
class MeasurementRow extends FitnessItemRow {
|
||||
MeasurementRow({ Measurement measurement, FitnessItemHandler onDismissed })
|
||||
: super(item: measurement, onDismissed: onDismissed);
|
||||
|
||||
Widget buildContent(BuildContext context) {
|
||||
Measurement measurement = item;
|
||||
List<Widget> children = <Widget>[
|
||||
new Flexible(
|
||||
child: new Text(
|
||||
measurement.displayWeight,
|
||||
style: Theme.of(context).text.subhead
|
||||
)
|
||||
),
|
||||
new Flexible(
|
||||
child: new Text(
|
||||
measurement.displayDate,
|
||||
style: Theme.of(context).text.caption.copyWith(textAlign: TextAlign.right)
|
||||
)
|
||||
)
|
||||
];
|
||||
return new Row(
|
||||
children,
|
||||
alignItems: FlexAlignItems.baseline,
|
||||
textBaseline: DefaultTextStyle.of(context).textBaseline
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MeasurementDateDialog extends StatefulComponent {
|
||||
MeasurementDateDialog({ this.previousDate });
|
||||
|
||||
final DateTime previousDate;
|
||||
|
||||
MeasurementDateDialogState createState() => new MeasurementDateDialogState();
|
||||
}
|
||||
|
||||
class MeasurementDateDialogState extends State<MeasurementDateDialog> {
|
||||
@override
|
||||
void initState() {
|
||||
_selectedDate = config.previousDate;
|
||||
}
|
||||
|
||||
DateTime _selectedDate;
|
||||
|
||||
void _handleDateChanged(DateTime value) {
|
||||
setState(() {
|
||||
_selectedDate = value;
|
||||
});
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Dialog(
|
||||
content: new DatePicker(
|
||||
selectedDate: _selectedDate,
|
||||
firstDate: new DateTime(2015, 8),
|
||||
lastDate: new DateTime(2101),
|
||||
onChanged: _handleDateChanged
|
||||
),
|
||||
contentPadding: EdgeDims.zero,
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text('CANCEL'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('OK'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(_selectedDate);
|
||||
}
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MeasurementFragment extends StatefulComponent {
|
||||
MeasurementFragment({ this.onCreated });
|
||||
|
||||
final FitnessItemHandler onCreated;
|
||||
|
||||
MeasurementFragmentState createState() => new MeasurementFragmentState();
|
||||
}
|
||||
|
||||
class MeasurementFragmentState extends State<MeasurementFragment> {
|
||||
final GlobalKey<PlaceholderState> _snackBarPlaceholderKey = new GlobalKey<PlaceholderState>();
|
||||
|
||||
String _weight = "";
|
||||
DateTime _when = new DateTime.now();
|
||||
|
||||
void _handleSave() {
|
||||
double parsedWeight;
|
||||
try {
|
||||
parsedWeight = double.parse(_weight);
|
||||
} on FormatException catch(e) {
|
||||
print("Exception $e");
|
||||
showSnackBar(
|
||||
context: context,
|
||||
placeholderKey: _snackBarPlaceholderKey,
|
||||
content: new Text('Save failed')
|
||||
);
|
||||
}
|
||||
config.onCreated(new Measurement(when: _when, weight: parsedWeight));
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
Widget buildToolBar() {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
icon: "navigation/close",
|
||||
onPressed: Navigator.of(context).pop),
|
||||
center: new Text('New Measurement'),
|
||||
right: <Widget>[
|
||||
// TODO(abarth): Should this be a FlatButton?
|
||||
new InkWell(
|
||||
onTap: _handleSave,
|
||||
child: new Text('SAVE')
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
void _handleWeightChanged(String weight) {
|
||||
setState(() {
|
||||
_weight = weight;
|
||||
});
|
||||
}
|
||||
|
||||
static final GlobalKey weightKey = new GlobalKey();
|
||||
|
||||
Future _handleDatePressed() async {
|
||||
DateTime value = await showDialog(
|
||||
context: context,
|
||||
child: new MeasurementDateDialog(previousDate: _when)
|
||||
);
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_when = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildBody(BuildContext context) {
|
||||
Measurement measurement = new Measurement(when: _when);
|
||||
// TODO(jackson): Revisit the layout of this pane to be more maintainable
|
||||
return new Container(
|
||||
padding: const EdgeDims.all(20.0),
|
||||
child: new Column(<Widget>[
|
||||
new GestureDetector(
|
||||
onTap: _handleDatePressed,
|
||||
child: new Container(
|
||||
height: 50.0,
|
||||
child: new Column(<Widget>[
|
||||
new Text('Measurement Date'),
|
||||
new Text(measurement.displayDate, style: Theme.of(context).text.caption),
|
||||
], alignItems: FlexAlignItems.start)
|
||||
)
|
||||
),
|
||||
new Input(
|
||||
key: weightKey,
|
||||
placeholder: 'Enter weight',
|
||||
keyboardType: KeyboardType.NUMBER,
|
||||
onChanged: _handleWeightChanged
|
||||
),
|
||||
], alignItems: FlexAlignItems.stretch)
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
toolBar: buildToolBar(),
|
||||
body: buildBody(context),
|
||||
snackBar: new Placeholder(key: _snackBarPlaceholderKey)
|
||||
);
|
||||
}
|
||||
}
|
||||
121
examples/fitness/lib/settings.dart
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of fitness;
|
||||
|
||||
typedef void SettingsUpdater({
|
||||
BackupMode backup,
|
||||
double goalWeight
|
||||
});
|
||||
|
||||
class SettingsFragment extends StatefulComponent {
|
||||
SettingsFragment({ this.userData, this.updater });
|
||||
|
||||
final UserData userData;
|
||||
final SettingsUpdater updater;
|
||||
|
||||
SettingsFragmentState createState() => new SettingsFragmentState();
|
||||
}
|
||||
|
||||
class SettingsFragmentState extends State<SettingsFragment> {
|
||||
void _handleBackupChanged(bool value) {
|
||||
assert(config.updater != null);
|
||||
config.updater(backup: value ? BackupMode.enabled : BackupMode.disabled);
|
||||
}
|
||||
|
||||
Widget buildToolBar() {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
icon: "navigation/arrow_back",
|
||||
onPressed: () => Navigator.of(context).pop()
|
||||
),
|
||||
center: new Text('Settings')
|
||||
);
|
||||
}
|
||||
|
||||
String get goalWeightText {
|
||||
if (config.userData.goalWeight == null || config.userData.goalWeight == 0.0)
|
||||
return "None";
|
||||
return "${config.userData.goalWeight}";
|
||||
}
|
||||
|
||||
static final GlobalKey weightGoalKey = new GlobalKey();
|
||||
|
||||
double _goalWeight;
|
||||
|
||||
void _handleGoalWeightChanged(String goalWeight) {
|
||||
// TODO(jackson): Looking for null characters to detect enter key is a hack
|
||||
if (goalWeight.endsWith("\u{0}")) {
|
||||
Navigator.of(context).pop(double.parse(goalWeight.replaceAll("\u{0}", "")));
|
||||
} else {
|
||||
setState(() {
|
||||
try {
|
||||
_goalWeight = double.parse(goalWeight);
|
||||
} on FormatException {
|
||||
_goalWeight = 0.0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future _handleGoalWeightPressed() async {
|
||||
double goalWeight = await showDialog(
|
||||
context: context,
|
||||
child: new Dialog(
|
||||
title: new Text("Goal Weight"),
|
||||
content: new Input(
|
||||
key: weightGoalKey,
|
||||
placeholder: 'Goal weight in lbs',
|
||||
keyboardType: KeyboardType.NUMBER,
|
||||
onChanged: _handleGoalWeightChanged
|
||||
),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text('CANCEL'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('SAVE'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(_goalWeight);
|
||||
}
|
||||
),
|
||||
]
|
||||
)
|
||||
);
|
||||
config.updater(goalWeight: goalWeight);
|
||||
}
|
||||
|
||||
Widget buildSettingsPane(BuildContext context) {
|
||||
return new Block(<Widget>[
|
||||
new DrawerItem(
|
||||
onPressed: () { _handleBackupChanged(!(config.userData.backupMode == BackupMode.enabled)); },
|
||||
child: new Row(<Widget>[
|
||||
new Flexible(child: new Text('Back up data to the cloud')),
|
||||
new Switch(value: config.userData.backupMode == BackupMode.enabled, onChanged: _handleBackupChanged),
|
||||
])
|
||||
),
|
||||
new DrawerItem(
|
||||
onPressed: () => _handleGoalWeightPressed(),
|
||||
child: new Column(<Widget>[
|
||||
new Text('Goal Weight'),
|
||||
new Text(goalWeightText, style: Theme.of(context).text.caption),
|
||||
],
|
||||
alignItems: FlexAlignItems.start
|
||||
)
|
||||
),
|
||||
],
|
||||
padding: const EdgeDims.symmetric(vertical: 20.0)
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
toolBar: buildToolBar(),
|
||||
body: buildSettingsPane(context)
|
||||
);
|
||||
}
|
||||
}
|
||||
40
examples/fitness/lib/user_data.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'main.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
String cachedDataFilePath = null;
|
||||
|
||||
Future<String> dataFilePath() async {
|
||||
if (cachedDataFilePath == null) {
|
||||
String dataDir = await getFilesDir();
|
||||
cachedDataFilePath = path.join(dataDir, 'data.json');
|
||||
}
|
||||
return cachedDataFilePath;
|
||||
}
|
||||
|
||||
Future<UserData> loadFitnessData() async {
|
||||
String dataPath = await dataFilePath();
|
||||
print("Loading from $dataPath");
|
||||
JsonDecoder decoder = new JsonDecoder();
|
||||
Map data = await decoder.convert(await new File(dataPath).readAsString());
|
||||
return new UserDataImpl.fromJson(data);
|
||||
}
|
||||
|
||||
// Intentionally synchronous for execution just before shutdown.
|
||||
Future saveFitnessData(UserDataImpl data) async {
|
||||
String dataPath = await dataFilePath();
|
||||
print("Saving to $dataPath");
|
||||
JsonEncoder encoder = new JsonEncoder();
|
||||
String contents = await encoder.convert(data);
|
||||
File dataFile = await new File(dataPath).writeAsString(contents);
|
||||
print("Success! $dataFile");
|
||||
}
|
||||
34
examples/fitness/mac/Info.plist
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>fitness_app</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.domokit.sky.fitness</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Asteroids</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2015 The Chromium Authors. All rights reserved.</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>sky_mac</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>SkyApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
695
examples/fitness/mac/sky_mac.xib
Normal file
@@ -0,0 +1,695 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7702" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7702"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="SkyApplication">
|
||||
<connections>
|
||||
<outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="SkyAppDelegate">
|
||||
<connections>
|
||||
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
|
||||
<items>
|
||||
<menuItem title="Sky" id="1Xt-HY-uBw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Sky" systemMenu="apple" id="uQy-DD-JDr">
|
||||
<items>
|
||||
<menuItem title="About Sky" id="5kV-Vb-QxS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="orderFrontStandardAboutPanel:" target="-1" id="Exp-CZ-Vem"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
|
||||
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
|
||||
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
|
||||
<menuItem title="Services" id="NMo-om-nkz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
|
||||
<menuItem title="Hide Sky" keyEquivalent="h" id="Olw-nP-bQN">
|
||||
<connections>
|
||||
<action selector="hide:" target="-1" id="PnN-Uc-m68"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="hideOtherApplications:" target="-1" id="VT4-aY-XCT"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Show All" id="Kd2-mp-pUS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="unhideAllApplications:" target="-1" id="Dhg-Le-xox"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
|
||||
<menuItem title="Quit Sky" keyEquivalent="q" id="4sb-4s-VLi">
|
||||
<connections>
|
||||
<action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="File" id="dMs-cI-mzQ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="File" id="bib-Uj-vzu">
|
||||
<items>
|
||||
<menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
|
||||
<connections>
|
||||
<action selector="newDocument:" target="-1" id="4Si-XN-c54"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
|
||||
<connections>
|
||||
<action selector="openDocument:" target="-1" id="bVn-NM-KNZ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open Recent" id="tXI-mr-wws">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
|
||||
<items>
|
||||
<menuItem title="Clear Menu" id="vNY-rz-j42">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="clearRecentDocuments:" target="-1" id="Daa-9d-B3U"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
|
||||
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
|
||||
<connections>
|
||||
<action selector="performClose:" target="-1" id="HmO-Ls-i7Q"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
|
||||
<connections>
|
||||
<action selector="saveDocument:" target="-1" id="teZ-XB-qJY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
|
||||
<connections>
|
||||
<action selector="saveDocumentAs:" target="-1" id="mDf-zr-I0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Revert to Saved" id="KaW-ft-85H">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="revertDocumentToSaved:" target="-1" id="iJ3-Pv-kwq"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
|
||||
<menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
|
||||
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="runPageLayout:" target="-1" id="Din-rz-gC5"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Print…" keyEquivalent="p" id="aTl-1u-JFS">
|
||||
<connections>
|
||||
<action selector="print:" target="-1" id="qaZ-4w-aoO"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Edit" id="5QF-Oa-p0T">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Edit" id="W48-6f-4Dl">
|
||||
<items>
|
||||
<menuItem title="Undo" keyEquivalent="z" id="dRJ-4n-Yzg">
|
||||
<connections>
|
||||
<action selector="undo:" target="-1" id="M6e-cu-g7V"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Redo" keyEquivalent="Z" id="6dh-zS-Vam">
|
||||
<connections>
|
||||
<action selector="redo:" target="-1" id="oIA-Rs-6OD"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="WRV-NI-Exz"/>
|
||||
<menuItem title="Cut" keyEquivalent="x" id="uRl-iY-unG">
|
||||
<connections>
|
||||
<action selector="cut:" target="-1" id="YJe-68-I9s"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy" keyEquivalent="c" id="x3v-GG-iWU">
|
||||
<connections>
|
||||
<action selector="copy:" target="-1" id="G1f-GL-Joy"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
|
||||
<connections>
|
||||
<action selector="paste:" target="-1" id="UvS-8e-Qdg"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste and Match Style" keyEquivalent="V" id="WeT-3V-zwk">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteAsPlainText:" target="-1" id="cEh-KX-wJQ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Delete" id="pa3-QI-u2k">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="delete:" target="-1" id="0Mk-Ml-PaM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Select All" keyEquivalent="a" id="Ruw-6m-B2m">
|
||||
<connections>
|
||||
<action selector="selectAll:" target="-1" id="VNm-Mi-diN"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="uyl-h8-XO2"/>
|
||||
<menuItem title="Find" id="4EN-yA-p0u">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Find" id="1b7-l0-nxx">
|
||||
<items>
|
||||
<menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="cD7-Qs-BN4"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="WD3-Gg-5AJ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find Next" tag="2" keyEquivalent="g" id="q09-fT-Sye">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="NDo-RZ-v9R"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find Previous" tag="3" keyEquivalent="G" id="OwM-mh-QMV">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="HOh-sY-3ay"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="buJ-ug-pKt">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="U76-nv-p5D"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
|
||||
<connections>
|
||||
<action selector="centerSelectionInVisibleArea:" target="-1" id="IOG-6D-g5B"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Spelling and Grammar" id="Dv1-io-Yv7">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Spelling" id="3IN-sU-3Bg">
|
||||
<items>
|
||||
<menuItem title="Show Spelling and Grammar" keyEquivalent=":" id="HFo-cy-zxI">
|
||||
<connections>
|
||||
<action selector="showGuessPanel:" target="-1" id="vFj-Ks-hy3"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check Document Now" keyEquivalent=";" id="hz2-CU-CR7">
|
||||
<connections>
|
||||
<action selector="checkSpelling:" target="-1" id="fz7-VC-reM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="bNw-od-mp5"/>
|
||||
<menuItem title="Check Spelling While Typing" id="rbD-Rh-wIN">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleContinuousSpellChecking:" target="-1" id="7w6-Qz-0kB"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check Grammar With Spelling" id="mK6-2p-4JG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleGrammarChecking:" target="-1" id="muD-Qn-j4w"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Correct Spelling Automatically" id="78Y-hA-62v">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticSpellingCorrection:" target="-1" id="2lM-Qi-WAP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Substitutions" id="9ic-FL-obx">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Substitutions" id="FeM-D8-WVr">
|
||||
<items>
|
||||
<menuItem title="Show Substitutions" id="z6F-FW-3nz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="orderFrontSubstitutionsPanel:" target="-1" id="oku-mr-iSq"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="gPx-C9-uUO"/>
|
||||
<menuItem title="Smart Copy/Paste" id="9yt-4B-nSM">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleSmartInsertDelete:" target="-1" id="3IJ-Se-DZD"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Quotes" id="hQb-2v-fYv">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticQuoteSubstitution:" target="-1" id="ptq-xd-QOA"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Dashes" id="rgM-f4-ycn">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticDashSubstitution:" target="-1" id="oCt-pO-9gS"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Links" id="cwL-P1-jid">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticLinkDetection:" target="-1" id="Gip-E3-Fov"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Data Detectors" id="tRr-pd-1PS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticDataDetection:" target="-1" id="R1I-Nq-Kbl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Text Replacement" id="HFQ-gK-NFA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticTextReplacement:" target="-1" id="DvP-Fe-Py6"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Transformations" id="2oI-Rn-ZJC">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Transformations" id="c8a-y6-VQd">
|
||||
<items>
|
||||
<menuItem title="Make Upper Case" id="vmV-6d-7jI">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="uppercaseWord:" target="-1" id="sPh-Tk-edu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Make Lower Case" id="d9M-CD-aMd">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="lowercaseWord:" target="-1" id="iUZ-b5-hil"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Capitalize" id="UEZ-Bs-lqG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="capitalizeWord:" target="-1" id="26H-TL-nsh"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Speech" id="xrE-MZ-jX0">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Speech" id="3rS-ZA-NoH">
|
||||
<items>
|
||||
<menuItem title="Start Speaking" id="Ynk-f8-cLZ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="startSpeaking:" target="-1" id="654-Ng-kyl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Stop Speaking" id="Oyz-dy-DGm">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="stopSpeaking:" target="-1" id="dX8-6p-jy9"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Format" id="jxT-CU-nIS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Format" id="GEO-Iw-cKr">
|
||||
<items>
|
||||
<menuItem title="Font" id="Gi5-1S-RQB">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Font" systemMenu="font" id="aXa-aM-Jaq">
|
||||
<items>
|
||||
<menuItem title="Show Fonts" keyEquivalent="t" id="Q5e-8K-NDq">
|
||||
<connections>
|
||||
<action selector="orderFrontFontPanel:" target="YLy-65-1bz" id="WHr-nq-2xA"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Bold" tag="2" keyEquivalent="b" id="GB9-OM-e27">
|
||||
<connections>
|
||||
<action selector="addFontTrait:" target="YLy-65-1bz" id="hqk-hr-sYV"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Italic" tag="1" keyEquivalent="i" id="Vjx-xi-njq">
|
||||
<connections>
|
||||
<action selector="addFontTrait:" target="YLy-65-1bz" id="IHV-OB-c03"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Underline" keyEquivalent="u" id="WRG-CD-K1S">
|
||||
<connections>
|
||||
<action selector="underline:" target="-1" id="FYS-2b-JAY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="5gT-KC-WSO"/>
|
||||
<menuItem title="Bigger" tag="3" keyEquivalent="+" id="Ptp-SP-VEL">
|
||||
<connections>
|
||||
<action selector="modifyFont:" target="YLy-65-1bz" id="Uc7-di-UnL"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smaller" tag="4" keyEquivalent="-" id="i1d-Er-qST">
|
||||
<connections>
|
||||
<action selector="modifyFont:" target="YLy-65-1bz" id="HcX-Lf-eNd"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="kx3-Dk-x3B"/>
|
||||
<menuItem title="Kern" id="jBQ-r6-VK2">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Kern" id="tlD-Oa-oAM">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="GUa-eO-cwY">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useStandardKerning:" target="-1" id="6dk-9l-Ckg"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use None" id="cDB-IK-hbR">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="turnOffKerning:" target="-1" id="U8a-gz-Maa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Tighten" id="46P-cB-AYj">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="tightenKerning:" target="-1" id="hr7-Nz-8ro"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Loosen" id="ogc-rX-tC1">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="loosenKerning:" target="-1" id="8i4-f9-FKE"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Ligatures" id="o6e-r0-MWq">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Ligatures" id="w0m-vy-SC9">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="agt-UL-0e3">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useStandardLigatures:" target="-1" id="7uR-wd-Dx6"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use None" id="J7y-lM-qPV">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="turnOffLigatures:" target="-1" id="iX2-gA-Ilz"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use All" id="xQD-1f-W4t">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useAllLigatures:" target="-1" id="KcB-kA-TuK"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Baseline" id="OaQ-X3-Vso">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Baseline" id="ijk-EB-dga">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="3Om-Ey-2VK">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="unscript:" target="-1" id="0vZ-95-Ywn"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Superscript" id="Rqc-34-cIF">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="superscript:" target="-1" id="3qV-fo-wpU"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Subscript" id="I0S-gh-46l">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="subscript:" target="-1" id="Q6W-4W-IGz"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Raise" id="2h7-ER-AoG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="raiseBaseline:" target="-1" id="4sk-31-7Q9"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Lower" id="1tx-W0-xDw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="lowerBaseline:" target="-1" id="OF1-bc-KW4"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="Ndw-q3-faq"/>
|
||||
<menuItem title="Show Colors" keyEquivalent="C" id="bgn-CT-cEk">
|
||||
<connections>
|
||||
<action selector="orderFrontColorPanel:" target="-1" id="mSX-Xz-DV3"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="iMs-zA-UFJ"/>
|
||||
<menuItem title="Copy Style" keyEquivalent="c" id="5Vv-lz-BsD">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="copyFont:" target="-1" id="GJO-xA-L4q"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste Style" keyEquivalent="v" id="vKC-jM-MkH">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteFont:" target="-1" id="JfD-CL-leO"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Text" id="Fal-I4-PZk">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Text" id="d9c-me-L2H">
|
||||
<items>
|
||||
<menuItem title="Align Left" keyEquivalent="{" id="ZM1-6Q-yy1">
|
||||
<connections>
|
||||
<action selector="alignLeft:" target="-1" id="zUv-R1-uAa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Center" keyEquivalent="|" id="VIY-Ag-zcb">
|
||||
<connections>
|
||||
<action selector="alignCenter:" target="-1" id="spX-mk-kcS"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Justify" id="J5U-5w-g23">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="alignJustified:" target="-1" id="ljL-7U-jND"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Align Right" keyEquivalent="}" id="wb2-vD-lq4">
|
||||
<connections>
|
||||
<action selector="alignRight:" target="-1" id="r48-bG-YeY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="4s2-GY-VfK"/>
|
||||
<menuItem title="Writing Direction" id="H1b-Si-o9J">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Writing Direction" id="8mr-sm-Yjd">
|
||||
<items>
|
||||
<menuItem title="Paragraph" enabled="NO" id="ZvO-Gk-QUH">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem id="YGs-j5-SAR">
|
||||
<string key="title"> Default</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionNatural:" target="-1" id="qtV-5e-UBP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="Lbh-J2-qVU">
|
||||
<string key="title"> Left to Right</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionLeftToRight:" target="-1" id="S0X-9S-QSf"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="jFq-tB-4Kx">
|
||||
<string key="title"> Right to Left</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionRightToLeft:" target="-1" id="5fk-qB-AqJ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="swp-gr-a21"/>
|
||||
<menuItem title="Selection" enabled="NO" id="cqv-fj-IhA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem id="Nop-cj-93Q">
|
||||
<string key="title"> Default</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionNatural:" target="-1" id="lPI-Se-ZHp"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="BgM-ve-c93">
|
||||
<string key="title"> Left to Right</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionLeftToRight:" target="-1" id="caW-Bv-w94"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="RB4-Sm-HuC">
|
||||
<string key="title"> Right to Left</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionRightToLeft:" target="-1" id="EXD-6r-ZUu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="fKy-g9-1gm"/>
|
||||
<menuItem title="Show Ruler" id="vLm-3I-IUL">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleRuler:" target="-1" id="FOx-HJ-KwY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy Ruler" keyEquivalent="c" id="MkV-Pr-PK5">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="copyRuler:" target="-1" id="71i-fW-3W2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste Ruler" keyEquivalent="v" id="LVM-kO-fVI">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteRuler:" target="-1" id="cSh-wd-qM2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="View" id="H8h-7b-M4v">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="View" id="HyV-fh-RgO">
|
||||
<items>
|
||||
<menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="toggleToolbarShown:" target="-1" id="BXY-wc-z0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="runToolbarCustomizationPalette:" target="-1" id="pQI-g3-MTW"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Window" id="aUF-d1-5bR">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
|
||||
<items>
|
||||
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
|
||||
<connections>
|
||||
<action selector="performMiniaturize:" target="-1" id="VwT-WD-YPe"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Zoom" id="R4o-n2-Eq4">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="performZoom:" target="-1" id="DIl-cC-cCs"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
|
||||
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="arrangeInFront:" target="-1" id="DRN-fu-gQh"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Help" id="wpr-3q-Mcd">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
|
||||
<items>
|
||||
<menuItem title="Sky Help" keyEquivalent="?" id="FKE-Sm-Kum">
|
||||
<connections>
|
||||
<action selector="showHelp:" target="-1" id="y7X-2Q-9no"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
<window title="Sky" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g" customClass="SkyWindow">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="335" y="390" width="480" height="360"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
|
||||
<view key="contentView" id="EiT-Mj-1SZ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<openGLView autoresizesSubviews="NO" useAuxiliaryDepthBufferStencil="NO" useDoubleBufferingEnabled="YES" allowOffline="YES" translatesAutoresizingMaskIntoConstraints="NO" id="AUD-Hu-um3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
|
||||
</openGLView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="AUD-Hu-um3" secondAttribute="trailing" id="9W1-4Z-nsQ"/>
|
||||
<constraint firstItem="AUD-Hu-um3" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" id="KpO-qK-Zhv"/>
|
||||
<constraint firstAttribute="bottom" secondItem="AUD-Hu-um3" secondAttribute="bottom" id="Myy-UN-4eQ"/>
|
||||
<constraint firstItem="AUD-Hu-um3" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" id="gf3-3r-c0N"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="renderSurface" destination="AUD-Hu-um3" id="0jv-sx-91g"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="128" y="455"/>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
||||
12
examples/fitness/pubspec.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
name: fitness
|
||||
dependencies:
|
||||
flutter:
|
||||
'0.0.16'
|
||||
playfair: ^0.0.10
|
||||
path: ^1.3.6
|
||||
sky_tools: any
|
||||
dependency_overrides:
|
||||
material_design_icons:
|
||||
path: ../../sky/packages/material_design_icons
|
||||
flutter:
|
||||
path: ../../sky/packages/sky
|
||||
28
examples/game/BUILD.gn
Normal file
@@ -0,0 +1,28 @@
|
||||
# Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//sky/build/sky_app.gni")
|
||||
|
||||
sky_app("game") {
|
||||
main_dart = "lib/main.dart"
|
||||
manifest = "flutter.yaml"
|
||||
|
||||
if (is_android) {
|
||||
apk_name = "Asteroids"
|
||||
|
||||
deps = [
|
||||
"//examples/game/apk:resources",
|
||||
]
|
||||
} else if (is_ios) {
|
||||
info_plist = "ios/Info.plist"
|
||||
launcher_resources = [
|
||||
"assets/Icon.png",
|
||||
"assets/Icon@2x.png",
|
||||
"ios/LaunchScreen.storyboardc",
|
||||
]
|
||||
} else if (is_mac) {
|
||||
info_plist = "mac/Info.plist"
|
||||
xibs = [ "mac/sky_mac.xib" ]
|
||||
}
|
||||
}
|
||||
4
examples/game/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Assets for this game are from Galactic Guardian:
|
||||
https://github.com/slembcke/GalacticGuardian.spritebuilder
|
||||
And are used under MIT license:
|
||||
https://github.com/slembcke/GalacticGuardian.spritebuilder/pull/2
|
||||
24
examples/game/apk/AndroidManifest.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
Use of this source code is governed by a BSD-style license that can be
|
||||
found in the LICENSE file.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.domokit.asteroids">
|
||||
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application android:icon="@mipmap/ic_launcher" android:name="org.domokit.sky.shell.SkyApplication" android:label="Asteroids">
|
||||
<activity android:name="org.domokit.sky.shell.SkyActivity"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
|
||||
android:hardwareAccelerated="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
12
examples/game/apk/BUILD.gn
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
assert(is_android)
|
||||
|
||||
import("//build/config/android/config.gni")
|
||||
import("//build/config/android/rules.gni")
|
||||
|
||||
android_resources("resources") {
|
||||
resource_dirs = [ "res" ]
|
||||
android_manifest = "AndroidManifest.xml"
|
||||
}
|
||||
BIN
examples/game/apk/res/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
examples/game/apk/res/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
examples/game/apk/res/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
examples/game/apk/res/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
examples/game/apk/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
examples/game/assets/Icon.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
examples/game/assets/Icon@2x.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
examples/game/assets/checker.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
examples/game/assets/explosion.wav
Normal file
156
examples/game/assets/game_ui.json
Normal file
@@ -0,0 +1,156 @@
|
||||
{"frames": [
|
||||
|
||||
{
|
||||
"filename": "bar_shield.png",
|
||||
"frame": {"x":2,"y":954,"w":412,"h":100},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":412,"h":100},
|
||||
"sourceSize": {"w":412,"h":100},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "bar_shield_fill.png",
|
||||
"frame": {"x":2,"y":1156,"w":320,"h":72},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":320,"h":72},
|
||||
"sourceSize": {"w":320,"h":72},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "btn_play_down.png",
|
||||
"frame": {"x":2,"y":484,"w":468,"h":468},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":2,"y":16,"w":468,"h":468},
|
||||
"sourceSize": {"w":472,"h":484},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "btn_play_up.png",
|
||||
"frame": {"x":2,"y":2,"w":468,"h":480},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":2,"y":4,"w":468,"h":480},
|
||||
"sourceSize": {"w":472,"h":484},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "coinboard.png",
|
||||
"frame": {"x":366,"y":1056,"w":261,"h":100},
|
||||
"rotated": true,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":261,"h":100},
|
||||
"sourceSize": {"w":261,"h":100},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_0.png",
|
||||
"frame": {"x":416,"y":954,"w":38,"h":63},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":23,"y":22,"w":38,"h":63},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_1.png",
|
||||
"frame": {"x":299,"y":1286,"w":16,"h":57},
|
||||
"rotated": true,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":45,"y":25,"w":16,"h":57},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_2.png",
|
||||
"frame": {"x":324,"y":1156,"w":38,"h":63},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":23,"y":22,"w":38,"h":63},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_3.png",
|
||||
"frame": {"x":197,"y":1230,"w":35,"h":63},
|
||||
"rotated": true,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":26,"y":22,"w":35,"h":63},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_4.png",
|
||||
"frame": {"x":197,"y":1267,"w":38,"h":57},
|
||||
"rotated": true,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":23,"y":25,"w":38,"h":57},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_5.png",
|
||||
"frame": {"x":324,"y":1221,"w":38,"h":63},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":23,"y":22,"w":38,"h":63},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_6.png",
|
||||
"frame": {"x":2,"y":1230,"w":38,"h":63},
|
||||
"rotated": true,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":23,"y":22,"w":38,"h":63},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_7.png",
|
||||
"frame": {"x":262,"y":1230,"w":35,"h":60},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":26,"y":22,"w":35,"h":60},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_8.png",
|
||||
"frame": {"x":67,"y":1230,"w":38,"h":63},
|
||||
"rotated": true,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":23,"y":22,"w":38,"h":63},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "number_9.png",
|
||||
"frame": {"x":132,"y":1230,"w":38,"h":63},
|
||||
"rotated": true,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":23,"y":22,"w":38,"h":63},
|
||||
"sourceSize": {"w":84,"h":107},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "scoreboard.png",
|
||||
"frame": {"x":2,"y":1056,"w":362,"h":98},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":362,"h":98},
|
||||
"sourceSize": {"w":362,"h":98},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
}],
|
||||
"meta": {
|
||||
"app": "http://www.codeandweb.com/texturepacker",
|
||||
"version": "1.0",
|
||||
"image": "game_ui.png",
|
||||
"format": "RGBA8888",
|
||||
"size": {"w":472,"h":1319},
|
||||
"scale": "1",
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:2fc7dfe766eba152274e2661737d6b51:b44b32d1e0a4146b3591d51b12f2d7ae:10ac111e32c27e51f4e8444dbb39eff6$"
|
||||
}
|
||||
}
|
||||
BIN
examples/game/assets/game_ui.png
Normal file
|
After Width: | Height: | Size: 184 KiB |
BIN
examples/game/assets/laser.wav
Normal file
BIN
examples/game/assets/levelup.wav
Normal file
BIN
examples/game/assets/line_effects.png
Normal file
|
After Width: | Height: | Size: 382 KiB |
BIN
examples/game/assets/nebula.png
Normal file
|
After Width: | Height: | Size: 859 KiB |
BIN
examples/game/assets/pickup.wav
Normal file
246
examples/game/assets/sprites.json
Normal file
@@ -0,0 +1,246 @@
|
||||
{"frames": [
|
||||
|
||||
{
|
||||
"filename": "asteroid_big_0.nrm.png",
|
||||
"frame": {"x":2,"y":260,"w":200,"h":188},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":200,"h":188},
|
||||
"sourceSize": {"w":200,"h":188},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_big_0.png",
|
||||
"frame": {"x":2,"y":450,"w":200,"h":167},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":0,"y":21,"w":200,"h":167},
|
||||
"sourceSize": {"w":200,"h":188},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_big_1.nrm.png",
|
||||
"frame": {"x":2,"y":619,"w":204,"h":166},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":204,"h":166},
|
||||
"sourceSize": {"w":204,"h":166},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_big_1.png",
|
||||
"frame": {"x":2,"y":787,"w":204,"h":166},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":204,"h":166},
|
||||
"sourceSize": {"w":204,"h":166},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_big_2.nrm.png",
|
||||
"frame": {"x":204,"y":335,"w":194,"h":165},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":194,"h":165},
|
||||
"sourceSize": {"w":194,"h":165},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_big_2.png",
|
||||
"frame": {"x":208,"y":502,"w":194,"h":165},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":0,"y":2,"w":194,"h":165},
|
||||
"sourceSize": {"w":194,"h":167},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_small_0.nrm.png",
|
||||
"frame": {"x":347,"y":843,"w":102,"h":84},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":84},
|
||||
"sourceSize": {"w":102,"h":84},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_small_0.png",
|
||||
"frame": {"x":347,"y":929,"w":102,"h":84},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":84},
|
||||
"sourceSize": {"w":102,"h":84},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_small_1.nrm.png",
|
||||
"frame": {"x":404,"y":463,"w":96,"h":102},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":96,"h":102},
|
||||
"sourceSize": {"w":96,"h":102},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_small_1.png",
|
||||
"frame": {"x":404,"y":567,"w":96,"h":102},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":96,"h":102},
|
||||
"sourceSize": {"w":96,"h":106},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_small_2.nrm.png",
|
||||
"frame": {"x":347,"y":671,"w":109,"h":84},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":109,"h":84},
|
||||
"sourceSize": {"w":109,"h":84},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "asteroid_small_2.png",
|
||||
"frame": {"x":347,"y":757,"w":109,"h":84},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":109,"h":84},
|
||||
"sourceSize": {"w":109,"h":84},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "coin.png",
|
||||
"frame": {"x":429,"y":270,"w":42,"h":47},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":6,"y":4,"w":42,"h":47},
|
||||
"sourceSize": {"w":54,"h":56},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "enemy_destroyer_1.png",
|
||||
"frame": {"x":260,"y":193,"w":167,"h":140},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":10,"y":31,"w":167,"h":140},
|
||||
"sourceSize": {"w":188,"h":188},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "enemy_scout_0.png",
|
||||
"frame": {"x":400,"y":335,"w":107,"h":126},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":11,"y":1,"w":107,"h":126},
|
||||
"sourceSize": {"w":129,"h":129},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "explosion_flare.png",
|
||||
"frame": {"x":451,"y":2,"w":56,"h":209},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":0,"w":56,"h":209},
|
||||
"sourceSize": {"w":64,"h":256},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "explosion_particle.png",
|
||||
"frame": {"x":204,"y":260,"w":36,"h":60},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":14,"y":1,"w":36,"h":60},
|
||||
"sourceSize": {"w":64,"h":64},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "explosion_ring.png",
|
||||
"frame": {"x":2,"y":2,"w":256,"h":256},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":256,"h":256},
|
||||
"sourceSize": {"w":256,"h":256},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "fire_particle.png",
|
||||
"frame": {"x":429,"y":213,"w":55,"h":55},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":4,"w":55,"h":55},
|
||||
"sourceSize": {"w":64,"h":64},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "laser.png",
|
||||
"frame": {"x":458,"y":671,"w":37,"h":76},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":37,"h":76},
|
||||
"sourceSize": {"w":37,"h":76},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "shield.png",
|
||||
"frame": {"x":260,"y":2,"w":189,"h":189},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":189,"h":189},
|
||||
"sourceSize": {"w":189,"h":189},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "ship.nrm.png",
|
||||
"frame": {"x":208,"y":669,"w":137,"h":167},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":137,"h":167},
|
||||
"sourceSize": {"w":137,"h":167},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "ship.png",
|
||||
"frame": {"x":208,"y":838,"w":137,"h":167},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":25,"y":10,"w":137,"h":167},
|
||||
"sourceSize": {"w":188,"h":188},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "star_0.png",
|
||||
"frame": {"x":2,"y":955,"w":62,"h":62},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":1,"w":62,"h":62},
|
||||
"sourceSize": {"w":64,"h":64},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "star_1.png",
|
||||
"frame": {"x":66,"y":955,"w":62,"h":62},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":1,"w":62,"h":62},
|
||||
"sourceSize": {"w":64,"h":64},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
},
|
||||
{
|
||||
"filename": "star_2.png",
|
||||
"frame": {"x":130,"y":955,"w":62,"h":62},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":1,"w":62,"h":62},
|
||||
"sourceSize": {"w":64,"h":64},
|
||||
"pivot": {"x":0.5,"y":0.5}
|
||||
}],
|
||||
"meta": {
|
||||
"app": "http://www.codeandweb.com/texturepacker",
|
||||
"version": "1.0",
|
||||
"image": "sprites.png",
|
||||
"format": "RGBA8888",
|
||||
"size": {"w":509,"h":1019},
|
||||
"scale": "1",
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:2164a72d7de59aa3603277aa505ff73b:f339feca6ccc1f78132ecc733c94dbc5:1eabdf11f75e3a4fe3147baf7b5be24b$"
|
||||
}
|
||||
}
|
||||
BIN
examples/game/assets/sprites.png
Normal file
|
After Width: | Height: | Size: 569 KiB |
BIN
examples/game/assets/starfield.png
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
BIN
examples/game/assets/temp_music.aac
Normal file
179
examples/game/example_effect_line.dart
Normal file
@@ -0,0 +1,179 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||
|
||||
AssetBundle _initBundle() {
|
||||
if (rootBundle != null)
|
||||
return rootBundle;
|
||||
return new NetworkAssetBundle(Uri.base);
|
||||
}
|
||||
|
||||
final AssetBundle _bundle = _initBundle();
|
||||
|
||||
ImageMap _images;
|
||||
SpriteSheet _spriteSheet;
|
||||
|
||||
main() async {
|
||||
_images = new ImageMap(_bundle);
|
||||
|
||||
await _images.load(<String>[
|
||||
'assets/checker.png',
|
||||
'assets/line_effects.png'
|
||||
]);
|
||||
|
||||
assert(_images["assets/checker.png"] != null);
|
||||
|
||||
runApp(new TestApp());
|
||||
}
|
||||
|
||||
class TestApp extends StatefulComponent {
|
||||
TestAppState createState() => new TestAppState();
|
||||
}
|
||||
|
||||
final ThemeData _theme = new ThemeData(
|
||||
brightness: ThemeBrightness.light,
|
||||
primarySwatch: Colors.blue
|
||||
);
|
||||
|
||||
class TestAppState extends State<TestApp> {
|
||||
TestApp() {
|
||||
_testBed = new TestBed(_labelTexts[_selectedLine]);
|
||||
}
|
||||
|
||||
TestBed _testBed;
|
||||
int _selectedLine = 0;
|
||||
|
||||
List<String> _labelTexts = <String>[
|
||||
"Colored",
|
||||
"Smoke",
|
||||
"Electric",
|
||||
"Rocket Trail"
|
||||
];
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new MaterialApp(
|
||||
title: 'EffectLine Demo',
|
||||
theme: _theme,
|
||||
routes: <String, RouteBuilder>{
|
||||
'/': _buildColumn
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Column _buildColumn(RouteArguments args) {
|
||||
return new Column(<Widget>[
|
||||
new Flexible(child: _buildSpriteWidget()),
|
||||
_buildTabBar()
|
||||
]);
|
||||
}
|
||||
|
||||
TabBar _buildTabBar() {
|
||||
return new TabBar(
|
||||
labels: _buildTabLabels(),
|
||||
selectedIndex: _selectedLine,
|
||||
onChanged: (int selectedLine) {
|
||||
setState(() {
|
||||
_selectedLine = selectedLine;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
List<TabLabel> _buildTabLabels() {
|
||||
List<TabLabel> labels = <TabLabel>[];
|
||||
for (String text in _labelTexts)
|
||||
labels.add(new TabLabel(text: text));
|
||||
return labels;
|
||||
}
|
||||
|
||||
SpriteWidget _buildSpriteWidget() {
|
||||
_testBed.setupLine(_labelTexts[_selectedLine]);
|
||||
|
||||
return new SpriteWidget(
|
||||
_testBed,
|
||||
SpriteBoxTransformMode.letterbox
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TestBed extends NodeWithSize {
|
||||
EffectLine _line;
|
||||
|
||||
TestBed(String lineType) : super(new Size(1024.0, 1024.0)) {
|
||||
userInteractionEnabled = true;
|
||||
setupLine(lineType);
|
||||
}
|
||||
|
||||
void setupLine(String lineType) {
|
||||
if (_line != null) {
|
||||
_line.removeFromParent();
|
||||
}
|
||||
|
||||
if (lineType == "Colored") {
|
||||
// Create a line with no texture and a color sequence
|
||||
_line = new EffectLine(
|
||||
texture: null,
|
||||
colorSequence: new ColorSequence.fromStartAndEndColor(new Color(0xaaffff00), new Color(0xaaff9900)),
|
||||
widthMode: EffectLineWidthMode.barrel,
|
||||
minWidth: 10.0,
|
||||
maxWidth: 15.0,
|
||||
fadeAfterDelay: 1.0,
|
||||
fadeDuration: 1.0
|
||||
);
|
||||
} else if (lineType == "Smoke") {
|
||||
Texture baseTexture = new Texture(_images['assets/line_effects.png']);
|
||||
Texture smokyLineTexture = baseTexture.textureFromRect(new Rect.fromLTRB(0.0, 0.0, 1024.0, 128.0));
|
||||
|
||||
_line = new EffectLine(
|
||||
texture: smokyLineTexture,
|
||||
textureLoopLength: 300.0,
|
||||
colorSequence: new ColorSequence.fromStartAndEndColor(new Color(0xffffffff), new Color(0x00ffffff)),
|
||||
widthMode: EffectLineWidthMode.barrel,
|
||||
minWidth: 20.0,
|
||||
maxWidth: 80.0,
|
||||
animationMode: EffectLineAnimationMode.scroll
|
||||
);
|
||||
} else if (lineType == "Electric") {
|
||||
Texture baseTexture = new Texture(_images['assets/line_effects.png']);
|
||||
Texture electricLineTexture = baseTexture.textureFromRect(new Rect.fromLTRB(0.0, 384.0, 1024.0, 512.0));
|
||||
|
||||
_line = new EffectLine(
|
||||
texture: electricLineTexture,
|
||||
textureLoopLength: 300.0,
|
||||
widthMode: EffectLineWidthMode.barrel,
|
||||
minWidth: 20.0,
|
||||
maxWidth: 100.0,
|
||||
animationMode: EffectLineAnimationMode.random
|
||||
);
|
||||
} else if (lineType == "Rocket Trail") {
|
||||
Texture baseTexture = new Texture(_images['assets/line_effects.png']);
|
||||
Texture trailLineTexture = baseTexture.textureFromRect(new Rect.fromLTRB(0.0, 896.0, 1024.0, 1024.0));
|
||||
|
||||
_line = new EffectLine(
|
||||
texture: trailLineTexture,
|
||||
textureLoopLength: 300.0,
|
||||
widthMode: EffectLineWidthMode.barrel,
|
||||
minWidth: 20.0,
|
||||
maxWidth: 40.0,
|
||||
widthGrowthSpeed: 40.0,
|
||||
fadeAfterDelay: 0.5,
|
||||
fadeDuration: 1.5
|
||||
);
|
||||
}
|
||||
|
||||
addChild(_line);
|
||||
}
|
||||
|
||||
bool handleEvent(SpriteBoxEvent event) {
|
||||
if (event.type == "pointerdown")
|
||||
_line.points = <Point>[];
|
||||
|
||||
if (event.type == "pointerdown" || event.type == "pointermove") {
|
||||
Point pos = convertPointToNodeSpace(event.boxPosition);
|
||||
_line.addPoint(pos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
12
examples/game/flutter.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
assets:
|
||||
- assets/nebula.png
|
||||
- assets/sprites.json
|
||||
- assets/sprites.png
|
||||
- assets/starfield.png
|
||||
- assets/game_ui.png
|
||||
- assets/game_ui.json
|
||||
- assets/explosion.wav
|
||||
- assets/laser.wav
|
||||
- assets/levelup.wav
|
||||
- assets/pickup.wav
|
||||
- assets/temp_music.aac
|
||||
58
examples/game/ios/Info.plist
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
|
||||
<!--
|
||||
This executable name must match the name of the app provided to the
|
||||
ios_app GN template
|
||||
-->
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>game_app</string>
|
||||
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Asteroids</string>
|
||||
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.google.sky.game</string>
|
||||
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>game_app</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>DTPlatformName</key>
|
||||
<string>iphonesimulator</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>iphonesimulator8.3</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>8.3</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>iPhoneSimulator</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
examples/game/ios/LaunchScreen.storyboardc/01J-lp-oVM-view-Ze5-6b-2t3.nib
generated
Normal file
BIN
examples/game/ios/LaunchScreen.storyboardc/Info.plist
Normal file
BIN
examples/game/ios/LaunchScreen.storyboardc/UIViewController-01J-lp-oVM.nib
generated
Normal file
35
examples/game/lib/custom_actions.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
part of game;
|
||||
|
||||
typedef void PointSetterCallback(Point value);
|
||||
|
||||
class ActionCircularMove extends ActionInterval {
|
||||
ActionCircularMove(this.setter, this.center, this.radius, this.startAngle, this.clockWise, double duration) : super (duration);
|
||||
|
||||
final PointSetterCallback setter;
|
||||
final Point center;
|
||||
final double radius;
|
||||
final double startAngle;
|
||||
final bool clockWise;
|
||||
|
||||
void update(double t) {
|
||||
if (!clockWise) t = -t;
|
||||
double rad = radians(startAngle + t * 360.0);
|
||||
Offset offset = new Offset(math.cos(rad) * radius, math.sin(rad) * radius);
|
||||
Point pos = center + offset;
|
||||
setter(pos);
|
||||
}
|
||||
}
|
||||
|
||||
class ActionOscillate extends ActionInterval {
|
||||
ActionOscillate(this.setter, this.center, this.radius, double duration) : super(duration);
|
||||
|
||||
final PointSetterCallback setter;
|
||||
final Point center;
|
||||
final double radius;
|
||||
|
||||
void update(double t) {
|
||||
double rad = radians(t * 360.0);
|
||||
Offset offset = new Offset(math.sin(rad) * radius, 0.0);
|
||||
setter(center + offset);
|
||||
}
|
||||
}
|
||||
109
examples/game/lib/explosions.dart
Normal file
@@ -0,0 +1,109 @@
|
||||
part of game;
|
||||
|
||||
class Explosion extends Node {
|
||||
Explosion() {
|
||||
zPosition = 10.0;
|
||||
}
|
||||
}
|
||||
|
||||
class ExplosionBig extends Explosion {
|
||||
ExplosionBig(SpriteSheet sheet) {
|
||||
// Add particles
|
||||
ParticleSystem particlesDebris = new ParticleSystem(
|
||||
sheet["explosion_particle.png"],
|
||||
rotateToMovement: true,
|
||||
startRotation:90.0,
|
||||
startRotationVar: 0.0,
|
||||
endRotation: 90.0,
|
||||
startSize: 0.3,
|
||||
startSizeVar: 0.1,
|
||||
endSize: 0.3,
|
||||
endSizeVar: 0.1,
|
||||
numParticlesToEmit: 25,
|
||||
emissionRate:1000.0,
|
||||
greenVar: 127,
|
||||
redVar: 127,
|
||||
life: 0.75,
|
||||
lifeVar: 0.5
|
||||
);
|
||||
particlesDebris.zPosition = 1010.0;
|
||||
addChild(particlesDebris);
|
||||
|
||||
ParticleSystem particlesFire = new ParticleSystem(
|
||||
sheet["fire_particle.png"],
|
||||
colorSequence: new ColorSequence(<Color>[new Color(0xffffff33), new Color(0xffff3333), new Color(0x00ff3333)], <double>[0.0, 0.5, 1.0]),
|
||||
numParticlesToEmit: 25,
|
||||
emissionRate: 1000.0,
|
||||
startSize: 0.5,
|
||||
startSizeVar: 0.1,
|
||||
endSize: 0.5,
|
||||
endSizeVar: 0.1,
|
||||
posVar: new Point(10.0, 10.0),
|
||||
speed: 10.0,
|
||||
speedVar: 5.0,
|
||||
life: 0.75,
|
||||
lifeVar: 0.5
|
||||
);
|
||||
particlesFire.zPosition = 1011.0;
|
||||
addChild(particlesFire);
|
||||
|
||||
// Add ring
|
||||
Sprite spriteRing = new Sprite(sheet["explosion_ring.png"]);
|
||||
spriteRing.transferMode = ui.TransferMode.plus;
|
||||
addChild(spriteRing);
|
||||
|
||||
Action scale = new ActionTween((double a) { spriteRing.scale = a; }, 0.2, 1.0, 0.75);
|
||||
Action scaleAndRemove = new ActionSequence(<Action>[scale, new ActionRemoveNode(spriteRing)]);
|
||||
Action fade = new ActionTween((double a) { spriteRing.opacity = a; }, 1.0, 0.0, 0.75);
|
||||
actions.run(scaleAndRemove);
|
||||
actions.run(fade);
|
||||
|
||||
// Add streaks
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Sprite spriteFlare = new Sprite(sheet["explosion_flare.png"]);
|
||||
spriteFlare.pivot = new Point(0.3, 1.0);
|
||||
spriteFlare.scaleX = 0.3;
|
||||
spriteFlare.transferMode = ui.TransferMode.plus;
|
||||
spriteFlare.rotation = randomDouble() * 360.0;
|
||||
addChild(spriteFlare);
|
||||
|
||||
double multiplier = randomDouble() * 0.3 + 1.0;
|
||||
|
||||
Action scale = new ActionTween((double a) { spriteFlare.scaleY = a; }, 0.3 * multiplier, 0.8, 0.75 * multiplier);
|
||||
Action scaleAndRemove = new ActionSequence(<Action>[scale, new ActionRemoveNode(spriteFlare)]);
|
||||
Action fadeIn = new ActionTween((double a) { spriteFlare.opacity = a; }, 0.0, 1.0, 0.25 * multiplier);
|
||||
Action fadeOut = new ActionTween((double a) { spriteFlare.opacity = a; }, 1.0, 0.0, 0.5 * multiplier);
|
||||
Action fadeInOut = new ActionSequence(<Action>[fadeIn, fadeOut]);
|
||||
actions.run(scaleAndRemove);
|
||||
actions.run(fadeInOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ExplosionMini extends Explosion {
|
||||
ExplosionMini(SpriteSheet sheet) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Sprite star = new Sprite(sheet["star_0.png"]);
|
||||
star.scale = 0.5;
|
||||
star.colorOverlay = new Color(0xff95f4fb);
|
||||
star.transferMode = ui.TransferMode.plus;
|
||||
addChild(star);
|
||||
|
||||
double rotationStart = randomDouble() * 90.0;
|
||||
double rotationEnd = 180.0 + randomDouble() * 90.0;
|
||||
if (i == 0) {
|
||||
rotationStart = -rotationStart;
|
||||
rotationEnd = -rotationEnd;
|
||||
}
|
||||
|
||||
ActionTween rotate = new ActionTween((double a) { star.rotation = a; }, rotationStart, rotationEnd, 0.2);
|
||||
actions.run(rotate);
|
||||
|
||||
ActionTween fade = new ActionTween((double a) { star.opacity = a; }, 1.0, 0.0, 0.2);
|
||||
actions.run(fade);
|
||||
}
|
||||
|
||||
ActionSequence seq = new ActionSequence(<Action>[new ActionDelay(0.2), new ActionRemoveNode(this)]);
|
||||
actions.run(seq);
|
||||
}
|
||||
}
|
||||
23
examples/game/lib/flash.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
part of game;
|
||||
|
||||
class Flash extends NodeWithSize {
|
||||
Flash(Size size, this.duration) : super(size) {
|
||||
ActionTween fade = new ActionTween((double a) { _opacity = a; }, 1.0, 0.0, duration);
|
||||
ActionSequence seq = new ActionSequence(<Action>[fade, new ActionRemoveNode(this)]);
|
||||
actions.run(seq);
|
||||
}
|
||||
|
||||
double duration;
|
||||
double _opacity = 1.0;
|
||||
Paint _cachedPaint = new Paint();
|
||||
|
||||
void paint(PaintingCanvas canvas) {
|
||||
// Update the color
|
||||
_cachedPaint.color = new Color.fromARGB((255.0 * _opacity).toInt(),
|
||||
255, 255, 255);
|
||||
// Fill the area
|
||||
applyTransformForPivot(canvas);
|
||||
canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height),
|
||||
_cachedPaint);
|
||||
}
|
||||
}
|
||||
20
examples/game/lib/game_demo.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
library game;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
part 'custom_actions.dart';
|
||||
part 'explosions.dart';
|
||||
part 'flash.dart';
|
||||
part 'game_demo_node.dart';
|
||||
part 'game_objects.dart';
|
||||
part 'game_object_factory.dart';
|
||||
part 'player_state.dart';
|
||||
part 'power_bar.dart';
|
||||
part 'repeated_image.dart';
|
||||
part 'star_field.dart';
|
||||
279
examples/game/lib/game_demo_node.dart
Normal file
@@ -0,0 +1,279 @@
|
||||
part of game;
|
||||
|
||||
final double _gameSizeWidth = 320.0;
|
||||
double _gameSizeHeight = 320.0;
|
||||
|
||||
final double _chunkSpacing = 640.0;
|
||||
final int _chunksPerLevel = 9;
|
||||
|
||||
final bool _drawDebug = false;
|
||||
|
||||
typedef void GameOverCallback(int score);
|
||||
|
||||
class GameDemoNode extends NodeWithSize {
|
||||
|
||||
GameDemoNode(
|
||||
this._images,
|
||||
this._spritesGame,
|
||||
this._spritesUI,
|
||||
this._sounds,
|
||||
this._gameOverCallback
|
||||
): super(new Size(320.0, 320.0)) {
|
||||
// Add background
|
||||
_background = new RepeatedImage(_images["assets/starfield.png"]);
|
||||
addChild(_background);
|
||||
|
||||
// Create starfield
|
||||
_starField = new StarField(_spritesGame, 200);
|
||||
addChild(_starField);
|
||||
|
||||
// Add nebula
|
||||
_nebula = new RepeatedImage(_images["assets/nebula.png"], ui.TransferMode.plus);
|
||||
addChild(_nebula);
|
||||
|
||||
// Setup game screen, it will always be anchored to the bottom of the screen
|
||||
_gameScreen = new Node();
|
||||
addChild(_gameScreen);
|
||||
|
||||
// Setup the level and add it to the screen, the level is the node where
|
||||
// all our game objects live. It is moved to scroll the game
|
||||
_level = new Level();
|
||||
_gameScreen.addChild(_level);
|
||||
|
||||
// Add heads up display
|
||||
_playerState = new PlayerState(_spritesUI, _spritesGame);
|
||||
addChild(_playerState);
|
||||
|
||||
_objectFactory = new GameObjectFactory(_spritesGame, _sounds, _level, _playerState);
|
||||
|
||||
_level.ship = new Ship(_objectFactory);
|
||||
_level.ship.setupActions();
|
||||
_level.addChild(_level.ship);
|
||||
|
||||
// Add the joystick
|
||||
_joystick = new VirtualJoystick();
|
||||
_gameScreen.addChild(_joystick);
|
||||
|
||||
// Add initial game objects
|
||||
addObjects();
|
||||
}
|
||||
|
||||
// Resources
|
||||
ImageMap _images;
|
||||
Map<String, SoundEffect> _sounds;
|
||||
SpriteSheet _spritesGame;
|
||||
SpriteSheet _spritesUI;
|
||||
|
||||
// Sounds
|
||||
SoundEffectPlayer _effectPlayer = SoundEffectPlayer.sharedInstance();
|
||||
|
||||
// Callback
|
||||
GameOverCallback _gameOverCallback;
|
||||
|
||||
// Game screen nodes
|
||||
Node _gameScreen;
|
||||
VirtualJoystick _joystick;
|
||||
|
||||
GameObjectFactory _objectFactory;
|
||||
Level _level;
|
||||
StarField _starField;
|
||||
RepeatedImage _background;
|
||||
RepeatedImage _nebula;
|
||||
PlayerState _playerState;
|
||||
|
||||
// Game properties
|
||||
double _scroll = 0.0;
|
||||
|
||||
int _framesToFire = 0;
|
||||
int _framesBetweenShots = 20;
|
||||
|
||||
bool _gameOver = false;
|
||||
|
||||
void spriteBoxPerformedLayout() {
|
||||
_gameSizeHeight = spriteBox.visibleArea.height;
|
||||
_gameScreen.position = new Point(0.0, _gameSizeHeight);
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
// Scroll the level
|
||||
_scroll = _level.scroll(_playerState.scrollSpeed);
|
||||
_starField.move(0.0, _playerState.scrollSpeed);
|
||||
|
||||
_background.move(_playerState.scrollSpeed * 0.1);
|
||||
_nebula.move(_playerState.scrollSpeed);
|
||||
|
||||
// Add objects
|
||||
addObjects();
|
||||
|
||||
// Move the ship
|
||||
if (!_gameOver) {
|
||||
_level.ship.applyThrust(_joystick.value, _scroll);
|
||||
}
|
||||
|
||||
// Add shots
|
||||
if (_framesToFire == 0 && _joystick.isDown && !_gameOver) {
|
||||
fire();
|
||||
_framesToFire = (_playerState.speedLaserActive) ? _framesBetweenShots ~/ 2 : _framesBetweenShots;
|
||||
}
|
||||
if (_framesToFire > 0) _framesToFire--;
|
||||
|
||||
// Move game objects
|
||||
for (Node node in _level.children) {
|
||||
if (node is GameObject) {
|
||||
node.move();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove offscreen game objects
|
||||
for (int i = _level.children.length - 1; i >= 0; i--) {
|
||||
Node node = _level.children[i];
|
||||
if (node is GameObject) {
|
||||
node.removeIfOffscreen(_scroll);
|
||||
}
|
||||
}
|
||||
|
||||
if (_gameOver) return;
|
||||
|
||||
// Check for collisions between lasers and objects that can take damage
|
||||
List<Laser> lasers = <Laser>[];
|
||||
for (Node node in _level.children) {
|
||||
if (node is Laser) lasers.add(node);
|
||||
}
|
||||
|
||||
List<GameObject> damageables = <GameObject>[];
|
||||
for (Node node in _level.children) {
|
||||
if (node is GameObject && node.canBeDamaged) damageables.add(node);
|
||||
}
|
||||
|
||||
for (Laser laser in lasers) {
|
||||
for (GameObject damageable in damageables) {
|
||||
if (laser.collidingWith(damageable)) {
|
||||
// Hit something that can take damage
|
||||
damageable.addDamage(laser.impact);
|
||||
laser.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for collsions between ship and objects that can damage the ship
|
||||
List<Node> nodes = new List<Node>.from(_level.children);
|
||||
for (Node node in nodes) {
|
||||
if (node is GameObject && node.canDamageShip) {
|
||||
if (node.collidingWith(_level.ship)) {
|
||||
if (_playerState.shieldActive) {
|
||||
// Hit, but saved by the shield!
|
||||
node.destroy();
|
||||
} else {
|
||||
// The ship was hit :(
|
||||
killShip();
|
||||
}
|
||||
}
|
||||
} else if (node is GameObject && node.canBeCollected) {
|
||||
if (node.collidingWith(_level.ship)) {
|
||||
// The ship ran over something collectable
|
||||
node.collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int _chunk = 0;
|
||||
|
||||
void addObjects() {
|
||||
|
||||
while (_scroll + _chunkSpacing >= _chunk * _chunkSpacing) {
|
||||
addLevelChunk(
|
||||
_chunk,
|
||||
-_chunk * _chunkSpacing - _chunkSpacing);
|
||||
|
||||
_chunk += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void addLevelChunk(int chunk, double yPos) {
|
||||
int level = chunk ~/ _chunksPerLevel;
|
||||
int part = chunk % _chunksPerLevel;
|
||||
|
||||
if (part == 0) {
|
||||
LevelLabel lbl = new LevelLabel(_objectFactory, level + 1);
|
||||
lbl.position = new Point(0.0, yPos + _chunkSpacing / 2.0 - 150.0);
|
||||
_level.addChild(lbl);
|
||||
} else if (part == 1) {
|
||||
_objectFactory.addAsteroids(10 + level * 2, yPos, 0.0 + (level * 0.2).clamp(0.0, 0.7));
|
||||
} else if (part == 2) {
|
||||
_objectFactory.addEnemyScoutSwarm(4 + level * 2, yPos);
|
||||
} else if (part == 3) {
|
||||
_objectFactory.addAsteroids(10 + level * 2, yPos, 0.0 + (level * 0.2).clamp(0.0, 0.7));
|
||||
} else if (part == 4) {
|
||||
_objectFactory.addEnemyDestroyerSwarm(2 + level, yPos);
|
||||
} else if (part == 5) {
|
||||
_objectFactory.addAsteroids(10 + level * 2, yPos, 0.0 + (level * 0.2).clamp(0.0, 0.7));
|
||||
} else if (part == 6) {
|
||||
_objectFactory.addEnemyScoutSwarm(4 + level * 2, yPos);
|
||||
} else if (part == 7) {
|
||||
_objectFactory.addAsteroids(10 + level * 2, yPos, 0.0 + (level * 0.2).clamp(0.0, 0.7));
|
||||
} else if (part == 8) {
|
||||
_objectFactory.addBossFight(level, yPos);
|
||||
}
|
||||
}
|
||||
|
||||
void fire() {
|
||||
int laserLevel = _objectFactory.playerState.laserLevel;
|
||||
|
||||
Laser shot0 = new Laser(_objectFactory, laserLevel, -90.0);
|
||||
shot0.position = _level.ship.position + new Offset(17.0, -10.0);
|
||||
_level.addChild(shot0);
|
||||
|
||||
Laser shot1 = new Laser(_objectFactory, laserLevel, -90.0);
|
||||
shot1.position = _level.ship.position + new Offset(-17.0, -10.0);
|
||||
_level.addChild(shot1);
|
||||
|
||||
if (_playerState.sideLaserActive) {
|
||||
Laser shot2 = new Laser(_objectFactory, laserLevel, -45.0);
|
||||
shot2.position = _level.ship.position + new Offset(17.0, -10.0);
|
||||
_level.addChild(shot2);
|
||||
|
||||
Laser shot3 = new Laser(_objectFactory, laserLevel, -135.0);
|
||||
shot3.position = _level.ship.position + new Offset(-17.0, -10.0);
|
||||
_level.addChild(shot3);
|
||||
}
|
||||
|
||||
_effectPlayer.play(_sounds["laser"]);
|
||||
}
|
||||
|
||||
void killShip() {
|
||||
// Hide ship
|
||||
_level.ship.visible = false;
|
||||
|
||||
_effectPlayer.play(_sounds["explosion"]);
|
||||
|
||||
// Add explosion
|
||||
ExplosionBig explo = new ExplosionBig(_spritesGame);
|
||||
explo.scale = 1.5;
|
||||
explo.position = _level.ship.position;
|
||||
_level.addChild(explo);
|
||||
|
||||
// Add flash
|
||||
Flash flash = new Flash(size, 1.0);
|
||||
addChild(flash);
|
||||
|
||||
// Set the state to game over
|
||||
_gameOver = true;
|
||||
|
||||
// Return to main scene and report the score back in 2 seconds
|
||||
new Timer(new Duration(seconds: 2), () { _gameOverCallback(_playerState.score); });
|
||||
}
|
||||
}
|
||||
|
||||
class Level extends Node {
|
||||
Level() {
|
||||
position = new Point(160.0, 0.0);
|
||||
}
|
||||
|
||||
Ship ship;
|
||||
|
||||
double scroll(double scrollSpeed) {
|
||||
position += new Offset(0.0, scrollSpeed);
|
||||
return position.y;
|
||||
}
|
||||
}
|
||||
74
examples/game/lib/game_object_factory.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
part of game;
|
||||
|
||||
class GameObjectFactory {
|
||||
GameObjectFactory(this.sheet, this.sounds, this.level, this.playerState);
|
||||
|
||||
SpriteSheet sheet;
|
||||
Map<String,SoundEffect> sounds;
|
||||
Level level;
|
||||
PlayerState playerState;
|
||||
|
||||
void addAsteroids(int numAsteroids, double yPos, double distribution) {
|
||||
for (int i = 0; i < numAsteroids; i++) {
|
||||
GameObject obj;
|
||||
if (i == 0)
|
||||
obj = new AsteroidPowerUp(this);
|
||||
else if (randomDouble() < distribution)
|
||||
obj = new AsteroidBig(this);
|
||||
else
|
||||
obj = new AsteroidSmall(this);
|
||||
|
||||
Point pos = new Point(randomSignedDouble() * 160.0,
|
||||
yPos + _chunkSpacing * randomDouble());
|
||||
addGameObject(obj, pos);
|
||||
}
|
||||
}
|
||||
|
||||
void addEnemyScoutSwarm(int numEnemies, double yPos) {
|
||||
for (int i = 0; i < numEnemies; i++) {
|
||||
double spacing = math.max(_chunkSpacing / (numEnemies + 1.0), 80.0);
|
||||
double y = yPos + _chunkSpacing / 2.0 - (numEnemies - 1) * spacing / 2.0 + i * spacing;
|
||||
addGameObject(new EnemyScout(this), new Point(0.0, y));
|
||||
}
|
||||
}
|
||||
|
||||
void addEnemyDestroyerSwarm(int numEnemies, double yPos) {
|
||||
for (int i = 0; i < numEnemies; i++) {
|
||||
addGameObject(new EnemyDestroyer(this), new Point(randomSignedDouble() * 120.0 , yPos + _chunkSpacing * randomDouble()));
|
||||
}
|
||||
}
|
||||
|
||||
void addGameObject(GameObject obj, Point pos) {
|
||||
obj.position = pos;
|
||||
obj.setupActions();
|
||||
|
||||
level.addChild(obj);
|
||||
}
|
||||
|
||||
void addBossFight(int l, double yPos) {
|
||||
// Add boss
|
||||
EnemyBoss boss = new EnemyBoss(this);
|
||||
Point pos = new Point(0.0, yPos + _chunkSpacing / 2.0);
|
||||
|
||||
addGameObject(boss, pos);
|
||||
|
||||
playerState.boss = boss;
|
||||
|
||||
// Add boss's helpers
|
||||
if (l >= 1) {
|
||||
EnemyDestroyer destroyer0 = new EnemyDestroyer(this);
|
||||
addGameObject(destroyer0, new Point(-80.0, yPos + _chunkSpacing / 2.0 + 70.0));
|
||||
|
||||
EnemyDestroyer destroyer1 = new EnemyDestroyer(this);
|
||||
addGameObject(destroyer1, new Point(80.0, yPos + _chunkSpacing / 2.0 + 70.0));
|
||||
|
||||
if (l >= 2) {
|
||||
EnemyDestroyer destroyer0 = new EnemyDestroyer(this);
|
||||
addGameObject(destroyer0, new Point(-80.0, yPos + _chunkSpacing / 2.0 - 70.0));
|
||||
|
||||
EnemyDestroyer destroyer1 = new EnemyDestroyer(this);
|
||||
addGameObject(destroyer1, new Point(80.0, yPos + _chunkSpacing / 2.0 - 70.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
596
examples/game/lib/game_objects.dart
Normal file
@@ -0,0 +1,596 @@
|
||||
part of game;
|
||||
|
||||
abstract class GameObject extends Node {
|
||||
GameObject(this.f);
|
||||
|
||||
double radius = 0.0;
|
||||
double removeLimit = 1280.0;
|
||||
bool canDamageShip = true;
|
||||
bool canBeDamaged = true;
|
||||
bool canBeCollected = false;
|
||||
double maxDamage = 3.0;
|
||||
double damage = 0.0;
|
||||
|
||||
final GameObjectFactory f;
|
||||
|
||||
Paint _paintDebug = new Paint()
|
||||
..color=new Color(0xffff0000)
|
||||
..strokeWidth = 1.0
|
||||
..style = ui.PaintingStyle.stroke;
|
||||
|
||||
bool collidingWith(GameObject obj) {
|
||||
return (GameMath.distanceBetweenPoints(position, obj.position)
|
||||
< radius + obj.radius);
|
||||
}
|
||||
|
||||
void move() {
|
||||
}
|
||||
|
||||
void removeIfOffscreen(double scroll) {
|
||||
;
|
||||
if (-position.y > scroll + removeLimit ||
|
||||
-position.y < scroll - 50.0) {
|
||||
removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
if (parent != null) {
|
||||
Explosion explo = createExplosion();
|
||||
if (explo != null) {
|
||||
explo.position = position;
|
||||
parent.addChild(explo);
|
||||
}
|
||||
|
||||
Collectable powerUp = createPowerUp();
|
||||
if (powerUp != null) {
|
||||
f.addGameObject(powerUp, position);
|
||||
}
|
||||
|
||||
removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
void collect() {
|
||||
removeFromParent();
|
||||
}
|
||||
|
||||
void addDamage(double d) {
|
||||
if (!canBeDamaged) return;
|
||||
|
||||
damage += d;
|
||||
if (damage >= maxDamage) {
|
||||
destroy();
|
||||
f.playerState.score += (maxDamage * 10).ceil();
|
||||
}
|
||||
}
|
||||
|
||||
Explosion createExplosion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collectable createPowerUp() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void paint(PaintingCanvas canvas) {
|
||||
if (_drawDebug) {
|
||||
canvas.drawCircle(Point.origin, radius, _paintDebug);
|
||||
}
|
||||
super.paint(canvas);
|
||||
}
|
||||
|
||||
void setupActions() {
|
||||
}
|
||||
}
|
||||
|
||||
class LevelLabel extends GameObject {
|
||||
LevelLabel(GameObjectFactory f, int level) : super(f) {
|
||||
canDamageShip = false;
|
||||
canBeDamaged = false;
|
||||
|
||||
Label lbl = new Label(
|
||||
"L E V E L $level",
|
||||
new TextStyle(
|
||||
textAlign: TextAlign.center,
|
||||
color:new Color(0xffffffff),
|
||||
fontSize: 24.0,
|
||||
fontWeight: FontWeight.w600
|
||||
));
|
||||
addChild(lbl);
|
||||
}
|
||||
}
|
||||
|
||||
class Ship extends GameObject {
|
||||
Ship(GameObjectFactory f) : super(f) {
|
||||
// Add main ship sprite
|
||||
_sprite = new Sprite(f.sheet["ship.png"]);
|
||||
_sprite.scale = 0.3;
|
||||
_sprite.rotation = -90.0;
|
||||
addChild(_sprite);
|
||||
|
||||
_spriteShield = new Sprite(f.sheet["shield.png"]);
|
||||
_spriteShield.scale = 0.35;
|
||||
_spriteShield.transferMode = ui.TransferMode.plus;
|
||||
addChild(_spriteShield);
|
||||
|
||||
radius = 20.0;
|
||||
canBeDamaged = false;
|
||||
canDamageShip = false;
|
||||
|
||||
// Set start position
|
||||
position = new Point(0.0, 50.0);
|
||||
}
|
||||
|
||||
Sprite _sprite;
|
||||
Sprite _spriteShield;
|
||||
|
||||
void applyThrust(Point joystickValue, double scroll) {
|
||||
Point oldPos = position;
|
||||
Point target = new Point(joystickValue.x * 160.0, joystickValue.y * 220.0 - 250.0 - scroll);
|
||||
double filterFactor = 0.2;
|
||||
|
||||
position = new Point(
|
||||
GameMath.filter(oldPos.x, target.x, filterFactor),
|
||||
GameMath.filter(oldPos.y, target.y, filterFactor));
|
||||
}
|
||||
|
||||
void setupActions() {
|
||||
ActionTween rotate = new ActionTween((double a) { _spriteShield.rotation = a; }, 0.0, 360.0, 1.0);
|
||||
_spriteShield.actions.run(new ActionRepeatForever(rotate));
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
// Update shield
|
||||
if (f.playerState.shieldActive) {
|
||||
if (f.playerState.shieldDeactivating)
|
||||
_spriteShield.visible = !_spriteShield.visible;
|
||||
else
|
||||
_spriteShield.visible = true;
|
||||
} else {
|
||||
_spriteShield.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Laser extends GameObject {
|
||||
double impact = 0.0;
|
||||
|
||||
final List<Color> laserColors = <Color>[
|
||||
new Color(0xff95f4fb),
|
||||
new Color(0xff5bff35),
|
||||
new Color(0xffff886c),
|
||||
new Color(0xffffd012),
|
||||
new Color(0xfffd7fff)
|
||||
];
|
||||
|
||||
Laser(GameObjectFactory f, int level, double r) : super(f) {
|
||||
// Game object properties
|
||||
radius = 10.0;
|
||||
removeLimit = _gameSizeHeight + radius;
|
||||
canDamageShip = false;
|
||||
canBeDamaged = false;
|
||||
impact = 1.0 + level * 0.5;
|
||||
|
||||
// Offset for movement
|
||||
_offset = new Offset(
|
||||
math.cos(radians(r)) * 8.0,
|
||||
math.sin(radians(r)) * 8.0 - f.playerState.scrollSpeed);
|
||||
|
||||
// Drawing properties
|
||||
rotation = r + 90.0;
|
||||
int numLasers = level % 3 + 1;
|
||||
Color laserColor = laserColors[(level ~/ 3) % laserColors.length];
|
||||
|
||||
// Add sprites
|
||||
List<Sprite> sprites = <Sprite>[];
|
||||
for (int i = 0; i < numLasers; i++) {
|
||||
Sprite sprite = new Sprite(f.sheet["explosion_particle.png"]);
|
||||
sprite.scale = 0.5;
|
||||
sprite.colorOverlay = laserColor;
|
||||
sprite.transferMode = ui.TransferMode.plus;
|
||||
addChild(sprite);
|
||||
sprites.add(sprite);
|
||||
}
|
||||
|
||||
// Position the individual sprites
|
||||
if (numLasers == 2) {
|
||||
sprites[0].position = new Point(-3.0, 0.0);
|
||||
sprites[1].position = new Point(3.0, 0.0);
|
||||
} else if (numLasers == 3) {
|
||||
sprites[0].position = new Point(-4.0, 0.0);
|
||||
sprites[1].position = new Point(4.0, 0.0);
|
||||
sprites[2].position = new Point(0.0, -2.0);
|
||||
}
|
||||
}
|
||||
|
||||
Offset _offset;
|
||||
|
||||
void move() {
|
||||
position += _offset;
|
||||
}
|
||||
|
||||
Explosion createExplosion() {
|
||||
return new ExplosionMini(f.sheet);
|
||||
}
|
||||
}
|
||||
|
||||
Color colorForDamage(double damage, double maxDamage) {
|
||||
int alpha = ((200.0 * damage) ~/ maxDamage).clamp(0, 200);
|
||||
return new Color.fromARGB(alpha, 255, 3, 86);
|
||||
}
|
||||
|
||||
abstract class Obstacle extends GameObject {
|
||||
|
||||
Obstacle(GameObjectFactory f) : super(f);
|
||||
|
||||
double explosionScale = 1.0;
|
||||
|
||||
Explosion createExplosion() {
|
||||
SoundEffectPlayer.sharedInstance().play(f.sounds["explosion"]);
|
||||
Explosion explo = new ExplosionBig(f.sheet);
|
||||
explo.scale = explosionScale;
|
||||
return explo;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Asteroid extends Obstacle {
|
||||
Asteroid(GameObjectFactory f) : super(f);
|
||||
|
||||
Sprite _sprite;
|
||||
|
||||
void setupActions() {
|
||||
// Rotate obstacle
|
||||
int direction = 1;
|
||||
if (randomBool()) direction = -1;
|
||||
ActionTween rotate = new ActionTween(
|
||||
(double a) { _sprite.rotation = a; },
|
||||
0.0, 360.0 * direction, 5.0 + 5.0 * randomDouble());
|
||||
_sprite.actions.run(new ActionRepeatForever(rotate));
|
||||
}
|
||||
|
||||
set damage(double d) {
|
||||
super.damage = d;
|
||||
_sprite.colorOverlay = colorForDamage(d, maxDamage);
|
||||
}
|
||||
|
||||
Collectable createPowerUp() {
|
||||
return new Coin(f);
|
||||
}
|
||||
}
|
||||
|
||||
class AsteroidBig extends Asteroid {
|
||||
AsteroidBig(GameObjectFactory f) : super(f) {
|
||||
_sprite = new Sprite(f.sheet["asteroid_big_${randomInt(3)}.png"]);
|
||||
_sprite.scale = 0.3;
|
||||
radius = 25.0;
|
||||
maxDamage = 5.0;
|
||||
addChild(_sprite);
|
||||
}
|
||||
}
|
||||
|
||||
class AsteroidSmall extends Asteroid {
|
||||
AsteroidSmall(GameObjectFactory f) : super(f) {
|
||||
_sprite = new Sprite(f.sheet["asteroid_small_${randomInt(3)}.png"]);
|
||||
_sprite.scale = 0.3;
|
||||
radius = 12.0;
|
||||
maxDamage = 3.0;
|
||||
addChild(_sprite);
|
||||
}
|
||||
}
|
||||
|
||||
class AsteroidPowerUp extends AsteroidBig {
|
||||
AsteroidPowerUp(GameObjectFactory f) : super(f);
|
||||
|
||||
Collectable createPowerUp() {
|
||||
return new PowerUp(f, nextPowerUpType());
|
||||
}
|
||||
}
|
||||
|
||||
class EnemyScout extends Obstacle {
|
||||
EnemyScout(GameObjectFactory f) : super(f) {
|
||||
_sprite = new Sprite(f.sheet["enemy_scout_0.png"]);
|
||||
_sprite.scale = 0.32;
|
||||
radius = 12.0;
|
||||
maxDamage = 1.0;
|
||||
addChild(_sprite);
|
||||
|
||||
constraints = <Constraint>[new ConstraintRotationToMovement(dampening: 0.5)];
|
||||
}
|
||||
|
||||
final double _swirlSpacing = 80.0;
|
||||
|
||||
_addRandomSquare(List<Offset> offsets, double x, double y) {
|
||||
double xMove = (randomBool()) ? _swirlSpacing : -_swirlSpacing;
|
||||
double yMove = (randomBool()) ? _swirlSpacing : -_swirlSpacing;
|
||||
|
||||
if (randomBool()) {
|
||||
offsets.addAll(<Offset>[
|
||||
new Offset(x, y),
|
||||
new Offset(xMove + x, y),
|
||||
new Offset(xMove + x, yMove + y),
|
||||
new Offset(x, yMove + y),
|
||||
new Offset(x, y)
|
||||
]);
|
||||
} else {
|
||||
offsets.addAll(<Offset>[
|
||||
new Offset(x, y),
|
||||
new Offset(x, y + yMove),
|
||||
new Offset(xMove + x, yMove + y),
|
||||
new Offset(xMove + x, y),
|
||||
new Offset(x, y)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
void setupActions() {
|
||||
|
||||
List<Offset> offsets = <Offset>[];
|
||||
_addRandomSquare(offsets, -_swirlSpacing, 0.0);
|
||||
_addRandomSquare(offsets, _swirlSpacing, 0.0);
|
||||
offsets.add(new Offset(-_swirlSpacing, 0.0));
|
||||
|
||||
List<Point> points = <Point>[];
|
||||
for (Offset offset in offsets) {
|
||||
points.add(position + offset);
|
||||
}
|
||||
|
||||
ActionSpline spline = new ActionSpline((Point a) => position = a, points, 6.0);
|
||||
spline.tension = 0.7;
|
||||
actions.run(new ActionRepeatForever(spline));
|
||||
}
|
||||
|
||||
Collectable createPowerUp() {
|
||||
return new Coin(f);
|
||||
}
|
||||
|
||||
Sprite _sprite;
|
||||
}
|
||||
|
||||
class EnemyDestroyer extends Obstacle {
|
||||
EnemyDestroyer(GameObjectFactory f) : super(f) {
|
||||
_sprite = new Sprite(f.sheet["enemy_destroyer_1.png"]);
|
||||
_sprite.scale = 0.32;
|
||||
radius = 24.0;
|
||||
maxDamage = 4.0;
|
||||
addChild(_sprite);
|
||||
|
||||
constraints = <Constraint>[new ConstraintRotationToNode(f.level.ship, dampening: 0.05)];
|
||||
}
|
||||
|
||||
int _countDown = randomInt(120) + 240;
|
||||
|
||||
void setupActions() {
|
||||
ActionCircularMove circle = new ActionCircularMove(
|
||||
(Point a) { position = a; },
|
||||
position, 40.0,
|
||||
360.0 * randomDouble(),
|
||||
randomBool(),
|
||||
3.0);
|
||||
actions.run(new ActionRepeatForever(circle));
|
||||
}
|
||||
|
||||
Collectable createPowerUp() {
|
||||
return new Coin(f);
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
_countDown -= 1;
|
||||
if (_countDown <= 0) {
|
||||
// Shoot at player
|
||||
EnemyLaser laser = new EnemyLaser(f, rotation, 5.0, new Color(0xffffe38e));
|
||||
laser.position = position;
|
||||
f.level.addChild(laser);
|
||||
|
||||
_countDown = 60 + randomInt(120);
|
||||
}
|
||||
}
|
||||
|
||||
set damage(double d) {
|
||||
super.damage = d;
|
||||
_sprite.colorOverlay = colorForDamage(d, maxDamage);
|
||||
}
|
||||
|
||||
Sprite _sprite;
|
||||
}
|
||||
|
||||
class EnemyLaser extends Obstacle {
|
||||
EnemyLaser(GameObjectFactory f, double rotation, double speed, Color color) : super(f) {
|
||||
_sprite = new Sprite(f.sheet["explosion_particle.png"]);
|
||||
_sprite.scale = 0.5;
|
||||
_sprite.rotation = rotation + 90;
|
||||
_sprite.colorOverlay = color;
|
||||
addChild(_sprite);
|
||||
|
||||
canDamageShip = true;
|
||||
canBeDamaged = false;
|
||||
|
||||
double rad = radians(rotation);
|
||||
_movement = new Offset(math.cos(rad) * speed, math.sin(rad) * speed);
|
||||
}
|
||||
|
||||
Sprite _sprite;
|
||||
Offset _movement;
|
||||
|
||||
void move() {
|
||||
position += _movement;
|
||||
}
|
||||
}
|
||||
|
||||
class EnemyBoss extends Obstacle {
|
||||
EnemyBoss(GameObjectFactory f) : super(f) {
|
||||
radius = 48.0;
|
||||
_sprite = new Sprite(f.sheet["enemy_destroyer_1.png"]);
|
||||
_sprite.scale = 0.64;
|
||||
addChild(_sprite);
|
||||
maxDamage = 40.0;
|
||||
|
||||
constraints = <Constraint>[new ConstraintRotationToNode(f.level.ship, dampening: 0.05)];
|
||||
|
||||
_powerBar = new PowerBar(new Size(60.0, 10.0));
|
||||
_powerBar.pivot = new Point(0.5, 0.5);
|
||||
f.level.addChild(_powerBar);
|
||||
_powerBar.constraints = <Constraint>[new ConstraintPositionToNode(
|
||||
this,
|
||||
dampening: 0.5,
|
||||
offset: new Offset(0.0, -70.0)
|
||||
)];
|
||||
}
|
||||
|
||||
Sprite _sprite;
|
||||
PowerBar _powerBar;
|
||||
|
||||
int _countDown = randomInt(120) + 240;
|
||||
|
||||
void update(double dt) {
|
||||
_countDown -= 1;
|
||||
if (_countDown <= 0) {
|
||||
// Shoot at player
|
||||
fire(10.0);
|
||||
fire(0.0);
|
||||
fire(-10.0);
|
||||
|
||||
_countDown = 60 + randomInt(120);
|
||||
}
|
||||
}
|
||||
|
||||
void fire(double r) {
|
||||
r += rotation;
|
||||
EnemyLaser laser = new EnemyLaser(f, r, 5.0, new Color(0xffffe38e));
|
||||
|
||||
double rad = radians(r);
|
||||
Offset startOffset = new Offset(math.cos(rad) * 30.0, math.sin(rad) * 30.0);
|
||||
|
||||
laser.position = position + startOffset;
|
||||
f.level.addChild(laser);
|
||||
}
|
||||
|
||||
void setupActions() {
|
||||
ActionOscillate oscillate = new ActionOscillate((Point a) { position = a; }, position, 120.0, 3.0);
|
||||
actions.run(new ActionRepeatForever(oscillate));
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
f.playerState.boss = null;
|
||||
_powerBar.removeFromParent();
|
||||
|
||||
// Flash the screen
|
||||
NodeWithSize screen = f.playerState.parent;
|
||||
screen.addChild(new Flash(screen.size, 1.0));
|
||||
super.destroy();
|
||||
|
||||
// Add coins
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Coin coin = new Coin(f);
|
||||
Point pos = new Point(
|
||||
randomSignedDouble() * 160,
|
||||
position.y + randomSignedDouble() * 160.0);
|
||||
f.addGameObject(coin, pos);
|
||||
}
|
||||
}
|
||||
|
||||
Explosion createExplosion() {
|
||||
ExplosionBig explo = new ExplosionBig(f.sheet);
|
||||
explo.scale = 1.5;
|
||||
return explo;
|
||||
}
|
||||
|
||||
set damage(double d) {
|
||||
super.damage = d;
|
||||
_sprite.actions.stopAll();
|
||||
_sprite.actions.run(new ActionTween(
|
||||
(Color a) { _sprite.colorOverlay = a; },
|
||||
new Color.fromARGB(180, 255, 3, 86),
|
||||
new Color(0x00000000),
|
||||
0.3
|
||||
));
|
||||
|
||||
_powerBar.power = (1.0 - (damage / maxDamage)).clamp(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
class Collectable extends GameObject {
|
||||
Collectable(GameObjectFactory f) : super(f) {
|
||||
canDamageShip = false;
|
||||
canBeDamaged = false;
|
||||
canBeCollected = true;
|
||||
|
||||
zPosition = 20.0;
|
||||
}
|
||||
}
|
||||
|
||||
class Coin extends Collectable {
|
||||
Coin(GameObjectFactory f) : super(f) {
|
||||
_sprite = new Sprite(f.sheet["coin.png"]);
|
||||
_sprite.scale = 0.7;
|
||||
addChild(_sprite);
|
||||
|
||||
radius = 7.5;
|
||||
}
|
||||
|
||||
void setupActions() {
|
||||
// Rotate
|
||||
ActionTween rotate = new ActionTween((double a) { _sprite.rotation = a; }, 0.0, 360.0, 1.0);
|
||||
actions.run(new ActionRepeatForever(rotate));
|
||||
|
||||
// Fade in
|
||||
ActionTween fadeIn = new ActionTween((double a) { _sprite.opacity = a; }, 0.0, 1.0, 0.6);
|
||||
actions.run(fadeIn);
|
||||
}
|
||||
|
||||
Sprite _sprite;
|
||||
|
||||
void collect() {
|
||||
f.playerState.addCoin(this);
|
||||
super.collect();
|
||||
}
|
||||
}
|
||||
|
||||
enum PowerUpType {
|
||||
shield,
|
||||
speedLaser,
|
||||
sideLaser,
|
||||
speedBoost,
|
||||
}
|
||||
|
||||
List<PowerUpType> _powerUpTypes = new List<PowerUpType>.from(PowerUpType.values);
|
||||
int _lastPowerUp = _powerUpTypes.length;
|
||||
|
||||
PowerUpType nextPowerUpType() {
|
||||
if (_lastPowerUp >= _powerUpTypes.length) {
|
||||
_powerUpTypes.shuffle();
|
||||
_lastPowerUp = 0;
|
||||
}
|
||||
|
||||
PowerUpType type = _powerUpTypes[_lastPowerUp];
|
||||
_lastPowerUp++;
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
class PowerUp extends Collectable {
|
||||
PowerUp(GameObjectFactory f, this.type) : super(f) {
|
||||
_sprite = new Sprite(f.sheet["coin.png"]);
|
||||
_sprite.scale = 1.2;
|
||||
addChild(_sprite);
|
||||
|
||||
radius = 10.0;
|
||||
}
|
||||
|
||||
Sprite _sprite;
|
||||
PowerUpType type;
|
||||
|
||||
void setupActions() {
|
||||
ActionTween rotate = new ActionTween((double a) { _sprite.rotation = a; }, 0.0, 360.0, 1.0);
|
||||
actions.run(new ActionRepeatForever(rotate));
|
||||
|
||||
// Fade in
|
||||
ActionTween fadeIn = new ActionTween((double a) { _sprite.opacity = a; }, 0.0, 1.0, 0.6);
|
||||
actions.run(fadeIn);
|
||||
}
|
||||
|
||||
void collect() {
|
||||
f.playerState.activatePowerUp(type);
|
||||
super.collect();
|
||||
}
|
||||
}
|
||||
260
examples/game/lib/main.dart
Normal file
@@ -0,0 +1,260 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||
|
||||
import 'game_demo.dart';
|
||||
|
||||
AssetBundle _initBundle() {
|
||||
if (rootBundle != null)
|
||||
return rootBundle;
|
||||
return new NetworkAssetBundle(new Uri.directory(Uri.base.origin));
|
||||
}
|
||||
|
||||
final AssetBundle _bundle = _initBundle();
|
||||
|
||||
ImageMap _imageMap;
|
||||
SpriteSheet _spriteSheet;
|
||||
SpriteSheet _spriteSheetUI;
|
||||
Map<String, SoundEffect> _sounds = <String, SoundEffect>{};
|
||||
|
||||
main() async {
|
||||
_imageMap = new ImageMap(_bundle);
|
||||
|
||||
// Use a list to wait on all loads in parallel just before starting the app.
|
||||
List loads = [];
|
||||
|
||||
loads.add(_imageMap.load(<String>[
|
||||
'assets/nebula.png',
|
||||
'assets/sprites.png',
|
||||
'assets/starfield.png',
|
||||
'assets/game_ui.png',
|
||||
]));
|
||||
|
||||
// TODO(eseidel): SoundEffect doesn't really do anything except hold a future.
|
||||
_sounds['explosion'] = new SoundEffect(_bundle.load('assets/explosion.wav'));
|
||||
_sounds['laser'] = new SoundEffect(_bundle.load('assets/laser.wav'));
|
||||
|
||||
loads.addAll([
|
||||
_sounds['explosion'].load(),
|
||||
_sounds['laser'].load(),
|
||||
]);
|
||||
|
||||
await Future.wait(loads);
|
||||
|
||||
// TODO(eseidel): These load in serial which is bad for startup!
|
||||
String json = await _bundle.loadString('assets/sprites.json');
|
||||
_spriteSheet = new SpriteSheet(_imageMap['assets/sprites.png'], json);
|
||||
|
||||
json = await _bundle.loadString('assets/game_ui.json');
|
||||
_spriteSheetUI = new SpriteSheet(_imageMap['assets/game_ui.png'], json);
|
||||
|
||||
assert(_spriteSheet.image != null);
|
||||
|
||||
SoundTrackPlayer stPlayer = SoundTrackPlayer.sharedInstance();
|
||||
SoundTrack music = await stPlayer.load(_bundle.load('assets/temp_music.aac'));
|
||||
stPlayer.play(music);
|
||||
|
||||
runApp(new GameDemo());
|
||||
}
|
||||
|
||||
// TODO(viktork): The task bar purple is the wrong purple, we may need
|
||||
// a custom theme swatch to match the purples in the sprites.
|
||||
final ThemeData _theme = new ThemeData(
|
||||
brightness: ThemeBrightness.light,
|
||||
primarySwatch: Colors.purple
|
||||
);
|
||||
|
||||
class GameDemo extends StatefulComponent {
|
||||
GameDemoState createState() => new GameDemoState();
|
||||
}
|
||||
|
||||
class GameDemoState extends State<GameDemo> {
|
||||
NodeWithSize _game;
|
||||
int _lastScore = 0;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new MaterialApp(
|
||||
title: 'Asteroids',
|
||||
theme: _theme,
|
||||
routes: <String, RouteBuilder>{
|
||||
'/': _buildMainScene,
|
||||
'/game': _buildGameScene
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGameScene(RouteArguments args) {
|
||||
return new SpriteWidget(_game, SpriteBoxTransformMode.fixedWidth);
|
||||
}
|
||||
|
||||
Widget _buildMainScene(RouteArguments args) {
|
||||
NavigatorState navigatorState = Navigator.of(args.context);
|
||||
|
||||
return new Stack(<Widget>[
|
||||
new SpriteWidget(new MainScreenBackground(), SpriteBoxTransformMode.fixedWidth),
|
||||
new Column(<Widget>[
|
||||
new TextureButton(
|
||||
onPressed: () {
|
||||
_game = new GameDemoNode(
|
||||
_imageMap,
|
||||
_spriteSheet,
|
||||
_spriteSheetUI,
|
||||
_sounds,
|
||||
(int lastScore) {
|
||||
setState(() { _lastScore = lastScore; });
|
||||
navigatorState.pop();
|
||||
}
|
||||
);
|
||||
navigatorState.pushNamed('/game');
|
||||
},
|
||||
texture: _spriteSheetUI['btn_play_up.png'],
|
||||
textureDown: _spriteSheetUI['btn_play_down.png'],
|
||||
width: 128.0,
|
||||
height: 128.0
|
||||
),
|
||||
new DefaultTextStyle(
|
||||
child: new Text(
|
||||
"Last Score: $_lastScore"
|
||||
),
|
||||
style: new TextStyle(fontSize:20.0)
|
||||
)
|
||||
],
|
||||
justifyContent: FlexJustifyContent.center
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
class TextureButton extends StatefulComponent {
|
||||
TextureButton({
|
||||
Key key,
|
||||
this.onPressed,
|
||||
this.texture,
|
||||
this.textureDown,
|
||||
this.width: 128.0,
|
||||
this.height: 128.0
|
||||
}) : super(key: key);
|
||||
|
||||
final VoidCallback onPressed;
|
||||
final Texture texture;
|
||||
final Texture textureDown;
|
||||
final double width;
|
||||
final double height;
|
||||
|
||||
TextureButtonState createState() => new TextureButtonState();
|
||||
}
|
||||
|
||||
class TextureButtonState extends State<TextureButton> {
|
||||
bool _highlight = false;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new GestureDetector(
|
||||
child: new Container(
|
||||
width: config.width,
|
||||
height: config.height,
|
||||
child: new CustomPaint(
|
||||
onPaint: paintCallback,
|
||||
token: new _TextureButtonToken(
|
||||
_highlight,
|
||||
config.texture,
|
||||
config.textureDown,
|
||||
config.width,
|
||||
config.height
|
||||
)
|
||||
)
|
||||
),
|
||||
onTapDown: (_) {
|
||||
setState(() {
|
||||
_highlight = true;
|
||||
});
|
||||
},
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_highlight = false;
|
||||
});
|
||||
if (config.onPressed != null)
|
||||
config.onPressed();
|
||||
},
|
||||
onTapCancel: () {
|
||||
setState(() {
|
||||
_highlight = false;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void paintCallback(PaintingCanvas canvas, Size size) {
|
||||
if (config.texture == null)
|
||||
return;
|
||||
|
||||
canvas.save();
|
||||
if (_highlight && config.textureDown != null) {
|
||||
// Draw down state
|
||||
canvas.scale(size.width / config.textureDown.size.width, size.height / config.textureDown.size.height);
|
||||
config.textureDown.drawTexture(canvas, Point.origin, new Paint());
|
||||
} else {
|
||||
// Draw up state
|
||||
canvas.scale(size.width / config.texture.size.width, size.height / config.texture.size.height);
|
||||
config.texture.drawTexture(canvas, Point.origin, new Paint());
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
class _TextureButtonToken {
|
||||
_TextureButtonToken(
|
||||
this._highlight,
|
||||
this._texture,
|
||||
this._textureDown,
|
||||
this._width,
|
||||
this._height
|
||||
);
|
||||
|
||||
final bool _highlight;
|
||||
final Texture _texture;
|
||||
final Texture _textureDown;
|
||||
final double _width;
|
||||
final double _height;
|
||||
|
||||
bool operator== (other) {
|
||||
return
|
||||
other is _TextureButtonToken &&
|
||||
_highlight == other._highlight &&
|
||||
_texture == other._texture &&
|
||||
_textureDown == other._textureDown &&
|
||||
_width == other._width &&
|
||||
_height == other._height;
|
||||
}
|
||||
|
||||
int get hashCode {
|
||||
int value = 373;
|
||||
value = 37 * value * _highlight.hashCode;
|
||||
value = 37 * value * _texture.hashCode;
|
||||
value = 37 * value * _textureDown.hashCode;
|
||||
value = 37 * value * _width.hashCode;
|
||||
value = 37 * value * _height.hashCode;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
class MainScreenBackground extends NodeWithSize {
|
||||
MainScreenBackground() : super(new Size(320.0, 320.0)) {
|
||||
assert(_spriteSheet.image != null);
|
||||
|
||||
StarField starField = new StarField(_spriteSheet, 200, true);
|
||||
addChild(starField);
|
||||
}
|
||||
|
||||
void paint(PaintingCanvas canvas) {
|
||||
canvas.drawRect(new Rect.fromLTWH(0.0, 0.0, 320.0, 320.0), new Paint()..color=new Color(0xff000000));
|
||||
super.paint(canvas);
|
||||
}
|
||||
}
|
||||
180
examples/game/lib/player_state.dart
Normal file
@@ -0,0 +1,180 @@
|
||||
part of game;
|
||||
|
||||
class PlayerState extends Node {
|
||||
PlayerState(this._sheetUI, this._sheetGame) {
|
||||
// Score display
|
||||
_spriteBackgroundScore = new Sprite(_sheetUI["scoreboard.png"]);
|
||||
_spriteBackgroundScore.pivot = new Point(1.0, 0.0);
|
||||
_spriteBackgroundScore.scale = 0.35;
|
||||
_spriteBackgroundScore.position = new Point(240.0, 10.0);
|
||||
addChild(_spriteBackgroundScore);
|
||||
|
||||
_scoreDisplay = new ScoreDisplay(_sheetUI);
|
||||
_scoreDisplay.position = new Point(-13.0, 49.0);
|
||||
_spriteBackgroundScore.addChild(_scoreDisplay);
|
||||
|
||||
// Coin display
|
||||
_spriteBackgroundCoins = new Sprite(_sheetUI["coinboard.png"]);
|
||||
_spriteBackgroundCoins.pivot = new Point(1.0, 0.0);
|
||||
_spriteBackgroundCoins.scale = 0.35;
|
||||
_spriteBackgroundCoins.position = new Point(105.0, 10.0);
|
||||
addChild(_spriteBackgroundCoins);
|
||||
|
||||
_coinDisplay = new ScoreDisplay(_sheetUI);
|
||||
_coinDisplay.position = new Point(-13.0, 49.0);
|
||||
_spriteBackgroundCoins.addChild(_coinDisplay);
|
||||
}
|
||||
|
||||
final SpriteSheet _sheetUI;
|
||||
final SpriteSheet _sheetGame;
|
||||
|
||||
int laserLevel = 0;
|
||||
|
||||
static const double normalScrollSpeed = 2.0;
|
||||
|
||||
double scrollSpeed = normalScrollSpeed;
|
||||
|
||||
double _scrollSpeedTarget = normalScrollSpeed;
|
||||
|
||||
EnemyBoss boss;
|
||||
|
||||
Sprite _spriteBackgroundScore;
|
||||
ScoreDisplay _scoreDisplay;
|
||||
Sprite _spriteBackgroundCoins;
|
||||
ScoreDisplay _coinDisplay;
|
||||
|
||||
int get score => _scoreDisplay.score;
|
||||
|
||||
set score(int score) {
|
||||
_scoreDisplay.score = score;
|
||||
flashBackgroundSprite(_spriteBackgroundScore);
|
||||
}
|
||||
|
||||
int get coins => _coinDisplay.score;
|
||||
|
||||
void addCoin(Coin c) {
|
||||
// Animate coin to the top of the screen
|
||||
Point startPos = convertPointFromNode(Point.origin, c);
|
||||
Point finalPos = new Point(30.0, 30.0);
|
||||
Point middlePos = new Point((startPos.x + finalPos.x) / 2.0 + 50.0,
|
||||
(startPos.y + finalPos.y) / 2.0);
|
||||
|
||||
List<Point> path = <Point>[startPos, middlePos, finalPos];
|
||||
|
||||
Sprite sprite = new Sprite(_sheetGame["coin.png"]);
|
||||
sprite.scale = 0.7;
|
||||
|
||||
ActionSpline spline = new ActionSpline((Point a) { sprite.position = a; }, path, 0.5);
|
||||
spline.tension = 0.25;
|
||||
ActionTween rotate = new ActionTween((double a) { sprite.rotation = a; }, 0.0, 360.0, 0.5);
|
||||
ActionTween scale = new ActionTween((double a) { sprite.scale = a; }, 0.7, 1.2, 0.5);
|
||||
ActionGroup group = new ActionGroup(<Action>[spline, rotate, scale]);
|
||||
sprite.actions.run(new ActionSequence(<Action>[
|
||||
group,
|
||||
new ActionRemoveNode(sprite),
|
||||
new ActionCallFunction(() {
|
||||
_coinDisplay.score += 1;
|
||||
flashBackgroundSprite(_spriteBackgroundCoins);
|
||||
})
|
||||
]));
|
||||
|
||||
addChild(sprite);
|
||||
}
|
||||
|
||||
void activatePowerUp(PowerUpType type) {
|
||||
if (type == PowerUpType.shield) {
|
||||
_shieldFrames += 300;
|
||||
} else if (type == PowerUpType.sideLaser) {
|
||||
_sideLaserFrames += 300;
|
||||
} else if (type == PowerUpType.speedLaser) {
|
||||
_speedLaserFrames += 300;
|
||||
} else if (type == PowerUpType.speedBoost) {
|
||||
_speedBoostFrames += 150;
|
||||
}
|
||||
}
|
||||
|
||||
int _shieldFrames = 0;
|
||||
bool get shieldActive => _shieldFrames > 0 || _speedBoostFrames > 0;
|
||||
bool get shieldDeactivating =>
|
||||
math.max(_shieldFrames, _speedBoostFrames) > 0 && math.max(_shieldFrames, _speedBoostFrames) < 60;
|
||||
|
||||
int _sideLaserFrames = 0;
|
||||
bool get sideLaserActive => _sideLaserFrames > 0;
|
||||
|
||||
int _speedLaserFrames = 0;
|
||||
bool get speedLaserActive => _speedLaserFrames > 0;
|
||||
|
||||
int _speedBoostFrames = 0;
|
||||
bool get speedBoostActive => _speedBoostFrames > 0;
|
||||
|
||||
void flashBackgroundSprite(Sprite sprite) {
|
||||
sprite.actions.stopAll();
|
||||
ActionTween flash = new ActionTween(
|
||||
(Color a) { sprite.colorOverlay = a; },
|
||||
new Color(0x66ccfff0),
|
||||
new Color(0x00ccfff0),
|
||||
0.3);
|
||||
sprite.actions.run(flash);
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
if (_shieldFrames > 0)
|
||||
_shieldFrames--;
|
||||
if (_sideLaserFrames > 0)
|
||||
_sideLaserFrames--;
|
||||
if (_speedLaserFrames > 0)
|
||||
_speedLaserFrames--;
|
||||
if (_speedBoostFrames > 0)
|
||||
_speedBoostFrames--;
|
||||
|
||||
// Update speed
|
||||
if (boss != null) {
|
||||
Point globalBossPos = boss.convertPointToBoxSpace(Point.origin);
|
||||
if (globalBossPos.y > (_gameSizeHeight - 400.0))
|
||||
_scrollSpeedTarget = 0.0;
|
||||
else
|
||||
_scrollSpeedTarget = normalScrollSpeed;
|
||||
} else {
|
||||
if (speedBoostActive)
|
||||
_scrollSpeedTarget = normalScrollSpeed * 6.0;
|
||||
else
|
||||
_scrollSpeedTarget = normalScrollSpeed;
|
||||
}
|
||||
|
||||
scrollSpeed = GameMath.filter(scrollSpeed, _scrollSpeedTarget, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
class ScoreDisplay extends Node {
|
||||
ScoreDisplay(this._sheetUI);
|
||||
|
||||
int _score = 0;
|
||||
|
||||
int get score => _score;
|
||||
|
||||
set score(int score) {
|
||||
_score = score;
|
||||
_dirtyScore = true;
|
||||
}
|
||||
|
||||
SpriteSheet _sheetUI;
|
||||
|
||||
bool _dirtyScore = true;
|
||||
|
||||
void update(double dt) {
|
||||
if (_dirtyScore) {
|
||||
removeAllChildren();
|
||||
|
||||
String scoreStr = _score.toString();
|
||||
double xPos = -37.0;
|
||||
for (int i = scoreStr.length - 1; i >= 0; i--) {
|
||||
String numStr = scoreStr.substring(i, i + 1);
|
||||
Sprite numSprite = new Sprite(_sheetUI["number_$numStr.png"]);
|
||||
numSprite.position = new Point(xPos, 0.0);
|
||||
addChild(numSprite);
|
||||
xPos -= 37.0;
|
||||
}
|
||||
_dirtyScore = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
examples/game/lib/power_bar.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
part of game;
|
||||
|
||||
class PowerBar extends NodeWithSize {
|
||||
PowerBar(Size size, [this.power = 1.0]) : super(size);
|
||||
|
||||
double power;
|
||||
|
||||
Paint _paintFill = new Paint()
|
||||
..color = new Color(0xffffffff);
|
||||
Paint _paintOutline = new Paint()
|
||||
..color = new Color(0xffffffff)
|
||||
..strokeWidth = 1.0
|
||||
..style = ui.PaintingStyle.stroke;
|
||||
|
||||
void paint(PaintingCanvas canvas) {
|
||||
applyTransformForPivot(canvas);
|
||||
|
||||
canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width - 0.0, size.height - 0.0), _paintOutline);
|
||||
canvas.drawRect(new Rect.fromLTRB(2.0, 2.0, (size.width - 2.0) * power, size.height - 2.0), _paintFill);
|
||||
}
|
||||
}
|
||||
29
examples/game/lib/repeated_image.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
part of game;
|
||||
|
||||
class RepeatedImage extends Node {
|
||||
Sprite _sprite0;
|
||||
Sprite _sprite1;
|
||||
|
||||
RepeatedImage(ui.Image image, [ui.TransferMode mode = null]) {
|
||||
_sprite0 = new Sprite.fromImage(image);
|
||||
_sprite0.size = new Size(1024.0, 1024.0);
|
||||
_sprite0.pivot = Point.origin;
|
||||
_sprite1 = new Sprite.fromImage(image);
|
||||
_sprite1.size = new Size(1024.0, 1024.0);
|
||||
_sprite1.pivot = Point.origin;
|
||||
_sprite1.position = new Point(0.0, -1024.0);
|
||||
|
||||
if (mode != null) {
|
||||
_sprite0.transferMode = mode;
|
||||
_sprite1.transferMode = mode;
|
||||
}
|
||||
|
||||
addChild(_sprite0);
|
||||
addChild(_sprite1);
|
||||
}
|
||||
|
||||
void move(double dy) {
|
||||
double yPos = (position.y + dy) % 1024.0;
|
||||
position = new Point(0.0, yPos);
|
||||
}
|
||||
}
|
||||
89
examples/game/lib/star_field.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
part of game;
|
||||
|
||||
class StarField extends NodeWithSize {
|
||||
ui.Image _image;
|
||||
SpriteSheet _spriteSheet;
|
||||
int _numStars;
|
||||
bool _autoScroll;
|
||||
|
||||
List<Point> _starPositions;
|
||||
List<double> _starScales;
|
||||
List<Rect> _rects;
|
||||
List<Color> _colors;
|
||||
|
||||
final double _padding = 50.0;
|
||||
Size _paddedSize = Size.zero;
|
||||
|
||||
Paint _paint = new Paint()
|
||||
..filterQuality = ui.FilterQuality.low
|
||||
..isAntiAlias = false
|
||||
..transferMode = ui.TransferMode.plus;
|
||||
|
||||
StarField(this._spriteSheet, this._numStars, [this._autoScroll = false]) : super(Size.zero) {
|
||||
_image = _spriteSheet.image;
|
||||
}
|
||||
|
||||
void addStars() {
|
||||
_starPositions = <Point>[];
|
||||
_starScales = <double>[];
|
||||
_colors = <Color>[];
|
||||
_rects = <Rect>[];
|
||||
|
||||
size = spriteBox.visibleArea.size;
|
||||
_paddedSize = new Size(size.width + _padding * 2.0,
|
||||
size.height + _padding * 2.0);
|
||||
|
||||
for (int i = 0; i < _numStars; i++) {
|
||||
_starPositions.add(new Point(randomDouble() * _paddedSize.width,
|
||||
randomDouble() * _paddedSize.height));
|
||||
_starScales.add(randomDouble() * 0.4);
|
||||
_colors.add(new Color.fromARGB((255.0 * (randomDouble() * 0.5 + 0.5)).toInt(), 255, 255, 255));
|
||||
_rects.add(_spriteSheet["star_${randomInt(2)}.png"].frame);
|
||||
}
|
||||
}
|
||||
|
||||
void spriteBoxPerformedLayout() {
|
||||
addStars();
|
||||
}
|
||||
|
||||
void paint(PaintingCanvas canvas) {
|
||||
// Create a transform for each star
|
||||
List<ui.RSTransform> transforms = <ui.RSTransform>[];
|
||||
for (int i = 0; i < _numStars; i++) {
|
||||
ui.RSTransform transform = new ui.RSTransform(
|
||||
_starScales[i],
|
||||
0.0,
|
||||
_starPositions[i].x - _padding,
|
||||
_starPositions[i].y - _padding);
|
||||
|
||||
transforms.add(transform);
|
||||
}
|
||||
|
||||
// Draw the stars
|
||||
canvas.drawAtlas(_image, transforms, _rects, _colors, ui.TransferMode.modulate, null, _paint);
|
||||
}
|
||||
|
||||
void move(double dx, double dy) {
|
||||
for (int i = 0; i < _numStars; i++) {
|
||||
double xPos = _starPositions[i].x;
|
||||
double yPos = _starPositions[i].y;
|
||||
double scale = _starScales[i];
|
||||
|
||||
xPos += dx * scale;
|
||||
yPos += dy * scale;
|
||||
|
||||
if (xPos >= _paddedSize.width) xPos -= _paddedSize.width;
|
||||
if (xPos < 0) xPos += _paddedSize.width;
|
||||
if (yPos >= _paddedSize.height) yPos -= _paddedSize.height;
|
||||
if (yPos < 0) yPos += _paddedSize.height;
|
||||
|
||||
_starPositions[i] = new Point(xPos, yPos);
|
||||
}
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
if (_autoScroll) {
|
||||
move(0.0, dt * 100.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
examples/game/mac/Info.plist
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>game_app</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.domokit.sky.asteroids</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Asteroids</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2015 The Chromium Authors. All rights reserved.</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>sky_mac</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>SkyApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
695
examples/game/mac/sky_mac.xib
Normal file
@@ -0,0 +1,695 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7702" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7702"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="SkyApplication">
|
||||
<connections>
|
||||
<outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="SkyAppDelegate">
|
||||
<connections>
|
||||
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
|
||||
<items>
|
||||
<menuItem title="Sky" id="1Xt-HY-uBw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Sky" systemMenu="apple" id="uQy-DD-JDr">
|
||||
<items>
|
||||
<menuItem title="About Sky" id="5kV-Vb-QxS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="orderFrontStandardAboutPanel:" target="-1" id="Exp-CZ-Vem"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
|
||||
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
|
||||
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
|
||||
<menuItem title="Services" id="NMo-om-nkz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
|
||||
<menuItem title="Hide Sky" keyEquivalent="h" id="Olw-nP-bQN">
|
||||
<connections>
|
||||
<action selector="hide:" target="-1" id="PnN-Uc-m68"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="hideOtherApplications:" target="-1" id="VT4-aY-XCT"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Show All" id="Kd2-mp-pUS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="unhideAllApplications:" target="-1" id="Dhg-Le-xox"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
|
||||
<menuItem title="Quit Sky" keyEquivalent="q" id="4sb-4s-VLi">
|
||||
<connections>
|
||||
<action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="File" id="dMs-cI-mzQ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="File" id="bib-Uj-vzu">
|
||||
<items>
|
||||
<menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
|
||||
<connections>
|
||||
<action selector="newDocument:" target="-1" id="4Si-XN-c54"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
|
||||
<connections>
|
||||
<action selector="openDocument:" target="-1" id="bVn-NM-KNZ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open Recent" id="tXI-mr-wws">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
|
||||
<items>
|
||||
<menuItem title="Clear Menu" id="vNY-rz-j42">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="clearRecentDocuments:" target="-1" id="Daa-9d-B3U"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
|
||||
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
|
||||
<connections>
|
||||
<action selector="performClose:" target="-1" id="HmO-Ls-i7Q"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
|
||||
<connections>
|
||||
<action selector="saveDocument:" target="-1" id="teZ-XB-qJY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
|
||||
<connections>
|
||||
<action selector="saveDocumentAs:" target="-1" id="mDf-zr-I0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Revert to Saved" id="KaW-ft-85H">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="revertDocumentToSaved:" target="-1" id="iJ3-Pv-kwq"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
|
||||
<menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
|
||||
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="runPageLayout:" target="-1" id="Din-rz-gC5"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Print…" keyEquivalent="p" id="aTl-1u-JFS">
|
||||
<connections>
|
||||
<action selector="print:" target="-1" id="qaZ-4w-aoO"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Edit" id="5QF-Oa-p0T">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Edit" id="W48-6f-4Dl">
|
||||
<items>
|
||||
<menuItem title="Undo" keyEquivalent="z" id="dRJ-4n-Yzg">
|
||||
<connections>
|
||||
<action selector="undo:" target="-1" id="M6e-cu-g7V"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Redo" keyEquivalent="Z" id="6dh-zS-Vam">
|
||||
<connections>
|
||||
<action selector="redo:" target="-1" id="oIA-Rs-6OD"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="WRV-NI-Exz"/>
|
||||
<menuItem title="Cut" keyEquivalent="x" id="uRl-iY-unG">
|
||||
<connections>
|
||||
<action selector="cut:" target="-1" id="YJe-68-I9s"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy" keyEquivalent="c" id="x3v-GG-iWU">
|
||||
<connections>
|
||||
<action selector="copy:" target="-1" id="G1f-GL-Joy"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
|
||||
<connections>
|
||||
<action selector="paste:" target="-1" id="UvS-8e-Qdg"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste and Match Style" keyEquivalent="V" id="WeT-3V-zwk">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteAsPlainText:" target="-1" id="cEh-KX-wJQ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Delete" id="pa3-QI-u2k">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="delete:" target="-1" id="0Mk-Ml-PaM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Select All" keyEquivalent="a" id="Ruw-6m-B2m">
|
||||
<connections>
|
||||
<action selector="selectAll:" target="-1" id="VNm-Mi-diN"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="uyl-h8-XO2"/>
|
||||
<menuItem title="Find" id="4EN-yA-p0u">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Find" id="1b7-l0-nxx">
|
||||
<items>
|
||||
<menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="cD7-Qs-BN4"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="WD3-Gg-5AJ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find Next" tag="2" keyEquivalent="g" id="q09-fT-Sye">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="NDo-RZ-v9R"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find Previous" tag="3" keyEquivalent="G" id="OwM-mh-QMV">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="HOh-sY-3ay"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="buJ-ug-pKt">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="U76-nv-p5D"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
|
||||
<connections>
|
||||
<action selector="centerSelectionInVisibleArea:" target="-1" id="IOG-6D-g5B"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Spelling and Grammar" id="Dv1-io-Yv7">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Spelling" id="3IN-sU-3Bg">
|
||||
<items>
|
||||
<menuItem title="Show Spelling and Grammar" keyEquivalent=":" id="HFo-cy-zxI">
|
||||
<connections>
|
||||
<action selector="showGuessPanel:" target="-1" id="vFj-Ks-hy3"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check Document Now" keyEquivalent=";" id="hz2-CU-CR7">
|
||||
<connections>
|
||||
<action selector="checkSpelling:" target="-1" id="fz7-VC-reM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="bNw-od-mp5"/>
|
||||
<menuItem title="Check Spelling While Typing" id="rbD-Rh-wIN">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleContinuousSpellChecking:" target="-1" id="7w6-Qz-0kB"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check Grammar With Spelling" id="mK6-2p-4JG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleGrammarChecking:" target="-1" id="muD-Qn-j4w"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Correct Spelling Automatically" id="78Y-hA-62v">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticSpellingCorrection:" target="-1" id="2lM-Qi-WAP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Substitutions" id="9ic-FL-obx">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Substitutions" id="FeM-D8-WVr">
|
||||
<items>
|
||||
<menuItem title="Show Substitutions" id="z6F-FW-3nz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="orderFrontSubstitutionsPanel:" target="-1" id="oku-mr-iSq"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="gPx-C9-uUO"/>
|
||||
<menuItem title="Smart Copy/Paste" id="9yt-4B-nSM">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleSmartInsertDelete:" target="-1" id="3IJ-Se-DZD"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Quotes" id="hQb-2v-fYv">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticQuoteSubstitution:" target="-1" id="ptq-xd-QOA"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Dashes" id="rgM-f4-ycn">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticDashSubstitution:" target="-1" id="oCt-pO-9gS"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Links" id="cwL-P1-jid">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticLinkDetection:" target="-1" id="Gip-E3-Fov"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Data Detectors" id="tRr-pd-1PS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticDataDetection:" target="-1" id="R1I-Nq-Kbl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Text Replacement" id="HFQ-gK-NFA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticTextReplacement:" target="-1" id="DvP-Fe-Py6"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Transformations" id="2oI-Rn-ZJC">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Transformations" id="c8a-y6-VQd">
|
||||
<items>
|
||||
<menuItem title="Make Upper Case" id="vmV-6d-7jI">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="uppercaseWord:" target="-1" id="sPh-Tk-edu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Make Lower Case" id="d9M-CD-aMd">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="lowercaseWord:" target="-1" id="iUZ-b5-hil"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Capitalize" id="UEZ-Bs-lqG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="capitalizeWord:" target="-1" id="26H-TL-nsh"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Speech" id="xrE-MZ-jX0">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Speech" id="3rS-ZA-NoH">
|
||||
<items>
|
||||
<menuItem title="Start Speaking" id="Ynk-f8-cLZ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="startSpeaking:" target="-1" id="654-Ng-kyl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Stop Speaking" id="Oyz-dy-DGm">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="stopSpeaking:" target="-1" id="dX8-6p-jy9"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Format" id="jxT-CU-nIS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Format" id="GEO-Iw-cKr">
|
||||
<items>
|
||||
<menuItem title="Font" id="Gi5-1S-RQB">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Font" systemMenu="font" id="aXa-aM-Jaq">
|
||||
<items>
|
||||
<menuItem title="Show Fonts" keyEquivalent="t" id="Q5e-8K-NDq">
|
||||
<connections>
|
||||
<action selector="orderFrontFontPanel:" target="YLy-65-1bz" id="WHr-nq-2xA"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Bold" tag="2" keyEquivalent="b" id="GB9-OM-e27">
|
||||
<connections>
|
||||
<action selector="addFontTrait:" target="YLy-65-1bz" id="hqk-hr-sYV"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Italic" tag="1" keyEquivalent="i" id="Vjx-xi-njq">
|
||||
<connections>
|
||||
<action selector="addFontTrait:" target="YLy-65-1bz" id="IHV-OB-c03"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Underline" keyEquivalent="u" id="WRG-CD-K1S">
|
||||
<connections>
|
||||
<action selector="underline:" target="-1" id="FYS-2b-JAY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="5gT-KC-WSO"/>
|
||||
<menuItem title="Bigger" tag="3" keyEquivalent="+" id="Ptp-SP-VEL">
|
||||
<connections>
|
||||
<action selector="modifyFont:" target="YLy-65-1bz" id="Uc7-di-UnL"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smaller" tag="4" keyEquivalent="-" id="i1d-Er-qST">
|
||||
<connections>
|
||||
<action selector="modifyFont:" target="YLy-65-1bz" id="HcX-Lf-eNd"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="kx3-Dk-x3B"/>
|
||||
<menuItem title="Kern" id="jBQ-r6-VK2">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Kern" id="tlD-Oa-oAM">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="GUa-eO-cwY">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useStandardKerning:" target="-1" id="6dk-9l-Ckg"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use None" id="cDB-IK-hbR">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="turnOffKerning:" target="-1" id="U8a-gz-Maa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Tighten" id="46P-cB-AYj">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="tightenKerning:" target="-1" id="hr7-Nz-8ro"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Loosen" id="ogc-rX-tC1">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="loosenKerning:" target="-1" id="8i4-f9-FKE"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Ligatures" id="o6e-r0-MWq">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Ligatures" id="w0m-vy-SC9">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="agt-UL-0e3">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useStandardLigatures:" target="-1" id="7uR-wd-Dx6"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use None" id="J7y-lM-qPV">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="turnOffLigatures:" target="-1" id="iX2-gA-Ilz"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use All" id="xQD-1f-W4t">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useAllLigatures:" target="-1" id="KcB-kA-TuK"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Baseline" id="OaQ-X3-Vso">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Baseline" id="ijk-EB-dga">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="3Om-Ey-2VK">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="unscript:" target="-1" id="0vZ-95-Ywn"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Superscript" id="Rqc-34-cIF">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="superscript:" target="-1" id="3qV-fo-wpU"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Subscript" id="I0S-gh-46l">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="subscript:" target="-1" id="Q6W-4W-IGz"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Raise" id="2h7-ER-AoG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="raiseBaseline:" target="-1" id="4sk-31-7Q9"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Lower" id="1tx-W0-xDw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="lowerBaseline:" target="-1" id="OF1-bc-KW4"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="Ndw-q3-faq"/>
|
||||
<menuItem title="Show Colors" keyEquivalent="C" id="bgn-CT-cEk">
|
||||
<connections>
|
||||
<action selector="orderFrontColorPanel:" target="-1" id="mSX-Xz-DV3"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="iMs-zA-UFJ"/>
|
||||
<menuItem title="Copy Style" keyEquivalent="c" id="5Vv-lz-BsD">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="copyFont:" target="-1" id="GJO-xA-L4q"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste Style" keyEquivalent="v" id="vKC-jM-MkH">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteFont:" target="-1" id="JfD-CL-leO"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Text" id="Fal-I4-PZk">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Text" id="d9c-me-L2H">
|
||||
<items>
|
||||
<menuItem title="Align Left" keyEquivalent="{" id="ZM1-6Q-yy1">
|
||||
<connections>
|
||||
<action selector="alignLeft:" target="-1" id="zUv-R1-uAa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Center" keyEquivalent="|" id="VIY-Ag-zcb">
|
||||
<connections>
|
||||
<action selector="alignCenter:" target="-1" id="spX-mk-kcS"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Justify" id="J5U-5w-g23">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="alignJustified:" target="-1" id="ljL-7U-jND"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Align Right" keyEquivalent="}" id="wb2-vD-lq4">
|
||||
<connections>
|
||||
<action selector="alignRight:" target="-1" id="r48-bG-YeY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="4s2-GY-VfK"/>
|
||||
<menuItem title="Writing Direction" id="H1b-Si-o9J">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Writing Direction" id="8mr-sm-Yjd">
|
||||
<items>
|
||||
<menuItem title="Paragraph" enabled="NO" id="ZvO-Gk-QUH">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem id="YGs-j5-SAR">
|
||||
<string key="title"> Default</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionNatural:" target="-1" id="qtV-5e-UBP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="Lbh-J2-qVU">
|
||||
<string key="title"> Left to Right</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionLeftToRight:" target="-1" id="S0X-9S-QSf"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="jFq-tB-4Kx">
|
||||
<string key="title"> Right to Left</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionRightToLeft:" target="-1" id="5fk-qB-AqJ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="swp-gr-a21"/>
|
||||
<menuItem title="Selection" enabled="NO" id="cqv-fj-IhA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem id="Nop-cj-93Q">
|
||||
<string key="title"> Default</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionNatural:" target="-1" id="lPI-Se-ZHp"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="BgM-ve-c93">
|
||||
<string key="title"> Left to Right</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionLeftToRight:" target="-1" id="caW-Bv-w94"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="RB4-Sm-HuC">
|
||||
<string key="title"> Right to Left</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionRightToLeft:" target="-1" id="EXD-6r-ZUu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="fKy-g9-1gm"/>
|
||||
<menuItem title="Show Ruler" id="vLm-3I-IUL">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleRuler:" target="-1" id="FOx-HJ-KwY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy Ruler" keyEquivalent="c" id="MkV-Pr-PK5">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="copyRuler:" target="-1" id="71i-fW-3W2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste Ruler" keyEquivalent="v" id="LVM-kO-fVI">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteRuler:" target="-1" id="cSh-wd-qM2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="View" id="H8h-7b-M4v">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="View" id="HyV-fh-RgO">
|
||||
<items>
|
||||
<menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="toggleToolbarShown:" target="-1" id="BXY-wc-z0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="runToolbarCustomizationPalette:" target="-1" id="pQI-g3-MTW"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Window" id="aUF-d1-5bR">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
|
||||
<items>
|
||||
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
|
||||
<connections>
|
||||
<action selector="performMiniaturize:" target="-1" id="VwT-WD-YPe"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Zoom" id="R4o-n2-Eq4">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="performZoom:" target="-1" id="DIl-cC-cCs"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
|
||||
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="arrangeInFront:" target="-1" id="DRN-fu-gQh"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Help" id="wpr-3q-Mcd">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
|
||||
<items>
|
||||
<menuItem title="Sky Help" keyEquivalent="?" id="FKE-Sm-Kum">
|
||||
<connections>
|
||||
<action selector="showHelp:" target="-1" id="y7X-2Q-9no"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
<window title="Sky" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g" customClass="SkyWindow">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="335" y="390" width="480" height="360"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
|
||||
<view key="contentView" id="EiT-Mj-1SZ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<openGLView autoresizesSubviews="NO" useAuxiliaryDepthBufferStencil="NO" useDoubleBufferingEnabled="YES" allowOffline="YES" translatesAutoresizingMaskIntoConstraints="NO" id="AUD-Hu-um3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
|
||||
</openGLView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="AUD-Hu-um3" secondAttribute="trailing" id="9W1-4Z-nsQ"/>
|
||||
<constraint firstItem="AUD-Hu-um3" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" id="KpO-qK-Zhv"/>
|
||||
<constraint firstAttribute="bottom" secondItem="AUD-Hu-um3" secondAttribute="bottom" id="Myy-UN-4eQ"/>
|
||||
<constraint firstItem="AUD-Hu-um3" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" id="gf3-3r-c0N"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="renderSurface" destination="AUD-Hu-um3" id="0jv-sx-91g"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="128" y="455"/>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
||||
15
examples/game/pubspec.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
name: asteroids
|
||||
dependencies:
|
||||
flutter:
|
||||
'0.0.16'
|
||||
sky_tools: any
|
||||
flutter_sprites:
|
||||
'0.0.13'
|
||||
box2d: any
|
||||
dependency_overrides:
|
||||
material_design_icons:
|
||||
path: ../../sky/packages/material_design_icons
|
||||
flutter:
|
||||
path: ../../sky/packages/sky
|
||||
flutter_sprites:
|
||||
path: ../../skysprites
|
||||
58
examples/game/test_bed.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||
|
||||
AssetBundle _initBundle() {
|
||||
if (rootBundle != null)
|
||||
return rootBundle;
|
||||
return new NetworkAssetBundle(Uri.base);
|
||||
}
|
||||
|
||||
final AssetBundle _bundle = _initBundle();
|
||||
|
||||
ImageMap _images;
|
||||
SpriteSheet _spriteSheet;
|
||||
TestBedApp _app;
|
||||
|
||||
main() async {
|
||||
_images = new ImageMap(_bundle);
|
||||
|
||||
await _images.load(<String>[
|
||||
'assets/sprites.png'
|
||||
]);
|
||||
|
||||
String json = await _bundle.loadString('assets/sprites.json');
|
||||
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
||||
|
||||
_app = new TestBedApp();
|
||||
runApp(_app);
|
||||
}
|
||||
|
||||
class TestBedApp extends MaterialApp {
|
||||
|
||||
Widget build() {
|
||||
ThemeData theme = new ThemeData(
|
||||
brightness: ThemeBrightness.light,
|
||||
primarySwatch: Colors.purple
|
||||
);
|
||||
|
||||
return new Theme(
|
||||
data: theme,
|
||||
child: new Title(
|
||||
title: 'Test Bed',
|
||||
child: new SpriteWidget(
|
||||
new TestBed(),
|
||||
SpriteBoxTransformMode.letterbox
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TestBed extends NodeWithSize {
|
||||
TestBed() : super(new Size(1024.0, 1024.0));
|
||||
}
|
||||
75
examples/game/test_drawatlas.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||
|
||||
AssetBundle _initBundle() {
|
||||
if (rootBundle != null)
|
||||
return rootBundle;
|
||||
return new NetworkAssetBundle(Uri.base);
|
||||
}
|
||||
|
||||
final AssetBundle _bundle = _initBundle();
|
||||
|
||||
ImageMap _images;
|
||||
SpriteSheet _spriteSheet;
|
||||
|
||||
final ThemeData _theme = new ThemeData(
|
||||
brightness: ThemeBrightness.light,
|
||||
primarySwatch: Colors.purple
|
||||
);
|
||||
|
||||
main() async {
|
||||
_images = new ImageMap(_bundle);
|
||||
|
||||
await _images.load(<String>[
|
||||
'assets/sprites.png'
|
||||
]);
|
||||
|
||||
String json = await _bundle.loadString('assets/sprites.json');
|
||||
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
||||
|
||||
runApp(new MaterialApp(
|
||||
title: 'Test drawAtlas',
|
||||
theme: _theme,
|
||||
routes: <String, RouteBuilder>{
|
||||
'/': (RouteArguments args) {
|
||||
return new SpriteWidget(
|
||||
new TestDrawAtlas(),
|
||||
SpriteBoxTransformMode.fixedWidth
|
||||
);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
class TestDrawAtlas extends NodeWithSize {
|
||||
TestDrawAtlas() : super(new Size(1024.0, 1024.0));
|
||||
|
||||
void paint(PaintingCanvas canvas) {
|
||||
List<RSTransform> transforms = <RSTransform>[
|
||||
new RSTransform(1.0, 0.0, 100.0, 100.0)
|
||||
];
|
||||
List<Rect> rects = <Rect>[
|
||||
_spriteSheet["ship.png"].frame
|
||||
];
|
||||
List<Color> colors = <Color>[
|
||||
new Color(0xffffffff)
|
||||
];
|
||||
|
||||
canvas.drawAtlas(
|
||||
_spriteSheet.image,
|
||||
transforms,
|
||||
rects,
|
||||
colors,
|
||||
TransferMode.src,
|
||||
null,
|
||||
new Paint()
|
||||
..filterQuality = FilterQuality.low
|
||||
..isAntiAlias = false
|
||||
);
|
||||
}
|
||||
}
|
||||
297
examples/game/test_performance.dart
Normal file
@@ -0,0 +1,297 @@
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||
|
||||
AssetBundle _initBundle() {
|
||||
if (rootBundle != null)
|
||||
return rootBundle;
|
||||
return new NetworkAssetBundle(Uri.base);
|
||||
}
|
||||
|
||||
final AssetBundle _bundle = _initBundle();
|
||||
|
||||
ImageMap _images;
|
||||
SpriteSheet _spriteSheet;
|
||||
|
||||
final ThemeData _theme = new ThemeData(
|
||||
brightness: ThemeBrightness.light,
|
||||
primarySwatch: Colors.purple
|
||||
);
|
||||
|
||||
main() async {
|
||||
_images = new ImageMap(_bundle);
|
||||
|
||||
await _images.load(<String>[
|
||||
'assets/sprites.png'
|
||||
]);
|
||||
|
||||
String json = await _bundle.loadString('assets/sprites.json');
|
||||
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
||||
|
||||
runApp(new MaterialApp(
|
||||
title: 'Test Sprite Performance',
|
||||
theme: _theme,
|
||||
routes: <String, RouteBuilder>{
|
||||
'/': (RouteArguments args) => new SpriteWidget(new TestPerformance())
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
class TestPerformance extends NodeWithSize {
|
||||
|
||||
TestPerformance() : super(new Size(1024.0, 1024.0));
|
||||
|
||||
final int numFramesPerTest = 100;
|
||||
final int numTests = 5;
|
||||
|
||||
int test = 0;
|
||||
int frame = 0;
|
||||
int testStartTime;
|
||||
|
||||
void update(double dt) {
|
||||
if (frame % numFramesPerTest == 0) {
|
||||
if (test > 0 && test <= numTests) {
|
||||
// End last test
|
||||
int currentTime = new DateTime.now().millisecondsSinceEpoch;
|
||||
int totalTestTime = currentTime - testStartTime;
|
||||
double millisPerFrame =
|
||||
totalTestTime.toDouble() / numFramesPerTest.toDouble();
|
||||
print(" - RESULT fps: ${(1.0 / (millisPerFrame / 1000)).toStringAsFixed(1)} millis/frame: ${millisPerFrame.round()}");
|
||||
|
||||
// Clear test
|
||||
removeAllChildren();
|
||||
}
|
||||
|
||||
if (test < numTests) {
|
||||
// Start new test
|
||||
PerformanceTest perfTest = createTest(test);
|
||||
addChild(perfTest);
|
||||
|
||||
print("TEST ${test + 1}/$numTests STARTING: ${perfTest.name}");
|
||||
|
||||
testStartTime = new DateTime.now().millisecondsSinceEpoch;
|
||||
}
|
||||
test++;
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
|
||||
PerformanceTest createTest(int n) {
|
||||
if (test == 0) {
|
||||
// Test atlas performance
|
||||
return new TestPerformanceAtlas();
|
||||
} else if (test == 1) {
|
||||
// Test atlas performance
|
||||
return new TestPerformanceAtlas2();
|
||||
} else if (test == 2) {
|
||||
// Test sprite performance
|
||||
return new TestPerformanceSprites();
|
||||
} else if (test == 3) {
|
||||
// Test sprite performance
|
||||
return new TestPerformanceSprites2();
|
||||
} else if (test == 4) {
|
||||
// Test particle performance
|
||||
return new TestPerformanceParticles();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class PerformanceTest extends Node {
|
||||
String get name;
|
||||
}
|
||||
|
||||
class TestPerformanceParticles extends PerformanceTest {
|
||||
String get name => "64 particle systems";
|
||||
|
||||
final grid = 8;
|
||||
TestPerformanceParticles() {
|
||||
for (int x = 0; x < grid; x++) {
|
||||
for (int y = 0; y < grid; y++) {
|
||||
ParticleSystem particles = new ParticleSystem(
|
||||
_spriteSheet["explosion_particle.png"],
|
||||
rotateToMovement: true,
|
||||
startRotation:90.0,
|
||||
startRotationVar: 0.0,
|
||||
endRotation: 90.0,
|
||||
startSize: 0.3,
|
||||
startSizeVar: 0.1,
|
||||
endSize: 0.3,
|
||||
endSizeVar: 0.1,
|
||||
emissionRate:100.0,
|
||||
greenVar: 127,
|
||||
redVar: 127
|
||||
);
|
||||
particles.position = new Point(x * 1024.0 / (grid - 1), y * 1024.0 / (grid - 1));
|
||||
addChild(particles);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestPerformanceSprites extends PerformanceTest {
|
||||
String get name => "1001 sprites (24% offscreen)";
|
||||
|
||||
final int grid = 100;
|
||||
|
||||
TestPerformanceSprites() {
|
||||
for (int x = 0; x < grid; x++) {
|
||||
for (int y = 0; y < grid; y++) {
|
||||
Sprite sprite = new Sprite(_spriteSheet["asteroid_big_1.png"]);
|
||||
sprite.scale = 1.0;
|
||||
sprite.position = new Point(x * 1024.0 / (grid - 1), y * 1024.0 / (grid - 1));
|
||||
addChild(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
Sprite sprite = new Sprite(_spriteSheet["asteroid_big_1.png"]);
|
||||
sprite.position = new Point(512.0, 512.0);
|
||||
addChild(sprite);
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
for (Node child in children) {
|
||||
final Sprite sprite = child;
|
||||
sprite.rotation += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestPerformanceSprites2 extends PerformanceTest {
|
||||
String get name => "1001 sprites (24% offscreen never added)";
|
||||
|
||||
final int grid = 100;
|
||||
|
||||
TestPerformanceSprites2() {
|
||||
for (int x = 12; x < grid - 12; x++) {
|
||||
for (int y = 0; y < grid; y++) {
|
||||
Sprite sprite = new Sprite(_spriteSheet["asteroid_big_1.png"]);
|
||||
sprite.scale = 1.0;
|
||||
sprite.position = new Point(x * 1024.0 / (grid - 1), y * 1024.0 / (grid - 1));
|
||||
addChild(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
Sprite sprite = new Sprite(_spriteSheet["asteroid_big_1.png"]);
|
||||
sprite.position = new Point(512.0, 512.0);
|
||||
addChild(sprite);
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
for (Node child in children) {
|
||||
final Sprite sprite = child;
|
||||
sprite.rotation += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestPerformanceAtlas extends PerformanceTest {
|
||||
String get name => "1001 rects drawAtlas (24% offscreen)";
|
||||
|
||||
final int grid = 100;
|
||||
|
||||
double rotation = 0.0;
|
||||
List<Rect> rects = <Rect>[];
|
||||
Paint cachedPaint = new Paint()
|
||||
..filterQuality = ui.FilterQuality.low
|
||||
..isAntiAlias = false;
|
||||
|
||||
TestPerformanceAtlas() {
|
||||
for (int x = 0; x < grid; x++) {
|
||||
for (int y = 0; y < grid; y++) {
|
||||
rects.add(_spriteSheet["asteroid_big_1.png"].frame);
|
||||
}
|
||||
}
|
||||
rects.add(_spriteSheet["asteroid_big_1.png"].frame);
|
||||
}
|
||||
|
||||
void paint(PaintingCanvas canvas) {
|
||||
// Setup transforms
|
||||
List<ui.RSTransform> transforms = <ui.RSTransform>[];
|
||||
|
||||
for (int x = 0; x < grid; x++) {
|
||||
for (int y = 0; y < grid; y++) {
|
||||
double xPos = x * 1024.0 / (grid - 1);
|
||||
double yPos = y * 1024.0 / (grid - 1);
|
||||
|
||||
transforms.add(createTransform(xPos, yPos, rects[0].size.width / 2.0, rects[0].size.height / 2.0, rotation, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
transforms.add(createTransform(512.0, 512.0, rects[0].size.width / 2.0, rects[0].size.height / 2.0, rotation, 1.0));
|
||||
|
||||
// Draw atlas
|
||||
Rect cullRect = spriteBox.visibleArea;
|
||||
canvas.drawAtlas(_spriteSheet.image, transforms, rects, null, null, cullRect, cachedPaint);
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
rotation += 1.0;
|
||||
}
|
||||
|
||||
ui.RSTransform createTransform(double x, double y, double ax, double ay, double rot, double scale) {
|
||||
double scos = math.cos(convertDegrees2Radians(rot)) * scale;
|
||||
double ssin = math.sin(convertDegrees2Radians(rot)) * scale;
|
||||
double tx = x + -scos * ax + ssin * ay;
|
||||
double ty = y + -ssin * ax - scos * ay;
|
||||
return new ui.RSTransform(scos, ssin, tx, ty);
|
||||
}
|
||||
}
|
||||
|
||||
class TestPerformanceAtlas2 extends PerformanceTest {
|
||||
String get name => "1001 rects drawAtlas (24% offscreen never added)";
|
||||
|
||||
final int grid = 100;
|
||||
|
||||
double rotation = 0.0;
|
||||
List<Rect> rects = <Rect>[];
|
||||
Paint cachedPaint = new Paint()
|
||||
..filterQuality = ui.FilterQuality.low
|
||||
..isAntiAlias = false;
|
||||
|
||||
TestPerformanceAtlas2() {
|
||||
for (int x = 12; x < grid - 12; x++) {
|
||||
for (int y = 0; y < grid; y++) {
|
||||
rects.add(_spriteSheet["asteroid_big_1.png"].frame);
|
||||
}
|
||||
}
|
||||
rects.add(_spriteSheet["asteroid_big_1.png"].frame);
|
||||
}
|
||||
|
||||
void paint(PaintingCanvas canvas) {
|
||||
// Setup transforms
|
||||
List<ui.RSTransform> transforms = <ui.RSTransform>[];
|
||||
|
||||
for (int x = 12; x < grid - 12; x++) {
|
||||
for (int y = 0; y < grid; y++) {
|
||||
double xPos = x * 1024.0 / (grid - 1);
|
||||
double yPos = y * 1024.0 / (grid - 1);
|
||||
|
||||
transforms.add(createTransform(xPos, yPos, rects[0].size.width / 2.0, rects[0].size.height / 2.0, rotation, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
transforms.add(createTransform(512.0, 512.0, rects[0].size.width / 2.0, rects[0].size.height / 2.0, rotation, 1.0));
|
||||
|
||||
// Draw atlas
|
||||
Rect cullRect = spriteBox.visibleArea;
|
||||
canvas.drawAtlas(_spriteSheet.image, transforms, rects, null, null, cullRect, cachedPaint);
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
rotation += 1.0;
|
||||
}
|
||||
|
||||
ui.RSTransform createTransform(double x, double y, double ax, double ay, double rot, double scale) {
|
||||
double scos = math.cos(convertDegrees2Radians(rot)) * scale;
|
||||
double ssin = math.sin(convertDegrees2Radians(rot)) * scale;
|
||||
double tx = x + -scos * ax + ssin * ay;
|
||||
double ty = y + -ssin * ax - scos * ay;
|
||||
return new ui.RSTransform(scos, ssin, tx, ty);
|
||||
}
|
||||
}
|
||||
308
examples/game/test_performance_computation.dart
Normal file
@@ -0,0 +1,308 @@
|
||||
import 'dart:math' as math;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
main() {
|
||||
runTest();
|
||||
}
|
||||
|
||||
const int numSystems = 1000;
|
||||
const int numFrames = 1000;
|
||||
|
||||
void runTest() {
|
||||
int timeStart;
|
||||
timeStart = new DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
// Create systems
|
||||
List<TestParticleSystem> systems = <TestParticleSystem>[];
|
||||
for (int i = 0; i < numSystems; i++)
|
||||
systems.add(new TestParticleSystem());
|
||||
|
||||
int timeAfterCreate = new DateTime.now().millisecondsSinceEpoch;
|
||||
print("TIME creation ${(timeAfterCreate - timeStart) / 1000.0}");
|
||||
timeStart = new DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
// Update systems
|
||||
for (int frame = 0; frame < numFrames; frame++) {
|
||||
for (int i = 0; i < numSystems; i++) {
|
||||
systems[i].update(1.0 / 60.0);
|
||||
}
|
||||
}
|
||||
|
||||
int timeAfterUpdates = new DateTime.now().millisecondsSinceEpoch;
|
||||
print("TIME updates ${(timeAfterUpdates - timeStart) / 1000.0}");
|
||||
timeStart = new DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
// Calculate matrices
|
||||
for (int frame = 0; frame < numFrames; frame++) {
|
||||
for (int i = 0; i < numSystems; i++) {
|
||||
systems[i].paint();
|
||||
}
|
||||
}
|
||||
|
||||
int timeAfterMatrices = new DateTime.now().millisecondsSinceEpoch;
|
||||
print("TIME matrices ${(timeAfterMatrices - timeStart) / 1000.0}");
|
||||
}
|
||||
|
||||
class TestParticle {
|
||||
Vector2 pos;
|
||||
Vector2 startPos;
|
||||
|
||||
double colorPos;
|
||||
double deltaColorPos;
|
||||
|
||||
double size;
|
||||
double deltaSize;
|
||||
|
||||
double rotation;
|
||||
double deltaRotation;
|
||||
|
||||
double timeToLive;
|
||||
|
||||
Vector2 dir;
|
||||
|
||||
double radialAccel;
|
||||
double tangentialAccel;
|
||||
|
||||
Float64List simpleColorSequence;
|
||||
|
||||
Matrix4 transform;
|
||||
}
|
||||
|
||||
class TestParticleSystem {
|
||||
double life;
|
||||
double lifeVar;
|
||||
|
||||
Vector2 posVar;
|
||||
|
||||
double startSize;
|
||||
double startSizeVar;
|
||||
|
||||
double endSize;
|
||||
double endSizeVar;
|
||||
|
||||
double startRotation;
|
||||
double startRotationVar;
|
||||
|
||||
double endRotation;
|
||||
double endRotationVar;
|
||||
|
||||
double direction;
|
||||
double directionVar;
|
||||
|
||||
double speed;
|
||||
double speedVar;
|
||||
|
||||
double radialAcceleration;
|
||||
double radialAccelerationVar;
|
||||
|
||||
double tangentialAcceleration;
|
||||
double tangentialAccelerationVar;
|
||||
|
||||
Vector2 gravity;
|
||||
|
||||
int maxParticles;
|
||||
int numParticlesToEmit;
|
||||
double emissionRate;
|
||||
|
||||
List<TestParticle> _particles;
|
||||
|
||||
double _emitCounter;
|
||||
int _numEmittedParticles = 0;
|
||||
|
||||
TestParticleSystem({this.life: 1.5,
|
||||
this.lifeVar: 0.0,
|
||||
this.startSize: 2.5,
|
||||
this.startSizeVar: 0.5,
|
||||
this.endSize: 0.0,
|
||||
this.endSizeVar: 0.0,
|
||||
this.startRotation: 0.0,
|
||||
this.startRotationVar: 0.0,
|
||||
this.endRotation: 0.0,
|
||||
this.endRotationVar: 0.0,
|
||||
this.direction: 0.0,
|
||||
this.directionVar: 360.0,
|
||||
this.speed: 100.0,
|
||||
this.speedVar: 50.0,
|
||||
this.radialAcceleration: 0.0,
|
||||
this.radialAccelerationVar: 0.0,
|
||||
this.tangentialAcceleration: 0.0,
|
||||
this.tangentialAccelerationVar: 0.0,
|
||||
this.gravity,
|
||||
this.maxParticles: 100,
|
||||
this.emissionRate: 50.0,
|
||||
this.numParticlesToEmit: 0}) {
|
||||
posVar = new Vector2.zero();
|
||||
_particles = new List<TestParticle>();
|
||||
_emitCounter = 0.0;
|
||||
gravity = new Vector2.zero();
|
||||
}
|
||||
|
||||
void update(double dt) {
|
||||
// Create new particles
|
||||
double rate = 1.0 / emissionRate;
|
||||
|
||||
if (_particles.length < maxParticles) {
|
||||
_emitCounter += dt;
|
||||
}
|
||||
|
||||
while(_particles.length < maxParticles
|
||||
&& _emitCounter > rate
|
||||
&& (numParticlesToEmit == 0 || _numEmittedParticles < numParticlesToEmit)) {
|
||||
// Add a new particle
|
||||
_addParticle();
|
||||
_emitCounter -= rate;
|
||||
}
|
||||
|
||||
// Iterate over all particles
|
||||
for (int i = _particles.length -1; i >= 0; i--) {
|
||||
TestParticle particle = _particles[i];
|
||||
|
||||
// Manage life time
|
||||
particle.timeToLive -= dt;
|
||||
if (particle.timeToLive <= 0) {
|
||||
_particles.removeAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Update the particle
|
||||
|
||||
// Radial acceleration
|
||||
Vector2 radial;
|
||||
if (particle.pos[0] != 0 || particle.pos[1] != 0) {
|
||||
radial = new Vector2.copy(particle.pos).normalize();
|
||||
} else {
|
||||
radial = new Vector2.zero();
|
||||
}
|
||||
Vector2 tangential = new Vector2.copy(radial);
|
||||
radial.scale(particle.radialAccel);
|
||||
|
||||
// Tangential acceleration
|
||||
double newY = tangential.x;
|
||||
tangential.x = -tangential.y;
|
||||
tangential.y = newY;
|
||||
tangential.scale(particle.tangentialAccel);
|
||||
|
||||
// (gravity + radial + tangential) * dt
|
||||
Vector2 accel = (gravity + radial + tangential).scale(dt);
|
||||
particle.dir += accel;
|
||||
|
||||
// Update particle position
|
||||
particle.pos[0] += particle.dir[0] * dt;
|
||||
particle.pos[1] += particle.dir[1] * dt;
|
||||
|
||||
// Size
|
||||
particle.size = math.max(particle.size + particle.deltaSize * dt, 0.0);
|
||||
|
||||
// Angle
|
||||
particle.rotation += particle.deltaRotation * dt;
|
||||
|
||||
// Color
|
||||
if (particle.simpleColorSequence != null) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
particle.simpleColorSequence[i] += particle.simpleColorSequence[i + 4] * dt;
|
||||
}
|
||||
} else {
|
||||
particle.colorPos = math.min(particle.colorPos + particle.deltaColorPos * dt, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _addParticle() {
|
||||
|
||||
TestParticle particle = new TestParticle();
|
||||
|
||||
// Time to live
|
||||
particle.timeToLive = math.max(life + lifeVar * randomSignedDouble(), 0.0);
|
||||
|
||||
// Position
|
||||
Vector2 srcPos = new Vector2.zero();
|
||||
particle.pos = new Vector2(srcPos.x + posVar.x * randomSignedDouble(),
|
||||
srcPos.y + posVar.y * randomSignedDouble());
|
||||
|
||||
// Size
|
||||
particle.size = math.max(startSize + startSizeVar * randomSignedDouble(), 0.0);
|
||||
double endSizeFinal = math.max(endSize + endSizeVar * randomSignedDouble(), 0.0);
|
||||
particle.deltaSize = (endSizeFinal - particle.size) / particle.timeToLive;
|
||||
|
||||
// Rotation
|
||||
particle.rotation = startRotation + startRotationVar * randomSignedDouble();
|
||||
double endRotationFinal = endRotation + endRotationVar * randomSignedDouble();
|
||||
particle.deltaRotation = (endRotationFinal - particle.rotation) / particle.timeToLive;
|
||||
|
||||
// Direction
|
||||
double dirRadians = radians(direction + directionVar * randomSignedDouble());
|
||||
Vector2 dirVector = new Vector2(math.cos(dirRadians), math.sin(dirRadians));
|
||||
double speedFinal = speed + speedVar * randomSignedDouble();
|
||||
particle.dir = dirVector.scale(speedFinal);
|
||||
|
||||
// Radial acceleration
|
||||
particle.radialAccel = radialAcceleration + radialAccelerationVar * randomSignedDouble();
|
||||
|
||||
// Tangential acceleration
|
||||
particle.tangentialAccel = tangentialAcceleration + tangentialAccelerationVar * randomSignedDouble();
|
||||
|
||||
// Colors
|
||||
particle.simpleColorSequence = new Float64List(8);
|
||||
particle.simpleColorSequence[0] = 255.0;
|
||||
particle.simpleColorSequence[1] = 255.0;
|
||||
particle.simpleColorSequence[2] = 255.0;
|
||||
particle.simpleColorSequence[3] = 255.0;
|
||||
|
||||
particle.simpleColorSequence[4] = 255.0;
|
||||
particle.simpleColorSequence[5] = 0.0;
|
||||
particle.simpleColorSequence[6] = 0.0;
|
||||
particle.simpleColorSequence[7] = 0.0;
|
||||
|
||||
// Transform
|
||||
particle.transform = new Matrix4.identity();
|
||||
|
||||
// Add particle
|
||||
_particles.add(particle);
|
||||
_numEmittedParticles++;
|
||||
}
|
||||
|
||||
|
||||
void paint() {
|
||||
|
||||
if (!printed) {
|
||||
printed = true;
|
||||
}
|
||||
|
||||
for (int i = _particles.length -1; i >= 0; i--) {
|
||||
TestParticle particle = _particles[i];
|
||||
particle.rotation + randomSignedDouble();
|
||||
|
||||
// Transform
|
||||
double c = math.cos(radians(particle.rotation));
|
||||
double s = math.sin(radians(particle.rotation));
|
||||
|
||||
// Create transformation matrix for scale, position and rotation
|
||||
Matrix4 matrix = new Matrix4(c * particle.size, s * particle.size, 0.0, 0.0,
|
||||
-s * particle.size, c * particle.size, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
particle.pos.x, particle.pos.y, 0.0, 1.0);
|
||||
|
||||
particle.transform.multiply(matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
math.Random _random = new math.Random();
|
||||
|
||||
bool printed = false;
|
||||
|
||||
// Random methods
|
||||
|
||||
double randomDouble() {
|
||||
return _random.nextDouble();
|
||||
}
|
||||
|
||||
double randomSignedDouble() {
|
||||
return _random.nextDouble() * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
int randomInt(int max) {
|
||||
return _random.nextInt(max);
|
||||
}
|
||||
125
examples/game/test_physics.dart
Normal file
@@ -0,0 +1,125 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||
|
||||
AssetBundle _initBundle() {
|
||||
if (rootBundle != null)
|
||||
return rootBundle;
|
||||
return new NetworkAssetBundle(Uri.base);
|
||||
}
|
||||
|
||||
final AssetBundle _bundle = _initBundle();
|
||||
|
||||
ImageMap _images;
|
||||
SpriteSheet _spriteSheet;
|
||||
|
||||
main() async {
|
||||
_images = new ImageMap(_bundle);
|
||||
|
||||
await _images.load(<String>[
|
||||
'assets/sprites.png'
|
||||
]);
|
||||
|
||||
String json = await _bundle.loadString('assets/sprites.json');
|
||||
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
||||
|
||||
runApp(new MaterialApp(
|
||||
title: 'Test Physics',
|
||||
theme: new ThemeData(
|
||||
brightness: ThemeBrightness.light,
|
||||
primarySwatch: Colors.purple
|
||||
),
|
||||
routes: <String, RouteBuilder>{
|
||||
'/': (RouteArguments args) {
|
||||
return new SpriteWidget(
|
||||
new TestBed(),
|
||||
SpriteBoxTransformMode.letterbox
|
||||
);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
class TestBed extends NodeWithSize {
|
||||
Sprite _obstacle;
|
||||
PhysicsWorld _world;
|
||||
PhysicsGroup _group;
|
||||
PhysicsGroup _group2;
|
||||
|
||||
TestBed() : super(new Size(1024.0, 1024.0)) {
|
||||
_world = new PhysicsWorld(new Offset(0.0, 100.0));
|
||||
_world.drawDebug = true;
|
||||
_group = new PhysicsGroup();
|
||||
_group2 = new PhysicsGroup();
|
||||
_group2.position = new Point(50.0, 50.0);
|
||||
_world.addChild(_group);
|
||||
_world.addChild(_group2);
|
||||
|
||||
_obstacle = new Sprite(_spriteSheet["ship.png"]);
|
||||
_obstacle.position = new Point(512.0, 800.0);
|
||||
_obstacle.size = new Size(64.0, 64.0);
|
||||
_obstacle.scale = 2.0;
|
||||
_obstacle.physicsBody = new PhysicsBody(
|
||||
new PhysicsShapeCircle(Point.origin, 32.0),
|
||||
type: PhysicsBodyType.static,
|
||||
friction: 0.5,
|
||||
tag: "obstacle"
|
||||
);
|
||||
_group.addChild(_obstacle);
|
||||
_world.addContactCallback(myCallback, "obstacle", "ship", PhysicsContactType.begin);
|
||||
|
||||
// Animate group
|
||||
ActionSequence seq = new ActionSequence(<Action>[
|
||||
new ActionTween((Point a) { _group.position = a; }, new Point(-256.0, 0.0), new Point(256.0, 0.0), 1.0, Curves.easeInOut),
|
||||
new ActionTween((Point a) { _group.position = a; }, new Point(256.0, 0.0), new Point(-256.0, 0.0), 1.0, Curves.easeInOut)
|
||||
]);
|
||||
_group.actions.run(new ActionRepeatForever(seq));
|
||||
|
||||
addChild(_world);
|
||||
|
||||
userInteractionEnabled = true;
|
||||
}
|
||||
|
||||
void myCallback(PhysicsContactType type, PhysicsContact contact) {
|
||||
}
|
||||
|
||||
bool handleEvent(SpriteBoxEvent event) {
|
||||
if (event.type == "pointerdown") {
|
||||
Point pos = convertPointToNodeSpace(event.boxPosition);
|
||||
|
||||
PhysicsGroup group = new PhysicsGroup();
|
||||
group.position = pos;
|
||||
_world.addChild(group);
|
||||
|
||||
Sprite shipA;
|
||||
shipA = new Sprite(_spriteSheet["ship.png"]);
|
||||
shipA.opacity = 0.3;
|
||||
shipA.position = new Point(-40.0, 0.0);
|
||||
shipA.size = new Size(64.0, 64.0);
|
||||
shipA.physicsBody = new PhysicsBody(new PhysicsShapeCircle(Point.origin, 32.0),
|
||||
friction: 0.5,
|
||||
restitution: 0.5,
|
||||
tag: "ship"
|
||||
);
|
||||
group.addChild(shipA);
|
||||
|
||||
Sprite shipB;
|
||||
shipB = new Sprite(_spriteSheet["ship.png"]);
|
||||
shipB.opacity = 0.3;
|
||||
shipB.position = new Point(40.0, 0.0);
|
||||
shipB.size = new Size(64.0, 64.0);
|
||||
shipB.physicsBody = new PhysicsBody(new PhysicsShapePolygon(<Point>[new Point(-25.0, -25.0), new Point(25.0, -25.0), new Point(25.0, 25.0), new Point(-25.0, 25.0)]),
|
||||
friction: 0.5,
|
||||
restitution: 0.5,
|
||||
tag: "ship"
|
||||
);
|
||||
group.addChild(shipB);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
7
examples/hello_world/lib/main.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
void main() => runApp(new Center(child: new Text('Hello, world!')));
|
||||
10
examples/hello_world/pubspec.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
name: hello_world
|
||||
dependencies:
|
||||
flutter:
|
||||
'0.0.16'
|
||||
sky_tools: any
|
||||
dependency_overrides:
|
||||
material_design_icons:
|
||||
path: ../../sky/packages/material_design_icons
|
||||
flutter:
|
||||
path: ../../sky/packages/sky
|
||||
13
examples/mine_digger/BUILD.gn
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//sky/build/sky_app.gni")
|
||||
|
||||
sky_app("mine_digger") {
|
||||
main_dart = "lib/main.dart"
|
||||
|
||||
if (is_android) {
|
||||
apk_name = "MineDigger"
|
||||
}
|
||||
}
|
||||
24
examples/mine_digger/apk/AndroidManifest.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
Use of this source code is governed by a BSD-style license that can be
|
||||
found in the LICENSE file.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.domokit.mine_digger">
|
||||
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application android:name="org.domokit.sky.shell.SkyApplication" android:label="Mine Digger">
|
||||
<activity android:name="org.domokit.sky.shell.SkyActivity"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
|
||||
android:hardwareAccelerated="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
337
examples/mine_digger/lib/main.dart
Normal file
@@ -0,0 +1,337 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
// Classic minesweeper-inspired game. The mouse controls are standard
|
||||
// except for left + right combo which is not implemented. For touch,
|
||||
// the duration of the pointer determines probing versus flagging.
|
||||
//
|
||||
// There are only 3 classes to understand. MineDiggerApp, which is
|
||||
// contains all the logic and two classes that describe the mines:
|
||||
// CoveredMineNode and ExposedMineNode, none of them holding state.
|
||||
|
||||
// Colors for each mine count (0-8):
|
||||
const List<Color> textColors = const <Color>[
|
||||
const Color(0xFF555555),
|
||||
const Color(0xFF0094FF), // blue
|
||||
const Color(0xFF13A023), // green
|
||||
const Color(0xFFDA1414), // red
|
||||
const Color(0xFF1E2347), // black
|
||||
const Color(0xFF7F0037), // dark red
|
||||
const Color(0xFF000000),
|
||||
const Color(0xFF000000),
|
||||
const Color(0xFF000000),
|
||||
];
|
||||
|
||||
final List<TextStyle> textStyles = textColors.map((Color color) {
|
||||
return new TextStyle(color: color, fontWeight: bold, textAlign: TextAlign.center);
|
||||
}).toList();
|
||||
|
||||
enum CellState { covered, exploded, cleared, flagged, shown }
|
||||
|
||||
class MineDigger extends StatefulComponent {
|
||||
MineDiggerState createState() => new MineDiggerState();
|
||||
}
|
||||
|
||||
class MineDiggerState extends State<MineDigger> {
|
||||
static const int rows = 9;
|
||||
static const int cols = 9;
|
||||
static const int totalMineCount = 11;
|
||||
|
||||
bool alive;
|
||||
bool hasWon;
|
||||
int detectedCount;
|
||||
|
||||
// |cells| keeps track of the positions of the mines.
|
||||
List<List<bool>> cells;
|
||||
// |uiState| keeps track of the visible player progess.
|
||||
List<List<CellState>> uiState;
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
resetGame();
|
||||
}
|
||||
|
||||
void resetGame() {
|
||||
alive = true;
|
||||
hasWon = false;
|
||||
detectedCount = 0;
|
||||
// Initialize matrices.
|
||||
cells = new List<List<bool>>.generate(rows, (int row) {
|
||||
return new List<bool>.filled(cols, false);
|
||||
});
|
||||
uiState = new List<List<CellState>>.generate(rows, (int row) {
|
||||
return new List<CellState>.filled(cols, CellState.covered);
|
||||
});
|
||||
// Place the mines.
|
||||
Random random = new Random();
|
||||
int minesRemaining = totalMineCount;
|
||||
while (minesRemaining > 0) {
|
||||
int pos = random.nextInt(rows * cols);
|
||||
int row = pos ~/ rows;
|
||||
int col = pos % cols;
|
||||
if (!cells[row][col]) {
|
||||
cells[row][col] = true;
|
||||
minesRemaining--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PointerEventListener _pointerDownHandlerFor(int posX, int posY) {
|
||||
return (PointerInputEvent event) {
|
||||
if (event.buttons == 1) {
|
||||
probe(posX, posY);
|
||||
} else if (event.buttons == 2) {
|
||||
flag(posX, posY);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Widget buildBoard() {
|
||||
bool hasCoveredCell = false;
|
||||
List<Row> flexRows = <Row>[];
|
||||
for (int iy = 0; iy < rows; iy++) {
|
||||
List<Widget> row = <Widget>[];
|
||||
for (int ix = 0; ix < cols; ix++) {
|
||||
CellState state = uiState[iy][ix];
|
||||
int count = mineCount(ix, iy);
|
||||
if (!alive) {
|
||||
if (state != CellState.exploded)
|
||||
state = cells[iy][ix] ? CellState.shown : state;
|
||||
}
|
||||
if (state == CellState.covered || state == CellState.flagged) {
|
||||
row.add(new GestureDetector(
|
||||
onTap: () {
|
||||
if (state == CellState.covered)
|
||||
probe(ix, iy);
|
||||
},
|
||||
onLongPress: () {
|
||||
userFeedback.performHapticFeedback(HapticFeedbackType.LONG_PRESS);
|
||||
flag(ix, iy);
|
||||
},
|
||||
child: new Listener(
|
||||
onPointerDown: _pointerDownHandlerFor(ix, iy),
|
||||
child: new CoveredMineNode(
|
||||
flagged: state == CellState.flagged,
|
||||
posX: ix,
|
||||
posY: iy
|
||||
)
|
||||
)
|
||||
));
|
||||
if (state == CellState.covered) {
|
||||
// Mutating |hasCoveredCell| here is hacky, but convenient, same
|
||||
// goes for mutating |hasWon| below.
|
||||
hasCoveredCell = true;
|
||||
}
|
||||
} else {
|
||||
row.add(new ExposedMineNode(
|
||||
state: state,
|
||||
count: count
|
||||
));
|
||||
}
|
||||
}
|
||||
flexRows.add(
|
||||
new Row(
|
||||
row,
|
||||
justifyContent: FlexJustifyContent.center,
|
||||
key: new ValueKey<int>(iy)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!hasCoveredCell) {
|
||||
// all cells uncovered. Are all mines flagged?
|
||||
if ((detectedCount == totalMineCount) && alive) {
|
||||
hasWon = true;
|
||||
}
|
||||
}
|
||||
|
||||
return new Container(
|
||||
padding: new EdgeDims.all(10.0),
|
||||
margin: new EdgeDims.all(10.0),
|
||||
decoration: new BoxDecoration(backgroundColor: const Color(0xFF6B6B6B)),
|
||||
child: new Column(flexRows)
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildToolBar(BuildContext context) {
|
||||
String toolbarCaption = hasWon ?
|
||||
'Awesome!!' : alive ?
|
||||
'Mine Digger [$detectedCount-$totalMineCount]': 'Kaboom! [press here]';
|
||||
|
||||
return new ToolBar(
|
||||
// FIXME: Strange to have the toolbar be tapable.
|
||||
center: new Listener(
|
||||
onPointerDown: handleToolbarPointerDown,
|
||||
child: new Text(toolbarCaption, style: Theme.of(context).text.title)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
// We build the board before we build the toolbar because we compute the win state during build step.
|
||||
Widget board = buildBoard();
|
||||
return new Title(
|
||||
title: 'Mine Digger',
|
||||
child: new Scaffold(
|
||||
toolBar: buildToolBar(context),
|
||||
body: new Container(
|
||||
child: new Center(child: board),
|
||||
decoration: new BoxDecoration(backgroundColor: Colors.grey[50])
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void handleToolbarPointerDown(PointerInputEvent event) {
|
||||
setState(() {
|
||||
resetGame();
|
||||
});
|
||||
}
|
||||
|
||||
// User action. The user uncovers the cell which can cause losing the game.
|
||||
void probe(int x, int y) {
|
||||
if (!alive)
|
||||
return;
|
||||
if (uiState[y][x] == CellState.flagged)
|
||||
return;
|
||||
setState(() {
|
||||
// Allowed to probe.
|
||||
if (cells[y][x]) {
|
||||
// Probed on a mine --> dead!!
|
||||
uiState[y][x] = CellState.exploded;
|
||||
alive = false;
|
||||
} else {
|
||||
// No mine, uncover nearby if possible.
|
||||
cull(x, y);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// User action. The user is sure a mine is at this location.
|
||||
void flag(int x, int y) {
|
||||
setState(() {
|
||||
if (uiState[y][x] == CellState.flagged) {
|
||||
uiState[y][x] = CellState.covered;
|
||||
--detectedCount;
|
||||
} else {
|
||||
uiState[y][x] = CellState.flagged;
|
||||
++detectedCount;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Recursively uncovers cells whose totalMineCount is zero.
|
||||
void cull(int x, int y) {
|
||||
if (!inBoard(x, y))
|
||||
return;
|
||||
if (uiState[y][x] == CellState.cleared)
|
||||
return;
|
||||
uiState[y][x] = CellState.cleared;
|
||||
|
||||
if (mineCount(x, y) > 0)
|
||||
return;
|
||||
|
||||
cull(x - 1, y);
|
||||
cull(x + 1, y);
|
||||
cull(x, y - 1);
|
||||
cull(x, y + 1 );
|
||||
cull(x - 1, y - 1);
|
||||
cull(x + 1, y + 1);
|
||||
cull(x + 1, y - 1);
|
||||
cull(x - 1, y + 1);
|
||||
}
|
||||
|
||||
int mineCount(int x, int y) {
|
||||
int count = 0;
|
||||
count += bombs(x - 1, y);
|
||||
count += bombs(x + 1, y);
|
||||
count += bombs(x, y - 1);
|
||||
count += bombs(x, y + 1 );
|
||||
count += bombs(x - 1, y - 1);
|
||||
count += bombs(x + 1, y + 1);
|
||||
count += bombs(x + 1, y - 1);
|
||||
count += bombs(x - 1, y + 1);
|
||||
return count;
|
||||
}
|
||||
|
||||
int bombs(int x, int y) => inBoard(x, y) && cells[y][x] ? 1 : 0;
|
||||
|
||||
bool inBoard(int x, int y) => x >= 0 && x < cols && y >= 0 && y < rows;
|
||||
}
|
||||
|
||||
Widget buildCell(Widget child) {
|
||||
return new Container(
|
||||
padding: new EdgeDims.all(1.0),
|
||||
height: 27.0, width: 27.0,
|
||||
decoration: new BoxDecoration(backgroundColor: const Color(0xFFC0C0C0)),
|
||||
margin: new EdgeDims.all(2.0),
|
||||
child: child
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildInnerCell(Widget child) {
|
||||
return new Container(
|
||||
padding: new EdgeDims.all(1.0),
|
||||
margin: new EdgeDims.all(3.0),
|
||||
height: 17.0, width: 17.0,
|
||||
child: child
|
||||
);
|
||||
}
|
||||
|
||||
class CoveredMineNode extends StatelessComponent {
|
||||
|
||||
CoveredMineNode({ this.flagged, this.posX, this.posY });
|
||||
|
||||
final bool flagged;
|
||||
final int posX;
|
||||
final int posY;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
Widget text;
|
||||
if (flagged)
|
||||
text = buildInnerCell(new StyledText(elements : [textStyles[5], '\u2691']));
|
||||
|
||||
Container inner = new Container(
|
||||
margin: new EdgeDims.all(2.0),
|
||||
height: 17.0, width: 17.0,
|
||||
decoration: new BoxDecoration(backgroundColor: const Color(0xFFD9D9D9)),
|
||||
child: text
|
||||
);
|
||||
|
||||
return buildCell(inner);
|
||||
}
|
||||
}
|
||||
|
||||
class ExposedMineNode extends StatelessComponent {
|
||||
|
||||
ExposedMineNode({ this.state, this.count });
|
||||
|
||||
final CellState state;
|
||||
final int count;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
StyledText text;
|
||||
if (state == CellState.cleared) {
|
||||
// Uncovered cell with nearby mine count.
|
||||
if (count != 0)
|
||||
text = new StyledText(elements : [textStyles[count], '$count']);
|
||||
} else {
|
||||
// Exploded mine or shown mine for 'game over'.
|
||||
int color = state == CellState.exploded ? 3 : 0;
|
||||
text = new StyledText(elements : [textStyles[color], '\u2600']);
|
||||
}
|
||||
return buildCell(buildInnerCell(text));
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(new MineDigger());
|
||||
}
|
||||
10
examples/mine_digger/pubspec.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
name: mine_digger
|
||||
dependencies:
|
||||
flutter:
|
||||
'0.0.16'
|
||||
sky_tools: any
|
||||
dependency_overrides:
|
||||
material_design_icons:
|
||||
path: ../../sky/packages/material_design_icons
|
||||
flutter:
|
||||
path: ../../sky/packages/sky
|
||||
72
examples/raw/hello_world.dart
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:typed_data';
|
||||
|
||||
ui.Color color;
|
||||
|
||||
ui.Picture paint(ui.Rect paintBounds) {
|
||||
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
ui.Size size = paintBounds.size;
|
||||
|
||||
double radius = size.shortestSide * 0.45;
|
||||
ui.Paint paint = new ui.Paint()
|
||||
..color = color;
|
||||
canvas.drawCircle(size.center(ui.Point.origin), radius, paint);
|
||||
|
||||
return recorder.endRecording();
|
||||
}
|
||||
|
||||
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
|
||||
Float64List deviceTransform = new Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||
..pop();
|
||||
return sceneBuilder.build();
|
||||
}
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
|
||||
ui.Picture picture = paint(paintBounds);
|
||||
ui.Scene scene = composite(picture, paintBounds);
|
||||
ui.window.render(scene);
|
||||
}
|
||||
|
||||
bool handleEvent(ui.Event event) {
|
||||
if (event.type == 'pointerdown') {
|
||||
color = new ui.Color.fromARGB(255, 0, 0, 255);
|
||||
ui.window.scheduleFrame();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.type == 'pointerup') {
|
||||
color = new ui.Color.fromARGB(255, 0, 255, 0);
|
||||
ui.window.scheduleFrame();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.type == 'back') {
|
||||
print('Pressed back button.');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
print('Hello, world');
|
||||
color = new ui.Color.fromARGB(255, 0, 255, 0);
|
||||
ui.window.onBeginFrame = beginFrame;
|
||||
ui.window.onEvent = handleEvent;
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
121
examples/raw/painting.dart
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:typed_data';
|
||||
|
||||
ui.Picture paint(ui.Rect paintBounds) {
|
||||
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
ui.Size size = paintBounds.size;
|
||||
|
||||
ui.Paint paint = new ui.Paint();
|
||||
ui.Point mid = size.center(ui.Point.origin);
|
||||
double radius = size.shortestSide / 2.0;
|
||||
canvas.drawPaint(new ui.Paint()..color = const ui.Color(0xFFFFFFFF));
|
||||
|
||||
canvas.save();
|
||||
canvas.translate(-mid.x/2.0, ui.window.size.height*2.0);
|
||||
canvas.clipRect(
|
||||
new ui.Rect.fromLTRB(0.0, -ui.window.size.height, ui.window.size.width, radius));
|
||||
|
||||
canvas.translate(mid.x, mid.y);
|
||||
paint.color = const ui.Color.fromARGB(128, 255, 0, 255);
|
||||
canvas.rotate(math.PI/4.0);
|
||||
|
||||
ui.Gradient yellowBlue = new ui.Gradient.linear(
|
||||
<ui.Point>[new ui.Point(-radius, -radius), new ui.Point(0.0, 0.0)],
|
||||
<ui.Color>[const ui.Color(0xFFFFFF00), const ui.Color(0xFF0000FF)]
|
||||
);
|
||||
canvas.drawRect(new ui.Rect.fromLTRB(-radius, -radius, radius, radius),
|
||||
new ui.Paint()..shader = yellowBlue);
|
||||
|
||||
// Scale x and y by 0.5.
|
||||
Float64List scaleMatrix = new Float64List.fromList(<double>[
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0,
|
||||
]);
|
||||
canvas.concat(scaleMatrix);
|
||||
paint.color = const ui.Color.fromARGB(128, 0, 255, 0);
|
||||
canvas.drawCircle(ui.Point.origin, radius, paint);
|
||||
|
||||
canvas.restore();
|
||||
|
||||
canvas.translate(0.0, 50.0);
|
||||
ui.LayerDrawLooperBuilder builder = new ui.LayerDrawLooperBuilder()
|
||||
..addLayerOnTop(
|
||||
new ui.DrawLooperLayerInfo()
|
||||
..setOffset(const ui.Offset(150.0, 0.0))
|
||||
..setColorMode(ui.TransferMode.src)
|
||||
..setPaintBits(ui.PaintBits.all),
|
||||
new ui.Paint()
|
||||
..color = const ui.Color.fromARGB(128, 255, 255, 0)
|
||||
..colorFilter = new ui.ColorFilter.mode(
|
||||
const ui.Color.fromARGB(128, 0, 0, 255),
|
||||
ui.TransferMode.srcIn
|
||||
)
|
||||
..maskFilter = new ui.MaskFilter.blur(
|
||||
ui.BlurStyle.normal, 3.0, highQuality: true
|
||||
)
|
||||
)
|
||||
..addLayerOnTop(
|
||||
new ui.DrawLooperLayerInfo()
|
||||
..setOffset(const ui.Offset(75.0, 75.0))
|
||||
..setColorMode(ui.TransferMode.src)
|
||||
..setPaintBits(ui.PaintBits.shader),
|
||||
new ui.Paint()
|
||||
..shader = new ui.Gradient.radial(
|
||||
new ui.Point(0.0, 0.0), radius/3.0,
|
||||
<ui.Color>[
|
||||
const ui.Color(0xFFFFFF00),
|
||||
const ui.Color(0xFFFF0000)
|
||||
],
|
||||
null,
|
||||
ui.TileMode.mirror
|
||||
)
|
||||
// Since we're don't set ui.PaintBits.maskFilter, this has no effect.
|
||||
..maskFilter = new ui.MaskFilter.blur(
|
||||
ui.BlurStyle.normal, 50.0, highQuality: true
|
||||
)
|
||||
)
|
||||
..addLayerOnTop(
|
||||
new ui.DrawLooperLayerInfo()..setOffset(const ui.Offset(225.0, 75.0)),
|
||||
// Since this layer uses a DST color mode, this has no effect.
|
||||
new ui.Paint()..color = const ui.Color.fromARGB(128, 255, 0, 0)
|
||||
);
|
||||
paint.drawLooper = builder.build();
|
||||
canvas.drawCircle(ui.Point.origin, radius, paint);
|
||||
|
||||
return recorder.endRecording();
|
||||
}
|
||||
|
||||
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
|
||||
Float64List deviceTransform = new Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||
..pop();
|
||||
return sceneBuilder.build();
|
||||
}
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
|
||||
ui.Picture picture = paint(paintBounds);
|
||||
ui.Scene scene = composite(picture, paintBounds);
|
||||
ui.window.render(scene);
|
||||
}
|
||||
|
||||
void main() {
|
||||
ui.window.onBeginFrame = beginFrame;
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
10
examples/raw/pubspec.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
name: sky_raw_examples
|
||||
dependencies:
|
||||
flutter:
|
||||
'0.0.16'
|
||||
sky_tools: any
|
||||
dependency_overrides:
|
||||
material_design_icons:
|
||||
path: ../../sky/packages/material_design_icons
|
||||
flutter:
|
||||
path: ../../sky/packages/sky
|
||||
64
examples/raw/shadow.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:typed_data';
|
||||
|
||||
ui.Picture paint(ui.Rect paintBounds) {
|
||||
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
|
||||
double size = 100.0;
|
||||
canvas.translate(size + 10.0, size + 10.0);
|
||||
|
||||
ui.Paint paint = new ui.Paint();
|
||||
paint.color = const ui.Color.fromARGB(255, 0, 255, 0);
|
||||
var builder = new ui.LayerDrawLooperBuilder()
|
||||
// Shadow layer.
|
||||
..addLayerOnTop(
|
||||
new ui.DrawLooperLayerInfo()
|
||||
..setPaintBits(ui.PaintBits.all)
|
||||
..setOffset(const ui.Offset(5.0, 5.0))
|
||||
..setColorMode(ui.TransferMode.src),
|
||||
new ui.Paint()
|
||||
..color = const ui.Color.fromARGB(128, 55, 55, 55)
|
||||
..maskFilter = new ui.MaskFilter.blur(ui.BlurStyle.normal, 5.0)
|
||||
)
|
||||
// Main layer.
|
||||
..addLayerOnTop(new ui.DrawLooperLayerInfo(), new ui.Paint());
|
||||
paint.drawLooper = builder.build();
|
||||
|
||||
canvas.drawPaint(
|
||||
new ui.Paint()..color = const ui.Color.fromARGB(255, 255, 255, 255));
|
||||
canvas.drawRect(new ui.Rect.fromLTRB(-size, -size, size, size), paint);
|
||||
|
||||
return recorder.endRecording();
|
||||
}
|
||||
|
||||
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
|
||||
Float64List deviceTransform = new Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||
..pop();
|
||||
return sceneBuilder.build();
|
||||
}
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
|
||||
ui.Picture picture = paint(paintBounds);
|
||||
ui.Scene scene = composite(picture, paintBounds);
|
||||
ui.window.render(scene);
|
||||
}
|
||||
|
||||
void main() {
|
||||
ui.window.onBeginFrame = beginFrame;
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
68
examples/raw/spinning_arabic.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:typed_data';
|
||||
|
||||
Duration timeBase = null;
|
||||
ui.Paragraph paragraph;
|
||||
|
||||
ui.Picture paint(ui.Rect paintBounds, double delta) {
|
||||
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
|
||||
canvas.translate(ui.window.size.width / 2.0, ui.window.size.height / 2.0);
|
||||
canvas.rotate(math.PI * delta / 1800);
|
||||
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
|
||||
|
||||
double sin = math.sin(delta / 200);
|
||||
paragraph.maxWidth = 150.0 + (50 * sin);
|
||||
paragraph.layout();
|
||||
|
||||
canvas.translate(paragraph.maxWidth / -2.0, (paragraph.maxWidth / 2.0) - 125);
|
||||
paragraph.paint(canvas, ui.Offset.zero);
|
||||
|
||||
return recorder.endRecording();
|
||||
}
|
||||
|
||||
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
|
||||
Float64List deviceTransform = new Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||
..pop();
|
||||
return sceneBuilder.build();
|
||||
}
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
if (timeBase == null)
|
||||
timeBase = timeStamp;
|
||||
double delta = (timeStamp - timeBase).inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND;
|
||||
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
|
||||
ui.Picture picture = paint(paintBounds, delta);
|
||||
ui.Scene scene = composite(picture, paintBounds);
|
||||
ui.window.render(scene);
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
|
||||
void main() {
|
||||
// TODO(abarth): We're missing some bidi style information:
|
||||
// block.style['direction'] = 'rtl';
|
||||
// block.style['unicode-bidi'] = 'plaintext';
|
||||
ui.ParagraphBuilder builder = new ui.ParagraphBuilder();
|
||||
builder.addText("هذا هو قليلا طويلة من النص الذي يجب التفاف .");
|
||||
builder.addText(" و أكثر قليلا لجعله أطول. ");
|
||||
paragraph = builder.build(new ui.ParagraphStyle());
|
||||
|
||||
ui.window.onBeginFrame = beginFrame;
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
98
examples/raw/spinning_image.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
Duration timeBase = null;
|
||||
|
||||
ui.Image image = null;
|
||||
String url1 = "https://raw.githubusercontent.com/dart-lang/logos/master/logos_and_wordmarks/dart-logo.png";
|
||||
String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg";
|
||||
|
||||
ui.Picture paint(ui.Rect paintBounds, double delta) {
|
||||
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
|
||||
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
||||
canvas.rotate(math.PI * delta / 1800);
|
||||
canvas.scale(0.2, 0.2);
|
||||
ui.Paint paint = new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0);
|
||||
|
||||
// Draw image
|
||||
if (image != null)
|
||||
canvas.drawImage(image, new ui.Point(-image.width / 2.0, -image.height / 2.0), paint);
|
||||
|
||||
// Draw cut out of image
|
||||
canvas.rotate(math.PI * delta / 1800);
|
||||
if (image != null) {
|
||||
var w = image.width.toDouble();
|
||||
var h = image.width.toDouble();
|
||||
canvas.drawImageRect(image,
|
||||
new ui.Rect.fromLTRB(w * 0.25, h * 0.25, w * 0.75, h * 0.75),
|
||||
new ui.Rect.fromLTRB(-w / 4.0, -h / 4.0, w / 4.0, h / 4.0),
|
||||
paint);
|
||||
}
|
||||
|
||||
return recorder.endRecording();
|
||||
}
|
||||
|
||||
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
|
||||
Float64List deviceTransform = new Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||
..pop();
|
||||
return sceneBuilder.build();
|
||||
}
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
if (timeBase == null)
|
||||
timeBase = timeStamp;
|
||||
double delta = (timeStamp - timeBase).inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND;
|
||||
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
|
||||
ui.Picture picture = paint(paintBounds, delta);
|
||||
ui.Scene scene = composite(picture, paintBounds);
|
||||
ui.window.render(scene);
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
|
||||
|
||||
void handleImageLoad(result) {
|
||||
if (result != image) {
|
||||
print("${result.width}x${result.width} image loaded!");
|
||||
image = result;
|
||||
ui.window.scheduleFrame();
|
||||
} else {
|
||||
print("Existing image was loaded again");
|
||||
}
|
||||
}
|
||||
|
||||
bool handleEvent(ui.Event event) {
|
||||
if (event.type == "pointerdown") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.type == "pointerup") {
|
||||
imageCache.load(url2).first.then(handleImageLoad);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
imageCache.load(url1).first.then(handleImageLoad);
|
||||
ui.window.onEvent = handleEvent;
|
||||
ui.window.onBeginFrame = beginFrame;
|
||||
}
|
||||
48
examples/raw/spinning_square.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:typed_data';
|
||||
|
||||
Duration timeBase = null;
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
ui.tracing.begin('beginFrame');
|
||||
if (timeBase == null)
|
||||
timeBase = timeStamp;
|
||||
double delta = (timeStamp - timeBase).inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND;
|
||||
|
||||
// paint
|
||||
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
|
||||
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
||||
canvas.rotate(math.PI * delta / 1800);
|
||||
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
|
||||
ui.Picture picture = recorder.endRecording();
|
||||
|
||||
// composite
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
|
||||
Float64List deviceTransform = new Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||
..pop();
|
||||
ui.window.render(sceneBuilder.build());
|
||||
|
||||
ui.tracing.end('beginFrame');
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
|
||||
void main() {
|
||||
ui.window.onBeginFrame = beginFrame;
|
||||
ui.window.scheduleFrame();
|
||||
}
|
||||
46
examples/rendering/align_items.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
import 'lib/solid_color_box.dart';
|
||||
|
||||
void main() {
|
||||
RenderFlex table = new RenderFlex(direction: FlexDirection.vertical);
|
||||
|
||||
for (FlexAlignItems alignItems in FlexAlignItems.values) {
|
||||
TextStyle style = const TextStyle(color: const Color(0xFF000000));
|
||||
RenderParagraph paragraph = new RenderParagraph(new StyledTextSpan(style, <TextSpan>[new PlainTextSpan("$alignItems")]));
|
||||
table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0)));
|
||||
RenderFlex row = new RenderFlex(alignItems: alignItems, textBaseline: TextBaseline.alphabetic);
|
||||
style = new TextStyle(fontSize: 15.0, color: const Color(0xFF000000));
|
||||
row.add(new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(backgroundColor: const Color(0x7FFFCCCC)),
|
||||
child: new RenderParagraph(new StyledTextSpan(style, <TextSpan>[new PlainTextSpan('foo foo foo')]))
|
||||
));
|
||||
style = new TextStyle(fontSize: 10.0, color: const Color(0xFF000000));
|
||||
row.add(new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCFFCC)),
|
||||
child: new RenderParagraph(new StyledTextSpan(style, <TextSpan>[new PlainTextSpan('foo foo foo')]))
|
||||
));
|
||||
RenderFlex subrow = new RenderFlex(alignItems: alignItems, textBaseline: TextBaseline.alphabetic);
|
||||
style = new TextStyle(fontSize: 25.0, color: const Color(0xFF000000));
|
||||
subrow.add(new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCCCFF)),
|
||||
child: new RenderParagraph(new StyledTextSpan(style, <TextSpan>[new PlainTextSpan('foo foo foo foo')]))
|
||||
));
|
||||
subrow.add(new RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: new Size(30.0, 40.0)));
|
||||
row.add(subrow);
|
||||
table.add(row);
|
||||
final FlexParentData rowParentData = row.parentData;
|
||||
rowParentData.flex = 1;
|
||||
}
|
||||
|
||||
RenderDecoratedBox root = new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF)),
|
||||
child: new RenderPadding(child: table, padding: new EdgeDims.symmetric(vertical: 50.0))
|
||||
);
|
||||
|
||||
new FlutterBinding(root: root);
|
||||
}
|
||||
76
examples/rendering/baseline.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
RenderBox getBox(double lh) {
|
||||
RenderParagraph paragraph = new RenderParagraph(
|
||||
new StyledTextSpan(
|
||||
new TextStyle(
|
||||
color: const Color(0xFF0000A0)
|
||||
),
|
||||
<TextSpan>[
|
||||
new PlainTextSpan('test'),
|
||||
new StyledTextSpan(
|
||||
new TextStyle(
|
||||
fontFamily: 'serif',
|
||||
fontSize: 50.0,
|
||||
height: lh
|
||||
),
|
||||
<TextSpan>[new PlainTextSpan('مرحبا Hello')]
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
return new RenderPadding(
|
||||
padding: new EdgeDims.all(10.0),
|
||||
child: new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tightFor(height: 200.0),
|
||||
child: new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: const Color(0xFFFFFFFF)
|
||||
),
|
||||
child: new RenderPadding(
|
||||
padding: new EdgeDims.all(10.0),
|
||||
child: new RenderCustomPaint(
|
||||
child: paragraph,
|
||||
onPaint: (PaintingCanvas canvas, Size size) {
|
||||
double baseline = paragraph.getDistanceToBaseline(TextBaseline.alphabetic);
|
||||
double w = paragraph.getMaxIntrinsicWidth(new BoxConstraints.loose(size));
|
||||
double h = paragraph.getMaxIntrinsicHeight(new BoxConstraints.loose(size));
|
||||
Path path = new Path();
|
||||
path.moveTo(0.0, 0.0);
|
||||
path.lineTo(w, 0.0);
|
||||
path.moveTo(0.0, baseline);
|
||||
path.lineTo(w, baseline);
|
||||
path.moveTo(0.0, h);
|
||||
path.lineTo(w, h);
|
||||
Paint paint = new Paint()
|
||||
..color = const Color(0xFFFF9000)
|
||||
..style = ui.PaintingStyle.stroke
|
||||
..strokeWidth = 3.0;
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
RenderBox root = new RenderFlex(children: <RenderBox>[
|
||||
new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tightFor(height: 50.0)
|
||||
),
|
||||
getBox(1.0),
|
||||
getBox(null),
|
||||
],
|
||||
direction: FlexDirection.vertical,
|
||||
alignItems: FlexAlignItems.stretch
|
||||
);
|
||||
new FlutterBinding(root: root);
|
||||
}
|
||||
77
examples/rendering/borders.dart
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
void main() {
|
||||
RenderFlex root = new RenderFlex(
|
||||
children: <RenderBox>[
|
||||
new RenderPadding(
|
||||
padding: new EdgeDims.all(10.0),
|
||||
child: new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||
child: new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: new ui.Color(0xFFFFFF00)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
new RenderPadding(
|
||||
padding: new EdgeDims.all(10.0),
|
||||
child: new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||
child: new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(
|
||||
border: new Border(
|
||||
top: new BorderSide(color: new ui.Color(0xFFF00000), width: 5.0),
|
||||
right: new BorderSide(color: new ui.Color(0xFFFF9000), width: 10.0),
|
||||
bottom: new BorderSide(color: new ui.Color(0xFFFFF000), width: 15.0),
|
||||
left: new BorderSide(color: new ui.Color(0xFF00FF00), width: 20.0)
|
||||
),
|
||||
backgroundColor: new ui.Color(0xFFDDDDDD)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
new RenderPadding(
|
||||
padding: new EdgeDims.all(10.0),
|
||||
child: new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||
child: new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: new ui.Color(0xFFFFFF00)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
new RenderPadding(
|
||||
padding: new EdgeDims.all(10.0),
|
||||
child: new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||
child: new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: new ui.Color(0xFFFFFF00)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
new RenderPadding(
|
||||
padding: new EdgeDims.all(10.0),
|
||||
child: new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||
child: new RenderDecoratedBox(
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: new ui.Color(0xFFFFFF00)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
],
|
||||
direction: FlexDirection.vertical
|
||||
);
|
||||
new FlutterBinding(root: root);
|
||||
}
|
||||