117 Commits
0.8.0 ... 1.3.0

Author SHA1 Message Date
7b7819fe6e [view] fix change in FrameSwitcher 2020-02-28 21:58:49 +03:00
2428ed20e0 [yaml] use yaml 2.0.0 library 2020-02-21 14:10:24 +03:00
bc3d6e4458 [view] add stretch param to TailLayout 2020-02-19 20:52:25 +03:00
d217727d94 [demo] add TestStorage 2020-02-13 22:31:10 +03:00
c889ca04da [yaml] add sources 2020-02-13 17:20:50 +03:00
39ca4b3d9b [style] rework 2020-02-11 22:47:03 +03:00
f81ab02e67 [geom] addd 2020-02-11 22:46:47 +03:00
284593e82c [view] add ConfirmView 2020-02-07 17:02:56 +03:00
a311dc1c19 [view] add AlertView 2020-02-06 17:10:19 +03:00
07c228121c [view] add back method to frame switcher 2020-02-05 23:18:29 +03:00
a6ff04fd1b [macro] TemplateMacro: move init to constructor 2019-11-19 21:53:33 +03:00
a768e75cec [demo] fixes 2019-11-19 17:51:30 +03:00
7a5b32b251 [macro] add ClassProvideMacro 2019-11-18 18:00:55 +03:00
74ed2d4425 [macro] add ClassTypeMacro and FieldMacro 2019-11-15 16:32:57 +03:00
fcbac5587e [view] add focus method 2019-11-14 16:48:51 +03:00
78f4ae3a03 [view] popup close fix 2019-11-10 17:03:24 +03:00
b18b9d2d30 [macro] add SignletonMacro 2019-10-30 22:15:46 +03:00
c88a2c810f [view] fix onTouchEnd in GroupView 2019-09-29 12:26:28 +03:00
a253aeaed4 [view] SpriteSkin: add round param 2019-09-11 21:04:42 +03:00
3478963a6f [view] add ActionDataView 2019-09-11 17:52:30 +03:00
5989da3fe4 [view] ListView: add selected style 2019-09-10 19:48:08 +03:00
32309389e5 Merge branch 'master' of bitbucket.org:shmyga/haxework 2019-09-09 21:46:03 +03:00
3d54a2489b [view] DataView: add onDataAction signal 2019-09-09 21:45:39 +03:00
7a68604cad [log] add AndroidLog 2019-08-23 14:38:27 +03:00
f31b1ce506 [view] GroupView: add maskEnable; Color: fromString improve 2019-07-29 17:57:11 +03:00
f186b08e9f build fixes 2019-07-22 23:25:18 +03:00
e2bda0fefa [view] fix InputView 2019-07-22 22:59:03 +03:00
af5a4319f7 [view] fix layouts 2019-07-22 17:45:18 +03:00
da5616bf47 [view] fixes 2019-07-19 16:38:29 +03:00
ec42687d1b [view] remove ScrollView, add scrolls to GroupView 2019-07-18 17:55:55 +03:00
ddc8581445 [view] add Style 2019-07-18 14:21:52 +03:00
8122349668 [view] remove old styles 2019-07-17 17:48:09 +03:00
374b286ebb [view] fix view size 2019-07-16 20:12:02 +03:00
37e6f3d7f8 [view] add style meta to Layout 2019-07-16 17:56:01 +03:00
451b107f6b [macro] update StyleMacro 2019-07-16 14:53:36 +03:00
d52d8ff4f3 [macro] add StyleMacro 2019-07-16 11:44:32 +03:00
5faa179116 [view] fixes 2019-07-13 16:14:27 +03:00
b488e6f88a [view] fixes 2019-07-13 12:48:01 +03:00
6274bd271e [view] fixes 2019-07-12 21:15:01 +03:00
b9908f2d5b [view] fixes 2019-07-12 17:08:58 +03:00
2dbfe79371 [view] fixes 2019-07-12 12:12:20 +03:00
ce17fff6df [view] rework view size system 2019-07-12 11:10:35 +03:00
0a072562cb [view] fix InputView 2019-07-11 22:12:31 +03:00
ce4f6854f7 [theme] use ResMap for theme skins 2019-07-10 19:43:19 +03:00
4f3a6c5174 [view] reorganize packages 2019-07-09 22:09:32 +03:00
215d820e68 [view] add Theme 2019-07-09 17:44:48 +03:00
61e74a3755 [view] add SelectView 2019-07-09 12:03:38 +03:00
34cb98beb1 [demo] update 2019-06-27 10:51:28 +03:00
68c0c4d35f [view] remove trace 2019-06-24 22:10:36 +03:00
09d18808b4 [view] add FrameView 2019-06-24 22:09:22 +03:00
cdfc3fd344 [provider] add Enum support 2019-06-24 18:03:25 +03:00
b9c70a6512 Merge branch 'master' of bitbucket.org:shmyga/haxework 2019-06-18 17:07:59 +03:00
7b047e068e [view] add ButtonGroup; fixes 2019-06-18 17:07:41 +03:00
d192babccc [view] fix InputView text update on input 2019-06-13 21:41:47 +03:00
735e4c1444 [view] fix ScrollView position 2019-06-13 21:41:25 +03:00
400d91ef6e [view] fix layouts resize 2019-06-07 17:19:07 +03:00
b7ad9df8af [view] hide new items in ListView 2019-06-06 20:02:29 +03:00
6003158199 [signal] fix disconnect on neko platform 2019-05-24 15:20:50 +03:00
bdaf3504e3 [view] popup: add onShow and onClose methods 2019-05-21 21:15:20 +03:00
349916e504 [storage] add delete method 2019-05-13 22:35:46 +03:00
53460a1ad6 [provider] return null instead throw error 2019-05-13 17:34:24 +03:00
7fe246e8d3 [dispatcher] rename signal vars 2019-04-22 10:36:07 +03:00
1d4fd3b2a9 [dispatcher] add dispatcher macro 2019-04-21 15:29:43 +03:00
7c879ee159 [translate] add 2019-04-19 12:05:21 +03:00
cd6ad0e3ed [view] layout/skin fixes 2019-04-18 17:51:17 +03:00
3638c8d2b6 [view] add Geometry size ratio param 2019-04-17 16:42:26 +03:00
c5002ec3fe [skin] add borderColor to ButtonColorSkin 2019-04-08 21:45:24 +03:00
33f4b3eea0 [signal] add Signal0 2019-04-07 20:46:35 +03:00
493a319ef5 [view] remove InputTextView 2019-04-05 16:47:16 +03:00
b87338cbef [view] ImageView stretc true as default 2019-04-04 20:41:32 +03:00
de0a7a3687 [view] big update 2019-04-04 17:11:33 +03:00
a29594e79c [view] dataViews attribute on DatView 2019-04-03 21:15:49 +03:00
5c564f8bb1 [view] check fontSize in TextSkin 2019-04-02 23:32:07 +03:00
56122a37c3 [storage] use haxe Serializer/Deserializer 2019-03-29 11:49:41 +03:00
d55201ecc0 [view] fix ImageView color 2019-03-28 17:38:15 +03:00
22e7894c03 [view] rename from gui 2019-03-25 16:24:57 +03:00
ad504de290 [gui] fix TailLayout margin 2019-03-25 16:01:16 +03:00
9fb1c1405f [gui] fontEmbed param in TextSkin 2019-03-22 15:47:11 +03:00
bee0fc7562 [gui] Box fix 2019-03-21 20:26:09 +03:00
7ed1515072 [skin] update ButtonColorSkin 2019-03-21 17:44:03 +03:00
58674f3572 [gui] add LayoutSkin 2019-03-20 17:35:50 +03:00
7a1a98daf3 [gui] add GeometrySkin 2019-03-19 22:47:02 +03:00
0771e89873 [macro] update ProvideMacro 2019-03-15 16:16:29 +03:00
80c200f5f7 [gui] fix layouts 2019-03-13 13:06:23 +03:00
301360df31 [gui] public setContentSize method in View 2019-03-12 17:20:58 +03:00
a07d9eb366 fixes for openfl html5 build 2019-03-11 22:37:31 +03:00
d86b1c713b [skin] fix ButtonColorSkin 2019-03-11 17:50:46 +03:00
62ddbb683e add Color abstract 2019-03-11 17:02:34 +03:00
8c0991adb0 [gui] fix 2019-03-06 17:48:13 +03:00
b0824773c9 [gui] update 2019-03-06 17:07:26 +03:00
c2ab82b351 remove unused code 2019-03-05 17:36:47 +03:00
3f842f4cfc [gui] add TailLayout rowSize 2019-03-05 16:38:34 +03:00
f1302e5636 [gui] add SizeValue wrapper 2019-03-04 21:12:05 +03:00
02e5481bbd [gui] update DataView 2019-03-04 18:00:11 +03:00
66f0e79297 [gui] add DataView 2019-03-01 17:33:01 +03:00
cad4faa580 [gui] update 2019-03-01 16:29:53 +03:00
3e06e5df26 [gui] update 2019-03-01 12:48:07 +03:00
020fb23188 [gui] layouts fixes 2019-02-28 17:52:20 +03:00
b3196d2295 [gui] update 2019-02-27 18:00:48 +03:00
d819271cd3 [gui] add view geometry 2019-02-27 16:57:31 +03:00
71995ef672 [macro] signal macro expression wrap with function 2019-02-27 12:26:37 +03:00
d4aeffb8a6 [demo] update 2019-02-27 11:49:55 +03:00
34c6a269de [skin] process contentSize views in bitmap skins 2019-02-25 17:39:17 +03:00
5cd1bbc30a [skin] update 2019-02-22 15:38:34 +03:00
78ecd35587 [demo] update 2019-02-13 10:53:43 +03:00
e517c0a298 [skin] update 2019-02-07 17:55:49 +03:00
eeb659622c [macro] update template parser 2019-02-07 12:24:13 +03:00
9182210001 [samples] update loader sample 2019-02-06 23:01:39 +03:00
bc2bb7d125 [gui] udpate skins and dispatchers 2019-02-06 17:59:13 +03:00
6c0bb2af8c up openfl library version 2018-10-12 14:13:56 +03:00
7f28abd635 [macro] add @:style macro 2018-08-09 12:14:58 +03:00
7d26241584 [macro] add setter in @:provide macro 2018-08-09 12:14:33 +03:00
2b9cea80bc [gui] Hide ScrollSkin if scroll ratio=1 2018-07-27 17:27:56 +03:00
a518daed82 [log] use Stdio in TraceLogger for cpp 2018-04-27 21:55:32 +03:00
35caa8571a [fix] TraceLogger in html5 2018-04-27 16:07:31 +03:00
167d43342a [log] use custom print in TraceLogger 2018-04-06 16:30:31 +03:00
4487aedee7 [log] update 2018-03-19 17:38:43 +03:00
223 changed files with 6455 additions and 4259 deletions

