Compare commits
157 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e2bda0fefa | |||
| af5a4319f7 | |||
| da5616bf47 | |||
| ec42687d1b | |||
| ddc8581445 | |||
| 8122349668 | |||
| 374b286ebb | |||
| 37e6f3d7f8 | |||
| 451b107f6b | |||
| d52d8ff4f3 | |||
| 5faa179116 | |||
| b488e6f88a | |||
| 6274bd271e | |||
| b9908f2d5b | |||
| 2dbfe79371 | |||
| ce17fff6df | |||
| 0a072562cb | |||
| ce4f6854f7 | |||
| 4f3a6c5174 | |||
| 215d820e68 | |||
| 61e74a3755 | |||
| 34cb98beb1 | |||
| 68c0c4d35f | |||
| 09d18808b4 | |||
| cdfc3fd344 | |||
| b9c70a6512 | |||
| 7b047e068e | |||
| d192babccc | |||
| 735e4c1444 | |||
| 400d91ef6e | |||
| b7ad9df8af | |||
| 6003158199 | |||
| bdaf3504e3 | |||
| 349916e504 | |||
| 53460a1ad6 | |||
| 7fe246e8d3 | |||
| 1d4fd3b2a9 | |||
| 7c879ee159 | |||
| cd6ad0e3ed | |||
| 3638c8d2b6 | |||
| c5002ec3fe | |||
| 33f4b3eea0 | |||
| 493a319ef5 | |||
| b87338cbef | |||
| de0a7a3687 | |||
| a29594e79c | |||
| 5c564f8bb1 | |||
| 56122a37c3 | |||
| d55201ecc0 | |||
| 22e7894c03 | |||
| ad504de290 | |||
| 9fb1c1405f | |||
| bee0fc7562 | |||
| 7ed1515072 | |||
| 58674f3572 | |||
| 7a1a98daf3 | |||
| 0771e89873 | |||
| 80c200f5f7 | |||
| 301360df31 | |||
| a07d9eb366 | |||
| d86b1c713b | |||
| 62ddbb683e | |||
| 8c0991adb0 | |||
| b0824773c9 | |||
| c2ab82b351 | |||
| 3f842f4cfc | |||
| f1302e5636 | |||
| 02e5481bbd | |||
| 66f0e79297 | |||
| cad4faa580 | |||
| 3e06e5df26 | |||
| 020fb23188 | |||
| b3196d2295 | |||
| d819271cd3 | |||
| 71995ef672 | |||
| d4aeffb8a6 | |||
| 34c6a269de | |||
| 5cd1bbc30a | |||
| 78ecd35587 | |||
| e517c0a298 | |||
| eeb659622c | |||
| 9182210001 | |||
| bc2bb7d125 | |||
| 6c0bb2af8c | |||
| 7f28abd635 | |||
| 7d26241584 | |||
| 2b9cea80bc | |||
| a518daed82 | |||
| 35caa8571a | |||
| 167d43342a | |||
| 4487aedee7 | |||
| 086518ae42 | |||
| a53510d1d4 | |||
| 4a65cef02a | |||
| 56baf7cfdc | |||
| 97b7686694 | |||
| 5b4e8dbb5e | |||
| 9671a37d0d | |||
| 823f3ea596 | |||
| cc6717f46b | |||
| 6bc4f297d5 | |||
| a6bbcb408f | |||
| 59058c1b92 | |||
| ff1233b28e | |||
| 6e7da7c348 | |||
| f32085e053 | |||
| fe5a4a71c4 | |||
| a39b45d090 | |||
| d4acd11c86 | |||
| 56d8509f8a | |||
| 2669e56e06 | |||
| 60a7f21a48 | |||
| cb348a4740 | |||
| 5f04ad6c57 | |||
| 29b1b05441 | |||
| c532dc6e9f | |||
| 047db87a25 | |||
| 18808764f9 | |||
| 61b0078f3f | |||
| 95ab956ea3 | |||
| 7f172ab7a0 | |||
| a060118589 | |||
| f53b065d59 | |||
| 7fb65137fa | |||
| 37846c4a18 | |||
| cd2e80501b | |||
| 6687bc83d1 | |||
| 1df0857db3 | |||
| 2113d81475 | |||
| b714f60be6 | |||
| 3bbb5e384d | |||
| 374f540fe5 | |||
| e2361b66a0 | |||
| 38ceb7eecb | |||
| 462ee023c3 | |||
| 78fb9bac50 | |||
| 75ca7b90f0 | |||
| 19fd6866f1 | |||
| 7c6bdf98f4 | |||
| 4d3acce9ea | |||
| 25a3fc7bf1 | |||
| 1643283b5d | |||
| 28b94b7470 | |||
| 9b80d545c1 | |||
| 448e48e803 | |||
| 9abd0ebf88 | |||
| 6ca134c3ee | |||
| 256c3e0457 | |||
| a9886d8cc4 | |||
| 91d588d622 | |||
| dd613b463a | |||
| 759cb4c0b3 | |||
| 8a29f1ca46 | |||
| 5403b13931 | |||
| d0fc36c097 | |||
| 1baa673f8a | |||
| 2e6dbb7b38 |
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
# Editor configuration, see http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,5 +1,8 @@
|
||||
/.idea
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
out/
|
||||
target/
|
||||
target/
|
||||
*.zip
|
||||
pack.sh
|
||||
30
Meta.hx
30
Meta.hx
@@ -1,30 +0,0 @@
|
||||
package;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
#end
|
||||
|
||||
class Meta {
|
||||
|
||||
#if macro
|
||||
private static inline var VERSION:String = "version";
|
||||
private static inline var BUILD:String = "build";
|
||||
|
||||
private static var data:Map<String, Dynamic> = new Map<String, Dynamic>();
|
||||
#end
|
||||
|
||||
macro static public function getBuild():ExprOf<String> {
|
||||
return Context.makeExpr(data.get(BUILD), Context.currentPos());
|
||||
}
|
||||
|
||||
macro static public function getVersion():ExprOf<String> {
|
||||
return Context.makeExpr(data.get(VERSION), Context.currentPos());
|
||||
}
|
||||
|
||||
macro static public function set(version:String) {
|
||||
data.set(BUILD, Date.now().toString());
|
||||
data.set(VERSION, version);
|
||||
return macro {};
|
||||
}
|
||||
}
|
||||
66
README.md
Executable file
66
README.md
Executable file
@@ -0,0 +1,66 @@
|
||||
# haxework
|
||||
|
||||
Gui framework for Haxe.
|
||||
|
||||
## View
|
||||
|
||||
`haxework.gui` provides views classes.
|
||||
|
||||
### Example
|
||||
|
||||
Build form using macro @:template.
|
||||
|
||||
form.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"$type": "haxework.gui.VGroupView",
|
||||
"skin": [{"$type": "haxework.gui.skin.ColorSkin", "color": "0xffff00"}],
|
||||
"geometry.padding": 20,
|
||||
"layout.margin": 10,
|
||||
"views":[
|
||||
{
|
||||
"id": "view1",
|
||||
"type":"haxework.gui.SpriteView",
|
||||
"geometry.size.stretch": true,
|
||||
"skin":[{"$type":"haxework.gui.skin.ColorSkin", "color": "0xff0000"}]
|
||||
},
|
||||
{
|
||||
"id": "view2",
|
||||
"type": "haxework.gui.SpriteView",
|
||||
"geometry.size.width": "100%",
|
||||
"geometry.size.height": 50,
|
||||
"skin": [{"$type":"haxework.gui.skin.ColorSkin", "color": "0x00ff00"}]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
```haxe
|
||||
@:template("form.json")
|
||||
class FormView extends VGroupView {
|
||||
@:view public var view1:SpriteView;
|
||||
@:view("view2") public var anyVarName:SpriteView;
|
||||
}
|
||||
|
||||
var form = new FormView();
|
||||
Root.bind(form); // Add form to stage as root view element.
|
||||
trace(form.view1);
|
||||
trace(form.anyVarName);
|
||||
```
|
||||
|
||||
## Loader
|
||||
|
||||
`haxework.net` provides loaders classes.
|
||||
|
||||
### Example
|
||||
|
||||
```haxe
|
||||
new JsonLoader().GET("http://example.com/file.json")
|
||||
.then(function(data) {
|
||||
trace("Json Ok: " + data);
|
||||
})
|
||||
.catchError(function(error) {
|
||||
trace("Json Fail: " + error);
|
||||
});
|
||||
```
|
||||
@@ -1,4 +0,0 @@
|
||||
-main examples.ViewExample
|
||||
-swf target/ViewExample.swf
|
||||
-debug
|
||||
-dce no
|
||||
14
demo/build.hxml
Executable file
14
demo/build.hxml
Executable file
@@ -0,0 +1,14 @@
|
||||
-cp src
|
||||
-cp ../src/main
|
||||
-lib yaml
|
||||
-lib promhx
|
||||
--macro haxework.parser.Parser.auto()
|
||||
-debug
|
||||
-D native_trace
|
||||
#-D dev_layout
|
||||
-swf-version 10.1
|
||||
-swf-header 800:600:30:000000
|
||||
|
||||
-main demo.Demo
|
||||
-swf target/demo.swf
|
||||
#-as3 target
|
||||
26
demo/project.xml
Normal file
26
demo/project.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<meta title="Demo" package="haxework.demo" version="1.0.0" company="MegaLoMania"/>
|
||||
<app main="demo.Demo" path="target" file="demo"/>
|
||||
<icon path="src/haxe-logo.png"/>
|
||||
|
||||
<source path="../src/main"/>
|
||||
<source path="src"/>
|
||||
<assets path="src" rename="image" include="*.png"/>
|
||||
|
||||
<haxelib name="lime" version="7.3.0"/>
|
||||
<haxelib name="openfl" version="8.9.0"/>
|
||||
<haxelib name="hxcpp" version="4.0.8"/>
|
||||
<haxelib name="promhx" version="1.1.0"/>
|
||||
<haxelib name="yaml" version="1.3.0"/>
|
||||
|
||||
<haxeflag name="--macro" value="haxework.parser.Parser.auto()"/>
|
||||
<haxeflag name="--macro" value="CompilationOption.set('build','xxx')"/>
|
||||
|
||||
<window fps="30"/>
|
||||
<window width="1024" height="768" unless="html5"/>
|
||||
|
||||
<haxeflag name="-D" value="swf-gpu"/>
|
||||
<haxeflag name="-D" value="native-trace"/>
|
||||
<haxeflag name="-dce" value="no"/>
|
||||
</project>
|
||||
6
demo/run.sh
Executable file
6
demo/run.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
echo "`pwd`/target" > ~/.macromedia/Flash_Player/#Security/FlashPlayerTrust/haxework_demo.cfg
|
||||
. /opt/sdk/neko/2.2.0/activate
|
||||
. /opt/sdk/haxe/3.4.7/activate
|
||||
haxe build.hxml && flashplayerdebugger target/demo.swf &
|
||||
tail -f ~/.macromedia/Flash_Player/Logs/flashlog.txt
|
||||
5
demo/run_openfl.sh
Executable file
5
demo/run_openfl.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
echo "`pwd`/target/flash/bin" > ~/.macromedia/Flash_Player/#Security/FlashPlayerTrust/haxework_demo.cfg
|
||||
. /opt/sdk/neko/2.2.0/activate
|
||||
. /opt/sdk/haxe/3.4.7/activate
|
||||
haxelib run openfl test flash
|
||||
26
demo/src/demo/AppTheme.hx
Normal file
26
demo/src/demo/AppTheme.hx
Normal file
@@ -0,0 +1,26 @@
|
||||
package demo;
|
||||
|
||||
import haxework.view.geometry.Box;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.theme.Theme;
|
||||
|
||||
using haxework.color.ColorUtil;
|
||||
|
||||
class AppTheme extends Theme {
|
||||
|
||||
public function new(?color:Color, ?textColor:Color):Void {
|
||||
super({name: "Courirer"}, {light: color, text: textColor});
|
||||
}
|
||||
|
||||
override private function reload():Void {
|
||||
super.reload();
|
||||
register(new Style("view", [
|
||||
"skin.background.color" => colors.light,
|
||||
"skin.border.color" => colors.border,
|
||||
"geometry.padding" => Box.fromFloat(3),
|
||||
], ["text"]));
|
||||
register(new Style("test", [
|
||||
"skin.background.color" => Color.fromInt(0x00ffff),
|
||||
]));
|
||||
}
|
||||
}
|
||||
88
demo/src/demo/Demo.hx
Normal file
88
demo/src/demo/Demo.hx
Normal file
@@ -0,0 +1,88 @@
|
||||
package demo;
|
||||
|
||||
import demo.dispatch.DemoDispatcher;
|
||||
import demo.popup.ColorPopup;
|
||||
import demo.popup.FontPopup;
|
||||
import haxework.App;
|
||||
import haxework.log.TraceLogger;
|
||||
import haxework.net.JsonLoader;
|
||||
import haxework.view.data.ButtonGroup;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.group.VGroupView;
|
||||
|
||||
@:template class DemoView extends VGroupView {
|
||||
@:view var switcher:FrameSwitcher;
|
||||
@:view var tabs:ButtonGroup<String>;
|
||||
|
||||
private function init():Void {
|
||||
switcher.change("list");
|
||||
}
|
||||
|
||||
private function onFrameSwitch(frame:FrameView<Dynamic>):Void {
|
||||
tabs.selected = frame.frameId;
|
||||
}
|
||||
|
||||
private function choiceColor():Void {
|
||||
new ColorPopup().show().then(function(color) {
|
||||
if (color != null) {
|
||||
theme.colors = {light: color};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function choiceFont():Void {
|
||||
new FontPopup().show().then(function(font) {
|
||||
if (font != null) {
|
||||
theme.font = font;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Demo extends App implements DemoListener {
|
||||
|
||||
public static function main() {
|
||||
L.push(new TraceLogger());
|
||||
|
||||
var app = new Demo(new AppTheme());
|
||||
app.resources.image.put("logo", HaxeLogo.resolve());
|
||||
app.start(new DemoView());
|
||||
|
||||
var dispatcher = new DemoDispatcher();
|
||||
dispatcher.connect(app);
|
||||
dispatcher.test1Signal.emit();
|
||||
dispatcher.test2Signal.emit(1);
|
||||
dispatcher.test3Signal.emit(1, "test");
|
||||
dispatcher.test4Signal.emit(app);
|
||||
dispatcher.disconnect(app);
|
||||
dispatcher.test1Signal.emit();
|
||||
dispatcher.test2Signal.emit(1);
|
||||
dispatcher.test3Signal.emit(1, "test");
|
||||
dispatcher.test4Signal.emit(app);
|
||||
|
||||
new JsonLoader().GET("https://embed.tvbit.co/channel/data2/renova.json")
|
||||
.then(function(data:Array<Model>) {
|
||||
app.resources.any.put("data", data);
|
||||
app.resources.any.put("data50", Util.marray(data, 50));
|
||||
})
|
||||
.catchError(function(error) trace(error));
|
||||
}
|
||||
|
||||
public function onTest1():Void {
|
||||
trace('test1');
|
||||
}
|
||||
|
||||
public function onTest2(a:Int):Void {
|
||||
trace('test2', a);
|
||||
}
|
||||
|
||||
public function onTest3(a:Int, b:String):Void {
|
||||
trace('test3', a, b);
|
||||
}
|
||||
|
||||
public function onTest4(app: App):Void {
|
||||
trace('test4', app);
|
||||
}
|
||||
|
||||
}
|
||||
54
demo/src/demo/DemoView.yaml
Normal file
54
demo/src/demo/DemoView.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
style: background
|
||||
views:
|
||||
- $type: haxework.view.ImageView
|
||||
geometry.padding: 10
|
||||
image: $r:image:logo
|
||||
- id: tabs
|
||||
$type: haxework.view.data.ButtonGroup<String>
|
||||
layout.margin: 5
|
||||
layout.hAlign: left
|
||||
geometry.width: 100%
|
||||
geometry.padding.left: 5
|
||||
geometry.margin.bottom: -6
|
||||
buttonStyle: button.tab
|
||||
+onDataSelect: ~function(id) switcher.change(id)
|
||||
data:
|
||||
- "list"
|
||||
- "tail"
|
||||
- "data"
|
||||
- "test_layout"
|
||||
- "select"
|
||||
- id: switcher
|
||||
$type: haxework.view.frame.FrameSwitcher
|
||||
animateFactory: { $class: haxework.animate.SlideAnimate }
|
||||
+onSwitch: ~onFrameSwitch
|
||||
geometry.stretch: true
|
||||
geometry.padding: 5
|
||||
factory:
|
||||
_list_: {$class: demo.form.ListForm}
|
||||
_tail_: {$class: demo.form.TailForm}
|
||||
_data_: {$class: demo.form.DataForm}
|
||||
_test_layout_: {$class: demo.form.TestLayoutForm}
|
||||
_select_: {$class: demo.form.SelectForm}
|
||||
- $type: haxework.view.group.HGroupView
|
||||
geometry.width: 100%
|
||||
geometry.padding: 10
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Color
|
||||
+onPress: ~choiceColor()
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Font
|
||||
+onPress: ~choiceFont()
|
||||
# separator
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.stretch: true
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: OK
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Apply
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Cancel
|
||||
+onPress: ~flash.system.System.exit(0)
|
||||
17
demo/src/demo/HaxeLogo.hx
Normal file
17
demo/src/demo/HaxeLogo.hx
Normal file
@@ -0,0 +1,17 @@
|
||||
package demo;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
|
||||
#if !openfl
|
||||
@:bitmap("haxe-logo.png")
|
||||
#end
|
||||
class HaxeLogo extends BitmapData {
|
||||
|
||||
public static function resolve():BitmapData {
|
||||
#if openfl
|
||||
return openfl.Assets.getBitmapData("image/haxe-logo.png");
|
||||
#else
|
||||
return new HaxeLogo(0, 0);
|
||||
#end
|
||||
}
|
||||
}
|
||||
10
demo/src/demo/Model.hx
Normal file
10
demo/src/demo/Model.hx
Normal file
@@ -0,0 +1,10 @@
|
||||
package demo;
|
||||
|
||||
typedef Model = {
|
||||
var id:String;
|
||||
var created_at:Int;
|
||||
var maker:String;
|
||||
var title:String;
|
||||
var message:String;
|
||||
var image:{url:String, width:Int, height:Int};
|
||||
}
|
||||
17
demo/src/demo/Test.hx
Normal file
17
demo/src/demo/Test.hx
Normal file
@@ -0,0 +1,17 @@
|
||||
package demo;
|
||||
|
||||
import demo.test.TestView;
|
||||
import haxework.view.Root;
|
||||
import haxework.view.SpriteView;
|
||||
|
||||
class Test {
|
||||
public static function main():Void {
|
||||
new Test();
|
||||
}
|
||||
|
||||
public function new() {
|
||||
trace("Test");
|
||||
var view = new SpriteView();
|
||||
Root.bind(new TestView());
|
||||
}
|
||||
}
|
||||
12
demo/src/demo/Util.hx
Normal file
12
demo/src/demo/Util.hx
Normal file
@@ -0,0 +1,12 @@
|
||||
package demo;
|
||||
|
||||
class Util {
|
||||
|
||||
public static function marray<T>(value:Array<T>, m:Int):Array<T> {
|
||||
var result = [];
|
||||
for (i in 0...m) {
|
||||
result = result.concat(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
14
demo/src/demo/dispatch/DemoDispatcher.hx
Normal file
14
demo/src/demo/dispatch/DemoDispatcher.hx
Normal file
@@ -0,0 +1,14 @@
|
||||
package demo.dispatch;
|
||||
|
||||
import haxework.App;
|
||||
|
||||
interface DemoListener {
|
||||
public function onTest1():Void;
|
||||
public function onTest2(a:Int):Void;
|
||||
public function onTest3(a:Int, b:String):Void;
|
||||
public function onTest4(app:App):Void;
|
||||
}
|
||||
|
||||
@:yield @:dispatcher(DemoListener) class DemoDispatcher {
|
||||
public function new() {}
|
||||
}
|
||||
19
demo/src/demo/form/DataForm.hx
Normal file
19
demo/src/demo/form/DataForm.hx
Normal file
@@ -0,0 +1,19 @@
|
||||
package demo.form;
|
||||
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.text.TextView;
|
||||
|
||||
@:template class DataForm extends FrameView<Dynamic> {
|
||||
public function new() {
|
||||
super("data");
|
||||
}
|
||||
|
||||
private function factory(index:Int, value:Model):TextView {
|
||||
var label = new TextView();
|
||||
label.geometry.width.percent = 100;
|
||||
label.geometry.margin = 1;
|
||||
label.geometry.padding = 2;
|
||||
label.text = (value.title != null ? '${value.title}\n-\n' : '') + value.message;
|
||||
return label;
|
||||
}
|
||||
}
|
||||
10
demo/src/demo/form/DataForm.yaml
Normal file
10
demo/src/demo/form/DataForm.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
overflow.y: scroll
|
||||
views:
|
||||
- id: data
|
||||
$type: haxework.view.data.DataView
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
factory: ~factory
|
||||
geometry.width: 100%
|
||||
data: $r:any:data
|
||||
22
demo/src/demo/form/ListForm.hx
Normal file
22
demo/src/demo/form/ListForm.hx
Normal file
@@ -0,0 +1,22 @@
|
||||
package demo.form;
|
||||
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.list.LabelListItem;
|
||||
import haxework.view.list.ListView.IListItemView;
|
||||
import haxework.view.list.VListView;
|
||||
|
||||
@:template class ListForm extends FrameView<Dynamic> {
|
||||
@:view public var list(default, null):VListView<Model>;
|
||||
|
||||
public function new() {
|
||||
super("list");
|
||||
}
|
||||
|
||||
private function factory() {
|
||||
return new LabelListItem(function(index:Int, value:Model) return '${index}. ${value.id}: ${value.title}');
|
||||
}
|
||||
|
||||
private function onItemSelect(item:IListItemView<Model>):Void {
|
||||
trace('onItemSelect: ${item.data.id}');
|
||||
}
|
||||
}
|
||||
10
demo/src/demo/form/ListForm.yaml
Normal file
10
demo/src/demo/form/ListForm.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
views:
|
||||
- id: list
|
||||
$type: haxework.view.list.VListView
|
||||
+onItemSelect: ~onItemSelect
|
||||
factory: ~factory
|
||||
geometry.stretch: true
|
||||
scroll:
|
||||
$type: haxework.view.list.VScrollBarView
|
||||
data: $r:any:data50
|
||||
9
demo/src/demo/form/SelectForm.hx
Normal file
9
demo/src/demo/form/SelectForm.hx
Normal file
@@ -0,0 +1,9 @@
|
||||
package demo.form;
|
||||
|
||||
import haxework.view.frame.FrameView;
|
||||
|
||||
@:template class SelectForm extends FrameView<Dynamic> {
|
||||
public function new() {
|
||||
super("select");
|
||||
}
|
||||
}
|
||||
31
demo/src/demo/form/SelectForm.yaml
Normal file
31
demo/src/demo/form/SelectForm.yaml
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
geometry.padding: 10
|
||||
layout.margin: 5
|
||||
views:
|
||||
- $type: haxework.view.form.SelectView<String>
|
||||
layout.margin: 2
|
||||
dataView.layout.margin: 1
|
||||
data:
|
||||
- "value 1"
|
||||
- "value 2"
|
||||
- "value 3"
|
||||
- "value 4"
|
||||
selected: "value 1"
|
||||
+onSelect: ~function(value) trace('select', value)
|
||||
|
||||
- $type: haxework.view.form.SelectView.SelectIdView<{id:Int,label:String}, Int>
|
||||
layout.margin: 2
|
||||
dataView.layout.margin: 1
|
||||
labelBuilder: |
|
||||
~function(item:{id:Int,label:String}):String {
|
||||
var result = item.label;
|
||||
result += " (" + item.id + ")";
|
||||
return result;
|
||||
}
|
||||
data:
|
||||
- {id: 1, label: "Aaaaaaaa", $type: Dynamic}
|
||||
- {id: 2, label: "Bbbbbb", $type: Dynamic}
|
||||
- {id: 3, label: "Cccc", $type: Dynamic}
|
||||
- {id: 4, label: "Ddd", $type: Dynamic}
|
||||
selectedId: 1
|
||||
+onSelect: ~function(value) trace('select', value)
|
||||
34
demo/src/demo/form/TailForm.hx
Normal file
34
demo/src/demo/form/TailForm.hx
Normal file
@@ -0,0 +1,34 @@
|
||||
package demo.form;
|
||||
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.ImageView;
|
||||
import haxework.view.IView;
|
||||
import haxework.view.text.TextView;
|
||||
import haxework.view.utils.DrawUtil;
|
||||
|
||||
@:template class TailForm extends FrameView<Dynamic> {
|
||||
|
||||
public function new() {
|
||||
super("tail");
|
||||
}
|
||||
|
||||
private function factory(index:Int, value:Model):IView<Dynamic> {
|
||||
var view:IView<Dynamic>;
|
||||
if (value.image != null) {
|
||||
var imageView = new ImageView();
|
||||
imageView.style = "view";
|
||||
imageView.stretch = false;
|
||||
//imageView.style = "border";
|
||||
imageView.fillType = FillType.CONTAIN;
|
||||
imageView.imageUrl = value.image.url;
|
||||
view = imageView;
|
||||
} else {
|
||||
var textView = new TextView();
|
||||
textView.style = "view";
|
||||
textView.text = '${value.id}\n${value.maker}';
|
||||
view = textView;
|
||||
}
|
||||
view.setSize(350, 200);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
12
demo/src/demo/form/TailForm.yaml
Normal file
12
demo/src/demo/form/TailForm.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
overflow.y: scroll
|
||||
views:
|
||||
- id: data
|
||||
$type: haxework.view.data.DataView
|
||||
geometry.padding: 4
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
margin: 6
|
||||
factory: ~factory
|
||||
geometry.width: 100%
|
||||
data: $r:any:data
|
||||
27
demo/src/demo/form/TestLayoutForm.hx
Normal file
27
demo/src/demo/form/TestLayoutForm.hx
Normal file
@@ -0,0 +1,27 @@
|
||||
package demo.form;
|
||||
|
||||
import flash.events.MouseEvent;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.SpriteView;
|
||||
|
||||
@:template class TestLayoutForm extends FrameView<Dynamic> {
|
||||
|
||||
@:view var render:SpriteView;
|
||||
|
||||
public function new() {
|
||||
super("test_layout");
|
||||
}
|
||||
|
||||
public function init():Void {
|
||||
resize();
|
||||
content.addEventListener(MouseEvent.CLICK, function(_) {
|
||||
resize();
|
||||
});
|
||||
}
|
||||
|
||||
private function resize():Void {
|
||||
var w = 200 + 400 * Math.random();
|
||||
var h = 100 + 200 * Math.random();
|
||||
render.setSize(w, h, "render");
|
||||
}
|
||||
}
|
||||
53
demo/src/demo/form/TestLayoutForm.yaml
Normal file
53
demo/src/demo/form/TestLayoutForm.yaml
Normal file
@@ -0,0 +1,53 @@
|
||||
---
|
||||
views:
|
||||
- id: main
|
||||
$type: haxework.view.group.VGroupView
|
||||
geometry.stretch: true
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: container
|
||||
$type: haxework.view.group.VGroupView
|
||||
layout.margin: 10
|
||||
skin:
|
||||
$type: [haxework.view.skin.Skin.color, 0xffff00]
|
||||
views:
|
||||
- id: top
|
||||
$type: haxework.view.group.GroupView
|
||||
layout.hAlign: center
|
||||
geometry.width: 100%
|
||||
geometry.height: 20
|
||||
style: test
|
||||
- id: middle
|
||||
$type: haxework.view.group.HGroupView
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: left
|
||||
$type: haxework.view.group.GroupView
|
||||
layout.vAlign: middle
|
||||
geometry.width: 20
|
||||
geometry.height: 100%
|
||||
style: test
|
||||
- id: render
|
||||
$type: haxework.view.SpriteView
|
||||
#geometry.width: 300
|
||||
#geometry.height: 200
|
||||
style: test
|
||||
- id: right
|
||||
$type: haxework.view.group.GroupView
|
||||
layout.vAlign: middle
|
||||
geometry.width: 20
|
||||
geometry.height: 100%
|
||||
style: test
|
||||
views:
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100
|
||||
geometry.height: 100%
|
||||
skin:
|
||||
$type: [haxework.view.skin.Skin.color, 0xff0000]
|
||||
- id: bottom
|
||||
$type: haxework.view.group.GroupView
|
||||
layout.hAlign: center
|
||||
style: test
|
||||
geometry.width: 100%
|
||||
geometry.height: 20
|
||||
16
demo/src/demo/popup/ColorPopup.hx
Normal file
16
demo/src/demo/popup/ColorPopup.hx
Normal file
@@ -0,0 +1,16 @@
|
||||
package demo.popup;
|
||||
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.popup.PopupView;
|
||||
import haxework.view.skin.Skin;
|
||||
|
||||
@:template class ColorPopup extends PopupView<Null<Int>> {
|
||||
|
||||
private function colorViewFactory(index:Int, color:Int) {
|
||||
var view = new ButtonView();
|
||||
view.setSize(48, 48, "fixed");
|
||||
view.geometry.padding = 0;
|
||||
view.skin = Skin.buttonColor(color);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
33
demo/src/demo/popup/ColorPopup.yaml
Normal file
33
demo/src/demo/popup/ColorPopup.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
view:
|
||||
$type: haxework.view.group.VGroupView
|
||||
geometry.width: 400
|
||||
geometry.height: 200
|
||||
geometry.padding: 10
|
||||
geometry.hAlign: center
|
||||
geometry.vAlign: middle
|
||||
style: frame
|
||||
views:
|
||||
- id: colors
|
||||
$type: haxework.view.data.DataView
|
||||
geometry.stretch: true
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
vAlign: middle
|
||||
margin: 5
|
||||
factory: ~colorViewFactory
|
||||
data:
|
||||
- 0x33AA33
|
||||
- 0xAA3333
|
||||
- 0xFFCC55 # 0x555555
|
||||
- 0xCC33AA
|
||||
- 0x3333AA
|
||||
+onDataSelect: ~close
|
||||
- $type: haxework.view.group.HGroupView
|
||||
geometry.width: 100%
|
||||
layout.hAlign: right
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Cancel
|
||||
+onPress: ~reject('cancel')
|
||||
47
demo/src/demo/popup/FontPopup.hx
Normal file
47
demo/src/demo/popup/FontPopup.hx
Normal file
@@ -0,0 +1,47 @@
|
||||
package demo.popup;
|
||||
|
||||
import flash.text.Font;
|
||||
import flash.text.FontType;
|
||||
import haxework.view.list.LabelListItem;
|
||||
import haxework.view.list.ListView;
|
||||
import haxework.view.popup.PopupView;
|
||||
import haxework.view.theme.ITheme;
|
||||
|
||||
class FontLabelView extends LabelListItem<ThemeFont> {
|
||||
|
||||
override private function set_data(value:ThemeFont):ThemeFont {
|
||||
style = item_index % 2 == 0 ? "light" : "dark";
|
||||
data = value;
|
||||
text = value.name;
|
||||
font.family = value.name;
|
||||
font.embed = value.embed;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@:template class FontPopup extends PopupView<ThemeFont> {
|
||||
|
||||
@:view var fonts:ListView<ThemeFont>;
|
||||
|
||||
private function init():Void {
|
||||
var values:Array<ThemeFont> = Font.enumerateFonts(true).map(function(font:Font) {
|
||||
return {
|
||||
name: font.fontName,
|
||||
embed: switch font.fontType {
|
||||
case DEVICE: false;
|
||||
case _: true;
|
||||
}
|
||||
}
|
||||
});
|
||||
values.sort(function(a:ThemeFont, b:ThemeFont) {
|
||||
return switch [a.embed, b.embed] {
|
||||
case [false, true]: 1;
|
||||
case [true, false]: -1;
|
||||
case _: 0;
|
||||
}
|
||||
});
|
||||
fonts.data = values;
|
||||
}
|
||||
|
||||
private function fontViewFactory() return new FontLabelView();
|
||||
}
|
||||
25
demo/src/demo/popup/FontPopup.yaml
Normal file
25
demo/src/demo/popup/FontPopup.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
view:
|
||||
$type: haxework.view.group.VGroupView
|
||||
geometry.width: 400
|
||||
geometry.height: 80%
|
||||
geometry.padding: 10
|
||||
geometry.hAlign: center
|
||||
geometry.vAlign: middle
|
||||
style: frame
|
||||
views:
|
||||
- id: fonts
|
||||
$type: haxework.view.list.VListView
|
||||
geometry.stretch: true
|
||||
factory: ~fontViewFactory
|
||||
+onItemSelect: ~function(item) close(item.data)
|
||||
scroll:
|
||||
$type: haxework.view.list.VScrollBarView
|
||||
- $type: haxework.view.group.HGroupView
|
||||
geometry.width: 100%
|
||||
geometry.margin.top: 10
|
||||
layout.hAlign: right
|
||||
views:
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Cancel
|
||||
+onPress: ~reject('cancel')
|
||||
7
demo/src/demo/test/TestView.hx
Normal file
7
demo/src/demo/test/TestView.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package demo.test;
|
||||
|
||||
import haxework.view.group.GroupView;
|
||||
|
||||
@:template class TestView extends GroupView {
|
||||
|
||||
}
|
||||
61
demo/src/demo/test/TestView.yaml
Normal file
61
demo/src/demo/test/TestView.yaml
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
geometry.padding: 10
|
||||
views:
|
||||
- $type: haxework.view.group.HGroupView
|
||||
geometry.padding: 10
|
||||
geometry.width: 100%
|
||||
layout.margin: 10
|
||||
layout.vAlign: middle
|
||||
skin:
|
||||
$type: haxework.view.skin.SpriteSkin
|
||||
background.color: 0xffff00
|
||||
background.alpha: 1
|
||||
views:
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100
|
||||
geometry.height: 100
|
||||
skin:
|
||||
$type: haxework.view.skin.SpriteSkin
|
||||
background.color: 0xff0000
|
||||
background.alpha: 1
|
||||
- $type: haxework.view.group.VGroupView
|
||||
geometry.padding: 10
|
||||
layout.margin: 10
|
||||
skin:
|
||||
$type: haxework.view.skin.SpriteSkin
|
||||
background.color: 0x00ffff
|
||||
background.alpha: 1
|
||||
views:
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100
|
||||
geometry.height: 100
|
||||
size:
|
||||
_test_: [200, 200]
|
||||
skin:
|
||||
$type: haxework.view.skin.SpriteSkin
|
||||
background.color: 0xff0000
|
||||
background.alpha: 1
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100
|
||||
geometry.height: 100
|
||||
skin:
|
||||
$type: haxework.view.skin.SpriteSkin
|
||||
background.color: 0xff0000
|
||||
background.alpha: 1
|
||||
- $type: haxework.view.text.TextView
|
||||
geometry.padding: 20
|
||||
text: "Azazaza"
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 60%
|
||||
geometry.height: 100%
|
||||
skin:
|
||||
$type: haxework.view.skin.SpriteSkin
|
||||
background.color: 0xff0000
|
||||
background.alpha: 1
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 40%
|
||||
geometry.height: 80%
|
||||
skin:
|
||||
$type: haxework.view.skin.SpriteSkin
|
||||
background.color: 0xff0000
|
||||
background.alpha: 1
|
||||
BIN
demo/src/haxe-logo.png
Normal file
BIN
demo/src/haxe-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -1,32 +0,0 @@
|
||||
package examples;
|
||||
|
||||
import haxework.gui.IGroupView;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.GuiBuilder;
|
||||
import haxework.asset.JsonAsset;
|
||||
import haxework.gui.Root;
|
||||
import flash.display.Sprite;
|
||||
|
||||
@:file("examples/form.json")
|
||||
class Form extends JsonAsset {}
|
||||
|
||||
class ViewExample implements ButtonViewListener {
|
||||
|
||||
public static function main() {
|
||||
new ViewExample();
|
||||
}
|
||||
|
||||
public function new() {
|
||||
//var form:Dynamic = new Form().value;
|
||||
var bytes = openfl.Assets.getBytes("examples/form.json");
|
||||
var form:Dynamic = haxe.Json.parse(bytes.readUTFBytes(bytes.bytesAvailable));
|
||||
var v:IGroupView<Sprite> = GuiBuilder.build(form, {listener:this});
|
||||
new Root(v);
|
||||
var button3:ButtonView = v.findViewById("panel:button3");
|
||||
trace(button3.id);
|
||||
}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
trace("onPress: " + view.id);
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
{
|
||||
"type":"haxework.gui.VGroupView",
|
||||
"layoutHAlign":"~haxework.gui.core.HAlign:CENTER",
|
||||
"layoutVAlign":"~haxework.gui.core.VAlign:MIDDLE",
|
||||
"paddings":20,
|
||||
"layoutMargin":10,
|
||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"},
|
||||
"views":[
|
||||
{
|
||||
"type":"haxework.gui.View",
|
||||
"pWidth":100,
|
||||
"pHeight":100,
|
||||
"leftMargin":5,
|
||||
"rightMargin":10,
|
||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"}
|
||||
},
|
||||
{
|
||||
"type":"haxework.gui.View",
|
||||
"vAlign":"~haxework.gui.core.VAlign:BOTTOM",
|
||||
"width":50,
|
||||
"height":50,
|
||||
"leftMargin":5,
|
||||
"rightMargin":10,
|
||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x0000ff"}
|
||||
},
|
||||
{
|
||||
"id":"panel",
|
||||
"type":"haxework.gui.HGroupView",
|
||||
"layoutHAlign":"~haxework.gui.core.HAlign:RIGHT",
|
||||
"layoutVAlign":"~haxework.gui.core.VAlign:MIDDLE",
|
||||
"pWidth":100,
|
||||
"height":30,
|
||||
"paddings":3,
|
||||
"layoutMargin":3,
|
||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xffff00"},
|
||||
"views":[
|
||||
{
|
||||
"id":"button1",
|
||||
"type":"haxework.gui.ButtonView",
|
||||
"width":100,
|
||||
"pHeight":100,
|
||||
"skin":{"type":"haxework.gui.skin.ButtonColorSkin", "color":"0xcc0000"},
|
||||
"text":"Text1",
|
||||
"onPress":"#listener"
|
||||
},
|
||||
{
|
||||
"id":"button2",
|
||||
"type":"haxework.gui.ButtonView",
|
||||
"contentSize":true,
|
||||
"skin":{"type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cc00"},
|
||||
"text":"Text2",
|
||||
"fontFamily":"Georgia",
|
||||
"fontColor":"0xffffff",
|
||||
"onPress":"#listener"
|
||||
},
|
||||
{
|
||||
"id":"button3",
|
||||
"type":"haxework.gui.ButtonView",
|
||||
"contentSize":true,
|
||||
"skin":{"type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cccc"},
|
||||
"text":"Text 3333333333 ddd",
|
||||
"fontFamily":"Tahoma",
|
||||
"fontColor":"0xff0000",
|
||||
"onPress":"#listener"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
1
extraParams.hxml
Normal file
1
extraParams.hxml
Normal file
@@ -0,0 +1 @@
|
||||
--macro haxework.parser.Parser.auto()
|
||||
28
haxelib.json
28
haxelib.json
@@ -1,11 +1,21 @@
|
||||
{
|
||||
"name": "haxework",
|
||||
"url" : "https://bitbucket.org/shmyga/haxework.git",
|
||||
"license": "BSD",
|
||||
"tags": ["flash"],
|
||||
"description": "Framework.",
|
||||
"version": "0.1.0",
|
||||
"releasenote": "Update.",
|
||||
"contributors": ["shmyga"],
|
||||
"dependencies": {}
|
||||
"name": "haxework",
|
||||
"url": "https://bitbucket.org/shmyga/haxework",
|
||||
"license": "MIT",
|
||||
"tags": [
|
||||
"view",
|
||||
"layout",
|
||||
"template"
|
||||
],
|
||||
"description": "View framework.",
|
||||
"version": "1.0.0",
|
||||
"releasenote": "Update.",
|
||||
"contributors": [
|
||||
"shmyga"
|
||||
],
|
||||
"classPath": "src/main",
|
||||
"dependencies": {
|
||||
"promhx": "1.1.0",
|
||||
"yaml": "1.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package haxework.asset;
|
||||
|
||||
import haxe.Json;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
class JsonAsset extends ByteArray {
|
||||
|
||||
public var value(default, null):Dynamic;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
value = Json.parse(readUTFBytes(bytesAvailable));
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package haxework.asset;
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
class StringAsset extends ByteArray {
|
||||
|
||||
public var value(default, null):String;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
value = readUTFBytes(bytesAvailable);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package haxework.core;
|
||||
|
||||
class Const {
|
||||
#if flash
|
||||
public static var UINT_MAX_VALUE:UInt = untyped __global__["uint"].MAX_VALUE;
|
||||
public static var UINT_MIN_VALUE:UInt = untyped __global__["uint"].MIN_VALUE;
|
||||
public static var INT_MAX_VALUE:Int = untyped __global__["int"].MAX_VALUE;
|
||||
public static var INT_MIN_VALUE:Int = untyped __global__["int"].MIN_VALUE;
|
||||
#else
|
||||
public static var UINT_MAX_VALUE:UInt = 0xffffffff;
|
||||
public static var UINT_MIN_VALUE:UInt = 0;
|
||||
public static var INT_MAX_VALUE:Int = 0xffffffff;
|
||||
public static var INT_MIN_VALUE:Int = -0xffffffff;
|
||||
#end
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package haxework.core;
|
||||
|
||||
interface IDisposable {
|
||||
public function dispose():Void;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package haxework.core;
|
||||
|
||||
import haxe.ds.ObjectMap;
|
||||
import Map.IMap;
|
||||
|
||||
class Set<T:{}> {
|
||||
|
||||
private static var O:Dynamic = {};
|
||||
|
||||
private var map:ObjectMap<T, Dynamic>;
|
||||
|
||||
public function new() {
|
||||
map = new ObjectMap<T, Dynamic>();
|
||||
}
|
||||
|
||||
public inline function iterator():Iterator<T> {
|
||||
return map.keys();
|
||||
}
|
||||
|
||||
public inline function set(value:T):Void {
|
||||
map.set(value, O);
|
||||
}
|
||||
|
||||
public inline function exists(value:T):Bool {
|
||||
return map.exists(value);
|
||||
}
|
||||
|
||||
public inline inline function remove(value:T):Bool {
|
||||
return map.remove(value);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package haxework.core;
|
||||
typedef Tuple2#if!H<T1, T2>#end = {
|
||||
var first(default, null):T1;
|
||||
var second(default, null):T2;
|
||||
}
|
||||
typedef Tuple3#if!H<T1, T2, T3>#end = {> Tuple2<T1, T2>,
|
||||
var third(default, null):T3;
|
||||
}
|
||||
typedef Tuple4#if!H<T1, T2, T3, T4>#end = {> Tuple3<T1, T2, T3>,
|
||||
var fourth(default, null):T4;
|
||||
}
|
||||
typedef Tuple5#if!H<T1, T2, T3, T4, T5>#end = {> Tuple4<T1, T2, T3, T4>,
|
||||
var fifth(default, null):T5;
|
||||
}
|
||||
|
||||
class Tuple {
|
||||
public static function five<T1, T2, T3, T4, T5>(first:T1, second:T2, third:T3, fourth:T4, fifth:T5):Tuple5<T1, T2, T3, T4, T5> {
|
||||
return new InternalTuple5(first, second, third, fourth, fifth);
|
||||
}
|
||||
|
||||
public static function four<T1, T2, T3, T4>(first:T1, second:T2, third:T3, fourth:T4):Tuple4<T1, T2, T3, T4> {
|
||||
return new InternalTuple4(first, second, third, fourth);
|
||||
}
|
||||
|
||||
public static function three<T1, T2, T3>(first:T1, second:T2, third:T3):Tuple3<T1, T2, T3> {
|
||||
return new InternalTuple3(first, second, third);
|
||||
}
|
||||
|
||||
public static function two<T1, T2>(first:T1, second:T2):Tuple2<T1, T2> {
|
||||
return new InternalTuple2(first, second);
|
||||
}
|
||||
|
||||
public static inline function asTuple2<T1, T2, T3>(tuple:Tuple3<T1, T2, T3>):Tuple2<T1, T2>
|
||||
return tuple;
|
||||
|
||||
public static inline function asTuple3<T1, T2, T3, T4>(tuple:Tuple4<T1, T2, T3, T4>):Tuple3<T1, T2, T3>
|
||||
return tuple;
|
||||
|
||||
public static inline function asTuple4<T1, T2, T3, T4, T5>(tuple:Tuple5<T1, T2, T3, T4, T5>):Tuple4<T1, T2, T3, T4>
|
||||
return tuple;
|
||||
}
|
||||
|
||||
private class InternalTuple2<T1, T2> {
|
||||
public var first(default, null):T1;
|
||||
public var second(default, null):T2;
|
||||
|
||||
/**
|
||||
* Creates a new tuple.
|
||||
* @param first The first value.
|
||||
* @param second The second value.
|
||||
*/
|
||||
|
||||
public function new(first:T1, second:T2) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return "(" + first + ", " + second + ")";
|
||||
}
|
||||
}
|
||||
private class InternalTuple3<T1, T2, T3> extends InternalTuple2<T1, T2> {
|
||||
public var third(default, null):T3;
|
||||
|
||||
/**
|
||||
* Creates a new tuple.
|
||||
* @param first The first value.
|
||||
* @param second The second value.
|
||||
* @param third The third value.
|
||||
*/
|
||||
|
||||
public function new(first:T1, second:T2, third:T3) {
|
||||
super(first, second);
|
||||
this.third = third;
|
||||
}
|
||||
|
||||
public override function toString():String {
|
||||
return "("
|
||||
+ first + ", "
|
||||
+ second + ", "
|
||||
+ third + ")";
|
||||
}
|
||||
}
|
||||
private class InternalTuple4<T1, T2, T3, T4> extends InternalTuple3<T1, T2, T3> {
|
||||
public var fourth(default, null):T4;
|
||||
|
||||
/**
|
||||
* Creates a new tuple.
|
||||
* @param first The first value.
|
||||
* @param second The second value.
|
||||
* @param third The third value.
|
||||
* @param fourth The fourth value.
|
||||
*/
|
||||
|
||||
public function new(first:T1, second:T2, third:T3, fourth:T4) {
|
||||
super(first, second, third);
|
||||
this.fourth = fourth;
|
||||
}
|
||||
|
||||
public override function toString():String {
|
||||
return "("
|
||||
+ first + ", "
|
||||
+ second + ", "
|
||||
+ third + ", "
|
||||
+ fourth + ")";
|
||||
}
|
||||
}
|
||||
private class InternalTuple5<T1, T2, T3, T4, T5> extends InternalTuple4<T1, T2, T3, T4> {
|
||||
public var fifth(default, null):T5;
|
||||
|
||||
/**
|
||||
* Creates a new tuple.
|
||||
* @param first The first value.
|
||||
* @param second The second value.
|
||||
* @param third The third value.
|
||||
* @param fourth The fourth value.
|
||||
* @param fifth The fifth value.
|
||||
*/
|
||||
|
||||
public function new(first:T1, second:T2, third:T3, fourth:T4, fifth:T5) {
|
||||
super(first, second, third, fourth);
|
||||
this.fifth = fifth;
|
||||
}
|
||||
|
||||
public override function toString():String {
|
||||
return "("
|
||||
+ first + ", "
|
||||
+ second + ", "
|
||||
+ third + ", "
|
||||
+ fourth + ", "
|
||||
+ fifth + ")";
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package haxework.dispath;
|
||||
|
||||
import haxe.ds.ObjectMap;
|
||||
|
||||
class Dispatcher<L:{}> implements IDispatcher<L> {
|
||||
|
||||
private var listeners(null, null):ObjectMap<L, Bool>;
|
||||
|
||||
public function new() {
|
||||
listeners = new ObjectMap<L, Bool>();
|
||||
}
|
||||
|
||||
public function addListener(listener:L):Void {
|
||||
listeners.set(listener, true);
|
||||
}
|
||||
|
||||
public function removeListener(listener:L):Bool {
|
||||
return listeners.remove(listener);
|
||||
}
|
||||
|
||||
public function removeAllListeners():Void {
|
||||
var i:Iterator<L> = listeners.keys();
|
||||
while (i.hasNext()) listeners.remove(i.next());
|
||||
}
|
||||
|
||||
public function dispatch(caller:L->Void):Void {
|
||||
var i:Iterator<L> = listeners.keys();
|
||||
while (i.hasNext()) caller(i.next());
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package haxework.dispath;
|
||||
|
||||
import haxe.ds.ObjectMap;
|
||||
|
||||
interface IDispatcher<L:{}> {
|
||||
|
||||
private var listeners(null, null):ObjectMap<L, Bool>;
|
||||
|
||||
public function addListener(listener:L):Void;
|
||||
public function removeListener(listener:L):Bool;
|
||||
public function removeAllListeners():Void;
|
||||
public function dispatch(caller:L->Void):Void;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package haxework.format;
|
||||
|
||||
import haxework.provider.Provider;
|
||||
import haxework.locale.ILocale;
|
||||
|
||||
class Formatter implements IFormatter {
|
||||
|
||||
public function formatDate(date:Date, format:String):String {
|
||||
var locale:ILocale = Provider.get(ILocale);
|
||||
var r:EReg = ~/\{(\w+)\}/g;
|
||||
return r.map(format, function(r:EReg):String {
|
||||
return switch(r.matched(1)) {
|
||||
case "ss": doubleDigit(date.getSeconds());
|
||||
case "nn": doubleDigit(date.getMinutes());
|
||||
case "hh": doubleDigit(date.getHours());
|
||||
case "dd": doubleDigit(date.getDate());
|
||||
case "d": Std.string(date.getDate());
|
||||
case "mm": doubleDigit(date.getMonth() + 1);
|
||||
case "yyyy": date.getFullYear() + "";
|
||||
case "month": locale.getArray("month")[date.getMonth()];
|
||||
case "Month": firstLetterUp(locale.getArray("month")[date.getMonth()]);
|
||||
case "month_r": locale.getArray("month_r")[date.getMonth()];
|
||||
case "Month_r": firstLetterUp(locale.getArray("month_r")[date.getMonth()]);
|
||||
default: r.matched(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function formatTime(time:Int):String {
|
||||
time = Math.round(time / 1000);
|
||||
var mm:Int = Math.floor(time / 60);
|
||||
var ss:Int = time - mm * 60;
|
||||
return doubleDigit(mm) + ":" + doubleDigit(ss);
|
||||
}
|
||||
|
||||
private static function doubleDigit(num:Int):String {
|
||||
return ((num < 10) ? "0" : "") + num;
|
||||
}
|
||||
|
||||
private static function firstLetterUp(s:String):String {
|
||||
return s.charAt(0).toUpperCase() + s.substring(1);
|
||||
}
|
||||
|
||||
public function formatDateFloat(date:Float, format:String):String {
|
||||
return formatDate(Date.fromTime(date), format);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package haxework.format;
|
||||
|
||||
interface IFormatter {
|
||||
public function formatDate(date:Date, format:String):String;
|
||||
public function formatDateFloat(date:Float, format:String):String;
|
||||
public function formatTime(time:Int):String;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package haxework.frame;
|
||||
|
||||
import flash.display.Sprite;
|
||||
import haxework.gui.IView;
|
||||
import haxework.gui.GroupView;
|
||||
|
||||
class FrameSwitcher extends GroupView implements IFrameSwitcher<Sprite> {
|
||||
|
||||
public var current(default, null):Null<IView<Dynamic>>;
|
||||
private var frames:Map<String, IView<Dynamic>>;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
frames = new Map<String, IView<Dynamic>>();
|
||||
current = null;
|
||||
}
|
||||
|
||||
public function change(id:String):IView<Dynamic> {
|
||||
if (current != null) {
|
||||
if (current.id == id) return current;
|
||||
var onHideethod:Dynamic = Reflect.field(current, "onHide");
|
||||
if (onHideethod != null) Reflect.callMethod(current, onHideethod, []);
|
||||
removeView(current);
|
||||
}
|
||||
current = frames.get(id);
|
||||
addView(current);
|
||||
var onShowMethod:Dynamic = Reflect.field(current, "onShow");
|
||||
if (onShowMethod != null) Reflect.callMethod(current, onShowMethod, []);
|
||||
return current;
|
||||
}
|
||||
|
||||
override public function set_views(value:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
||||
views = [];
|
||||
if (value.length > 0) {
|
||||
for (view in value) {
|
||||
view.pWidth = 100;
|
||||
view.pHeight = 100;
|
||||
frames.set(view.id, view);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package haxework.frame;
|
||||
|
||||
import haxework.gui.IView;
|
||||
|
||||
interface IFrameSwitcher<C:Content> extends IView<C> {
|
||||
public var current(default, null):Null<IView<Dynamic>>;
|
||||
public function change(id:String):IView<Dynamic>;
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxe.Timer;
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import haxework.gui.SpriteView;
|
||||
|
||||
class AnimateView extends SpriteView {
|
||||
|
||||
private var bitmap:Bitmap;
|
||||
public var frames(default, set):Array<BitmapData>;
|
||||
public var interval(default, set):Int;
|
||||
private var frame:Int;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
bitmap = new Bitmap();
|
||||
frames = [];
|
||||
frame = 0;
|
||||
interval = 200;
|
||||
content.addChild(bitmap);
|
||||
changeFrame();
|
||||
}
|
||||
|
||||
private function set_frames(value:Array<BitmapData>):Array<BitmapData> {
|
||||
if (frames != value) {
|
||||
frames = value;
|
||||
frame = 0;
|
||||
changeFrame(true);
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
|
||||
private function set_interval(value:Int):Int {
|
||||
if (interval != value) {
|
||||
interval = value;
|
||||
}
|
||||
return interval;
|
||||
}
|
||||
|
||||
private function changeFrame(?forse:Bool = false):Void {
|
||||
frame = ++frame % frames.length;
|
||||
bitmap.bitmapData = frames[frame];
|
||||
update();
|
||||
if (!forse) Timer.delay(function() changeFrame(false), interval);
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
if (contentSize && bitmap.bitmapData != null) {
|
||||
width = bitmap.bitmapData.width;
|
||||
height = bitmap.bitmapData.height;
|
||||
}
|
||||
super.update();
|
||||
bitmap.x = (width - bitmap.width) / 2;
|
||||
bitmap.y = (height - bitmap.height) / 2;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.events.MouseEvent;
|
||||
import haxework.dispath.Dispatcher;
|
||||
import haxework.dispath.IDispatcher;
|
||||
|
||||
enum ButtonState {
|
||||
UP;
|
||||
OVER;
|
||||
DOWN;
|
||||
}
|
||||
|
||||
class ButtonView extends LabelView {
|
||||
|
||||
public var disabled(default, set):Bool;
|
||||
public var state(get, null):ButtonState;
|
||||
public var dispatcher(default, null):IDispatcher<ButtonViewListener<Dynamic>>;
|
||||
public var onPress(null, set):ButtonViewListener<Dynamic>;
|
||||
|
||||
private var overed:Bool;
|
||||
private var downed:Bool;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
overed = false;
|
||||
downed = false;
|
||||
state = ButtonState.UP;
|
||||
dispatcher = new Dispatcher<ButtonViewListener<Dynamic>>();
|
||||
content.buttonMode = true;
|
||||
content.mouseChildren = false;
|
||||
content.addEventListener(MouseEvent.CLICK, onMouseClick);
|
||||
#if !mobile
|
||||
content.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
|
||||
content.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
|
||||
#end
|
||||
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
content.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
}
|
||||
|
||||
private function onMouseClick(event:MouseEvent):Void {
|
||||
event.stopImmediatePropagation();
|
||||
if (!disabled) dispatcher.dispatch(pressCaller);
|
||||
}
|
||||
|
||||
private function onMouseOver(event:MouseEvent):Void {
|
||||
overed = true;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private function onMouseOut(event:MouseEvent):Void {
|
||||
overed = false;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private function onMouseDown(event:MouseEvent):Void {
|
||||
downed = true;
|
||||
content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private function onMouseUp(event:MouseEvent):Void {
|
||||
downed = false;
|
||||
content.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private function pressCaller(listener:ButtonViewListener<Dynamic>):Void {
|
||||
try {listener.onPress(this);} catch (error:Dynamic) L.e("onPress", "", error);
|
||||
}
|
||||
|
||||
private function set_disabled(value:Bool):Bool {
|
||||
if (disabled != value) {
|
||||
disabled = value;
|
||||
content.buttonMode = !disabled;
|
||||
invalidate();
|
||||
}
|
||||
return disabled;
|
||||
}
|
||||
|
||||
private function get_state():ButtonState {
|
||||
#if mobile
|
||||
return downed ? ButtonState.DOWN : ButtonState.UP;
|
||||
#else
|
||||
return (downed && overed) ? ButtonState.DOWN : overed ? ButtonState.OVER : ButtonState.UP;
|
||||
#end
|
||||
}
|
||||
|
||||
private function set_onPress(value:ButtonViewListener<Dynamic>):ButtonViewListener<Dynamic> {
|
||||
dispatcher.addListener(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
dispatcher.removeAllListeners();
|
||||
content.removeEventListener(MouseEvent.CLICK, onMouseClick);
|
||||
content.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
|
||||
content.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
|
||||
content.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
content.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
}
|
||||
}
|
||||
|
||||
typedef ButtonViewListener<V:ButtonView> = {
|
||||
public function onPress(view:V):Void;
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.layout.DefaultLayout;
|
||||
import haxework.gui.layout.ILayout;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class GroupView extends SpriteView implements IGroupView<Sprite> {
|
||||
|
||||
public var views(default, set):Array<IView<Dynamic>>;
|
||||
public var layout(default, default):ILayout;
|
||||
|
||||
public var layoutVAlign(default, set):VAlign;
|
||||
public var layoutHAlign(default, set):HAlign;
|
||||
public var layoutMargin(default, set):Float = 0;
|
||||
|
||||
public var leftPadding(default, set):Float;
|
||||
public var rightPadding(default, set):Float;
|
||||
public var topPadding(default, set):Float;
|
||||
public var bottomPadding(default, set):Float;
|
||||
public var paddings(null, set):Float;
|
||||
|
||||
private var viewsById:Map<String, IView<Dynamic>>;
|
||||
|
||||
public function new(?layout:ILayout) {
|
||||
super();
|
||||
this.layout = layout == null ? new DefaultLayout() : layout;
|
||||
paddings = 0;
|
||||
//layoutMargin = 0;
|
||||
layoutHAlign = HAlign.CENTER;
|
||||
layoutVAlign = VAlign.MIDDLE;
|
||||
views = [];
|
||||
viewsById = new Map<String, IView<Sprite>>();
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
layout.place(this, views);
|
||||
for (view in views) {
|
||||
view.update();
|
||||
if (view.index > -1) {
|
||||
content.setChildIndex(view.content, view.index);
|
||||
}
|
||||
}
|
||||
super.update();
|
||||
}
|
||||
|
||||
public function set_views(value:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
||||
if (views == null) views = [];
|
||||
for (view in value) addView(view);
|
||||
return views;
|
||||
}
|
||||
|
||||
public function addView(view:IView<Dynamic>):IView<Dynamic> {
|
||||
views.push(view);
|
||||
viewsById.set(view.id, view);
|
||||
if (view.content != null) content.addChild(view.content);
|
||||
view.parent = this;
|
||||
invalidate();
|
||||
return view;
|
||||
}
|
||||
|
||||
public function addViewFirst(view:IView<Dynamic>):IView<Dynamic> {
|
||||
views.unshift(view);
|
||||
viewsById.set(view.id, view);
|
||||
content.addChild(view.content);
|
||||
view.parent = this;
|
||||
invalidate();
|
||||
return view;
|
||||
}
|
||||
|
||||
public function removeView(view:IView<Dynamic>):IView<Dynamic> {
|
||||
view.parent = null;
|
||||
viewsById.remove(view.id);
|
||||
views.remove(view);
|
||||
if (view.content != null) content.removeChild(view.content);
|
||||
invalidate();
|
||||
return view;
|
||||
}
|
||||
|
||||
public function removeAllViews():Void {
|
||||
while (views.length > 0) {
|
||||
removeView(views[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeViewById(id:String):IView<Dynamic> {
|
||||
if (viewsById.exists(id)) {
|
||||
return removeView(viewsById.get(id));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function findViewById<V:IView<Dynamic>>(id:String, ?clazz:Class<V>):Null<V> {
|
||||
var idd:Array<String> = id.split(":");
|
||||
if (idd.length > 1) {
|
||||
var id0 = idd.shift();
|
||||
if (viewsById.exists(id0)) {
|
||||
var g:GroupView = findViewById(id0);
|
||||
return g.findViewById(idd.join(":"), clazz);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (viewsById.exists(id)) {
|
||||
return cast viewsById.get(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function set_layoutVAlign(value:VAlign):VAlign {
|
||||
if (layoutVAlign != value) {
|
||||
layoutVAlign = value;
|
||||
invalidate();
|
||||
}
|
||||
return layoutVAlign;
|
||||
}
|
||||
|
||||
private function set_layoutHAlign(value:HAlign):HAlign {
|
||||
if (layoutHAlign != value) {
|
||||
layoutHAlign = value;
|
||||
invalidate();
|
||||
}
|
||||
return layoutHAlign;
|
||||
}
|
||||
|
||||
private function set_layoutMargin(value:Float):Float {
|
||||
if (layoutMargin != value) {
|
||||
layoutMargin = value;
|
||||
invalidate();
|
||||
}
|
||||
return layoutMargin;
|
||||
}
|
||||
|
||||
private function set_leftPadding(value:Float):Float {
|
||||
if (leftPadding != value) {
|
||||
leftPadding = value;
|
||||
invalidate();
|
||||
}
|
||||
return leftPadding;
|
||||
}
|
||||
|
||||
private function set_rightPadding(value:Float):Float {
|
||||
if (rightPadding != value) {
|
||||
rightPadding = value;
|
||||
invalidate();
|
||||
}
|
||||
return rightPadding;
|
||||
}
|
||||
|
||||
private function set_topPadding(value:Float):Float {
|
||||
if (topPadding != value) {
|
||||
topPadding = value;
|
||||
invalidate();
|
||||
}
|
||||
return topPadding;
|
||||
}
|
||||
|
||||
private function set_bottomPadding(value:Float):Float {
|
||||
if (bottomPadding != value) {
|
||||
bottomPadding = value;
|
||||
invalidate();
|
||||
}
|
||||
return bottomPadding;
|
||||
}
|
||||
|
||||
private function set_paddings(value:Float):Float {
|
||||
leftPadding = rightPadding = topPadding = bottomPadding = value;
|
||||
invalidate();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
|
||||
//ToDo:
|
||||
import flash.errors.Error;
|
||||
import openfl.Assets;
|
||||
import flash.errors.TypeError;
|
||||
import flash.errors.ArgumentError;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.gui.View;
|
||||
import haxework.gui.SpriteView;
|
||||
import haxework.gui.MovieView;
|
||||
import haxework.gui.GroupView;
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.VGroupView;
|
||||
import haxework.gui.TextView;
|
||||
import haxework.gui.InputView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.ToggleButtonView;
|
||||
import haxework.gui.ProgressView;
|
||||
import haxework.gui.AnimateView;
|
||||
import haxework.gui.skin.ColorSkin;
|
||||
import haxework.gui.skin.BitmapSkin;
|
||||
import haxework.gui.skin.ButtonColorSkin;
|
||||
import haxework.gui.skin.ButtonBitmapSkin;
|
||||
import haxework.gui.skin.ProgressSkin;
|
||||
|
||||
import haxework.frame.FrameSwitcher;
|
||||
|
||||
class GuiBuilder {
|
||||
|
||||
public static function build(data:Dynamic, ?links:Dynamic):Dynamic {
|
||||
return new GuiB(data, links, data._includes).build();
|
||||
}
|
||||
|
||||
public static function fill(object:Dynamic, data:Dynamic, ?links:Dynamic):Void {
|
||||
new GuiF(object, data, links, data._includes).fill();
|
||||
}
|
||||
}
|
||||
|
||||
class GuiB {
|
||||
|
||||
private var data:Dynamic;
|
||||
private var links:Dynamic;
|
||||
private var includes:Dynamic;
|
||||
|
||||
public function new(data:Dynamic, ?links:Dynamic, ?includes:Dynamic) {
|
||||
this.data = data;
|
||||
this.links = links;
|
||||
this.includes = includes;
|
||||
}
|
||||
|
||||
public function build():Dynamic {
|
||||
if (Reflect.hasField(data, "type")) {
|
||||
var type:String = data.type;
|
||||
//Reflect.deleteField(data, "type");
|
||||
if (type.charAt(0) == "~") return Type.resolveClass(type.substr(1));
|
||||
var object:Dynamic = instance(type);
|
||||
new GuiF(object, data, links, includes).fill();
|
||||
var initMethod:Dynamic = Reflect.field(object, "init");
|
||||
if (initMethod != null) Reflect.callMethod(object, initMethod, []);
|
||||
return object;
|
||||
} else if (Std.is(data, String)) {
|
||||
return GuiF.convertString(data, links);
|
||||
} else {
|
||||
new GuiF(data, data, links, includes).fill();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
private static function instance(type:String):Dynamic {
|
||||
var clazz:Class<Dynamic> = Type.resolveClass(type);
|
||||
if (clazz == null) throw new TypeError("Class \"" + type + "\" not found");
|
||||
var instance:Dynamic = Type.createInstance(clazz, []);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
class GuiF {
|
||||
|
||||
private var object:Dynamic;
|
||||
private var data:Dynamic;
|
||||
private var links:Dynamic;
|
||||
private var includes:Dynamic;
|
||||
|
||||
public function new(object:Dynamic, data:Dynamic, ?links:Dynamic, ?includes:Dynamic) {
|
||||
this.object = object;
|
||||
this.data = data;
|
||||
this.links = links;
|
||||
this.includes = includes;
|
||||
}
|
||||
|
||||
public static function convertString(value:Dynamic, ?links:Dynamic):Dynamic {
|
||||
var s:String = cast(value, String);
|
||||
var c:String = s.charAt(0);
|
||||
if (c == "#") {
|
||||
value = Reflect.field(links, s.substr(1));
|
||||
} else if (c == "~") {
|
||||
var a:Array<String> = s.substr(1).split(":");
|
||||
var e:Enum<Dynamic> = Type.resolveEnum(a[0]);
|
||||
value = Type.createEnum(e, a[1]);
|
||||
} else if (c == "@") {
|
||||
if (s.charAt(1) == "~") {
|
||||
var a:Array<String> = s.substr(2).split(":");
|
||||
value = Assets.getBitmapData(a[1]);
|
||||
} else {
|
||||
var a:Array<String> = s.substr(1).split(":");
|
||||
value = Reflect.field(Provider.get(IResources), a[0]).get(a[1]);
|
||||
}
|
||||
} else if (~/0x[A-Fa-f\d]{6}/.match(value)) {
|
||||
value = Std.parseInt(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public function fill() {
|
||||
var fields:Array<String> = Reflect.fields(data);
|
||||
for (field in fields) {
|
||||
if (field == "type") continue;
|
||||
if (field == "_includes") continue;
|
||||
var value:Dynamic = Reflect.field(data, field);
|
||||
if (field == "_include") {
|
||||
var data:Dynamic = includes == null ? null : Reflect.field(includes, value);
|
||||
if (data != null) {
|
||||
new GuiF(object, data, links).fill();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (Std.is(value, Array)) {
|
||||
var a:Array<Dynamic> = [];
|
||||
for (o in cast(value, Array<Dynamic>)) a.push(new GuiB(o, links, includes).build());
|
||||
value = a;
|
||||
} else if (Std.is(value, String)) {
|
||||
var s:String = cast(value, String);
|
||||
var c:String = s.charAt(0);
|
||||
if (c == "#") {
|
||||
value = Reflect.field(links, s.substr(1));
|
||||
} else if (c == "~") {
|
||||
var a:Array<String> = s.substr(1).split(":");
|
||||
var e:Enum<Dynamic> = Type.resolveEnum(a[0]);
|
||||
value = Type.createEnum(e, a[1]);
|
||||
} else if (c == "@") {
|
||||
if (s.charAt(1) == "~") {
|
||||
var a:Array<String> = s.substr(2).split(":");
|
||||
switch (a[0]) {
|
||||
case "image": Reflect.setProperty(object, field, Assets.getBitmapData(a[1]));
|
||||
}
|
||||
} else {
|
||||
var a:Array<String> = s.substr(1).split(":");
|
||||
//value = Reflect.field(Provider.get(IResources), a[0]).get(a[1]);
|
||||
Reflect.field(Provider.get(IResources), a[0]).bind(a[1], object, field);
|
||||
}
|
||||
continue;
|
||||
} else if (~/0x[A-Fa-f\d]{6}/.match(value)) {
|
||||
value = Std.parseInt(value);
|
||||
}
|
||||
} else if (Std.is(value, Float)) {
|
||||
|
||||
} else if (Std.is(value, Bool)) {
|
||||
|
||||
} else {
|
||||
var o:Dynamic = new GuiB(value, links, includes).build();
|
||||
new GuiF(o, value, links).fill();
|
||||
value = o;
|
||||
}
|
||||
try {
|
||||
Reflect.setProperty(object, field, value);
|
||||
} catch(error:Dynamic) {
|
||||
L.e("GuiBuilder", "", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.IView.Content;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.layout.ILayout;
|
||||
|
||||
interface IGroupView<C:Content> extends IView<C> {
|
||||
|
||||
public var views(default, null):Array<IView<Dynamic>>;
|
||||
public var layout(default, default):ILayout;
|
||||
|
||||
public var layoutVAlign(default, set):VAlign;
|
||||
public var layoutHAlign(default, set):HAlign;
|
||||
public var layoutMargin(default, set):Float;
|
||||
|
||||
public var leftPadding(default, set):Float;
|
||||
public var rightPadding(default, set):Float;
|
||||
public var topPadding(default, set):Float;
|
||||
public var bottomPadding(default, set):Float;
|
||||
public var paddings(null, set):Float;
|
||||
|
||||
public function addView(view:IView<Dynamic>):IView<Dynamic>;
|
||||
public function addViewFirst(view:IView<Dynamic>):IView<Dynamic>;
|
||||
public function removeView(view:IView<Dynamic>):IView<Dynamic>;
|
||||
public function removeAllViews():Void;
|
||||
public function removeViewById(id:String):IView<Dynamic>;
|
||||
public function findViewById<V:IView<Dynamic>>(id:String, ?clazz:Class<V>):Null<V>;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.IView.Content;
|
||||
import flash.text.TextFormatAlign;
|
||||
|
||||
interface ITextView<C:Content, T> extends IView<C> {
|
||||
public var textField(default, null):T;
|
||||
public var text(get, set):String;
|
||||
public var align(default, set):TextFormatAlign;
|
||||
//ToDo: font properties to object
|
||||
public var fontFamily(default, set):String;
|
||||
public var fontEmbed(default, set):Bool;
|
||||
public var fontColor(default, set):Int;
|
||||
public var fontSize(default, set):Float;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.skin.ISkin;
|
||||
import haxework.gui.core.SizeType;
|
||||
|
||||
typedef Content = {
|
||||
#if flash
|
||||
var x(default,default):Float;
|
||||
var y(default,default):Float;
|
||||
var visible(default,default):Bool;
|
||||
@:optional var mouseEnabled(default,default):Bool;
|
||||
#else
|
||||
var x(get,set):Float;
|
||||
var y(get,set):Float;
|
||||
var visible(get,set):Bool;
|
||||
@:optional var mouseEnabled(default,default):Bool;
|
||||
#end
|
||||
}
|
||||
|
||||
interface IView<C:Content> {
|
||||
public var id(default, default):String;
|
||||
|
||||
public var x(default, set):Float;
|
||||
public var y(default, set):Float;
|
||||
|
||||
public var w(default, set):Float;
|
||||
public var h(default, set):Float;
|
||||
|
||||
public var r(default, set):Float;
|
||||
|
||||
public var widthType(default, null):SizeType;
|
||||
public var heightType(default, null):SizeType;
|
||||
|
||||
public var width(get, set):Float;
|
||||
public var height(get, set):Float;
|
||||
|
||||
public var pWidth(default, set):Float;
|
||||
public var pHeight(default, set):Float;
|
||||
|
||||
public var contentSize(default, set):Bool;
|
||||
|
||||
public var hAlign(default, set):HAlign;
|
||||
public var vAlign(default, set):VAlign;
|
||||
|
||||
public var leftMargin(default, set):Float;
|
||||
public var rightMargin(default, set):Float;
|
||||
public var topMargin(default, set):Float;
|
||||
public var bottomMargin(default, set):Float;
|
||||
public var margins(null, set):Float;
|
||||
|
||||
public var content(default, null):C;
|
||||
public var skin(default, set):ISkin<C, IView<C>>;
|
||||
|
||||
public var parent(default, null):Null<IGroupView<Dynamic>>;
|
||||
public var inLayout(default, set):Bool;
|
||||
|
||||
public var visible(default, set):Bool;
|
||||
public var index(default, set):Int;
|
||||
public var mouseEnabled(default, set):Bool;
|
||||
|
||||
public function update():Void;
|
||||
public function invalidate():Void;
|
||||
|
||||
public function remove():Void;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.utils.DrawUtil.FillType;
|
||||
import haxework.gui.skin.BitmapSkin;
|
||||
import haxework.gui.skin.ButtonBitmapSkin;
|
||||
import flash.display.BitmapData;
|
||||
|
||||
class ImageView extends SpriteView {
|
||||
|
||||
public var image(default, set):BitmapData;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
skin = untyped new BitmapSkin(image, FillType.CONTAIN);
|
||||
invalidate();
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.events.Event;
|
||||
import flash.ui.Keyboard;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldType;
|
||||
import flash.events.KeyboardEvent;
|
||||
import haxe.Timer;
|
||||
import flash.events.MouseEvent;
|
||||
|
||||
class InputTextField extends TextField {
|
||||
|
||||
private var focused:Bool;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
#if flash
|
||||
type = TextFieldType.INPUT;
|
||||
#elseif html5
|
||||
addEventListener(MouseEvent.CLICK, onMouseClick);
|
||||
#end
|
||||
}
|
||||
|
||||
#if html5
|
||||
private function onMouseClick(event:MouseEvent):Void {
|
||||
focused = true;
|
||||
border = true;
|
||||
borderColor = 0x00ff00;
|
||||
Timer.delay(function() {
|
||||
stage.addEventListener(MouseEvent.CLICK, onFocusOut);
|
||||
}, 1);
|
||||
addEventListener(Event.REMOVED_FROM_STAGE, onFocusOut);
|
||||
stage.addEventListener(KeyboardEvent.KEY_UP, onStageKeyUp);
|
||||
stage.addEventListener(KeyboardEvent.KEY_DOWN, onStageKeyDown);
|
||||
}
|
||||
|
||||
private function onStageKeyDown(event:KeyboardEvent):Void {
|
||||
event.stopPropagation();
|
||||
event.stopImmediatePropagation();
|
||||
untyped __js__("window.event.preventDefault()");
|
||||
}
|
||||
|
||||
private function onStageKeyUp(event:KeyboardEvent):Void {
|
||||
event.stopPropagation();
|
||||
event.stopImmediatePropagation();
|
||||
untyped __js__("window.event.preventDefault()");
|
||||
switch (event.keyCode) {
|
||||
case Keyboard.BACKSPACE:
|
||||
text = event.ctrlKey ? "" : text.substring(0, text.length - 1);
|
||||
case x if (x >= 65 && x <= 90):
|
||||
text += String.fromCharCode(event.keyCode + (event.shiftKey ? 0 : 32));
|
||||
case x if (x >= 48 && x <= 57):
|
||||
text += String.fromCharCode(event.keyCode);
|
||||
case x if (x >= 96 && x <= 105):
|
||||
text += String.fromCharCode(event.keyCode - 48);
|
||||
}
|
||||
}
|
||||
|
||||
private function onFocusOut(_):Void {
|
||||
if (stage != null) {
|
||||
stage.removeEventListener(MouseEvent.CLICK, onFocusOut);
|
||||
stage.removeEventListener(KeyboardEvent.KEY_UP, onStageKeyUp);
|
||||
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onStageKeyDown);
|
||||
}
|
||||
focused = false;
|
||||
border = false;
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.dispath.Dispatcher;
|
||||
import haxework.dispath.IDispatcher;
|
||||
import flash.events.Event;
|
||||
import flash.text.TextFormat;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextField;
|
||||
import haxework.core.IDisposable;
|
||||
import haxework.core.Const;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.events.TextEvent;
|
||||
import flash.text.TextFieldType;
|
||||
|
||||
class InputView extends TextView implements IDisposable {
|
||||
|
||||
public var hint(default, set):String;
|
||||
public var dispatcher(default, null):IDispatcher<InputViewListener>;
|
||||
public var onKeyUp(null, set):InputViewListener;
|
||||
|
||||
private var hintTextField:TextField;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
dispatcher = new Dispatcher<InputViewListener>();
|
||||
textField.addEventListener(Event.CHANGE, onTextChange);
|
||||
textField.addEventListener(KeyboardEvent.KEY_UP, _onKeyUp);
|
||||
textField.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
|
||||
hintTextField = buildHintTextField();
|
||||
content.addChild(hintTextField);
|
||||
}
|
||||
|
||||
override private function buildTextField():TextField {
|
||||
return new InputTextField();
|
||||
}
|
||||
|
||||
private function set_hint(value:String):String {
|
||||
if (hint != value) {
|
||||
hint = value;
|
||||
invalidate();
|
||||
}
|
||||
return hint;
|
||||
}
|
||||
|
||||
private function buildHintTextField():TextField {
|
||||
var textField:TextField = new TextField();
|
||||
textField.autoSize = TextFieldAutoSize.NONE;
|
||||
textField.type = TextFieldType.DYNAMIC;
|
||||
textField.multiline = false;
|
||||
textField.defaultTextFormat = new TextFormat("Arial", 16, 0xa0a0a0);
|
||||
textField.mouseEnabled = false;
|
||||
return textField;
|
||||
}
|
||||
|
||||
private function onTextChange(event:Event):Void {
|
||||
hintTextField.visible = (textField.text == "");
|
||||
}
|
||||
|
||||
private function _onKeyUp(event:KeyboardEvent):Void {
|
||||
event.stopImmediatePropagation();
|
||||
dispatcher.dispatch(function(listener) listener.onKeyUp(textField.text));
|
||||
}
|
||||
|
||||
private function onKeyDown(event:KeyboardEvent):Void {
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var htf:TextFormat = textField.defaultTextFormat;
|
||||
htf.color = 0xa0a0a0;
|
||||
htf.size -= 2;
|
||||
hintTextField.defaultTextFormat = htf;
|
||||
hintTextField.text = hint == null ? "" : hint;
|
||||
placeTextField(hintTextField);
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
textField.removeEventListener(Event.CHANGE, onTextChange);
|
||||
textField.removeEventListener(KeyboardEvent.KEY_UP, _onKeyUp);
|
||||
textField.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
}
|
||||
|
||||
private function set_onKeyUp(value:InputViewListener):InputViewListener {
|
||||
dispatcher.addListener(value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
typedef InputViewListener = {
|
||||
public function onKeyUp(text:String):Void;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.VAlign;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
|
||||
class LabelView extends TextView {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
fill = false;
|
||||
textField.selectable = false;
|
||||
textField.wordWrap = false;
|
||||
layoutHAlign = HAlign.CENTER;
|
||||
layoutVAlign = VAlign.MIDDLE;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
class ProgressView extends SpriteView {
|
||||
|
||||
public var value(default, set):Int;
|
||||
public var max(default, set):Int;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
value = 0;
|
||||
max = 1;
|
||||
}
|
||||
|
||||
private function set_value(value:Int):Int {
|
||||
if (this.value != value) {
|
||||
this.value = value;
|
||||
invalidate();
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private function set_max(value:Int):Int {
|
||||
if (max != value) {
|
||||
max = value;
|
||||
invalidate();
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.Lib;
|
||||
import flash.display.StageAlign;
|
||||
import flash.display.StageScaleMode;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.events.Event;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class Root {
|
||||
|
||||
private var view:IView<Sprite>;
|
||||
|
||||
public function new(view:IView<Sprite>) {
|
||||
this.view = view;
|
||||
Lib.current.addChild(view.content);
|
||||
var content:DisplayObject = view.content;
|
||||
if (content.stage == null) {
|
||||
content.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
|
||||
} else {
|
||||
onAddedToStage();
|
||||
}
|
||||
View.updater.update();
|
||||
}
|
||||
|
||||
private function onAddedToStage(?_):Void {
|
||||
var content:DisplayObject = view.content;
|
||||
content.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
|
||||
content.stage.scaleMode = StageScaleMode.NO_SCALE;
|
||||
content.stage.align = StageAlign.TOP_LEFT;
|
||||
View.updater.stage = content.stage;
|
||||
|
||||
content.stage.addEventListener(Event.RESIZE, onResize);
|
||||
onResize();
|
||||
}
|
||||
|
||||
private function onResize(?_):Void {
|
||||
var content:DisplayObject = view.content;
|
||||
view.width = content.stage.stageWidth;
|
||||
view.height = content.stage.stageHeight;
|
||||
L.d("Screen", content.stage.stageWidth + "x" + content.stage.stageHeight);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class SpriteView extends View<Sprite> {
|
||||
|
||||
public function new() {
|
||||
super(new Sprite());
|
||||
}
|
||||
|
||||
/*override public function update():Void {
|
||||
super.update();
|
||||
var g:Graphics = content.graphics;
|
||||
g.lineStyle(1, 0x00ff00);
|
||||
g.drawRect(0, 0, width, height);
|
||||
g.lineStyle();
|
||||
}*/
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.geom.Point;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.VAlign;
|
||||
import flash.text.TextFormatAlign;
|
||||
import haxework.gui.skin.ISize;
|
||||
import flash.text.TextFormat;
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
|
||||
class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
||||
|
||||
public var textField(default, null):TextField;
|
||||
public var text(get, set):String;
|
||||
private var _text:String;
|
||||
public var align(default, set):TextFormatAlign;
|
||||
public var fontFamily(default, set):String;
|
||||
public var fontEmbed(default, set):Bool;
|
||||
public var fontColor(default, set):Int;
|
||||
public var fontSize(default, set):Float;
|
||||
|
||||
public var layoutHAlign(default, set):HAlign;
|
||||
public var layoutVAlign(default, set):VAlign;
|
||||
public var fill(default, set):Bool = true;
|
||||
public var paddings(default, set):Float = 0.0;
|
||||
|
||||
private var textFormat:TextFormat;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
layoutHAlign = HAlign.NONE;
|
||||
layoutVAlign = VAlign.NONE;
|
||||
textField = buildTextField();
|
||||
textField.width = 1;
|
||||
textField.height = #if html5 25 #else 1 #end;
|
||||
textField.wordWrap = true;
|
||||
textFormat = textField.defaultTextFormat;
|
||||
textFormat.font = "Arial";
|
||||
textFormat.size = 16;
|
||||
content.addChild(textField);
|
||||
}
|
||||
|
||||
private function buildTextField():TextField {
|
||||
return new TextField();
|
||||
}
|
||||
|
||||
private function set_paddings(value:Float):Float {
|
||||
if (paddings != value) {
|
||||
paddings = value;
|
||||
invalidate();
|
||||
}
|
||||
return paddings;
|
||||
}
|
||||
|
||||
private function set_fill(value:Bool):Bool {
|
||||
if (fill != value) {
|
||||
fill = value;
|
||||
invalidate();
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
private function set_layoutHAlign(value:HAlign):HAlign {
|
||||
if (layoutHAlign != value) {
|
||||
layoutHAlign = value;
|
||||
invalidate();
|
||||
}
|
||||
return layoutHAlign;
|
||||
}
|
||||
|
||||
private function set_layoutVAlign(value:VAlign):VAlign {
|
||||
if (layoutVAlign != value) {
|
||||
layoutVAlign = value;
|
||||
invalidate();
|
||||
}
|
||||
return layoutVAlign;
|
||||
}
|
||||
|
||||
private function get_text():String {
|
||||
return textField.text;
|
||||
}
|
||||
|
||||
private function set_text(value:String):String {
|
||||
if (_text != value) {
|
||||
_text = value;
|
||||
invalidate();
|
||||
}
|
||||
return _text;
|
||||
}
|
||||
|
||||
private function set_align(value:TextFormatAlign):TextFormatAlign {
|
||||
if (align != value) {
|
||||
align = value;
|
||||
#if (flash || html5)
|
||||
textFormat.align = value;
|
||||
#else
|
||||
textFormat.align = Std.string(value);
|
||||
#end
|
||||
invalidate();
|
||||
}
|
||||
return align;
|
||||
}
|
||||
|
||||
private function set_fontFamily(value:String):String {
|
||||
if (fontFamily != value) {
|
||||
fontFamily = value;
|
||||
textFormat.font = fontFamily;
|
||||
invalidate();
|
||||
}
|
||||
return fontFamily;
|
||||
}
|
||||
|
||||
private function set_fontEmbed(value:Bool):Bool {
|
||||
if (fontEmbed != value) {
|
||||
fontEmbed = value;
|
||||
invalidate();
|
||||
}
|
||||
return fontEmbed;
|
||||
}
|
||||
|
||||
private function set_fontColor(value:Int):Int {
|
||||
if (fontColor != value) {
|
||||
fontColor = value;
|
||||
textFormat.color = fontColor;
|
||||
invalidate();
|
||||
}
|
||||
return fontColor;
|
||||
}
|
||||
|
||||
private function set_fontSize(value:Float):Float {
|
||||
if (fontSize != value) {
|
||||
fontSize = value;
|
||||
textFormat.size = fontSize;
|
||||
invalidate();
|
||||
}
|
||||
return fontSize;
|
||||
}
|
||||
|
||||
private function currentText():String {
|
||||
return _text;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
textField.embedFonts = fontEmbed;
|
||||
textField.defaultTextFormat = textFormat;
|
||||
textField.autoSize = fill ? TextFieldAutoSize.NONE : TextFieldAutoSize.LEFT;
|
||||
var t:String = currentText();
|
||||
if (t != null) textField.text = t;
|
||||
if (contentSize && !Std.is(skin, ISize)) {
|
||||
width = textField.width + paddings * 2;
|
||||
height = textField.height + paddings * 2;
|
||||
textField.x = paddings;
|
||||
textField.y = paddings;
|
||||
} else {
|
||||
placeTextField(textField);
|
||||
}
|
||||
//ToDo:
|
||||
var t:Point = content.localToGlobal(new Point(textField.x, textField.y));
|
||||
t.x = Math.round(t.x);
|
||||
t.y = Math.round(t.y);
|
||||
t = content.globalToLocal(t);
|
||||
textField.x = t.x;
|
||||
textField.y = t.y;
|
||||
super.update();
|
||||
}
|
||||
|
||||
private function placeTextField(textField:TextField):Void {
|
||||
if (fill) {
|
||||
textField.width = width - paddings * 2;
|
||||
textField.height = height - paddings * 2;
|
||||
textField.x = paddings;
|
||||
textField.y = paddings;
|
||||
} else {
|
||||
textField.x = switch (layoutHAlign) {
|
||||
case HAlign.NONE: 0;
|
||||
case HAlign.LEFT: paddings;
|
||||
case HAlign.CENTER: (width - textField.width) / 2;
|
||||
case HAlign.RIGHT: width - textField.width - paddings;
|
||||
}
|
||||
textField.y = switch (layoutVAlign) {
|
||||
case VAlign.NONE: 0;
|
||||
case VAlign.TOP: paddings;
|
||||
case VAlign.MIDDLE: (height - textField.height) / 2;
|
||||
case VAlign.BOTTOM: height - textField.height - paddings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override private function set_mouseEnabled(value:Bool):Bool {
|
||||
textField.mouseEnabled = value;
|
||||
return super.set_mouseEnabled(value);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.display.Sprite;
|
||||
import haxework.gui.skin.ISkin;
|
||||
|
||||
class ToggleButtonView extends ButtonView {
|
||||
|
||||
public var on(default, set):Bool;
|
||||
public var onSkin(default, set):ISkin<Sprite, IView<Sprite>>;
|
||||
|
||||
public var onText(default, set):String;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
private function set_on(value:Bool):Bool {
|
||||
on = value;
|
||||
invalidate();
|
||||
return on;
|
||||
}
|
||||
|
||||
private function set_onSkin(value:ISkin<Sprite, IView<Sprite>>):ISkin<Sprite, IView<Sprite>> {
|
||||
onSkin = value;
|
||||
invalidate();
|
||||
return onSkin;
|
||||
}
|
||||
|
||||
override private function currentSkin():ISkin<Sprite, IView<Sprite>> {
|
||||
return on ? onSkin : skin;
|
||||
}
|
||||
|
||||
private function set_onText(value:String):String {
|
||||
if (onText != value) {
|
||||
onText = value;
|
||||
invalidate;
|
||||
}
|
||||
return onText;
|
||||
}
|
||||
|
||||
override private function currentText():String {
|
||||
return on && onText != null ? onText : super.currentText();
|
||||
}
|
||||
}
|
||||
@@ -1,335 +0,0 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.IView.Content;
|
||||
import haxework.gui.skin.ISize;
|
||||
import haxework.gui.core.SizeType;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.VAlign;
|
||||
import flash.events.Event;
|
||||
import flash.display.Stage;
|
||||
import haxework.gui.skin.FakeSkin;
|
||||
import haxework.gui.skin.ISkin;
|
||||
|
||||
import flash.display.Sprite;
|
||||
|
||||
class View<C:Content> implements IView<C> {
|
||||
|
||||
private static var counter:Int = 0;
|
||||
public static var updater(default, null):Updater = new Updater();
|
||||
|
||||
public var id(default, default):String;
|
||||
|
||||
public var x(default, set):Float;
|
||||
public var y(default, set):Float;
|
||||
|
||||
public var w(default, set):Float;
|
||||
public var h(default, set):Float;
|
||||
|
||||
public var r(default, set):Float;
|
||||
|
||||
public var widthType(default, null):SizeType;
|
||||
public var heightType(default, null):SizeType;
|
||||
|
||||
public var width(get, set):Float;
|
||||
public var height(get, set):Float;
|
||||
|
||||
public var pWidth(default, set):Float;
|
||||
public var pHeight(default, set):Float;
|
||||
|
||||
public var contentSize(default, set):Bool;
|
||||
|
||||
public var hAlign(default, set):HAlign;
|
||||
public var vAlign(default, set):VAlign;
|
||||
|
||||
public var leftMargin(default, set):Float;
|
||||
public var rightMargin(default, set):Float;
|
||||
public var topMargin(default, set):Float;
|
||||
public var bottomMargin(default, set):Float;
|
||||
public var margins(null, set):Float;
|
||||
|
||||
public var content(default, null):C;
|
||||
public var skin(default, set):ISkin<C, IView<C>>;
|
||||
|
||||
public var parent(default, null):Null<IGroupView<Dynamic>>;
|
||||
public var inLayout(default, set):Bool;
|
||||
|
||||
public var visible(default, set):Bool;
|
||||
public var index(default, set):Int;
|
||||
public var mouseEnabled(default, set):Bool = true;
|
||||
|
||||
public function new(content:C) {
|
||||
id = Type.getClassName(Type.getClass(this)) + counter++;
|
||||
this.content = content;
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = 1;
|
||||
height = 1;
|
||||
margins = 0;
|
||||
vAlign = VAlign.NONE;
|
||||
hAlign = HAlign.NONE;
|
||||
inLayout = true;
|
||||
visible = true;
|
||||
index = -1;
|
||||
}
|
||||
|
||||
private function currentSkin():ISkin<C, IView<C>> {
|
||||
return skin;
|
||||
}
|
||||
|
||||
public function invalidate():Void {
|
||||
updater.invalidate(this);
|
||||
}
|
||||
|
||||
private function invalidateParent():Void {
|
||||
if (parent != null)
|
||||
updater.invalidate(parent);
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
if (content != null) {
|
||||
content.x = x;
|
||||
content.y = y;
|
||||
}
|
||||
var skin:ISkin<C, IView<C>> = currentSkin();
|
||||
if (contentSize && skin != null && Std.is(skin, ISize)) {
|
||||
var size:ISize = cast(skin, ISize);
|
||||
if (!Math.isNaN(size.width)) width = size.width;
|
||||
if (!Math.isNaN(size.height)) height = size.height;
|
||||
}
|
||||
if (skin != null) skin.draw(this);
|
||||
}
|
||||
|
||||
public function remove():Void {
|
||||
if (parent != null) parent.removeView(this);
|
||||
}
|
||||
|
||||
private function set_x(value:Float):Float {
|
||||
if (x != value) {
|
||||
x = value;
|
||||
invalidate();
|
||||
}
|
||||
return x;
|
||||
}
|
||||
private function set_y(value:Float):Float {
|
||||
if (y != value) {
|
||||
y = value;
|
||||
invalidate();
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
private function set_w(value:Float):Float {
|
||||
if (w != value) {
|
||||
w = value;
|
||||
if (!Math.isNaN(r) && r > 0) h = w / r;
|
||||
invalidate();
|
||||
}
|
||||
return w;
|
||||
}
|
||||
private function set_h(value:Float):Float {
|
||||
if (h != value) {
|
||||
h = value;
|
||||
if (!Math.isNaN(r) && r > 0) w = h * r;
|
||||
invalidate();
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
private function set_r(value:Float):Float {
|
||||
if (r != value) {
|
||||
r = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private function get_width():Float {
|
||||
return w;
|
||||
}
|
||||
|
||||
private function get_height():Float {
|
||||
return h;
|
||||
}
|
||||
|
||||
private function set_width(value:Float):Float {
|
||||
if (w != value || widthType != SizeType.NORMAL) {
|
||||
w = value;
|
||||
widthType = SizeType.NORMAL;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
private function set_height(value:Float):Float {
|
||||
if (h != value || heightType != SizeType.NORMAL) {
|
||||
h = value;
|
||||
heightType = SizeType.NORMAL;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
private function set_pWidth(value:Float):Float {
|
||||
if (pWidth != value || widthType != SizeType.PERCENT) {
|
||||
pWidth = value;
|
||||
widthType = SizeType.PERCENT;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return pWidth;
|
||||
}
|
||||
|
||||
private function set_pHeight(value:Float):Float {
|
||||
if (pHeight != value || heightType != SizeType.PERCENT) {
|
||||
pHeight = value;
|
||||
heightType = SizeType.PERCENT;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return pHeight;
|
||||
}
|
||||
|
||||
private function set_contentSize(value:Bool):Bool {
|
||||
if (contentSize != value) {
|
||||
contentSize = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return contentSize;
|
||||
}
|
||||
|
||||
private function set_hAlign(value:HAlign):HAlign {
|
||||
if (hAlign != value) {
|
||||
hAlign = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return hAlign;
|
||||
}
|
||||
|
||||
private function set_vAlign(value:VAlign):VAlign {
|
||||
if (vAlign != value) {
|
||||
vAlign = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return vAlign;
|
||||
}
|
||||
|
||||
private function set_leftMargin(value:Float):Float {
|
||||
if (leftMargin != value) {
|
||||
leftMargin = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return leftMargin;
|
||||
}
|
||||
|
||||
private function set_rightMargin(value:Float):Float {
|
||||
if (rightMargin != value) {
|
||||
rightMargin = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return rightMargin;
|
||||
}
|
||||
|
||||
private function set_topMargin(value:Float):Float {
|
||||
if (topMargin != value) {
|
||||
topMargin = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return topMargin;
|
||||
}
|
||||
|
||||
private function set_bottomMargin(value:Float):Float {
|
||||
if (bottomMargin != value) {
|
||||
bottomMargin = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
}
|
||||
return bottomMargin;
|
||||
}
|
||||
|
||||
private function set_margins(value:Float):Float {
|
||||
leftMargin = rightMargin = topMargin = bottomMargin = value;
|
||||
invalidate();
|
||||
invalidateParent();
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_skin(value:ISkin<C, IView<C>>):ISkin<C, IView<C>> {
|
||||
skin = value;
|
||||
invalidate();
|
||||
return skin;
|
||||
}
|
||||
|
||||
private function set_inLayout(value:Bool):Bool {
|
||||
if (inLayout != value) {
|
||||
inLayout = value;
|
||||
invalidateParent();
|
||||
}
|
||||
return inLayout;
|
||||
}
|
||||
|
||||
private function set_visible(value:Bool):Bool {
|
||||
if (visible != value) {
|
||||
visible = value;
|
||||
if (content != null) content.visible = visible;
|
||||
}
|
||||
return visible;
|
||||
}
|
||||
|
||||
private function set_index(value:Int):Int {
|
||||
if (index != value) {
|
||||
index = value;
|
||||
invalidateParent();
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private function set_mouseEnabled(value:Bool):Bool {
|
||||
if (mouseEnabled != value) {
|
||||
mouseEnabled = value;
|
||||
if (content != null) content.mouseEnabled = mouseEnabled;
|
||||
}
|
||||
return mouseEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Updater {
|
||||
|
||||
public var stage(null, set):Stage;
|
||||
private var invalidated:Array<IView<Dynamic>>;
|
||||
|
||||
public function new() {
|
||||
invalidated = [];
|
||||
}
|
||||
|
||||
private function set_stage(value:Stage):Stage {
|
||||
value.addEventListener(Event.ENTER_FRAME, update);
|
||||
return value;
|
||||
}
|
||||
|
||||
public function invalidate(view:IView<Dynamic>):Void {
|
||||
if (Lambda.indexOf(invalidated, view) == -1) invalidated.push(view);
|
||||
}
|
||||
|
||||
public function update(?_):Void {
|
||||
while (invalidated.length > 0) {
|
||||
var v = null;
|
||||
try {
|
||||
v = invalidated.shift();
|
||||
v.update();
|
||||
} catch (error:Dynamic) {
|
||||
L.e("Update", v + "", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package haxework.gui.core;
|
||||
|
||||
enum Direction {
|
||||
HORIZONTAL;
|
||||
VERTICAL;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package haxework.gui.core;
|
||||
|
||||
@:fakeEnum(String) enum HAlign {
|
||||
NONE;
|
||||
LEFT;
|
||||
CENTER;
|
||||
RIGHT;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package haxework.gui.core;
|
||||
|
||||
enum SizeType {
|
||||
NORMAL;
|
||||
PERCENT;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package haxework.gui.core;
|
||||
|
||||
@:fakeEnum(String) enum VAlign {
|
||||
NONE;
|
||||
TOP;
|
||||
MIDDLE;
|
||||
BOTTOM;
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package haxework.gui.layout;
|
||||
|
||||
import haxework.gui.core.SizeType;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.core.HAlign;
|
||||
|
||||
class DefaultLayout implements ILayout {
|
||||
|
||||
public function new() {
|
||||
|
||||
}
|
||||
|
||||
public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
for (view in views) {
|
||||
setViewWidth(group, view);
|
||||
setViewHeight(group, view);
|
||||
placeViewHorizontal(group, view);
|
||||
placeViewVertical(group, view);
|
||||
}
|
||||
}
|
||||
|
||||
private function filterViews(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
||||
return Lambda.array(Lambda.filter(views, function(view:IView<Dynamic>):Bool {
|
||||
return if (view.inLayout) {
|
||||
true;
|
||||
} else {
|
||||
setViewWidth(group, view);
|
||||
setViewHeight(group, view);
|
||||
placeViewHorizontal(group, view);
|
||||
placeViewVertical(group, view);
|
||||
false;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private function setViewWidth(group:IGroupView<Dynamic>, view:IView<Dynamic>):Void {
|
||||
if (view.widthType == SizeType.PERCENT) {
|
||||
view.w = view.pWidth / 100 * (group.width - view.leftMargin - view.rightMargin - group.leftPadding - group.rightPadding);
|
||||
} else if (group.contentSize && group.width < view.width) {
|
||||
group.width = view.width;
|
||||
}
|
||||
}
|
||||
|
||||
private function setViewHeight(group:IGroupView<Dynamic>, view:IView<Dynamic>):Void {
|
||||
if (view.heightType == SizeType.PERCENT) {
|
||||
view.h = view.pHeight / 100 * (group.height - view.topMargin - view.bottomMargin - group.topPadding - group.bottomPadding);
|
||||
} else if (group.contentSize && group.height < view.height) {
|
||||
group.height = view.height;
|
||||
}
|
||||
}
|
||||
|
||||
private function placeViewHorizontal(group:IGroupView<Dynamic>, view:IView<Dynamic>):Void {
|
||||
var align:HAlign = view.hAlign;
|
||||
if (align == HAlign.NONE) align = group.layoutHAlign;
|
||||
switch (align) {
|
||||
case HAlign.LEFT:
|
||||
view.x = group.leftPadding + view.leftMargin;
|
||||
case HAlign.CENTER:
|
||||
view.x = (group.width - view.width) / 2 + (group.leftPadding - group.rightPadding) + (view.leftMargin - view.rightMargin);
|
||||
case HAlign.RIGHT:
|
||||
view.x = group.width - view.width - group.rightPadding - view.rightMargin;
|
||||
case HAlign.NONE:
|
||||
}
|
||||
}
|
||||
|
||||
private function placeViewVertical(group:IGroupView<Dynamic>, view:IView<Dynamic>):Void {
|
||||
var align:VAlign = view.vAlign;
|
||||
if (align == VAlign.NONE) align = group.layoutVAlign;
|
||||
switch (align) {
|
||||
case VAlign.TOP:
|
||||
view.y = group.topPadding + view.topMargin;
|
||||
case VAlign.MIDDLE:
|
||||
view.y = (group.height - view.height) / 2 + (group.topPadding - group.bottomPadding) + (view.topMargin - view.bottomMargin);
|
||||
case VAlign.BOTTOM:
|
||||
view.y = group.height - view.height - group.bottomPadding - view.bottomMargin;
|
||||
case VAlign.NONE:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package haxework.gui.layout;
|
||||
|
||||
import haxework.core.Tuple;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.SizeType;
|
||||
|
||||
class HorizontalLayout extends DefaultLayout {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
override public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
views = filterViews(group, views);
|
||||
|
||||
var fixedSize:Float = group.layoutMargin * (views.length - 1);
|
||||
var leftSize:Float = group.width - group.leftPadding - group.rightPadding;
|
||||
var maxHeight:Float = 0;
|
||||
|
||||
for (view in views) {
|
||||
switch (view.widthType) {
|
||||
case SizeType.NORMAL: fixedSize += (view.width + view.leftMargin + view.rightMargin);
|
||||
case SizeType.PERCENT: leftSize -= (view.leftMargin + view.rightMargin);
|
||||
}
|
||||
setViewHeight(group, view);
|
||||
placeViewVertical(group, view);
|
||||
maxHeight = Math.max(maxHeight, view.height);
|
||||
}
|
||||
|
||||
if (group.contentSize) {
|
||||
group.width = Math.max(group.width, fixedSize + group.leftPadding + group.rightPadding);
|
||||
group.height = maxHeight + group.topPadding + group.bottomPadding;
|
||||
}
|
||||
|
||||
leftSize -= fixedSize;
|
||||
for (view in views) {
|
||||
if (view.widthType == SizeType.PERCENT) {
|
||||
view.w = view.pWidth / 100 * leftSize;
|
||||
fixedSize += view.width + view.leftMargin + view.rightMargin;
|
||||
}
|
||||
}
|
||||
|
||||
var x:Float = 0;
|
||||
switch (group.layoutHAlign) {
|
||||
case HAlign.LEFT: x = group.leftPadding;
|
||||
case HAlign.CENTER: x = (group.width - fixedSize) / 2 + group.leftPadding - group.rightPadding;
|
||||
case HAlign.RIGHT: x = group.width - fixedSize - group.rightPadding;
|
||||
}
|
||||
|
||||
for (view in views) {
|
||||
view.x = x + view.leftMargin;
|
||||
x += (view.width + view.leftMargin + view.rightMargin + group.layoutMargin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package haxework.gui.layout;
|
||||
|
||||
interface ILayout {
|
||||
public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package haxework.gui.layout;
|
||||
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.core.SizeType;
|
||||
|
||||
class VerticalLayout extends DefaultLayout {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
override public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
views = filterViews(group, views);
|
||||
|
||||
var fixedSize:Float = group.layoutMargin * (views.length - 1);
|
||||
var leftSize:Float = group.height - group.topPadding - group.bottomPadding;
|
||||
var maxWidth:Float = 0;
|
||||
|
||||
for (view in views) {
|
||||
switch (view.heightType) {
|
||||
case SizeType.NORMAL: fixedSize += (view.height + view.topMargin + view.bottomMargin);
|
||||
case SizeType.PERCENT: leftSize -= (view.topMargin + view.bottomMargin);
|
||||
}
|
||||
setViewWidth(group, view);
|
||||
placeViewHorizontal(group, view);
|
||||
maxWidth = Math.max(maxWidth, view.width);
|
||||
}
|
||||
|
||||
if (group.contentSize) {
|
||||
group.width = maxWidth + group.leftPadding + group.rightPadding;
|
||||
group.height = Math.max(group.height, fixedSize + group.topPadding + group.bottomPadding);
|
||||
}
|
||||
|
||||
leftSize -= fixedSize;
|
||||
for (view in views) {
|
||||
if (view.heightType == SizeType.PERCENT) {
|
||||
view.h = view.pHeight / 100 * leftSize;
|
||||
fixedSize += view.height + view.topMargin + view.bottomMargin;
|
||||
}
|
||||
}
|
||||
|
||||
var y:Float = 0;
|
||||
switch (group.layoutVAlign) {
|
||||
case VAlign.TOP: y = group.topPadding;
|
||||
case VAlign.MIDDLE: y = (group.height - fixedSize) / 2 + group.topPadding - group.bottomPadding;
|
||||
case VAlign.BOTTOM: y = group.height - fixedSize - group.bottomPadding;
|
||||
}
|
||||
|
||||
for (view in views) {
|
||||
view.y = y + view.topMargin;
|
||||
y += (view.height + view.topMargin + view.bottomMargin + group.layoutMargin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.list.ListView.IListItemView;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.layout.VerticalLayout;
|
||||
import haxework.gui.list.HScrollView;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.layout.HorizontalLayout;
|
||||
|
||||
class HListView<D> extends ListView<D> {
|
||||
|
||||
public function new() {
|
||||
super(new HorizontalLayout(), new VerticalLayout());
|
||||
container.layoutHAlign = HAlign.LEFT;
|
||||
container.layoutVAlign = VAlign.MIDDLE;
|
||||
}
|
||||
|
||||
override private function recalcSize(item:IListItemView<D>):Void {
|
||||
var view:IView<Dynamic> = item;
|
||||
itemSize = view.width + view.leftMargin + view.rightMargin + container.layoutMargin;
|
||||
size = Math.ceil(Math.max(0, container.width / itemSize)) + 2;
|
||||
sizeDiff = size - ((container.width - container.layoutMargin - 1) / itemSize);
|
||||
}
|
||||
|
||||
override private function set_offsetDiff(value:Float):Float {
|
||||
container.leftPadding = -value * itemSize;
|
||||
mask.leftMargin = -container.leftPadding;
|
||||
return super.set_offsetDiff(value);
|
||||
}
|
||||
|
||||
override private function onMouseWheel(value:Int):Void {
|
||||
offset = offset + value;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.skin.ISkin;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
|
||||
class HScrollSkin implements ISkin<Sprite, ScrollView> {
|
||||
|
||||
public var foreColor(default, default):Int;
|
||||
public var backColor(default, default):Int;
|
||||
|
||||
public function new(?foreColor:Int = 0xffffff, ?backColor:Int = 0x707070) {
|
||||
this.foreColor = foreColor;
|
||||
this.backColor = backColor;
|
||||
}
|
||||
|
||||
public function draw(view:ScrollView):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(backColor);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(foreColor);
|
||||
graphics.drawRect(view.width * view.position, 0, view.width * view.ratio, view.height);
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.list.ScrollView.ScrollListener;
|
||||
import flash.geom.Point;
|
||||
import haxework.gui.list.HScrollSkin;
|
||||
|
||||
class HScrollView extends ScrollView {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
override private function onMouseDown(p:Point):Void {
|
||||
mousePosition = p.x - width * position;
|
||||
}
|
||||
|
||||
override private function onMouseMove(p:Point):Void {
|
||||
position = (p.x - mousePosition) / width;
|
||||
dispatcher.dispatch(function(listener:ScrollListener):Void {
|
||||
listener.onScroll(position);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.skin.ColorSkin;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.layout.ILayout;
|
||||
import haxework.utils.NumberUtil;
|
||||
import haxework.dispath.Dispatcher;
|
||||
import haxework.dispath.IDispatcher;
|
||||
import haxework.gui.list.ScrollView.ScrollListener;
|
||||
import flash.events.MouseEvent;
|
||||
import haxework.gui.core.HAlign;
|
||||
import flash.display.Sprite;
|
||||
import haxework.gui.skin.ISkin;
|
||||
|
||||
class ListView<D> extends GroupView implements ScrollListener {
|
||||
|
||||
public var data(default, set):Array<D>;
|
||||
public var factory(null, default):Class<IListItemView<D>>;
|
||||
|
||||
public var offset(default, set):Int;
|
||||
private var offsetDiff(default, set):Float;
|
||||
|
||||
private var size(default, set):Int;
|
||||
private var sizeDiff:Float;
|
||||
|
||||
public var dispatcher(default, null):IDispatcher<ListViewListener<D>>;
|
||||
public var scroll(default, set):ScrollView;
|
||||
|
||||
public var prev(default, set):ButtonView;
|
||||
public var next(default, set):ButtonView;
|
||||
|
||||
public var filter(default, set):D->Bool;
|
||||
private var filteredData:Array<D>;
|
||||
|
||||
public var selected(default, set):Array<D>;
|
||||
|
||||
private var main:GroupView;
|
||||
private var container:GroupView;
|
||||
private var mask:SpriteView;
|
||||
private var itemSize:Float;
|
||||
|
||||
private var items:Array<IListItemView<D>>;
|
||||
private var itemsListeners:Map<IListItemView<D>, MouseEvent->Void>;
|
||||
|
||||
public function new(layout:ILayout, otherLayout:ILayout) {
|
||||
super(otherLayout);
|
||||
main = new GroupView(layout);
|
||||
main.layoutHAlign = HAlign.CENTER;
|
||||
main.layoutVAlign = VAlign.MIDDLE;
|
||||
main.pWidth = 100;
|
||||
main.pHeight = 100;
|
||||
addView(main);
|
||||
container = new GroupView(layout);
|
||||
container.pWidth = 100;
|
||||
container.pHeight = 100;
|
||||
main.addView(container);
|
||||
mask = new SpriteView();
|
||||
mask.pWidth = 100;
|
||||
mask.pHeight = 100;
|
||||
mask.inLayout = false;
|
||||
mask.skin = new ColorSkin(0xffffff);
|
||||
container.content.mask = mask.content;
|
||||
container.addView(mask);
|
||||
dispatcher = new Dispatcher<ListViewListener<D>>();
|
||||
itemSize = 0;
|
||||
offset = 0;
|
||||
offsetDiff = 0;
|
||||
sizeDiff = 0;
|
||||
items = [];
|
||||
itemsListeners = new Map<IListItemView<D>, MouseEvent->Void>();
|
||||
selected = [];
|
||||
content.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheelEvent);
|
||||
}
|
||||
|
||||
private function set_scroll(value:ScrollView):ScrollView {
|
||||
if (scroll != null) {
|
||||
scroll.dispatcher.removeListener(this);
|
||||
removeView(scroll);
|
||||
}
|
||||
scroll = value;
|
||||
if (scroll != null) {
|
||||
scroll.dispatcher.addListener(this);
|
||||
addView(scroll);
|
||||
}
|
||||
invalidate();
|
||||
return scroll;
|
||||
}
|
||||
|
||||
private function set_prev(value:ButtonView):ButtonView {
|
||||
if (prev != null) {
|
||||
main.removeView(prev);
|
||||
prev.dispose();
|
||||
}
|
||||
prev = value;
|
||||
prev.onPress = {onPress:onPrevPress};
|
||||
main.addViewFirst(prev);
|
||||
return prev;
|
||||
}
|
||||
|
||||
private function onPrevPress(_):Void {
|
||||
offset = offset - 1;
|
||||
}
|
||||
|
||||
private function set_next(value:ButtonView):ButtonView {
|
||||
if (next != null) {
|
||||
main.removeView(next);
|
||||
next.dispose();
|
||||
}
|
||||
next = value;
|
||||
next.onPress = {onPress:onNextPress};
|
||||
main.addView(next);
|
||||
return next;
|
||||
}
|
||||
|
||||
private function onNextPress(_):Void {
|
||||
offset = offset + 1;
|
||||
}
|
||||
|
||||
public function onScroll(position:Float):Void {
|
||||
var x:Float = filteredData.length * position;
|
||||
var o:Int = Math.floor(x);
|
||||
offsetDiff = (x - o);
|
||||
offset = o;
|
||||
}
|
||||
|
||||
private function onMouseWheelEvent(event:MouseEvent):Void {
|
||||
#if flash event.preventDefault(); #end
|
||||
onMouseWheel(event.delta);
|
||||
}
|
||||
|
||||
private function onMouseWheel(value:Int):Void {}
|
||||
|
||||
private function set_offset(value:Int):Int {
|
||||
value = NumberUtil.limitInt(value, 0, filteredData == null ? 0 : filteredData.length - size + 2);
|
||||
if (offset != value) {
|
||||
if (filteredData != null) {
|
||||
//ToDo: constant for 2
|
||||
if (value == 0) offsetDiff = 0;
|
||||
if (value == filteredData.length - size + 2) offsetDiff = sizeDiff - 2;
|
||||
}
|
||||
offset = value;
|
||||
render();
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
private function set_data(value:Array<D>):Array<D> {
|
||||
data = value;
|
||||
render();
|
||||
return data;
|
||||
}
|
||||
|
||||
private function set_filter(value:D->Bool):D->Bool {
|
||||
if (filter != value) {
|
||||
filter = value;
|
||||
render();
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
private function set_selected(value:Array<D>):Array<D> {
|
||||
if (selected != value) {
|
||||
selected = value;
|
||||
invalidate();
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
public function render():Void {
|
||||
if (data != null && factory != null) {
|
||||
filteredData = filter == null ? data : data.filter(filter);
|
||||
scroll.ratio = Math.min(1.0, (size - sizeDiff) / filteredData.length);
|
||||
scroll.position = ((offset + offsetDiff) / filteredData.length);
|
||||
for (i in 0...size) {
|
||||
var item:IListItemView<D> = items[i];
|
||||
var index = offset + i;
|
||||
if (filteredData[index] == null) {
|
||||
item.visible = false;
|
||||
} else {
|
||||
item.visible = true;
|
||||
item.item_index = index;
|
||||
item.data = filteredData[item.item_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
recalcSize(Type.createInstance(factory, []));
|
||||
render();
|
||||
}
|
||||
|
||||
private function recalcSize(item:IListItemView<D>):Void {}
|
||||
|
||||
private function set_size(value:Int):Int {
|
||||
if (size != value) {
|
||||
size = value;
|
||||
var diff:Int = size - items.length;
|
||||
if (diff > 0) {
|
||||
for (i in 0...diff) {
|
||||
var item:IListItemView<D> = Type.createInstance(factory, []);
|
||||
items.push(item);
|
||||
setClickListener(item);
|
||||
container.addView(item);
|
||||
}
|
||||
} else if (diff < 0) {
|
||||
for (i in 0...-diff) {
|
||||
var item:IListItemView<D> = items.pop();
|
||||
item.content.removeEventListener(MouseEvent.CLICK, itemsListeners.get(item));
|
||||
itemsListeners.remove(item);
|
||||
container.removeView(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
private function set_offsetDiff(value:Float):Float {
|
||||
offsetDiff = value;
|
||||
return offsetDiff;
|
||||
}
|
||||
|
||||
private function setClickListener(item:IListItemView<D>):Void {
|
||||
var listener:MouseEvent->Void = function(event:MouseEvent):Void {
|
||||
dispatcher.dispatch(function(listener:ListViewListener<D>):Void {
|
||||
listener.onListItemClick(item);
|
||||
});
|
||||
}
|
||||
item.content.addEventListener(MouseEvent.CLICK, listener);
|
||||
itemsListeners.set(item, listener);
|
||||
}
|
||||
|
||||
override private function set_layoutMargin(value:Float):Float {
|
||||
return container.layoutMargin = value;
|
||||
}
|
||||
}
|
||||
|
||||
interface IListItemView<D> extends IView<Sprite> {
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):D;
|
||||
}
|
||||
|
||||
interface ListViewListener<D> {
|
||||
public function onListItemClick(item:IListItemView<D>):Void;
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.utils.NumberUtil;
|
||||
import flash.geom.Point;
|
||||
import haxework.dispath.Dispatcher;
|
||||
import haxework.dispath.IDispatcher;
|
||||
import flash.events.MouseEvent;
|
||||
|
||||
class ScrollView extends SpriteView {
|
||||
|
||||
public var position(default, set):Float;
|
||||
public var ratio(default, set):Float;
|
||||
|
||||
public var dispatcher(default, null):IDispatcher<ScrollListener>;
|
||||
|
||||
private var mousePosition:Float;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
content.buttonMode = true;
|
||||
position = 0;
|
||||
ratio = 1;
|
||||
dispatcher = new Dispatcher<ScrollListener>();
|
||||
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownEvent);
|
||||
}
|
||||
|
||||
private function onMouseDownEvent(event:MouseEvent):Void {
|
||||
content.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveEvent);
|
||||
content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpEvent);
|
||||
var p:Point = content.globalToLocal(new Point(event.stageX, event.stageY));
|
||||
onMouseDown(p);
|
||||
}
|
||||
|
||||
private function onMouseMoveEvent(event:MouseEvent):Void {
|
||||
var p:Point = content.globalToLocal(new Point(event.stageX, event.stageY));
|
||||
onMouseMove(p);
|
||||
}
|
||||
|
||||
private function onMouseUpEvent(event:MouseEvent):Void {
|
||||
content.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveEvent);
|
||||
content.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpEvent);
|
||||
}
|
||||
|
||||
private function onMouseDown(p:Point):Void {}
|
||||
|
||||
private function onMouseMove(p:Point):Void {}
|
||||
|
||||
private function set_position(value:Float):Float {
|
||||
value = NumberUtil.limitFloat(value, 0, 1 - ratio);
|
||||
if (position != value) {
|
||||
position = value;
|
||||
invalidate();
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
private function set_ratio(value:Float):Float {
|
||||
if (ratio != value) {
|
||||
ratio = value;
|
||||
invalidate();
|
||||
}
|
||||
return ratio;
|
||||
}
|
||||
}
|
||||
|
||||
interface ScrollListener {
|
||||
public function onScroll(position:Float):Void;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.list.ListView.IListItemView;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.layout.VerticalLayout;
|
||||
import haxework.gui.list.VScrollView;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.layout.HorizontalLayout;
|
||||
|
||||
class VListView<D> extends ListView<D> {
|
||||
|
||||
public function new() {
|
||||
super(new VerticalLayout(), new HorizontalLayout());
|
||||
container.layoutHAlign = HAlign.CENTER;
|
||||
container.layoutVAlign = VAlign.TOP;
|
||||
}
|
||||
|
||||
override private function recalcSize(item:IListItemView<D>):Void {
|
||||
var view:IView<Dynamic> = item;
|
||||
itemSize = view.height + view.topMargin + view.bottomMargin + container.layoutMargin;
|
||||
size = Math.ceil(Math.max(0, container.height / itemSize)) + 2;
|
||||
sizeDiff = size - ((container.height - container.layoutMargin - 1) / itemSize);
|
||||
}
|
||||
|
||||
override private function set_offsetDiff(value:Float):Float {
|
||||
container.topPadding = -value * itemSize;
|
||||
mask.topMargin = -container.topPadding;
|
||||
return super.set_offsetDiff(value);
|
||||
}
|
||||
|
||||
override private function onMouseWheel(value:Int):Void {
|
||||
offset = offset - value;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.skin.ISkin;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
|
||||
class VScrollSkin implements ISkin<Sprite, ScrollView> {
|
||||
|
||||
public var foreColor(default, default):Int;
|
||||
public var backColor(default, default):Int;
|
||||
|
||||
public function new(?foreColor:Int = 0xffffff, ?backColor:Int = 0x707070) {
|
||||
this.foreColor = foreColor;
|
||||
this.backColor = backColor;
|
||||
}
|
||||
|
||||
public function draw(view:ScrollView):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(backColor);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(foreColor);
|
||||
graphics.drawRect(0, view.height * view.position, view.width, view.height * view.ratio);
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.list.ScrollView.ScrollListener;
|
||||
import flash.geom.Point;
|
||||
import haxework.gui.list.VScrollSkin;
|
||||
|
||||
class VScrollView extends ScrollView {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
override private function onMouseDown(p:Point):Void {
|
||||
mousePosition = p.y - height * position;
|
||||
}
|
||||
|
||||
override private function onMouseMove(p:Point):Void {
|
||||
position = (p.y - mousePosition) / height;
|
||||
dispatcher.dispatch(function(listener:ScrollListener):Void {
|
||||
listener.onScroll(position);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
import flash.geom.Rectangle;
|
||||
import flash.geom.Matrix;
|
||||
import flash.display.BitmapData;
|
||||
import haxework.gui.utils.ColorUtils;
|
||||
import haxework.gui.utils.DrawUtil;
|
||||
import haxework.gui.ButtonView.ButtonState;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class BitmapSkin implements ISkin<Sprite, SpriteView> implements ISize {
|
||||
|
||||
public var width(default, null):Float;
|
||||
public var height(default, null):Float;
|
||||
|
||||
public var image(null, set):BitmapData;
|
||||
public var color(default, default):Int;
|
||||
public var fillType(default, default):FillType;
|
||||
|
||||
public function new(?image:BitmapData = null, ?fillType = null, ?color = -1) {
|
||||
if (image != null) {
|
||||
this.image = image;
|
||||
}
|
||||
this.fillType = fillType;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
width = image.width;
|
||||
height = image.height;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public function draw(view:SpriteView):Void {
|
||||
if (image == null) return;
|
||||
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
import haxework.gui.utils.BitmapUtil;
|
||||
import haxework.gui.utils.DrawUtil;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.display.BitmapData;
|
||||
import haxework.gui.utils.ColorUtils;
|
||||
import haxework.gui.ButtonView.ButtonState;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class ButtonBitmapSkin implements ISkin<Sprite, ButtonView> implements ISize {
|
||||
|
||||
public var width(default, null):Float;
|
||||
public var height(default, null):Float;
|
||||
|
||||
public var fillType(default, default):FillType;
|
||||
public var color(default, default):Int;
|
||||
public var image(null, set):BitmapData;
|
||||
public var upImage(null, set):BitmapData;
|
||||
public var overImage(null, set):BitmapData;
|
||||
public var downImage(null, set):BitmapData;
|
||||
|
||||
private var images:Map<ButtonState, BitmapData>;
|
||||
private var disable:BitmapData;
|
||||
|
||||
public function new(?image:BitmapData = null, ?fillType:FillType = null, ?color = -1) {
|
||||
images = new Map<ButtonState, BitmapData>();
|
||||
if (image != null) {
|
||||
this.image = image;
|
||||
}
|
||||
this.fillType = fillType;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
width = value.width;
|
||||
height = value.height;
|
||||
images.set(ButtonState.UP, value);
|
||||
images.set(ButtonState.DOWN, BitmapUtil.multiply(value, 0.8));
|
||||
images.set(ButtonState.OVER, BitmapUtil.multiply(value, 1.2));
|
||||
disable = BitmapUtil.grayscale(value, 0.2);
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_upImage(value:BitmapData):BitmapData {
|
||||
width = value.width;
|
||||
height = value.height;
|
||||
images.set(ButtonState.UP, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_overImage(value:BitmapData):BitmapData {
|
||||
images.set(ButtonState.OVER, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_downImage(value:BitmapData):BitmapData {
|
||||
images.set(ButtonState.DOWN, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
if (images == null) return;
|
||||
var image:BitmapData = view.disabled ? disable : images.get(view.state);
|
||||
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
import haxework.gui.utils.ColorUtils;
|
||||
import haxework.gui.ButtonView.ButtonState;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class ButtonColorSkin implements ISkin<Sprite, ButtonView> {
|
||||
|
||||
public var color(default, set_color):Int;
|
||||
public var alpha(default, default):Float;
|
||||
public var disable(default, default):Int;
|
||||
private var colors:Map<ButtonState, Int>;
|
||||
|
||||
public function new(?color:Int = 0xffffff, ?alpha:Float = 1.0) {
|
||||
this.color = color;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
private function set_color(value:Int):Int {
|
||||
colors = new Map<ButtonState, Int>();
|
||||
colors.set(ButtonState.UP, value);
|
||||
colors.set(ButtonState.DOWN, ColorUtils.diff(value, -64));
|
||||
colors.set(ButtonState.OVER, ColorUtils.diff(value, 64));
|
||||
//disable = ColorUtils.multiply(value, 0.6);
|
||||
return value;
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
var color:Int = selectColor(view);
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(color, alpha);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.endFill();
|
||||
}
|
||||
|
||||
private function selectColor(view:ButtonView):Int {
|
||||
return view.disabled ? disable : colors.get(view.state);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class ColorSkin implements ISkin<Sprite, IView<Sprite>> {
|
||||
|
||||
public var color(default, default):Int;
|
||||
public var alpha(default, default):Float;
|
||||
|
||||
public function new(?color:Int = 0x000000, ?alpha:Float = 1.0) {
|
||||
this.color = color;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public function draw(view:IView<Sprite>):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(color, alpha);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.endFill();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class FakeSkin implements ISkin<Sprite, IView<Sprite>> {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function draw(view:IView<Sprite>):Void {
|
||||
/*var g:Graphics = view.content.graphics;
|
||||
g.clear();
|
||||
g.lineStyle(1, 0x00ff00);
|
||||
g.drawRect(0, 0, view.width, view.height);
|
||||
g.endFill();
|
||||
g.lineStyle();*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
interface ISize {
|
||||
public var width(default, null):Float;
|
||||
public var height(default, null):Float;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
import haxework.gui.IView.Content;
|
||||
|
||||
interface ISkin<C:Content, V:IView<C>> {
|
||||
public function draw(view:V):Void;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package haxework.gui.skin;
|
||||
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
import haxework.gui.skin.ISkin;
|
||||
|
||||
class ProgressSkin implements ISkin<Sprite, ProgressView> {
|
||||
|
||||
public var foreColor:Int;
|
||||
public var backColor:Int;
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function draw(view:ProgressView):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(backColor);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(foreColor);
|
||||
graphics.drawRect(0, 0, view.width * (view.max > 0 ? view.value / view.max : 0), view.height);
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package haxework.gui.utils;
|
||||
|
||||
import flash.geom.Point;
|
||||
import flash.filters.ColorMatrixFilter;
|
||||
import flash.geom.ColorTransform;
|
||||
import flash.display.BitmapData;
|
||||
|
||||
class BitmapUtil {
|
||||
|
||||
public static function multiply(image:BitmapData, m:Float):BitmapData {
|
||||
var ct:ColorTransform = new ColorTransform(m, m, m, 1.0, 0, 0, 0);
|
||||
var out:BitmapData = image.clone();
|
||||
out.colorTransform(out.rect, ct);
|
||||
return out;
|
||||
}
|
||||
|
||||
public static function grayscale(image:BitmapData, m:Float):BitmapData {
|
||||
var matrix:Array<Float> = [];
|
||||
matrix = matrix.concat([m, m, m, 0, 0]);
|
||||
matrix = matrix.concat([m, m, m, 0, 0]);
|
||||
matrix = matrix.concat([m, m, m, 0, 0]);
|
||||
matrix = matrix.concat([0, 0, 0, 1, 0]);
|
||||
var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix);
|
||||
var out:BitmapData = image.clone();
|
||||
out.applyFilter(out, out.rect, new Point(0,0), cmf);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package haxework.gui.utils;
|
||||
|
||||
class ColorUtils {
|
||||
|
||||
public static function multiply(color:Int, m:Float):Int {
|
||||
var rgb:Array<Int> = color2rgb(color);
|
||||
var red:Int = cast Math.min(255, Math.round(rgb[0] * m));
|
||||
var green:Int = cast Math.min(255, Math.round(rgb[1] * m));
|
||||
var blue:Int = cast Math.min(255, Math.round(rgb[2] * m));
|
||||
return rgb2color(red, green, blue);
|
||||
}
|
||||
|
||||
public static function diff(color:Int, d:Int):Int {
|
||||
var rgb:Array<Int> = color2rgb(color);
|
||||
var red:Int = cast Math.max(0, Math.min(255, rgb[0] + d));
|
||||
var green:Int = cast Math.max(0, Math.min(255, rgb[1] + d));
|
||||
var blue:Int = cast Math.max(0, Math.min(255, rgb[2] + d));
|
||||
return rgb2color(red, green, blue);
|
||||
}
|
||||
|
||||
public static function rgb2color(red:Int, green:Int, blue:Int):Int {
|
||||
return (red << 16) + (green << 8) + blue;
|
||||
}
|
||||
|
||||
public static function color2rgb(color:Int):Array<Int> {
|
||||
var red:Int = ((color & 0xFF0000) >>> 16);
|
||||
var green:Int = ((color & 0x00FF00) >> 8);
|
||||
var blue:Int = (color & 0x0000FF);
|
||||
return [red, green, blue];
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package haxework.gui.utils;
|
||||
|
||||
import flash.display.Bitmap;
|
||||
import flash.Lib;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.Graphics;
|
||||
|
||||
@:fakeEnum(String) enum FillType {
|
||||
NONE;
|
||||
DEFAULT;
|
||||
COVER;
|
||||
CONTAIN;
|
||||
REPEAT;
|
||||
STRETCH;
|
||||
NINEPATH;
|
||||
}
|
||||
|
||||
class DrawUtil {
|
||||
|
||||
public static function draw(graphics:Graphics, image:BitmapData, rect:Rectangle, ?fillType:FillType = null, ?color:Int = -1, ?clear:Bool = true):Void {
|
||||
if (fillType == null) fillType = FillType.DEFAULT;
|
||||
if (clear) graphics.clear();
|
||||
if (color > -1) {
|
||||
graphics.beginFill(color);
|
||||
graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
|
||||
graphics.endFill();
|
||||
}
|
||||
var m:Matrix = new Matrix();
|
||||
var sx:Float = 1.0;
|
||||
var sy:Float = 1.0;
|
||||
switch (fillType) {
|
||||
case FillType.REPEAT:
|
||||
graphics.beginBitmapFill(image, m, true, false);
|
||||
graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
|
||||
graphics.endFill();
|
||||
return;
|
||||
case FillType.NONE:
|
||||
graphics.beginBitmapFill(image, m, false, false);
|
||||
graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
|
||||
graphics.endFill();
|
||||
return;
|
||||
case FillType.NINEPATH:
|
||||
draw9path(graphics, image, rect);
|
||||
return;
|
||||
case FillType.DEFAULT:
|
||||
case FillType.CONTAIN:
|
||||
sx = sy = Math.min(rect.width / image.width, rect.height / image.height);
|
||||
case FillType.COVER:
|
||||
sx = sy = Math.max(rect.width / image.width, rect.height / image.height);
|
||||
case FillType.STRETCH:
|
||||
sx = rect.width / image.width;
|
||||
sy = rect.height / image.height;
|
||||
}
|
||||
m.scale(sx, sy);
|
||||
var dx:Float = (rect.width - image.width * sx) / 2;
|
||||
var dy:Float = (rect.height - image.height * sy) / 2;
|
||||
m.translate(dx, dy);
|
||||
graphics.beginBitmapFill(image, m, false, true);
|
||||
rect.x = Math.max(rect.x, m.tx);
|
||||
rect.y = Math.max(rect.y, m.ty);
|
||||
rect.width = Math.min(rect.width, image.width * sx);
|
||||
rect.height = Math.min(rect.height, image.height * sy);
|
||||
graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
|
||||
graphics.endFill();
|
||||
}
|
||||
|
||||
private static function draw9path(graphics:Graphics, image:BitmapData, rect:Rectangle):Void {
|
||||
var w:Int = Math.round(image.width / 2);
|
||||
var h:Int = Math.round(image.height / 2);
|
||||
var m:Matrix = null;
|
||||
//lt
|
||||
graphics.beginBitmapFill(image, m, false);
|
||||
graphics.drawRect(0, 0, w, h);
|
||||
graphics.endFill();
|
||||
//rt
|
||||
m = new Matrix();
|
||||
m.translate(rect.width - 2 * w, 0);
|
||||
graphics.beginBitmapFill(image, m, false);
|
||||
graphics.drawRect(rect.width - w, 0, w, h);
|
||||
graphics.endFill();
|
||||
//lb
|
||||
m = new Matrix();
|
||||
m.translate(0, rect.height - 2 * h);
|
||||
graphics.beginBitmapFill(image, m, false);
|
||||
graphics.drawRect(0, rect.height - h, w, h);
|
||||
graphics.endFill();
|
||||
//rb
|
||||
m = new Matrix();
|
||||
m.translate(rect.width - 2 * w, rect.height - 2 * h);
|
||||
graphics.beginBitmapFill(image, m, false);
|
||||
graphics.drawRect(rect.width - w, rect.height - h, w, h);
|
||||
graphics.endFill();
|
||||
//c
|
||||
graphics.beginFill(image.getPixel(w, h));
|
||||
graphics.drawRect(w - 1, h - 1, rect.width - 2 * w + 2, rect.height - 2 * h + 2);
|
||||
graphics.endFill();
|
||||
//t
|
||||
var t:BitmapData = new BitmapData(1, h);
|
||||
t.copyPixels(image, new Rectangle(w, 0, 1, h), new Point(0, 0));
|
||||
graphics.beginBitmapFill(t, null, true);
|
||||
graphics.drawRect(w, 0, rect.width - w * 2, h);
|
||||
graphics.endFill();
|
||||
//b
|
||||
var b:BitmapData = new BitmapData(1, h);
|
||||
b.copyPixels(image, new Rectangle(w, h, 1, h), new Point(0, 0));
|
||||
m = new Matrix();
|
||||
m.translate(0, rect.height - h);
|
||||
graphics.beginBitmapFill(b, m, true);
|
||||
graphics.drawRect(w, rect.height - h, rect.width - w * 2, h - 2); //ToDo:?
|
||||
graphics.endFill();
|
||||
//l
|
||||
var l:BitmapData = new BitmapData(w, 1);
|
||||
l.copyPixels(image, new Rectangle(0, h, w, 1), new Point(0, 0));
|
||||
graphics.beginBitmapFill(l, null, true);
|
||||
graphics.drawRect(0, h, w, rect.height - h * 2);
|
||||
graphics.endFill();
|
||||
//r
|
||||
var r:BitmapData = new BitmapData(w, 1);
|
||||
r.copyPixels(image, new Rectangle(w, h, w, 1), new Point(0, 0));
|
||||
m = new Matrix();
|
||||
m.translate(rect.width - w, 0);
|
||||
graphics.beginBitmapFill(r, m, true);
|
||||
graphics.drawRect(rect.width - w, h, w, rect.height - h * 2);
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package haxework.locale;
|
||||
|
||||
interface ILocale {
|
||||
public function getString(key:String):String;
|
||||
public function formatString(key:String, args:Array<Dynamic>):String;
|
||||
public function getArray(key:String):Array<String>;
|
||||
public function getPlural(key:String, num:Int):String;
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package haxework.locale;
|
||||
|
||||
class Locale implements ILocale {
|
||||
|
||||
private var data:Dynamic;
|
||||
private var lang:String;
|
||||
|
||||
public function new(lang:String, data:Dynamic) {
|
||||
this.lang = lang;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public function formatString(key:String, args:Array<Dynamic>):String {
|
||||
var string:String = getString(key);
|
||||
for (i in 0...args.length) {
|
||||
var arg:Dynamic = args[i];
|
||||
string = StringTools.replace(string, "{" + i + "}", arg);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
public function getString(key:String):String {
|
||||
return getObject(key);
|
||||
}
|
||||
|
||||
public function getArray(key:String):Array<String> {
|
||||
return getObject(key);
|
||||
}
|
||||
|
||||
|
||||
public function getPlural(key:String, num:Int):String {
|
||||
var array:Array<String> = getArray(key);
|
||||
switch (lang) {
|
||||
case "ru": return plurarRU(array, num);
|
||||
default: return plurarDefault(array, num);
|
||||
}
|
||||
}
|
||||
|
||||
private function getObject(key:String):Dynamic {
|
||||
var path:Array<String> = key.split(".");
|
||||
var tmp:Dynamic = data;
|
||||
for (i in 0...path.length) {
|
||||
if (Reflect.hasField(tmp, path[i])) {
|
||||
tmp = Reflect.field(tmp, path[i]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private function plurarRU(strings:Array<String>, num:Int):String {
|
||||
if (num > 10 && num < 20) return strings[2];
|
||||
var n:Int = num % 10;
|
||||
switch (n) {
|
||||
case 1: return strings[0];
|
||||
case 2: return strings[1];
|
||||
case 3: return strings[1];
|
||||
case 4: return strings[1];
|
||||
default: return strings[2];
|
||||
}
|
||||
}
|
||||
|
||||
private function plurarDefault(strings:Array<String>, num:Int):String {
|
||||
var n:Int = num % 10;
|
||||
switch (n) {
|
||||
case 1: return strings[0];
|
||||
default: return strings[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package haxework.log;
|
||||
|
||||
#if flash
|
||||
import flash.events.ErrorEvent;
|
||||
import flash.errors.Error;
|
||||
#end
|
||||
import haxework.log.ILogger.LogLevel;
|
||||
|
||||
class BaseLogger implements ILogger {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function log(level:LogLevel, tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
||||
write(buildString(level, tag, message, error), p);
|
||||
}
|
||||
|
||||
private function buildString(level:LogLevel, tag:String, message:String, ?error:Dynamic):String {
|
||||
return "[" + level + "] " + tag + " - " + message + (error == null ? "" : " {" + error2strign(error) + "}");
|
||||
}
|
||||
|
||||
public static function error2strign(error:Dynamic):String {
|
||||
#if flash
|
||||
return if (Std.is(error, Error)) {
|
||||
var stack:String = error.getStackTrace();
|
||||
stack == null ? Std.string(error) : stack;
|
||||
} else if (Std.is(error, ErrorEvent)) {
|
||||
var event:ErrorEvent = cast(error, ErrorEvent);
|
||||
event.type + " - " + event.text;
|
||||
} else {
|
||||
Std.string(error);
|
||||
}
|
||||
#else
|
||||
return Std.string(error);
|
||||
#end
|
||||
}
|
||||
|
||||
private function write(text:String, ?p:haxe.PosInfos):Void {}
|
||||
|
||||
public function d(tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
||||
log(LogLevel.DEBUG, tag, message, error, p);
|
||||
}
|
||||
|
||||
public function i(tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
||||
log(LogLevel.INFO, tag, message, error, p);
|
||||
}
|
||||
|
||||
public function w(tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
||||
log(LogLevel.WARNING, tag, message, error, p);
|
||||
}
|
||||
|
||||
public function e(tag:String, message:String, ?error:Dynamic, ?p:haxe.PosInfos):Void {
|
||||
log(LogLevel.ERROR, tag, message, error, p);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package haxework.log;
|
||||
|
||||
import haxework.log.ILogger.LogLevel;
|
||||
import flash.external.ExternalInterface;
|
||||
import haxework.log.BaseLogger;
|
||||
|
||||
class JSLogger extends BaseLogger {
|
||||
|
||||
private var available:Bool;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
available = ExternalInterface.available;
|
||||
}
|
||||
|
||||
override public function e(tag:String, message:String, error:Dynamic = null, p:haxe.PosInfos = null):Void {
|
||||
if (available) {
|
||||
var text:String = buildString(LogLevel.ERROR, tag, message, error);
|
||||
var s:String = p.fileName + ":" + p.lineNumber + ":" + text + "\n";
|
||||
try {ExternalInterface.call("console.error", s);} catch (error:Dynamic) {available = false;}
|
||||
}
|
||||
}
|
||||
|
||||
override private function write(text:String, ?p:haxe.PosInfos):Void {
|
||||
if (available) {
|
||||
var s:String = p.fileName + ":" + p.lineNumber + ":" + text + "\n";
|
||||
try {ExternalInterface.call("console.log", s);} catch (error:Dynamic) {available = false;}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package haxework.log;
|
||||
|
||||
import haxework.log.BaseLogger;
|
||||
#if flash
|
||||
import flash.net.Socket;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
#else
|
||||
import sys.net.Host;
|
||||
import sys.net.Socket;
|
||||
#end
|
||||
|
||||
class SocketLogger extends BaseLogger {
|
||||
|
||||
private var socket:Socket;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
socket = new Socket();
|
||||
#if flash
|
||||
socket.addEventListener(IOErrorEvent.IO_ERROR, function(error):Void {
|
||||
//L.e("SocketLogger", "", error);
|
||||
});
|
||||
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(error):Void {
|
||||
//L.e("SocketLogger", "", error);
|
||||
});
|
||||
socket.connect(CompilationOption.get("debug.address"), Std.parseInt(CompilationOption.get("debug.port")));
|
||||
#else
|
||||
socket.connect(new Host(CompilationOption.get("debug.address")), Std.parseInt(CompilationOption.get("debug.port")));
|
||||
#end
|
||||
}
|
||||
|
||||
override private function write(text:String, ?p:haxe.PosInfos):Void {
|
||||
try {
|
||||
var s:String = p.fileName + ":" + p.lineNumber + ":" + text + "\n";
|
||||
#if flash
|
||||
socket.writeUTF(s);
|
||||
socket.flush();
|
||||
#else
|
||||
socket.write(s);
|
||||
#end
|
||||
} catch (error:Dynamic) {}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package haxework.log;
|
||||
|
||||
import haxework.log.ILogger.LogLevel;
|
||||
|
||||
class TraceLogger extends BaseLogger {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
override private function write(text:String, ?p:haxe.PosInfos):Void {
|
||||
haxe.Log.trace(text, p);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user