diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 7102a109..185c285d 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -78,6 +78,7 @@ class MarbleGame { case x: x; }; @:privateAccess Key.keyPressed[buttonCode] = Key.getFrame(); + @:privateAccess Window.getInstance().onMouseDown(e); }); pointercontainer.addEventListener('mouseup', (e:js.html.MouseEvent) -> { var buttonCode = switch (e.button) { @@ -86,6 +87,7 @@ class MarbleGame { case x: x; }; @:privateAccess Key.keyPressed[buttonCode] = -Key.getFrame(); + @:privateAccess Window.getInstance().onMouseUp(e); }); canvas.addEventListener('mousedown', (e:js.html.MouseEvent) -> { var buttonCode = switch (e.button) { @@ -103,13 +105,18 @@ class MarbleGame { }; @:privateAccess Key.keyPressed[buttonCode] = -Key.getFrame(); }); + pointercontainer.addEventListener('keypress', (e:js.html.KeyboardEvent) -> { + @:privateAccess Window.getInstance().onKeyPress(e); + }); pointercontainer.addEventListener('keydown', (e:js.html.KeyboardEvent) -> { var buttonCode = (e.keyCode); @:privateAccess Key.keyPressed[buttonCode] = Key.getFrame(); + @:privateAccess Window.getInstance().onKeyDown(e); }); pointercontainer.addEventListener('keyup', (e:js.html.KeyboardEvent) -> { var buttonCode = (e.keyCode); @:privateAccess Key.keyPressed[buttonCode] = -Key.getFrame(); + @:privateAccess Window.getInstance().onKeyUp(e); }); js.Browser.window.addEventListener('keydown', (e:js.html.KeyboardEvent) -> { var buttonCode = (e.keyCode); diff --git a/src/ParticleSystem.hx b/src/ParticleSystem.hx index 9b76524f..e4be8ed1 100644 --- a/src/ParticleSystem.hx +++ b/src/ParticleSystem.hx @@ -150,7 +150,7 @@ class Particle { this.part.g = this.color.g; this.part.b = this.color.b; this.part.ratio = 1; - this.part.size = this.scale; + this.part.size = this.scale / 2; } } diff --git a/src/gui/GuiMLText.hx b/src/gui/GuiMLText.hx index a24ea106..aff0af73 100644 --- a/src/gui/GuiMLText.hx +++ b/src/gui/GuiMLText.hx @@ -1,5 +1,6 @@ package gui; +import h2d.Flow; import h3d.mat.Texture; import h2d.Tile; import h2d.Bitmap; @@ -18,10 +19,7 @@ import src.Settings; class GuiMLText extends GuiControl { var text:HtmlText; var justify:Justification = Left; - var bmp:Bitmap; - var textTexture:Texture; - var _textContents = ""; - var _dirty = true; + var flow:Flow; public var scrollable:Bool = false; @@ -29,7 +27,6 @@ class GuiMLText extends GuiControl { super(); this.text = new HtmlText(font); this.text.loadFont = loadFontFunc; - this._textContents = text.text; } public override function render(scene2d:Scene) { @@ -37,19 +34,16 @@ class GuiMLText extends GuiControl { text.maxWidth = renderRect.extent.x; if (this.scrollable) { - if (textTexture != null) - textTexture.dispose(); + this.flow = new Flow(); + this.flow.addChild(this.text); - textTexture = new Texture(cast text.maxWidth, cast renderRect.extent.y, [Target]); - - if (bmp != null) { - bmp.tile = Tile.fromTexture(textTexture); - } else { - bmp = new Bitmap(Tile.fromTexture(textTexture)); - } + this.flow.maxWidth = cast renderRect.extent.x; + this.flow.maxHeight = cast renderRect.extent.y; + this.flow.multiline = true; + this.flow.overflow = FlowOverflow.Hidden; } - var obj:h2d.Object = this.scrollable ? bmp : text; + var obj:h2d.Object = this.scrollable ? flow : text; if (justify == Left) { obj.setPosition(Math.floor(renderRect.position.x), Math.floor(renderRect.position.y)); @@ -69,10 +63,6 @@ class GuiMLText extends GuiControl { scene2d.addChild(obj); - // if (text.filter == null) { - // text.filter = new GuiRender(renderRect); - // } - scene2d.addChild(obj); super.render(scene2d); } @@ -82,15 +72,14 @@ class GuiMLText extends GuiControl { if (!this.scrollable) { this.text.remove(); } else { - this.bmp.remove(); - this.textTexture.dispose(); + this.flow.remove(); } } public override function onRemove() { super.onRemove(); - if (MarbleGame.canvas.scene2d.contains(bmp)) { - MarbleGame.canvas.scene2d.removeChild(bmp); // Refresh "layer" + if (MarbleGame.canvas.scene2d.contains(flow)) { + MarbleGame.canvas.scene2d.removeChild(flow); // Refresh "layer" } if (MarbleGame.canvas.scene2d.contains(text)) { MarbleGame.canvas.scene2d.removeChild(text); // Refresh "layer" @@ -99,23 +88,5 @@ class GuiMLText extends GuiControl { public override function onScroll(scrollX:Float, scrollY:Float) { text.setPosition(0, -scrollY); - this._dirty = true; - } - - public override function renderEngine(engine:Engine) { - if (this.scrollable) { - #if hl - if (this._textContents != this.text.text || this._dirty) { - #end - textTexture.clear(0, 0); - text.drawTo(textTexture); - this._textContents = this.text.text; - #if hl - this._dirty = false; - } - #end - - super.renderEngine(engine); - } } } diff --git a/src/gui/GuiTextListCtrl.hx b/src/gui/GuiTextListCtrl.hx index 697ad0f7..f069dba3 100644 --- a/src/gui/GuiTextListCtrl.hx +++ b/src/gui/GuiTextListCtrl.hx @@ -1,5 +1,6 @@ package gui; +import h2d.Flow; import h3d.Engine; import h2d.Tile; import h2d.Bitmap; @@ -21,10 +22,6 @@ class GuiTextListCtrl extends GuiControl { var g:Graphics; var _prevSelected:Int = -1; - var bmp:Bitmap; - var textTexture:Texture; - var _dirty = true; - public var selectedColor:Int = 0x206464; public var selectedFillColor:Int = 0xC8C8C8; @@ -34,6 +31,8 @@ class GuiTextListCtrl extends GuiControl { public var scrollable:Bool = false; + var flow:Flow; + public function new(font:Font, texts:Array) { super(); this.font = font; @@ -59,12 +58,20 @@ class GuiTextListCtrl extends GuiControl { tobj.text = text; tobj.textColor = 0; textObjs.push(tobj); + + if (this.scrollable) { + if (this.flow.contains(tobj)) + this.flow.removeChild(tobj); + + this.flow.addChild(tobj); + + this.flow.getProperties(tobj).isAbsolute = true; + } } this.texts = texts; this._prevSelected = -1; if (this.onSelectedFunc != null) this.onSelectedFunc(-1); - this._dirty = true; redrawSelectionRect(renderRect); @@ -88,44 +95,46 @@ class GuiTextListCtrl extends GuiControl { g.setPosition(renderRect.position.x, renderRect.position.y - this.scroll); if (scrollable) { - if (textTexture != null) - textTexture.dispose(); + this.flow = new Flow(); var htr = this.getHitTestRect(); - textTexture = new Texture(cast htr.extent.x, cast htr.extent.y, [Target]); - if (bmp != null) { - bmp.tile = Tile.fromTexture(textTexture); - } else { - bmp = new Bitmap(Tile.fromTexture(textTexture)); - } + this.flow.maxWidth = cast htr.extent.x; + this.flow.maxHeight = cast htr.extent.y; + this.flow.multiline = true; + this.flow.layout = Stack; + this.flow.overflow = FlowOverflow.Hidden; + if (scene2d.contains(this.flow)) + scene2d.removeChild(this.flow); - if (scene2d.contains(bmp)) - scene2d.removeChild(bmp); + scene2d.addChild(this.flow); - scene2d.addChild(bmp); - - bmp.setPosition(htr.position.x, htr.position.y); + this.flow.setPosition(htr.position.x, htr.position.y); } for (i in 0...textObjs.length) { var text = textObjs[i]; - text.setPosition(Math.floor((!scrollable ? renderRect.position.x : 0) + 5), - Math.floor((!scrollable ? renderRect.position.y : 0) + (i * (text.font.size + 4) + 5 + textYOffset - this.scroll))); if (!scrollable) { if (scene2d.contains(text)) scene2d.removeChild(text); scene2d.addChild(text); + } else { + if (this.flow.contains(text)) + this.flow.removeChild(text); + this.flow.addChild(text); + + this.flow.getProperties(text).isAbsolute = true; } + text.setPosition(Math.floor((!scrollable ? renderRect.position.x : 0) + 5), + Math.floor((!scrollable ? renderRect.position.y : 0) + (i * (text.font.size + 4) + 5 + textYOffset - this.scroll))); + if (_prevSelected == i) { text.textColor = selectedColor; } } redrawSelectionRect(renderRect); - redrawText(); - super.render(scene2d); } @@ -140,8 +149,7 @@ class GuiTextListCtrl extends GuiControl { } this.g.remove(); if (this.scrollable) { - this.textTexture.dispose(); - this.bmp.remove(); + this.flow.remove(); } } @@ -173,7 +181,6 @@ class GuiTextListCtrl extends GuiControl { text.textColor = selected ? selectedColor : 0; // fill color = 0xC8C8C8 } - this._dirty = true; // obviously in renderRect } @@ -185,7 +192,6 @@ class GuiTextListCtrl extends GuiControl { text.textColor = 0; // fill color = 0xC8C8C8 } - this._dirty = true; } public override function onMousePress(mouseState:MouseState) { @@ -200,7 +206,6 @@ class GuiTextListCtrl extends GuiControl { selectedIndex = -1; } if (_prevSelected != selectedIndex) { - this._dirty = true; _prevSelected = selectedIndex; redrawSelectionRect(renderRect); @@ -255,35 +260,7 @@ class GuiTextListCtrl extends GuiControl { var text = textObjs[i]; text.y = Math.floor((i * (text.font.size + 4) + 5 + textYOffset - scrollY)); g.y = renderRect.position.y - scrollY; - - // if (text.y < hittestrect.position.y - text.textHeight || text.y > hittestrect.position.y + hittestrect.extent.y) - // text.visible = false; - // else { - // text.visible = true; - // } } redrawSelectionRect(hittestrect); - this._dirty = true; - } - - function redrawText() { - if (this.scrollable) { - #if hl - if (this._dirty) { - #end - textTexture.clear(0, 0); - for (txt in this.textObjs) { - txt.drawTo(textTexture); - } - #if hl - this._dirty = false; - } - #end - } - } - - public override function renderEngine(engine:Engine) { - redrawText(); - super.renderEngine(engine); } } diff --git a/src/shaders/CubemapRenderer.hx b/src/shaders/CubemapRenderer.hx index a1a1eebc..0312aa4a 100644 --- a/src/shaders/CubemapRenderer.hx +++ b/src/shaders/CubemapRenderer.hx @@ -20,7 +20,7 @@ class CubemapRenderer { public function new(scene:Scene) { this.scene = scene; this.cubemap = new Texture(128, 128, [Cube, Dynamic, Target]); - this.camera = new Camera(90, 1, 1); + this.camera = new Camera(90, 1, 1, 0.02, 100); this.position = new Vector(); this.nextFaceToRender = 0; }