9
.editorconfig Normal file
View 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

View File

@@ -8,28 +8,29 @@ Gui framework for Haxe.
### Example ### Example
Build form using `haxework.gui.ViewBuilder`. Build form using macro @:template.
form.json: form.json:
```json ```json
{ {
"@type":"haxework.gui.VGroupView", "$type": "haxework.gui.VGroupView",
"skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0xffff00"}, "skin": [{"$type": "haxework.gui.skin.ColorSkin", "color": "0xffff00"}],
"paddings":20, "geometry.padding": 20,
"layoutMargin":10, "layout.margin": 10,
"views":[ "views":[
{ {
"id": "view1", "id": "view1",
"type":"haxework.gui.SpriteView", "type":"haxework.gui.SpriteView",
"pWidth":100, "pHeight":100, "geometry.size.stretch": true,
"skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"} "skin":[{"$type":"haxework.gui.skin.ColorSkin", "color": "0xff0000"}]
}, },
{ {
"id": "view2", "id": "view2",
"type": "haxework.gui.SpriteView", "type": "haxework.gui.SpriteView",
"pWidth":100, "height":50, "geometry.size.width": "100%",
"skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"} "geometry.size.height": 50,
"skin": [{"$type":"haxework.gui.skin.ColorSkin", "color": "0x00ff00"}]
} }
] ]
} }
@@ -38,8 +39,8 @@ form.json:
```haxe ```haxe
@:template("form.json") @:template("form.json")
class FormView extends VGroupView { class FormView extends VGroupView {
@:view public var view1:IView; @:view public var view1:SpriteView;
@:view("view2") public var anyVarName:IView; @:view("view2") public var anyVarName:SpriteView;
} }
var form = new FormView(); var form = new FormView();

