Compare commits
139 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a6f7841e1 | |||
| 4a7403022b | |||
| 163e6d68c3 | |||
| f396c86a23 | |||
| e5f8d7834a | |||
| a4ca9a924c | |||
| 88b4459023 | |||
| ccfa8c05f8 | |||
| 4017df4d00 | |||
| fe60e78b74 | |||
| 279baa1113 | |||
| 7b7819fe6e | |||
| 2428ed20e0 | |||
| bc3d6e4458 | |||
| d217727d94 | |||
| c889ca04da | |||
| 39ca4b3d9b | |||
| f81ab02e67 | |||
| 284593e82c | |||
| a311dc1c19 | |||
| 07c228121c | |||
| a6ff04fd1b | |||
| a768e75cec | |||
| 7a5b32b251 | |||
| 74ed2d4425 | |||
| fcbac5587e | |||
| 78f4ae3a03 | |||
| b18b9d2d30 | |||
| c88a2c810f | |||
| a253aeaed4 | |||
| 3478963a6f | |||
| 5989da3fe4 | |||
| 32309389e5 | |||
| 3d54a2489b | |||
| 7a68604cad | |||
| f31b1ce506 | |||
| f186b08e9f | |||
| 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 |
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
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ out/
|
|||||||
target/
|
target/
|
||||||
*.zip
|
*.zip
|
||||||
pack.sh
|
pack.sh
|
||||||
|
.vscode/
|
||||||
|
|||||||
67
README.md
67
README.md
@@ -1,62 +1,65 @@
|
|||||||
# haxework
|
# HaxeWork
|
||||||
|
|
||||||
Gui framework for Haxe.
|
HaXe framework.
|
||||||
|
|
||||||
## View
|
## View
|
||||||
|
|
||||||
`haxework.gui` provides views classes.
|
`hw.view` provides views classes.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
Build form using `haxework.gui.ViewBuilder`.
|
Build form using macro @:template.
|
||||||
|
|
||||||
form.json:
|
form.yaml:
|
||||||
|
|
||||||
```json
|
```yaml
|
||||||
{
|
---
|
||||||
"type":"haxework.gui.VGroupView",
|
skin:
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xffff00"},
|
- $type: hw.gui.skin.ColorSkin
|
||||||
"paddings":20,
|
color: 0xffff00
|
||||||
"layoutMargin":10,
|
geometry.padding: 20
|
||||||
"views":[
|
layout.margin: 10
|
||||||
{
|
views:
|
||||||
"id":"view1",
|
- id: view1
|
||||||
"type":"haxework.gui.SpriteView",
|
type: hw.view.SpriteView
|
||||||
"pWidth":100, "pHeight":100,
|
geometry.size.stretch: true
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"}
|
skin:
|
||||||
},
|
- $type: hw.view.skin.ColorSkin
|
||||||
{
|
color: 0xff0000
|
||||||
"id":"view2",
|
- id: view2
|
||||||
"type":"haxework.gui.SpriteView",
|
type: hw.view.SpriteView
|
||||||
"pWidth":100, "height":50,
|
geometry.size.width: 100%
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"}
|
geometry.size.height: 50
|
||||||
}
|
skin:
|
||||||
]
|
- "$type": hw.view.skin.ColorSkin
|
||||||
}
|
color: 0x00ff00
|
||||||
```
|
```
|
||||||
|
|
||||||
```haxe
|
```haxe
|
||||||
@:template("form.json")
|
@:template("form.yaml")
|
||||||
class FormView extends VGroupView implements ViewBuilder {}
|
class FormView extends VGroupView {
|
||||||
|
@:view public var view1:SpriteView;
|
||||||
|
@:view("view2") public var anyVarName:SpriteView;
|
||||||
|
}
|
||||||
|
|
||||||
var form = new FormView();
|
var form = new FormView();
|
||||||
Root.bind(form); // Add form to stage as root view element.
|
Root.bind(form); // Add form to stage as root view element.
|
||||||
trace(form.view1);
|
trace(form.view1);
|
||||||
trace(form.view2);
|
trace(form.anyVarName);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Loader
|
## Loader
|
||||||
|
|
||||||
`haxework.net` provides loaders classes.
|
`hw.net` provides loaders classes.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```haxe
|
```haxe
|
||||||
new JsonLoader().GET("http://example.com/file.json")
|
new JsonLoader().GET("http://example.com/file.json")
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
trace("Json Ok: " + data);
|
trace("Json Ok: " + data);
|
||||||
})
|
})
|
||||||
.catchError(function(error) {
|
.catchError(function(error) {
|
||||||
trace("Json Fail: " + error);
|
trace("Json Fail: " + error);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
1
build.hxml
Normal file
1
build.hxml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-p src/main
|
||||||
15
demo/build.hxml
Executable file
15
demo/build.hxml
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
-cp src
|
||||||
|
#-cp ../src/main
|
||||||
|
-lib yaml
|
||||||
|
-lib promhx
|
||||||
|
-lib haxework
|
||||||
|
--macro hw.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="hw.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=""/>
|
||||||
|
<haxelib name="openfl" version=""/>
|
||||||
|
<haxelib name="hxcpp" version=""/>
|
||||||
|
<!--<haxelib name="promhx" version=""/>-->
|
||||||
|
<haxelib name="haxework" version="git"/>
|
||||||
|
|
||||||
|
<!--<haxeflag name="--macro" value="hw.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>
|
||||||
7
demo/run.sh
Executable file
7
demo/run.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
SDK_PATH=~/sdk
|
||||||
|
echo "`pwd`/target" > ~/.macromedia/Flash_Player/#Security/FlashPlayerTrust/haxework_demo.cfg
|
||||||
|
. ${SDK_PATH}/neko/2.2.0/activate
|
||||||
|
. ${SDK_PATH}/haxe/4.0.5/activate
|
||||||
|
haxe build.hxml && ${SDK_PATH}/flashplayer/32/flashplayerdebugger target/demo.swf &
|
||||||
|
tail -f ~/.macromedia/Flash_Player/Logs/flashlog.txt
|
||||||
7
demo/run_openfl.sh
Executable file
7
demo/run_openfl.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
SDK_PATH=~/sdk
|
||||||
|
echo "`pwd`/target/flash/bin" > ~/.macromedia/Flash_Player/#Security/FlashPlayerTrust/haxework_demo.cfg
|
||||||
|
. ${SDK_PATH}/neko/2.2.0/activate
|
||||||
|
. ${SDK_PATH}/haxe/4.0.5/activate
|
||||||
|
#haxelib run openfl test flash
|
||||||
|
haxelib run openfl test html5
|
||||||
26
demo/src/demo/AppTheme.hx
Normal file
26
demo/src/demo/AppTheme.hx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package demo;
|
||||||
|
|
||||||
|
import hw.view.geometry.Box;
|
||||||
|
import hw.color.Color;
|
||||||
|
import hw.view.theme.Theme;
|
||||||
|
|
||||||
|
using hw.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),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
97
demo/src/demo/Demo.hx
Normal file
97
demo/src/demo/Demo.hx
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package demo;
|
||||||
|
|
||||||
|
import demo.dispatch.DemoDispatcher;
|
||||||
|
import demo.popup.ColorPopup;
|
||||||
|
import demo.popup.FontPopup;
|
||||||
|
import demo.storage.TestStorage;
|
||||||
|
import hw.app.App;
|
||||||
|
import hw.log.TraceLogger;
|
||||||
|
import hw.net.JsonLoader;
|
||||||
|
import hw.resources.IResources;
|
||||||
|
import hw.view.data.ButtonGroup;
|
||||||
|
import hw.view.frame.FrameSwitcher;
|
||||||
|
import hw.view.frame.FrameView;
|
||||||
|
import hw.view.group.VGroupView;
|
||||||
|
|
||||||
|
@:template class DemoView extends VGroupView {
|
||||||
|
@:view var switcher:FrameSwitcher;
|
||||||
|
@:view var tabs:ButtonGroup<String>;
|
||||||
|
|
||||||
|
public function new():Void {
|
||||||
|
super();
|
||||||
|
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 {
|
||||||
|
|
||||||
|
@:provide static var storage:TestStorage;
|
||||||
|
|
||||||
|
public static function main() {
|
||||||
|
L.push(new TraceLogger());
|
||||||
|
|
||||||
|
App.resources.image.put("logo", HaxeLogo.resolve());
|
||||||
|
var app = new Demo();
|
||||||
|
app.theme = new AppTheme();
|
||||||
|
app.icon = App.resources.image.get("logo");
|
||||||
|
app.view = new DemoView();
|
||||||
|
trace(storage);
|
||||||
|
storage.write("test", "value");
|
||||||
|
|
||||||
|
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: hw.view.ImageView
|
||||||
|
geometry.padding: 10
|
||||||
|
image: $r:image:logo
|
||||||
|
- id: tabs
|
||||||
|
$type: hw.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: hw.view.frame.FrameSwitcher
|
||||||
|
animateFactory: { $class: hw.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: hw.view.group.HGroupView
|
||||||
|
geometry.width: 100%
|
||||||
|
geometry.padding: 10
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- $type: hw.view.form.ButtonView
|
||||||
|
text: Color
|
||||||
|
+onPress: ~choiceColor()
|
||||||
|
- $type: hw.view.form.ButtonView
|
||||||
|
text: Font
|
||||||
|
+onPress: ~choiceFont()
|
||||||
|
# separator
|
||||||
|
- $type: hw.view.SpriteView
|
||||||
|
geometry.stretch: true
|
||||||
|
- $type: hw.view.form.ButtonView
|
||||||
|
text: OK
|
||||||
|
- $type: hw.view.form.ButtonView
|
||||||
|
text: Apply
|
||||||
|
- $type: hw.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 hw.view.Root;
|
||||||
|
import hw.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 hw.app.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@: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 hw.view.frame.FrameView;
|
||||||
|
import hw.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: hw.view.data.DataView
|
||||||
|
layout:
|
||||||
|
$type: hw.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 hw.view.frame.FrameView;
|
||||||
|
import hw.view.list.LabelListItem;
|
||||||
|
import hw.view.list.ListView.IListItemView;
|
||||||
|
import hw.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: hw.view.list.VListView
|
||||||
|
+onItemSelect: ~onItemSelect
|
||||||
|
factory: ~factory
|
||||||
|
geometry.stretch: true
|
||||||
|
scroll:
|
||||||
|
$type: hw.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 hw.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: hw.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: hw.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 hw.view.frame.FrameView;
|
||||||
|
import hw.view.ImageView;
|
||||||
|
import hw.view.IView;
|
||||||
|
import hw.view.text.TextView;
|
||||||
|
import hw.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: hw.view.data.DataView
|
||||||
|
geometry.padding: 4
|
||||||
|
layout:
|
||||||
|
$type: hw.view.layout.TailLayout
|
||||||
|
margin: 6
|
||||||
|
factory: ~factory
|
||||||
|
geometry.width: 100%
|
||||||
|
data: $r:any:data
|
||||||
24
demo/src/demo/form/TestLayoutForm.hx
Normal file
24
demo/src/demo/form/TestLayoutForm.hx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package demo.form;
|
||||||
|
|
||||||
|
import flash.events.MouseEvent;
|
||||||
|
import hw.view.frame.FrameView;
|
||||||
|
import hw.view.SpriteView;
|
||||||
|
|
||||||
|
@:template class TestLayoutForm extends FrameView<Dynamic> {
|
||||||
|
|
||||||
|
@:view var render:SpriteView;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super("test_layout");
|
||||||
|
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: hw.view.group.VGroupView
|
||||||
|
geometry.stretch: true
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- id: container
|
||||||
|
$type: hw.view.group.VGroupView
|
||||||
|
layout.margin: 10
|
||||||
|
skin:
|
||||||
|
$type: [hw.view.skin.Skin.color, 0xffff00]
|
||||||
|
views:
|
||||||
|
- id: top
|
||||||
|
$type: hw.view.group.GroupView
|
||||||
|
layout.hAlign: center
|
||||||
|
geometry.width: 100%
|
||||||
|
geometry.height: 20
|
||||||
|
style: test
|
||||||
|
- id: middle
|
||||||
|
$type: hw.view.group.HGroupView
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: left
|
||||||
|
$type: hw.view.group.GroupView
|
||||||
|
layout.vAlign: middle
|
||||||
|
geometry.width: 20
|
||||||
|
geometry.height: 100%
|
||||||
|
style: test
|
||||||
|
- id: render
|
||||||
|
$type: hw.view.SpriteView
|
||||||
|
#geometry.width: 300
|
||||||
|
#geometry.height: 200
|
||||||
|
style: test
|
||||||
|
- id: right
|
||||||
|
$type: hw.view.group.GroupView
|
||||||
|
layout.vAlign: middle
|
||||||
|
geometry.width: 20
|
||||||
|
geometry.height: 100%
|
||||||
|
style: test
|
||||||
|
views:
|
||||||
|
- $type: hw.view.SpriteView
|
||||||
|
geometry.width: 100
|
||||||
|
geometry.height: 100%
|
||||||
|
skin:
|
||||||
|
$type: [hw.view.skin.Skin.color, 0xff0000]
|
||||||
|
- id: bottom
|
||||||
|
$type: hw.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 hw.view.form.ButtonView;
|
||||||
|
import hw.view.popup.PopupView;
|
||||||
|
import hw.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: hw.view.group.VGroupView
|
||||||
|
geometry.width: 400
|
||||||
|
geometry.height: 200
|
||||||
|
geometry.padding: 10
|
||||||
|
geometry.hAlign: center
|
||||||
|
geometry.vAlign: middle
|
||||||
|
style: frame
|
||||||
|
views:
|
||||||
|
- id: colors
|
||||||
|
$type: hw.view.data.DataView
|
||||||
|
geometry.stretch: true
|
||||||
|
layout:
|
||||||
|
$type: hw.view.layout.TailLayout
|
||||||
|
vAlign: middle
|
||||||
|
margin: 5
|
||||||
|
factory: ~colorViewFactory
|
||||||
|
data:
|
||||||
|
- 0x33AA33
|
||||||
|
- 0xAA3333
|
||||||
|
- 0xFFCC55 # 0x555555
|
||||||
|
- 0xCC33AA
|
||||||
|
- 0x3333AA
|
||||||
|
+onDataSelect: ~close
|
||||||
|
- $type: hw.view.group.HGroupView
|
||||||
|
geometry.width: 100%
|
||||||
|
layout.hAlign: right
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- $type: hw.view.form.ButtonView
|
||||||
|
text: Cancel
|
||||||
|
+onPress: ~reject('cancel')
|
||||||
48
demo/src/demo/popup/FontPopup.hx
Normal file
48
demo/src/demo/popup/FontPopup.hx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package demo.popup;
|
||||||
|
|
||||||
|
import flash.text.Font;
|
||||||
|
import flash.text.FontType;
|
||||||
|
import hw.view.list.LabelListItem;
|
||||||
|
import hw.view.list.ListView;
|
||||||
|
import hw.view.popup.PopupView;
|
||||||
|
import hw.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>;
|
||||||
|
|
||||||
|
public function new():Void {
|
||||||
|
super();
|
||||||
|
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: hw.view.group.VGroupView
|
||||||
|
geometry.width: 400
|
||||||
|
geometry.height: 80%
|
||||||
|
geometry.padding: 10
|
||||||
|
geometry.hAlign: center
|
||||||
|
geometry.vAlign: middle
|
||||||
|
style: frame
|
||||||
|
views:
|
||||||
|
- id: fonts
|
||||||
|
$type: hw.view.list.VListView
|
||||||
|
geometry.stretch: true
|
||||||
|
factory: ~fontViewFactory
|
||||||
|
+onItemSelect: ~function(item) close(item.data)
|
||||||
|
scroll:
|
||||||
|
$type: hw.view.list.VScrollBarView
|
||||||
|
- $type: hw.view.group.HGroupView
|
||||||
|
geometry.width: 100%
|
||||||
|
geometry.margin.top: 10
|
||||||
|
layout.hAlign: right
|
||||||
|
views:
|
||||||
|
- $type: hw.view.form.ButtonView
|
||||||
|
text: Cancel
|
||||||
|
+onPress: ~reject('cancel')
|
||||||
10
demo/src/demo/storage/TestStorage.hx
Normal file
10
demo/src/demo/storage/TestStorage.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package demo.storage;
|
||||||
|
|
||||||
|
import hw.storage.SharedObjectStorage;
|
||||||
|
|
||||||
|
@:provide class TestStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super("test");
|
||||||
|
}
|
||||||
|
}
|
||||||
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 hw.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: hw.view.group.HGroupView
|
||||||
|
geometry.padding: 10
|
||||||
|
geometry.width: 100%
|
||||||
|
layout.margin: 10
|
||||||
|
layout.vAlign: middle
|
||||||
|
skin:
|
||||||
|
$type: hw.view.skin.SpriteSkin
|
||||||
|
background.color: 0xffff00
|
||||||
|
background.alpha: 1
|
||||||
|
views:
|
||||||
|
- $type: hw.view.SpriteView
|
||||||
|
geometry.width: 100
|
||||||
|
geometry.height: 100
|
||||||
|
skin:
|
||||||
|
$type: hw.view.skin.SpriteSkin
|
||||||
|
background.color: 0xff0000
|
||||||
|
background.alpha: 1
|
||||||
|
- $type: hw.view.group.VGroupView
|
||||||
|
geometry.padding: 10
|
||||||
|
layout.margin: 10
|
||||||
|
skin:
|
||||||
|
$type: hw.view.skin.SpriteSkin
|
||||||
|
background.color: 0x00ffff
|
||||||
|
background.alpha: 1
|
||||||
|
views:
|
||||||
|
- $type: hw.view.SpriteView
|
||||||
|
geometry.width: 100
|
||||||
|
geometry.height: 100
|
||||||
|
size:
|
||||||
|
_test_: [200, 200]
|
||||||
|
skin:
|
||||||
|
$type: hw.view.skin.SpriteSkin
|
||||||
|
background.color: 0xff0000
|
||||||
|
background.alpha: 1
|
||||||
|
- $type: hw.view.SpriteView
|
||||||
|
geometry.width: 100
|
||||||
|
geometry.height: 100
|
||||||
|
skin:
|
||||||
|
$type: hw.view.skin.SpriteSkin
|
||||||
|
background.color: 0xff0000
|
||||||
|
background.alpha: 1
|
||||||
|
- $type: hw.view.text.TextView
|
||||||
|
geometry.padding: 20
|
||||||
|
text: "Azazaza"
|
||||||
|
- $type: hw.view.SpriteView
|
||||||
|
geometry.width: 60%
|
||||||
|
geometry.height: 100%
|
||||||
|
skin:
|
||||||
|
$type: hw.view.skin.SpriteSkin
|
||||||
|
background.color: 0xff0000
|
||||||
|
background.alpha: 1
|
||||||
|
- $type: hw.view.SpriteView
|
||||||
|
geometry.width: 40%
|
||||||
|
geometry.height: 80%
|
||||||
|
skin:
|
||||||
|
$type: hw.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
extraParams.hxml
Normal file
1
extraParams.hxml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
--macro hw.parser.Parser.auto()
|
||||||
27
haxelib.json
27
haxelib.json
@@ -1,14 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "haxework",
|
"name": "haxework",
|
||||||
"url" : "https://bitbucket.org/shmyga/haxework.git",
|
"url": "https://bitbucket.org/shmyga/haxework",
|
||||||
"license": "BSD",
|
"license": "MIT",
|
||||||
"tags": ["flash"],
|
"tags": ["view", "layout", "template"],
|
||||||
"description": "Framework.",
|
"description": "View framework.",
|
||||||
"version": "0.6.1",
|
"version": "2.1.0",
|
||||||
"releasenote": "Update.",
|
"releasenote": "Update.",
|
||||||
"contributors": ["shmyga"],
|
"contributors": ["shmyga"],
|
||||||
"classPath": "src/main",
|
"classPath": "src/main",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"promhx": ""
|
"promhx": "1.1.0",
|
||||||
}
|
"protohx": "0.4.6",
|
||||||
|
"haxe-crypto": "0.0.8",
|
||||||
|
"yaml": "2.0.1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
-cp src
|
|
||||||
-lib haxework
|
|
||||||
-main ViewExample.hx
|
|
||||||
-swf target/ViewExample.swf
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package;
|
|
||||||
|
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.gui.VGroupView;
|
|
||||||
import haxework.gui.ButtonView;
|
|
||||||
import haxework.gui.Root;
|
|
||||||
|
|
||||||
@:template("form.json")
|
|
||||||
class FormView extends VGroupView implements ViewBuilder {}
|
|
||||||
|
|
||||||
class ViewExample {
|
|
||||||
|
|
||||||
public static function main() {
|
|
||||||
new ViewExample();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
var form = new FormView({listener:this});
|
|
||||||
Root.bind(form);
|
|
||||||
trace(form.panel);
|
|
||||||
trace(form.button1);
|
|
||||||
trace(form.button2);
|
|
||||||
trace(form.button3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onPress(view:ButtonView):Void {
|
|
||||||
trace("onPress: " + view.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
{
|
|
||||||
"@type":"haxework.gui.VGroupView",
|
|
||||||
"paddings":20,
|
|
||||||
"layoutMargin":10,
|
|
||||||
"skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"},
|
|
||||||
"views":[
|
|
||||||
{
|
|
||||||
"@type":"haxework.gui.SpriteView",
|
|
||||||
"pWidth":100,
|
|
||||||
"pHeight":100,
|
|
||||||
"leftMargin":5,
|
|
||||||
"rightMargin":10,
|
|
||||||
"skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"@type":"haxework.gui.SpriteView",
|
|
||||||
"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":"RIGHT",
|
|
||||||
"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":"@link:listener"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":"button2",
|
|
||||||
"@type":"haxework.gui.ButtonView",
|
|
||||||
"contentSize":true,
|
|
||||||
"skin":{"@type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cc00"},
|
|
||||||
"text":"Text2",
|
|
||||||
"fontFamily":"Georgia",
|
|
||||||
"fontColor":"0xffffff",
|
|
||||||
"onPress":"@link: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":"@link:listener"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
-cp src
|
|
||||||
-lib promhx
|
|
||||||
-lib haxework
|
|
||||||
-main LoaderExample.hx
|
|
||||||
-swf-version 10.1
|
|
||||||
-swf target/LoaderExample.swf
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package;
|
|
||||||
|
|
||||||
import flash.display.Bitmap;
|
|
||||||
import flash.Lib;
|
|
||||||
import flash.display.BitmapData;
|
|
||||||
import haxework.net.ImageLoader;
|
|
||||||
import haxework.net.JsonLoader;
|
|
||||||
|
|
||||||
typedef ChannelItem = {
|
|
||||||
var id:String;
|
|
||||||
var maker:String;
|
|
||||||
var title:String;
|
|
||||||
var message:String;
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoaderExample {
|
|
||||||
|
|
||||||
public static function main() {
|
|
||||||
// Json
|
|
||||||
trace("Json Request");
|
|
||||||
new JsonLoader().GET("http://umix.tv/channel/data2/renova.json")
|
|
||||||
.then(function(channel:Array<ChannelItem>) {
|
|
||||||
trace("Json Ok: " + channel.length);
|
|
||||||
for (item in channel) {
|
|
||||||
trace(item.id + ": " + item.message);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catchError(function(error) {
|
|
||||||
trace(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Image
|
|
||||||
trace("Image Request");
|
|
||||||
new ImageLoader().GET("http://umix.tv/channel/block/renova/1")
|
|
||||||
.then(function(image:BitmapData) {
|
|
||||||
trace("Image Ok: " + image.width + "x" + image.height);
|
|
||||||
Lib.current.addChild(new Bitmap(image));
|
|
||||||
})
|
|
||||||
.catchError(function(error) {
|
|
||||||
trace(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package;
|
package;
|
||||||
|
|
||||||
import haxework.log.ILogger;
|
import hw.log.ILogger;
|
||||||
|
|
||||||
class L {
|
class L {
|
||||||
|
|
||||||
|
|||||||
@@ -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 {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package haxework.animate;
|
|
||||||
|
|
||||||
import openfl.events.Event;
|
|
||||||
import flash.display.Stage;
|
|
||||||
|
|
||||||
class Animate implements IAnimate {
|
|
||||||
|
|
||||||
private static var running:Array<IAnimate> = new Array<IAnimate>();
|
|
||||||
|
|
||||||
public static function bind(stage:Stage):Void {
|
|
||||||
stage.addEventListener(Event.ENTER_FRAME, function(_) {
|
|
||||||
Animate.updateAll();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function updateAll():Void {
|
|
||||||
if (running.length > 0) {
|
|
||||||
var time = Date.now().getTime();
|
|
||||||
for (animate in running) animate.update(time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var callback:Animate -> Void;
|
|
||||||
private var duration:Int;
|
|
||||||
private var startTime:Float;
|
|
||||||
private var progress:Float;
|
|
||||||
|
|
||||||
public function new(duration:Int) {
|
|
||||||
this.duration = duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void {
|
|
||||||
startTime = Date.now().getTime();
|
|
||||||
this.callback = callback;
|
|
||||||
if (!custom) running.push(this);
|
|
||||||
update(startTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function update(time:Float):Void {
|
|
||||||
progress = (time - startTime) / duration;
|
|
||||||
if (progress >= 1) {
|
|
||||||
running.remove(this);
|
|
||||||
if (callback != null) {
|
|
||||||
callback(this);
|
|
||||||
callback = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function cancel():Void {
|
|
||||||
if (!Math.isNaN(startTime)) update(startTime + duration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package haxework.animate;
|
|
||||||
|
|
||||||
import flash.display.DisplayObjectContainer;
|
|
||||||
import haxework.animate.IAnimate;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import haxework.gui.IView;
|
|
||||||
import haxework.animate.Animate;
|
|
||||||
|
|
||||||
class CircleMaskAnimate extends Animate {
|
|
||||||
|
|
||||||
private var view:IView;
|
|
||||||
private var mask:Sprite;
|
|
||||||
private var cyrcle:Sprite;
|
|
||||||
private var size:Float;
|
|
||||||
|
|
||||||
public function new(view:IView, ?duration:Int = 1000) {
|
|
||||||
super(duration);
|
|
||||||
this.view = view;
|
|
||||||
this.mask = new Sprite();
|
|
||||||
this.cyrcle = new Sprite();
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void {
|
|
||||||
var width = view.parent.width;
|
|
||||||
var height = view.parent.height;
|
|
||||||
size = Math.sqrt(width * width + height * height);
|
|
||||||
//size = Math.max(width, height);
|
|
||||||
cyrcle.x = mask.x = -(size - width) / 2 - size;
|
|
||||||
cyrcle.y = mask.y = -(size - height) / 2 - size;
|
|
||||||
|
|
||||||
redraw(size, size);
|
|
||||||
|
|
||||||
view.parent.container.addChild(mask);
|
|
||||||
view.content.mask = mask;
|
|
||||||
view.parent.container.addChild(cyrcle);
|
|
||||||
|
|
||||||
super.start(callback, custom);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function redraw(size:Float, r:Float):Void {
|
|
||||||
mask.graphics.clear();
|
|
||||||
mask.graphics.beginFill(0xffffff);
|
|
||||||
mask.graphics.drawCircle(size + size / 2, size + size / 2, r / 2);
|
|
||||||
mask.graphics.endFill();
|
|
||||||
|
|
||||||
cyrcle.graphics.clear();
|
|
||||||
cyrcle.graphics.lineStyle(8, 0xffffff);
|
|
||||||
cyrcle.graphics.drawCircle(size + size / 2, size + size / 2, r / 2);
|
|
||||||
cyrcle.graphics.lineStyle();
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function update(time:Float):Void {
|
|
||||||
super.update(time);
|
|
||||||
|
|
||||||
redraw(size, size * progress);
|
|
||||||
|
|
||||||
if (progress >= 1 && view.content.parent != null) {
|
|
||||||
if (view.content.parent.contains(mask)) view.content.parent.removeChild(mask);
|
|
||||||
view.content.mask = null;
|
|
||||||
if (view.content.parent.contains(cyrcle)) view.parent.container.removeChild(cyrcle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package haxework.animate;
|
|
||||||
|
|
||||||
import haxework.animate.IAnimate;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import haxework.gui.IView;
|
|
||||||
import haxework.animate.Animate;
|
|
||||||
|
|
||||||
class FadeAnimate extends Animate {
|
|
||||||
|
|
||||||
private var view:IView;
|
|
||||||
|
|
||||||
public function new(view:IView, ?duration = 500) {
|
|
||||||
super(duration);
|
|
||||||
this.view = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void {
|
|
||||||
view.content.alpha = 1.0;
|
|
||||||
super.start(callback, custom);
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function update(time:Float):Void {
|
|
||||||
super.update(time);
|
|
||||||
view.content.alpha = 1 - (progress * 1.0);
|
|
||||||
if (progress >= 1) {
|
|
||||||
view.content.alpha = 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package haxework.animate;
|
|
||||||
|
|
||||||
interface IAnimate {
|
|
||||||
|
|
||||||
public function start(callback:IAnimate->Void, ?custom:Bool = false):Void;
|
|
||||||
public function cancel():Void;
|
|
||||||
|
|
||||||
private function update(time:Float):Void;
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package haxework.animate;
|
|
||||||
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import haxework.gui.IView;
|
|
||||||
import haxework.animate.Animate;
|
|
||||||
|
|
||||||
class UnFadeAnimate extends Animate {
|
|
||||||
|
|
||||||
private var view:IView;
|
|
||||||
|
|
||||||
public function new(view:IView, ?duration = 500) {
|
|
||||||
super(duration);
|
|
||||||
this.view = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void {
|
|
||||||
view.content.alpha = 0.0;
|
|
||||||
super.start(callback, custom);
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function update(time:Float):Void {
|
|
||||||
super.update(time);
|
|
||||||
view.content.alpha = progress * 1.0;
|
|
||||||
if (progress >= 1) {
|
|
||||||
view.content.alpha = 1.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,36 +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, once:Bool = false):Void {
|
|
||||||
listeners.set(listener, once);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
var r:Array<L> = [];
|
|
||||||
while (i.hasNext()) {
|
|
||||||
var l = i.next();
|
|
||||||
caller(l);
|
|
||||||
if (listeners.get(l)) r.push(l);
|
|
||||||
};
|
|
||||||
for (l in r) listeners.remove(l);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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, once:Bool = false):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,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;
|
|
||||||
contentAsSprite.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,116 +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>>();
|
|
||||||
contentAsSprite.buttonMode = true;
|
|
||||||
contentAsSprite.mouseChildren = false;
|
|
||||||
#if js
|
|
||||||
content.addEventListener(MouseEvent.MOUSE_UP, onMouseClick);
|
|
||||||
#else
|
|
||||||
content.addEventListener(MouseEvent.CLICK, onMouseClick);
|
|
||||||
#end
|
|
||||||
#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 {
|
|
||||||
#if js if (downed) { #end
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
if (!disabled) dispatcher.dispatch(pressCaller);
|
|
||||||
#if js } #end
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
if (content.stage != null) {
|
|
||||||
content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onMouseUp(event:MouseEvent):Void {
|
|
||||||
downed = false;
|
|
||||||
if (content.stage != null) {
|
|
||||||
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;
|
|
||||||
contentAsSprite.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_UP, 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,192 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import flash.display.DisplayObjectContainer;
|
|
||||||
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 {
|
|
||||||
public var container(get, null):DisplayObjectContainer;
|
|
||||||
|
|
||||||
public var views(default, set):Array<IView>;
|
|
||||||
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>;
|
|
||||||
|
|
||||||
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>();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline private function get_container():DisplayObjectContainer {
|
|
||||||
return contentAsSprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
layout.place(this, views);
|
|
||||||
for (view in views) {
|
|
||||||
view.update();
|
|
||||||
if (view.index > -1) {
|
|
||||||
contentAsSprite.setChildIndex(view.content, view.index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_views(value:Array<IView>):Array<IView> {
|
|
||||||
removeAllViews();
|
|
||||||
if (views == null) views = [];
|
|
||||||
for (view in value) addView(view);
|
|
||||||
return views;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addView(view:IView):IView {
|
|
||||||
views.push(view);
|
|
||||||
viewsById.set(view.id, view);
|
|
||||||
if (view.content != null) contentAsSprite.addChild(view.content);
|
|
||||||
view.parent = this;
|
|
||||||
invalidate();
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function insertView(view:IView, index:Int):IView {
|
|
||||||
if (index < 0) index = views.length + index;
|
|
||||||
views.insert(index, view);
|
|
||||||
viewsById.set(view.id, view);
|
|
||||||
if (view.content != null) contentAsSprite.addChild(view.content);
|
|
||||||
view.parent = this;
|
|
||||||
invalidate();
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addViewFirst(view:IView):IView {
|
|
||||||
views.unshift(view);
|
|
||||||
viewsById.set(view.id, view);
|
|
||||||
contentAsSprite.addChild(view.content);
|
|
||||||
view.parent = this;
|
|
||||||
invalidate();
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeView(view:IView):IView {
|
|
||||||
view.parent = null;
|
|
||||||
viewsById.remove(view.id);
|
|
||||||
views.remove(view);
|
|
||||||
if (view.content != null) contentAsSprite.removeChild(view.content);
|
|
||||||
invalidate();
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeAllViews():Void {
|
|
||||||
if (views != null) while (views.length > 0) {
|
|
||||||
removeView(views[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeViewById(id:String):IView {
|
|
||||||
if (viewsById.exists(id)) {
|
|
||||||
return removeView(viewsById.get(id));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findViewById<V:IView>(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,9 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
interface HasPaddings {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import flash.display.DisplayObject;
|
|
||||||
import flash.display.DisplayObjectContainer;
|
|
||||||
import haxework.gui.core.HAlign;
|
|
||||||
import haxework.gui.core.VAlign;
|
|
||||||
import haxework.gui.layout.ILayout;
|
|
||||||
|
|
||||||
interface IGroupView extends IView extends HasPaddings {
|
|
||||||
public var container(get, null):DisplayObjectContainer;
|
|
||||||
|
|
||||||
public var views(default, set):Array<IView>;
|
|
||||||
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 function addView(view:IView):IView;
|
|
||||||
public function addViewFirst(view:IView):IView;
|
|
||||||
public function insertView(view:IView, index:Int):IView;
|
|
||||||
public function removeView(view:IView):IView;
|
|
||||||
public function removeAllViews():Void;
|
|
||||||
public function removeViewById(id:String):IView;
|
|
||||||
public function findViewById<V:IView>(id:String, ?clazz:Class<V>):Null<V>;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import flash.text.TextField;
|
|
||||||
import haxework.gui.IView.Content;
|
|
||||||
import flash.text.TextFormatAlign;
|
|
||||||
|
|
||||||
interface ITextView extends IView extends HasPaddings {
|
|
||||||
public var textField(default, null):TextField;
|
|
||||||
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):Int;
|
|
||||||
public var fontBold(default, set):Bool;
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import flash.display.DisplayObject;
|
|
||||||
import haxework.gui.core.VAlign;
|
|
||||||
import haxework.gui.core.HAlign;
|
|
||||||
import haxework.gui.skin.ISkin;
|
|
||||||
import haxework.gui.core.SizeType;
|
|
||||||
|
|
||||||
interface IView {
|
|
||||||
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):DisplayObject;
|
|
||||||
public var skin(default, set):ISkin<Dynamic>;
|
|
||||||
|
|
||||||
public var parent(default, null):Null<IGroupView>;
|
|
||||||
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,39 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import haxework.net.ImageLoader;
|
|
||||||
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 var imageUrl(default, set):String;
|
|
||||||
|
|
||||||
public function new(?image:BitmapData) {
|
|
||||||
super();
|
|
||||||
if (image != null) {
|
|
||||||
this.image = image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_image(value:BitmapData):BitmapData {
|
|
||||||
if (image != value) {
|
|
||||||
image = value;
|
|
||||||
skin = cast new BitmapSkin(image, FillType.CONTAIN);
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_imageUrl(value:String):String {
|
|
||||||
if (imageUrl != value) {
|
|
||||||
imageUrl = value;
|
|
||||||
new ImageLoader().GET(imageUrl).then(function(data) {
|
|
||||||
image = data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return imageUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 js
|
|
||||||
//addEventListener(MouseEvent.CLICK, onMouseClick);
|
|
||||||
//#end
|
|
||||||
}
|
|
||||||
|
|
||||||
#if js
|
|
||||||
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,95 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import flash.text.TextFormatAlign;
|
|
||||||
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();
|
|
||||||
contentAsSprite.addChild(hintTextField);
|
|
||||||
textFormat.align = TextFormatAlign.LEFT;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,18 +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;
|
|
||||||
textField.multiline = true;
|
|
||||||
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,59 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import flash.errors.Error;
|
|
||||||
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 {
|
|
||||||
|
|
||||||
public static function bind(view:IView, autoSize:Bool = true) {
|
|
||||||
new Root(view, autoSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static var instance(default, null):Root;
|
|
||||||
|
|
||||||
public var view(default, null):IView;
|
|
||||||
public var autoSize(default, default):Bool;
|
|
||||||
|
|
||||||
public function new(view:IView, autoSize:Bool = true) {
|
|
||||||
if (instance != null) throw new Error("Only one instance");
|
|
||||||
instance = this;
|
|
||||||
this.view = view;
|
|
||||||
this.autoSize = autoSize;
|
|
||||||
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;
|
|
||||||
if (autoSize) {
|
|
||||||
view.width = content.stage.stageWidth;
|
|
||||||
view.height = content.stage.stageHeight;
|
|
||||||
} else {
|
|
||||||
view.x = (content.stage.stageWidth - view.width) / 2;
|
|
||||||
view.y = (content.stage.stageHeight - view.height) / 2;
|
|
||||||
}
|
|
||||||
L.d("Screen", content.stage.stageWidth + "x" + content.stage.stageHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import flash.display.Graphics;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
|
|
||||||
class SpriteView extends View {
|
|
||||||
|
|
||||||
public var contentAsSprite(get, null):Sprite;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super(new Sprite());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline private function get_contentAsSprite():Sprite {
|
|
||||||
return cast content;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if dev_layout
|
|
||||||
override public function update():Void {
|
|
||||||
super.update();
|
|
||||||
var g:Graphics = contentAsSprite.graphics;
|
|
||||||
g.lineStyle(1, 0x00ff00);
|
|
||||||
g.drawRect(0, 0, width, height);
|
|
||||||
g.lineStyle();
|
|
||||||
}
|
|
||||||
#end
|
|
||||||
}
|
|
||||||
@@ -1,288 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import haxework.text.TextUtil;
|
|
||||||
import haxework.text.BitmapTextField;
|
|
||||||
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 {
|
|
||||||
|
|
||||||
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):Int;
|
|
||||||
public var fontBold(default, set):Bool;
|
|
||||||
|
|
||||||
public var layoutHAlign(default, set):HAlign;
|
|
||||||
public var layoutVAlign(default, set):VAlign;
|
|
||||||
public var fill(default, set):Bool = true;
|
|
||||||
|
|
||||||
public var leftPadding(default, set):Float = 0.0;
|
|
||||||
public var rightPadding(default, set):Float = 0.0;
|
|
||||||
public var topPadding(default, set):Float = 0.0;
|
|
||||||
public var bottomPadding(default, set):Float = 0.0;
|
|
||||||
public var paddings(null, set):Float = 0.0;
|
|
||||||
|
|
||||||
public var shadow(default, set):Bool;
|
|
||||||
public var shadowColor(default, set):Int;
|
|
||||||
|
|
||||||
private var textFormat:TextFormat;
|
|
||||||
|
|
||||||
private var _textWidth:Float;
|
|
||||||
private var _textHeight:Float;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super();
|
|
||||||
layoutHAlign = HAlign.CENTER;
|
|
||||||
layoutVAlign = VAlign.MIDDLE;
|
|
||||||
textField = buildTextField();
|
|
||||||
textField.width = 1;
|
|
||||||
textField.height = 1;
|
|
||||||
textField.multiline = true;
|
|
||||||
textField.wordWrap = true;
|
|
||||||
#if dev_layout
|
|
||||||
textField.borderColor = 0xff0000;
|
|
||||||
textField.border = true;
|
|
||||||
#end
|
|
||||||
textFormat = textField.defaultTextFormat;
|
|
||||||
textFormat.font = "Arial";
|
|
||||||
textFormat.size = 16;
|
|
||||||
textFormat.leading = 0;
|
|
||||||
textFormat.align = TextFormatAlign.CENTER;
|
|
||||||
contentAsSprite.addChild(textField);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function buildTextField():TextField {
|
|
||||||
#if bitmap_text
|
|
||||||
return new BitmapTextField();
|
|
||||||
#else
|
|
||||||
return new TextField();
|
|
||||||
#end
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
textFormat.align = value;
|
|
||||||
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:Int):Int {
|
|
||||||
if (fontSize != value) {
|
|
||||||
fontSize = value;
|
|
||||||
textFormat.size = fontSize;
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
return fontSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_fontBold(value:Bool):Bool {
|
|
||||||
if (fontBold != value) {
|
|
||||||
fontBold = value;
|
|
||||||
textFormat.bold = fontBold;
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
return fontBold;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function currentText():String {
|
|
||||||
return _text;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function updateTextSize():Void {
|
|
||||||
var size = TextUtil.getSize(textField);
|
|
||||||
_textWidth = size.x;
|
|
||||||
_textHeight = size.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
textField.setTextFormat(textFormat);
|
|
||||||
updateTextSize();
|
|
||||||
if (contentSize && !Std.is(skin, ISize)) {
|
|
||||||
#if html5
|
|
||||||
var h = _textHeight;
|
|
||||||
var w = _textWidth;
|
|
||||||
//if (h > textFormat.size * 1.5) h = h / 2;
|
|
||||||
textField.height = h;
|
|
||||||
textField.width = w;
|
|
||||||
#end
|
|
||||||
width = textField.width + leftPadding + rightPadding;
|
|
||||||
height = textField.height + topPadding + bottomPadding;
|
|
||||||
textField.x = leftPadding;
|
|
||||||
textField.y = topPadding;
|
|
||||||
} 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 {
|
|
||||||
textField.width = width;
|
|
||||||
textField.height = _textHeight;
|
|
||||||
|
|
||||||
textField.x = switch (layoutHAlign) {
|
|
||||||
case HAlign.NONE: 0;
|
|
||||||
case HAlign.LEFT: leftPadding;
|
|
||||||
case HAlign.CENTER: (width - textField.width) / 2 + leftPadding - rightPadding;
|
|
||||||
case HAlign.RIGHT: width - textField.width - rightPadding;
|
|
||||||
default: 0;
|
|
||||||
}
|
|
||||||
textField.y = switch (layoutVAlign) {
|
|
||||||
case VAlign.NONE: 0;
|
|
||||||
case VAlign.TOP: topPadding;
|
|
||||||
case VAlign.MIDDLE: (height - _textHeight) / 2 + topPadding - bottomPadding;
|
|
||||||
case VAlign.BOTTOM: height - _textHeight - bottomPadding;
|
|
||||||
default: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function set_mouseEnabled(value:Bool):Bool {
|
|
||||||
textField.mouseEnabled = value;
|
|
||||||
return super.set_mouseEnabled(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_shadow(value) {
|
|
||||||
if (Std.is(textField, BitmapTextField)) {
|
|
||||||
cast(textField, BitmapTextField).shadow = value;
|
|
||||||
return cast(textField, BitmapTextField).shadow;
|
|
||||||
} else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_shadowColor(value) {
|
|
||||||
if (Std.is(textField, BitmapTextField)) {
|
|
||||||
cast(textField, BitmapTextField).shadowColor = value;
|
|
||||||
cast(textField, BitmapTextField).shadow = true;
|
|
||||||
return cast(textField, BitmapTextField).shadowColor;
|
|
||||||
} else {
|
|
||||||
return 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<Dynamic>;
|
|
||||||
|
|
||||||
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<Dynamic>):ISkin<Dynamic> {
|
|
||||||
onSkin = value;
|
|
||||||
invalidate();
|
|
||||||
return onSkin;
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function currentSkin():ISkin<Dynamic> {
|
|
||||||
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,342 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import flash.display.InteractiveObject;
|
|
||||||
import flash.display.DisplayObject;
|
|
||||||
import flash.errors.Error;
|
|
||||||
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 implements IView {
|
|
||||||
|
|
||||||
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):DisplayObject;
|
|
||||||
public var skin(default, set):ISkin<Dynamic>;
|
|
||||||
|
|
||||||
public var parent(default, null):Null<IGroupView>;
|
|
||||||
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:DisplayObject) {
|
|
||||||
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<Dynamic> {
|
|
||||||
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<Dynamic> = 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<Dynamic>):ISkin<Dynamic> {
|
|
||||||
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 && Std.is(content, InteractiveObject)) {
|
|
||||||
cast(content, InteractiveObject).mouseEnabled = mouseEnabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mouseEnabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Updater {
|
|
||||||
|
|
||||||
public var stage(null, set):Stage;
|
|
||||||
private var invalidated:Array<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):Void {
|
|
||||||
if (Lambda.indexOf(invalidated, view) == -1) invalidated.push(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(?_):Void {
|
|
||||||
var t = Date.now().getTime();
|
|
||||||
while (invalidated.length > 0) {
|
|
||||||
var v = null;
|
|
||||||
try {
|
|
||||||
v = invalidated.shift();
|
|
||||||
v.update();
|
|
||||||
} catch (error:Dynamic) {
|
|
||||||
L.e("Update", v + "", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t = Date.now().getTime() - t;
|
|
||||||
if (t > 10) trace("UPDATE(" + t + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package haxework.gui;
|
|
||||||
|
|
||||||
import haxework.gui.build.Builder;
|
|
||||||
|
|
||||||
@:remove @:autoBuild(haxework.gui.ViewBuilderImpl.build())
|
|
||||||
extern interface ViewBuilder {}
|
|
||||||
|
|
||||||
class ViewBuilderImpl {
|
|
||||||
#if macro
|
|
||||||
public static function build() {
|
|
||||||
return new Builder().build();
|
|
||||||
}
|
|
||||||
#end
|
|
||||||
}
|
|
||||||
@@ -1,193 +0,0 @@
|
|||||||
package haxework.gui.build;
|
|
||||||
#if macro
|
|
||||||
|
|
||||||
import haxe.macro.Context;
|
|
||||||
import haxework.gui.build.PositionJsonParser;
|
|
||||||
import haxe.macro.Expr;
|
|
||||||
import haxe.macro.Expr.Field;
|
|
||||||
|
|
||||||
class Builder {
|
|
||||||
|
|
||||||
private var templateFile:String;
|
|
||||||
private var templateKey:String;
|
|
||||||
private var styleFile:String;
|
|
||||||
|
|
||||||
private var template:Dynamic;
|
|
||||||
private var fields:Array<Field>;
|
|
||||||
private var exprs:Array<Expr>;
|
|
||||||
private var style:Dynamic;
|
|
||||||
|
|
||||||
private var i:Int;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
var templateMeta = BuilderUtil.getMeta(":template");
|
|
||||||
var templatePath = templateMeta[0].split("@");
|
|
||||||
templateFile = Context.resolvePath(templatePath[0]);
|
|
||||||
templateKey = templatePath[1];
|
|
||||||
|
|
||||||
template = BuilderUtil.loadJsonFile(templateFile);
|
|
||||||
if (templateKey != null) template = Reflect.field(template, templateKey);
|
|
||||||
|
|
||||||
if (templateMeta[1] != null) {
|
|
||||||
styleFile = Context.resolvePath(templateMeta[1]);
|
|
||||||
style = BuilderUtil.loadJsonFile(styleFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
fields = Context.getBuildFields();
|
|
||||||
exprs = [];
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getPosition(?position:JsonKeyPosition):Position {
|
|
||||||
var min = position == null ? 1 : position.min + 32; // :-(
|
|
||||||
var max = position == null ? 1 : position.max + 32;
|
|
||||||
var file = position == null || position.file == null ? templateFile : position.file;
|
|
||||||
return Context.makePosition({min:min, max:max, file:file});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function specialValue(name:String, key:String, a:Array<String>, position:JsonKeyPosition):Dynamic {
|
|
||||||
return switch (a[0]) {
|
|
||||||
case "asset":
|
|
||||||
switch (a[1]) {
|
|
||||||
case "image":
|
|
||||||
"openfl.Assets.getBitmapData(\"" + a[2] + "\")";
|
|
||||||
case _:
|
|
||||||
a[2];
|
|
||||||
}
|
|
||||||
case "res":
|
|
||||||
var res = "haxework.provider.Provider.get(haxework.resources.IResources)." + a[1];
|
|
||||||
var bindExpr = res + ".bind(\"" + a[2] + "\", " + name + ", \"" + key + "\")";
|
|
||||||
exprs.push(Context.parse(bindExpr, getPosition(position)));
|
|
||||||
//res + ".get(\"" + a[2] + "\")";
|
|
||||||
null;
|
|
||||||
case "locale":
|
|
||||||
"new haxework.locale.LString(\"" + a[1] + "\")";
|
|
||||||
case "class":
|
|
||||||
a[1];
|
|
||||||
case "layout":
|
|
||||||
var template = BuilderUtil.loadJsonFile(a[1]);
|
|
||||||
return getValue(name, key, template, position);
|
|
||||||
case "link":
|
|
||||||
"(links == null) ? untyped this : Reflect.field(links, \"" + a[1] + "\")";
|
|
||||||
case _:
|
|
||||||
Context.error("Unsupported prefix \"" + a[0] + "\"", getPosition(position));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getValue(name:String, key:String, value:Dynamic, position:JsonKeyPosition):Dynamic {
|
|
||||||
return if (Std.is(value, Array)) {
|
|
||||||
value.map(function(v) {
|
|
||||||
return getValue(null, null, v, position);
|
|
||||||
});
|
|
||||||
} else if (Std.is(value, String)) {
|
|
||||||
if (value.charAt(0) == "@") {
|
|
||||||
specialValue(name, key, value.substring(1, value.length).split(":"), position);
|
|
||||||
} else if (~/(0x|#)[A-Fa-f\d]{6}/.match(value)) {
|
|
||||||
Std.parseInt(StringTools.replace(Std.string(value), "#", "0x"));
|
|
||||||
} else {
|
|
||||||
"\"" + value + "\"";
|
|
||||||
}
|
|
||||||
} else if (Std.is(value, Float) || (Std.is(value, Bool))) {
|
|
||||||
value;
|
|
||||||
} else if (value != null) {
|
|
||||||
if (Reflect.hasField(value, "@type")) {
|
|
||||||
var n = "a" + i++;
|
|
||||||
var type = Reflect.field(value, "@type");
|
|
||||||
if (type == "Dynamic") {
|
|
||||||
//ToDo:
|
|
||||||
exprs.push(Context.parse("var " + n + " = cast {}", getPosition(position)));
|
|
||||||
} else {
|
|
||||||
exprs.push(Context.parse("var " + n + " = new " + type + "()", getPosition(position)));
|
|
||||||
}
|
|
||||||
createElement(value, n);
|
|
||||||
n;
|
|
||||||
} else {
|
|
||||||
Context.error("Need @type field", getPosition(position));
|
|
||||||
null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createElement(template:Dynamic, name:String):String {
|
|
||||||
if (Reflect.hasField(template, "@style")) {
|
|
||||||
var s = Reflect.field(style, Reflect.field(template, "@style"));
|
|
||||||
for (key in Reflect.fields(s)) {
|
|
||||||
if (key.charAt(0) != "$" && !Reflect.hasField(template, key)) {
|
|
||||||
Reflect.setField(template, key, Reflect.field(s, key));
|
|
||||||
Reflect.setField(template, "$" + key, Reflect.field(s, "$" + key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Reflect.hasField(template, "id")) {
|
|
||||||
var id = Reflect.field(template, "id");
|
|
||||||
var type = Reflect.field(template, "@type");
|
|
||||||
var expr = Context.parse("var a:" + type, getPosition());
|
|
||||||
var complexType = switch (expr.expr) {
|
|
||||||
case EVars(vars): vars[0].type;
|
|
||||||
case _: null;
|
|
||||||
}
|
|
||||||
fields.push({
|
|
||||||
name: id,
|
|
||||||
access: [APublic],
|
|
||||||
pos: getPosition(),
|
|
||||||
kind: FProp("default", "null", complexType)
|
|
||||||
});
|
|
||||||
exprs.push(Context.parse("this." + id + " = " + name, getPosition()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (key in Reflect.fields(template)) {
|
|
||||||
if (key.charAt(0) == "$" || key.charAt(0) == "@") continue;
|
|
||||||
var position = Reflect.field(template, "$" + key);
|
|
||||||
var value = getValue(name, key, Reflect.field(template, key), position);
|
|
||||||
if (value != null) {
|
|
||||||
exprs.push(Context.parse(name + "." + key + " = " + value, getPosition(position)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function build():Array<Field> {
|
|
||||||
createElement(template, "this");
|
|
||||||
|
|
||||||
var init = false;
|
|
||||||
for (f in fields) if (f.name == "init") {
|
|
||||||
init = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fields.push({
|
|
||||||
name: "build",
|
|
||||||
access: [APublic],
|
|
||||||
pos: getPosition(),
|
|
||||||
kind: FFun({
|
|
||||||
args: [{name:"links", type:TPath({name:"Dynamic", pack:[], params:[]}), opt:true, value:null}],
|
|
||||||
expr: macro $b{exprs},
|
|
||||||
params: [],
|
|
||||||
ret: null
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
var contstrExprs = [];
|
|
||||||
contstrExprs.push(macro super());
|
|
||||||
contstrExprs.push(macro build(links));
|
|
||||||
if (init) contstrExprs.push(macro init());
|
|
||||||
|
|
||||||
fields.push({
|
|
||||||
name: "new",
|
|
||||||
access: [APublic],
|
|
||||||
pos: getPosition(),
|
|
||||||
kind: FFun({
|
|
||||||
args: [{name:"links", type:TPath({name:"Dynamic", pack:[], params:[]}), opt:true, value:null}],
|
|
||||||
expr: macro $b{contstrExprs},
|
|
||||||
params: [],
|
|
||||||
ret: null
|
|
||||||
})
|
|
||||||
});
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#end
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package haxework.gui.build;
|
|
||||||
#if macro
|
|
||||||
|
|
||||||
import haxe.macro.Context;
|
|
||||||
import haxe.macro.Expr.Constant;
|
|
||||||
import haxe.macro.Expr.ExprDef;
|
|
||||||
|
|
||||||
class BuilderUtil {
|
|
||||||
|
|
||||||
public static function loadJsonFile(path:String) {
|
|
||||||
Context.registerModuleDependency(Context.getLocalModule(), path);
|
|
||||||
var content = sys.io.File.getContent(path);
|
|
||||||
var json = null;
|
|
||||||
try {
|
|
||||||
json = PositionJsonParser.parse(content, path);
|
|
||||||
} catch(error:Dynamic) {
|
|
||||||
Context.error(error, Context.makePosition({min:0, max:0, file:path}));
|
|
||||||
}
|
|
||||||
Context.parse(content, Context.makePosition({min:0, max:0, file:path}));
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getMeta(key:String):Array<String> {
|
|
||||||
var c = Context.getLocalClass().get();
|
|
||||||
for (meta in c.meta.get()) {
|
|
||||||
if (meta.name == key) {
|
|
||||||
return meta.params.map(function(param) return switch(param.expr) {
|
|
||||||
case ExprDef.EConst(Constant.CString(value)): value;
|
|
||||||
case _: null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#end
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package haxework.gui.core;
|
|
||||||
|
|
||||||
enum Direction {
|
|
||||||
HORIZONTAL;
|
|
||||||
VERTICAL;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package haxework.gui.core;
|
|
||||||
|
|
||||||
@:enum abstract HAlign(String) from String to String {
|
|
||||||
var NONE = "NONE";
|
|
||||||
var LEFT = "LEFT";
|
|
||||||
var CENTER = "CENTER";
|
|
||||||
var RIGHT = "RIGHT";
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package haxework.gui.core;
|
|
||||||
|
|
||||||
enum SizeType {
|
|
||||||
NORMAL;
|
|
||||||
PERCENT;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package haxework.gui.core;
|
|
||||||
|
|
||||||
@:enum abstract VAlign(String) from String to String {
|
|
||||||
var NONE = "NONE";
|
|
||||||
var TOP = "TOP";
|
|
||||||
var MIDDLE = "MIDDLE";
|
|
||||||
var BOTTOM = "BOTTOM";
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
package haxework.gui.frame;
|
|
||||||
|
|
||||||
import haxework.animate.IAnimate;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import haxework.gui.IView;
|
|
||||||
import haxework.gui.GroupView;
|
|
||||||
|
|
||||||
class FrameSwitcher extends GroupView implements IFrameSwitcher {
|
|
||||||
|
|
||||||
public var current(default, null):Null<IView>;
|
|
||||||
private var frames:Map<String, IView>;
|
|
||||||
|
|
||||||
public var animateFactory(default, default):Class<IAnimate>;
|
|
||||||
private var animate:IAnimate;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super();
|
|
||||||
frames = new Map<String, IView>();
|
|
||||||
current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function buildAnimate(view:IView):Null<IAnimate> {
|
|
||||||
if (animateFactory != null) {
|
|
||||||
return Type.createInstance(animateFactory, [view]);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function change(id:String):IView {
|
|
||||||
var prev = null;
|
|
||||||
if (current != null) {
|
|
||||||
if (current.id == id) return current;
|
|
||||||
prev = current;
|
|
||||||
}
|
|
||||||
current = frames.get(id);
|
|
||||||
addView(current);
|
|
||||||
//ToDo:
|
|
||||||
if (content.stage != null) content.stage.focus = cast(current, SpriteView).contentAsSprite;
|
|
||||||
var onShowMethod:Dynamic = Reflect.field(current, "onShow");
|
|
||||||
if (onShowMethod != null) Reflect.callMethod(current, onShowMethod, []);
|
|
||||||
if (animate != null) animate.cancel();
|
|
||||||
animate = buildAnimate(current);
|
|
||||||
if (animate != null && prev != null) {
|
|
||||||
animate.start(function(_) {
|
|
||||||
removePrev(prev);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
removePrev(prev);
|
|
||||||
}
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function removePrev(prev:Null<IView>):Void {
|
|
||||||
if (prev != null) {
|
|
||||||
var onHideMethod:Dynamic = Reflect.field(prev, "onHide");
|
|
||||||
if (onHideMethod != null) Reflect.callMethod(prev, onHideMethod, []);
|
|
||||||
removeView(prev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function set_views(value:Array<IView>):Array<IView> {
|
|
||||||
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.gui.frame;
|
|
||||||
|
|
||||||
import haxework.gui.IView;
|
|
||||||
|
|
||||||
interface IFrameSwitcher extends IView {
|
|
||||||
public var current(default, null):Null<IView>;
|
|
||||||
public function change(id:String):IView;
|
|
||||||
}
|
|
||||||
@@ -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, views:Array<IView>):Void {
|
|
||||||
for (view in views) {
|
|
||||||
setViewWidth(group, view);
|
|
||||||
setViewHeight(group, view);
|
|
||||||
placeViewHorizontal(group, view);
|
|
||||||
placeViewVertical(group, view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function filterViews(group:IGroupView, views:Array<IView>):Array<IView> {
|
|
||||||
return Lambda.array(Lambda.filter(views, function(view:IView):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, view:IView):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, view:IView):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, view:IView):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, view:IView):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,56 +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, views:Array<IView>):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;
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
|
|
||||||
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, views:Array<IView>):Void;
|
|
||||||
}
|
|
||||||
@@ -1,55 +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, views:Array<IView>):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;
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
|
|
||||||
for (view in views) {
|
|
||||||
view.y = y + view.topMargin;
|
|
||||||
y += (view.height + view.topMargin + view.bottomMargin + group.layoutMargin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +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());
|
|
||||||
box.layoutHAlign = HAlign.LEFT;
|
|
||||||
box.layoutVAlign = VAlign.MIDDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function recalcSize(item:IListItemView<D>):Void {
|
|
||||||
itemSize = item.width + item.leftMargin + item.rightMargin + box.layoutMargin;
|
|
||||||
size = Math.ceil(Math.max(0, box.width / itemSize)) + 2;
|
|
||||||
sizeDiff = size - ((box.width - box.layoutMargin - 1) / itemSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function set_offsetDiff(value:Float):Float {
|
|
||||||
box.leftPadding = -value * itemSize;
|
|
||||||
mask.leftMargin = -box.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<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.contentAsSprite.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 box: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);
|
|
||||||
box = new GroupView(layout);
|
|
||||||
box.pWidth = 100;
|
|
||||||
box.pHeight = 100;
|
|
||||||
main.addView(box);
|
|
||||||
mask = new SpriteView();
|
|
||||||
mask.pWidth = 100;
|
|
||||||
mask.pHeight = 100;
|
|
||||||
mask.inLayout = false;
|
|
||||||
mask.skin = new ColorSkin(0xffffff);
|
|
||||||
box.content.mask = mask.content;
|
|
||||||
box.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);
|
|
||||||
box.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);
|
|
||||||
box.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 box.layoutMargin = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IListItemView<D> extends IView {
|
|
||||||
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();
|
|
||||||
contentAsSprite.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,33 +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());
|
|
||||||
box.layoutHAlign = HAlign.CENTER;
|
|
||||||
box.layoutVAlign = VAlign.TOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function recalcSize(item:IListItemView<D>):Void {
|
|
||||||
itemSize = item.height + item.topMargin + item.bottomMargin + box.layoutMargin;
|
|
||||||
size = Math.ceil(Math.max(0, box.height / itemSize)) + 2;
|
|
||||||
sizeDiff = size - ((box.height - box.layoutMargin - 1) / itemSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function set_offsetDiff(value:Float):Float {
|
|
||||||
box.topPadding = -value * itemSize;
|
|
||||||
mask.topMargin = -box.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<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.contentAsSprite.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,47 +0,0 @@
|
|||||||
package haxework.gui.popup;
|
|
||||||
|
|
||||||
import haxework.animate.IAnimate;
|
|
||||||
import haxework.gui.Root;
|
|
||||||
import haxework.gui.IGroupView;
|
|
||||||
|
|
||||||
class PopupManager {
|
|
||||||
|
|
||||||
public var showAnimateFactory(default, default):Class<IAnimate>;
|
|
||||||
public var closeAnimateFactory(default, default):Class<IAnimate>;
|
|
||||||
|
|
||||||
private var popups:Array<PopupView<Dynamic>>;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
popups = new Array<PopupView<Dynamic>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show(popup:PopupView<Dynamic>):Void {
|
|
||||||
cast(Root.instance.view, IGroupView).addView(popup);
|
|
||||||
if (showAnimateFactory != null) {
|
|
||||||
Type.createInstance(showAnimateFactory, [popup]).start(null);
|
|
||||||
}
|
|
||||||
popups.push(popup);
|
|
||||||
popup.onShow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function close(popup:PopupView<Dynamic>):Void {
|
|
||||||
popups.remove(popup);
|
|
||||||
if (closeAnimateFactory != null) {
|
|
||||||
Type.createInstance(closeAnimateFactory, [popup]).start(function(_) {
|
|
||||||
cast(Root.instance.view, IGroupView).removeView(popup);
|
|
||||||
popup.onClose();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
cast(Root.instance.view, IGroupView).removeView(popup);
|
|
||||||
popup.onClose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function closeTop():Bool {
|
|
||||||
if (popups.length > 0) {
|
|
||||||
close(popups[popups.length - 1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package haxework.gui.popup;
|
|
||||||
|
|
||||||
import promhx.Deferred;
|
|
||||||
import haxe.Timer;
|
|
||||||
import haxework.provider.Provider;
|
|
||||||
import haxework.dispath.Dispatcher;
|
|
||||||
import haxework.dispath.IDispatcher;
|
|
||||||
import haxework.gui.IGroupView;
|
|
||||||
import haxework.gui.ButtonView;
|
|
||||||
import haxework.gui.skin.ColorSkin;
|
|
||||||
import haxework.gui.GroupView;
|
|
||||||
|
|
||||||
class PopupView<V:IView> extends GroupView {
|
|
||||||
|
|
||||||
private var buttonId:String;
|
|
||||||
private var contentView:V;
|
|
||||||
private var deferred:Deferred<String>;
|
|
||||||
|
|
||||||
public function new(contentViewFactory:Class<V>) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
pWidth = 100;
|
|
||||||
pHeight = 100;
|
|
||||||
inLayout = false;
|
|
||||||
skin = new ColorSkin(0x000000, 0.6);
|
|
||||||
|
|
||||||
this.contentView = Type.createInstance(contentViewFactory, [{listener:this}]);
|
|
||||||
addView(contentView);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onPress(button:ButtonView) {
|
|
||||||
this.buttonId = button.id;
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show():Deferred<String> {
|
|
||||||
Provider.get(PopupManager).show(this);
|
|
||||||
deferred = new Deferred<String>();
|
|
||||||
return deferred;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function close():Void {
|
|
||||||
Provider.get(PopupManager).close(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
buttonId = "close";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onClose():Void {
|
|
||||||
if (deferred != null) {
|
|
||||||
deferred.resolve(buttonId);
|
|
||||||
deferred = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<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.contentAsSprite.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,70 +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<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;
|
|
||||||
public var disableImage(null, default):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 ? disableImage == null ? disable : disableImage : images.get(view.state);
|
|
||||||
DrawUtil.draw(view.contentAsSprite.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user