15
demo/build.hxml Executable file
View File

@@ -0,0 +1,15 @@
-cp src
#-cp ../src/main
-lib yaml
-lib promhx
-lib haxework
--macro haxework.parser.Parser.auto()
-debug
-D native_trace
#-D dev_layout
-swf-version 10.1
-swf-header 800:600:30:000000
-main demo.Demo
-swf target/demo.swf
#-as3 target

26
demo/project.xml Normal file
View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<meta title="Demo" package="haxework.demo" version="1.0.0" company="MegaLoMania"/>
<app main="demo.Demo" path="target" file="demo"/>
<icon path="src/haxe-logo.png"/>
<source path="../src/main"/>
<source path="src"/>
<assets path="src" rename="image" include="*.png"/>
<haxelib name="lime" version=""/>
<haxelib name="openfl" version=""/>
<haxelib name="hxcpp" version=""/>
<!--<haxelib name="promhx" version=""/>-->
<haxelib name="haxework" version="git"/>
<!--<haxeflag name="&#45;&#45;macro" value="haxework.parser.Parser.auto()"/>-->
<haxeflag name="--macro" value="CompilationOption.set('build','xxx')"/>
<window fps="30"/>
<window width="1024" height="768" unless="html5"/>
<haxeflag name="-D" value="swf-gpu"/>
<haxeflag name="-D" value="native-trace"/>
<haxeflag name="-dce" value="no"/>
</project>

7
demo/run.sh Executable file
View 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
View 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
View File

@@ -0,0 +1,26 @@
package demo;
import haxework.view.geometry.Box;
import haxework.color.Color;
import haxework.view.theme.Theme;
using haxework.color.ColorUtil;
class AppTheme extends Theme {
public function new(?color:Color, ?textColor:Color):Void {
super({name: "Courirer"}, {light: color, text: textColor});
}
override private function reload():Void {
super.reload();
register(new Style("view", [
"skin.background.color" => colors.light,
"skin.border.color" => colors.border,
"geometry.padding" => Box.fromFloat(3),
], ["text"]));
register(new Style("test", [
"skin.background.color" => Color.fromInt(0x00ffff),
]));
}
}

98
demo/src/demo/Demo.hx Normal file
View File

@@ -0,0 +1,98 @@
package demo;
import demo.storage.TestStorage;
import haxework.resources.IResources;
import haxework.provider.Provider;
import demo.dispatch.DemoDispatcher;
import demo.popup.ColorPopup;
import demo.popup.FontPopup;
import haxework.App;
import haxework.log.TraceLogger;
import haxework.net.JsonLoader;
import haxework.view.data.ButtonGroup;
import haxework.view.frame.FrameSwitcher;
import haxework.view.frame.FrameView;
import haxework.view.group.VGroupView;
@:template class DemoView extends VGroupView {
@:view var switcher:FrameSwitcher;
@:view var tabs:ButtonGroup<String>;
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 resources:IResources;
@:provide static var storage:TestStorage;
public static function main() {
L.push(new TraceLogger());
resources.image.put("logo", HaxeLogo.resolve());
var app = new Demo(new AppTheme(), resources.image.get("logo"));
app.start(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>) {
resources.any.put("data", data);
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);
}
}

View File

@@ -0,0 +1,54 @@
---
style: background
views:
- $type: haxework.view.ImageView
geometry.padding: 10
image: $r:image:logo
- id: tabs
$type: haxework.view.data.ButtonGroup<String>
layout.margin: 5
layout.hAlign: left
geometry.width: 100%
geometry.padding.left: 5
geometry.margin.bottom: -6
buttonStyle: button.tab
+onDataSelect: ~function(id) switcher.change(id)
data:
- "list"
- "tail"
- "data"
- "test_layout"
- "select"
- id: switcher
$type: haxework.view.frame.FrameSwitcher
animateFactory: { $class: haxework.animate.SlideAnimate }
+onSwitch: ~onFrameSwitch
geometry.stretch: true
geometry.padding: 5
factory:
_list_: {$class: demo.form.ListForm}
_tail_: {$class: demo.form.TailForm}
_data_: {$class: demo.form.DataForm}
_test_layout_: {$class: demo.form.TestLayoutForm}
_select_: {$class: demo.form.SelectForm}
- $type: haxework.view.group.HGroupView
geometry.width: 100%
geometry.padding: 10
layout.margin: 10
views:
- $type: haxework.view.form.ButtonView
text: Color
+onPress: ~choiceColor()
- $type: haxework.view.form.ButtonView
text: Font
+onPress: ~choiceFont()
# separator
- $type: haxework.view.SpriteView
geometry.stretch: true
- $type: haxework.view.form.ButtonView
text: OK
- $type: haxework.view.form.ButtonView
text: Apply
- $type: haxework.view.form.ButtonView
text: Cancel
+onPress: ~flash.system.System.exit(0)

17
demo/src/demo/HaxeLogo.hx Normal file
View 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
View 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
View File

@@ -0,0 +1,17 @@
package demo;
import demo.test.TestView;
import haxework.view.Root;
import haxework.view.SpriteView;
class Test {
public static function main():Void {
new Test();
}
public function new() {
trace("Test");
var view = new SpriteView();
Root.bind(new TestView());
}
}

12
demo/src/demo/Util.hx Normal file
View 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;
}
}

View File

@@ -0,0 +1,14 @@
package demo.dispatch;
import haxework.App;
interface DemoListener {
public function onTest1():Void;
public function onTest2(a:Int):Void;
public function onTest3(a:Int, b:String):Void;
public function onTest4(app:App):Void;
}
@:dispatcher(DemoListener) class DemoDispatcher {
public function new() {}
}

View File

@@ -0,0 +1,19 @@
package demo.form;
import haxework.view.frame.FrameView;
import haxework.view.text.TextView;
@:template class DataForm extends FrameView<Dynamic> {
public function new() {
super("data");
}
private function factory(index:Int, value:Model):TextView {
var label = new TextView();
label.geometry.width.percent = 100;
label.geometry.margin = 1;
label.geometry.padding = 2;
label.text = (value.title != null ? '${value.title}\n-\n' : '') + value.message;
return label;
}
}

View File

@@ -0,0 +1,10 @@
---
overflow.y: scroll
views:
- id: data
$type: haxework.view.data.DataView
layout:
$type: haxework.view.layout.VerticalLayout
factory: ~factory
geometry.width: 100%
data: $r:any:data

View File

@@ -0,0 +1,22 @@
package demo.form;
import haxework.view.frame.FrameView;
import haxework.view.list.LabelListItem;
import haxework.view.list.ListView.IListItemView;
import haxework.view.list.VListView;
@:template class ListForm extends FrameView<Dynamic> {
@:view public var list(default, null):VListView<Model>;
public function new() {
super("list");
}
private function factory() {
return new LabelListItem(function(index:Int, value:Model) return '${index}. ${value.id}: ${value.title}');
}
private function onItemSelect(item:IListItemView<Model>):Void {
trace('onItemSelect: ${item.data.id}');
}
}

View File

@@ -0,0 +1,10 @@
---
views:
- id: list
$type: haxework.view.list.VListView
+onItemSelect: ~onItemSelect
factory: ~factory
geometry.stretch: true
scroll:
$type: haxework.view.list.VScrollBarView
data: $r:any:data50

View File

@@ -0,0 +1,9 @@
package demo.form;
import haxework.view.frame.FrameView;
@:template class SelectForm extends FrameView<Dynamic> {
public function new() {
super("select");
}
}

View File

@@ -0,0 +1,31 @@
---
geometry.padding: 10
layout.margin: 5
views:
- $type: haxework.view.form.SelectView<String>
layout.margin: 2
dataView.layout.margin: 1
data:
- "value 1"
- "value 2"
- "value 3"
- "value 4"
selected: "value 1"
+onSelect: ~function(value) trace('select', value)
- $type: haxework.view.form.SelectView.SelectIdView<{id:Int,label:String}, Int>
layout.margin: 2
dataView.layout.margin: 1
labelBuilder: |
~function(item:{id:Int,label:String}):String {
var result = item.label;
result += " (" + item.id + ")";
return result;
}
data:
- {id: 1, label: "Aaaaaaaa", $type: Dynamic}
- {id: 2, label: "Bbbbbb", $type: Dynamic}
- {id: 3, label: "Cccc", $type: Dynamic}
- {id: 4, label: "Ddd", $type: Dynamic}
selectedId: 1
+onSelect: ~function(value) trace('select', value)

View File

@@ -0,0 +1,34 @@
package demo.form;
import haxework.view.frame.FrameView;
import haxework.view.ImageView;
import haxework.view.IView;
import haxework.view.text.TextView;
import haxework.view.utils.DrawUtil;
@:template class TailForm extends FrameView<Dynamic> {
public function new() {
super("tail");
}
private function factory(index:Int, value:Model):IView<Dynamic> {
var view:IView<Dynamic>;
if (value.image != null) {
var imageView = new ImageView();
imageView.style = "view";
imageView.stretch = false;
//imageView.style = "border";
imageView.fillType = FillType.CONTAIN;
imageView.imageUrl = value.image.url;
view = imageView;
} else {
var textView = new TextView();
textView.style = "view";
textView.text = '${value.id}\n${value.maker}';
view = textView;
}
view.setSize(350, 200);
return view;
}
}

View File

@@ -0,0 +1,12 @@
---
overflow.y: scroll
views:
- id: data
$type: haxework.view.data.DataView
geometry.padding: 4
layout:
$type: haxework.view.layout.TailLayout
margin: 6
factory: ~factory
geometry.width: 100%
data: $r:any:data

View File

@@ -0,0 +1,24 @@
package demo.form;
import flash.events.MouseEvent;
import haxework.view.frame.FrameView;
import haxework.view.SpriteView;
@:template class TestLayoutForm extends FrameView<Dynamic> {
@:view var render:SpriteView;
public function new() {
super("test_layout");
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");
}
}

View File

@@ -0,0 +1,53 @@
---
views:
- id: main
$type: haxework.view.group.VGroupView
geometry.stretch: true
layout.hAlign: center
layout.vAlign: middle
views:
- id: container
$type: haxework.view.group.VGroupView
layout.margin: 10
skin:
$type: [haxework.view.skin.Skin.color, 0xffff00]
views:
- id: top
$type: haxework.view.group.GroupView
layout.hAlign: center
geometry.width: 100%
geometry.height: 20
style: test
- id: middle
$type: haxework.view.group.HGroupView
layout.margin: 10
views:
- id: left
$type: haxework.view.group.GroupView
layout.vAlign: middle
geometry.width: 20
geometry.height: 100%
style: test
- id: render
$type: haxework.view.SpriteView
#geometry.width: 300
#geometry.height: 200
style: test
- id: right
$type: haxework.view.group.GroupView
layout.vAlign: middle
geometry.width: 20
geometry.height: 100%
style: test
views:
- $type: haxework.view.SpriteView
geometry.width: 100
geometry.height: 100%
skin:
$type: [haxework.view.skin.Skin.color, 0xff0000]
- id: bottom
$type: haxework.view.group.GroupView
layout.hAlign: center
style: test
geometry.width: 100%
geometry.height: 20

View File

@@ -0,0 +1,16 @@
package demo.popup;
import haxework.view.form.ButtonView;
import haxework.view.popup.PopupView;
import haxework.view.skin.Skin;
@:template class ColorPopup extends PopupView<Null<Int>> {
private function colorViewFactory(index:Int, color:Int) {
var view = new ButtonView();
view.setSize(48, 48, "fixed");
view.geometry.padding = 0;
view.skin = Skin.buttonColor(color);
return view;
}
}

View File

@@ -0,0 +1,33 @@
---
view:
$type: haxework.view.group.VGroupView
geometry.width: 400
geometry.height: 200
geometry.padding: 10
geometry.hAlign: center
geometry.vAlign: middle
style: frame
views:
- id: colors
$type: haxework.view.data.DataView
geometry.stretch: true
layout:
$type: haxework.view.layout.TailLayout
vAlign: middle
margin: 5
factory: ~colorViewFactory
data:
- 0x33AA33
- 0xAA3333
- 0xFFCC55 # 0x555555
- 0xCC33AA
- 0x3333AA
+onDataSelect: ~close
- $type: haxework.view.group.HGroupView
geometry.width: 100%
layout.hAlign: right
layout.margin: 10
views:
- $type: haxework.view.form.ButtonView
text: Cancel
+onPress: ~reject('cancel')

View File

@@ -0,0 +1,48 @@
package demo.popup;
import flash.text.Font;
import flash.text.FontType;
import haxework.view.list.LabelListItem;
import haxework.view.list.ListView;
import haxework.view.popup.PopupView;
import haxework.view.theme.ITheme;
class FontLabelView extends LabelListItem<ThemeFont> {
override private function set_data(value:ThemeFont):ThemeFont {
style = item_index % 2 == 0 ? "light" : "dark";
data = value;
text = value.name;
font.family = value.name;
font.embed = value.embed;
return data;
}
}
@:template class FontPopup extends PopupView<ThemeFont> {
@:view var fonts:ListView<ThemeFont>;
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();
}

View File

@@ -0,0 +1,25 @@
---
view:
$type: haxework.view.group.VGroupView
geometry.width: 400
geometry.height: 80%
geometry.padding: 10
geometry.hAlign: center
geometry.vAlign: middle
style: frame
views:
- id: fonts
$type: haxework.view.list.VListView
geometry.stretch: true
factory: ~fontViewFactory
+onItemSelect: ~function(item) close(item.data)
scroll:
$type: haxework.view.list.VScrollBarView
- $type: haxework.view.group.HGroupView
geometry.width: 100%
geometry.margin.top: 10
layout.hAlign: right
views:
- $type: haxework.view.form.ButtonView
text: Cancel
+onPress: ~reject('cancel')

View File

@@ -0,0 +1,10 @@
package demo.storage;
import haxework.storage.SharedObjectStorage;
@:provide class TestStorage extends SharedObjectStorage {
public function new() {
super("test");
}
}

View File

@@ -0,0 +1,7 @@
package demo.test;
import haxework.view.group.GroupView;
@:template class TestView extends GroupView {
}

View File

@@ -0,0 +1,61 @@
---
geometry.padding: 10
views:
- $type: haxework.view.group.HGroupView
geometry.padding: 10
geometry.width: 100%
layout.margin: 10
layout.vAlign: middle
skin:
$type: haxework.view.skin.SpriteSkin
background.color: 0xffff00
background.alpha: 1
views:
- $type: haxework.view.SpriteView
geometry.width: 100
geometry.height: 100
skin:
$type: haxework.view.skin.SpriteSkin
background.color: 0xff0000
background.alpha: 1
- $type: haxework.view.group.VGroupView
geometry.padding: 10
layout.margin: 10
skin:
$type: haxework.view.skin.SpriteSkin
background.color: 0x00ffff
background.alpha: 1
views:
- $type: haxework.view.SpriteView
geometry.width: 100
geometry.height: 100
size:
_test_: [200, 200]
skin:
$type: haxework.view.skin.SpriteSkin
background.color: 0xff0000
background.alpha: 1
- $type: haxework.view.SpriteView
geometry.width: 100
geometry.height: 100
skin:
$type: haxework.view.skin.SpriteSkin
background.color: 0xff0000
background.alpha: 1
- $type: haxework.view.text.TextView
geometry.padding: 20
text: "Azazaza"
- $type: haxework.view.SpriteView
geometry.width: 60%
geometry.height: 100%
skin:
$type: haxework.view.skin.SpriteSkin
background.color: 0xff0000
background.alpha: 1
- $type: haxework.view.SpriteView
geometry.width: 40%
geometry.height: 80%
skin:
$type: haxework.view.skin.SpriteSkin
background.color: 0xff0000
background.alpha: 1

BIN
demo/src/haxe-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -1,16 +1,21 @@
{ {
"name": "haxework", "name": "haxework",
"url" : "https://bitbucket.org/shmyga/haxework.git", "url": "https://bitbucket.org/shmyga/haxework",
"license": "BSD", "license": "MIT",
"tags": ["flash", "openfl"], "tags": [
"description": "Framework.", "view",
"version": "0.8.0", "layout",
"template"
],
"description": "View framework.",
"version": "1.3.0",
"releasenote": "Update.", "releasenote": "Update.",
"contributors": ["shmyga"], "contributors": [
"shmyga"
],
"classPath": "src/main", "classPath": "src/main",
"dependencies": { "dependencies": {
"promhx": "1.1.0", "promhx": "1.1.0",
"openfl": "7.0.0", "yaml": "2.0.0"
"yaml": "1.3.0"
} }
} }

View File

@@ -1,9 +0,0 @@
-cp src
-cp ../../src/main
-lib yaml
-lib promhx
-main ViewExample.hx
--macro haxework.parser.Parser.auto()
-swf target/ViewExample.swf
#-as3 target

View File

@@ -1,39 +0,0 @@
package;
import haxework.gui.View;
import haxework.gui.VGroupView;
import haxework.gui.ButtonView;
import haxework.gui.Root;
@:template2("form.json")
class FormView extends VGroupView {
@:view public var panel(default, null):View;
@:view public var button1(default, null):View;
@:view public var button2(default, null):View;
@:view public var button3(default, null):View;
private function init() {
trace('Init');
}
}
class ViewExample {
public static function main() {
new ViewExample();
}
public function new() {
var form:FormView = new FormView();
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);
}
}

View File

@@ -1,63 +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"
},
{
"id":"button2",
"@type":"haxework.gui.ButtonView",
"contentSize":true,
"skin":{"@type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cc00"},
"text":"Text2",
"fontFamily":"Georgia",
"fontColor":"0xffffff"
},
{
"id":"button3",
"@type":"haxework.gui.ButtonView",
"contentSize":true,
"skin":{"@type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cccc"},
"text":"Text 3333333333 ddd",
"fontFamily":"Tahoma",
"fontColor":"0xff0000"
}
]
}
]
}

View File

@@ -1,6 +0,0 @@
-cp src
-lib promhx
-lib haxework
-main LoaderExample.hx
-swf-version 10.1
-swf target/LoaderExample.swf

View File

@@ -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);
});
}
}

View File

@@ -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 {};
}
}

35
src/main/haxework/App.hx Normal file
View File

@@ -0,0 +1,35 @@
package haxework;
import flash.display.BitmapData;
import flash.Lib;
import haxework.animate.Animate;
import haxework.animate.FadeAnimate;
import haxework.animate.UnFadeAnimate;
import haxework.view.IView;
import haxework.view.popup.PopupManager;
import haxework.view.Root;
import haxework.view.theme.ITheme;
class App {
@:provide var app:App;
@:provide var theme:ITheme;
@:provide var popupManager:PopupManager;
public function new(?theme:ITheme, ?icon:BitmapData) {
this.theme = theme;
#if linux
if (icon != null) {
haxework.app.LinuxIcon.value = icon;
}
#end
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v);
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v);
app = this;
}
public function start(view:IView<Dynamic>) {
Animate.bind(Lib.current.stage);
Root.bind(view);
}
}

View File

@@ -1,9 +1,12 @@
package haxework.animate; package haxework.animate;
import openfl.events.Event; import flash.display.DisplayObject;
import flash.display.Stage; import flash.display.Stage;
import flash.events.Event;
import haxework.view.IView;
class Animate implements IAnimate { class Animate implements IAnimate {
public static var defaultDuraion = 300;
private static var running:Array<IAnimate> = new Array<IAnimate>(); private static var running:Array<IAnimate> = new Array<IAnimate>();
@@ -21,15 +24,23 @@ class Animate implements IAnimate {
} }
private var callback:Animate -> Void; private var callback:Animate -> Void;
private var view:IView<Dynamic>;
private var duration:Int; private var duration:Int;
private var startTime:Float; private var startTime:Float;
private var progress:Float; private var progress:Float;
public function new(duration:Int) { private var object(get, null):DisplayObject;
this.duration = duration;
public function new(view:IView<Dynamic>, duration:Int = -1) {
this.view = view;
this.duration = duration > -1 ? duration : defaultDuraion;
} }
public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void { private inline function get_object():DisplayObject {
return cast view.content;
}
public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
startTime = Date.now().getTime(); startTime = Date.now().getTime();
this.callback = callback; this.callback = callback;
if (!custom) running.push(this); if (!custom) running.push(this);

View File

@@ -1,26 +1,25 @@
package haxework.animate; package haxework.animate;
import flash.display.DisplayObjectContainer; import flash.display.DisplayObject;
import haxework.animate.IAnimate;
import flash.display.Sprite; import flash.display.Sprite;
import haxework.gui.IView;
import haxework.animate.Animate; import haxework.animate.Animate;
import haxework.animate.IAnimate;
import haxework.view.IView;
class CircleMaskAnimate extends Animate { class CircleMaskAnimate extends Animate {
private var view:IView;
private var mask:Sprite; private var mask:Sprite;
private var cyrcle:Sprite; private var cyrcle:Sprite;
private var size:Float; private var size:Float;
public function new(view:IView, ?duration:Int = 1000) { public function new(view:IView<DisplayObject>, duration:Int = -1) {
super(duration); super(view, duration);
this.view = view; this.view = view;
this.mask = new Sprite(); this.mask = new Sprite();
this.cyrcle = new Sprite(); this.cyrcle = new Sprite();
} }
override public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void { override public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
var width = view.parent.width; var width = view.parent.width;
var height = view.parent.height; var height = view.parent.height;
size = Math.sqrt(width * width + height * height); size = Math.sqrt(width * width + height * height);
@@ -44,7 +43,7 @@ class CircleMaskAnimate extends Animate {
mask.graphics.endFill(); mask.graphics.endFill();
cyrcle.graphics.clear(); cyrcle.graphics.clear();
cyrcle.graphics.lineStyle(8, 0xffffff); cyrcle.graphics.lineStyle(4, 0xffffff);
cyrcle.graphics.drawCircle(size + size / 2, size + size / 2, r / 2); cyrcle.graphics.drawCircle(size + size / 2, size + size / 2, r / 2);
cyrcle.graphics.lineStyle(); cyrcle.graphics.lineStyle();
} }

View File

@@ -1,29 +1,20 @@
package haxework.animate; package haxework.animate;
import haxework.animate.IAnimate;
import flash.display.Sprite;
import haxework.gui.IView;
import haxework.animate.Animate; import haxework.animate.Animate;
import haxework.animate.IAnimate;
class FadeAnimate extends Animate { class FadeAnimate extends Animate {
private var view:IView; override public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
object.alpha = 1.0;
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); super.start(callback, custom);
} }
override private function update(time:Float):Void { override private function update(time:Float):Void {
super.update(time); super.update(time);
view.content.alpha = 1 - (progress * 1.0); object.alpha = 1 - (progress * 1.0);
if (progress >= 1) { if (progress >= 1) {
view.content.alpha = 0.0; object.alpha = 0.0;
} }
} }
} }

View File

@@ -2,7 +2,8 @@ package haxework.animate;
interface IAnimate { interface IAnimate {
public function start(callback:IAnimate->Void, ?custom:Bool = false):Void; public function start(callback:IAnimate -> Void, custom:Bool = false):Void;
public function cancel():Void; public function cancel():Void;
private function update(time:Float):Void; private function update(time:Float):Void;

View File

@@ -0,0 +1,14 @@
package haxework.animate;
class SlideAnimate extends Animate {
override public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
object.x = view.x - this.view.width + this.view.width / progress;
super.start(callback, custom);
}
override private function update(time:Float):Void {
super.update(time);
object.x = view.x - this.view.width + this.view.width / Math.min(1, progress);
}
}

View File

@@ -1,28 +1,19 @@
package haxework.animate; package haxework.animate;
import flash.display.Sprite;
import haxework.gui.IView;
import haxework.animate.Animate; import haxework.animate.Animate;
class UnFadeAnimate extends Animate { class UnFadeAnimate extends Animate {
private var view:IView; override public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
object.alpha = 0.0;
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); super.start(callback, custom);
} }
override private function update(time:Float):Void { override private function update(time:Float):Void {
super.update(time); super.update(time);
view.content.alpha = progress * 1.0; object.alpha = progress * 1.0;
if (progress >= 1) { if (progress >= 1) {
view.content.alpha = 1.0; object.alpha = 1.0;
} }
} }
} }

View File

@@ -0,0 +1,29 @@
package haxework.app;
import flash.display.BitmapData;
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
import flash.Lib;
class LinuxIcon {
public static var value(default, set):BitmapData;
private static function set_value(value:BitmapData):BitmapData {
LinuxIcon.value = value;
Lib.current.stage.window.setIcon(prepareIcon(value).image);
return LinuxIcon.value;
}
private static function prepareIcon(bitmap:BitmapData):BitmapData {
var matrix:Array<Float> = [];
matrix = matrix.concat([0, 0, 1, 0, 0]);
matrix = matrix.concat([0, 1, 0, 0, 0]);
matrix = matrix.concat([1, 0, 0, 0, 0]);
matrix = matrix.concat([0, 0, 0, 1, 0]);
var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix);
var bitmap:BitmapData = bitmap.clone();
bitmap.applyFilter(bitmap, bitmap.rect, new Point(0, 0), cmf);
return bitmap;
}
}

View File

@@ -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));
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,71 @@
package haxework.color;
abstract Color(Int) {
public var alpha(get, never):Int;
public var red(get, never):Int;
public var green(get, never):Int;
public var blue(get, never):Int;
public var zero(get, never):Bool;
public inline function new(value:Int) {
this = value;
}
private inline function get_alpha():Int {
return (this >> 24) & 255;
}
private inline function get_red():Int {
return (this >> 16) & 255;
}
private inline function get_green():Int {
return (this >> 8) & 255;
}
private inline function get_blue():Int {
return this & 255;
}
private inline function get_zero():Bool {
return green == 0 && red == 0 && blue == 0;
}
@:from static public inline function fromArray(value:Array<Int>):Color {
return new Color((value[0] << 24) + (value[1] << 16) + (value[2] << 8) + value[3]);
}
@:from static public inline function fromInt(value:Int):Color {
return new Color(value);
}
@:to public inline function toInt():Int {
return this;
}
@:from static public inline function fromString(value:String):Color {
return new Color(switch value {
case "white": 0xFFFFFF;
case "silver": 0xC0C0C0;
case "gray": 0x808080;
case "black": 0x000000;
case "red": 0xFF0000;
case "maroon": 0x800000;
case "yellow": 0xFFFF00;
case "olive": 0x808000;
case "lime": 0x00FF00;
case "green": 0x008000;
case "aqua": 0x00FFFF;
case "teal": 0x008080;
case "blue": 0x0000FF;
case "navy": 0x000080;
case "fuchsia": 0xFF00FF;
case "purple": 0x800080;
case x: Std.parseInt('0x${x.split('#').pop()}');
});
}
@:to public inline function toString():String {
return StringTools.hex(this);
}
}

View File

@@ -0,0 +1,36 @@
package haxework.color;
class ColorUtil {
public static function floor(colorPart:Float):Int {
return Std.int(Math.max(0, Math.min(255, colorPart)));
}
public static function multiply(color:Color, m:Float):Color {
return [
color.alpha,
floor(color.red * m),
floor(color.green * m),
floor(color.blue * m),
];
}
public static function diff(color:Color, d:Int):Color {
return [
color.alpha,
floor(color.red + d),
floor(color.green + d),
floor(color.blue + d),
];
}
public static function grey(color:Color):Color {
var m = (color.red + color.green + color.blue) / 3;
return [
color.alpha,
floor(m),
floor(m),
floor(m),
];
}
}

View File

@@ -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
}

View File

@@ -1,5 +0,0 @@
package haxework.core;
interface IDisposable {
public function dispose():Void;
}

View File

@@ -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);
}
}

View File

@@ -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 + ")";
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -0,0 +1,35 @@
package haxework.geom;
abstract IntPoint(Array<Int>) {
public var x(get, set):Int;
public var y(get, set):Int;
public function new(x:Int, y:Int) {
this = [x, y];
}
private inline function get_x() return this[0];
private inline function set_x(value) return this[0] = value;
private inline function get_y() return this[1];
private inline function set_y(value) return this[1] = value;
public function clone():IntPoint {
return new IntPoint(x, y);
}
public function toString():String {
return 'IntPoint{x=$x,y=$y}';
}
@:to inline public function toInt():Int {
return (x << 16) + y;
}
@:to inline public function toPoint():Point {
return new Point(x, y);
}
}

View File

@@ -0,0 +1,40 @@
package haxework.geom;
import flash.geom.Point as FlashPoint;
abstract Point(Array<Float>) {
public var x(get, set):Float;
public var y(get, set):Float;
public function new(x:Float, y:Float) {
this = [x, y];
}
private inline function get_x() return this[0];
private inline function set_x(value) return this[0] = value;
private inline function get_y() return this[1];
private inline function set_y(value) return this[1] = value;
public function add(point:Point):Point {
return new Point(x + point.x, y + point.y);
}
public function subtract(point:Point):Point {
return new Point(x - point.x, y - point.y);
}
public function clone():Point {
return new Point(x, y);
}
public function toString():String {
return 'Point{x=$x,y=$y}';
}
@:from public static function fromFlashPoint(value:FlashPoint):Point {
return new Point(value.x, value.y);
}
}

View File

@@ -0,0 +1,102 @@
package haxework.geom;
abstract Rectangle(Array<Float>) {
public var x(get, set):Float;
public var y(get, set):Float;
public var width(get, set):Float;
public var height(get, set):Float;
public var center(get, set):Point;
public var size(get, set):Point;
public var left(get, never):Float;
public var right(get, never):Float;
public var top(get, never):Float;
public var bottom(get, never):Float;
public var position(get, set):Point;
public function new(x:Float = 0, y:Float = 0, width:Float = 0, height:Float = 0) {
this = [x, y, width, height];
}
private inline function get_x() return this[0];
private inline function set_x(value) return this[0] = value;
private inline function get_y() return this[1];
private inline function set_y(value) return this[1] = value;
private inline function get_width() return this[2];
private inline function set_width(value) return this[2] = value;
private inline function get_height() return this[3];
private inline function set_height(value) return this[3] = value;
private function get_center():Point {
return new Point(x + width / 2, y + height / 2);
}
private function set_center(value:Point):Point {
x = value.x - width / 2;
y = value.y - height / 2;
return value;
}
private function get_size():Point {
return new Point(width, height);
}
private function set_size(value:Point):Point {
width = value.x;
height = value.y;
return value;
}
public function contain(point:Point):Bool {
return point.x >= left && point.y >= top && point.x <= right && point.y <= bottom;
}
public function intersection(rect:Rectangle):Bool {
return !(
rect.left > right ||
rect.right < left ||
rect.top > bottom ||
rect.bottom < top
);
}
public function clone():Rectangle {
return new Rectangle(x, y, width, height);
}
public function toString():String {
return 'Rectangle{x=$x,y=$y,width=$width,height=$height}';
}
private function get_left():Float {
return x;
}
private function get_right():Float {
return x + width;
}
private function get_top():Float {
return y;
}
private function get_bottom():Float {
return y + height;
}
private function get_position():Point {
return new Point(x, y);
}
private function set_position(position:Point):Point {
x = position.x;
y = position.y;
return position;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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>;
}

View File

@@ -1,17 +0,0 @@
package haxework.gui;
import flash.text.TextField;
import haxework.gui.IView;
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;
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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
}

View File

@@ -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;
}
}
}

View File

@@ -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();
}
}

View File

@@ -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 + ")");
}
}

View File

@@ -1,6 +0,0 @@
package haxework.gui.core;
enum Direction {
HORIZONTAL;
VERTICAL;
}

View File

@@ -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";
}

View File

@@ -1,6 +0,0 @@
package haxework.gui.core;
enum SizeType {
NORMAL;
PERCENT;
}

View File

@@ -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";
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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:
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -1,5 +0,0 @@
package haxework.gui.layout;
interface ILayout {
public function place(group:IGroupView, views:Array<IView>):Void;
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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);
});
}
}

View File

@@ -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;
public var items(default, null):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;
}
typedef ListViewListener<D> = {
public function onListItemClick(item:IListItemView<D>):Void;
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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);
});
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}

Some files were not shown because too many files have changed in this diff Show More